Move codec code out of omx plugin directories
separate actual codec code for amrnb, amrwb, m4v_h263, and mp3dec from
the OMX plugins.
Bug: 147679485
Test: build
Change-Id: I8b6005384872e667cdcf5f700a848beba355a395
diff --git a/media/codecs/amrnb/TEST_MAPPING b/media/codecs/amrnb/TEST_MAPPING
new file mode 100644
index 0000000..343d08a
--- /dev/null
+++ b/media/codecs/amrnb/TEST_MAPPING
@@ -0,0 +1,10 @@
+// mappings for frameworks/av/media/libstagefright/codecs/amrnb
+{
+ // tests which require dynamic content
+ // invoke with: atest -- --enable-module-dynamic-download=true
+ // TODO(b/148094059): unit tests not allowed to download content
+ "dynamic-presubmit": [
+ { "name": "AmrnbDecoderTest"},
+ { "name": "AmrnbEncoderTest"}
+ ]
+}
diff --git a/media/codecs/amrnb/common/Android.bp b/media/codecs/amrnb/common/Android.bp
new file mode 100644
index 0000000..59a791d
--- /dev/null
+++ b/media/codecs/amrnb/common/Android.bp
@@ -0,0 +1,91 @@
+cc_library {
+ name: "libstagefright_amrnb_common",
+ vendor_available: true,
+ host_supported: true,
+ min_sdk_version: "29",
+
+ srcs: [
+ "src/add.cpp",
+ "src/az_lsp.cpp",
+ "src/bitno_tab.cpp",
+ "src/bitreorder_tab.cpp",
+ "src/bits2prm.cpp",
+ "src/c2_9pf_tab.cpp",
+ "src/copy.cpp",
+ "src/div_32.cpp",
+ "src/div_s.cpp",
+ "src/extract_h.cpp",
+ "src/extract_l.cpp",
+ "src/gains_tbl.cpp",
+ "src/gc_pred.cpp",
+ "src/gmed_n.cpp",
+ "src/grid_tbl.cpp",
+ "src/gray_tbl.cpp",
+ "src/int_lpc.cpp",
+ "src/inv_sqrt.cpp",
+ "src/inv_sqrt_tbl.cpp",
+ "src/l_abs.cpp",
+ "src/l_deposit_h.cpp",
+ "src/l_deposit_l.cpp",
+ "src/l_shr_r.cpp",
+ "src/log2.cpp",
+ "src/log2_norm.cpp",
+ "src/log2_tbl.cpp",
+ "src/lsfwt.cpp",
+ "src/lsp.cpp",
+ "src/lsp_az.cpp",
+ "src/lsp_lsf.cpp",
+ "src/lsp_lsf_tbl.cpp",
+ "src/lsp_tab.cpp",
+ "src/mult_r.cpp",
+ "src/norm_l.cpp",
+ "src/norm_s.cpp",
+ "src/ph_disp_tab.cpp",
+ "src/pow2.cpp",
+ "src/pow2_tbl.cpp",
+ "src/pred_lt.cpp",
+ "src/q_plsf.cpp",
+ "src/q_plsf_3.cpp",
+ "src/q_plsf_3_tbl.cpp",
+ "src/q_plsf_5.cpp",
+ "src/q_plsf_5_tbl.cpp",
+ "src/qua_gain_tbl.cpp",
+ "src/reorder.cpp",
+ "src/residu.cpp",
+ "src/round.cpp",
+ "src/set_zero.cpp",
+ "src/shr.cpp",
+ "src/shr_r.cpp",
+ "src/sqrt_l.cpp",
+ "src/sqrt_l_tbl.cpp",
+ "src/sub.cpp",
+ "src/syn_filt.cpp",
+ "src/vad1.cpp",
+ "src/weight_a.cpp",
+ "src/window_tab.cpp",
+ ],
+
+ export_include_dirs: ["include"],
+
+ cflags: [
+ "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+ "-DOSCL_IMPORT_REF=",
+ "-DOSCL_EXPORT_REF=",
+
+ "-Werror",
+ ],
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+
+ //addressing b/25409744
+ //sanitize: {
+ // misc_undefined: [
+ // "signed-integer-overflow",
+ // "unsigned-integer-overflow",
+ // ],
+ //},
+}
diff --git a/media/codecs/amrnb/common/MODULE_LICENSE_APACHE2 b/media/codecs/amrnb/common/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/amrnb/common/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/amrnb/common/NOTICE b/media/codecs/amrnb/common/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/amrnb/common/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/amrnb/common/include/abs_s.h b/media/codecs/amrnb/common/include/abs_s.h
new file mode 100644
index 0000000..e92eaf4
--- /dev/null
+++ b/media/codecs/amrnb/common/include/abs_s.h
@@ -0,0 +1,113 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/abs_s.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for abs_s function.
+
+ Description: Updated template to make it build for Symbian.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the abs_s function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef ABS_S_H
+#define ABS_S_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 abs_s(Word16 var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ABS_S_H */
+
+
diff --git a/media/codecs/amrnb/common/include/add.h b/media/codecs/amrnb/common/include/add.h
new file mode 100644
index 0000000..43daeca
--- /dev/null
+++ b/media/codecs/amrnb/common/include/add.h
@@ -0,0 +1,116 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/add.h
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Created separate header file for add function.
+
+ Description: Changed function prototype; pointer to overflow flag is passed
+ in as a parameter.
+
+ Description: Updated copyright section.
+ Changed "overflow" to "pOverflow" in the function prototype.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the add function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef ADD_H
+#define ADD_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 add(Word16 var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ADD_H_ */
+
diff --git a/media/codecs/amrnb/common/include/az_lsp.h b/media/codecs/amrnb/common/include/az_lsp.h
new file mode 100644
index 0000000..7c24ca9
--- /dev/null
+++ b/media/codecs/amrnb/common/include/az_lsp.h
@@ -0,0 +1,120 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/az_lsp.h.h
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Changed function prototype; pointer to overflow flag is passed
+ in as a parameter. Added extern declaration for grid_tbl[],
+ defined in grid_tbl.c
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the function Az_lsp()
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef AZ_LSP_H
+#define AZ_LSP_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define grid_points 60
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 grid[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Az_lsp(
+ Word16 a[], /* (i) : predictor coefficients (MP1) */
+ Word16 lsp[], /* (o) : line spectral pairs (M) */
+ Word16 old_lsp[], /* (i) : old lsp[] (in case not found 10 roots) (M) */
+ Flag *pOverflow /* (i/o): overflow flag */
+ );
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _AZ_LSP_H */
+
diff --git a/media/codecs/amrnb/common/include/basic_op.h b/media/codecs/amrnb/common/include/basic_op.h
new file mode 100644
index 0000000..f6c80e2
--- /dev/null
+++ b/media/codecs/amrnb/common/include/basic_op.h
@@ -0,0 +1,448 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./include/basic_op.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Revised basic_op.h since the basicop2.c functions were split
+ up into separate source and header files. This function was
+ retained because there are legacy GSM AMR C functions that still
+ include this file. This file now includes the various basicop2
+ functions' header files instead of defining the function
+ prototypes.
+
+ Description: Including header files with platform specific inline assembly
+ instructions.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file includes all the basicop2.c functions' header files.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef BASIC_OP_H
+#define BASIC_OP_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+#if defined(PV_ARM_V5)
+#include "basic_op_arm_v5.h"
+
+#elif defined(PV_ARM_GCC_V5)
+#include "basic_op_arm_gcc_v5.h"
+
+#else
+#include "basic_op_c_equivalent.h"
+
+#endif
+
+
+
+#include "add.h"
+#include "div_s.h"
+#include "div_32.h"
+#include "extract_h.h"
+#include "extract_l.h"
+#include "l_deposit_h.h"
+#include "l_deposit_l.h"
+#include "l_shr_r.h"
+#include "mult_r.h"
+#include "norm_l.h"
+#include "norm_s.h"
+#include "round.h"
+#include "shr_r.h"
+#include "sub.h"
+#include "shr.h"
+#include "l_abs.h"
+#include "l_negate.h"
+#include "l_extract.h"
+#include "l_abs.h"
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: mac_32
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+ L_var1_hi = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ L_var1_lo = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+ L_var2_hi = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ L_var2_lo = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit mac operation resulted in overflow
+
+ Returns:
+ L_var3 = 32-bit result of L_var3 + (L_var1 * L_var2)(Word32)
+
+ */
+ static inline Word32 Mac_32(Word32 L_var3,
+ Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 L_var2_hi,
+ Word16 L_var2_lo,
+ Flag *pOverflow)
+ {
+ Word16 product;
+
+ L_var3 = L_mac(L_var3, L_var1_hi, L_var2_hi, pOverflow);
+
+ product = mult(L_var1_hi, L_var2_lo, pOverflow);
+ L_var3 = L_mac(L_var3, product, 1, pOverflow);
+
+ product = mult(L_var1_lo, L_var2_hi, pOverflow);
+ L_var3 = L_mac(L_var3, product, 1, pOverflow);
+
+ return (L_var3);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: mac_32_16
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+ L_var1_hi = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ L_var1_lo = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+ var2= 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit mac operation resulted in overflow
+
+ Returns:
+ L_var3 = 32-bit result of L_var3 + (L_var1 * var2)(Word32)
+ */
+
+ static inline Word32 Mac_32_16(Word32 L_var3,
+ Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+ {
+ Word16 product;
+
+ L_var3 = L_mac(L_var3, L_var1_hi, var2, pOverflow);
+
+ product = mult(L_var1_lo, var2, pOverflow);
+ L_var3 = L_mac(L_var3, product, 1, pOverflow);
+
+ return (L_var3);
+ }
+
+
+ /*----------------------------------------------------------------------------
+ Function Name : negate
+
+ Negate var1 with saturation, saturate in the case where input is -32768:
+ negate(var1) = sub(0,var1).
+
+ Inputs :
+ var1
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 0x8000 <= var1 <= 0x7fff.
+
+ Outputs :
+ none
+
+ Return Value :
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 0x8000 <= var_out <= 0x7fff.
+ ----------------------------------------------------------------------------*/
+
+ static inline Word16 negate(Word16 var1)
+ {
+ return (((var1 == MIN_16) ? MAX_16 : -var1));
+ }
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : shl
+
+ Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill
+ the var2 LSB of the result. If var2 is negative, arithmetically shift
+ var1 right by -var2 with sign extension. Saturate the result in case of
+ underflows or overflows.
+
+ Inputs :
+ var1
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 0x8000 <= var1 <= 0x7fff.
+
+ var2
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 0x8000 <= var1 <= 0x7fff.
+
+ pOverflow : pointer to overflow (Flag)
+
+ Return Value :
+ var_out
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 0x8000 <= var_out <= 0x7fff.
+ ----------------------------------------------------------------------------*/
+
+ static inline Word16 shl(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word16 var_out = 0;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ if (var2 < 0)
+ {
+ var2 = -var2;
+ if (var2 < 15)
+ {
+ var_out = var1 >> var2;
+ }
+
+ }
+ else
+ {
+ var_out = var1 << var2;
+ if (var_out >> var2 != var1)
+ {
+ var_out = (var1 >> 15) ^ MAX_16;
+ }
+ }
+ return (var_out);
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : L_shl
+
+ Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero
+ fill the var2 LSB of the result. If var2 is negative, arithmetically
+ shift L_var1 right by -var2 with sign extension. Saturate the result in
+ case of underflows or overflows.
+
+ Inputs :
+ L_var1 32 bit long signed integer (Word32) whose value falls in the
+ range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ var2
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 8000 <= var2 <= 7fff.
+
+ pOverflow : pointer to overflow (Flag)
+
+ Return Value :
+ 32 bit long signed integer (Word32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+ static inline Word32 L_shl(Word32 L_var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 L_var_out = 0;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ if (var2 > 0)
+ {
+ L_var_out = L_var1 << var2;
+ if (L_var_out >> var2 != L_var1)
+ {
+ L_var_out = (L_var1 >> 31) ^ MAX_32;
+ }
+ }
+ else
+ {
+ var2 = -var2;
+ if (var2 < 31)
+ {
+ L_var_out = L_var1 >> var2;
+ }
+
+ }
+
+ return (L_var_out);
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : L_shr
+
+ Arithmetically shift the 32 bit input L_var1 right var2 positions with
+ sign extension. If var2 is negative, arithmetically shift L_var1 left
+ by -var2 and zero fill the -var2 LSB of the result. Saturate the result
+ in case of underflows or overflows.
+
+ Inputs :
+ L_var1 32 bit long signed integer (Word32) whose value falls in the
+ range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ var2
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 8000 <= var2 <= 7fff.
+
+ pOverflow : pointer to overflow (Flag)
+
+ Return Value :
+ 32 bit long signed integer (Word32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+ static inline Word32 L_shr(Word32 L_var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 L_var_out = 0;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ if (var2 > 0)
+ {
+ if (var2 < 31)
+ {
+ L_var_out = L_var1 >> var2;
+ }
+ }
+ else
+ {
+ var2 = -var2;
+
+ L_var_out = L_var1 << (var2) ;
+ if ((L_var_out >> (var2)) != L_var1)
+ {
+ L_var_out = (L_var1 >> 31) ^ MAX_32;
+ }
+
+ }
+
+ return (L_var_out);
+ }
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : abs_s
+
+ Absolute value of var1; abs_s(-32768) = 32767.
+
+ Inputs :
+ var1
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 0x8000 <= var1 <= 0x7fff.
+
+ pOverflow : pointer to overflow (Flag)
+
+ Outputs :
+ none
+
+ Return Value :
+ 16 bit short signed integer (Word16) whose value falls in the
+ range : 0x0000 <= var_out <= 0x7fff.
+
+ ----------------------------------------------------------------------------*/
+
+ static inline Word16 abs_s(Word16 var1)
+ {
+
+ Word16 y = var1 - (var1 < 0);
+ y = y ^(y >> 15);
+ return (y);
+
+ }
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* BASIC_OP_H */
+
+
diff --git a/media/codecs/amrnb/common/include/basic_op_arm_gcc_v5.h b/media/codecs/amrnb/common/include/basic_op_arm_gcc_v5.h
new file mode 100644
index 0000000..48f0bcb
--- /dev/null
+++ b/media/codecs/amrnb/common/include/basic_op_arm_gcc_v5.h
@@ -0,0 +1,543 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./include/basic_op_arm_gcc_v5.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file includes all the GCC-ARM V5 basicop.c functions.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef BASIC_OP_ARM_GCC_V5_H
+#define BASIC_OP_ARM_GCC_V5_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_add
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ L_var2 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_sum = 32-bit sum of L_var1 and L_var2 (Word32)
+ */
+
+ __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
+ {
+ register Word32 ra = L_var1;
+ register Word32 rb = L_var2;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("qadd %0, %1, %2"
+ : "=r"(result)
+ : "r"(ra), "r"(rb)
+ );
+ return (result);
+
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_sub
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ L_var2 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_diff = 32-bit difference of L_var1 and L_var2 (Word32)
+ */
+ __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
+{
+ register Word32 ra = L_var1;
+ register Word32 rb = L_var2;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("qsub %0, %1, %2"
+ : "=r"(result)
+ : "r"(ra), "r"(rb)
+ );
+
+ return (result);
+ }
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_mac
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ result = 32-bit result of L_var3 + (var1 * var2)(Word32)
+ */
+ static inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+{
+ register Word32 ra = L_var3;
+ register Word32 rb = var1;
+ register Word32 rc = var2;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(result)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(rc)
+ : "r"(ra), "r"(result)
+ );
+
+ return (rc);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_mult
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ L_var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_product = 32-bit product of L_var1 and L_var2 (Word32)
+ */
+
+ __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
+{
+ register Word32 ra = var1;
+ register Word32 rb = var2;
+ Word32 result;
+ Word32 product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product)
+ : "r"(ra), "r"(rb)
+ );
+
+ asm volatile("qadd %0, %1, %2"
+ : "=r"(result)
+ : "r"(product), "r"(product)
+ );
+
+ return(result);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_msu
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit operation resulted in overflow
+
+ Returns:
+ result = 32-bit result of L_var3 - (var1 * var2)
+ */
+ __inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+{
+ register Word32 ra = L_var3;
+ register Word32 rb = var1;
+ register Word32 rc = var2;
+ Word32 product;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("qdsub %0, %1, %2"
+ : "=r"(result)
+ : "r"(ra), "r"(product)
+ );
+
+ return (result);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Mpy_32
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1_hi = most significant word of first input (Word16).
+ L_var1_lo = least significant word of first input (Word16).
+ L_var2_hi = most significant word of second input (Word16).
+ L_var2_lo = least significant word of second input (Word16).
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit multiply operation resulted in overflow
+
+ Returns:
+ L_product = 32-bit product of L_var1 and L_var2 (Word32)
+ */
+ static inline Word32 Mpy_32(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 L_var2_hi,
+ Word16 L_var2_lo,
+ Flag *pOverflow)
+{
+ register Word32 product32;
+ register Word32 L_sum;
+ register Word32 L_product, result;
+ register Word32 ra = L_var1_hi;
+ register Word32 rb = L_var1_lo;
+ register Word32 rc = L_var2_hi;
+ register Word32 rd = L_var2_lo;
+
+
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(ra), "r"(rc)
+ );
+ asm volatile("mov %0, #0"
+ : "=r"(result)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_sum)
+ : "r"(result), "r"(L_product)
+ );
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product32)
+ : "r"(ra), "r"(rd)
+ );
+
+ asm volatile("mov %0, %1, ASR #15"
+ : "=r"(ra)
+ : "r"(product32)
+ );
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(L_sum), "r"(ra)
+ );
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product32)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("mov %0, %1, ASR #15"
+ : "=r"(rb)
+ : "r"(product32)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_sum)
+ : "r"(L_product), "r"(rb)
+ );
+
+ return (L_sum);
+ }
+
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Mpy_32_16
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1_hi = most significant 16 bits of 32-bit input (Word16).
+ L_var1_lo = least significant 16 bits of 32-bit input (Word16).
+ var2 = 16-bit signed integer (Word16).
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit product operation resulted in overflow
+
+ Returns:
+ product = 32-bit product of the 32-bit L_var1 and 16-bit var1 (Word32)
+ */
+ static inline Word32 Mpy_32_16(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+{
+
+ register Word32 ra = L_var1_hi;
+ register Word32 rb = L_var1_lo;
+ register Word32 rc = var2;
+ Word32 result, L_product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(ra), "r"(rc)
+ );
+ asm volatile("mov %0, #0"
+ : "=r"(result)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(result), "r"(L_product)
+ );
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(result)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("mov %0, %1, ASR #15"
+ : "=r"(ra)
+ : "r"(result)
+ );
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(result)
+ : "r"(L_product), "r"(ra)
+ );
+
+ return (result);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: mult
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the add operation resulted in overflow
+
+ Returns:
+ product = 16-bit limited product of var1 and var2 (Word16)
+ */
+ __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow)
+{
+ register Word32 ra = var1;
+ register Word32 rb = var2;
+ Word32 product;
+ Word32 temp;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile(
+ "smulbb %0, %1, %2"
+ : "=r"(temp)
+ : "r"(ra), "r"(rb)
+ );
+ asm volatile(
+ "qadd %0, %1, %2\n\t"
+ "mov %0, %0, asr #16"
+ : "=&r*i"(product)
+ : "r"(temp), "r"(temp)
+ );
+
+ return ((Word16) product);
+ }
+
+ __inline Word32 amrnb_fxp_mac_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
+{
+ register Word32 ra = L_var1;
+ register Word32 rb = L_var2;
+ register Word32 rc = L_var3;
+ Word32 result;
+
+ asm volatile("smlabb %0, %1, %2, %3"
+ : "=r"(result)
+ : "r"(ra), "r"(rb), "r"(rc)
+ );
+ return (result);
+ }
+
+ __inline Word32 amrnb_fxp_msu_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
+{
+ register Word32 ra = L_var1;
+ register Word32 rb = L_var2;
+ register Word32 rc = L_var3;
+ Word32 result;
+
+ asm volatile("rsb %0, %1, #0"
+ : "=r"(ra)
+ : "r"(ra)
+ );
+
+ asm volatile("smlabb %0, %1, %2, %3"
+ : "=r"(result)
+ : "r"(ra), "r"(rb), "r"(rc)
+ );
+ return (result);
+ }
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BASIC_OP_ARM_GCC_V5_H */
+
+
diff --git a/media/codecs/amrnb/common/include/basic_op_arm_v5.h b/media/codecs/amrnb/common/include/basic_op_arm_v5.h
new file mode 100644
index 0000000..c939356
--- /dev/null
+++ b/media/codecs/amrnb/common/include/basic_op_arm_v5.h
@@ -0,0 +1,440 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./include/basic_op_arm_v5.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file includes all the ARM-V5 based basicop.c functions.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef BASIC_OP_ARM_V5_H
+#define BASIC_OP_ARM_V5_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_add
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ L_var2 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_sum = 32-bit sum of L_var1 and L_var2 (Word32)
+ */
+
+ __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
+ {
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+ __asm
+ {
+ QADD result, L_var1, L_var2
+ }
+ return(result);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_sub
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ L_var2 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_diff = 32-bit difference of L_var1 and L_var2 (Word32)
+ */
+ __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
+ {
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ QSUB result, L_var1, L_var2
+ }
+
+ return(result);
+
+ }
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_mac
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ result = 32-bit result of L_var3 + (var1 * var2)(Word32)
+ */
+ __inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+ Word32 L_sum;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm {SMULBB result, var1, var2}
+ __asm {QDADD L_sum, L_var3, result}
+ return (L_sum);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_mult
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ L_var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_product = 32-bit product of L_var1 and L_var2 (Word32)
+ */
+ __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+ Word32 product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ SMULBB product, var1, var2
+ QADD result, product, product
+ }
+
+ return (result);
+ }
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_msu
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit operation resulted in overflow
+
+ Returns:
+ result = 32-bit result of L_var3 - (var1 * var2)
+ */
+ __inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 product;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ SMULBB product, var1, var2
+ QDSUB result, L_var3, product
+ }
+
+ return (result);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Mpy_32
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1_hi = most significant word of first input (Word16).
+ L_var1_lo = least significant word of first input (Word16).
+ L_var2_hi = most significant word of second input (Word16).
+ L_var2_lo = least significant word of second input (Word16).
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit multiply operation resulted in overflow
+
+ Returns:
+ L_product = 32-bit product of L_var1 and L_var2 (Word32)
+ */
+ __inline Word32 Mpy_32(Word16 L_var1_hi, Word16 L_var1_lo, Word16 L_var2_hi,
+ Word16 L_var2_lo, Flag *pOverflow)
+
+ {
+
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 product32;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ SMULBB L_product, L_var1_hi, L_var2_hi
+ QDADD L_product, 0, L_product
+ SMULBB product32, L_var1_hi, L_var2_lo
+ }
+ product32 >>= 15;
+ __asm
+ {
+ QDADD L_sum, L_product, product32
+ }
+ L_product = L_sum;
+ __asm
+ {
+ SMULBB product32, L_var1_lo, L_var2_hi
+ }
+ product32 >>= 15;
+ __asm
+ {
+ QDADD L_sum, L_product, product32
+ }
+ return (L_sum);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Mpy_32_16
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1_hi = most significant 16 bits of 32-bit input (Word16).
+ L_var1_lo = least significant 16 bits of 32-bit input (Word16).
+ var2 = 16-bit signed integer (Word16).
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit product operation resulted in overflow
+
+ Returns:
+ product = 32-bit product of the 32-bit L_var1 and 16-bit var1 (Word32)
+ */
+ __inline Word32 Mpy_32_16(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+ {
+
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm {SMULBB L_product, L_var1_hi, var2}
+ __asm {QDADD L_product, 0, L_product}
+ __asm {SMULBB result, L_var1_lo, var2}
+ result >>= 15;
+ __asm {QDADD L_sum, L_product, result}
+ return (L_sum);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: mult
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the add operation resulted in overflow
+
+ Returns:
+ product = 16-bit limited product of var1 and var2 (Word16)
+ */
+ __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ SMULBB product, var1, var2
+ MOV product, product, ASR #15
+ CMP product, 0x7FFF
+ MOVGE product, 0x7FFF
+ }
+
+ return ((Word16) product);
+ }
+
+ __inline Word32 amrnb_fxp_mac_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
+ {
+ Word32 result;
+ __asm
+ {
+ smlabb result, L_var1, L_var2, L_var3
+ }
+ return result;
+ }
+
+ __inline Word32 amrnb_fxp_msu_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
+ {
+ Word32 result;
+ __asm
+ {
+ rsb L_var1, L_var1, #0
+ smlabb result, L_var1, L_var2, L_var3
+ }
+ return result;
+ }
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BASIC_OP_ARM_V5_H */
diff --git a/media/codecs/amrnb/common/include/basic_op_c_equivalent.h b/media/codecs/amrnb/common/include/basic_op_c_equivalent.h
new file mode 100644
index 0000000..8f0867a
--- /dev/null
+++ b/media/codecs/amrnb/common/include/basic_op_c_equivalent.h
@@ -0,0 +1,506 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./include/basic_op_c_equivalent.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file includes all the C-Equivalent basicop.c functions.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef BASIC_OP_C_EQUIVALENT_H
+#define BASIC_OP_C_EQUIVALENT_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_add
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ L_var2 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_sum = 32-bit sum of L_var1 and L_var2 (Word32)
+ */
+ __attribute__((no_sanitize("integer")))
+ static inline Word32 L_add(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
+ {
+ Word32 L_sum;
+
+ L_sum = L_var1 + L_var2;
+
+ if ((L_var1 ^ L_var2) >= 0)
+ {
+ if ((L_sum ^ L_var1) < 0)
+ {
+ L_sum = (L_var1 < 0) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+
+ return (L_sum);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_sub
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ L_var2 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_diff = 32-bit difference of L_var1 and L_var2 (Word32)
+ */
+ static inline Word32 L_sub(Word32 L_var1, Word32 L_var2,
+ Flag *pOverflow)
+ {
+ Word32 L_diff;
+
+ L_diff = L_var1 - L_var2;
+
+ if ((L_var1 ^ L_var2) < 0)
+ {
+ if ((L_diff ^ L_var1) & MIN_32)
+ {
+ L_diff = (L_var1 < 0L) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+
+ return (L_diff);
+ }
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_mac
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ result = 32-bit result of L_var3 + (var1 * var2)(Word32)
+ */
+ __inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+ Word32 L_sum;
+ result = (Word32) var1 * var2;
+ if (result != (Word32) 0x40000000L)
+ {
+ L_sum = (result << 1) + L_var3;
+
+ /* Check if L_sum and L_var_3 share the same sign */
+ if ((L_var3 ^ result) > 0)
+ {
+ if ((L_sum ^ L_var3) < 0)
+ {
+ L_sum = (L_var3 < 0) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_sum = MAX_32;
+ }
+ return (L_sum);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_mult
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ L_var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+
+ Returns:
+ L_product = 32-bit product of L_var1 and L_var2 (Word32)
+ */
+ static inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 L_product;
+
+ L_product = (Word32) var1 * var2;
+
+ if (L_product != (Word32) 0x40000000L)
+ {
+ L_product <<= 1; /* Multiply by 2 */
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_product = MAX_32;
+ }
+
+ return (L_product);
+ }
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: L_msu
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var3 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit operation resulted in overflow
+
+ Returns:
+ result = 32-bit result of L_var3 - (var1 * var2)
+ */
+
+ static inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+
+ result = L_mult(var1, var2, pOverflow);
+ result = L_sub(L_var3, result, pOverflow);
+
+ return (result);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Mpy_32
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1_hi = most significant word of first input (Word16).
+ L_var1_lo = least significant word of first input (Word16).
+ L_var2_hi = most significant word of second input (Word16).
+ L_var2_lo = least significant word of second input (Word16).
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit multiply operation resulted in overflow
+
+ Returns:
+ L_product = 32-bit product of L_var1 and L_var2 (Word32)
+ */
+ __inline Word32 Mpy_32(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 L_var2_hi,
+ Word16 L_var2_lo,
+ Flag *pOverflow)
+ {
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 product32;
+
+ OSCL_UNUSED_ARG(pOverflow);
+ L_product = (Word32) L_var1_hi * L_var2_hi;
+
+ if (L_product != (Word32) 0x40000000L)
+ {
+ L_product <<= 1;
+ }
+ else
+ {
+ L_product = MAX_32;
+ }
+
+ /* result = mult (L_var1_hi, L_var2_lo, pOverflow); */
+ product32 = ((Word32) L_var1_hi * L_var2_lo) >> 15;
+
+ /* L_product = L_mac (L_product, result, 1, pOverflow); */
+ L_sum = L_product + (product32 << 1);
+
+ if ((L_product ^ product32) > 0)
+ {
+ if ((L_sum ^ L_product) < 0)
+ {
+ L_sum = (L_product < 0) ? MIN_32 : MAX_32;
+ }
+ }
+
+ L_product = L_sum;
+
+ /* result = mult (L_var1_lo, L_var2_hi, pOverflow); */
+ product32 = ((Word32) L_var1_lo * L_var2_hi) >> 15;
+
+ /* L_product = L_mac (L_product, result, 1, pOverflow); */
+ L_sum = L_product + (product32 << 1);
+
+ if ((L_product ^ product32) > 0)
+ {
+ if ((L_sum ^ L_product) < 0)
+ {
+ L_sum = (L_product < 0) ? MIN_32 : MAX_32;
+ }
+ }
+ return (L_sum);
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Mpy_32_16
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1_hi = most significant 16 bits of 32-bit input (Word16).
+ L_var1_lo = least significant 16 bits of 32-bit input (Word16).
+ var2 = 16-bit signed integer (Word16).
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit product operation resulted in overflow
+
+ Returns:
+ product = 32-bit product of the 32-bit L_var1 and 16-bit var1 (Word32)
+ */
+
+ __inline Word32 Mpy_32_16(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+ {
+
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 result;
+ L_product = (Word32) L_var1_hi * var2;
+
+ if (L_product != (Word32) 0x40000000L)
+ {
+ L_product <<= 1;
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_product = MAX_32;
+ }
+
+ result = ((Word32)L_var1_lo * var2) >> 15;
+
+ L_sum = L_product + (result << 1);
+
+ if ((L_product ^ result) > 0)
+ {
+ if ((L_sum ^ L_product) < 0)
+ {
+ L_sum = (L_product < 0) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+ return (L_sum);
+
+ }
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: mult
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the add operation resulted in overflow
+
+ Returns:
+ product = 16-bit limited product of var1 and var2 (Word16)
+ */
+ static inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 product;
+
+ product = ((Word32) var1 * var2) >> 15;
+
+ /* Saturate result (if necessary). */
+ /* var1 * var2 >0x00007fff is the only case */
+ /* that saturation occurs. */
+
+ if (product > 0x00007fffL)
+ {
+ *pOverflow = 1;
+ product = (Word32) MAX_16;
+ }
+
+
+ /* Return the product as a 16 bit value by type casting Word32 to Word16 */
+
+ return ((Word16) product);
+ }
+
+
+ static inline Word32 amrnb_fxp_mac_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
+ {
+ Word32 result;
+
+ result = L_var3 + L_var1 * L_var2;
+
+ return result;
+ }
+
+ static inline Word32 amrnb_fxp_msu_16_by_16bb(Word32 L_var1, Word32 L_var2, Word32 L_var3)
+ {
+ Word32 result;
+
+ result = L_var3 - L_var1 * L_var2;
+
+ return result;
+ }
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BASIC_OP_C_EQUIVALENT_H */
+
+
+
diff --git a/media/codecs/amrnb/common/include/basicop_malloc.h b/media/codecs/amrnb/common/include/basicop_malloc.h
new file mode 100644
index 0000000..363d148
--- /dev/null
+++ b/media/codecs/amrnb/common/include/basicop_malloc.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/basicop_malloc.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains constant definitions and external references to the stores
+ used by any arithmetic function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef BASICOP_MALLOC_H
+#define BASICOP_MALLOC_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define MAX_32 (Word32)0x7fffffffL
+#define MIN_32 (Word32)0x80000000L
+
+#define MAX_16 (Word16)0x7fff
+#define MIN_16 (Word16)0x8000
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern Flag Overflow;
+ extern Flag Carry;
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/bitno_tab.h b/media/codecs/amrnb/common/include/bitno_tab.h
new file mode 100644
index 0000000..a170750
--- /dev/null
+++ b/media/codecs/amrnb/common/include/bitno_tab.h
@@ -0,0 +1,146 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/include/bitno_tab.h
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Define "const Word16 *bitno[N_MODES]" as "const Word16 *const
+ bitno[N_MODES]"
+
+ Description: Added #ifdef __cplusplus after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares a tables in bitno_tab.c.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef BITNO_TAB_H
+#define BITNO_TAB_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define BIT_0 0
+#define BIT_1 1
+
+#define PRMNO_MR475 17
+#define PRMNO_MR515 19
+#define PRMNO_MR59 19
+#define PRMNO_MR67 19
+#define PRMNO_MR74 19
+#define PRMNO_MR795 23
+#define PRMNO_MR102 39
+#define PRMNO_MR122 57
+#define PRMNO_MRDTX 5
+
+ /* number of parameters to first subframe */
+#define PRMNOFSF_MR475 7
+#define PRMNOFSF_MR515 7
+#define PRMNOFSF_MR59 7
+#define PRMNOFSF_MR67 7
+#define PRMNOFSF_MR74 7
+#define PRMNOFSF_MR795 8
+#define PRMNOFSF_MR102 12
+#define PRMNOFSF_MR122 18
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 prmno[];
+ extern const Word16 prmnofsf[];
+ extern const Word16 bitno_MR475[];
+ extern const Word16 bitno_MR515[];
+ extern const Word16 bitno_MR59[];
+ extern const Word16 bitno_MR67[];
+ extern const Word16 bitno_MR74[];
+ extern const Word16 bitno_MR95[];
+ extern const Word16 bitno_MR102[];
+ extern const Word16 bitno_MR122[];
+ extern const Word16 bitno_MRDTX[];
+ extern const Word16 *const bitno[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/bitreorder_tab.h b/media/codecs/amrnb/common/include/bitreorder_tab.h
new file mode 100644
index 0000000..bfcb4cf
--- /dev/null
+++ b/media/codecs/amrnb/common/include/bitreorder_tab.h
@@ -0,0 +1,125 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/include/bitreorder.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Define "const Word16 *reorderBits[NUM_MODES-1]" as
+ "const Word16 *const reorderBits[NUM_MODES-1]".
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares a tables in bitreorder.c.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef BITREORDER_H
+#define BITREORDER_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 numOfBits[];
+ extern const Word16 reorderBits_MR475[];
+ extern const Word16 reorderBits_MR515[];
+ extern const Word16 reorderBits_MR59[];
+ extern const Word16 reorderBits_MR67[];
+ extern const Word16 reorderBits_MR74[];
+ extern const Word16 reorderBits_MR795[];
+ extern const Word16 reorderBits_MR102[];
+ extern const Word16 reorderBits_MR122[];
+
+ extern const Word16 *const reorderBits[];
+ extern const Word16 numCompressedBytes[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/bits2prm.h b/media/codecs/amrnb/common/include/bits2prm.h
new file mode 100644
index 0000000..6a11bb4
--- /dev/null
+++ b/media/codecs/amrnb/common/include/bits2prm.h
@@ -0,0 +1,91 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+*****************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+*****************************************************************************
+*
+* File : bits2prm.h
+* Purpose : Retrieves the vector of encoder parameters from
+* : the received serial bits in a frame.
+*
+*****************************************************************************
+*/
+#ifndef bits2prm_h
+#define bits2prm_h "$Id $"
+
+/*
+*****************************************************************************
+* INCLUDE FILES
+*****************************************************************************
+*/
+#include "typedef.h"
+#include "mode.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ *****************************************************************************
+ * DEFINITION OF DATA TYPES
+ *****************************************************************************
+ */
+
+ /*
+ *****************************************************************************
+ * DECLARATION OF PROTOTYPES
+ *****************************************************************************
+ */
+ /*
+ **************************************************************************
+ *
+ * Function : Bits2prm
+ * Purpose : Retrieves the vector of encoder parameters from
+ * the received serial bits in a frame.
+ * Returns : void
+ *
+ **************************************************************************
+ */
+ OSCL_IMPORT_REF void Bits2prm(
+ enum Mode mode,
+ Word16 bits[], /* input : serial bits, (244 + bfi) */
+ Word16 prm[] /* output: analysis parameters, (57+1 parameters) */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/cnst.h b/media/codecs/amrnb/common/include/cnst.h
new file mode 100644
index 0000000..b648eb7
--- /dev/null
+++ b/media/codecs/amrnb/common/include/cnst.h
@@ -0,0 +1,129 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ INCLUDE DESCRIPTION
+
+ This file contains the Speech code (encoder, decoder, and postfilter)
+ constant parameters.
+
+ NOTE: This file must be synchronized with /gsm-amr/asm/include/cnst.inc file.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef _CNST_H_
+#define _CNST_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define L_TOTAL 320 /* Total size of speech buffer. */
+#define L_WINDOW 240 /* Window size in LP analysis */
+#define L_FRAME 160 /* Frame size */
+#define L_FRAME_BY2 80 /* Frame size divided by 2 */
+#define L_SUBFR 40 /* Subframe size */
+#define L_CODE 40 /* codevector length */
+#define NB_TRACK 5 /* number of tracks */
+#define STEP 5 /* codebook step size */
+#define NB_TRACK_MR102 4 /* number of tracks mode mr102 */
+#define STEP_MR102 4 /* codebook step size mode mr102 */
+#define M 10 /* Order of LP filter */
+#define MP1 (M+1) /* Order of LP filter + 1 */
+#define LSF_GAP 205 /* Minimum distance between LSF after quan- */
+ /* tization; 50 Hz = 205 */
+#define LSP_PRED_FAC_MR122 21299 /* MR122 LSP prediction factor (0.65 Q15) */
+#define AZ_SIZE (4*M+4) /* Size of array of LP filters in 4 subfr.s */
+#define PIT_MIN_MR122 18 /* Minimum pitch lag (MR122 mode) */
+#define PIT_MIN 20 /* Minimum pitch lag (all other modes) */
+#define PIT_MAX 143 /* Maximum pitch lag */
+#define L_INTERPOL (10+1) /* Length of filter for interpolation */
+#define L_INTER_SRCH 4 /* Length of filter for CL LTP search */
+ /* interpolation */
+
+#define MU 26214 /* Factor for tilt compensation filter 0.8 */
+#define AGC_FAC 29491 /* Factor for automatic gain control 0.9 */
+
+#define L_NEXT 40 /* Overhead in LP analysis */
+#define SHARPMAX 13017 /* Maximum value of pitch sharpening */
+#define SHARPMIN 0 /* Minimum value of pitch sharpening */
+
+
+#define MAX_PRM_SIZE 57 /* max. num. of params */
+#define MAX_SERIAL_SIZE 244 /* max. num. of serial bits */
+
+#define GP_CLIP 15565 /* Pitch gain clipping = 0.95 */
+#define N_FRAME 7 /* old pitch gains in average calculation */
+
+#define EHF_MASK 0x0008 /* encoder homing frame pattern */
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CNST_H_ */
diff --git a/media/codecs/amrnb/common/include/cnst_vad.h b/media/codecs/amrnb/common/include/cnst_vad.h
new file mode 100644
index 0000000..6877a1b
--- /dev/null
+++ b/media/codecs/amrnb/common/include/cnst_vad.h
@@ -0,0 +1,133 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+**-------------------------------------------------------------------------**
+** **
+** GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 **
+** R99 Version 3.2.0 **
+** REL-4 Version 4.0.0 **
+** **
+**-------------------------------------------------------------------------**
+********************************************************************************
+*
+* File : cnst_vad.h
+* Purpose : Constants and definitions for VAD
+*
+********************************************************************************
+*/
+#ifndef cnst_vad_h
+#define cnst_vad_h "$Id $"
+
+#define FRAME_LEN 160 /* Length (samples) of the input frame */
+#define COMPLEN 9 /* Number of sub-bands used by VAD */
+#define INV_COMPLEN 3641 /* 1.0/COMPLEN*2^15 */
+#define LOOKAHEAD 40 /* length of the lookahead used by speech coder */
+
+#define UNITY 512 /* Scaling used with SNR calculation */
+#define UNIRSHFT 6 /* = log2(MAX_16/UNITY) */
+
+#define TONE_THR (Word16)(0.65*MAX_16) /* Threshold for tone detection */
+
+/* Constants for background spectrum update */
+#define ALPHA_UP1 (Word16)((1.0 - 0.95)*MAX_16) /* Normal update, upwards: */
+#define ALPHA_DOWN1 (Word16)((1.0 - 0.936)*MAX_16) /* Normal update, downwards */
+#define ALPHA_UP2 (Word16)((1.0 - 0.985)*MAX_16) /* Forced update, upwards */
+#define ALPHA_DOWN2 (Word16)((1.0 - 0.943)*MAX_16) /* Forced update, downwards */
+#define ALPHA3 (Word16)((1.0 - 0.95)*MAX_16) /* Update downwards */
+#define ALPHA4 (Word16)((1.0 - 0.9)*MAX_16) /* For stationary estimation */
+#define ALPHA5 (Word16)((1.0 - 0.5)*MAX_16) /* For stationary estimation */
+
+/* Constants for VAD threshold */
+#define VAD_THR_HIGH 1260 /* Highest threshold */
+#define VAD_THR_LOW 720 /* Lowest threshold */
+#define VAD_P1 0 /* Noise level for highest threshold */
+#define VAD_P2 6300 /* Noise level for lowest threshold */
+#define VAD_SLOPE (Word16)(MAX_16*(float)(VAD_THR_LOW-VAD_THR_HIGH)/(float)(VAD_P2-VAD_P1))
+
+/* Parameters for background spectrum recovery function */
+#define STAT_COUNT 20 /* threshold of stationary detection counter */
+#define STAT_COUNT_BY_2 10 /* threshold of stationary detection counter */
+#define CAD_MIN_STAT_COUNT 5 /* threshold of stationary detection counter */
+
+#define STAT_THR_LEVEL 184 /* Threshold level for stationarity detection */
+#define STAT_THR 1000 /* Threshold for stationarity detection */
+
+/* Limits for background noise estimate */
+#define NOISE_MIN 40 /* minimum */
+#define NOISE_MAX 16000 /* maximum */
+#define NOISE_INIT 150 /* initial */
+
+/* Constants for VAD hangover addition */
+#define HANG_NOISE_THR 100
+#define BURST_LEN_HIGH_NOISE 4
+#define HANG_LEN_HIGH_NOISE 7
+#define BURST_LEN_LOW_NOISE 5
+#define HANG_LEN_LOW_NOISE 4
+
+/* Thresholds for signal power */
+#define VAD_POW_LOW (Word32)15000 /* If input power is lower, */
+/* VAD is set to 0 */
+#define POW_PITCH_THR (Word32)343040 /* If input power is lower, pitch */
+/* detection is ignored */
+
+#define POW_COMPLEX_THR (Word32)15000 /* If input power is lower, complex */
+/* flags value for previous frame is un-set */
+
+
+/* Constants for the filter bank */
+#define LEVEL_SHIFT 0 /* scaling */
+#define COEFF3 13363 /* coefficient for the 3rd order filter */
+#define COEFF5_1 21955 /* 1st coefficient the for 5th order filter */
+#define COEFF5_2 6390 /* 2nd coefficient the for 5th order filter */
+
+/* Constants for pitch detection */
+#define LTHRESH 4
+#define NTHRESH 4
+
+/* Constants for complex signal VAD */
+#define CVAD_THRESH_ADAPT_HIGH (Word16)(0.6 * MAX_16) /* threshold for adapt stopping high */
+#define CVAD_THRESH_ADAPT_LOW (Word16)(0.5 * MAX_16) /* threshold for adapt stopping low */
+#define CVAD_THRESH_IN_NOISE (Word16)(0.65 * MAX_16) /* threshold going into speech on */
+/* a short term basis */
+
+#define CVAD_THRESH_HANG (Word16)(0.70 * MAX_16) /* threshold */
+#define CVAD_HANG_LIMIT (Word16)(100) /* 2 second estimation time */
+#define CVAD_HANG_LENGTH (Word16)(250) /* 5 second hangover */
+
+#define CVAD_LOWPOW_RESET (Word16) (0.40 * MAX_16) /* init in low power segment */
+#define CVAD_MIN_CORR (Word16) (0.40 * MAX_16) /* lowest adaptation value */
+
+#define CVAD_BURST 20 /* speech burst length for speech reset */
+#define CVAD_ADAPT_SLOW (Word16)(( 1.0 - 0.98) * MAX_16) /* threshold for slow adaption */
+#define CVAD_ADAPT_FAST (Word16)((1.0 - 0.92) * MAX_16) /* threshold for fast adaption */
+#define CVAD_ADAPT_REALLY_FAST (Word16)((1.0 - 0.80) * MAX_16) /* threshold for really fast */
+/* adaption */
+
+#endif
diff --git a/media/codecs/amrnb/common/include/copy.h b/media/codecs/amrnb/common/include/copy.h
new file mode 100644
index 0000000..b539ebb
--- /dev/null
+++ b/media/codecs/amrnb/common/include/copy.h
@@ -0,0 +1,88 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+* File : copy.h
+* Purpose : Copy vector x[] to y[]
+*
+********************************************************************************
+*/
+#ifndef copy_h
+#define copy_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+
+ /*
+ **************************************************************************
+ *
+ * Function : Copy
+ * Purpose : Copy vector x[] to y[], vector length L
+ * Returns : void
+ *
+ **************************************************************************
+ */
+ void Copy(
+ const Word16 x[], /* i : input vector (L) */
+ Word16 y[], /* o : output vector (L) */
+ Word16 L /* i : vector length */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/d_gain_c.h b/media/codecs/amrnb/common/include/d_gain_c.h
new file mode 100644
index 0000000..70868f4
--- /dev/null
+++ b/media/codecs/amrnb/common/include/d_gain_c.h
@@ -0,0 +1,125 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/include/d_gain_c.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : d_gain_c.h
+ Purpose : Decode the fixed codebook gain using the received index.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _D_GAIN_C_H_
+#define _D_GAIN_C_H_
+#define d_gain_c_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "gc_pred.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /*
+ * Function : d_gain_code
+ * Purpose : Decode the fixed codebook gain using the received index.
+ * Description : The received index gives the gain correction factor
+ * gamma. The quantized gain is given by g_q = g0 * gamma
+ * where g0 is the predicted gain. To find g0, 4th order
+ * MA prediction is applied to the mean-removed innovation
+ * energy in dB.
+ * Returns : void
+ */
+ void d_gain_code(
+ gc_predState *pred_state, /* i/o : MA predictor state */
+ enum Mode mode, /* i : AMR mode */
+ Word16 index, /* i : received quantization index */
+ Word16 code[], /* i : innovation codevector */
+ Word16 *gain_code, /* o : decoded innovation gain */
+ Flag *pOverflow
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _D_GAIN_C_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/d_gain_p.h b/media/codecs/amrnb/common/include/d_gain_p.h
new file mode 100644
index 0000000..fec072b
--- /dev/null
+++ b/media/codecs/amrnb/common/include/d_gain_p.h
@@ -0,0 +1,80 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : d_gain_p.h
+* Purpose : Decodes the pitch gain using the received index.
+*
+********************************************************************************
+*/
+#ifndef d_gain_p_h
+#define d_gain_p_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "mode.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ **************************************************************************
+ *
+ * Function : d_gain_pitch
+ * Purpose : Decodes the pitch gain using the received index.
+ * Description : In case of no frame erasure, the gain is obtained
+ * from the quantization table at the given index;
+ * otherwise, a downscaled past gain is used.
+ * Returns : Quantized pitch gain
+ *
+ **************************************************************************
+ */
+ Word16 d_gain_pitch( /* return value: gain (Q14) */
+ enum Mode mode, /* i : AMR mode */
+ Word16 index /* i : index of quantization */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/d_plsf.h b/media/codecs/amrnb/common/include/d_plsf.h
new file mode 100644
index 0000000..0e5ca9a
--- /dev/null
+++ b/media/codecs/amrnb/common/include/d_plsf.h
@@ -0,0 +1,199 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/d_plsf.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the d_plsf_3.c and d_plsf_5.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef d_plsf_h
+#define d_plsf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 past_r_q[M]; /* Past quantized prediction error, Q15 */
+ Word16 past_lsf_q[M]; /* Past dequantized lsfs, Q15 */
+ } D_plsfState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*
+ **************************************************************************
+ *
+ * Function : D_plsf_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ *
+ **************************************************************************
+ */
+ Word16 D_plsf_reset(D_plsfState *st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : D_plsf_exit
+ * Purpose : The memory used for state memory is freed
+ * Description : Stores NULL in *st
+ * Returns : void
+ *
+ **************************************************************************
+ */
+ void D_plsf_exit(D_plsfState **st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : D_plsf_5
+ * Purpose : Decodes the 2 sets of LSP parameters in a frame
+ * using the received quantization indices.
+ * Description : The two sets of LSFs are quantized using split by
+ * 5 matrix quantization (split-MQ) with 1st order MA
+ * prediction.
+ * See "q_plsf_5.c" for more details about the
+ * quantization procedure
+ * Returns : 0
+ *
+ **************************************************************************
+ */
+ void D_plsf_5(
+ D_plsfState *st, /* i/o: State variables */
+ Word16 bfi, /* i : bad frame indicator (set to 1 if a bad
+ frame is received) */
+ Word16 *indice, /* i : quantization indices of 5 submatrices, Q0 */
+ Word16 *lsp1_q, /* o : quantized 1st LSP vector (M) Q15 */
+ Word16 *lsp2_q, /* o : quantized 2nd LSP vector (M) Q15 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*************************************************************************
+ *
+ * FUNCTION: D_plsf_3()
+ *
+ * PURPOSE: Decodes the LSP parameters using the received quantization
+ * indices.1st order MA prediction and split by 3 matrix
+ * quantization (split-MQ)
+ *
+ *************************************************************************/
+
+ void D_plsf_3(
+ D_plsfState *st, /* i/o: State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 bfi, /* i : bad frame indicator (set to 1 if a */
+ /* bad frame is received) */
+ Word16 * indice, /* i : quantization indices of 3 submatrices, Q0 */
+ Word16 * lsp1_q, /* o : quantized 1st LSP vector, Q15 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*************************************************************************
+ *
+ * FUNCTION: Init_D_plsf_3()
+ *
+ * PURPOSE: Set the past_r_q[M] vector to one of the eight
+ * past_rq_init vectors.
+ *
+ *************************************************************************/
+ void Init_D_plsf_3(D_plsfState *st, /* i/o: State struct */
+ Word16 index /* i : past_rq_init[] index [0, 7] */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _Q_PLSF_H_ */
+
diff --git a/media/codecs/amrnb/common/include/div_32.h b/media/codecs/amrnb/common/include/div_32.h
new file mode 100644
index 0000000..28b726b
--- /dev/null
+++ b/media/codecs/amrnb/common/include/div_32.h
@@ -0,0 +1,116 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/div_32.h
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the Div_32 function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef DIV_32_H
+#define DIV_32_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 Div_32(Word32 L_num,
+ Word16 L_denom_hi,
+ Word16 L_denom_lo,
+ Flag *pOverflow) ;
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _DIV_32_H_ */
diff --git a/media/codecs/amrnb/common/include/div_s.h b/media/codecs/amrnb/common/include/div_s.h
new file mode 100644
index 0000000..e8421db
--- /dev/null
+++ b/media/codecs/amrnb/common/include/div_s.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/div_s.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for div_s function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the div_s function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef DIV_S_H
+#define DIV_S_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 div_s(Word16 var1, Word16 var2);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/dtx_common_def.h b/media/codecs/amrnb/common/include/dtx_common_def.h
new file mode 100644
index 0000000..c29b9e1
--- /dev/null
+++ b/media/codecs/amrnb/common/include/dtx_common_def.h
@@ -0,0 +1,103 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/dtx_common_def.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : dtx_common_def.h
+ Purpose : DTX definitions common to encoder and decoder
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef DTX_COMMON_DEF_H
+#define DTX_COMMON_DEF_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define DTX_MAX_EMPTY_THRESH 50
+#define DTX_HIST_SIZE 8
+#define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1)
+#define DTX_HANG_CONST 7 /* yields eight frames of SP HANGOVER */
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DTX_COMMON_DEF_H */
+
diff --git a/media/codecs/amrnb/common/include/extract_h.h b/media/codecs/amrnb/common/include/extract_h.h
new file mode 100644
index 0000000..34a623f
--- /dev/null
+++ b/media/codecs/amrnb/common/include/extract_h.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/extract_h.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for extract_h function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the extract_h function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef EXTRACT_H_H
+#define EXTRACT_H_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 extract_h(Word32 L_var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/extract_l.h b/media/codecs/amrnb/common/include/extract_l.h
new file mode 100644
index 0000000..ed7460d
--- /dev/null
+++ b/media/codecs/amrnb/common/include/extract_l.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/extract_l.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for extract_l function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the extract_l function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef EXTRACT_L_H
+#define EXTRACT_L_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 extract_l(Word32 L_var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/frame.h b/media/codecs/amrnb/common/include/frame.h
new file mode 100644
index 0000000..1d0c6c1
--- /dev/null
+++ b/media/codecs/amrnb/common/include/frame.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+*****************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+*****************************************************************************
+*
+* File : frame.h
+* Purpose : Declaration of received and transmitted frame types
+*
+*****************************************************************************
+*/
+#ifndef frame_h
+#define frame_h "$Id $"
+
+/*
+*****************************************************************************
+* INCLUDE FILES
+*****************************************************************************
+*/
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ *****************************************************************************
+ * DEFINITION OF DATA TYPES
+ *****************************************************************************
+ * Note: The order of the TX and RX_Type identifiers has been chosen in
+ * the way below to be compatible to an earlier version of the
+ * AMR-NB C reference program.
+ *****************************************************************************
+ */
+
+ enum RXFrameType { RX_SPEECH_GOOD = 0,
+ RX_SPEECH_DEGRADED,
+ RX_ONSET,
+ RX_SPEECH_BAD,
+ RX_SID_FIRST,
+ RX_SID_UPDATE,
+ RX_SID_BAD,
+ RX_NO_DATA,
+ RX_N_FRAMETYPES /* number of frame types */
+ };
+
+ enum TXFrameType { TX_SPEECH_GOOD = 0,
+ TX_SID_FIRST,
+ TX_SID_UPDATE,
+ TX_NO_DATA,
+ TX_SPEECH_DEGRADED,
+ TX_SPEECH_BAD,
+ TX_SID_BAD,
+ TX_ONSET,
+ TX_N_FRAMETYPES /* number of frame types */
+ };
+
+
+ /* Channel decoded frame type */
+ enum CHDECFrameType { CHDEC_SID_FIRST = 0,
+ CHDEC_SID_FIRST_INCOMPLETE,
+ CHDEC_SID_UPDATE_INCOMPLETE,
+ CHDEC_SID_UPDATE,
+ CHDEC_SPEECH,
+ CHDEC_SPEECH_ONSET,
+ CHDEC_ESCAPE_MARKER,
+ CHDEC_ESCAPE_DATA,
+ CHDEC_NO_DATA
+ };
+
+ /* Channel decoded frame quality */
+ enum CHDECFrameQuality { CHDEC_GOOD = 0,
+ CHDEC_PROBABLY_DEGRADED,
+ CHDEC_PROBABLY_BAD,
+ CHDEC_BAD
+ };
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/frame_type_3gpp.h b/media/codecs/amrnb/common/include/frame_type_3gpp.h
new file mode 100644
index 0000000..3d482be
--- /dev/null
+++ b/media/codecs/amrnb/common/include/frame_type_3gpp.h
@@ -0,0 +1,151 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/include/frame_type_3gpp.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated to new PV C header template.
+
+ Description: Added #ifdef __cplusplus after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the definition of the 3GPP frame types.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef FRAME_TYPE_3GPP_H
+#define FRAME_TYPE_3GPP_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ enum Frame_Type_3GPP
+ {
+ AMR_475 = 0, /* 4.75 kbps */
+ AMR_515, /* 5.15 kbps */
+ AMR_59, /* 5.9 kbps */
+ AMR_67, /* 6.7 kbps */
+ AMR_74, /* 7.4 kbps */
+ AMR_795, /* 7.95 kbps */
+ AMR_102, /* 10.2 kbps */
+ AMR_122, /* 12.2 kbps */
+ AMR_SID, /* GSM AMR DTX */
+ GSM_EFR_SID, /* GSM EFR DTX */
+ TDMA_EFR_SID, /* TDMA EFR DTX */
+ PDC_EFR_SID, /* PDC EFR DTX */
+ FOR_FUTURE_USE1, /* Unused 1 */
+ FOR_FUTURE_USE2, /* Unused 2 */
+ FOR_FUTURE_USE3, /* Unused 3 */
+ AMR_NO_DATA /* No data */
+ };
+
+typedef enum
+{
+ /*
+ * One word (2-byte) to indicate type of frame type.
+ * One word (2-byte) to indicate frame type.
+ * One word (2-byte) to indicate mode.
+ * N words (2-byte) containing N bits (bit 0 = 0xff81, bit 1 = 0x007f).
+ */
+ ETS = 0, /* Both AMR-Narrowband and AMR-Wideband */
+
+ /*
+ * One word (2-byte) for sync word (good frames: 0x6b21, bad frames: 0x6b20)
+ * One word (2-byte) for frame length N.
+ * N words (2-byte) containing N bits (bit 0 = 0x007f, bit 1 = 0x0081).
+ */
+ ITU, /* AMR-Wideband */
+
+ /*
+ * AMR-WB MIME/storage format, see RFC 3267 (sections 5.1 and 5.3) for details
+ */
+ MIME_IETF,
+
+ WMF, /* AMR-Narrowband */
+
+ IF2 /* AMR-Narrowband */
+
+} bitstream_format;
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _FRAME_TYPE_3GPP_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/gc_pred.h b/media/codecs/amrnb/common/include/gc_pred.h
new file mode 100644
index 0000000..b82603c
--- /dev/null
+++ b/media/codecs/amrnb/common/include/gc_pred.h
@@ -0,0 +1,176 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/include/gc_pred.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : gc_pred.h
+ Purpose : codebook gain MA prediction
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _GC_PRED_H_
+#define _GC_PRED_H_
+#define gc_pred_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 past_qua_en[4]; /* normal MA predictor memory, Q10 */
+ /* (contains 20*log10(qua_err)) */
+ Word16 past_qua_en_MR122[4]; /* MA predictor memory for MR122 mode, Q10 */
+ /* (contains log2(qua_err)) */
+ } gc_predState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ Word16 gc_pred_reset(gc_predState *st);
+ /* reset of codebook gain MA predictor state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void gc_pred_exit(gc_predState **st);
+ /* de-initialize codebook gain MA predictor state (i.e. free state struct)
+ stores NULL in *st
+ */
+
+ void
+ gc_pred_copy(
+ gc_predState *st_src, /* i : State struct */
+ gc_predState *st_dest /* o : State struct */
+ );
+
+ /*
+ * FUNCTION: gc_pred()
+ * PURPOSE: MA prediction of the innovation energy
+ * (in dB/(20*log10(2))) with mean removed).
+ */
+ void gc_pred(
+ gc_predState *st, /* i/o: State struct */
+ enum Mode mode, /* i : AMR mode */
+ Word16 *code, /* i : innovative codebook vector (L_SUBFR) */
+ /* MR122: Q12, other modes: Q13 */
+ Word16 *exp_gcode0, /* o : exponent of predicted gain factor, Q0 */
+ Word16 *frac_gcode0,/* o : fraction of predicted gain factor Q15 */
+ Word16 *exp_en, /* o : exponent of innovation energy, Q0 */
+ /* (only calculated for MR795) */
+ Word16 *frac_en, /* o : fraction of innovation energy, Q15 */
+ /* (only calculated for MR795) */
+ Flag *pOverflow
+ );
+
+ /*
+ * FUNCTION: gc_pred_update()
+ * PURPOSE: update MA predictor with last quantized energy
+ */
+ void gc_pred_update(
+ gc_predState *st, /* i/o: State struct */
+ Word16 qua_ener_MR122, /* i : quantized energy for update, Q10 */
+ /* (log2(qua_err)) */
+ Word16 qua_ener /* i : quantized energy for update, Q10 */
+ /* (20*log10(qua_err)) */
+ );
+
+ /*
+ * FUNCTION: gc_pred_average_limited()
+ * PURPOSE: get average of MA predictor state values (with a lower limit)
+ * [used in error concealment]
+ */
+ void gc_pred_average_limited(
+ gc_predState *st, /* i: State struct */
+ Word16 *ener_avg_MR122, /* o: averaged quantized energy, Q10 */
+ /* (log2(qua_err)) */
+ Word16 *ener_avg, /* o: averaged quantized energy, Q10 */
+ /* (20*log10(qua_err)) */
+ Flag *pOverflow
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GC_PRED_H_ */
+
+
+
diff --git a/media/codecs/amrnb/common/include/gmed_n.h b/media/codecs/amrnb/common/include/gmed_n.h
new file mode 100644
index 0000000..1c4ede2
--- /dev/null
+++ b/media/codecs/amrnb/common/include/gmed_n.h
@@ -0,0 +1,80 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : gmed_n.h
+* Purpose : calculates N-point median.
+*
+********************************************************************************
+*/
+#ifndef gmed_n_h
+#define gmed_n_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ Word16 gmed_n( /* o : index of the median value (0...N-1) */
+ Word16 ind[], /* i : Past gain values */
+ Word16 n /* i : The number of gains; this routine */
+ /* is only valid for a odd number of gains */
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/gsm_amr_typedefs.h b/media/codecs/amrnb/common/include/gsm_amr_typedefs.h
new file mode 100644
index 0000000..4abcbbd
--- /dev/null
+++ b/media/codecs/amrnb/common/include/gsm_amr_typedefs.h
@@ -0,0 +1,133 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: codecs/audio/gsm_amr/gsm_two_way/c/include/gsm_amr_typedefs.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Removed unused defintions and corrected ifdef, that depended on
+ incorrect typedef
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the definition of the amr codec types.
+
+------------------------------------------------------------------------------
+*/
+#ifndef GSM_AMR_TYPEDEFS_H
+#define GSM_AMR_TYPEDEFS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include <stdint.h>
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+typedef int8_t Word8;
+typedef uint8_t UWord8;
+
+
+/*----------------------------------------------------------------------------
+; Define 16 bit signed and unsigned words
+----------------------------------------------------------------------------*/
+
+typedef int16_t Word16;
+typedef uint16_t UWord16;
+
+/*----------------------------------------------------------------------------
+; Define 32 bit signed and unsigned words
+----------------------------------------------------------------------------*/
+
+typedef int32_t Word32;
+typedef uint32_t UWord32;
+
+
+/*----------------------------------------------------------------------------
+; Define boolean type
+----------------------------------------------------------------------------*/
+typedef int Bool;
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef OFF
+#define OFF 0
+#endif
+
+#ifndef ON
+#define ON 1
+#endif
+
+#ifndef NO
+#define NO 0
+#endif
+
+#ifndef YES
+#define YES 1
+#endif
+
+#ifndef SUCCESS
+#define SUCCESS 0
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+typedef int32_t Flag;
+
+#endif /* GSM_AMR_TYPEDEFS_H */
diff --git a/media/codecs/amrnb/common/include/int_lpc.h b/media/codecs/amrnb/common/include/int_lpc.h
new file mode 100644
index 0000000..e95e6ca
--- /dev/null
+++ b/media/codecs/amrnb/common/include/int_lpc.h
@@ -0,0 +1,212 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/lsp_avg.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the lsp_avg.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef int_lpc_h
+#define int_lpc_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*
+ **************************************************************************
+ *
+ * Function : Int_lpc_1and3
+ * Purpose : Interpolates the LSPs and converts to LPC parameters
+ * to get a different LP filter in each subframe.
+ * Description : The 20 ms speech frame is divided into 4 subframes.
+ * The LSPs are quantized and transmitted at the 2nd and
+ * 4th subframes (twice per frame) and interpolated at the
+ * 1st and 3rd subframe.
+ *
+ * |------|------|------|------|
+ * sf1 sf2 sf3 sf4
+ * F0 Fm F1
+ *
+ * sf1: 1/2 Fm + 1/2 F0 sf3: 1/2 F1 + 1/2 Fm
+ * sf2: Fm sf4: F1
+ * Returns : void
+ *
+ **************************************************************************
+ */
+ void Int_lpc_1and3(
+ Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */
+ Word16 lsp_mid[], /* i : LSP vector at the 2nd subfr. of
+ present frame (M) */
+ Word16 lsp_new[], /* i : LSP vector at the 4th subfr. of
+ present frame (M) */
+ Word16 Az[], /* o : interpolated LP parameters in all subfr.
+ (AZ_SIZE) */
+ Flag *pOverflow
+ );
+
+ /*
+ **************************************************************************
+ *
+ * Function : Int_lpc_1and3_2
+ * Purpose : Interpolation of the LPC parameters. Same as the Int_lpc
+ * function but we do not recompute Az() for subframe 2 and
+ * 4 because it is already available.
+ * Returns : void
+ *
+ **************************************************************************
+ */
+ void Int_lpc_1and3_2(
+ Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */
+ Word16 lsp_mid[], /* i : LSP vector at the 2nd subframe of
+ present frame (M) */
+ Word16 lsp_new[], /* i : LSP vector at the 4th subframe of
+ present frame (M) */
+ Word16 Az[], /* o :interpolated LP parameters
+ in subframes 1 and 3 (AZ_SIZE) */
+ Flag *pOverflow
+ );
+
+ /*
+ **************************************************************************
+ *
+ * Function : Int_lpc_1to3
+ * Purpose : Interpolates the LSPs and converts to LPC parameters
+ * to get a different LP filter in each subframe.
+ * Description : The 20 ms speech frame is divided into 4 subframes.
+ * The LSPs are quantized and transmitted at the 4th
+ * subframes (once per frame) and interpolated at the
+ * 1st, 2nd and 3rd subframe.
+ *
+ * |------|------|------|------|
+ * sf1 sf2 sf3 sf4
+ * F0 F1
+ *
+ * sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1
+ * sf2: 1/2 F0 + 1/2 F1 sf4: F1
+ * Returns : void
+ *
+ **************************************************************************
+ */
+ void Int_lpc_1to3(
+ Word16 lsp_old[], /* i : LSP vector at the 4th SF of past frame (M) */
+ Word16 lsp_new[], /* i : LSP vector at the 4th SF of present frame (M) */
+ Word16 Az[], /* o : interpolated LP parameters in all SFs (AZ_SIZE) */
+ Flag *pOverflow
+ );
+
+ /*
+ **************************************************************************
+ *
+ * Function : Int_lpc_1to3_2
+ * Purpose : Interpolation of the LPC parameters. Same as the Int_lpc
+ * function but we do not recompute Az() for subframe 4
+ * because it is already available.
+ * Returns : void
+ *
+ **************************************************************************
+ */
+ void Int_lpc_1to3_2(
+ Word16 lsp_old[], /* i : LSP vector at the 4th SF of past frame (M) */
+ Word16 lsp_new[], /* i : LSP vector at the 4th SF present frame (M) */
+ Word16 Az[], /* o :interpolated LP parameters in SFs 1, 2, 3
+ (AZ_SIZE) */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _INT_LPC_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/int_lsf.h b/media/codecs/amrnb/common/include/int_lsf.h
new file mode 100644
index 0000000..4e02ae6
--- /dev/null
+++ b/media/codecs/amrnb/common/include/int_lsf.h
@@ -0,0 +1,113 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/int_lsf.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the int_lsf function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef int_lsf_h
+#define int_lsf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Int_lsf(
+ Word16 lsf_old[], /* i : LSF vector at the 4th SF of past frame */
+ Word16 lsf_new[], /* i : LSF vector at the 4th SF of present frame */
+ Word16 i_subfr, /* i : Current sf (equal to 0,40,80 or 120) */
+ Word16 lsf_out[], /* o : interpolated LSF parameters for current sf */
+ Flag *pOverflow /* o : flag set if overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _INT_LSF_H_ */
diff --git a/media/codecs/amrnb/common/include/inv_sqrt.h b/media/codecs/amrnb/common/include/inv_sqrt.h
new file mode 100644
index 0000000..91ab3e4
--- /dev/null
+++ b/media/codecs/amrnb/common/include/inv_sqrt.h
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/inv_sqrt.h
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Added an extern declaration for inv_sqrt_tbl[], now defined in
+ the file inv_sqrt_tbl.c
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the inv_sqrt() function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef INV_SQRT_H
+#define INV_SQRT_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 inv_sqrt_tbl[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 Inv_sqrt( /* (o) : output value */
+ Word32 L_x, /* (i) : input value */
+ Flag *pOverflow /* (i) : pointer to overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _INV_SQRT_H_ */
+
diff --git a/media/codecs/amrnb/common/include/l_abs.h b/media/codecs/amrnb/common/include/l_abs.h
new file mode 100644
index 0000000..db57b82
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_abs.h
@@ -0,0 +1,111 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/l_abs.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_abs function.
+
+ Description: Moved _cplusplus #ifdef after Include section..
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_abs function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_ABS_H
+#define L_ABS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_abs(Word32 L_var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/l_add.h b/media/codecs/amrnb/common/include/l_add.h
new file mode 100644
index 0000000..136b914
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_add.h
@@ -0,0 +1,171 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/l_add.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_add function.
+
+ Description: Changed function prototype declaration. A pointer to the overflow
+ flag is being passed in as a parameter instead of using global
+ data.
+
+ Description: Updated template. Changed paramter name from overflow to
+ pOverflow
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Providing support for ARM and Linux-ARM assembly instructions.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_add function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_ADD_H
+#define L_ADD_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
+
+ __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
+ {
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+ __asm
+ {
+ QADD result, L_var1, L_var2
+ }
+ return(result);
+ }
+
+#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
+
+ __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
+ {
+ register Word32 ra = L_var1;
+ register Word32 rb = L_var2;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("qadd %0, %1, %2"
+ : "=r"(result)
+ : "r"(ra), "r"(rb)
+ );
+ return (result);
+
+ }
+
+#else /* C EQUIVALENT */
+
+
+ static inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
+ {
+ Word32 L_sum;
+
+ L_sum = L_var1 + L_var2;
+
+ if ((L_var1 ^ L_var2) >= 0)
+ {
+ if ((L_sum ^ L_var1) < 0)
+ {
+ L_sum = (L_var1 < 0) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+
+ return (L_sum);
+ }
+
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_ADD_H_ */
diff --git a/media/codecs/amrnb/common/include/l_add_c.h b/media/codecs/amrnb/common/include/l_add_c.h
new file mode 100644
index 0000000..3585a3c
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_add_c.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/l_add_c.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_add_c function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag and carry flag is passed into the
+ function. Updated template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_add_c function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_ADD_C_H
+#define L_ADD_C_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_add_c(Word32 L_var1, Word32 L_var2, Flag *pOverflow, Flag *pCarry);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_ADD_C_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/l_comp.h b/media/codecs/amrnb/common/include/l_comp.h
new file mode 100644
index 0000000..02a4bb7
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_comp.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/l_comp.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Passing in pOverflow for EPOC changes.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_comp function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_COMP_H
+#define L_COMP_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_Comp(Word16 hi, Word16 lo, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/media/codecs/amrnb/common/include/l_deposit_h.h b/media/codecs/amrnb/common/include/l_deposit_h.h
new file mode 100644
index 0000000..e58bc5f
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_deposit_h.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/l_deposit_h.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_deposit_h function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_deposit_h function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_DEPOSIT_H_H
+#define L_DEPOSIT_H_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_deposit_h(Word16 var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/l_deposit_l.h b/media/codecs/amrnb/common/include/l_deposit_l.h
new file mode 100644
index 0000000..09fabfd
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_deposit_l.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/l_deposit_l.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_deposit_l function.
+
+ Description: Updated template to make it build for Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_deposit_l function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_DEPOSIT_L_H
+#define L_DEPOSIT_L_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_deposit_l(Word16 var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/l_extract.h b/media/codecs/amrnb/common/include/l_extract.h
new file mode 100644
index 0000000..fdbe351
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_extract.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/l_extract.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_extract function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_EXTRACT_H
+#define L_EXTRACT_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void L_Extract(Word32 L_var,
+ Word16 *pL_var_hi,
+ Word16 *pL_var_lo,
+ Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_EXTRACT_H_ */
diff --git a/media/codecs/amrnb/common/include/l_mac.h b/media/codecs/amrnb/common/include/l_mac.h
new file mode 100644
index 0000000..b4af3aa
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_mac.h
@@ -0,0 +1,183 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/l_mac.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_mac function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: 1. Updated the function to include ARM and Linux-ARM assembly
+ instructions.
+ 2. Added OSCL_UNUSED_ARG(pOverflow) to remove compiler warnings.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_mac function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_MAC_H
+#define L_MAC_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
+
+ __inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+ Word32 L_sum;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm {SMULBB result, var1, var2}
+ __asm {QDADD L_sum, L_var3, result}
+ return (L_sum);
+ }
+
+#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
+
+ static inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ register Word32 ra = L_var3;
+ register Word32 rb = var1;
+ register Word32 rc = var2;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(result)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(rc)
+ : "r"(ra), "r"(result)
+ );
+
+ return (rc);
+ }
+
+#else /* C_EQUIVALENT */
+
+ __inline Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+ Word32 L_sum;
+ result = (Word32) var1 * var2;
+ if (result != (Word32) 0x40000000L)
+ {
+ L_sum = (result << 1) + L_var3;
+
+ /* Check if L_sum and L_var_3 share the same sign */
+ if ((L_var3 ^ result) > 0)
+ {
+ if ((L_sum ^ L_var3) < 0)
+ {
+ L_sum = (L_var3 < 0) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_sum = MAX_32;
+ }
+ return (L_sum);
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_MAC_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/l_msu.h b/media/codecs/amrnb/common/include/l_msu.h
new file mode 100644
index 0000000..3bafb00
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_msu.h
@@ -0,0 +1,171 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/l_msu.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_msu function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Providing support for ARM and Linux-ARM assembly instructions.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_msu function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_MSU_H
+#define L_MSU_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+#include "l_mult.h"
+#include "l_sub.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
+
+ __inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 product;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ SMULBB product, var1, var2
+ QDSUB result, L_var3, product
+ }
+
+ return (result);
+ }
+
+#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
+
+ __inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ register Word32 ra = L_var3;
+ register Word32 rb = var1;
+ register Word32 rc = var2;
+ Word32 product;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("qdsub %0, %1, %2"
+ : "=r"(result)
+ : "r"(ra), "r"(product)
+ );
+
+ return (result);
+ }
+
+#else /* C EQUIVALENT */
+
+ static inline Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+
+ result = L_mult(var1, var2, pOverflow);
+ result = L_sub(L_var3, result, pOverflow);
+
+ return (result);
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_MSU_H_ */
diff --git a/media/codecs/amrnb/common/include/l_mult.h b/media/codecs/amrnb/common/include/l_mult.h
new file mode 100644
index 0000000..061df60
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_mult.h
@@ -0,0 +1,178 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/l_mult.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_mult function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Providing support for ARM and Linux-ARM assembly instructions.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_mult function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_MULT_H
+#define L_MULT_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
+
+ __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 result;
+ Word32 product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ SMULBB product, var1, var2
+ QADD result, product, product
+ }
+
+ return (result);
+ }
+
+#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
+
+ __inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ register Word32 ra = var1;
+ register Word32 rb = var2;
+ Word32 result;
+ Word32 product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product)
+ : "r"(ra), "r"(rb)
+ );
+
+ asm volatile("qadd %0, %1, %2"
+ : "=r"(result)
+ : "r"(product), "r"(product)
+ );
+
+ return(result);
+ }
+
+#else /* C EQUIVALENT */
+
+ static inline Word32 L_mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ register Word32 L_product;
+
+ L_product = (Word32) var1 * var2;
+
+ if (L_product != (Word32) 0x40000000L)
+ {
+ L_product <<= 1; /* Multiply by 2 */
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_product = MAX_32;
+ }
+
+ return (L_product);
+ }
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_MULT_H */
+
diff --git a/media/codecs/amrnb/common/include/l_negate.h b/media/codecs/amrnb/common/include/l_negate.h
new file mode 100644
index 0000000..11e14a8
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_negate.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/l_negate.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_negate function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_negate function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_NEGATE_H
+#define L_NEGATE_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_negate(Word32 L_var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/l_shl.h b/media/codecs/amrnb/common/include/l_shl.h
new file mode 100644
index 0000000..7b9fdb1
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_shl.h
@@ -0,0 +1,116 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/l_shl.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_shl function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_shl function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_SHL_H
+#define L_SHL_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_shl(Word32 L_var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_SHL_H_ */
+
+
+
diff --git a/media/codecs/amrnb/common/include/l_shr.h b/media/codecs/amrnb/common/include/l_shr.h
new file mode 100644
index 0000000..ef22073
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_shr.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/l_shr.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_shr function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_shr function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_SHR_H
+#define L_SHR_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_shr(Word32 L_var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_SHR_H_ */
+
+
+
diff --git a/media/codecs/amrnb/common/include/l_shr_r.h b/media/codecs/amrnb/common/include/l_shr_r.h
new file mode 100644
index 0000000..1a1661f
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_shr_r.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/l_shr_r.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_shr_r function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_shr_r function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_SHR_R_H
+#define L_SHR_R_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word32 L_shr_r(Word32 L_var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_SHR_R_H_ */
+
diff --git a/media/codecs/amrnb/common/include/l_sub.h b/media/codecs/amrnb/common/include/l_sub.h
new file mode 100644
index 0000000..97d7538
--- /dev/null
+++ b/media/codecs/amrnb/common/include/l_sub.h
@@ -0,0 +1,173 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/l_sub.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for L_sub function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Providing support for ARM and Linux-ARM assembly instructions.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the L_sub function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef L_SUB_H
+#define L_SUB_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
+
+ __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
+ {
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ QSUB result, L_var1, L_var2
+ }
+
+ return(result);
+
+ }
+
+#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
+
+ __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
+ {
+ register Word32 ra = L_var1;
+ register Word32 rb = L_var2;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("qsub %0, %1, %2"
+ : "=r"(result)
+ : "r"(ra), "r"(rb)
+ );
+
+ return (result);
+ }
+
+#else /* C EQUIVALENT */
+
+ static inline Word32 L_sub(register Word32 L_var1, register Word32 L_var2,
+ register Flag *pOverflow)
+ {
+ Word32 L_diff;
+
+ L_diff = L_var1 - L_var2;
+
+ if ((L_var1 ^ L_var2) < 0)
+ {
+ if ((L_diff ^ L_var1) & MIN_32)
+ {
+ L_diff = (L_var1 < 0L) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+
+ return (L_diff);
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _L_SUB_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/log2.h b/media/codecs/amrnb/common/include/log2.h
new file mode 100644
index 0000000..e589b2f
--- /dev/null
+++ b/media/codecs/amrnb/common/include/log2.h
@@ -0,0 +1,120 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/log2.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. Deleted function
+ prototype for Log2_norm and put it in its own header file.
+ Added log2_norm.h in Include section for legacy files.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section..
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the function prototype definition for Log2 function.
+
+------------------------------------------------------------------------------
+*/
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef LOG2_H
+#define LOG2_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+#include "log2_norm.h" /* Used by legacy files */
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Log2(
+ Word32 L_x, /* (i) : input value */
+ Word16 *pExponent, /* (o) : Integer part of Log2. (range: 0<=val<=30)*/
+ Word16 *pFraction, /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ Flag *pOverflow /* (i/o) : overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LOG2_H_ */
diff --git a/media/codecs/amrnb/common/include/log2_norm.h b/media/codecs/amrnb/common/include/log2_norm.h
new file mode 100644
index 0000000..46b4e4d
--- /dev/null
+++ b/media/codecs/amrnb/common/include/log2_norm.h
@@ -0,0 +1,119 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/log2_norm.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for Log2_norm function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template. Added extern declaration for log2_tbl[]
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the prototype declaration for Log2_norm function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef LOG2_NORM_H
+#define LOG2_NORM_H
+
+#define log2_h "$Id $" /* Used by legacy code */
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 log2_tbl[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Log2_norm(
+ Word32 L_x, /* (i) : input value (normalized) */
+ Word16 exp, /* (i) : norm_l (L_x) */
+ Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LOG2_NORM_H_ */
diff --git a/media/codecs/amrnb/common/include/lsfwt.h b/media/codecs/amrnb/common/include/lsfwt.h
new file mode 100644
index 0000000..d9a1f80
--- /dev/null
+++ b/media/codecs/amrnb/common/include/lsfwt.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/lsfwt.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the lsfwt.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef lsfwt_h
+#define lsfwt_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Lsf_wt(
+ Word16 *lsf, /* input : LSF vector */
+ Word16 *wf, /* output: square of weighting factors */
+ Flag * pOverflow); /* o : Flag set when overflow occurs */
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LSF_WT_H_ */
+
diff --git a/media/codecs/amrnb/common/include/lsp.h b/media/codecs/amrnb/common/include/lsp.h
new file mode 100644
index 0000000..26a4b34
--- /dev/null
+++ b/media/codecs/amrnb/common/include/lsp.h
@@ -0,0 +1,186 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/lsp.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the lsp.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef lsp_h
+#define lsp_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "q_plsf.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+
+ /* Past LSPs */
+ Word16 lsp_old[M];
+ Word16 lsp_old_q[M];
+
+ /* Quantization state */
+ Q_plsfState *qSt;
+
+ } lspState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ /*
+ **************************************************************************
+ *
+ * Function : lsp_init
+ * Purpose : Allocates memory and initializes state variables
+ * Description : Stores pointer to filter status struct in *st. This
+ * pointer has to be passed to lsp in each call.
+ * Returns : 0 on success
+ *
+ **************************************************************************
+ */
+ Word16 lsp_init(lspState **st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : lsp_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ *
+ **************************************************************************
+ */
+ Word16 lsp_reset(lspState *st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : lsp_exit
+ * Purpose : The memory used for state memory is freed
+ * Description : Stores NULL in *st
+ *
+ **************************************************************************
+ */
+ void lsp_exit(lspState **st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : lsp
+ * Purpose : Conversion from LP coefficients to LSPs.
+ * Quantization of LSPs.
+ * Description : Generates 2 sets of LSPs from 2 sets of
+ * LP coefficients for mode 12.2. For the other
+ * modes 1 set of LSPs is generated from 1 set of
+ * LP coefficients. These LSPs are quantized with
+ * Matrix/Vector quantization (depending on the mode)
+ * and interpolated for the subframes not yet having
+ * their own LSPs.
+ *
+ **************************************************************************
+ */
+ void lsp(lspState *st, /* i/o : State struct */
+ enum Mode req_mode, /* i : requested coder mode */
+ enum Mode used_mode,/* i : used coder mode */
+ Word16 az[], /* i/o : interpolated LP parameters Q12 */
+ Word16 azQ[], /* o : quantization interpol. LP parameters Q12*/
+ Word16 lsp_new[], /* o : new lsp vector */
+ Word16 **anap, /* o : analysis parameters */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LSP_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/lsp_az.h b/media/codecs/amrnb/common/include/lsp_az.h
new file mode 100644
index 0000000..ae81507
--- /dev/null
+++ b/media/codecs/amrnb/common/include/lsp_az.h
@@ -0,0 +1,111 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/lsp_az.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the lsp_az function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef LSP_AZ_H
+#define LSP_AZ_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Lsp_Az(
+ Word16 lsp[], /* (i) : line spectral frequencies */
+ Word16 a[], /* (o) : predictor coefficients (order = 10) */
+ Flag *pOverflow /* (o) : overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LSP_AZ_H_ */
diff --git a/media/codecs/amrnb/common/include/lsp_lsf.h b/media/codecs/amrnb/common/include/lsp_lsf.h
new file mode 100644
index 0000000..186b4d3
--- /dev/null
+++ b/media/codecs/amrnb/common/include/lsp_lsf.h
@@ -0,0 +1,121 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/lsp_lsf.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the lsp_lsf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef lsp_lsf_h
+#define lsp_lsf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void Lsf_lsp(
+ Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */
+ Word16 m, /* (i) : LPC order */
+ Flag *pOverflow /* (o) : Flag set when overflow occurs */
+ );
+ void Lsp_lsf(
+ Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */
+ Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 m, /* (i) : LPC order */
+ Flag *pOverflow /* (o) : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LSP_LSF_H_ */
+
diff --git a/media/codecs/amrnb/common/include/lsp_tab.h b/media/codecs/amrnb/common/include/lsp_tab.h
new file mode 100644
index 0000000..01b3317
--- /dev/null
+++ b/media/codecs/amrnb/common/include/lsp_tab.h
@@ -0,0 +1,111 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/include/lsp_tab.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares a table lsp_init_data.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef LSP_TAB_H
+#define LSP_TAB_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 lsp_init_data[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/mac_32.h b/media/codecs/amrnb/common/include/mac_32.h
new file mode 100644
index 0000000..9e9ebe1
--- /dev/null
+++ b/media/codecs/amrnb/common/include/mac_32.h
@@ -0,0 +1,150 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/mac_32.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Inlined the functions from mac_32.cpp. A performance improvement
+ change.
+
+ Who: Date:
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the Mac_32 and Mac_32_16 functions
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef MAC_32_H
+#define MAC_32_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ static inline Word32 Mac_32(Word32 L_var3,
+ Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 L_var2_hi,
+ Word16 L_var2_lo,
+ Flag *pOverflow)
+ {
+ Word16 product;
+
+ L_var3 = L_mac(L_var3, L_var1_hi, L_var2_hi, pOverflow);
+
+ product = mult(L_var1_hi, L_var2_lo, pOverflow);
+ L_var3 = L_mac(L_var3, product, 1, pOverflow);
+
+ product = mult(L_var1_lo, L_var2_hi, pOverflow);
+ L_var3 = L_mac(L_var3, product, 1, pOverflow);
+
+ return (L_var3);
+ }
+
+ static inline Word32 Mac_32_16(Word32 L_var3,
+ Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+ {
+ Word16 product;
+
+ L_var3 = L_mac(L_var3, L_var1_hi, var2, pOverflow);
+
+ product = mult(L_var1_lo, var2, pOverflow);
+ L_var3 = L_mac(L_var3, product, 1, pOverflow);
+
+ return (L_var3);
+ }
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MAC_32_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/mode.h b/media/codecs/amrnb/common/include/mode.h
new file mode 100644
index 0000000..75f86cb
--- /dev/null
+++ b/media/codecs/amrnb/common/include/mode.h
@@ -0,0 +1,82 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : mode.h
+* Purpose : Declaration of mode type
+*
+********************************************************************************
+*/
+#ifndef mode_h
+#define mode_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+ enum Mode { MR475 = 0,
+ MR515,
+ MR59,
+ MR67,
+ MR74,
+ MR795,
+ MR102,
+ MR122,
+
+ MRDTX,
+
+ N_MODES /* number of (SPC) modes */
+
+ };
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/mpy_32.h b/media/codecs/amrnb/common/include/mpy_32.h
new file mode 100644
index 0000000..03f36b2
--- /dev/null
+++ b/media/codecs/amrnb/common/include/mpy_32.h
@@ -0,0 +1,272 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/mpy_32.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Updated the function to include ARM and Linux-ARM assembly
+ instructions.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the Mpy_32 function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef MPY_32_H
+#define MPY_32_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
+
+ __inline Word32 Mpy_32(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 L_var2_hi,
+ Word16 L_var2_lo,
+ Flag *pOverflow)
+
+ {
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 product32;
+
+ OSCL_UNUSED_ARG(pOverflow);
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* L_product = L_mult (L_var1_hi, L_var2_hi, pOverflow);*/
+
+ __asm {SMULBB L_product, L_var1_hi, L_var2_hi}
+ __asm {QDADD L_product, 0, L_product}
+ __asm {SMULBB product32, L_var1_hi, L_var2_lo}
+ product32 >>= 15;
+ __asm {QDADD L_sum, L_product, product32}
+ L_product = L_sum;
+ __asm {SMULBB product32, L_var1_lo, L_var2_hi}
+ product32 >>= 15;
+ __asm {QDADD L_sum, L_product, product32}
+ return (L_sum);
+ }
+
+#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
+
+ static inline Word32 Mpy_32(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 L_var2_hi,
+ Word16 L_var2_lo,
+ Flag *pOverflow)
+ {
+ register Word32 product32;
+ register Word32 L_sum;
+ register Word32 L_product, result;
+ register Word32 ra = L_var1_hi;
+ register Word32 rb = L_var1_lo;
+ register Word32 rc = L_var2_hi;
+ register Word32 rd = L_var2_lo;
+
+
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(ra), "r"(rc)
+ );
+ asm volatile("mov %0, #0"
+ : "=r"(result)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_sum)
+ : "r"(result), "r"(L_product)
+ );
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product32)
+ : "r"(ra), "r"(rd)
+ );
+
+ asm volatile("mov %0, %1, ASR #15"
+ : "=r"(ra)
+ : "r"(product32)
+ );
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(L_sum), "r"(ra)
+ );
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product32)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("mov %0, %1, ASR #15"
+ : "=r"(rb)
+ : "r"(product32)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_sum)
+ : "r"(L_product), "r"(rb)
+ );
+
+ return (L_sum);
+ }
+
+#else /* C_EQUIVALENT */
+
+ __inline Word32 Mpy_32(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 L_var2_hi,
+ Word16 L_var2_lo,
+ Flag *pOverflow)
+ {
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 product32;
+
+ OSCL_UNUSED_ARG(pOverflow);
+ L_product = (Word32) L_var1_hi * L_var2_hi;
+
+ if (L_product != (Word32) 0x40000000L)
+ {
+ L_product <<= 1;
+ }
+ else
+ {
+ L_product = MAX_32;
+ }
+
+ /* result = mult (L_var1_hi, L_var2_lo, pOverflow); */
+ product32 = ((Word32) L_var1_hi * L_var2_lo) >> 15;
+
+ /* L_product = L_mac (L_product, result, 1, pOverflow); */
+ L_sum = L_product + (product32 << 1);
+
+ if ((L_product ^ product32) > 0)
+ {
+ if ((L_sum ^ L_product) < 0)
+ {
+ L_sum = (L_product < 0) ? MIN_32 : MAX_32;
+ }
+ }
+
+ L_product = L_sum;
+
+ /* result = mult (L_var1_lo, L_var2_hi, pOverflow); */
+ product32 = ((Word32) L_var1_lo * L_var2_hi) >> 15;
+
+ /* L_product = L_mac (L_product, result, 1, pOverflow); */
+ L_sum = L_product + (product32 << 1);
+
+ if ((L_product ^ product32) > 0)
+ {
+ if ((L_sum ^ L_product) < 0)
+ {
+ L_sum = (L_product < 0) ? MIN_32 : MAX_32;
+ }
+ }
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return (L_sum);
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MPY_32_H_ */
diff --git a/media/codecs/amrnb/common/include/mpy_32_16.h b/media/codecs/amrnb/common/include/mpy_32_16.h
new file mode 100644
index 0000000..7eaa741
--- /dev/null
+++ b/media/codecs/amrnb/common/include/mpy_32_16.h
@@ -0,0 +1,206 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/mpy_32_16.h
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the Mpy_32_16 function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef MPY_32_16_H
+#define MPY_32_16_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
+
+ __inline Word32 Mpy_32_16(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+ {
+
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 result;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm {SMULBB L_product, L_var1_hi, var2}
+ __asm {QDADD L_product, 0, L_product}
+ __asm {SMULBB result, L_var1_lo, var2}
+ result >>= 15;
+ __asm {QDADD L_sum, L_product, result}
+ return (L_sum);
+ }
+
+#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
+
+ static inline Word32 Mpy_32_16(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+ {
+
+ register Word32 ra = L_var1_hi;
+ register Word32 rb = L_var1_lo;
+ register Word32 rc = var2;
+ Word32 result, L_product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(ra), "r"(rc)
+ );
+ asm volatile("mov %0, #0"
+ : "=r"(result)
+ );
+
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(L_product)
+ : "r"(result), "r"(L_product)
+ );
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(result)
+ : "r"(rb), "r"(rc)
+ );
+
+ asm volatile("mov %0, %1, ASR #15"
+ : "=r"(ra)
+ : "r"(result)
+ );
+ asm volatile("qdadd %0, %1, %2"
+ : "=r"(result)
+ : "r"(L_product), "r"(ra)
+ );
+
+ return (result);
+ }
+
+#else /* C_EQUIVALENT */
+ __inline Word32 Mpy_32_16(Word16 L_var1_hi,
+ Word16 L_var1_lo,
+ Word16 var2,
+ Flag *pOverflow)
+ {
+
+ Word32 L_product;
+ Word32 L_sum;
+ Word32 result;
+ L_product = (Word32) L_var1_hi * var2;
+
+ if (L_product != (Word32) 0x40000000L)
+ {
+ L_product <<= 1;
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_product = MAX_32;
+ }
+
+ result = ((Word32)L_var1_lo * var2) >> 15;
+
+ L_sum = L_product + (result << 1);
+
+ if ((L_product ^ result) > 0)
+ {
+ if ((L_sum ^ L_product) < 0)
+ {
+ L_sum = (L_product < 0) ? MIN_32 : MAX_32;
+ *pOverflow = 1;
+ }
+ }
+ return (L_sum);
+
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MPY_32_16_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/mult.h b/media/codecs/amrnb/common/include/mult.h
new file mode 100644
index 0000000..6927eba
--- /dev/null
+++ b/media/codecs/amrnb/common/include/mult.h
@@ -0,0 +1,190 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/mult.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for mult function.
+
+ Description: Changed prototype of the mult() function. Instead of using global
+ a pointer to overflow flag is now passed into the function.
+
+ Description: Updated copyright information.
+ Updated variable name from "overflow" to "pOverflow" to match
+ with original function declaration.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Providing support for ARM and Linux-ARM assembly instructions.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the mult function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef MULT_H
+#define MULT_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if defined(PV_ARM_V5)
+
+ __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ Word32 product;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ __asm
+ {
+ SMULBB product, var1, var2
+ MOV product, product, ASR #15
+ CMP product, 0x7FFF
+ MOVGE product, 0x7FFF
+ }
+
+ return ((Word16) product);
+ }
+
+#elif defined(PV_ARM_GCC_V5)
+
+ __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ register Word32 ra = var1;
+ register Word32 rb = var2;
+ Word32 product;
+ Word32 temp = 0x7FFF;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=r"(product)
+ : "r"(ra), "r"(rb)
+ );
+ asm volatile("mov %0, %1, ASR #15"
+ : "=r"(product)
+ : "r"(product)
+ );
+ asm volatile("cmp %0, %1"
+ : "=r"(product)
+ : "r"(temp)
+ );
+ asm volatile("movge %0, %1"
+ : "=r"(product)
+ : "r"(temp)
+ );
+
+ return ((Word16) product);
+ }
+
+#else /* C EQUIVALENT */
+
+ static inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow)
+ {
+ register Word32 product;
+
+ product = ((Word32) var1 * var2) >> 15;
+
+ /* Saturate result (if necessary). */
+ /* var1 * var2 >0x00007fff is the only case */
+ /* that saturation occurs. */
+
+ if (product > 0x00007fffL)
+ {
+ *pOverflow = 1;
+ product = (Word32) MAX_16;
+ }
+
+
+ /* Return the product as a 16 bit value by type casting Word32 to Word16 */
+
+ return ((Word16) product);
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MULT_H_ */
+
diff --git a/media/codecs/amrnb/common/include/mult_r.h b/media/codecs/amrnb/common/include/mult_r.h
new file mode 100644
index 0000000..d7a1857
--- /dev/null
+++ b/media/codecs/amrnb/common/include/mult_r.h
@@ -0,0 +1,121 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/mult_r.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for mult_r function.
+
+ Description: Changed prototype of the mult() function. Instead of using global
+ data, a pointer to overflow flag is now passed into the function.
+
+ Description: Made the following based on P2/P3 review
+ 1) Changed the parameter name from "overflow" to "pOverflow"
+ in the function prototype declaration.
+ 2) Updated template
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the mult_r function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef MULT_R__H
+#define MULT_R__H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 mult_r(Word16 var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _MULT_R_H_ */
+
+
+
+
+
diff --git a/media/codecs/amrnb/common/include/n_proc.h b/media/codecs/amrnb/common/include/n_proc.h
new file mode 100644
index 0000000..e5738c1
--- /dev/null
+++ b/media/codecs/amrnb/common/include/n_proc.h
@@ -0,0 +1,31 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/* $Id $ */
+
+void proc_head(char *mes);
diff --git a/media/codecs/amrnb/common/include/negate.h b/media/codecs/amrnb/common/include/negate.h
new file mode 100644
index 0000000..f67569e
--- /dev/null
+++ b/media/codecs/amrnb/common/include/negate.h
@@ -0,0 +1,113 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/include/negate.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for negate function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the negate function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef NEGATE_H
+#define NEGATE_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 negate(register Word16 var1);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/norm_l.h b/media/codecs/amrnb/common/include/norm_l.h
new file mode 100644
index 0000000..533b105
--- /dev/null
+++ b/media/codecs/amrnb/common/include/norm_l.h
@@ -0,0 +1,153 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/include/norm_l.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for norm_l function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Support for ARM and Linux-ARM assembly.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the norm_l function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef NORM_L_H
+#define NORM_L_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) )
+
+ /* C EQUIVALENT */
+ Word16 norm_l(Word32 L_var1);
+
+#elif defined(PV_ARM_V5)
+
+ __inline Word16 norm_l(Word32 L_var1)
+ {
+ register Word32 var_out = 0;
+
+ __asm
+ {
+ CMP L_var1, #0
+ EORNE L_var1, L_var1, L_var1, LSL #1
+ CLZNE var_out, L_var1
+ }
+
+ return ((Word16)var_out);
+ }
+
+#elif defined(PV_ARM_GCC_V5)
+
+ static inline Word16 norm_l(Word32 L_var1)
+ {
+ register Word32 var_out = 0;
+ register Word32 ra = L_var1;
+ if (L_var1)
+ {
+ ra ^= (ra << 1);
+ asm volatile(
+ "clz %0, %1"
+ : "=r"(var_out)
+ : "r"(ra)
+ );
+ }
+ return (var_out);
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/norm_s.h b/media/codecs/amrnb/common/include/norm_s.h
new file mode 100644
index 0000000..2e37a9f
--- /dev/null
+++ b/media/codecs/amrnb/common/include/norm_s.h
@@ -0,0 +1,153 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/include/norm_s.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for norm_s function.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the norm_s function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef NORM_S_H
+#define NORM_S_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) )
+
+ /* C EQUIVALENT */
+
+ Word16 norm_s(Word16 var1);
+
+#elif defined(PV_ARM_V5)
+
+ __inline Word16 norm_s(Word16 var)
+ {
+ register Word32 var_out = 0;
+ Word32 var1 = var << 16;
+
+ __asm
+ {
+ CMP var1, #0
+ EORNE var1, var1, var1, LSL #1
+ CLZNE var_out, var1
+ }
+
+ return ((Word16)var_out);
+ }
+
+#elif defined(PV_ARM_GCC_V5)
+
+ static inline Word16 norm_s(Word16 var1)
+ {
+ register Word32 var_out = 0;
+ register Word32 ra = var1 << 16;
+ if (ra)
+ {
+ ra ^= (ra << 1);
+ asm volatile(
+ "clz %0, %1"
+ : "=r"(var_out)
+ : "r"(ra)
+ );
+ }
+ return (var_out);
+ }
+
+#endif
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/oper_32b.h b/media/codecs/amrnb/common/include/oper_32b.h
new file mode 100644
index 0000000..ec3fcfb
--- /dev/null
+++ b/media/codecs/amrnb/common/include/oper_32b.h
@@ -0,0 +1,102 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/include/oper_32b.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Deleted inclusion of files that were not part of the original
+ oper_32b.h file.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file includes all the oper_32b.c functions' header files.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef OPER_32B_H
+#define OPER_32B_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+#include "div_32.h"
+#include "l_comp.h"
+#include "l_extract.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/p_ol_wgh.h b/media/codecs/amrnb/common/include/p_ol_wgh.h
new file mode 100644
index 0000000..6c277da
--- /dev/null
+++ b/media/codecs/amrnb/common/include/p_ol_wgh.h
@@ -0,0 +1,144 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/include/p_ol_wgh.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : p_ol_wgh.h
+ Purpose : Compute the open loop pitch lag with weighting.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef P_OL_WGH_H
+#define P_OL_WGH_H "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "vad.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+ extern const Word16 corrweight[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ /* state variable */
+
+ typedef struct
+ {
+ Word16 old_T0_med;
+ Word16 ada_w;
+ Word16 wght_flg;
+ } pitchOLWghtState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 p_ol_wgh_init(pitchOLWghtState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to p_ol_wgh in each call.
+ returns 0 on success
+ */
+
+ Word16 p_ol_wgh_reset(pitchOLWghtState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void p_ol_wgh_exit(pitchOLWghtState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ Word16 Pitch_ol_wgh( /* o : open loop pitch lag */
+ pitchOLWghtState *st, /* i/o : State struct */
+ vadState *vadSt, /* i/o : VAD state struct */
+ Word16 signal[], /* i : signal used to compute the open loop pitch */
+ /* signal[-pit_max] to signal[-1] should be known */
+ Word16 pit_min, /* i : minimum pitch lag */
+ Word16 pit_max, /* i : maximum pitch lag */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 old_lags[], /* i : history with old stored Cl lags */
+ Word16 ol_gain_flg[], /* i : OL gain flag */
+ Word16 idx, /* i : index */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* o : overflow flag */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _P_OL_WGH_H_ */
diff --git a/media/codecs/amrnb/common/include/pow2.h b/media/codecs/amrnb/common/include/pow2.h
new file mode 100644
index 0000000..9b944eb
--- /dev/null
+++ b/media/codecs/amrnb/common/include/pow2.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/log2_norm.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template. Added extern declaration for pow2_tbl[]
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the prototype declaration for Pow2() function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef POW2_H
+#define POW2_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 pow2_tbl[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word32 Pow2( /* (o) : result (range: 0<=val<=0x7fffffff) */
+ Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */
+ Word16 fraction, /* (i) : Fractional part. (range: 0.0<=val<1.0) */
+ Flag *pOverflow /* (i/o) : overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _POW2_H_ */
diff --git a/media/codecs/amrnb/common/include/pred_lt.h b/media/codecs/amrnb/common/include/pred_lt.h
new file mode 100644
index 0000000..a2bfed2
--- /dev/null
+++ b/media/codecs/amrnb/common/include/pred_lt.h
@@ -0,0 +1,113 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/pred_lt.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the pred_lt function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef pred_lt_h
+#define pred_lt_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Pred_lt_3or6(
+ Word16 exc[], /* in/out: excitation buffer */
+ Word16 T0, /* input : integer pitch lag */
+ Word16 frac, /* input : fraction of lag */
+ Word16 L_subfr, /* input : subframe size */
+ Word16 flag3, /* input : if set, upsampling rate = 3 (6 otherwise) */
+ Flag *pOverflow /* output: if set, overflow occurred in this function */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PRED_LT_H */
diff --git a/media/codecs/amrnb/common/include/q_plsf.h b/media/codecs/amrnb/common/include/q_plsf.h
new file mode 100644
index 0000000..431272a
--- /dev/null
+++ b/media/codecs/amrnb/common/include/q_plsf.h
@@ -0,0 +1,169 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/q_plsf.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the q_plsf_3.c and q_plsf_5.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef q_plsf_h
+#define q_plsf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define MR795_1_SIZE 512
+#define PAST_RQ_INIT_SIZE 8
+
+#define DICO1_SIZE 256
+#define DICO2_SIZE 512
+#define DICO3_SIZE 512
+
+#define DICO1_5_SIZE 128
+#define DICO2_5_SIZE 256
+#define DICO3_5_SIZE 256
+#define DICO4_5_SIZE 256
+#define DICO5_5_SIZE 64
+
+#define MR515_3_SIZE 128
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 past_rq[M]; /* Past quantized prediction error, Q15 */
+
+ } Q_plsfState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word16 Q_plsf_init(Q_plsfState **st);
+ /* initialize one instance of the state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to Q_plsf_5 / Q_plsf_3 in each call.
+ returns 0 on success
+ */
+
+ Word16 Q_plsf_reset(Q_plsfState *st);
+ /* reset of state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void Q_plsf_exit(Q_plsfState **st);
+ /* de-initialize state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void Q_plsf_3(
+ Q_plsfState *st, /* i/o: state struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 *lsp1, /* i : 1st LSP vector Q15 */
+ Word16 *lsp1_q, /* o : quantized 1st LSP vector Q15 */
+ Word16 *indice, /* o : quantization indices of 3 vectors Q0 */
+ Word16 *pred_init_i,/* o : init index for MA prediction in DTX mode */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ void Q_plsf_5(
+ Q_plsfState *st,
+ Word16 *lsp1, /* i : 1st LSP vector, Q15 */
+ Word16 *lsp2, /* i : 2nd LSP vector, Q15 */
+ Word16 *lsp1_q, /* o : quantized 1st LSP vector, Q15 */
+ Word16 *lsp2_q, /* o : quantized 2nd LSP vector, Q15 */
+ Word16 *indice, /* o : quantization indices of 5 matrices, Q0 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ );
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _Q_PLSF_H_ */
+
diff --git a/media/codecs/amrnb/common/include/q_plsf_3_tbl.h b/media/codecs/amrnb/common/include/q_plsf_3_tbl.h
new file mode 100644
index 0000000..2e43d10
--- /dev/null
+++ b/media/codecs/amrnb/common/include/q_plsf_3_tbl.h
@@ -0,0 +1,136 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/q_plsf_3_tbl.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created this file from the reference, q_plsf_3_tbl.tab
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+#define MR795_1_SIZE 512
+#define PAST_RQ_INIT_SIZE 8
+
+#define DICO1_SIZE 256
+#define DICO2_SIZE 512
+#define DICO3_SIZE 512
+
+#define MR515_3_SIZE 128
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /* Codebooks of LSF prediction residual */
+ extern const Word16 mean_lsf_3[];
+
+ extern const Word16 pred_fac_3[];
+
+ extern const Word16 dico1_lsf_3[];
+ extern const Word16 dico2_lsf_3[];
+ extern const Word16 dico3_lsf_3[];
+
+ extern const Word16 mr515_3_lsf[];
+ extern const Word16 mr795_1_lsf[];
+
+ extern const Word16 past_rq_init[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/media/codecs/amrnb/common/include/q_plsf_5_tbl.h b/media/codecs/amrnb/common/include/q_plsf_5_tbl.h
new file mode 100644
index 0000000..245b5f4
--- /dev/null
+++ b/media/codecs/amrnb/common/include/q_plsf_5_tbl.h
@@ -0,0 +1,110 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/include/q_plsf_5_tbl.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares tables defined in q_plsf_5_tbl.c.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef Q_PLSF_5_TBL_H
+#define Q_PLSF_5_TBL_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 mean_lsf_5[];
+ extern const Word16 dico1_lsf_5[];
+ extern const Word16 dico2_lsf_5[];
+ extern const Word16 dico3_lsf_5[];
+ extern const Word16 dico4_lsf_5[];
+ extern const Word16 dico5_lsf_5[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/qgain475_tab.h b/media/codecs/amrnb/common/include/qgain475_tab.h
new file mode 100644
index 0000000..6c0d766
--- /dev/null
+++ b/media/codecs/amrnb/common/include/qgain475_tab.h
@@ -0,0 +1,107 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/include/qgain475_tab.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares tables defined in qgain475_tab.c.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef QGAIN475_TAB_H
+#define QGAIN475_TAB_H
+
+#define MR475_VQ_SIZE 256
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 table_gain_MR475[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/qua_gain.h b/media/codecs/amrnb/common/include/qua_gain.h
new file mode 100644
index 0000000..65b35ee
--- /dev/null
+++ b/media/codecs/amrnb/common/include/qua_gain.h
@@ -0,0 +1,135 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/qua_gain.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, qua_gain.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef qua_gain_h
+#define qua_gain_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "gc_pred.h"
+#include "mode.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define VQ_SIZE_HIGHRATES 128
+#define VQ_SIZE_LOWRATES 64
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word16
+ Qua_gain( /* o : index of quantization. */
+ enum Mode mode, /* i : AMR mode */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
+ Word16 exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
+ /* (frac_coeff and exp_coeff computed in */
+ /* calc_filt_energies()) */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *gain_cod, /* o : Code gain, Q1 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Flag *pOverflow /* o : overflow indicator */
+ );
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* qua_gain_h */
+
+
+
diff --git a/media/codecs/amrnb/common/include/qua_gain_tbl.h b/media/codecs/amrnb/common/include/qua_gain_tbl.h
new file mode 100644
index 0000000..a7691e7
--- /dev/null
+++ b/media/codecs/amrnb/common/include/qua_gain_tbl.h
@@ -0,0 +1,108 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/include/qua_gain_tbl.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares tables defined in qua_gain_tbl.c.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef QUA_GAIN_TBL_H
+#define QUA_GAIN_TBL_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 table_gain_highrates[];
+ extern const Word16 table_gain_lowrates[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/reorder.h b/media/codecs/amrnb/common/include/reorder.h
new file mode 100644
index 0000000..620cd0b
--- /dev/null
+++ b/media/codecs/amrnb/common/include/reorder.h
@@ -0,0 +1,109 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/reorder.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the Reorder_lsf() function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef REORDER_H
+#define REORDER_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Reorder_lsf(
+ Word16 *lsf, /* (i/o) : vector of LSFs (range: 0<=val<=0.5) */
+ Word16 min_dist, /* (i) : minimum required distance */
+ Word16 n, /* (i) : LPC order */
+ Flag *pOverflow /* (i/o) : overflow Flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _REORDER_H_ */
+
diff --git a/media/codecs/amrnb/common/include/residu.h b/media/codecs/amrnb/common/include/residu.h
new file mode 100644
index 0000000..f4d0041
--- /dev/null
+++ b/media/codecs/amrnb/common/include/residu.h
@@ -0,0 +1,83 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : residu.h
+* Purpose : Computes the LP residual.
+* Description : The LP residual is computed by filtering the input
+* : speech through the LP inverse filter A(z).
+*
+*
+********************************************************************************
+*/
+#ifndef residu_h
+#define residu_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ void Residu(
+ Word16 a[], /* (i) : prediction coefficients */
+ Word16 x[], /* (i) : speech signal */
+ Word16 y[], /* (o) : residual signal */
+ Word16 lg /* (i) : size of filtering */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/reverse_bits.h b/media/codecs/amrnb/common/include/reverse_bits.h
new file mode 100644
index 0000000..fcc8df6
--- /dev/null
+++ b/media/codecs/amrnb/common/include/reverse_bits.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/include/reverse_bits.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Adding #include "mode.h" so that it compiles and works for the
+ ARM tools.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the reverse_bits function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef REVERSE_BITS_H
+#define REVERSE_BITS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void reverse_bits(enum Mode mode, unsigned char *pCompressedBlock);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/round.h b/media/codecs/amrnb/common/include/round.h
new file mode 100644
index 0000000..3129e27
--- /dev/null
+++ b/media/codecs/amrnb/common/include/round.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/round.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for round function.
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the pv_round function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef ROUND_H
+#define ROUND_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 pv_round(Word32 L_var1, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ROUND_H_ */
diff --git a/media/codecs/amrnb/common/include/set_zero.h b/media/codecs/amrnb/common/include/set_zero.h
new file mode 100644
index 0000000..debd223
--- /dev/null
+++ b/media/codecs/amrnb/common/include/set_zero.h
@@ -0,0 +1,79 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : set_zero.h
+* Description : Set vector x[] to zero
+*
+*
+********************************************************************************
+*/
+#ifndef set_zero_h
+#define set_zero_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ void Set_zero(
+ Word16 x[], /* (o) : vector to clear */
+ Word16 L /* (i) : length of vector */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/shl.h b/media/codecs/amrnb/common/include/shl.h
new file mode 100644
index 0000000..84ca8d9
--- /dev/null
+++ b/media/codecs/amrnb/common/include/shl.h
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/shl.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for shl function.
+
+ Description: Changed prototype of the mult() function. Instead of using global
+ a pointer to overflow flag is now passed into the function.
+
+ Description: Updated template. Changed the parameter name from "overflow" to
+ "pOverflow" in the function prototype declaration
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the shl function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef SHL_H
+#define SHL_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 shl(Word16 var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SHL_H_ */
+
+
+
diff --git a/media/codecs/amrnb/common/include/shr.h b/media/codecs/amrnb/common/include/shr.h
new file mode 100644
index 0000000..e961c04
--- /dev/null
+++ b/media/codecs/amrnb/common/include/shr.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/shr.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for shr function.
+
+ Description: Changed the function prototype declaration.
+ Updated template.
+
+ Description: Updated template. Changed the parameter name from "overflow" to
+ "pOverflow" in the function prototype declaration
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the shr function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef SHR_H
+#define SHR_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 shr(Word16 var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SHR_H_ */
diff --git a/media/codecs/amrnb/common/include/shr_r.h b/media/codecs/amrnb/common/include/shr_r.h
new file mode 100644
index 0000000..c4f9e2c
--- /dev/null
+++ b/media/codecs/amrnb/common/include/shr_r.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/include/shr_r.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for shr_r function.
+
+ Description: Passing in pOverflow.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #define after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the shr_r function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef SHR_R_H
+#define SHR_R_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 shr_r(Word16 var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/sqrt_l.h b/media/codecs/amrnb/common/include/sqrt_l.h
new file mode 100644
index 0000000..a6a2ee5
--- /dev/null
+++ b/media/codecs/amrnb/common/include/sqrt_l.h
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/sqrt_l.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Updated function prototype declaration to reflect new interface.
+ A pointer to overflow flag is passed into the function. Updated
+ template.
+
+ Description: Added extern declaration for sqrt_l_tbl[]
+
+ Description: Moved _cplusplus #ifdef before function prototype.
+
+ Who: Date:
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the sqrt_l() function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef SQRT_L_H
+#define SQRT_L_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 sqrt_l_tbl[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word32 sqrt_l_exp( /* o : output value, Q31 */
+ Word32 L_x, /* i : input value, Q31 */
+ Word16 *pExp, /* o : right shift to be applied to result, Q1 */
+ Flag *pOverflow /* i : pointer to overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SQRT_L__H_ */
+
diff --git a/media/codecs/amrnb/common/include/sub.h b/media/codecs/amrnb/common/include/sub.h
new file mode 100644
index 0000000..18dc456
--- /dev/null
+++ b/media/codecs/amrnb/common/include/sub.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/sub.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for sub function.
+
+ Description: Changed function prototype declaration.
+
+ Description: Updated copyright information.
+ Updated variable name from "overflow" to "pOverflow" to match
+ with original function declaration.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the sub function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef SUB_H
+#define SUB_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 sub(Word16 var1, Word16 var2, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SUB_H_ */
diff --git a/media/codecs/amrnb/common/include/syn_filt.h b/media/codecs/amrnb/common/include/syn_filt.h
new file mode 100644
index 0000000..7fff112
--- /dev/null
+++ b/media/codecs/amrnb/common/include/syn_filt.h
@@ -0,0 +1,83 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : syn_filt.h
+* Purpose : Perform synthesis filtering through 1/A(z).
+*
+*
+********************************************************************************
+*/
+#ifndef syn_filt_h
+#define syn_filt_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ void Syn_filt(
+ Word16 a[], /* (i) : a[m+1] prediction coefficients (m=10) */
+ Word16 x[], /* (i) : input signal */
+ Word16 y[], /* (o) : output signal */
+ Word16 lg, /* (i) : size of filtering */
+ Word16 mem[], /* (i/o): memory associated with this filtering. */
+ Word16 update /* (i) : 0=no update, 1=update of memory. */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/typedef.h b/media/codecs/amrnb/common/include/typedef.h
new file mode 100644
index 0000000..ee4d732
--- /dev/null
+++ b/media/codecs/amrnb/common/include/typedef.h
@@ -0,0 +1,73 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : typedef.c
+* Purpose : Basic types.
+*
+********************************************************************************
+*/
+#ifndef typedef_h
+#define typedef_h "$Id $"
+
+#undef ORIGINAL_TYPEDEF_H /* CHANGE THIS TO #define to get the */
+/* "original" ETSI version of typedef.h */
+/* CHANGE TO #undef for PV version */
+
+#ifdef ORIGINAL_TYPEDEF_H
+/*
+ * this is the original code from the ETSI file typedef.h
+ */
+
+#if defined(__unix__) || defined(__unix)
+typedef signed char Word8;
+typedef short Word16;
+typedef int Word32;
+typedef int Flag;
+
+#else
+#error No System recognized
+#endif
+#else /* not original typedef.h */
+
+/*
+ * use (improved) type definition file typdefs.h
+ */
+#include "gsm_amr_typedefs.h"
+
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/vad.h b/media/codecs/amrnb/common/include/vad.h
new file mode 100644
index 0000000..b9ee89f
--- /dev/null
+++ b/media/codecs/amrnb/common/include/vad.h
@@ -0,0 +1,76 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+**-------------------------------------------------------------------------**
+** **
+** GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001 **
+** R99 Version 3.2.0 **
+** REL-4 Version 4.0.0 **
+** **
+**-------------------------------------------------------------------------**
+********************************************************************************
+*
+* File : vad.h
+* Purpose : Voice Activity Detection (VAD) for AMR
+*
+********************************************************************************
+*/
+#ifndef vad_h
+#define vad_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+
+#include "vad1.h" /* for VAD option 1 */
+#include "vad2.h" /* for VAD option 2 */
+
+/*
+********************************************************************************
+* LOCAL VARIABLES AND TABLES
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+* DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+
+#ifndef VAD2
+#define vadState vadState1
+#else
+#define vadState vadState2
+#endif
+
+
+#endif
diff --git a/media/codecs/amrnb/common/include/vad1.h b/media/codecs/amrnb/common/include/vad1.h
new file mode 100644
index 0000000..c144ea0
--- /dev/null
+++ b/media/codecs/amrnb/common/include/vad1.h
@@ -0,0 +1,197 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/include/vad_1.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions, prototype and structure
+ definitions needed by vad_1.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef vad_1_h
+#define vad_1_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst_vad.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ /* state variable */
+ typedef struct
+ {
+
+ Word16 bckr_est[COMPLEN]; /* background noise estimate */
+ Word16 ave_level[COMPLEN]; /* averaged input components for stationary */
+ /* estimation */
+ Word16 old_level[COMPLEN]; /* input levels of the previous frame */
+ Word16 sub_level[COMPLEN]; /* input levels calculated at the end of
+ a frame (lookahead) */
+ Word16 a_data5[3][2]; /* memory for the filter bank */
+ Word16 a_data3[5]; /* memory for the filter bank */
+
+ Word16 burst_count; /* counts length of a speech burst */
+ Word16 hang_count; /* hangover counter */
+ Word16 stat_count; /* stationary counter */
+
+ /* Note that each of the following three variables (vadreg, pitch and tone)
+ holds 15 flags. Each flag reserves 1 bit of the variable. The newest
+ flag is in the bit 15 (assuming that LSB is bit 1 and MSB is bit 16). */
+ Word16 vadreg; /* flags for intermediate VAD decisions */
+ Word16 pitch; /* flags for pitch detection */
+ Word16 tone; /* flags for tone detection */
+ Word16 complex_high; /* flags for complex detection */
+ Word16 complex_low; /* flags for complex detection */
+
+ Word16 oldlag_count, oldlag; /* variables for pitch detection */
+
+ Word16 complex_hang_count; /* complex hangover counter, used by VAD */
+ Word16 complex_hang_timer; /* hangover initiator, used by CAD */
+
+ Word16 best_corr_hp; /* FIP filtered value Q15 */
+
+ Word16 speech_vad_decision; /* final decision */
+ Word16 complex_warning; /* complex background warning */
+
+ Word16 sp_burst_count; /* counts length of a speech burst incl */
+ Word16 corr_hp_fast; /* filtered value */
+ } vadState1;
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 vad1_init(vadState1 **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to vad in each call.
+ returns 0 on success
+ */
+
+ Word16 vad1_reset(vadState1 *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void vad1_exit(vadState1 **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void vad_complex_detection_update(vadState1 *st, /* i/o : State struct */
+ Word16 best_corr_hp /* i : best Corr Q15 */
+ );
+
+ void vad_tone_detection(vadState1 *st, /* i/o : State struct */
+ Word32 t0, /* i : autocorrelation maxima */
+ Word32 t1, /* i : energy */
+ Flag *pOverflow
+ );
+
+ void vad_tone_detection_update(
+ vadState1 *st, /* i/o : State struct */
+ Word16 one_lag_per_frame, /* i : 1 if one open-loop lag is
+ calculated per each frame,
+ otherwise 0 */
+ Flag *pOverflow
+ );
+
+ void vad_pitch_detection(vadState1 *st, /* i/o : State struct */
+ Word16 lags[], /* i : speech encoder open loop lags */
+ Flag *pOverflow
+ );
+
+ Word16 vad1(vadState1 *st, /* i/o : State struct */
+ Word16 in_buf[], /* i : samples of the input frame
+ inbuf[159] is the very last sample,
+ incl lookahead */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VAD1_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/vad2.h b/media/codecs/amrnb/common/include/vad2.h
new file mode 100644
index 0000000..3197b3a
--- /dev/null
+++ b/media/codecs/amrnb/common/include/vad2.h
@@ -0,0 +1,203 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/include/vad2.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Added pOverflow to the r_fft function prototype.
+
+ Description: Added pOverflow to the LTP_flag_update prototype.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions, prototype and structure
+ definitions needed by vad_2.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef vad_2_h
+#define vad_2_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+#define YES 1
+#define NO 0
+#define ON 1
+#define OFF 0
+#define TRUE 1
+#define FALSE 0
+
+#define FRM_LEN 80
+#define DELAY 24
+#define FFT_LEN 128
+
+#define NUM_CHAN 16
+#define LO_CHAN 0
+#define HI_CHAN 15
+
+#define UPDATE_THLD 35
+#define HYSTER_CNT_THLD 6
+#define UPDATE_CNT_THLD 50
+
+#define SHIFT_STATE_0 0 /* channel energy scaled as 22,9 */
+#define SHIFT_STATE_1 1 /* channel energy scaled as 27,4 */
+
+#define NOISE_FLOOR_CHAN_0 512 /* 1.0 scaled as 22,9 */
+#define MIN_CHAN_ENRG_0 32 /* 0.0625 scaled as 22,9 */
+#define MIN_NOISE_ENRG_0 32 /* 0.0625 scaled as 22,9 */
+#define INE_NOISE_0 8192 /* 16.0 scaled as 22,9 */
+#define FRACTIONAL_BITS_0 9 /* used as input to fn10Log10() */
+
+#define NOISE_FLOOR_CHAN_1 16 /* 1.0 scaled as 27,4 */
+#define MIN_CHAN_ENRG_1 1 /* 0.0625 scaled as 27,4 */
+#define MIN_NOISE_ENRG_1 1 /* 0.0625 scaled as 27,4 */
+#define INE_NOISE_1 256 /* 16.0 scaled as 27,4 */
+#define FRACTIONAL_BITS_1 4 /* used as input to fn10Log10() */
+
+#define STATE_1_TO_0_SHIFT_R (FRACTIONAL_BITS_1-FRACTIONAL_BITS_0) /* state correction factor */
+#define STATE_0_TO_1_SHIFT_R (FRACTIONAL_BITS_0-FRACTIONAL_BITS_1) /* state correction factor */
+
+#define HIGH_ALPHA 29491 /* 0.9 scaled as 0,15 */
+#define LOW_ALPHA 22938 /* 0.7 scaled as 0,15 */
+#define ALPHA_RANGE (HIGH_ALPHA - LOW_ALPHA)
+#define DEV_THLD 7168 /* 28.0 scaled as 7,8 */
+
+#define PRE_EMP_FAC (-26214) /* -0.8 scaled as 0,15 */
+
+#define CEE_SM_FAC 18022 /* 0.55 scaled as 0,15 */
+#define ONE_MINUS_CEE_SM_FAC 14746 /* 0.45 scaled as 0,15 */
+
+#define CNE_SM_FAC 3277 /* 0.1 scaled as 0,15 */
+#define ONE_MINUS_CNE_SM_FAC 29491 /* 0.9 scaled as 0,15 */
+
+#define FFT_HEADROOM 2
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ typedef struct
+ {
+ Word16 pre_emp_mem;
+ Word16 update_cnt;
+ Word16 hyster_cnt;
+ Word16 last_update_cnt;
+ Word16 ch_enrg_long_db[NUM_CHAN]; /* scaled as 7,8 */
+
+ Word32 Lframe_cnt;
+ Word32 Lch_enrg[NUM_CHAN]; /* scaled as 22,9 or 27,4 */
+ Word32 Lch_noise[NUM_CHAN]; /* scaled as 22,9 */
+
+ Word16 last_normb_shift; /* last block norm shift count */
+
+ Word16 tsnr; /* total signal-to-noise ratio in dB (scaled as 7,8) */
+ Word16 hangover;
+ Word16 burstcount;
+ Word16 fupdate_flag; /* forced update flag from previous frame */
+ Word16 negSNRvar; /* Negative SNR variance (scaled as 7,8) */
+ Word16 negSNRbias; /* sensitivity bias from negative SNR variance (scaled as 15,0) */
+
+ Word16 shift_state; /* use 22,9 or 27,4 scaling for ch_enrg[] */
+
+ Word32 L_R0;
+ Word32 L_Rmax;
+ Flag LTP_flag; /* Use to indicate the the LTP gain is > LTP_THRESH */
+
+ } vadState2;
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 vad2(Word16 *farray_ptr, vadState2 *st, Flag *pOverflow);
+ Word16 vad2_init(vadState2 **st);
+ Word16 vad2_reset(vadState2 *st);
+ void vad2_exit(vadState2 **state);
+
+ void r_fft(Word16 *farray_ptr, Flag *pOverflow);
+
+ void LTP_flag_update(vadState2 *st, Word16 mode, Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VAD2_H_ */
+
+
diff --git a/media/codecs/amrnb/common/include/weight_a.h b/media/codecs/amrnb/common/include/weight_a.h
new file mode 100644
index 0000000..0358c85
--- /dev/null
+++ b/media/codecs/amrnb/common/include/weight_a.h
@@ -0,0 +1,81 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : weight_a.h
+* Purpose : Spectral expansion of LP coefficients. (order==10)
+* Description : a_exp[i] = a[i] * fac[i-1] ,i=1,10
+*
+*
+********************************************************************************
+*/
+#ifndef weight_a_h
+#define weight_a_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ void Weight_Ai(
+ Word16 a[], /* (i) : a[m+1] LPC coefficients (m=10) */
+ const Word16 fac[],/* (i) : Spectral expansion factors. */
+ Word16 a_exp[] /* (o) : Spectral expanded LPC coefficients */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/include/window_tab.h b/media/codecs/amrnb/common/include/window_tab.h
new file mode 100644
index 0000000..42233af
--- /dev/null
+++ b/media/codecs/amrnb/common/include/window_tab.h
@@ -0,0 +1,109 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: .audio/gsm-amr/c/include/window_tab.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares a tables in window_tab.c used in lpc.c.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef WINDOW_TAB_H
+#define WINDOW_TAB_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 window_200_40[];
+ extern const Word16 window_160_80[];
+ extern const Word16 window_232_8[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/common/include/wmf_to_ets.h b/media/codecs/amrnb/common/include/wmf_to_ets.h
new file mode 100644
index 0000000..8bcccc8
--- /dev/null
+++ b/media/codecs/amrnb/common/include/wmf_to_ets.h
@@ -0,0 +1,119 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/include/src/wmf_to_ets.h
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed mode to frame_type_3gpp
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the wmf_to_ets function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef WMF_TO_ETS_H
+#define WMF_TO_ETS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "frame_type_3gpp.h"
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void wmf_to_ets(enum Frame_Type_3GPP frame_type_3gpp,
+ UWord8 *wmf_input_ptr,
+ Word16 *ets_output_ptr);
+
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/common/src/add.cpp b/media/codecs/amrnb/common/src/add.cpp
new file mode 100644
index 0000000..d488ca5
--- /dev/null
+++ b/media/codecs/amrnb/common/src/add.cpp
@@ -0,0 +1,203 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/add.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for add function. Sync'ed up with the
+ current template and fixed tabs.
+
+ Description: Changed all occurrences of L_sum with sum.
+
+ Description: Changed function protype to pass in pointer to Overflow flag
+ as a parameter.
+
+ Description: Removed code that updates MOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Summation function with overflow control
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: add
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the add operation resulted in overflow
+
+ Returns:
+ sum = 16-bit limited sum of var1 and var2 (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the addition (var1+var2) with overflow control and
+ saturation; the 16 bit result is set at +32767 when overflow occurs or at
+ -32768 when underflow occurs.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] add.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 add (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 sum;
+
+ sum = (Word32) var1 + var2;
+
+* The reference ETSI code uses a global flag for Overflow inside the function
+* saturate(). In the actual implementation a pointer to Overflow flag is passed in
+* as a parameter to the function
+
+ var_out = saturate (sum);
+#if (WMOPS)
+ multiCounter[currCounter].add++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 add(Word16 var1, Word16 var2, Flag *pOverflow)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ Word32 sum;
+ sum = (Word32) var1 + var2;
+
+ /* Saturate result (if necessary). */
+ /* Replaced function call with in-line code */
+ /* to conserve MIPS, i.e., var_out = saturate (sum) */
+
+ if (sum > 0X00007fffL)
+ {
+ *pOverflow = 1;
+ sum = MAX_16;
+ }
+ else if (sum < (Word32) 0xffff8000L)
+ {
+ *pOverflow = 1;
+ sum = MIN_16;
+ }
+
+ /* Return the sum as a 16 bit value by type casting Word32 to Word16 */
+
+ return ((Word16) sum);
+}
+
diff --git a/media/codecs/amrnb/common/src/az_lsp.cpp b/media/codecs/amrnb/common/src/az_lsp.cpp
new file mode 100644
index 0000000..f3098f5
--- /dev/null
+++ b/media/codecs/amrnb/common/src/az_lsp.cpp
@@ -0,0 +1,742 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/az_lsp.c
+ Funtions: Chebps
+ Chebps_Wrapper
+ Az_lsp
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Finished first pass of optimization.
+
+ Description: Made changes based on review comments.
+
+ Description: Made input to Chebps_Wrapper consistent with that of Chebps.
+
+ Description: Replaced current Pseudo-code with the UMTS code version 3.2.0.
+ Updated coding template.
+
+ Description: Replaced basic_op.h and oper_32b.h with the header files of the
+ math functions used by the file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Used "-" operator instead of calling sub function in the
+ az_lsp() code.
+ 2. Copied detailed function description of az_lsp from the
+ header file.
+ 3. Modified local variable definition to one per line.
+ 4. Used NC in the definition of f1 and f2 arrays.
+ 5. Added curly brackets in the IF statement.
+
+ Description: Changed function interface to pass in a pointer to overflow
+ flag into the function instead of using a global flag. Removed
+ inclusion of unneeded header files.
+
+ Description: For Chebps() and Az_lsp()
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation.
+ 4. Eliminated not needed variables
+ 5. Eliminated if-else checks for saturation
+ 6. Deleted unused function cheps_wraper
+
+ Description: Added casting to eliminate warnings
+
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ These modules compute the LSPs from the LP coefficients.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "az_lsp.h"
+#include "cnst.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NC (M/2) /* M = LPC order, NC = M/2 */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Chebps
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x = input value (Word16)
+ f = polynomial (Word16)
+ n = polynomial order (Word16)
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the operations in the function resulted in saturation.
+
+ Returns:
+ cheb = Chebyshev polynomial for the input value x.(Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This module evaluates the Chebyshev polynomial series.
+ - The polynomial order is n = m/2 = 5
+ - The polynomial F(z) (F1(z) or F2(z)) is given by
+ F(w) = 2 exp(-j5w) C(x)
+ where
+ C(x) = T_n(x) + f(1)T_n-1(x) + ... +f(n-1)T_1(x) + f(n)/2
+ and T_m(x) = cos(mw) is the mth order Chebyshev
+ polynomial ( x=cos(w) )
+ - C(x) for the input x is returned.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ az_lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static Word16 Chebps (Word16 x,
+ Word16 f[], // (n)
+ Word16 n)
+{
+ Word16 i, cheb;
+ Word16 b0_h, b0_l, b1_h, b1_l, b2_h, b2_l;
+ Word32 t0;
+
+// The reference ETSI code uses a global flag for Overflow. However, in the
+// actual implementation a pointer to Overflow flag is passed in as a
+// parameter to the function. This pointer is passed into all the basic math
+// functions invoked
+
+ b2_h = 256; // b2 = 1.0
+ b2_l = 0;
+
+ t0 = L_mult (x, 512); // 2*x
+ t0 = L_mac (t0, f[1], 8192); // + f[1]
+ L_Extract (t0, &b1_h, &b1_l); // b1 = 2*x + f[1]
+
+ for (i = 2; i < n; i++)
+ {
+ t0 = Mpy_32_16 (b1_h, b1_l, x); // t0 = 2.0*x*b1
+ t0 = L_shl (t0, 1);
+ t0 = L_mac (t0, b2_h, (Word16) 0x8000); // t0 = 2.0*x*b1 - b2
+ t0 = L_msu (t0, b2_l, 1);
+ t0 = L_mac (t0, f[i], 8192); // t0 = 2.0*x*b1 - b2 + f[i]
+
+ L_Extract (t0, &b0_h, &b0_l); // b0 = 2.0*x*b1 - b2 + f[i]
+
+ b2_l = b1_l; // b2 = b1;
+ b2_h = b1_h;
+ b1_l = b0_l; // b1 = b0;
+ b1_h = b0_h;
+ }
+
+ t0 = Mpy_32_16 (b1_h, b1_l, x); // t0 = x*b1;
+ t0 = L_mac (t0, b2_h, (Word16) 0x8000); // t0 = x*b1 - b2
+ t0 = L_msu (t0, b2_l, 1);
+ t0 = L_mac (t0, f[i], 4096); // t0 = x*b1 - b2 + f[i]/2
+
+ t0 = L_shl (t0, 6);
+
+ cheb = extract_h (t0);
+
+ return (cheb);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+#ifdef __clang__
+__attribute__((no_sanitize("integer")))
+#endif
+static Word16 Chebps(Word16 x,
+ Word16 f[], /* (n) */
+ Word16 n,
+ Flag *pOverflow)
+{
+ Word16 i;
+ Word16 cheb;
+ Word16 b1_h;
+ Word16 b1_l;
+ Word32 t0;
+ Word32 L_temp;
+ Word16 *p_f = &f[1];
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ /* L_temp = 1.0 */
+
+ L_temp = 0x01000000L;
+
+ t0 = ((Word32) x << 10) + ((Word32) * (p_f++) << 14);
+
+ /* b1 = t0 = 2*x + f[1] */
+
+ b1_h = (Word16)(t0 >> 16);
+ b1_l = (Word16)((t0 >> 1) - (b1_h << 15));
+
+
+ for (i = 2; i < n; i++)
+ {
+ /* t0 = 2.0*x*b1 */
+ t0 = ((Word32) b1_h * x);
+ t0 += ((Word32) b1_l * x) >> 15;
+ t0 <<= 2;
+
+ /* t0 = 2.0*x*b1 - b2 */
+ t0 -= L_temp;
+
+ /* t0 = 2.0*x*b1 - b2 + f[i] */
+ t0 += (Word32) * (p_f++) << 14;
+
+ L_temp = ((Word32) b1_h << 16) + ((Word32) b1_l << 1);
+
+ /* b0 = 2.0*x*b1 - b2 + f[i]*/
+ b1_h = (Word16)(t0 >> 16);
+ b1_l = (Word16)((t0 >> 1) - (b1_h << 15));
+
+ }
+
+ /* t0 = x*b1; */
+ t0 = ((Word32) b1_h * x);
+ t0 += ((Word32) b1_l * x) >> 15;
+ t0 <<= 1;
+
+
+ /* t0 = x*b1 - b2 */
+ t0 -= L_temp;
+
+ /* t0 = x*b1 - b2 + f[i]/2 */
+ t0 += (Word32) * (p_f) << 13;
+
+
+ if ((UWord32)(t0 - 0xfe000000L) < (UWord32)0x03ffffffL)
+ {
+ cheb = (Word16)(t0 >> 10);
+ }
+ else
+ {
+ if (t0 > (Word32) 0x01ffffffL)
+ {
+ cheb = MAX_16;
+
+ }
+ else
+ {
+ cheb = MIN_16;
+ }
+ }
+
+ return (cheb);
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Az_lsp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS FOR Az_lsp
+
+ Inputs:
+ a = predictor coefficients (Word16)
+ lsp = line spectral pairs (Word16)
+ old_lsp = old line spectral pairs (Word16)
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the operations in the function resulted in saturation.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the LSPs from the LP coefficients.
+
+ The sum and difference filters are computed and divided by 1+z^{-1} and
+ 1-z^{-1}, respectively.
+
+ f1[i] = a[i] + a[11-i] - f1[i-1] ; i=1,...,5
+ f2[i] = a[i] - a[11-i] + f2[i-1] ; i=1,...,5
+
+ The roots of F1(z) and F2(z) are found using Chebyshev polynomial evaluation.
+ The polynomials are evaluated at 60 points regularly spaced in the
+ frequency domain. The sign change interval is subdivided 4 times to better
+ track the root. The LSPs are found in the cosine domain [1,-1].
+
+ If less than 10 roots are found, the LSPs from the past frame are used.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ az_lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Az_lsp (
+ Word16 a[], // (i) : predictor coefficients (MP1)
+ Word16 lsp[], // (o) : line spectral pairs (M)
+ Word16 old_lsp[] // (i) : old lsp[] (in case not found 10 roots) (M)
+)
+{
+ Word16 i, j, nf, ip;
+ Word16 xlow, ylow, xhigh, yhigh, xmid, ymid, xint;
+ Word16 x, y, sign, exp;
+ Word16 *coef;
+ Word16 f1[M / 2 + 1], f2[M / 2 + 1];
+ Word32 t0;
+
+ *-------------------------------------------------------------*
+ * find the sum and diff. pol. F1(z) and F2(z) *
+ * F1(z) <--- F1(z)/(1+z**-1) & F2(z) <--- F2(z)/(1-z**-1) *
+ * *
+ * f1[0] = 1.0; *
+ * f2[0] = 1.0; *
+ * *
+ * for (i = 0; i< NC; i++) *
+ * { *
+ * f1[i+1] = a[i+1] + a[M-i] - f1[i] ; *
+ * f2[i+1] = a[i+1] - a[M-i] + f2[i] ; *
+ * } *
+ *-------------------------------------------------------------*
+
+ f1[0] = 1024; // f1[0] = 1.0
+ f2[0] = 1024; // f2[0] = 1.0
+
+// The reference ETSI code uses a global flag for Overflow. However, in the
+// actual implementation a pointer to Overflow flag is passed in as a
+// parameter to the function. This pointer is passed into all the basic math
+// functions invoked
+
+ for (i = 0; i < NC; i++)
+ {
+ t0 = L_mult (a[i + 1], 8192); // x = (a[i+1] + a[M-i]) >> 2
+ t0 = L_mac (t0, a[M - i], 8192);
+ x = extract_h (t0);
+ // f1[i+1] = a[i+1] + a[M-i] - f1[i]
+ f1[i + 1] = sub (x, f1[i]);
+
+ t0 = L_mult (a[i + 1], 8192); // x = (a[i+1] - a[M-i]) >> 2
+ t0 = L_msu (t0, a[M - i], 8192);
+ x = extract_h (t0);
+ // f2[i+1] = a[i+1] - a[M-i] + f2[i]
+ f2[i + 1] = add (x, f2[i]);
+ }
+
+ *-------------------------------------------------------------*
+ * find the LSPs using the Chebychev pol. evaluation *
+ *-------------------------------------------------------------*
+
+ nf = 0; // number of found frequencies
+ ip = 0; // indicator for f1 or f2
+
+ coef = f1;
+
+ xlow = grid[0];
+ ylow = Chebps (xlow, coef, NC);
+
+ j = 0;
+ // while ( (nf < M) && (j < grid_points) )
+ while ((sub (nf, M) < 0) && (sub (j, grid_points) < 0))
+ {
+ j++;
+ xhigh = xlow;
+ yhigh = ylow;
+ xlow = grid[j];
+ ylow = Chebps (xlow, coef, NC);
+
+ if (L_mult (ylow, yhigh) <= (Word32) 0L)
+ {
+
+ // divide 4 times the interval
+
+ for (i = 0; i < 4; i++)
+ {
+ // xmid = (xlow + xhigh)/2
+ xmid = add (shr (xlow, 1), shr (xhigh, 1));
+ ymid = Chebps (xmid, coef, NC);
+
+ if (L_mult (ylow, ymid) <= (Word32) 0L)
+ {
+ yhigh = ymid;
+ xhigh = xmid;
+ }
+ else
+ {
+ ylow = ymid;
+ xlow = xmid;
+ }
+ }
+
+ *-------------------------------------------------------------*
+ * Linear interpolation *
+ * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow); *
+ *-------------------------------------------------------------*
+
+ x = sub (xhigh, xlow);
+ y = sub (yhigh, ylow);
+
+ if (y == 0)
+ {
+ xint = xlow;
+ }
+ else
+ {
+ sign = y;
+ y = abs_s (y);
+ exp = norm_s (y);
+ y = shl (y, exp);
+ y = div_s ((Word16) 16383, y);
+ t0 = L_mult (x, y);
+ t0 = L_shr (t0, sub (20, exp));
+ y = extract_l (t0); // y= (xhigh-xlow)/(yhigh-ylow)
+
+ if (sign < 0)
+ y = negate (y);
+
+ t0 = L_mult (ylow, y);
+ t0 = L_shr (t0, 11);
+ xint = sub (xlow, extract_l (t0)); // xint = xlow - ylow*y
+ }
+
+ lsp[nf] = xint;
+ xlow = xint;
+ nf++;
+
+ if (ip == 0)
+ {
+ ip = 1;
+ coef = f2;
+ }
+ else
+ {
+ ip = 0;
+ coef = f1;
+ }
+ ylow = Chebps (xlow, coef, NC);
+
+ }
+ }
+
+ // Check if M roots found
+
+ if (sub (nf, M) < 0)
+ {
+ for (i = 0; i < M; i++)
+ {
+ lsp[i] = old_lsp[i];
+ }
+
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Az_lsp(
+ Word16 a[], /* (i) : predictor coefficients (MP1) */
+ Word16 lsp[], /* (o) : line spectral pairs (M) */
+ Word16 old_lsp[], /* (i) : old lsp[] (in case not found 10 roots) (M) */
+ Flag *pOverflow /* (i/o): overflow flag */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 nf;
+ Word16 ip;
+ Word16 xlow;
+ Word16 ylow;
+ Word16 xhigh;
+ Word16 yhigh;
+ Word16 xmid;
+ Word16 ymid;
+ Word16 xint;
+ Word16 x;
+ Word16 y;
+ Word16 sign;
+ Word16 exp;
+ Word16 *coef;
+ Word16 f1[NC + 1];
+ Word16 f2[NC + 1];
+ Word32 L_temp1;
+ Word32 L_temp2;
+ Word16 *p_f1 = f1;
+ Word16 *p_f2 = f2;
+
+ /*-------------------------------------------------------------*
+ * find the sum and diff. pol. F1(z) and F2(z) *
+ * F1(z) <--- F1(z)/(1+z**-1) & F2(z) <--- F2(z)/(1-z**-1) *
+ * *
+ * f1[0] = 1.0; *
+ * f2[0] = 1.0; *
+ * *
+ * for (i = 0; i< NC; i++) *
+ * { *
+ * f1[i+1] = a[i+1] + a[M-i] - f1[i] ; *
+ * f2[i+1] = a[i+1] - a[M-i] + f2[i] ; *
+ * } *
+ *-------------------------------------------------------------*/
+
+ *p_f1 = 1024; /* f1[0] = 1.0 */
+ *p_f2 = 1024; /* f2[0] = 1.0 */
+
+ for (i = 0; i < NC; i++)
+ {
+ L_temp1 = (Word32) * (a + i + 1);
+ L_temp2 = (Word32) * (a + M - i);
+ /* x = (a[i+1] + a[M-i]) >> 2 */
+ x = (Word16)((L_temp1 + L_temp2) >> 2);
+ /* y = (a[i+1] - a[M-i]) >> 2 */
+ y = (Word16)((L_temp1 - L_temp2) >> 2);
+ /* f1[i+1] = a[i+1] + a[M-i] - f1[i] */
+ x -= *(p_f1++);
+ *(p_f1) = x;
+ /* f2[i+1] = a[i+1] - a[M-i] + f2[i] */
+ y += *(p_f2++);
+ *(p_f2) = y;
+ }
+
+ /*-------------------------------------------------------------*
+ * find the LSPs using the Chebychev pol. evaluation *
+ *-------------------------------------------------------------*/
+
+ nf = 0; /* number of found frequencies */
+ ip = 0; /* indicator for f1 or f2 */
+
+ coef = f1;
+
+ xlow = *(grid);
+ ylow = Chebps(xlow, coef, NC, pOverflow);
+
+ j = 0;
+
+ while ((nf < M) && (j < grid_points))
+ {
+ j++;
+ xhigh = xlow;
+ yhigh = ylow;
+ xlow = *(grid + j);
+ ylow = Chebps(xlow, coef, NC, pOverflow);
+
+ if (((Word32)ylow*yhigh) <= 0)
+ {
+ /* divide 4 times the interval */
+ for (i = 4; i != 0; i--)
+ {
+ /* xmid = (xlow + xhigh)/2 */
+ x = xlow >> 1;
+ y = xhigh >> 1;
+ xmid = x + y;
+
+ ymid = Chebps(xmid, coef, NC, pOverflow);
+
+ if (((Word32)ylow*ymid) <= 0)
+ {
+ yhigh = ymid;
+ xhigh = xmid;
+ }
+ else
+ {
+ ylow = ymid;
+ xlow = xmid;
+ }
+ }
+
+ /*-------------------------------------------------------------*
+ * Linear interpolation *
+ * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow); *
+ *-------------------------------------------------------------*/
+
+ x = xhigh - xlow;
+ y = yhigh - ylow;
+
+ if (y == 0)
+ {
+ xint = xlow;
+ }
+ else
+ {
+ sign = y;
+ y = abs_s(y);
+ exp = norm_s(y);
+ y <<= exp;
+ y = div_s((Word16) 16383, y);
+
+ y = ((Word32)x * y) >> (19 - exp);
+
+ if (sign < 0)
+ {
+ y = -y;
+ }
+
+ /* xint = xlow - ylow*y */
+ xint = xlow - (((Word32) ylow * y) >> 10);
+ }
+
+ *(lsp + nf) = xint;
+ xlow = xint;
+ nf++;
+
+ if (ip == 0)
+ {
+ ip = 1;
+ coef = f2;
+ }
+ else
+ {
+ ip = 0;
+ coef = f1;
+ }
+
+ ylow = Chebps(xlow, coef, NC, pOverflow);
+
+ }
+ }
+
+ /* Check if M roots found */
+
+ if (nf < M)
+ {
+ for (i = NC; i != 0 ; i--)
+ {
+ *lsp++ = *old_lsp++;
+ *lsp++ = *old_lsp++;
+ }
+ }
+
+}
+
+Word16 Chebps_Wrapper(Word16 x,
+ Word16 f[], /* (n) */
+ Word16 n,
+ Flag *pOverflow)
+{
+ return Chebps(x, f, n, pOverflow);
+}
+
diff --git a/media/codecs/amrnb/common/src/bitno_tab.cpp b/media/codecs/amrnb/common/src/bitno_tab.cpp
new file mode 100644
index 0000000..4ee04a5
--- /dev/null
+++ b/media/codecs/amrnb/common/src/bitno_tab.cpp
@@ -0,0 +1,309 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/src/bitno_tab.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Define "const Word16 *bitno[N_MODES]" as "const Word16 *const
+ bitno[N_MODES]"
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : bitno.tab
+ Purpose : Tables for bit2prm and prm2bit
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h" /* parameter sizes: MAX_PRM_SIZE */
+#include "mode.h" /* N_MODES */
+#include "bitno_tab.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ /* number of parameters per modes (values must be <= MAX_PRM_SIZE!) */
+ const Word16 prmno[N_MODES] =
+ {
+ PRMNO_MR475,
+ PRMNO_MR515,
+ PRMNO_MR59,
+ PRMNO_MR67,
+ PRMNO_MR74,
+ PRMNO_MR795,
+ PRMNO_MR102,
+ PRMNO_MR122,
+ PRMNO_MRDTX
+ };
+
+ /* number of parameters to first subframe per modes */
+ const Word16 prmnofsf[N_MODES - 1] =
+ {
+ PRMNOFSF_MR475,
+ PRMNOFSF_MR515,
+ PRMNOFSF_MR59,
+ PRMNOFSF_MR67,
+ PRMNOFSF_MR74,
+ PRMNOFSF_MR795,
+ PRMNOFSF_MR102,
+ PRMNOFSF_MR122
+ };
+
+ /* parameter sizes (# of bits), one table per mode */
+ const Word16 bitno_MR475[PRMNO_MR475] =
+ {
+ 8, 8, 7, /* LSP VQ */
+ 8, 7, 2, 8, /* first subframe */
+ 4, 7, 2, /* second subframe */
+ 4, 7, 2, 8, /* third subframe */
+ 4, 7, 2, /* fourth subframe */
+ };
+
+ const Word16 bitno_MR515[PRMNO_MR515] =
+ {
+ 8, 8, 7, /* LSP VQ */
+ 8, 7, 2, 6, /* first subframe */
+ 4, 7, 2, 6, /* second subframe */
+ 4, 7, 2, 6, /* third subframe */
+ 4, 7, 2, 6, /* fourth subframe */
+ };
+
+ const Word16 bitno_MR59[PRMNO_MR59] =
+ {
+ 8, 9, 9, /* LSP VQ */
+ 8, 9, 2, 6, /* first subframe */
+ 4, 9, 2, 6, /* second subframe */
+ 8, 9, 2, 6, /* third subframe */
+ 4, 9, 2, 6, /* fourth subframe */
+ };
+
+ const Word16 bitno_MR67[PRMNO_MR67] =
+ {
+ 8, 9, 9, /* LSP VQ */
+ 8, 11, 3, 7, /* first subframe */
+ 4, 11, 3, 7, /* second subframe */
+ 8, 11, 3, 7, /* third subframe */
+ 4, 11, 3, 7, /* fourth subframe */
+ };
+
+ const Word16 bitno_MR74[PRMNO_MR74] =
+ {
+ 8, 9, 9, /* LSP VQ */
+ 8, 13, 4, 7, /* first subframe */
+ 5, 13, 4, 7, /* second subframe */
+ 8, 13, 4, 7, /* third subframe */
+ 5, 13, 4, 7, /* fourth subframe */
+ };
+
+ const Word16 bitno_MR795[PRMNO_MR795] =
+ {
+ 9, 9, 9, /* LSP VQ */
+ 8, 13, 4, 4, 5, /* first subframe */
+ 6, 13, 4, 4, 5, /* second subframe */
+ 8, 13, 4, 4, 5, /* third subframe */
+ 6, 13, 4, 4, 5, /* fourth subframe */
+ };
+
+ const Word16 bitno_MR102[PRMNO_MR102] =
+ {
+ 8, 9, 9, /* LSP VQ */
+ 8, 1, 1, 1, 1, 10, 10, 7, 7, /* first subframe */
+ 5, 1, 1, 1, 1, 10, 10, 7, 7, /* second subframe */
+ 8, 1, 1, 1, 1, 10, 10, 7, 7, /* third subframe */
+ 5, 1, 1, 1, 1, 10, 10, 7, 7, /* fourth subframe */
+ };
+
+ const Word16 bitno_MR122[PRMNO_MR122] =
+ {
+ 7, 8, 9, 8, 6, /* LSP VQ */
+ 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* first subframe */
+ 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* second subframe */
+ 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* third subframe */
+ 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5 /* fourth subframe */
+ };
+
+ const Word16 bitno_MRDTX[PRMNO_MRDTX] =
+ {
+ 3,
+ 8, 9, 9,
+ 6
+ };
+
+ /* overall table with all parameter sizes for all modes */
+ const Word16 * const bitno[N_MODES] =
+ {
+ bitno_MR475,
+ bitno_MR515,
+ bitno_MR59,
+ bitno_MR67,
+ bitno_MR74,
+ bitno_MR795,
+ bitno_MR102,
+ bitno_MR122,
+ bitno_MRDTX
+ };
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
diff --git a/media/codecs/amrnb/common/src/bitreorder_tab.cpp b/media/codecs/amrnb/common/src/bitreorder_tab.cpp
new file mode 100644
index 0000000..e284bbc
--- /dev/null
+++ b/media/codecs/amrnb/common/src/bitreorder_tab.cpp
@@ -0,0 +1,422 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/src/bitreorder.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed file name to bitreorder_tab.c and .h. Also, updated the
+ module description.
+
+ Description: Define "const Word16 *reorderBits[NUM_MODES-1]" as
+ "const Word16 *const reorderBits[NUM_MODES-1]".
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition. Removed corresponding header file from Include
+ section.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function contains tables needed to reformat the encoded speech bits
+ into IF2, WMF, and ETS.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ AMR Speech Codec Frame Structure,
+ 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "bitreorder_tab.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NUM_MODES 16
+#define NUMBIT_MR475 95
+#define NUMBIT_MR515 103
+#define NUMBIT_MR59 118
+#define NUMBIT_MR67 134
+#define NUMBIT_MR74 148
+#define NUMBIT_MR795 159
+#define NUMBIT_MR102 204
+#define NUMBIT_MR122 244
+#define NUMBIT_AMR_SID 39
+#define NUMBIT_GSMEFR_SID 43
+#define NUMBIT_TDMAEFR_SID 38
+#define NUMBIT_PDCEFR_SID 37
+#define NUMBIT_UNUSED1 0
+#define NUMBIT_UNUSED2 0
+#define NUMBIT_UNUSED3 0
+#define NUMBIT_NO_DATA 0
+
+#define MAX_NUM_BITS 244
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ /* number of parameters per modes (values must be <= MAX_PRM_SIZE!) */
+ const Word16 numOfBits[NUM_MODES] =
+ {
+ NUMBIT_MR475,
+ NUMBIT_MR515,
+ NUMBIT_MR59,
+ NUMBIT_MR67,
+ NUMBIT_MR74,
+ NUMBIT_MR795,
+ NUMBIT_MR102,
+ NUMBIT_MR122,
+ NUMBIT_AMR_SID,
+ NUMBIT_GSMEFR_SID,
+ NUMBIT_TDMAEFR_SID,
+ NUMBIT_PDCEFR_SID,
+ NUMBIT_UNUSED1,
+ NUMBIT_UNUSED2,
+ NUMBIT_UNUSED3,
+ NUMBIT_NO_DATA
+ };
+
+ const Word16 reorderBits_MR475[NUMBIT_MR475] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 23, 24, 25, 26,
+ 27, 28, 48, 49, 61, 62, 82, 83, 47, 46,
+ 45, 44, 81, 80, 79, 78, 17, 18, 20, 22,
+ 77, 76, 75, 74, 29, 30, 43, 42, 41, 40,
+ 38, 39, 16, 19, 21, 50, 51, 59, 60, 63,
+ 64, 72, 73, 84, 85, 93, 94, 32, 33, 35,
+ 36, 53, 54, 56, 57, 66, 67, 69, 70, 87,
+ 88, 90, 91, 34, 55, 68, 89, 37, 58, 71,
+ 92, 31, 52, 65, 86
+ };
+
+ const Word16 reorderBits_MR515[NUMBIT_MR515] =
+ {
+ 7, 6, 5, 4, 3, 2, 1, 0, 15, 14,
+ 13, 12, 11, 10, 9, 8, 23, 24, 25, 26,
+ 27, 46, 65, 84, 45, 44, 43, 64, 63, 62,
+ 83, 82, 81, 102, 101, 100, 42, 61, 80, 99,
+ 28, 47, 66, 85, 18, 41, 60, 79, 98, 29,
+ 48, 67, 17, 20, 22, 40, 59, 78, 97, 21,
+ 30, 49, 68, 86, 19, 16, 87, 39, 38, 58,
+ 57, 77, 35, 54, 73, 92, 76, 96, 95, 36,
+ 55, 74, 93, 32, 51, 33, 52, 70, 71, 89,
+ 90, 31, 50, 69, 88, 37, 56, 75, 94, 34,
+ 53, 72, 91
+ };
+
+ const Word16 reorderBits_MR59[NUMBIT_MR59] =
+ {
+ 0, 1, 4, 5, 3, 6, 7, 2, 13, 15,
+ 8, 9, 11, 12, 14, 10, 16, 28, 74, 29,
+ 75, 27, 73, 26, 72, 30, 76, 51, 97, 50,
+ 71, 96, 117, 31, 77, 52, 98, 49, 70, 95,
+ 116, 53, 99, 32, 78, 33, 79, 48, 69, 94,
+ 115, 47, 68, 93, 114, 46, 67, 92, 113, 19,
+ 21, 23, 22, 18, 17, 20, 24, 111, 43, 89,
+ 110, 64, 65, 44, 90, 25, 45, 66, 91, 112,
+ 54, 100, 40, 61, 86, 107, 39, 60, 85, 106,
+ 36, 57, 82, 103, 35, 56, 81, 102, 34, 55,
+ 80, 101, 42, 63, 88, 109, 41, 62, 87, 108,
+ 38, 59, 84, 105, 37, 58, 83, 104
+ };
+
+ const Word16 reorderBits_MR67[NUMBIT_MR67] =
+ {
+ 0, 1, 4, 3, 5, 6, 13, 7, 2, 8,
+ 9, 11, 15, 12, 14, 10, 28, 82, 29, 83,
+ 27, 81, 26, 80, 30, 84, 16, 55, 109, 56,
+ 110, 31, 85, 57, 111, 48, 73, 102, 127, 32,
+ 86, 51, 76, 105, 130, 52, 77, 106, 131, 58,
+ 112, 33, 87, 19, 23, 53, 78, 107, 132, 21,
+ 22, 18, 17, 20, 24, 25, 50, 75, 104, 129,
+ 47, 72, 101, 126, 54, 79, 108, 133, 46, 71,
+ 100, 125, 128, 103, 74, 49, 45, 70, 99, 124,
+ 42, 67, 96, 121, 39, 64, 93, 118, 38, 63,
+ 92, 117, 35, 60, 89, 114, 34, 59, 88, 113,
+ 44, 69, 98, 123, 43, 68, 97, 122, 41, 66,
+ 95, 120, 40, 65, 94, 119, 37, 62, 91, 116,
+ 36, 61, 90, 115
+ };
+
+ const Word16 reorderBits_MR74[NUMBIT_MR74] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 26, 87, 27,
+ 88, 28, 89, 29, 90, 30, 91, 51, 80, 112,
+ 141, 52, 81, 113, 142, 54, 83, 115, 144, 55,
+ 84, 116, 145, 58, 119, 59, 120, 21, 22, 23,
+ 17, 18, 19, 31, 60, 92, 121, 56, 85, 117,
+ 146, 20, 24, 25, 50, 79, 111, 140, 57, 86,
+ 118, 147, 49, 78, 110, 139, 48, 77, 53, 82,
+ 114, 143, 109, 138, 47, 76, 108, 137, 32, 33,
+ 61, 62, 93, 94, 122, 123, 41, 42, 43, 44,
+ 45, 46, 70, 71, 72, 73, 74, 75, 102, 103,
+ 104, 105, 106, 107, 131, 132, 133, 134, 135, 136,
+ 34, 63, 95, 124, 35, 64, 96, 125, 36, 65,
+ 97, 126, 37, 66, 98, 127, 38, 67, 99, 128,
+ 39, 68, 100, 129, 40, 69, 101, 130
+ };
+
+ const Word16 reorderBits_MR795[NUMBIT_MR795] =
+ {
+ 8, 7, 6, 5, 4, 3, 2, 14, 16, 9,
+ 10, 12, 13, 15, 11, 17, 20, 22, 24, 23,
+ 19, 18, 21, 56, 88, 122, 154, 57, 89, 123,
+ 155, 58, 90, 124, 156, 52, 84, 118, 150, 53,
+ 85, 119, 151, 27, 93, 28, 94, 29, 95, 30,
+ 96, 31, 97, 61, 127, 62, 128, 63, 129, 59,
+ 91, 125, 157, 32, 98, 64, 130, 1, 0, 25,
+ 26, 33, 99, 34, 100, 65, 131, 66, 132, 54,
+ 86, 120, 152, 60, 92, 126, 158, 55, 87, 121,
+ 153, 117, 116, 115, 46, 78, 112, 144, 43, 75,
+ 109, 141, 40, 72, 106, 138, 36, 68, 102, 134,
+ 114, 149, 148, 147, 146, 83, 82, 81, 80, 51,
+ 50, 49, 48, 47, 45, 44, 42, 39, 35, 79,
+ 77, 76, 74, 71, 67, 113, 111, 110, 108, 105,
+ 101, 145, 143, 142, 140, 137, 133, 41, 73, 107,
+ 139, 37, 69, 103, 135, 38, 70, 104, 136
+ };
+
+ const Word16 reorderBits_MR102[NUMBIT_MR102] =
+ {
+ 7, 6, 5, 4, 3, 2, 1, 0, 16, 15,
+ 14, 13, 12, 11, 10, 9, 8, 26, 27, 28,
+ 29, 30, 31, 115, 116, 117, 118, 119, 120, 72,
+ 73, 161, 162, 65, 68, 69, 108, 111, 112, 154,
+ 157, 158, 197, 200, 201, 32, 33, 121, 122, 74,
+ 75, 163, 164, 66, 109, 155, 198, 19, 23, 21,
+ 22, 18, 17, 20, 24, 25, 37, 36, 35, 34,
+ 80, 79, 78, 77, 126, 125, 124, 123, 169, 168,
+ 167, 166, 70, 67, 71, 113, 110, 114, 159, 156,
+ 160, 202, 199, 203, 76, 165, 81, 82, 92, 91,
+ 93, 83, 95, 85, 84, 94, 101, 102, 96, 104,
+ 86, 103, 87, 97, 127, 128, 138, 137, 139, 129,
+ 141, 131, 130, 140, 147, 148, 142, 150, 132, 149,
+ 133, 143, 170, 171, 181, 180, 182, 172, 184, 174,
+ 173, 183, 190, 191, 185, 193, 175, 192, 176, 186,
+ 38, 39, 49, 48, 50, 40, 52, 42, 41, 51,
+ 58, 59, 53, 61, 43, 60, 44, 54, 194, 179,
+ 189, 196, 177, 195, 178, 187, 188, 151, 136, 146,
+ 153, 134, 152, 135, 144, 145, 105, 90, 100, 107,
+ 88, 106, 89, 98, 99, 62, 47, 57, 64, 45,
+ 63, 46, 55, 56
+ };
+
+ const Word16 reorderBits_MR122[NUMBIT_MR122] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 23, 15, 16, 17, 18,
+ 19, 20, 21, 22, 24, 25, 26, 27, 28, 38,
+ 141, 39, 142, 40, 143, 41, 144, 42, 145, 43,
+ 146, 44, 147, 45, 148, 46, 149, 47, 97, 150,
+ 200, 48, 98, 151, 201, 49, 99, 152, 202, 86,
+ 136, 189, 239, 87, 137, 190, 240, 88, 138, 191,
+ 241, 91, 194, 92, 195, 93, 196, 94, 197, 95,
+ 198, 29, 30, 31, 32, 33, 34, 35, 50, 100,
+ 153, 203, 89, 139, 192, 242, 51, 101, 154, 204,
+ 55, 105, 158, 208, 90, 140, 193, 243, 59, 109,
+ 162, 212, 63, 113, 166, 216, 67, 117, 170, 220,
+ 36, 37, 54, 53, 52, 58, 57, 56, 62, 61,
+ 60, 66, 65, 64, 70, 69, 68, 104, 103, 102,
+ 108, 107, 106, 112, 111, 110, 116, 115, 114, 120,
+ 119, 118, 157, 156, 155, 161, 160, 159, 165, 164,
+ 163, 169, 168, 167, 173, 172, 171, 207, 206, 205,
+ 211, 210, 209, 215, 214, 213, 219, 218, 217, 223,
+ 222, 221, 73, 72, 71, 76, 75, 74, 79, 78,
+ 77, 82, 81, 80, 85, 84, 83, 123, 122, 121,
+ 126, 125, 124, 129, 128, 127, 132, 131, 130, 135,
+ 134, 133, 176, 175, 174, 179, 178, 177, 182, 181,
+ 180, 185, 184, 183, 188, 187, 186, 226, 225, 224,
+ 229, 228, 227, 232, 231, 230, 235, 234, 233, 238,
+ 237, 236, 96, 199
+ };
+
+ /* overall table with all parameter sizes for all modes */
+ const Word16 * const reorderBits[NUM_MODES-1] =
+ {
+ reorderBits_MR475,
+ reorderBits_MR515,
+ reorderBits_MR59,
+ reorderBits_MR67,
+ reorderBits_MR74,
+ reorderBits_MR795,
+ reorderBits_MR102,
+ reorderBits_MR122
+ };
+
+ /* Number of Frames (16-bit segments sent for each mode */
+ const Word16 numCompressedBytes[16] =
+ {
+ 13, /*4.75*/
+ 14, /*5.15*/
+ 16, /*5.90*/
+ 18, /*6.70*/
+ 19, /*7.40*/
+ 21, /*7.95*/
+ 26, /*10.2*/
+ 31, /*12.2*/
+ 6, /*GsmAmr comfort noise*/
+ 6, /*Gsm-Efr comfort noise*/
+ 6, /*IS-641 comfort noise*/
+ 6, /*Pdc-Efr comfort noise*/
+ 0, /*future use*/
+ 0, /*future use*/
+ 0, /*future use*/
+ 1 /*No transmission*/
+ };
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
+
+
+
diff --git a/media/codecs/amrnb/common/src/bits2prm.cpp b/media/codecs/amrnb/common/src/bits2prm.cpp
new file mode 100644
index 0000000..1d6f7b1
--- /dev/null
+++ b/media/codecs/amrnb/common/src/bits2prm.cpp
@@ -0,0 +1,292 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/bits2prm.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Fixed a typo in the include section. Optimized some lines of
+ code as per review comments.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "bits2prm.h"
+#include "typedef.h"
+#include "mode.h"
+#include "bitno_tab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Bin2int
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ no_of_bits = number of bits associated with value
+ bitstream = pointer to buffer where bits are read
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function : Bin2int
+ Purpose : Read "no_of_bits" bits from the array bitstream[]
+ and convert to integer.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static Word16 Bin2int ( // Reconstructed parameter
+ Word16 no_of_bits, // input : number of bits associated with value
+ Word16 *bitstream // output: address where bits are written
+)
+{
+ Word16 value, i, bit;
+
+ value = 0;
+ for (i = 0; i < no_of_bits; i++)
+ {
+ value = shl (value, 1);
+ bit = *bitstream++;
+ if (sub (bit, BIT_1) == 0)
+ value = add (value, 1);
+ }
+ return (value);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+static Word16 Bin2int( /* Reconstructed parameter */
+ Word16 no_of_bits, /* input : number of bits associated with value */
+ Word16 *bitstream /* input: address where bits are read from */
+)
+{
+ Word16 value;
+ Word16 i;
+ Word16 single_bit;
+
+ value = 0;
+ for (i = 0; i < no_of_bits; i++)
+ {
+ value <<= 1;
+ single_bit = *(bitstream++);
+ value |= single_bit;
+ }
+ return (value);
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: bits2prm
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode = AMR mode of type enum Mode
+ bits[] = pointer to serial bits of type Word16
+ prm[] = pointer to analysis parameters of type Word16
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function : Bits2prm
+ Purpose : Retrieves the vector of encoder parameters from
+ the received serial bits in a frame.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Bits2prm (
+ enum Mode mode, // i : AMR mode
+ Word16 bits[], // i : serial bits (size <= MAX_SERIAL_SIZE)
+ Word16 prm[] // o : analysis parameters (size <= MAX_PRM_SIZE)
+)
+{
+ Word16 i;
+
+ for (i = 0; i < prmno[mode]; i++)
+ {
+ prm[i] = Bin2int (bitno[mode][i], bits);
+ bits += bitno[mode][i];
+ add(0,0); // account for above pointer update
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+OSCL_EXPORT_REF void Bits2prm(
+ enum Mode mode, /* i : AMR mode */
+ Word16 bits[], /* i : serial bits (size <= MAX_SERIAL_SIZE) */
+ Word16 prm[] /* o : analysis parameters (size <= MAX_PRM_SIZE) */
+)
+{
+ Word16 i;
+
+ for (i = 0; i < prmno[mode]; i++)
+ {
+ prm[i] = Bin2int(bitno[mode][i], bits);
+ bits += bitno[mode][i];
+ }
+
+ return;
+}
+
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/common/src/c2_9pf_tab.cpp b/media/codecs/amrnb/common/src/c2_9pf_tab.cpp
new file mode 100644
index 0000000..20de9d6
--- /dev/null
+++ b/media/codecs/amrnb/common/src/c2_9pf_tab.cpp
@@ -0,0 +1,166 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/c2_9pf_tab.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ (1) Corrected the module description
+ (2) Corrected the filename in the template.
+ (3) Removed embedded tabs.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the declaration for startPos[] used by the functions
+ c2_9pf.c and d2_9pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+ extern const Word16 startPos[];
+ const Word16 startPos[2*4*2] = {0, 2, 0, 3,
+ 0, 2, 0, 3,
+ 1, 3, 2, 4,
+ 1, 4, 1, 4
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c2_9pf.c UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
diff --git a/media/codecs/amrnb/common/src/copy.cpp b/media/codecs/amrnb/common/src/copy.cpp
new file mode 100644
index 0000000..75890b2
--- /dev/null
+++ b/media/codecs/amrnb/common/src/copy.cpp
@@ -0,0 +1,87 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+* File : copy.h
+*
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+* MODULE INCLUDE FILE AND VERSION ID
+********************************************************************************
+*/
+#include "copy.h"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include <string.h>
+
+#include "typedef.h"
+#include "basic_op.h"
+
+/*
+********************************************************************************
+* PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+/*************************************************************************
+ *
+ * FUNCTION: Copy
+ *
+ * PURPOSE: Copy vector x[] to y[]
+ *
+ *
+ *************************************************************************/
+/*
+**************************************************************************
+*
+* Function : Copy
+* Purpose : Copy vector x[] to y[]
+*
+**************************************************************************
+*/
+void Copy(
+ const Word16 x[], /* i : input vector (L) */
+ Word16 y[], /* o : output vector (L) */
+ Word16 L /* i : vector length */
+)
+{
+ memmove(y, x, L*sizeof(*x));
+}
diff --git a/media/codecs/amrnb/common/src/div_32.cpp b/media/codecs/amrnb/common/src/div_32.cpp
new file mode 100644
index 0000000..143e37c
--- /dev/null
+++ b/media/codecs/amrnb/common/src/div_32.cpp
@@ -0,0 +1,209 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/div_32.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Changed function interface to pass in a
+ pointer to overflow flag into the function instead of using a
+ global flag. Removed inclusion of unwanted header files. Changed
+ the name of input and output variables for clarity.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced l_extract functionality, code size and speed
+ do not justify calling this function
+ 3. Eliminated sub() function call, replace by (-), this knowing
+ that the result will not saturate.
+
+ Description: Added casting to eliminate warnings
+
+ Who: Date:
+ Description:
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: div_32
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_num = 32 bit signed integer (Word32) whose value falls in the
+ range : 0x0000 0000 < L_num < L_denom
+ L_denom_hi = 16 bit positive normalized integer whose value falls in
+ the range : 0x4000 < hi < 0x7fff
+ L_denom_lo = 16 bit positive integer whose value falls in the range :
+ 0 < lo < 0x7fff
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit divide operation resulted in overflow
+
+ Returns:
+ result = 32-bit quotient of of the division of two 32 bit integers
+ L_num / L_denom (Word32)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function is a fractional integer division of two 32 bit numbers, the
+ numerator L_num and the denominator L_denom. The denominator is formed by
+ combining denom_hi and denom_lo. Note that denom_hi is a normalized numbers.
+ The numerator and denominator must be positive and the numerator must be
+ less than the denominator.
+
+ The division is done as follows:
+ 1. Find 1/L_denom by first approximating: approx = 1 / denom_hi.
+ 2. 1/L_denom = approx * (2.0 - L_denom * approx ).
+ 3. result = L_num * (1/L_denom).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] div_32() function in oper_32b.c, UMTS GSM AMR speech codec, R99 -
+ Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word32 Div_32(Word32 L_num,
+ Word16 L_denom_hi,
+ Word16 L_denom_lo,
+ Flag *pOverflow)
+{
+
+ Word16 approx;
+ Word16 hi;
+ Word16 lo;
+ Word16 n_hi;
+ Word16 n_lo;
+ Word32 result;
+
+ /* First approximation: 1 / L_denom = 1/L_denom_hi */
+
+ approx = div_s((Word16) 0x3fff, L_denom_hi);
+
+ /* 1/L_denom = approx * (2.0 - L_denom * approx) */
+
+ result = Mpy_32_16(L_denom_hi, L_denom_lo, approx, pOverflow);
+ /* result is > 0 , and less than 1.0 */
+ result = 0x7fffffffL - result;
+
+ hi = (Word16)(result >> 16);
+ lo = (result >> 1) - (hi << 15);
+
+ result = Mpy_32_16(hi, lo, approx, pOverflow);
+
+ /* L_num * (1/L_denom) */
+
+ hi = (Word16)(result >> 16);
+ lo = (result >> 1) - (hi << 15);
+
+ n_hi = (Word16)(L_num >> 16);
+ n_lo = (L_num >> 1) - (n_hi << 15);
+
+ result = Mpy_32(n_hi, n_lo, hi, lo, pOverflow);
+ result = L_shl(result, 2, pOverflow);
+
+ return (result);
+}
+
diff --git a/media/codecs/amrnb/common/src/div_s.cpp b/media/codecs/amrnb/common/src/div_s.cpp
new file mode 100644
index 0000000..14d30c5
--- /dev/null
+++ b/media/codecs/amrnb/common/src/div_s.cpp
@@ -0,0 +1,277 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/src/div_s.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the div_s function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Making changes based on review meeting.
+
+ Description: Made changes based on P3 review meeting.
+
+ Description: Changing abort() to exit(0).
+
+ Description: Made the following changes
+ 1. Unrolled the division loop to make three comparison per
+ pass, using only five iterations of the loop and saving
+ shifts cycles
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit signed integer (Word16) whose value falls in
+ the range : 0x0000 <= var1 <= 0x7fff.
+ var2 = 16 bit signed integer (Word16) whose value falls in
+ the range : 0x0000 <= var1 <= 0x7fff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ var_out = quotient of var1 divided by var2 (Word16)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function produces a result which is the fractional integer division of
+ var1 by var2; var1 and var2 must be positive and var2 must be greater or equal
+ to var1; the result is positive (leading bit equal to 0) and truncated to 16
+ bits. If var1 = var2 then div(var1,var2) = 32767.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 div_s (Word16 var1, Word16 var2)
+{
+ Word16 var_out = 0;
+ Word16 iteration;
+ Word32 L_num;
+ Word32 L_denom;
+ Word16 abort_flag = 0;
+
+ if ((var1 > var2) || (var1 < 0))
+ {
+ printf ("Division Error var1=%d var2=%d\n", var1, var2);
+ abort_flag = 1;
+ exit(0);
+ }
+ if ((var1 != 0) && (abort_flag == 0))
+ {
+ if (var1 == var2)
+ {
+ var_out = MAX_16;
+ }
+ else
+ {
+ L_num = (Word32) var1;
+ L_denom = (Word32) var2;
+
+ for (iteration = 15; iteration > 0; iteration--)
+ {
+ var_out <<= 1;
+ L_num <<= 1;
+
+ if (L_num >= L_denom)
+ {
+ L_num -= L_denom;
+ var_out += 1;
+ }
+ }
+ }
+ }
+
+#if (WMOPS)
+ multiCounter[currCounter].div_s++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 div_s(Word16 var1, Word16 var2)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ Word16 var_out = 0;
+ Word16 iteration;
+ Word32 L_num;
+ Word32 L_denom;
+ Word32 L_denom_by_2;
+ Word32 L_denom_by_4;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ if ((var1 > var2) || (var1 < 0))
+ {
+ return 0; // used to exit(0);
+ }
+ if (var1)
+ {
+ if (var1 != var2)
+ {
+
+ L_num = (Word32) var1;
+ L_denom = (Word32) var2;
+ L_denom_by_2 = (L_denom << 1);
+ L_denom_by_4 = (L_denom << 2);
+ for (iteration = 5; iteration > 0; iteration--)
+ {
+ var_out <<= 3;
+ L_num <<= 3;
+
+ if (L_num >= L_denom_by_4)
+ {
+ L_num -= L_denom_by_4;
+ var_out |= 4;
+ }
+
+ if (L_num >= L_denom_by_2)
+ {
+ L_num -= L_denom_by_2;
+ var_out |= 2;
+ }
+
+ if (L_num >= (L_denom))
+ {
+ L_num -= (L_denom);
+ var_out |= 1;
+ }
+
+ }
+ }
+ else
+ {
+ var_out = MAX_16;
+ }
+ }
+
+#if (WMOPS)
+ multiCounter[currCounter].div_s++;
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return (var_out);
+}
diff --git a/media/codecs/amrnb/common/src/extract_h.cpp b/media/codecs/amrnb/common/src/extract_h.cpp
new file mode 100644
index 0000000..e538f9f
--- /dev/null
+++ b/media/codecs/amrnb/common/src/extract_h.cpp
@@ -0,0 +1,177 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/src/extract_h.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the extract_h function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32 ) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ L_var1 = Most significant word of input (Word16)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function returns the 16 MSB of the input, L_var1.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 extract_h (Word32 L_var1)
+{
+ Word16 var_out;
+
+ var_out = (Word16) (L_var1 >> 16);
+#if (WMOPS)
+ multiCounter[currCounter].extract_h++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 extract_h(Word32 L_var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return ((Word16)(L_var1 >> 16));
+}
diff --git a/media/codecs/amrnb/common/src/extract_l.cpp b/media/codecs/amrnb/common/src/extract_l.cpp
new file mode 100644
index 0000000..dbb9a6e
--- /dev/null
+++ b/media/codecs/amrnb/common/src/extract_l.cpp
@@ -0,0 +1,176 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/src/extract_l.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the extract_l function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32 ) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ L_var1 = Most significant word of input (Word16)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function returns the 16 LSB of the input, L_var1.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 extract_l (Word32 L_var1)
+{
+ Word16 var_out;
+
+ var_out = (Word16) L_var1;
+#if (WMOPS)
+ multiCounter[currCounter].extract_l++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 extract_l(Word32 L_var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return ((Word16) L_var1);
+}
diff --git a/media/codecs/amrnb/common/src/gains_tbl.cpp b/media/codecs/amrnb/common/src/gains_tbl.cpp
new file mode 100644
index 0000000..a7cd6fb
--- /dev/null
+++ b/media/codecs/amrnb/common/src/gains_tbl.cpp
@@ -0,0 +1,219 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/gains_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created this file from the reference, gains.tab
+
+ Description: Added include of "typedef.h" to includes section.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+#define NB_QUA_PITCH 16
+#define NB_QUA_CODE 32
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+
+ extern const Word16 qua_gain_pitch[];
+ const Word16 qua_gain_pitch[NB_QUA_PITCH] =
+ {
+ 0, 3277, 6556, 8192, 9830, 11469, 12288, 13107,
+ 13926, 14746, 15565, 16384, 17203, 18022, 18842, 19661
+ };
+
+
+ extern const Word16 qua_gain_code[];
+ const Word16 qua_gain_code[(NB_QUA_CODE+1)*3] =
+ {
+ /* gain factor (g_fac) and quantized energy error (qua_ener_MR122, qua_ener)
+ * are stored:
+ *
+ * qua_ener_MR122 = log2(g_fac) (not the rounded floating point value, but
+ * the value the original EFR algorithm
+ * calculates from g_fac [using Log2])
+ * qua_ener = 20*log10(g_fac); (rounded floating point value)
+ *
+ *
+ * g_fac (Q11), qua_ener_MR122 (Q10), qua_ener (Q10)
+ */
+ 159, -3776, -22731,
+ 206, -3394, -20428,
+ 268, -3005, -18088,
+ 349, -2615, -15739,
+ 419, -2345, -14113,
+ 482, -2138, -12867,
+ 554, -1932, -11629,
+ 637, -1726, -10387,
+ 733, -1518, -9139,
+ 842, -1314, -7906,
+ 969, -1106, -6656,
+ 1114, -900, -5416,
+ 1281, -694, -4173,
+ 1473, -487, -2931,
+ 1694, -281, -1688,
+ 1948, -75, -445,
+ 2241, 133, 801,
+ 2577, 339, 2044,
+ 2963, 545, 3285,
+ 3408, 752, 4530,
+ 3919, 958, 5772,
+ 4507, 1165, 7016,
+ 5183, 1371, 8259,
+ 5960, 1577, 9501,
+ 6855, 1784, 10745,
+ 7883, 1991, 11988,
+ 9065, 2197, 13231,
+ 10425, 2404, 14474,
+ 12510, 2673, 16096,
+ 16263, 3060, 18429,
+ 21142, 3448, 20763,
+ 27485, 3836, 23097,
+ 27485, 3836, 23097
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] gains.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
diff --git a/media/codecs/amrnb/common/src/gc_pred.cpp b/media/codecs/amrnb/common/src/gc_pred.cpp
new file mode 100644
index 0000000..731dc52
--- /dev/null
+++ b/media/codecs/amrnb/common/src/gc_pred.cpp
@@ -0,0 +1,1046 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/gc_pred.c
+ Functions:
+ gc_pred_reset
+ gc_pred
+ gc_pred_update
+ gc_pred_average_limited
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that perform codebook gain MA prediction.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "gc_pred.h"
+#include "basicop_malloc.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "log2.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NPRED 4 /* number of prediction taps */
+
+/* average innovation energy. */
+/* MEAN_ENER = 36.0/constant, constant = 20*Log10(2) */
+#define MEAN_ENER_MR122 783741L /* 36/(20*log10(2)) (Q17) */
+
+/* minimum quantized energy: -14 dB */
+#define MIN_ENERGY (-14336) /* 14 Q10 */
+#define MIN_ENERGY_MR122 (-2381) /* 14 / (20*log10(2)) Q10 */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* MA prediction coefficients (Q13) */
+static const Word16 pred[NPRED] = {5571, 4751, 2785, 1556};
+
+/* MA prediction coefficients (Q6) */
+static const Word16 pred_MR122[NPRED] = {44, 37, 22, 12};
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gc_pred_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type gc_predState
+
+ Outputs:
+ past_qua_en field in the structure pointed to by state is initialized
+ to MIN_ENERGY
+ past_qua_en_MR122 field in the structure pointed to by state is
+ initialized to MIN_ENERGY_MR122
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes the state memory used by gc_pred to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int gc_pred_reset (gc_predState *state)
+{
+ Word16 i;
+
+ if (state == (gc_predState *) NULL){
+ fprintf(stderr, "gc_pred_reset: invalid parameter\n");
+ return -1;
+ }
+
+ for(i = 0; i < NPRED; i++)
+ {
+ state->past_qua_en[i] = MIN_ENERGY;
+ state->past_qua_en_MR122[i] = MIN_ENERGY_MR122;
+ }
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 gc_pred_reset(gc_predState *state)
+{
+ Word16 i;
+
+ if (state == (gc_predState *) NULL)
+ {
+ /* fprintf(stderr, "gc_pred_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ for (i = 0; i < NPRED; i++)
+ {
+ state->past_qua_en[i] = MIN_ENERGY;
+ state->past_qua_en_MR122[i] = MIN_ENERGY_MR122;
+ }
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gc_pred
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type gc_predState
+ mode = AMR mode (enum Mode)
+ code = pointer to the innovative codebook vector; Q12 in MR122 mode,
+ otherwise, Q13 (Word16)
+ exp_gcode0 = pointer to the exponent part of predicted gain factor
+ (Q0) (Word16)
+ frac_gcode0 = pointer to the fractional part of predicted gain factor
+ (Q15) (Word16)
+ exp_en = pointer to the exponent part of the innovation energy; this
+ is calculated for MR795 mode, Q0 (Word16)
+ frac_en = pointer to the fractional part of the innovation energy;
+ this is calculated for MR795 mode, Q15 (Word16)
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ store pointed to by exp_gcode0 contains the exponent part of the
+ recently calculated predicted gain factor
+ store pointed to by frac_gcode0 contains the fractional part of the
+ recently calculated predicted gain factor
+ store pointed to by exp_en contains the exponent part of the
+ recently calculated innovation energy
+ store pointed to by frac_en contains the fractional part of the
+ recently calculated innovation energy
+ pOverflow = 1 if the math functions called by gc_pred
+ results in overflow else zero.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ pred = table of MA prediction coefficients (Q13) (Word16)
+ pred_MR122 = table of MA prediction coefficients (Q6) (Word16)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the MA prediction of the innovation energy (in
+ dB/(20*log10(2))), with the mean removed.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+The original etsi reference code uses a global flag Overflow. However, in the
+actual implementation a pointer to a the overflow flag is passed in.
+
+void
+gc_pred(
+ gc_predState *st, // i/o: State struct
+ enum Mode mode, // i : AMR mode
+ Word16 *code, // i : innovative codebook vector (L_SUBFR)
+ // MR122: Q12, other modes: Q13
+ Word16 *exp_gcode0, // o : exponent of predicted gain factor, Q0
+ Word16 *frac_gcode0,// o : fraction of predicted gain factor Q15
+ Word16 *exp_en, // o : exponent of innovation energy, Q0
+ // (only calculated for MR795)
+ Word16 *frac_en // o : fraction of innovation energy, Q15
+ // (only calculated for MR795)
+)
+{
+ Word16 i;
+ Word32 ener_code;
+ Word16 exp, frac;
+
+ *-------------------------------------------------------------------*
+ * energy of code: *
+ * ~~~~~~~~~~~~~~~ *
+ * ener_code = sum(code[i]^2) *
+ *-------------------------------------------------------------------*
+ ener_code = L_mac((Word32) 0, code[0], code[0]);
+ // MR122: Q12*Q12 -> Q25
+ // others: Q13*Q13 -> Q27
+ for (i = 1; i < L_SUBFR; i++)
+ ener_code = L_mac(ener_code, code[i], code[i]);
+
+ if (sub (mode, MR122) == 0)
+ {
+ Word32 ener;
+
+ // ener_code = ener_code / lcode; lcode = 40; 1/40 = 26214 Q20
+ ener_code = L_mult (pv_round (ener_code), 26214); // Q9 * Q20 -> Q30
+
+ *-------------------------------------------------------------------*
+ * energy of code: *
+ * ~~~~~~~~~~~~~~~ *
+ * ener_code(Q17) = 10 * Log10(energy) / constant *
+ * = 1/2 * Log2(energy) *
+ * constant = 20*Log10(2) *
+ *-------------------------------------------------------------------*
+ // ener_code = 1/2 * Log2(ener_code); Note: Log2=log2+30
+ Log2(ener_code, &exp, &frac);
+ ener_code = L_Comp (sub (exp, 30), frac); // Q16 for log()
+ // ->Q17 for 1/2 log()
+
+ *-------------------------------------------------------------------*
+ * predicted energy: *
+ * ~~~~~~~~~~~~~~~~~ *
+ * ener(Q24) = (Emean + sum{pred[i]*past_en[i]})/constant *
+ * = MEAN_ENER + sum(pred[i]*past_qua_en[i]) *
+ * constant = 20*Log10(2) *
+ *-------------------------------------------------------------------*
+
+ ener = MEAN_ENER_MR122; // Q24 (Q17)
+ for (i = 0; i < NPRED; i++)
+ {
+ ener = L_mac (ener, st->past_qua_en_MR122[i], pred_MR122[i]);
+ // Q10 * Q13 -> Q24
+ // Q10 * Q6 -> Q17
+ }
+
+ *-------------------------------------------------------------------*
+ * predicted codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = Pow10( (ener*constant - ener_code*constant) / 20 ) *
+ * = Pow2(ener-ener_code) *
+ * = Pow2(int(d)+frac(d)) *
+ * *
+ * (store exp and frac for pow2()) *
+ *-------------------------------------------------------------------*
+
+ ener = L_shr (L_sub (ener, ener_code), 1); // Q16
+ L_Extract(ener, exp_gcode0, frac_gcode0);
+ }
+ else // all modes except 12.2
+ {
+ Word32 L_tmp;
+ Word16 exp_code, gcode0;
+
+ *-----------------------------------------------------------------*
+ * Compute: means_ener - 10log10(ener_code/ L_sufr) *
+ *-----------------------------------------------------------------*
+
+ exp_code = norm_l (ener_code);
+ ener_code = L_shl (ener_code, exp_code);
+
+ // Log2 = log2 + 27
+ Log2_norm (ener_code, exp_code, &exp, &frac);
+
+ // fact = 10/log2(10) = 3.01 = 24660 Q13
+ L_tmp = Mpy_32_16(exp, frac, -24660); // Q0.Q15 * Q13 -> Q14
+
+ * L_tmp = means_ener - 10log10(ener_code/L_SUBFR)
+ * = means_ener - 10log10(ener_code) + 10log10(L_SUBFR)
+ * = K - fact * Log2(ener_code)
+ * = K - fact * log2(ener_code) - fact*27
+ *
+ * ==> K = means_ener + fact*27 + 10log10(L_SUBFR)
+ *
+ * means_ener = 33 = 540672 Q14 (MR475, MR515, MR59)
+ * means_ener = 28.75 = 471040 Q14 (MR67)
+ * means_ener = 30 = 491520 Q14 (MR74)
+ * means_ener = 36 = 589824 Q14 (MR795)
+ * means_ener = 33 = 540672 Q14 (MR102)
+ * 10log10(L_SUBFR) = 16.02 = 262481.51 Q14
+ * fact * 27 = 1331640 Q14
+ * -----------------------------------------
+ * (MR475, MR515, MR59) K = 2134793.51 Q14 ~= 16678 * 64 * 2
+ * (MR67) K = 2065161.51 Q14 ~= 32268 * 32 * 2
+ * (MR74) K = 2085641.51 Q14 ~= 32588 * 32 * 2
+ * (MR795) K = 2183945.51 Q14 ~= 17062 * 64 * 2
+ * (MR102) K = 2134793.51 Q14 ~= 16678 * 64 * 2
+
+
+ if (sub (mode, MR102) == 0)
+ {
+ // mean = 33 dB
+ L_tmp = L_mac(L_tmp, 16678, 64); // Q14
+ }
+ else if (sub (mode, MR795) == 0)
+ {
+ // ener_code = <xn xn> * 2^27*2^exp_code
+ // frac_en = ener_code / 2^16
+ // = <xn xn> * 2^11*2^exp_code
+ // <xn xn> = <xn xn>*2^11*2^exp * 2^exp_en
+ // := frac_en * 2^exp_en
+
+ // ==> exp_en = -11-exp_code;
+
+ *frac_en = extract_h (ener_code);
+ *exp_en = sub (-11, exp_code);
+
+ // mean = 36 dB
+ L_tmp = L_mac(L_tmp, 17062, 64); // Q14
+ }
+ else if (sub (mode, MR74) == 0)
+ {
+ // mean = 30 dB
+ L_tmp = L_mac(L_tmp, 32588, 32); // Q14
+ }
+ else if (sub (mode, MR67) == 0)
+ {
+ // mean = 28.75 dB
+ L_tmp = L_mac(L_tmp, 32268, 32); // Q14
+ }
+ else // MR59, MR515, MR475
+ {
+ // mean = 33 dB
+ L_tmp = L_mac(L_tmp, 16678, 64); // Q14
+ }
+
+ *-----------------------------------------------------------------*
+ * Compute gcode0. *
+ * = Sum(i=0,3) pred[i]*past_qua_en[i] - ener_code + mean_ener *
+ *-----------------------------------------------------------------*
+
+ L_tmp = L_shl(L_tmp, 10); // Q24
+ for (i = 0; i < 4; i++)
+ L_tmp = L_mac(L_tmp, pred[i], st->past_qua_en[i]);
+ // Q13 * Q10 -> Q24
+
+ gcode0 = extract_h(L_tmp); // Q8
+
+ *-----------------------------------------------------------------*
+ * gcode0 = pow(10.0, gcode0/20) *
+ * = pow(2, 3.3219*gcode0/20) *
+ * = pow(2, 0.166*gcode0) *
+ *-----------------------------------------------------------------*
+
+ // 5439 Q15 = 0.165985
+ // (correct: 1/(20*log10(2)) 0.166096 = 5443 Q15)
+ if (sub (mode, MR74) == 0) // For IS641 bitexactness
+ L_tmp = L_mult(gcode0, 5439); // Q8 * Q15 -> Q24
+ else
+ L_tmp = L_mult(gcode0, 5443); // Q8 * Q15 -> Q24
+
+ L_tmp = L_shr(L_tmp, 8); // -> Q16
+ L_Extract(L_tmp, exp_gcode0, frac_gcode0); // -> Q0.Q15
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void gc_pred(
+ gc_predState *st, /* i/o: State struct */
+ enum Mode mode, /* i : AMR mode */
+ Word16 *code, /* i : innovative codebook vector (L_SUBFR) */
+ /* MR122: Q12, other modes: Q13 */
+ Word16 *exp_gcode0, /* o : exponent of predicted gain factor, Q0 */
+ Word16 *frac_gcode0,/* o : fraction of predicted gain factor Q15 */
+ Word16 *exp_en, /* o : exponent of innovation energy, Q0 */
+ /* (only calculated for MR795) */
+ Word16 *frac_en, /* o : fraction of innovation energy, Q15 */
+ /* (only calculated for MR795) */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word32 L_temp1, L_temp2;
+ Word32 L_tmp;
+ Word32 ener_code;
+ Word32 ener;
+ Word16 exp, frac;
+ Word16 exp_code, gcode0;
+ Word16 tmp;
+ Word16 *p_code = &code[0];
+
+ /*-------------------------------------------------------------------*
+ * energy of code: *
+ * ~~~~~~~~~~~~~~~ *
+ * ener_code = sum(code[i]^2) *
+ *-------------------------------------------------------------------*/
+ ener_code = 0;
+
+ /* MR122: Q12*Q12 -> Q25 */
+ /* others: Q13*Q13 -> Q27 */
+
+ for (i = L_SUBFR >> 2; i != 0; i--)
+ {
+ tmp = *(p_code++);
+ ener_code += ((Word32) tmp * tmp) >> 3;
+ tmp = *(p_code++);
+ ener_code += ((Word32) tmp * tmp) >> 3;
+ tmp = *(p_code++);
+ ener_code += ((Word32) tmp * tmp) >> 3;
+ tmp = *(p_code++);
+ ener_code += ((Word32) tmp * tmp) >> 3;
+ }
+
+ ener_code <<= 4;
+
+ if (ener_code < 0) /* Check for saturation */
+ {
+ ener_code = MAX_32;
+ }
+
+ if (mode == MR122)
+ {
+ /* ener_code = ener_code / lcode; lcode = 40; 1/40 = 26214 Q20 */
+ /* Q9 * Q20 -> Q30 */
+
+ ener_code = ((Word32)(pv_round(ener_code, pOverflow) * 26214)) << 1;
+
+ /*-------------------------------------------------------------*
+ * energy of code: *
+ * ~~~~~~~~~~~~~~~ *
+ * ener_code(Q17) = 10 * Log10(energy) / constant *
+ * = 1/2 * Log2(energy) *
+ * constant = 20*Log10(2) *
+ *-------------------------------------------------------------*/
+ /* ener_code = 1/2 * Log2(ener_code); Note: Log2=log2+30 */
+ Log2(ener_code, &exp, &frac, pOverflow);
+
+ /* Q16 for log() */
+ /* ->Q17 for 1/2 log()*/
+
+ L_temp1 = (Word32)(exp - 30) << 16;
+ ener_code = L_temp1 + ((Word32)frac << 1);
+
+ /*-------------------------------------------------------------*
+ * predicted energy: *
+ * ~~~~~~~~~~~~~~~~~ *
+ * ener(Q24) = (Emean + sum{pred[i]*past_en[i]})/constant *
+ * = MEAN_ENER + sum(pred[i]*past_qua_en[i]) *
+ * constant = 20*Log10(2) *
+ *-------------------------------------------------------------*/
+
+ ener = MEAN_ENER_MR122; /* Q24 (Q17) */
+ for (i = 0; i < NPRED; i++)
+ {
+ L_temp1 = (((Word32) st->past_qua_en_MR122[i]) *
+ pred_MR122[i]) << 1;
+ ener = L_add(ener, L_temp1, pOverflow);
+
+ /* Q10 * Q13 -> Q24 */
+ /* Q10 * Q6 -> Q17 */
+ }
+
+ /*---------------------------------------------------------------*
+ * predicted codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = Pow10( (ener*constant - ener_code*constant) / 20 ) *
+ * = Pow2(ener-ener_code) *
+ * = Pow2(int(d)+frac(d)) *
+ * *
+ * (store exp and frac for pow2()) *
+ *---------------------------------------------------------------*/
+ /* Q16 */
+
+ L_temp1 = L_sub(ener, ener_code, pOverflow);
+
+
+ *exp_gcode0 = (Word16)(L_temp1 >> 17);
+
+ L_temp2 = (Word32) * exp_gcode0 << 15;
+ L_temp1 >>= 2;
+
+ *frac_gcode0 = (Word16)(L_temp1 - L_temp2);
+
+ }
+ else /* all modes except 12.2 */
+ {
+ /*-----------------------------------------------------------------*
+ * Compute: means_ener - 10log10(ener_code/ L_sufr) *
+ *-----------------------------------------------------------------*/
+
+ exp_code = norm_l(ener_code);
+ ener_code = L_shl(ener_code, exp_code, pOverflow);
+
+ /* Log2 = log2 + 27 */
+ Log2_norm(ener_code, exp_code, &exp, &frac);
+
+ /* fact = 10/log2(10) = 3.01 = 24660 Q13 */
+ /* Q0.Q15 * Q13 -> Q14 */
+
+ L_temp2 = (((Word32) exp) * -24660) << 1;
+ L_tmp = (((Word32) frac) * -24660) >> 15;
+
+ /* Sign-extend resulting product */
+ if (L_tmp & (Word32) 0x00010000L)
+ {
+ L_tmp = L_tmp | (Word32) 0xffff0000L;
+ }
+
+ L_tmp = L_tmp << 1;
+ L_tmp = L_add(L_tmp, L_temp2, pOverflow);
+
+
+ /* L_tmp = means_ener - 10log10(ener_code/L_SUBFR)
+ * = means_ener - 10log10(ener_code) + 10log10(L_SUBFR)
+ * = K - fact * Log2(ener_code)
+ * = K - fact * log2(ener_code) - fact*27
+ *
+ * ==> K = means_ener + fact*27 + 10log10(L_SUBFR)
+ *
+ * means_ener = 33 = 540672 Q14 (MR475, MR515, MR59)
+ * means_ener = 28.75 = 471040 Q14 (MR67)
+ * means_ener = 30 = 491520 Q14 (MR74)
+ * means_ener = 36 = 589824 Q14 (MR795)
+ * means_ener = 33 = 540672 Q14 (MR102)
+ * 10log10(L_SUBFR) = 16.02 = 262481.51 Q14
+ * fact * 27 = 1331640 Q14
+ * -----------------------------------------
+ * (MR475, MR515, MR59) K = 2134793.51 Q14 ~= 16678 * 64 * 2
+ * (MR67) K = 2065161.51 Q14 ~= 32268 * 32 * 2
+ * (MR74) K = 2085641.51 Q14 ~= 32588 * 32 * 2
+ * (MR795) K = 2183945.51 Q14 ~= 17062 * 64 * 2
+ * (MR102) K = 2134793.51 Q14 ~= 16678 * 64 * 2
+ */
+
+ if (mode == MR102)
+ {
+ /* mean = 33 dB */
+ L_temp2 = (Word32) 16678 << 7;
+ L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */
+ }
+ else if (mode == MR795)
+ {
+ /* ener_code = <xn xn> * 2^27*2^exp_code
+ frac_en = ener_code / 2^16
+ = <xn xn> * 2^11*2^exp_code
+ <xn xn> = <xn xn>*2^11*2^exp * 2^exp_en
+ : = frac_en * 2^exp_en
+ ==> exp_en = -11-exp_code; */
+ *frac_en = (Word16)(ener_code >> 16);
+ *exp_en = sub(-11, exp_code, pOverflow);
+
+ /* mean = 36 dB */
+ L_temp2 = (Word32) 17062 << 7;
+ L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */
+ }
+ else if (mode == MR74)
+ {
+ /* mean = 30 dB */
+ L_temp2 = (Word32) 32588 << 6;
+ L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */
+ }
+ else if (mode == MR67)
+ {
+ /* mean = 28.75 dB */
+ L_temp2 = (Word32) 32268 << 6;
+ L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */
+ }
+ else /* MR59, MR515, MR475 */
+ {
+ /* mean = 33 dB */
+ L_temp2 = (Word32) 16678 << 7;
+ L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q14 */
+ }
+
+ /*-------------------------------------------------------------*
+ * Compute gcode0. *
+ * = Sum(i=0,3) pred[i]*past_qua_en[i] - ener_code + mean_ener *
+ *--------------------------------------------------------------*/
+ /* Q24 */
+ if (L_tmp > (Word32) 0X001fffffL)
+ {
+ *pOverflow = 1;
+ L_tmp = MAX_32;
+ }
+ else if (L_tmp < (Word32) 0xffe00000L)
+ {
+ *pOverflow = 1;
+ L_tmp = MIN_32;
+ }
+ else
+ {
+ L_tmp = L_tmp << 10;
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ L_temp2 = ((((Word32) pred[i]) * st->past_qua_en[i]) << 1);
+ L_tmp = L_add(L_tmp, L_temp2, pOverflow); /* Q13 * Q10 -> Q24 */
+ }
+
+ gcode0 = (Word16)(L_tmp >> 16); /* Q8 */
+
+ /*-----------------------------------------------------------*
+ * gcode0 = pow(10.0, gcode0/20) *
+ * = pow(2, 3.3219*gcode0/20) *
+ * = pow(2, 0.166*gcode0) *
+ *-----------------------------------------------------------*/
+
+ /* 5439 Q15 = 0.165985 */
+ /* (correct: 1/(20*log10(2)) 0.166096 = 5443 Q15) */
+
+ if (mode == MR74) /* For IS641 bitexactness */
+ {
+ L_tmp = (((Word32) gcode0) * 5439) << 1; /* Q8 * Q15 -> Q24 */
+ }
+ else
+ {
+ L_tmp = (((Word32) gcode0) * 5443) << 1; /* Q8 * Q15 -> Q24 */
+ }
+
+ if (L_tmp < 0)
+ {
+ L_tmp = ~((~L_tmp) >> 8);
+ }
+ else
+ {
+ L_tmp = L_tmp >> 8; /* -> Q16 */
+ }
+
+ *exp_gcode0 = (Word16)(L_tmp >> 16);
+ if (L_tmp < 0)
+ {
+ L_temp1 = ~((~L_tmp) >> 1);
+ }
+ else
+ {
+ L_temp1 = L_tmp >> 1;
+ }
+ L_temp2 = (Word32) * exp_gcode0 << 15;
+ *frac_gcode0 = (Word16)(L_sub(L_temp1, L_temp2, pOverflow));
+ /* -> Q0.Q15 */
+ }
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gc_pred_update
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type gc_predState
+ qua_ener_MR122 = quantized energy for update (Q10); calculated as
+ (log2(qua_err)) (Word16)
+ qua_ener = quantized energy for update (Q10); calculated as
+ (20*log10(qua_err)) (Word16)
+
+ Outputs:
+ structure pointed to by st contains the calculated quantized energy
+ for update
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function updates the MA predictor with the last quantized energy.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void gc_pred_update(
+ gc_predState *st, // i/o: State struct
+ Word16 qua_ener_MR122, // i : quantized energy for update, Q10
+ // (log2(qua_err))
+ Word16 qua_ener // i : quantized energy for update, Q10
+ // (20*log10(qua_err))
+)
+{
+ Word16 i;
+
+ for (i = 3; i > 0; i--)
+ {
+ st->past_qua_en[i] = st->past_qua_en[i - 1];
+ st->past_qua_en_MR122[i] = st->past_qua_en_MR122[i - 1];
+ }
+
+ st->past_qua_en_MR122[0] = qua_ener_MR122; // log2 (qua_err), Q10
+
+ st->past_qua_en[0] = qua_ener; // 20*log10(qua_err), Q10
+
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void gc_pred_update(
+ gc_predState *st, /* i/o: State struct */
+ Word16 qua_ener_MR122, /* i : quantized energy for update, Q10 */
+ /* (log2(qua_err)) */
+ Word16 qua_ener /* i : quantized energy for update, Q10 */
+ /* (20*log10(qua_err)) */
+)
+{
+ st->past_qua_en[3] = st->past_qua_en[2];
+ st->past_qua_en_MR122[3] = st->past_qua_en_MR122[2];
+
+ st->past_qua_en[2] = st->past_qua_en[1];
+ st->past_qua_en_MR122[2] = st->past_qua_en_MR122[1];
+
+ st->past_qua_en[1] = st->past_qua_en[0];
+ st->past_qua_en_MR122[1] = st->past_qua_en_MR122[0];
+
+ st->past_qua_en_MR122[0] = qua_ener_MR122; /* log2 (qua_err), Q10 */
+
+ st->past_qua_en[0] = qua_ener; /* 20*log10(qua_err), Q10 */
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gc_pred_average_limited
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type gc_predState
+ ener_avg_MR122 = pointer to the averaged quantized energy (Q10);
+ calculated as (log2(qua_err)) (Word16)
+ ener_avg = pointer to the averaged quantized energy (Q10); calculated
+ as (20*log10(qua_err)) (Word16)
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ store pointed to by ener_avg_MR122 contains the new averaged quantized
+ energy
+ store pointed to by ener_avg contains the new averaged quantized
+ energy
+ pOverflow = 1 if the math functions called by gc_pred_average_limited
+ results in overflow else zero.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates the average of MA predictor state values (with a
+ lower limit) used in error concealment.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+The original etsi reference code uses a global flag Overflow. However, in the
+actual implementation a pointer to a the overflow flag is passed in.
+
+void gc_pred_average_limited(
+ gc_predState *st, // i: State struct
+ Word16 *ener_avg_MR122, // o: everaged quantized energy, Q10
+ // (log2(qua_err))
+ Word16 *ener_avg // o: averaged quantized energy, Q10
+ // (20*log10(qua_err))
+)
+{
+ Word16 av_pred_en;
+ Word16 i;
+
+ // do average in MR122 mode (log2() domain)
+ av_pred_en = 0;
+ for (i = 0; i < NPRED; i++)
+ {
+ av_pred_en = add (av_pred_en, st->past_qua_en_MR122[i]);
+ }
+
+ // av_pred_en = 0.25*av_pred_en
+ av_pred_en = mult (av_pred_en, 8192);
+
+ // if (av_pred_en < -14/(20Log10(2))) av_pred_en = ..
+
+ if (sub (av_pred_en, MIN_ENERGY_MR122) < 0)
+ {
+ av_pred_en = MIN_ENERGY_MR122;
+ }
+ *ener_avg_MR122 = av_pred_en;
+
+ // do average for other modes (20*log10() domain)
+ av_pred_en = 0;
+ for (i = 0; i < NPRED; i++)
+ {
+ av_pred_en = add (av_pred_en, st->past_qua_en[i]);
+ }
+
+ // av_pred_en = 0.25*av_pred_en
+ av_pred_en = mult (av_pred_en, 8192);
+
+ // if (av_pred_en < -14) av_pred_en = ..
+
+ if (sub (av_pred_en, MIN_ENERGY) < 0)
+ {
+ av_pred_en = MIN_ENERGY;
+ }
+ *ener_avg = av_pred_en;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void gc_pred_average_limited(
+ gc_predState *st, /* i: State struct */
+ Word16 *ener_avg_MR122, /* o: everaged quantized energy, Q10 */
+ /* (log2(qua_err)) */
+ Word16 *ener_avg, /* o: averaged quantized energy, Q10 */
+ /* (20*log10(qua_err)) */
+ Flag *pOverflow
+)
+{
+ Word16 av_pred_en;
+ Word16 i;
+
+ /* do average in MR122 mode (log2() domain) */
+ av_pred_en = 0;
+ for (i = 0; i < NPRED; i++)
+ {
+ av_pred_en =
+ add(av_pred_en, st->past_qua_en_MR122[i], pOverflow);
+ }
+
+ /* av_pred_en = 0.25*av_pred_en (with sign-extension)*/
+ if (av_pred_en < 0)
+ {
+ av_pred_en = (av_pred_en >> 2) | 0xc000;
+ }
+ else
+ {
+ av_pred_en >>= 2;
+ }
+
+ /* if (av_pred_en < -14/(20Log10(2))) av_pred_en = .. */
+ if (av_pred_en < MIN_ENERGY_MR122)
+ {
+ av_pred_en = MIN_ENERGY_MR122;
+ }
+ *ener_avg_MR122 = av_pred_en;
+
+ /* do average for other modes (20*log10() domain) */
+ av_pred_en = 0;
+ for (i = 0; i < NPRED; i++)
+ {
+ av_pred_en = add(av_pred_en, st->past_qua_en[i], pOverflow);
+ }
+
+ /* av_pred_en = 0.25*av_pred_en (with sign-extension)*/
+ if (av_pred_en < 0)
+ {
+ av_pred_en = (av_pred_en >> 2) | 0xc000;
+ }
+ else
+ {
+ av_pred_en >>= 2;
+ }
+
+ /* if (av_pred_en < -14) av_pred_en = .. */
+ if (av_pred_en < MIN_ENERGY)
+ {
+ av_pred_en = MIN_ENERGY;
+ }
+ *ener_avg = av_pred_en;
+}
diff --git a/media/codecs/amrnb/common/src/gmed_n.cpp b/media/codecs/amrnb/common/src/gmed_n.cpp
new file mode 100644
index 0000000..2d3b9e4
--- /dev/null
+++ b/media/codecs/amrnb/common/src/gmed_n.cpp
@@ -0,0 +1,218 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/gmed_n.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Put file into template and first pass at optimization.
+
+ Description: Made changes based on comments from the review meeting. Used
+ pointers instead of index addressing in the arrays.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unncessary include files.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "gmed_n.h"
+#include "typedef.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NMAX 9 /* largest N used in median calculation */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gmed_n
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ ind = input values (Word16)
+ n = number of inputs to find the median (Word16)
+
+ Returns:
+ median value.
+
+ Outputs:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates N-point median of a data set. This routine is only
+ valid for a odd number of gains (n <= NMAX).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gmed_n.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 gmed_n ( // o : The median value (0...N-1)
+ Word16 ind[], // i : Past gain values
+ Word16 n // i : The number of gains; this routine
+ // is only valid for a odd number of gains
+ // (n <= NMAX)
+)
+{
+ Word16 i, j, ix = 0;
+ Word16 max;
+ Word16 medianIndex;
+ Word16 tmp[NMAX];
+ Word16 tmp2[NMAX];
+
+ for (i = 0; i < n; i++)
+ {
+ tmp2[i] = ind[i];
+ }
+
+ for (i = 0; i < n; i++)
+ {
+ max = -32767;
+ for (j = 0; j < n; j++)
+ {
+ if (sub (tmp2[j], max) >= 0)
+ {
+ max = tmp2[j];
+ ix = j;
+ }
+ }
+ tmp2[ix] = -32768;
+ tmp[i] = ix;
+ }
+
+ medianIndex=tmp[ shr(n,1) ]; // account for complex addressing
+ return (ind[medianIndex]);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 gmed_n( /* o : the median value */
+ Word16 ind[], /* i : input values */
+ Word16 n /* i : number of inputs */
+)
+{
+ Word16 i, j, ix = 0;
+ Word16 max;
+ Word16 medianIndex;
+ Word16 tmp[NMAX];
+ Word16 tmp2[NMAX];
+
+ for (i = 0; i < n; i++)
+ {
+ *(tmp2 + i) = *(ind + i);
+ }
+
+ for (i = 0; i < n; i++)
+ {
+ max = -32767;
+ for (j = 0; j < n; j++)
+ {
+ if (*(tmp2 + j) >= max)
+ {
+ max = *(tmp2 + j);
+ ix = j;
+ }
+ }
+ *(tmp2 + ix) = -32768;
+ *(tmp + i) = ix;
+ }
+
+ medianIndex = *(tmp + (n >> 1)); /* account for complex addressing */
+
+ return (*(ind + medianIndex));
+}
+
diff --git a/media/codecs/amrnb/common/src/gray_tbl.cpp b/media/codecs/amrnb/common/src/gray_tbl.cpp
new file mode 100644
index 0000000..c4b2dbc
--- /dev/null
+++ b/media/codecs/amrnb/common/src/gray_tbl.cpp
@@ -0,0 +1,162 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/gray_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the declaration for the gray encoding and decoding tables,
+ gray_tbl[] and dgray_tbl[] used by the c1035pf and d1035pf module
+ respectively.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+ extern const Word16 gray[];
+ extern const Word16 dgray[];
+ const Word16 gray[8] = {0, 1, 3, 2, 6, 4, 5, 7};
+ const Word16 dgray[8] = {0, 1, 3, 2, 5, 6, 4, 7};
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] gray.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/common/src/grid_tbl.cpp b/media/codecs/amrnb/common/src/grid_tbl.cpp
new file mode 100644
index 0000000..48566cc
--- /dev/null
+++ b/media/codecs/amrnb/common/src/grid_tbl.cpp
@@ -0,0 +1,181 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/grid_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the declaration for grid_tbl[] used by the az_lsp()
+ function.
+
+ // Table for az_lsp()
+ //
+ // grid[0] = 1.0;
+ // grid[grid_points+1] = -1.0;
+ // for (i = 1; i < grid_points; i++)
+ // grid[i] = cos((6.283185307*i)/(2.0*grid_points));
+ //
+ //
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "az_lsp.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+#define grid_points 60
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+ const Word16 grid[grid_points + 1] =
+ {
+ 32760, 32723, 32588, 32364, 32051, 31651,
+ 31164, 30591, 29935, 29196, 28377, 27481,
+ 26509, 25465, 24351, 23170, 21926, 20621,
+ 19260, 17846, 16384, 14876, 13327, 11743,
+ 10125, 8480, 6812, 5126, 3425, 1714,
+ 0, -1714, -3425, -5126, -6812, -8480,
+ -10125, -11743, -13327, -14876, -16384, -17846,
+ -19260, -20621, -21926, -23170, -24351, -25465,
+ -26509, -27481, -28377, -29196, -29935, -30591,
+ -31164, -31651, -32051, -32364, -32588, -32723,
+ -32760
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] grid.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/common/src/int_lpc.cpp b/media/codecs/amrnb/common/src/int_lpc.cpp
new file mode 100644
index 0000000..806474d
--- /dev/null
+++ b/media/codecs/amrnb/common/src/int_lpc.cpp
@@ -0,0 +1,633 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/int_lpc.c
+ Functions:
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Per review comments, replaced includes of "basic_op.h"
+ and "count.h" with "shr.h", "sub.h", and "add.h"
+
+ Description: For Int_lpc_1and3() and Int_lpc_1and3_2()
+ 1. Replaced array addressing by pointers
+ 2. Eliminated math operations that unnecessary checked for
+ saturation
+ 3. Unrolled loops to speed up processing
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "int_lpc.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "lsp_az.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Int_lpc_1and3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp_old -- array of type Word16 -- LSP vector at the
+ 4th subfr. of past frame (M)
+ lsp_mid -- array of type Word16 -- LSP vector at the 2nd subfr. of
+ present frame (M)
+ lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
+ present frame (M)
+
+ Outputs:
+ Az -- array of type Word16 -- interpolated LP parameters in all subfr.
+ (AZ_SIZE)
+ pOverflow -- pointer to type Flag -- Overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Interpolates the LSPs and converts to LPC parameters
+ to get a different LP filter in each subframe.
+ Description : The 20 ms speech frame is divided into 4 subframes.
+ The LSPs are quantized and transmitted at the 2nd and
+ 4th subframes (twice per frame) and interpolated at the
+ 1st and 3rd subframe.
+
+ |------|------|------|------|
+ sf1 sf2 sf3 sf4
+ F0 Fm F1
+
+ sf1: 1/2 Fm + 1/2 F0 sf3: 1/2 F1 + 1/2 Fm
+ sf2: Fm sf4: F1
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Int_lpc_1and3(
+ Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */
+ Word16 lsp_mid[], /* i : LSP vector at the 2nd subfr. of
+ present frame (M) */
+ Word16 lsp_new[], /* i : LSP vector at the 4th subfr. of
+ present frame (M) */
+ Word16 Az[], /* o : interpolated LP parameters in all subfr.
+ (AZ_SIZE) */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 lsp[M];
+ Word16 *p_lsp_old = &lsp_old[0];
+ Word16 *p_lsp_mid = &lsp_mid[0];
+ Word16 *p_lsp_new = &lsp_new[0];
+ Word16 *p_lsp = &lsp[0];
+
+ /* lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */
+
+ for (i = M >> 1; i != 0; i--)
+ {
+ *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
+ *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 1 */
+
+ Az += MP1;
+
+ Lsp_Az(
+ lsp_mid,
+ Az,
+ pOverflow); /* Subframe 2 */
+
+ Az += MP1;
+
+ p_lsp_mid = &lsp_mid[0];
+ p_lsp = &lsp[0];
+
+ for (i = M >> 1; i != 0; i--)
+ {
+ *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
+ *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 3 */
+
+ Az += MP1;
+
+ Lsp_Az(
+ lsp_new,
+ Az,
+ pOverflow); /* Subframe 4 */
+
+ return;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Int_lpc_1and3_2
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp_old -- array of type Word16 -- LSP vector at the
+ 4th subfr. of past frame (M)
+ lsp_mid -- array of type Word16 -- LSP vector at the 2nd subfr. of
+ present frame (M)
+ lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
+ present frame (M)
+
+ Outputs:
+ Az -- array of type Word16 -- interpolated LP parameters in.
+ subfr 1 and 2.
+ pOverflow -- pointer to type Flag -- Overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Interpolation of the LPC parameters. Same as the Int_lpc
+ function but we do not recompute Az() for subframe 2 and
+ 4 because it is already available.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Int_lpc_1and3_2(
+ Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */
+ Word16 lsp_mid[], /* i : LSP vector at the 2nd subframe of
+ present frame (M) */
+ Word16 lsp_new[], /* i : LSP vector at the 4th subframe of
+ present frame (M) */
+ Word16 Az[], /* o :interpolated LP parameters
+ in subframes 1 and 3 (AZ_SIZE) */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 lsp[M];
+ Word16 *p_lsp_old = &lsp_old[0];
+ Word16 *p_lsp_mid = &lsp_mid[0];
+ Word16 *p_lsp_new = &lsp_new[0];
+ Word16 *p_lsp = &lsp[0];
+
+ /* lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */
+
+ for (i = M >> 1; i != 0; i--)
+ {
+ *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
+ *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
+ }
+ Lsp_Az(lsp, Az, pOverflow); /* Subframe 1 */
+ Az += MP1 * 2;
+
+ p_lsp_mid = &lsp_mid[0];
+ p_lsp = &lsp[0];
+
+ for (i = M >> 1; i != 0; i--)
+ {
+ *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
+ *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
+ }
+
+ Lsp_Az(lsp, Az, pOverflow); /* Subframe 3 */
+
+ return;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lsp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp_old -- array of type Word16 -- LSP vector at the
+ 4th subfr. of past frame (M)
+ lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
+ present frame (M)
+
+ Outputs:
+ Az -- array of type Word16 -- interpolated LP parameters in.
+ all subframes.
+ pOverflow -- pointer to type Flag -- Overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Interpolates the LSPs and convert to LP parameters to get
+ a different LP filter in each subframe.
+
+ DESCRIPTION:
+ The 20 ms speech frame is divided into 4 subframes.
+ The LSPs are quantized and transmitted at the 4th subframe
+ (once per frame) and interpolated at the 1st, 2nd and 3rd subframe.
+
+ |------|------|------|------|
+ sf1 sf2 sf3 sf4
+ F0 F1
+
+ sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1
+ sf2: 1/2 F0 + 1/2 F1 sf4: F1
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Int_lpc_1to3(
+ Word16 lsp_old[], /* input : LSP vector at the 4th SF of past frame */
+ Word16 lsp_new[], /* input : LSP vector at the 4th SF of present frame */
+ Word16 Az[], /* output: interpolated LP parameters in all SFs */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 temp;
+ Word16 temp2;
+
+ Word16 lsp[M];
+
+ for (i = 0; i < M; i++)
+ {
+ temp = shr(lsp_old[i], 2, pOverflow);
+ temp = sub(lsp_old[i], temp, pOverflow);
+ temp2 = shr(lsp_new[i], 2, pOverflow);
+
+ lsp[i] = add(temp2, temp, pOverflow);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 1 */
+
+ Az += MP1;
+
+
+ for (i = 0; i < M; i++)
+ {
+ temp = shr(lsp_new[i], 1, pOverflow);
+ temp2 = shr(lsp_old[i], 1, pOverflow);
+ lsp[i] = add(temp, temp2, pOverflow);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 2 */
+
+ Az += MP1;
+
+ for (i = 0; i < M; i++)
+ {
+ temp = shr(lsp_new[i], 2, pOverflow);
+ temp = sub(lsp_new[i], temp, pOverflow);
+ temp2 = shr(lsp_old[i], 2, pOverflow);
+
+ lsp[i] = add(temp2, temp, pOverflow);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 3 */
+
+ Az += MP1;
+
+ Lsp_Az(
+ lsp_new,
+ Az,
+ pOverflow); /* Subframe 4 */
+
+ return;
+}
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Int_lpc_1to3_2
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp_old -- array of type Word16 -- LSP vector at the
+ 4th subfr. of past frame (M)
+ lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
+ present frame (M)
+
+ Outputs:
+ Az -- array of type Word16 -- interpolated LP parameters in.
+ subfr 1, 2, and 3.
+ pOverflow -- pointer to type Flag -- Overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Interpolation of the LPC parameters.
+ Same as the previous function but we do not recompute Az() for
+ subframe 4 because it is already available.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Int_lpc_1to3_2(
+ Word16 lsp_old[], /* input : LSP vector at the 4th SF of past frame */
+ Word16 lsp_new[], /* input : LSP vector at the 4th SF of present frame */
+ Word16 Az[], /* output: interpolated LP parameters in SFs 1,2,3 */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 temp;
+ Word16 temp2;
+ Word16 lsp[M];
+
+ for (i = 0; i < M; i++)
+ {
+ temp = shr(lsp_old[i], 2, pOverflow);
+
+ temp = sub(lsp_old[i], temp, pOverflow);
+
+ temp2 = shr(lsp_new[i], 2, pOverflow);
+
+ lsp[i] = add(temp2, temp, pOverflow);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 1 */
+
+ Az += MP1;
+
+ for (i = 0; i < M; i++)
+ {
+ temp = shr(lsp_new[i], 1, pOverflow);
+ temp2 = shr(lsp_old[i], 1, pOverflow);
+
+ lsp[i] = add(temp2, temp, pOverflow);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 2 */
+
+ Az += MP1;
+
+ for (i = 0; i < M; i++)
+ {
+ temp = shr(lsp_new[i], 2, pOverflow);
+ temp = sub(lsp_new[i], temp, pOverflow);
+ temp2 = shr(lsp_old[i], 2, pOverflow);
+
+ lsp[i] = add(temp, temp2, pOverflow);
+ }
+
+ Lsp_Az(
+ lsp,
+ Az,
+ pOverflow); /* Subframe 3 */
+
+ return;
+}
+
diff --git a/media/codecs/amrnb/common/src/inv_sqrt.cpp b/media/codecs/amrnb/common/src/inv_sqrt.cpp
new file mode 100644
index 0000000..83f4d0c
--- /dev/null
+++ b/media/codecs/amrnb/common/src/inv_sqrt.cpp
@@ -0,0 +1,270 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/inv_sqrt.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Put file into template.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h with the header files of the math functions
+ used in the file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Defined one local variable per line.
+ 2. Used "&=", ">>=", and "+=" in the code.
+
+ Description: Updated template. Changed function interface to pass in a
+ pointer to overflow flag into the function instead of using a
+ global flag.
+
+ Description: Removed inclusion of inv_sqrt.tab file. Changed array name
+ from "table" to "inv_sqrt_tbl"
+
+ Description: Removed math operations that were not needed as functions,
+ this because the numbers themselves will not saturate the
+ operators, so there is not need to check for saturation.
+
+ Description: Updated copyrigth year, according to code review comments.
+
+ Description: Replaced "int" and/or "char" with defined types.
+ Added proper casting (Word32) to some left shifting operations
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "inv_sqrt.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Inv_sqrt
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_x = input value (Word32)
+ pOverflow = pointer to overflow flag
+
+ Outputs:
+ pOverflow -> if the Inv_sqrt operation resulted in an overflow.
+
+ Returns:
+ L_y = inverse squareroot of L_x (Word32)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes 1/sqrt(L_x), where L_x is positive.
+ If L_x is negative or zero, the result is 1 (3fff ffff).
+
+ The function 1/sqrt(L_x) is approximated by a table and linear
+ interpolation. The inverse square root is computed using the
+ following steps:
+ 1- Normalization of L_x.
+ 2- If (30-exponent) is even then shift right once.
+ 3- exponent = (30-exponent)/2 +1
+ 4- i = bit25-b31 of L_x; 16<=i<=63 because of normalization.
+ 5- a = bit10-b24
+ 6- i -=16
+ 7- L_y = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ 8- L_y >>= exponent
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ inv_sqrt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 Inv_sqrt ( // (o) : output value
+ Word32 L_x // (i) : input value
+)
+{
+ Word16 exp, i, a, tmp;
+ Word32 L_y;
+
+* The reference ETSI code uses a global Overflow flag. In the actual
+* implementation a pointer to the overflow flag is passed into the function.
+* This pointer is in turn passed into the basic math functions such as add(),
+* L_shl(), L_shr(), sub() called by this module.
+
+ if (L_x <= (Word32) 0)
+ return ((Word32) 0x3fffffffL);
+
+ exp = norm_l (L_x);
+ L_x = L_shl (L_x, exp); // L_x is normalize
+
+ exp = sub (30, exp);
+
+ if ((exp & 1) == 0) // If exponent even -> shift right
+ {
+ L_x = L_shr (L_x, 1);
+ }
+ exp = shr (exp, 1);
+ exp = add (exp, 1);
+
+ L_x = L_shr (L_x, 9);
+ i = extract_h (L_x); // Extract b25-b31
+ L_x = L_shr (L_x, 1);
+ a = extract_l (L_x); // Extract b10-b24
+ a = a & (Word16) 0x7fff;
+
+ i = sub (i, 16);
+
+ L_y = L_deposit_h (table[i]); // table[i] << 16
+ tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1])
+ L_y = L_msu (L_y, tmp, a); // L_y -= tmp*a*2
+
+ L_y = L_shr (L_y, exp); // denormalization
+
+ return (L_y);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word32 Inv_sqrt( /* (o) : output value */
+ Word32 L_x, /* (i) : input value */
+ Flag * pOverflow /* (i) : pointer to overflow flag */
+)
+{
+ Word16 exp;
+ Word16 i;
+ Word16 a;
+ Word16 tmp;
+ Word32 L_y;
+ OSCL_UNUSED_ARG(pOverflow);
+
+ if (L_x <= (Word32) 0)
+ {
+ return ((Word32) 0x3fffffffL);
+ }
+
+ exp = norm_l(L_x);
+ L_x <<= exp; /* L_x is normalize */
+
+ exp = 30 - exp;
+
+ if ((exp & 1) == 0) /* If exponent even -> shift right */
+ {
+ L_x >>= 1;
+ }
+ exp >>= 1;
+ exp += 1;
+
+ L_x >>= 9;
+ i = (Word16)(L_x >> 16); /* Extract b25-b31 */
+ a = (Word16)(L_x >> 1); /* Extract b10-b24 */
+ a &= (Word16) 0x7fff;
+
+ i -= 16;
+
+ L_y = (Word32)inv_sqrt_tbl[i] << 16; /* inv_sqrt_tbl[i] << 16 */
+
+ /* inv_sqrt_tbl[i] - inv_sqrt_tbl[i+1]) */
+ tmp = inv_sqrt_tbl[i] - inv_sqrt_tbl[i + 1];
+ /* always a positive number less than 200 */
+
+ L_y -= ((Word32)tmp * a) << 1; /* L_y -= tmp*a*2 */
+ /* always a positive minus a small negative number */
+
+ L_y >>= exp; /* denormalization, exp always 0< exp < 31 */
+
+ return (L_y);
+}
+
diff --git a/media/codecs/amrnb/common/src/inv_sqrt_tbl.cpp b/media/codecs/amrnb/common/src/inv_sqrt_tbl.cpp
new file mode 100644
index 0000000..13c3b24
--- /dev/null
+++ b/media/codecs/amrnb/common/src/inv_sqrt_tbl.cpp
@@ -0,0 +1,168 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/inv_sqrt_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed table name to inv_sqrt_tbl
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the declaration for table[] used by the inv_sqrt function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "inv_sqrt.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+ const Word16 inv_sqrt_tbl[49] =
+ {
+
+ 32767, 31790, 30894, 30070, 29309, 28602, 27945, 27330, 26755, 26214,
+ 25705, 25225, 24770, 24339, 23930, 23541, 23170, 22817, 22479, 22155,
+ 21845, 21548, 21263, 20988, 20724, 20470, 20225, 19988, 19760, 19539,
+ 19326, 19119, 18919, 18725, 18536, 18354, 18176, 18004, 17837, 17674,
+ 17515, 17361, 17211, 17064, 16921, 16782, 16646, 16514, 16384
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] inv_sqrt.tab file, UMTS GSM AMR speech codec, R99 - Version 3.2.0,
+ March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/common/src/l_abs.cpp b/media/codecs/amrnb/common/src/l_abs.cpp
new file mode 100644
index 0000000..7e0ae99
--- /dev/null
+++ b/media/codecs/amrnb/common/src/l_abs.cpp
@@ -0,0 +1,193 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/src/l_abs.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the L_abs function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32 ) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ L_var1 = absolute value of input (Word32)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates the absolute value of L_var1; saturate in case
+ where the input is -214783648.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 L_abs (Word32 L_var1)
+{
+ Word32 L_var_out;
+
+ if (L_var1 == MIN_32)
+ {
+ L_var_out = MAX_32;
+ }
+ else
+ {
+ if (L_var1 < 0)
+ {
+ L_var_out = -L_var1;
+ }
+ else
+ {
+ L_var_out = L_var1;
+ }
+ }
+
+#if (WMOPS)
+ multiCounter[currCounter].L_abs++;
+#endif
+ return (L_var_out);
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word32 L_abs(Word32 L_var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ Word32 y = L_var1 - (L_var1 < 0);
+ y = y ^(y >> 31);
+ return (y);
+
+}
diff --git a/media/codecs/amrnb/common/src/l_deposit_h.cpp b/media/codecs/amrnb/common/src/l_deposit_h.cpp
new file mode 100644
index 0000000..e705ed1
--- /dev/null
+++ b/media/codecs/amrnb/common/src/l_deposit_h.cpp
@@ -0,0 +1,177 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/src/l_deposit_h.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the L_deposit_h function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ var1 = deposit of var1 into MSWord of 32 bit value (Word32)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function deposits the 16 bit var1 into the 16 MS bits of the 32 bit
+ output. The 16 LS bits of the output are zeroed.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 L_deposit_h (Word16 var1)
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1 << 16;
+#if (WMOPS)
+ multiCounter[currCounter].L_deposit_h++;
+#endif
+ return (L_var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word32 L_deposit_h(Word16 var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return ((Word32) var1 << 16);
+}
diff --git a/media/codecs/amrnb/common/src/l_deposit_l.cpp b/media/codecs/amrnb/common/src/l_deposit_l.cpp
new file mode 100644
index 0000000..5064fdb
--- /dev/null
+++ b/media/codecs/amrnb/common/src/l_deposit_l.cpp
@@ -0,0 +1,177 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/src/l_deposit_l.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the L_deposit_l function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ var1 = deposit of var1 into LSWord of 32 bit value (Word32)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function deposits the 16 bit var1 into the 16 LS bits of the 32 bit
+ output. The 16 MS bits of the output are sign extended.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 L_deposit_l (Word16 var1)
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1;
+#if (WMOPS)
+ multiCounter[currCounter].L_deposit_l++;
+#endif
+ return (L_var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word32 L_deposit_l(Word16 var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return ((Word32) var1);
+}
diff --git a/media/codecs/amrnb/common/src/l_shr_r.cpp b/media/codecs/amrnb/common/src/l_shr_r.cpp
new file mode 100644
index 0000000..47e1ee8
--- /dev/null
+++ b/media/codecs/amrnb/common/src/l_shr_r.cpp
@@ -0,0 +1,214 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/src/l_shr_r.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the L_shr_r function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Updated template. Changed function interface to pass in a
+ pointer to overflow flag into the function instead of using a
+ global flag. Removed code that updates MOPS counter. Changed
+ function return value name from "L_var_out" to "result".
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: L_shr_r
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32 ) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit shift operation resulted in overflow
+
+ Returns:
+ result = Shifted result w/ rounding (Word32)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function arithmetically shifts the 32 bit input L_var1 right var2
+ positions with rounding. If var2 is negative, the function
+ arithmetically shifts L_var1 left by -var2 and zero fills the -var2 LSB of
+ the result. The result is saturated in case of underflows or overflows, i.e.,
+
+ - If var2 is greater than zero :
+ if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))
+ is equal to zero
+ then
+ L_shr_r(L_var1,var2) = L_shr(L_var1,var2)
+ else
+ L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1)
+ - If var2 is less than or equal to zero :
+ L_shr_r(L_var1,var2) = L_shr(L_var1,var2).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] L_shr_r() function in basic_op2.c, UMTS GSM AMR speech codec, R99 -
+ Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 L_shr_r (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out;
+
+* The reference ETSI code uses a global flag for Overflow. In the actual
+* implementation a pointer to Overflow flag is passed in as a parameter to the
+* function L_shr()
+
+ if (var2 > 31)
+ {
+ L_var_out = 0;
+ }
+ else
+ {
+ L_var_out = L_shr (L_var1, var2);
+#if (WMOPS)
+ multiCounter[currCounter].L_shr--;
+#endif
+ if (var2 > 0)
+ {
+ if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
+ {
+ L_var_out++;
+ }
+ }
+ }
+#if (WMOPS)
+ multiCounter[currCounter].L_shr_r++;
+#endif
+ return (L_var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word32 L_shr_r(Word32 L_var1, Word16 var2, Flag *pOverflow)
+{
+ Word32 result;
+
+ if (var2 > 31)
+ {
+ result = 0;
+ }
+ else
+ {
+ result = L_shr(L_var1, var2, pOverflow);
+
+ if (var2 > 0)
+ {
+ if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
+ {
+ result++;
+ }
+ }
+ }
+ return (result);
+}
diff --git a/media/codecs/amrnb/common/src/log2.cpp b/media/codecs/amrnb/common/src/log2.cpp
new file mode 100644
index 0000000..0ada423
--- /dev/null
+++ b/media/codecs/amrnb/common/src/log2.cpp
@@ -0,0 +1,179 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/src/log2.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. Moved Log2_norm
+ function to its own file.
+
+ Description: Changed l_shl.c to l_shl.h in Include section.
+
+ Description: Updated template. Changed function interface to pass in a
+ pointer to overflow flag into the function instead of using a
+ global flag. Changed input pointer names for clarity.
+
+ Description:
+ 1. Eliminated l_shl function knowing that after normalization
+ the left shift factor will not saturate.
+ 2. Eliminated unused include files typedef.h and l_shl.h.
+
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "log2.h"
+#include "basic_op.h"
+#include "log2_norm.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: log2()
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_x = input value of type Word32
+ pExponent = pointer to the integer part of Log2 of type Word16 whose
+ valid range is: 0 <= value <= 30
+ pFraction = pointer to the fractional part of Log2 of type Word16
+ whose valid range is: 0 <= value < 1
+ pOverflow = pointer to overflow flag
+
+
+ Outputs:
+ pExponent -> integer part of the newly calculated Log2
+ pFraction -> fractional part of the newly calculated Log2
+ pOverflow -> 1 if the log2() operation resulted in saturation
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes logarithm (base2) of the input L_x, where L_x is
+ positive. If L_x is negative or zero, the result is 0.
+
+ This function first normalizes the input L_x and calls the function Log2_norm
+ to calculate the logarithm.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] log2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void Log2(
+ Word32 L_x, /* (i) : input value */
+ Word16 *pExponent, /* (o) : Integer part of Log2. (range: 0<=val<=30)*/
+ Word16 *pFraction, /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ Flag *pOverflow /* (i/o) : overflow flag */
+)
+{
+ Word16 exp;
+ Word32 result;
+ OSCL_UNUSED_ARG(pOverflow);
+
+ exp = norm_l(L_x);
+ result = L_x << exp;
+ Log2_norm(result, exp, pExponent, pFraction);
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/log2_norm.cpp b/media/codecs/amrnb/common/src/log2_norm.cpp
new file mode 100644
index 0000000..feda874
--- /dev/null
+++ b/media/codecs/amrnb/common/src/log2_norm.cpp
@@ -0,0 +1,238 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/log2_norm.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for Log2_norm function.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Modified code to improve performance.
+ 2. Fixed typecasting issue with TI C compiler.
+ 3. Added more comments to the code.
+
+ Description: Removed unnecessary line of code (line 208).
+
+ Description: Removed inclusion of "log2.tab"
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "log2_norm.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Log2_norm
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_x = normalized input value of type Word32
+ exp = number of shifts required to normalize L_x; it is of type Word16
+ exponent = pointer to the integer part of Log2 (of type Word16)
+ whose valid range is: 0 <= value <= 30
+ fraction = pointer to the fractional part of Log2 (of type Word16)
+ whose valid range is: 0 <= value < 1
+
+ Outputs:
+ exponent points to the newly calculated integer part of Log2
+ fraction points to the newly calculated fractional part of Log2
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ table = Log2 table of constants of type Word16
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The function Log2(L_x) calculates the logarithm of the normalized input
+ buffer L_x. The logarithm is approximated by a table and linear
+ interpolation. The following steps are used to compute Log2(L_x):
+
+ 1. exponent = 30 - norm_exponent
+ 2. i = bit25-b31 of L_x; 32<=i<=63 (because of normalization).
+ 3. a = bit10-b24
+ 4. i = i - 32
+ 5. fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ log2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Log2_norm (
+ Word32 L_x, // (i) : input value (normalized)
+ Word16 exp, // (i) : norm_l (L_x)
+ Word16 *exponent, // (o) : Integer part of Log2. (range: 0<=val<=30)
+ Word16 *fraction // (o) : Fractional part of Log2. (range: 0<=val<1)
+)
+{
+ Word16 i, a, tmp;
+ Word32 L_y;
+
+ if (L_x <= (Word32) 0)
+ {
+ *exponent = 0;
+ *fraction = 0;
+ return;
+ }
+
+ *exponent = sub (30, exp);
+
+ L_x = L_shr (L_x, 9);
+ i = extract_h (L_x); // Extract b25-b31
+ L_x = L_shr (L_x, 1);
+ a = extract_l (L_x); // Extract b10-b24 of fraction
+ a = a & (Word16) 0x7fff;
+
+ i = sub (i, 32);
+
+ L_y = L_deposit_h (table[i]); // table[i] << 16
+ tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1]
+ L_y = L_msu (L_y, tmp, a); // L_y -= tmp*a*2
+
+ *fraction = extract_h (L_y);
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Log2_norm(
+ Word32 L_x, /* (i) : input value (normalized) */
+ Word16 exp, /* (i) : norm_l (L_x) */
+ Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30)*/
+ Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+)
+{
+ Word16 i, a, tmp;
+ Word32 L_y;
+
+ if (L_x <= (Word32) 0)
+ {
+ *exponent = 0;
+ *fraction = 0;
+ }
+ else
+ {
+ /* Calculate exponent portion of Log2 */
+ *exponent = 30 - exp;
+
+ /* At this point, L_x > 0 */
+ /* Shift L_x to the right by 10 to extract bits 10-31, */
+ /* which is needed to calculate fractional part of Log2 */
+ L_x >>= 10;
+ i = (Word16)(L_x >> 15); /* Extract b25-b31 */
+ a = L_x & 0x7fff; /* Extract b10-b24 of fraction */
+
+ /* Calculate table index -> subtract by 32 is done for */
+ /* proper table indexing, since 32<=i<=63 (due to normalization) */
+ i -= 32;
+
+ /* Fraction part of Log2 is approximated by using table[] */
+ /* and linear interpolation, i.e., */
+ /* fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 */
+ L_y = (Word32) log2_tbl[i] << 16; /* table[i] << 16 */
+ tmp = log2_tbl[i] - log2_tbl[i + 1]; /* table[i] - table[i+1] */
+ L_y -= (((Word32) tmp) * a) << 1; /* L_y -= tmp*a*2 */
+
+ *fraction = (Word16)(L_y >> 16);
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/log2_tbl.cpp b/media/codecs/amrnb/common/src/log2_tbl.cpp
new file mode 100644
index 0000000..9b9b099
--- /dev/null
+++ b/media/codecs/amrnb/common/src/log2_tbl.cpp
@@ -0,0 +1,165 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/log2_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the declaration for log2_tbl[] used by the log2() and
+ log2_norm() function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "log2_norm.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+ const Word16 log2_tbl[33] =
+ {
+ 0, 1455, 2866, 4236, 5568, 6863, 8124, 9352, 10549, 11716,
+ 12855, 13967, 15054, 16117, 17156, 18172, 19167, 20142, 21097, 22033,
+ 22951, 23852, 24735, 25603, 26455, 27291, 28113, 28922, 29716, 30497,
+ 31266, 32023, 32767
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] log2.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/common/src/lsfwt.cpp b/media/codecs/amrnb/common/src/lsfwt.cpp
new file mode 100644
index 0000000..6b511f7
--- /dev/null
+++ b/media/codecs/amrnb/common/src/lsfwt.cpp
@@ -0,0 +1,242 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/lsfwt.c
+ Functions: Lsf_wt
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated to accept new parameter, Flag *pOverflow. Placed
+ file in the proper PV Software template.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation, by evaluating the operands
+ 4. Unrolled loops to speed up processing, use decrement loops
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Who: Date:
+ Description:
+
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf -- Pointer to Word16 -- LSF vector
+
+ Outputs:
+ wf -- Pointer to Word16 -- square of weighting factors
+ pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+Compute LSF weighting factors
+
+ d[i] = lsf[i+1] - lsf[i-1]
+
+ The weighting factors are approximated by two line segment
+
+ First segment passes by the following 2 points:
+
+ d[i] = 0Hz wf[i] = 3.347
+ d[i] = 450Hz wf[i] = 1.8
+
+ Second segment passes by the following 2 points:
+
+ d[i] = 450Hz wf[i] = 1.8
+ d[i] = 1500Hz wf[i] = 1.0
+
+ if( d[i] < 450Hz )
+ wf[i] = 3.347 - ( (3.347-1.8) / (450-0)) * d[i]
+ else
+ wf[i] = 1.8 - ( (1.8-1.0) / (1500-450)) * (d[i] - 450)
+
+
+ if( d[i] < 1843)
+ wf[i] = 3427 - (28160*d[i])>>15
+ else
+ wf[i] = 1843 - (6242*(d[i]-1843))>>15
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsfwt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "lsfwt.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Lsf_wt(
+ Word16 *lsf, /* input : LSF vector */
+ Word16 *wf, /* output: square of weighting factors */
+ Flag *pOverflow
+)
+{
+ Word16 temp;
+ Word16 wgt_fct;
+ Word16 i;
+ Word16 *p_wf = wf;
+ Word16 *p_lsf = &lsf[0];
+ Word16 *p_lsf_2 = &lsf[1];
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ /* wf[0] = lsf[1] - 0 */
+ *(p_wf++) = *(p_lsf_2++);
+
+ for (i = 4; i != 0 ; i--)
+ {
+ *(p_wf++) = *(p_lsf_2++) - *(p_lsf++);
+ *(p_wf++) = *(p_lsf_2++) - *(p_lsf++);
+ }
+ /*
+ * wf[9] = 4000 - lsf[8]
+ */
+ *(p_wf) = 16384 - *(p_lsf);
+
+ p_wf = wf;
+
+ for (i = 10; i != 0; i--)
+ {
+ /*
+ * (wf[i] - 450);
+ * 1843 == 450 Hz (Q15 considering 7FFF = 8000 Hz)
+ */
+ wgt_fct = *p_wf;
+ temp = wgt_fct - 1843;
+
+ if (temp > 0)
+ {
+ temp = (Word16)(((Word32)temp * 6242) >> 15);
+ wgt_fct = 1843 - temp;
+ }
+ else
+ {
+ temp = (Word16)(((Word32)wgt_fct * 28160) >> 15);
+ wgt_fct = 3427 - temp;
+ }
+
+ *(p_wf++) = wgt_fct << 3;
+
+ } /* for (i = 10; i != 0; i--) */
+
+ return;
+
+} /* Lsf_wt() */
diff --git a/media/codecs/amrnb/common/src/lsp.cpp b/media/codecs/amrnb/common/src/lsp.cpp
new file mode 100644
index 0000000..81d9cde
--- /dev/null
+++ b/media/codecs/amrnb/common/src/lsp.cpp
@@ -0,0 +1,532 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/lsp.c
+ Functions:
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Per review comments, added pOverflow flag to a few forgotten
+ functions. Removed unnecessary include files.
+
+ Description: For lsp_reset() and lsp()
+ 1. Replaced copy() with more efficient memcpy().
+ 2. Eliminated unused include file copy.h.
+
+ Description: For lsp_reset()
+ 1. Modified memcpy() operands order.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <string.h>
+
+#include "lsp.h"
+#include "typedef.h"
+#include "q_plsf.h"
+#include "az_lsp.h"
+#include "int_lpc.h"
+#include "lsp_tab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lsp_init (lspState **st)
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = Pointer to type lspState
+
+ Outputs:
+ st = Pointer to type lspState -- values are initialized.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ lsp_init_data = Word16 array.
+
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Initializes lsp state data.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 lsp_init(lspState **st)
+{
+ lspState* s;
+
+ if (st == (lspState **) NULL)
+ {
+ /* fprintf(stderr, "lsp_init: invalid parameter\n"); */
+ return -1;
+ }
+
+ *st = NULL;
+
+ /* allocate memory */
+ if ((s = (lspState *) calloc(sizeof(lspState), 1)) == NULL)
+ {
+ /* fprintf(stderr, "lsp_init: can not malloc state structure\n"); */
+ return -1;
+ }
+
+ /* Initialize quantization state */
+ if (0 != Q_plsf_init(&s->qSt))
+ {
+ lsp_exit(&s);
+ return -1;
+ }
+
+ if (0 != lsp_reset(s))
+ {
+ lsp_exit(&s);
+ return -1;
+ }
+
+ *st = s;
+
+ return 0;
+}
+
+
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lsp_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = Pointer to type lspState
+
+ Outputs:
+ st = Pointer to type lspState -- values are reset.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ resets lsp_state data
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 lsp_reset(lspState *st)
+{
+
+ if (st == (lspState *) NULL)
+ {
+ /* fprintf(stderr, "lsp_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ /* Init lsp_old[] */
+ memcpy(st->lsp_old, lsp_init_data, M*sizeof(Word16));
+
+ /* Initialize lsp_old_q[] */
+ memcpy(st->lsp_old_q, st->lsp_old, M*sizeof(Word16));
+
+ /* Reset quantization state */
+ Q_plsf_reset(st->qSt);
+
+ return 0;
+}
+
+
+
+
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lsp_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = Pointer to type lspState
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Frees memory used by lspState.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void lsp_exit(lspState **st)
+{
+ if (st == NULL || *st == NULL)
+ return;
+
+ /* Deallocate members */
+ Q_plsf_exit(&(*st)->qSt);
+
+ /* deallocate memory */
+ free(*st);
+ *st = NULL;
+
+ return;
+}
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lsp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+
+ Inputs:
+ st = Pointer to type lspState -- State struct
+ req_mode = enum Mode -- requested coder mode
+ used_mode = enum Mode -- used coder mode
+ az = array of type Word16 -- interpolated LP parameters Q12
+
+ Outputs:
+ azQ = array of type Word16 -- quantization interpol. LP parameters Q12
+ lsp_new = array of type Word16 -- new lsp vector
+ anap = Double pointer of type Word16 -- analysis parameters
+ pOverflow = Pointer to type Flag -- Flag set when overflow occurs
+ st = Pointer to type lspState -- State struct
+ az = array of type Word16 -- interpolated LP parameters Q12
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void lsp(lspState *st, /* i/o : State struct */
+ enum Mode req_mode, /* i : requested coder mode */
+ enum Mode used_mode,/* i : used coder mode */
+ Word16 az[], /* i/o : interpolated LP parameters Q12 */
+ Word16 azQ[], /* o : quantization interpol. LP parameters Q12*/
+ Word16 lsp_new[], /* o : new lsp vector */
+ Word16 **anap, /* o : analysis parameters */
+ Flag *pOverflow) /* o : Flag set when overflow occurs */
+
+{
+ Word16 lsp_new_q[M]; /* LSPs at 4th subframe */
+ Word16 lsp_mid[M], lsp_mid_q[M]; /* LSPs at 2nd subframe */
+
+ Word16 pred_init_i; /* init index for MA prediction in DTX mode */
+
+ if (req_mode == MR122)
+ {
+ Az_lsp(&az[MP1], lsp_mid, st->lsp_old, pOverflow);
+ Az_lsp(&az[MP1 * 3], lsp_new, lsp_mid, pOverflow);
+
+ /*--------------------------------------------------------------------*
+ * Find interpolated LPC parameters in all subframes (both quantized *
+ * and unquantized). *
+ * The interpolated parameters are in array A_t[] of size (M+1)*4 *
+ * and the quantized interpolated parameters are in array Aq_t[] *
+ *--------------------------------------------------------------------*/
+ Int_lpc_1and3_2(st->lsp_old, lsp_mid, lsp_new, az, pOverflow);
+
+ if (used_mode != MRDTX)
+ {
+ /* LSP quantization (lsp_mid[] and lsp_new[] jointly quantized) */
+ Q_plsf_5(
+ st->qSt,
+ lsp_mid,
+ lsp_new,
+ lsp_mid_q,
+ lsp_new_q,
+ *anap,
+ pOverflow);
+
+ Int_lpc_1and3(st->lsp_old_q, lsp_mid_q, lsp_new_q, azQ, pOverflow);
+
+ /* Advance analysis parameters pointer */
+ (*anap) += 5;
+ }
+ }
+ else
+ {
+ Az_lsp(&az[MP1 * 3], lsp_new, st->lsp_old, pOverflow); /* From A(z) to lsp */
+
+ /*--------------------------------------------------------------------*
+ * Find interpolated LPC parameters in all subframes (both quantized *
+ * and unquantized). *
+ * The interpolated parameters are in array A_t[] of size (M+1)*4 *
+ * and the quantized interpolated parameters are in array Aq_t[] *
+ *--------------------------------------------------------------------*/
+
+ Int_lpc_1to3_2(st->lsp_old, lsp_new, az, pOverflow);
+
+ if (used_mode != MRDTX)
+ {
+ /* LSP quantization */
+ Q_plsf_3(
+ st->qSt,
+ req_mode,
+ lsp_new,
+ lsp_new_q,
+ *anap,
+ &pred_init_i,
+ pOverflow);
+
+ Int_lpc_1to3(
+ st->lsp_old_q,
+ lsp_new_q,
+ azQ,
+ pOverflow);
+
+ /* Advance analysis parameters pointer */
+ (*anap) += 3;
+ }
+ }
+
+ /* update the LSPs for the next frame */
+ memcpy(st->lsp_old, lsp_new, M*sizeof(Word16));
+
+ if (used_mode != MRDTX)
+ {
+ memcpy(st->lsp_old_q, lsp_new_q, M*sizeof(Word16));
+ }
+}
+
diff --git a/media/codecs/amrnb/common/src/lsp_az.cpp b/media/codecs/amrnb/common/src/lsp_az.cpp
new file mode 100644
index 0000000..495359f
--- /dev/null
+++ b/media/codecs/amrnb/common/src/lsp_az.cpp
@@ -0,0 +1,555 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/lsp_az.c
+ Funtions: Get_lsp_pol
+ Lsp_Az
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Deleted all Local stores needed/modified. Optimized Lsp_Az
+ function by getting rid of call to L_shr_r function.
+
+ Description: Updated file per comments gathered from Phase 2/3 review.
+
+ Description: Added setting of Overflow flag in the inlined code.
+
+ Description: 1. Optimized Lsp_Az function code.
+ 2. Changed Input/Output definitions by adding Word type.
+
+ Description: Made changes based on review meeting.
+ 1. Removed pseudocode.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h and oper_32b.h with the header files of the
+ math functions used in the file.
+
+ Description: Modified to pass overflow flag through to L_add and L_sub. The
+ flag is passed back to the calling function by pointer reference.
+
+ Description: Removed the id line since it was removed in the header file by
+ Ken.
+
+ Description: Added the write-only variable, pOverflow, to the inputs section.
+
+ Description: For lsp_az() and Get_lsp_pol()
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation, in some cases this by shifting before adding and
+ in other cases by evaluating the operands
+ 4. Unrolled loops to speed up processing
+ 5. Replaced mpy_32_16 by multpilcations in place
+ 6. Eliminated if-else statements for sign extension when
+ right-shifting
+
+ Description: Added casting to eliminate warnings, and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with defined types.
+ Added proper casting (Word32) to some left shifting operations
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains functions that convert line spectral pairs (LSP) to
+ linear predictive (LP) coefficients (filter order = 10). The functions
+ included in this file include Get_lsp_pol, which finds the coefficients of
+ F1(z) and F2(z), and Lsp_Az, which converts LSP to LPC by multiplying
+ F1(z) by 1+z^(-1) and F2(z) by 1-z^(-1), then calculating A(z) = (F1(z) +
+ F2(z))/2.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "lsp_az.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Get_lsp_pol
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp = pointer to the buffer containing the line spectral pairs (LSP)
+ of type Word16
+ f = pointer to the polynomial of type Word32 to be generated
+
+ pOverflow = pointer set in case where one of the operations overflows.
+ [data type Pointer to Flag]
+
+ Outputs:
+ buffer pointed to by f contains the polynomial generated
+
+ pOverflow = pointer set in case where one of the operations overflows.
+ [data type Pointer to Flag]
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function finds the polynomial F1(z) or F2(z) from the LSPs. If the LSP
+ vector is passed at address 0, F1(z) is computed and if it is passed at
+ address 1, F2(z) is computed.
+
+ This is performed by expanding the product polynomials:
+
+ F1(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 )
+ i=0,2,4,6,8
+ F2(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 )
+ i=1,3,5,7,9
+
+ where lsp[] is the LSP vector in the cosine domain.
+
+ The expansion is performed using the following recursion:
+
+ f[0] = 1
+ b = -2.0 * lsp[0]
+ f[1] = b
+ for i=2 to 5 do
+ b = -2.0 * lsp[2*i-2];
+ for j=i-1 down to 2 do
+ f[j] = f[j] + b*f[j-1] + f[j-2];
+ f[1] = f[1] + b;
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp_az.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static void Get_lsp_pol (Word16 *lsp, Word32 *f)
+{
+ Word16 i, j, hi, lo;
+ Word32 t0;
+
+ // f[0] = 1.0;
+ *f = L_mult (4096, 2048);
+ f++;
+ *f = L_msu ((Word32) 0, *lsp, 512); // f[1] = -2.0 * lsp[0];
+ f++;
+ lsp += 2; // Advance lsp pointer
+
+ for (i = 2; i <= 5; i++)
+ {
+ *f = f[-2];
+
+ for (j = 1; j < i; j++, f--)
+ {
+ L_Extract (f[-1], &hi, &lo);
+ t0 = Mpy_32_16 (hi, lo, *lsp); // t0 = f[-1] * lsp
+ t0 = L_shl (t0, 1);
+ *f = L_add (*f, f[-2]); // *f += f[-2]
+ *f = L_sub (*f, t0); // *f -= t0
+ }
+ *f = L_msu (*f, *lsp, 512); // *f -= lsp<<9
+ f += i; // Advance f pointer
+ lsp += 2; // Advance lsp pointer
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void Get_lsp_pol(
+ Word16 *lsp,
+ Word32 *f,
+ Flag *pOverflow)
+{
+ Word16 i;
+ Word16 j;
+
+ Word16 hi;
+ Word16 lo;
+ Word32 t0;
+ OSCL_UNUSED_ARG(pOverflow);
+
+ /* f[0] = 1.0; */
+ *f++ = (Word32) 0x01000000;
+ *f++ = (Word32) - *(lsp++) << 10; /* f[1] = -2.0 * lsp[0]; */
+ lsp++; /* Advance lsp pointer */
+
+ for (i = 2; i <= 5; i++)
+ {
+ *f = *(f - 2);
+
+ for (j = 1; j < i; j++)
+ {
+ hi = (Word16)(*(f - 1) >> 16);
+
+ lo = (Word16)((*(f - 1) >> 1) - ((Word32) hi << 15));
+
+ t0 = ((Word32)hi * *lsp);
+ t0 += ((Word32)lo * *lsp) >> 15;
+
+ *(f) += *(f - 2); /* *f += f[-2] */
+ *(f--) -= t0 << 2; /* *f -= t0 */
+
+ }
+
+ *f -= (Word32)(*lsp++) << 10;
+
+ f += i;
+ lsp++;
+ }
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Get_lsp_pol_wrapper
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp = pointer to the buffer containing the line spectral pairs (LSP)
+ of type Word16
+ f = pointer to the polynomial of type Word32 to be generated
+
+ pOverflow = pointer set in case where one of the operations overflows.
+ [data type Pointer to Flag]
+
+ Outputs:
+ buffer pointed to by f contains the polynomial generated
+
+ pOverflow = pointer set in case where one of the operations overflows.
+ [data type Pointer to Flag]
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function provides external access to the static function Get_lsp_pol.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ CALL Get_lsp_pol(lsp = lsp_ptr
+ f = f_ptr )
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Get_lsp_pol_wrapper(
+ Word16 *lsp,
+ Word32 *f,
+ Flag *pOverflow)
+{
+ /*----------------------------------------------------------------------------
+ CALL Get_lsp_pol(lsp = lsp_ptr
+ f = f_ptr )
+ ----------------------------------------------------------------------------*/
+ Get_lsp_pol(lsp, f, pOverflow);
+
+ /*----------------------------------------------------------------------------
+ MODIFYING(nothing)
+ RETURNING(nothing)
+ ----------------------------------------------------------------------------*/
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Lsp_Az
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp = pointer to the buffer containing the line spectral pairs (LSP)
+ of type Word16
+
+ a = pointer to the buffer containing Linear Predictive (LP)
+ coefficients of type Word16 to be generated
+
+ pOverflow = pointer set in case where one of the operations overflows.
+ [data type Pointer to Flag]
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ pOverflow = pointer set in case where one of the operations overflows.
+ [data type Pointer to Flag]
+
+ Pointers and Buffers Modified:
+ a buffer contains the generated Linear Predictive (LP) coefficients
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function converts from the line spectral pairs (LSP) to LP coefficients
+ for a 10th order filter.
+
+ This is done by:
+ (1) Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol)
+ (2) Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1}
+ (3) A(z) = ( F1(z) + F2(z) ) / 2
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp_az.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Lsp_Az (
+ Word16 lsp[], // (i) : line spectral frequencies
+ Word16 a[] // (o) : predictor coefficients (order = 10)
+)
+{
+ Word16 i, j;
+ Word32 f1[6], f2[6];
+ Word32 t0;
+
+ Get_lsp_pol (&lsp[0], f1);
+ Get_lsp_pol (&lsp[1], f2);
+
+ for (i = 5; i > 0; i--)
+ {
+ f1[i] = L_add (f1[i], f1[i - 1]); // f1[i] += f1[i-1];
+ f2[i] = L_sub (f2[i], f2[i - 1]); // f2[i] -= f2[i-1];
+ }
+
+ a[0] = 4096;
+ for (i = 1, j = 10; i <= 5; i++, j--)
+ {
+ t0 = L_add (f1[i], f2[i]); // f1[i] + f2[i]
+ a[i] = extract_l (L_shr_r (t0, 13));
+ t0 = L_sub (f1[i], f2[i]); // f1[i] - f2[i]
+ a[j] = extract_l (L_shr_r (t0, 13));
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Lsp_Az(
+ Word16 lsp[], /* (i) : line spectral frequencies */
+ Word16 a[], /* (o) : predictor coefficients (order = 10) */
+ Flag *pOverflow /* (o) : overflow flag */
+)
+{
+ Word16 i;
+ Word16 j;
+
+ Word32 f1[6];
+ Word32 f2[6];
+ Word32 t0;
+ Word32 t1;
+ Word16 *p_a = &a[0];
+ Word32 *p_f1;
+ Word32 *p_f2;
+
+ Get_lsp_pol(&lsp[0], f1, pOverflow);
+
+ Get_lsp_pol(&lsp[1], f2, pOverflow);
+
+ p_f1 = &f1[5];
+ p_f2 = &f2[5];
+
+ for (i = 5; i > 0; i--)
+ {
+ *(p_f1--) += f1[i-1];
+ *(p_f2--) -= f2[i-1];
+ }
+
+ *(p_a++) = 4096;
+ p_f1 = &f1[1];
+ p_f2 = &f2[1];
+
+ for (i = 1, j = 10; i <= 5; i++, j--)
+ {
+ t0 = *(p_f1) + *(p_f2); /* f1[i] + f2[i] */
+ t1 = *(p_f1++) - *(p_f2++); /* f1[i] - f2[i] */
+
+ t0 = t0 + ((Word32) 1 << 12);
+ t1 = t1 + ((Word32) 1 << 12);
+
+ *(p_a++) = (Word16)(t0 >> 13);
+ a[j] = (Word16)(t1 >> 13);
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/lsp_lsf.cpp b/media/codecs/amrnb/common/src/lsp_lsf.cpp
new file mode 100644
index 0000000..39d6eda
--- /dev/null
+++ b/media/codecs/amrnb/common/src/lsp_lsf.cpp
@@ -0,0 +1,384 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/lsp_lsf.c
+ Functions: Lsp_lsf
+ Lsf_lsp
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+
+ Description: Deleted variables listed in the Local Stores Needed/Modified
+ section.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template and removed unnecessary include files.
+
+ Description: Replaced basic_op.h with the header file of the math functions
+ used in the file.
+
+ Description: Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Placed table declarations in a .c file, rather than an included
+ .tab. The tables are now referenced via an extern in this file.
+
+ Description: For Lsp_lsf()
+ 1. Eliminated unused include file typedef.h.
+ 2. Replaced array addressing by pointers
+
+ Description: Replaced "int" and/or "char" with defined types.
+ Added proper casting (Word32) to some left shifting operations
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that convert line spectral pairs (LSP) to
+ line spectral frequencies (LSF) and vice-versa.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "lsp_lsf.h"
+#include "basicop_malloc.h"
+#include "basic_op.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ extern const Word16 table[];
+ extern const Word16 slope[];
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Lsf_lsp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf = buffer containing normalized line spectral frequencies; valid
+ range is between 0 and 0.5 (Word16)
+ lsp = buffer containing line spectral pairs; valid range is between
+ -1 and 1 (Word16)
+ m = LPC order (Word16)
+
+ Outputs:
+ lsp contains the newly calculated line spectral pairs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ table = cosine table
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the LSF to LSP transformation using the equation:
+
+ lsf[i] = arccos(lsp[i])/(2*pi)
+
+ The transformation from lsp[i] to lsf[i] is approximated by a look-up table
+ and interpolation.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Lsf_lsp (
+ Word16 lsf[], // (i) : lsf[m] normalized (range: 0.0<=val<=0.5)
+ Word16 lsp[], // (o) : lsp[m] (range: -1<=val<1)
+ Word16 m // (i) : LPC order
+)
+{
+ Word16 i, ind, offset;
+ Word32 L_tmp;
+
+ for (i = 0; i < m; i++)
+ {
+ ind = shr (lsf[i], 8); // ind = b8-b15 of lsf[i]
+ offset = lsf[i] & 0x00ff; // offset = b0-b7 of lsf[i]
+
+ // lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256
+
+ L_tmp = L_mult (sub (table[ind + 1], table[ind]), offset);
+ lsp[i] = add (table[ind], extract_l (L_shr (L_tmp, 9)));
+
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Lsf_lsp(
+ Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */
+ Word16 m, /* (i) : LPC order */
+ Flag *pOverflow /* (o) : Flag set when overflow occurs */
+)
+{
+ Word16 i, ind, offset;
+ Word32 L_tmp;
+
+ for (i = 0; i < m; i++)
+ {
+ ind = lsf[i] >> 8; /* ind = b8-b15 of lsf[i] */
+ offset = lsf[i] & 0x00ff; /* offset = b0-b7 of lsf[i] */
+
+ /* lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256 */
+
+ L_tmp = ((Word32)(table[ind + 1] - table[ind]) * offset) >> 8;
+ lsp[i] = add(table[ind], (Word16) L_tmp, pOverflow);
+
+ }
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Lsp_lsf
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsp = buffer containing line spectral pairs; valid range is between
+ -1 and 1 (Word16)
+ lsf = buffer containing normalized line spectral frequencies; valid
+ range is between 0 and 0.5 (Word16)
+ m = LPC order (Word16)
+
+ Outputs:
+ lsf contains the newly calculated normalized line spectral frequencies
+
+ Returns:
+ None
+
+ Global Variables Used:
+ table = cosine table
+ slope = table to used to calculate inverse cosine
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the LSP to LSF transformation using the equation:
+
+ lsp[i] = cos(2*pi*lsf[i])
+
+ The transformation from lsf[i] to lsp[i] is approximated by a look-up table
+ and interpolation.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lsp_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Lsp_lsf (
+ Word16 lsp[], // (i) : lsp[m] (range: -1<=val<1)
+ Word16 lsf[], // (o) : lsf[m] normalized (range: 0.0<=val<=0.5)
+ Word16 m // (i) : LPC order
+)
+{
+ Word16 i, ind;
+ Word32 L_tmp;
+
+ ind = 63; // begin at end of table -1
+
+ for (i = m - 1; i >= 0; i--)
+ {
+ // find value in table that is just greater than lsp[i]
+
+ while (sub (table[ind], lsp[i]) < 0)
+ {
+ ind--;
+
+ }
+
+ // acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) *
+ slope[ind] )/4096
+
+ L_tmp = L_mult (sub (lsp[i], table[ind]), slope[ind]);
+ //(lsp[i]-table[ind])*slope[ind])>>12
+ lsf[i] = pv_round (L_shl (L_tmp, 3));
+ lsf[i] = add (lsf[i], shl (ind, 8));
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Lsp_lsf(
+ Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */
+ Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 m, /* (i) : LPC order */
+ Flag *pOverflow /* (o) : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 ind;
+ Word16 temp;
+ Word32 L_tmp;
+ Word16 *p_lsp = &lsp[m-1];
+ Word16 *p_lsf = &lsf[m-1];
+ OSCL_UNUSED_ARG(pOverflow);
+
+ ind = 63; /* begin at end of table -1 */
+
+ for (i = m - 1; i >= 0; i--)
+ {
+ /* find value in table that is just greater than lsp[i] */
+ temp = *(p_lsp--);
+ while (table[ind] < temp)
+ {
+ ind--;
+ }
+
+ /* acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) *
+ slope[ind] )/4096 */
+
+ L_tmp = (Word32)(temp - table[ind]) * slope[ind];
+
+ /*(lsp[i]-table[ind])*slope[ind])>>12*/
+ L_tmp = (L_tmp + 0x00000800) >> 12;
+
+ *(p_lsf--) = (Word16)(L_tmp) + (ind << 8);
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/lsp_lsf_tbl.cpp b/media/codecs/amrnb/common/src/lsp_lsf_tbl.cpp
new file mode 100644
index 0000000..ddeeba4
--- /dev/null
+++ b/media/codecs/amrnb/common/src/lsp_lsf_tbl.cpp
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/src/lsp_lsf_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created this file from the reference, lsp_lsf.tab
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+ extern const Word16 table[];
+ const Word16 table[65] =
+ {
+ 32767, 32729, 32610, 32413, 32138, 31786, 31357, 30853,
+ 30274, 29622, 28899, 28106, 27246, 26320, 25330, 24279,
+ 23170, 22006, 20788, 19520, 18205, 16846, 15447, 14010,
+ 12540, 11039, 9512, 7962, 6393, 4808, 3212, 1608,
+ 0, -1608, -3212, -4808, -6393, -7962, -9512, -11039,
+ -12540, -14010, -15447, -16846, -18205, -19520, -20788, -22006,
+ -23170, -24279, -25330, -26320, -27246, -28106, -28899, -29622,
+ -30274, -30853, -31357, -31786, -32138, -32413, -32610, -32729,
+ (Word16) 0x8000
+ };
+
+ /* 0x8000 = -32768 (used to silence the compiler) */
+
+ /* slope used to compute y = acos(x) */
+
+ extern const Word16 slope[];
+ const Word16 slope[64] =
+ {
+ -26887, -8812, -5323, -3813, -2979, -2444, -2081, -1811,
+ -1608, -1450, -1322, -1219, -1132, -1059, -998, -946,
+ -901, -861, -827, -797, -772, -750, -730, -713,
+ -699, -687, -677, -668, -662, -657, -654, -652,
+ -652, -654, -657, -662, -668, -677, -687, -699,
+ -713, -730, -750, -772, -797, -827, -861, -901,
+ -946, -998, -1059, -1132, -1219, -1322, -1450, -1608,
+ -1811, -2081, -2444, -2979, -3813, -5323, -8812, -26887
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/media/codecs/amrnb/common/src/lsp_tab.cpp b/media/codecs/amrnb/common/src/lsp_tab.cpp
new file mode 100644
index 0000000..0a32dd7
--- /dev/null
+++ b/media/codecs/amrnb/common/src/lsp_tab.cpp
@@ -0,0 +1,188 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: .audio/gsm-amr/c/src/lsp_tab.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition. Removed corresponding header file from Include
+ section.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : lsp.tab
+ Purpose : Table for lsp init
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "lsp_tab.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ const Word16 lsp_init_data[M] = {30000, 26000, 21000, 15000, 8000,
+ 0, -8000, -15000, -21000, -26000
+ };
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/common/src/mult_r.cpp b/media/codecs/amrnb/common/src/mult_r.cpp
new file mode 100644
index 0000000..7112b3d
--- /dev/null
+++ b/media/codecs/amrnb/common/src/mult_r.cpp
@@ -0,0 +1,218 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/mult_r.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the mult_r function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Passing in a pointer to the overflow flag instead of using
+ a global flag.
+
+ Description: Made the following changes based on P2/P3 review:
+ 1) Simplified test to determine if sign extension is necessary
+ 2) Changed the name of pointer "overflow" to "Poverflow"
+ 3) Removed code that updates MOPS counter
+ 4) Updated template and reference section
+
+ Who: Date:
+ Description:
+
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Multiplication function with rounding and overflow control
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: mult_r
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the add operation resulted in overflow
+
+ Returns:
+ L_product_arr = 16-bit limited product of var1 and var2 (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the multiplication of var1 by var2 with rounding, and
+ gives a 16 bit result which is scaled, i.e.:
+ mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and |
+ mult_r(-32768,-32768) = 32767
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] mult_r() function in basicop2.c, UMTS GSM AMR speech codec, R99 -
+ Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 mult_r (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_product_arr;
+
+ L_product_arr = (Word32) var1 *(Word32) var2;
+ L_product_arr += (Word32) 0x00004000L;
+ L_product_arr &= (Word32) 0xffff8000L;
+ L_product_arr >>= 15;
+
+ if (L_product_arr & (Word32) 0x00010000L)
+ {
+ L_product_arr |= (Word32) 0xffff0000L;
+ }
+* The reference ETSI code uses a global flag for Overflow inside the function
+* saturate(). In the actual implementation a pointer to Overflow flag is passed in
+* as a parameter to the function
+
+ var_out = saturate (L_product_arr);
+
+#if (WMOPS)
+ multiCounter[currCounter].mult_r++;
+#endif
+
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+Word16 mult_r(Word16 var1, Word16 var2, Flag *pOverflow)
+{
+
+ Word32 L_product_arr;
+
+ L_product_arr = ((Word32) var1) * var2; /* product */
+ L_product_arr += (Word32) 0x00004000L; /* round */
+ L_product_arr >>= 15; /* shift */
+
+ /* sign extend when necessary */
+ L_product_arr |= (Word32) - (L_product_arr & (Word32) 0x00010000L);
+
+ /* Saturate result (if necessary). */
+ /* Replaced function call with in-line code to conserve MIPS, */
+ /* i.e., var_out = saturate (L_product_arr) */
+
+ if (L_product_arr > 0X00007fffL)
+ {
+ *pOverflow = 1;
+ L_product_arr = MAX_16;
+ }
+ else if (L_product_arr < (Word32) 0xffff8000L)
+ {
+ *pOverflow = 1;
+ L_product_arr = MIN_16;
+ }
+
+ return ((Word16) L_product_arr);
+}
diff --git a/media/codecs/amrnb/common/src/negate.cpp b/media/codecs/amrnb/common/src/negate.cpp
new file mode 100644
index 0000000..aa36422
--- /dev/null
+++ b/media/codecs/amrnb/common/src/negate.cpp
@@ -0,0 +1,179 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/src/negate.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the negate function. Sync'ed up with
+ the current template and fixed tabs.
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ var1 = negated value of input (Word16)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function negates var1 with saturation; saturate in the case where input
+ is -32768: negate(var1) = sub(0,var1).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 negate (Word16 var1)
+{
+ Word16 var_out;
+
+ var_out = (var1 == MIN_16) ? MAX_16 : -var1;
+#if (WMOPS)
+ multiCounter[currCounter].negate++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "negate.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 negate(Word16 var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ var1 = (var1 == MIN_16) ? MAX_16 : -var1;
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return (var1);
+}
diff --git a/media/codecs/amrnb/common/src/norm_l.cpp b/media/codecs/amrnb/common/src/norm_l.cpp
new file mode 100644
index 0000000..d8d1259
--- /dev/null
+++ b/media/codecs/amrnb/common/src/norm_l.cpp
@@ -0,0 +1,247 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./gsm-amr/c/src/norm_l.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the norm_l function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Updated module description to be the same as the equivalent
+ assembly file (norm_l.asm).
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Description: Made the following changes
+ 1. Unrolled the search loop to make four comparison per
+ pass, using only four iterations of the loop and saving
+ shifts cycles
+ 2. Updated header and copyright year
+
+ Description: 1. Support for ARM and Linux-ARM assembly instructions.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= var1 <= 0x7fff ffff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ var_out = number of left shifts need to normalize input (Word16)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function produces the number of left shifts needed to normalize the 32
+ bit variable L_var1 for positive values on the interval with minimum of
+ 0x40000000 and maximum of 0x7fffffff, and for negative values on the interval
+ with minimum of 0x80000000 and maximum of 0xc0000000. Note that when L_var1
+ is equal to zero, the output var_out is set to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 norm_l (Word32 L_var1)
+{
+ Word16 var_out;
+
+ if (L_var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (L_var1 == (Word32) 0xffffffffL)
+ {
+ var_out = 31;
+ }
+ else
+ {
+ if (L_var1 < 0)
+ {
+ L_var1 = ~L_var1;
+ }
+ for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
+ {
+ L_var1 <<= 1;
+ }
+ }
+ }
+
+#if (WMOPS)
+ multiCounter[currCounter].norm_l++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) )
+Word16 norm_l(Word32 L_var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ Word16 var_out = 0;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ if (L_var1)
+ {
+
+ Word32 y = L_var1 - (L_var1 < 0);
+ L_var1 = y ^(y >> 31);
+
+
+ while (!(0x40000000L & L_var1))
+ {
+ var_out++;
+ if ((0x20000000L & L_var1))
+ {
+ break;
+ }
+ var_out++;
+ if ((0x10000000L & L_var1))
+ {
+ break;
+ }
+ var_out++;
+ if ((0x08000000L & L_var1))
+ {
+ break;
+ }
+ var_out++;
+ L_var1 <<= 4;
+ }
+ }
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+
+
+ return (var_out);
+}
+#endif
diff --git a/media/codecs/amrnb/common/src/norm_s.cpp b/media/codecs/amrnb/common/src/norm_s.cpp
new file mode 100644
index 0000000..6468b67
--- /dev/null
+++ b/media/codecs/amrnb/common/src/norm_s.cpp
@@ -0,0 +1,242 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/src/norm_s.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the norm_s function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Updated input/output definition and module description to
+ be the same as the equivalent assembly file (norm_s.asm).
+
+ Description: Updated definition of var1 to be the same as that in the
+ assembly file (norm_s.asm).
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit signed integer of type Word16, whose value falls
+ in the range: 0x8000 <= var1 <= 0x7fff
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ var_out = number of left shifts need to normalize var1 (Word16)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function produces the number of left shifts needed to normalize the 16
+ bit variable var1 for positive values on the interval with minimum of 0x4000
+ and maximum of 0x7fff, and for negative values on the interval with minimum
+ of 0x8000 and maximum of 0xc000. Note that when var1 is zero, the resulting
+ output var_out is set to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 norm_s (Word16 var1)
+{
+ Word16 var_out;
+
+ if (var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (var1 == (Word16) 0xffff)
+ {
+ var_out = 15;
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var1 = ~var1;
+ }
+ for (var_out = 0; var1 < 0x4000; var_out++)
+ {
+ var1 <<= 1;
+ }
+ }
+ }
+
+#if (WMOPS)
+ multiCounter[currCounter].norm_s++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+#if !( defined(PV_ARM_V5) || defined(PV_ARM_GCC_V5) )
+
+Word16 norm_s(Word16 var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ Word16 var_out = 0;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ if (var1)
+ {
+ Word16 y = var1 - (var1 < 0);
+ var1 = y ^(y >> 15);
+
+ while (!(0x4000 & var1))
+ {
+ var_out++;
+ if ((0x2000 & var1))
+ {
+ break;
+ }
+ var_out++;
+ if ((0x1000 & var1))
+ {
+ break;
+ }
+ var_out++;
+ if ((0x0800 & var1))
+ {
+ break;
+ }
+ var_out++;
+ var1 <<= 4;
+ }
+ }
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return (var_out);
+}
+
+#endif
diff --git a/media/codecs/amrnb/common/src/ph_disp_tab.cpp b/media/codecs/amrnb/common/src/ph_disp_tab.cpp
new file mode 100644
index 0000000..d568b78
--- /dev/null
+++ b/media/codecs/amrnb/common/src/ph_disp_tab.cpp
@@ -0,0 +1,192 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/ph_disp_tab.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the table of impulse responses of the phase dispersion
+ filters. All impulse responses are in Q15
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+ extern const Word16 ph_imp_low_MR795[];
+ const Word16 ph_imp_low_MR795[40] =
+ {
+ 26777, 801, 2505, -683, -1382, 582, 604, -1274, 3511, -5894,
+ 4534, -499, -1940, 3011, -5058, 5614, -1990, -1061, -1459, 4442,
+ -700, -5335, 4609, 452, -589, -3352, 2953, 1267, -1212, -2590,
+ 1731, 3670, -4475, -975, 4391, -2537, 949, -1363, -979, 5734
+ };
+ extern const Word16 ph_imp_mid_MR795[];
+ const Word16 ph_imp_mid_MR795[40] =
+ {
+ 30274, 3831, -4036, 2972, -1048, -1002, 2477, -3043, 2815, -2231,
+ 1753, -1611, 1714, -1775, 1543, -1008, 429, -169, 472, -1264,
+ 2176, -2706, 2523, -1621, 344, 826, -1529, 1724, -1657, 1701,
+ -2063, 2644, -3060, 2897, -1978, 557, 780, -1369, 842, 655
+ };
+
+ extern const Word16 ph_imp_low[];
+ const Word16 ph_imp_low[40] =
+ {
+ 14690, 11518, 1268, -2761, -5671, 7514, -35, -2807, -3040, 4823,
+ 2952, -8424, 3785, 1455, 2179, -8637, 8051, -2103, -1454, 777,
+ 1108, -2385, 2254, -363, -674, -2103, 6046, -5681, 1072, 3123,
+ -5058, 5312, -2329, -3728, 6924, -3889, 675, -1775, 29, 10145
+ };
+ extern const Word16 ph_imp_mid[];
+ const Word16 ph_imp_mid[40] =
+ {
+ 30274, 3831, -4036, 2972, -1048, -1002, 2477, -3043, 2815, -2231,
+ 1753, -1611, 1714, -1775, 1543, -1008, 429, -169, 472, -1264,
+ 2176, -2706, 2523, -1621, 344, 826, -1529, 1724, -1657, 1701,
+ -2063, 2644, -3060, 2897, -1978, 557, 780, -1369, 842, 655
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ph_disp.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
+
diff --git a/media/codecs/amrnb/common/src/pow2.cpp b/media/codecs/amrnb/common/src/pow2.cpp
new file mode 100644
index 0000000..a8686f8
--- /dev/null
+++ b/media/codecs/amrnb/common/src/pow2.cpp
@@ -0,0 +1,202 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/pow2.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Changed function interface to pass in a
+ pointer to overflow flag into the function instead of using a
+ global flag. Removed inclusion of "pow2.tab"
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pow2.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pow2
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ exponent = Integer part whose valid range is: 0 <= value <= 30 (Word16)
+ fraction = Fractional part whose valid range is 0 <= value < 1
+
+ pOverflow = pointer to overflow flag
+
+ Outputs:
+ L_x = Result of the Pow2() computation (Word32)
+ pOverflow -> 1 if the Pow2() function results in saturation
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes L_x = pow(2.0, exponent.fraction)
+
+ The function Pow2(L_x) is approximated by a table and linear interpolation.
+
+ 1- i = bit10-b15 of fraction, 0 <= i <= 31
+ 2- a = bit0-b9 of fraction
+ 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ 4- L_x = L_x >> (30-exponent) (with rounding)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pow2.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 Pow2 ( // (o) : result (range: 0<=val<=0x7fffffff)
+ Word16 exponent, // (i) : Integer part. (range: 0<=val<=30)
+ Word16 fraction // (i) : Fractional part. (range: 0.0<=val<1.0)
+)
+{
+ Word16 exp, i, a, tmp;
+ Word32 L_x;
+
+ L_x = L_mult (fraction, 32); // L_x = fraction<<6
+ i = extract_h (L_x); // Extract b10-b16 of fraction
+ L_x = L_shr (L_x, 1);
+ a = extract_l (L_x); // Extract b0-b9 of fraction
+ a = a & (Word16) 0x7fff;
+
+ L_x = L_deposit_h (table[i]); // table[i] << 16
+ tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1]
+ L_x = L_msu (L_x, tmp, a); // L_x -= tmp*a*2
+
+ exp = sub (30, exponent);
+ L_x = L_shr_r (L_x, exp);
+
+ return (L_x);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+Word32 Pow2( /* (o) : result (range: 0<=val<=0x7fffffff) */
+ Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */
+ Word16 fraction, /* (i) : Fractional part. (range: 0.0<=val<1.0) */
+ Flag *pOverflow
+)
+{
+ Word16 exp, i, a, tmp;
+ Word32 L_x;
+
+ L_x = L_mult(fraction, 32, pOverflow); /* L_x = fraction<<6 */
+
+ /* Extract b0-b16 of fraction */
+
+ i = ((Word16)(L_x >> 16)) & 31; /* ensure index i is bounded */
+ a = (Word16)((L_x >> 1) & 0x7fff);
+
+ L_x = L_deposit_h(pow2_tbl[i]); /* pow2_tbl[i] << 16 */
+
+ /* pow2_tbl[i] - pow2_tbl[i+1] */
+ tmp = sub(pow2_tbl[i], pow2_tbl[i + 1], pOverflow);
+ L_x = L_msu(L_x, tmp, a, pOverflow); /* L_x -= tmp*a*2 */
+
+ exp = sub(30, exponent, pOverflow);
+ L_x = L_shr_r(L_x, exp, pOverflow);
+
+ return (L_x);
+}
diff --git a/media/codecs/amrnb/common/src/pow2_tbl.cpp b/media/codecs/amrnb/common/src/pow2_tbl.cpp
new file mode 100644
index 0000000..902ea0f
--- /dev/null
+++ b/media/codecs/amrnb/common/src/pow2_tbl.cpp
@@ -0,0 +1,164 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/pow2_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the declaration for log2_tbl[] used by the Pow2() function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "pow2.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+ const Word16 pow2_tbl[33] =
+ {
+ 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911,
+ 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726,
+ 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706,
+ 31379, 32066, 32767
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] pow2.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/common/src/pred_lt.cpp b/media/codecs/amrnb/common/src/pred_lt.cpp
new file mode 100644
index 0000000..8a1aa9e
--- /dev/null
+++ b/media/codecs/amrnb/common/src/pred_lt.cpp
@@ -0,0 +1,349 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/pred_lt.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Deleted variables listed in the Local Stores Needed/Modified
+ sections.
+
+ Description: Updated file per comments from Phase 2/3 review.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Fixed typecasting issue with TI C compiler. Updated copyright
+ year.
+
+ Description:
+ (1) Removed instance of static in the const table "inter_6"
+ (2) Changed Overflow from a global to a parameter passed via a pointer.
+ (3) Made numerous small changes to bring code more in line with PV standards.
+
+ Description: For pred_ltp()
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation
+ 4. Unrolled loops to speed up processing, use decrement loops,
+ loaded into memory filter coefficient in linear order for
+ faster execution in main loop.
+ 5. Eliminated call to round by proper initialization
+
+ Description: Replaced "int" and/or "char" with defined types.
+ Added proper casting (Word32) to some left shifting operations
+
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pred_lt.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define UP_SAMP_MAX 6
+#define L_INTER10 (L_INTERPOL-1)
+#define FIR_SIZE (UP_SAMP_MAX*L_INTER10+1)
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* 1/6 resolution interpolation filter (-3 dB at 3600 Hz) */
+/* Note: the 1/3 resolution filter is simply a subsampled
+ * version of the 1/6 resolution filter, i.e. it uses
+ * every second coefficient:
+ *
+ * inter_3l[k] = inter_6[2*k], 0 <= k <= 3*L_INTER10
+ */
+
+const Word16 inter_6_pred_lt[FIR_SIZE] =
+{
+ 29443,
+ 28346, 25207, 20449, 14701, 8693, 3143,
+ -1352, -4402, -5865, -5850, -4673, -2783,
+ -672, 1211, 2536, 3130, 2991, 2259,
+ 1170, 0, -1001, -1652, -1868, -1666,
+ -1147, -464, 218, 756, 1060, 1099,
+ 904, 550, 135, -245, -514, -634,
+ -602, -451, -231, 0, 191, 308,
+ 340, 296, 198, 78, -36, -120,
+ -163, -165, -132, -79, -19, 34,
+ 73, 91, 89, 70, 38, 0
+};
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pred_lt_3or6
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ exc = buffer containing the excitation (Word16)
+ T0 = integer pitch lag (Word16)
+ frac = fraction of lag (Word16)
+ L_subfr = number of samples per subframe (Word16)
+ flag3 = flag to indicate the upsampling rate; if set, upsampling
+ rate is 3, otherwise, upsampling rate is 6 (Word16)
+
+ pOverflow = pointer to overflow (Flag)
+
+ Returns:
+ None
+
+ Outputs:
+ exc buffer contains the newly formed adaptive codebook excitation
+ pOverflow -> 1 if the add operation resulted in overflow
+
+ Global Variables Used:
+ inter_6_pred_lt = (1/6) resolution interpolation filter table (Word16)
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the result of long term prediction with fractional
+ interpolation of resolution 1/3 or 1/6. (Interpolated past excitation).
+
+ The past excitation signal at the given delay is interpolated at
+ the given fraction to build the adaptive codebook excitation.
+ On return exc[0..L_subfr-1] contains the interpolated signal
+ (adaptive codebook excitation).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pred_lt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Pred_lt_3or6 (
+ Word16 exc[], // in/out: excitation buffer
+ Word16 T0, // input : integer pitch lag
+ Word16 frac, // input : fraction of lag
+ Word16 L_subfr, // input : subframe size
+ Word16 flag3 // input : if set, upsampling rate = 3 (6 otherwise)
+)
+{
+ Word16 i, j, k;
+ Word16 *pX0, *pX1, *pX2;
+ const Word16 *pC1, *pC2;
+ Word32 s;
+
+ pX0 = &exc[-T0];
+
+ frac = negate (frac);
+ if (flag3 != 0)
+ {
+ frac = shl (frac, 1); // inter_3l[k] = inter_6[2*k] -> k' = 2*k
+ }
+
+ if (frac < 0)
+ {
+ frac = add (frac, UP_SAMP_MAX);
+ pX0--;
+ }
+
+ for (j = 0; j < L_subfr; j++)
+ {
+ pX1 = pX0++;
+ pX2 = pX0;
+ pC1 = &inter_6[frac];
+ pC2 = &inter_6[sub (UP_SAMP_MAX, frac)];
+
+ s = 0;
+ for (i = 0, k = 0; i < L_INTER10; i++, k += UP_SAMP_MAX)
+ {
+ s = L_mac (s, pX1[-i], pC1[k]);
+ s = L_mac (s, pX2[i], pC2[k]);
+ }
+
+ exc[j] = pv_round (s);
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Pred_lt_3or6(
+ Word16 exc[], /* in/out: excitation buffer */
+ Word16 T0, /* input : integer pitch lag */
+ Word16 frac, /* input : fraction of lag */
+ Word16 L_subfr, /* input : subframe size */
+ Word16 flag3, /* input : if set, upsampling rate = 3 (6 otherwise) */
+ Flag *pOverflow /* output: if set, overflow occurred in this function */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+
+ Word16 *pX0;
+ Word16 *pX2;
+ Word16 *pX3;
+ Word16 *p_exc;
+ Word16 *pC1;
+ const Word16 *pC1_ref;
+ const Word16 *pC2_ref;
+
+ Word16 Coeff_1[(L_INTER10<<1)];
+
+ Word32 s1;
+ Word32 s2;
+ OSCL_UNUSED_ARG(pOverflow);
+
+ pX0 = &(exc[-T0]);
+
+ /* frac goes between -3 and 3 */
+
+ frac = -frac;
+
+ if (flag3 != 0)
+ {
+ frac <<= 1; /* inter_3l[k] = inter_6[2*k] -> k' = 2*k */
+ }
+
+ if (frac < 0)
+ {
+ frac += UP_SAMP_MAX;
+ pX0--;
+ }
+
+ pC1_ref = &inter_6_pred_lt[frac];
+ pC2_ref = &inter_6_pred_lt[UP_SAMP_MAX-frac];
+
+
+ pC1 = Coeff_1;
+
+ k = 0;
+
+ for (i = L_INTER10 >> 1; i > 0; i--)
+ {
+ *(pC1++) = pC1_ref[k];
+ *(pC1++) = pC2_ref[k];
+ k += UP_SAMP_MAX;
+ *(pC1++) = pC1_ref[k];
+ *(pC1++) = pC2_ref[k];
+ k += UP_SAMP_MAX;
+
+ }
+
+ p_exc = exc;
+
+ for (j = (L_subfr >> 1); j != 0 ; j--)
+ {
+ pX0++;
+ pX2 = pX0;
+ pX3 = pX0++;
+
+ pC1 = Coeff_1;
+
+ s1 = 0x00004000L;
+ s2 = 0x00004000L;
+
+ for (i = L_INTER10 >> 1; i > 0; i--)
+ {
+ s2 += ((Word32) * (pX3--)) * *(pC1);
+ s1 += ((Word32) * (pX3)) * *(pC1++);
+ s1 += ((Word32) * (pX2++)) * *(pC1);
+ s2 += ((Word32) * (pX2)) * *(pC1++);
+ s2 += ((Word32) * (pX3--)) * *(pC1);
+ s1 += ((Word32) * (pX3)) * *(pC1++);
+ s1 += ((Word32) * (pX2++)) * *(pC1);
+ s2 += ((Word32) * (pX2)) * *(pC1++);
+
+ } /* for (i = L_INTER10>>1; i > 0; i--) */
+
+ *(p_exc++) = (Word16)(s1 >> 15);
+ *(p_exc++) = (Word16)(s2 >> 15);
+
+ } /* for (j = (L_subfr>>1); j != 0 ; j--) */
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/q_plsf.cpp b/media/codecs/amrnb/common/src/q_plsf.cpp
new file mode 100644
index 0000000..5d96baa
--- /dev/null
+++ b/media/codecs/amrnb/common/src/q_plsf.cpp
@@ -0,0 +1,144 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : q_plsf.c
+* Purpose : common part (init, exit, reset) of LSF quantization
+* module (rest in q_plsf_3.c and q_plsf_5.c)
+*
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+* MODULE INCLUDE FILE AND VERSION ID
+********************************************************************************
+*/
+
+#include <stdlib.h>
+
+#include "q_plsf.h"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "basic_op.h"
+
+
+/*
+********************************************************************************
+* PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+
+/*
+**************************************************************************
+*
+* Function : Q_plsf_init
+* Purpose : Allocates memory and initializes state variables
+*
+**************************************************************************
+*/
+Word16 Q_plsf_init(Q_plsfState **state)
+{
+ Q_plsfState* s;
+
+ if (state == (Q_plsfState **) NULL)
+ {
+ /* fprintf(stderr, "Q_plsf_init: invalid parameter\n"); */
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (Q_plsfState *) malloc(sizeof(Q_plsfState))) == NULL)
+ {
+ /* fprintf(stderr, "Q_plsf_init: can not malloc state structure\n"); */
+ return -1;
+ }
+
+ Q_plsf_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+/*
+**************************************************************************
+*
+* Function : Q_plsf_reset
+* Purpose : Resets state memory
+*
+**************************************************************************
+*/
+Word16 Q_plsf_reset(Q_plsfState *state)
+{
+ Word16 i;
+
+ if (state == (Q_plsfState *) NULL)
+ {
+ /* fprintf(stderr, "Q_plsf_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ for (i = 0; i < M; i++)
+ state->past_rq[i] = 0;
+
+ return 0;
+}
+
+/*
+**************************************************************************
+*
+* Function : Q_plsf_exit
+* Purpose : The memory used for state memory is freed
+*
+**************************************************************************
+*/
+void Q_plsf_exit(Q_plsfState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/q_plsf_3.cpp b/media/codecs/amrnb/common/src/q_plsf_3.cpp
new file mode 100644
index 0000000..c70847e
--- /dev/null
+++ b/media/codecs/amrnb/common/src/q_plsf_3.cpp
@@ -0,0 +1,1226 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/q_plsf_3.c
+ Funtions: Vq_subvec4
+ Test_Vq_subvec4
+ Vq_subvec3
+ Test_Vq_subvec3
+ Q_plsf_3
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Updated modules per Phase 2/3 review comments. Updated
+ Vq_subvec3 pseudo-code to reflect the new restructured code.
+
+ Description: Added setting of Overflow flag in inlined code.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h with the header file of the math functions
+ used in the file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Fixed typecasting issue with TI C compiler.
+ 2. Optimized IF stament in Vq_subvec3() function.
+ 3. Updated copyright year.
+
+ Description: Removed redundancy in the Vq_subvec4 function.
+
+ Description: Updated to accept new parameter, Flag *pOverflow.
+
+ Description: Per review comments, added pOverflow flag description
+ to the input/outputs section.
+
+ Description: Corrected missed Overflow global variables -- changed to
+ proper pOverflow.
+
+ Description: Optimized all functions to further reduce clock cycle usage.
+ Updated copyright year.
+
+ Description: Added left shift by 1 in line 1050 of Q_plsf_3().
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that perform the quantization of LSF
+ parameters with first order MA prediction and split by 3 vector
+ quantization (split-VQ).
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include <string.h>
+
+#include "q_plsf.h"
+#include "typedef.h"
+#include "lsp_lsf.h"
+#include "reorder.h"
+#include "lsfwt.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define PAST_RQ_INIT_SIZE 8
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ /* Codebooks of LSF prediction residual */
+ extern const Word16 mean_lsf_3[];
+
+ extern const Word16 pred_fac_3[];
+
+ extern const Word16 dico1_lsf_3[];
+ extern const Word16 dico2_lsf_3[];
+ extern const Word16 dico3_lsf_3[];
+
+ extern const Word16 mr515_3_lsf[];
+ extern const Word16 mr795_1_lsf[];
+
+ extern const Word16 past_rq_init[];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Vq_subvec4
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16)
+ dico = pointer to the quantization codebook (Q15) (const Word16)
+ wf1 = pointer to the first LSF weighting factor (Q13) (Word16)
+ dico_size = size of quantization codebook (Q0) (Word16)
+
+ Outputs:
+ buffer pointed to by lsf_r1 contains the selected vector
+ pOverflow -- pointer to Flag -- Flag set when overflow occurs
+
+ Returns:
+ index = quantization index (Q0) (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the quantization of a 4-dimensional subvector.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static Word16
+Vq_subvec4( // o: quantization index, Q0
+ Word16 * lsf_r1, // i: 1st LSF residual vector, Q15
+ Word16 * dico, // i: quantization codebook, Q15
+ Word16 * wf1, // i: 1st LSF weighting factors, Q13
+ Word16 dico_size) // i: size of quantization codebook, Q0
+{
+ Word16 i, index = 0;
+ Word16 *p_dico, temp;
+ Word32 dist_min, dist;
+
+ dist_min = MAX_32;
+ p_dico = dico;
+
+ for (i = 0; i < dico_size; i++)
+ {
+ temp = sub (lsf_r1[0], *p_dico++);
+ temp = mult (wf1[0], temp);
+ dist = L_mult (temp, temp);
+
+ temp = sub (lsf_r1[1], *p_dico++);
+ temp = mult (wf1[1], temp);
+ dist = L_mac (dist, temp, temp);
+
+ temp = sub (lsf_r1[2], *p_dico++);
+ temp = mult (wf1[2], temp);
+ dist = L_mac (dist, temp, temp);
+
+ temp = sub (lsf_r1[3], *p_dico++);
+ temp = mult (wf1[3], temp);
+ dist = L_mac (dist, temp, temp);
+
+
+ if (L_sub (dist, dist_min) < (Word32) 0)
+ {
+ dist_min = dist;
+ index = i;
+ }
+ }
+
+ // Reading the selected vector
+
+ p_dico = &dico[shl (index, 2)];
+ lsf_r1[0] = *p_dico++;
+ lsf_r1[1] = *p_dico++;
+ lsf_r1[2] = *p_dico++;
+ lsf_r1[3] = *p_dico;
+
+ return index;
+
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 Vq_subvec4( /* o: quantization index, Q0 */
+ Word16 * lsf_r1, /* i: 1st LSF residual vector, Q15 */
+ const Word16 * dico, /* i: quantization codebook, Q15 */
+ Word16 * wf1, /* i: 1st LSF weighting factors, Q13 */
+ Word16 dico_size, /* i: size of quantization codebook, Q0 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 temp;
+ const Word16 *p_dico;
+ Word16 index = 0;
+ Word32 dist_min;
+ Word32 dist;
+
+ Word16 lsf_r1_0;
+ Word16 lsf_r1_1;
+ Word16 lsf_r1_2;
+ Word16 lsf_r1_3;
+
+ Word16 wf1_0;
+ Word16 wf1_1;
+ Word16 wf1_2;
+ Word16 wf1_3;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ dist_min = MAX_32;
+ p_dico = dico;
+
+ lsf_r1_0 = lsf_r1[0];
+ lsf_r1_1 = lsf_r1[1];
+ lsf_r1_2 = lsf_r1[2];
+ lsf_r1_3 = lsf_r1[3];
+
+ wf1_0 = wf1[0];
+ wf1_1 = wf1[1];
+ wf1_2 = wf1[2];
+ wf1_3 = wf1[3];
+
+ for (i = 0; i < dico_size; i++)
+ {
+ temp = lsf_r1_0 - (*p_dico++);
+ temp = (Word16)((((Word32) wf1_0) * temp) >> 15);
+ dist = ((Word32) temp) * temp;
+
+ temp = lsf_r1_1 - (*p_dico++);
+ temp = (Word16)((((Word32) wf1_1) * temp) >> 15);
+ dist += ((Word32) temp) * temp;
+
+ temp = lsf_r1_2 - (*p_dico++);
+ temp = (Word16)((((Word32) wf1_2) * temp) >> 15);
+ dist += ((Word32) temp) * temp;
+
+ temp = lsf_r1_3 - (*p_dico++);
+ temp = (Word16)((((Word32) wf1_3) * temp) >> 15);
+ dist += ((Word32) temp) * temp;
+
+ if (dist < dist_min)
+ {
+ dist_min = dist;
+ index = i;
+ }
+ }
+
+ /* Reading the selected vector */
+
+ p_dico = dico + (index << 2);
+ *lsf_r1++ = *p_dico++;
+ *lsf_r1++ = *p_dico++;
+ *lsf_r1++ = *p_dico++;
+ *lsf_r1 = *p_dico;
+
+ return(index);
+
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Test_Vq_subvec4
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16)
+ dico = pointer to the quantization codebook (Q15) (const Word16)
+ wf1 = pointer to the first LSF weighting factor (Q13) (Word16)
+ dico_size = size of quantization codebook (Q0) (Word16)
+
+ Outputs:
+ buffer pointed to by lsf_r1 contains the selected vector
+ pOverflow -- pointer to Flag -- Flag set when overflow occurs
+
+ Returns:
+ index = quantization index (Q0) (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calls the static function Vq_subvec4. It is used for testing
+ purposes only
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+ CALL Vq_subvec4(lsf_r1 = lsf_r1
+ dico = dico
+ wf1 = wf1
+ dico_size = dico_size)
+ MODIFYING(nothing)
+ RETURNING(index = tst_index4)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Test_Vq_subvec4(
+ Word16 * lsf_r1,
+ const Word16 * dico,
+ Word16 * wf1,
+ Word16 dico_size,
+ Flag *pOverflow)
+{
+ Word16 tst_index4 = 0;
+
+ /*------------------------------------------------------------------------
+ CALL Vq_subvec4(lsf_r1 = lsf_r1
+ dico = dico
+ wf1 = wf1
+ dico_size = dico_size)
+ MODIFYING(nothing)
+ RETURNING(index = index)
+ ------------------------------------------------------------------------*/
+ tst_index4 =
+ Vq_subvec4(
+ lsf_r1,
+ dico,
+ wf1,
+ dico_size,
+ pOverflow);
+
+ return(tst_index4);
+
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Vq_subvec3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16)
+ dico = pointer to the quantization codebook (Q15) (const Word16)
+ wf1 = pointer to the first LSF weighting factor (Q13) (Word16)
+ dico_size = size of quantization codebook (Q0) (Word16)
+ use_half = flag to indicate use of every second entry in the
+ codebook (Flag)
+
+ Outputs:
+ buffer pointed to by lsf_r1 contains the selected vector
+ pOverflow -- pointer to Flag -- Flag set when overflow occurs
+
+ Returns:
+ index = quantization index (Q0) (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the quantization of a 3 dimensional subvector.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static Word16
+Vq_subvec3( // o: quantization index, Q0
+ Word16 * lsf_r1, // i: 1st LSF residual vector, Q15
+ Word16 * dico, // i: quantization codebook, Q15
+ Word16 * wf1, // i: 1st LSF weighting factors, Q13
+ Word16 dico_size, // i: size of quantization codebook, Q0
+ Flag use_half) // i: use every second entry in codebook
+{
+ Word16 i, index = 0;
+ Word16 *p_dico, temp;
+ Word32 dist_min, dist;
+
+ dist_min = MAX_32;
+ p_dico = dico;
+
+ if (use_half == 0) {
+ for (i = 0; i < dico_size; i++)
+ {
+ temp = sub(lsf_r1[0], *p_dico++);
+ temp = mult(wf1[0], temp);
+ dist = L_mult(temp, temp);
+
+ temp = sub(lsf_r1[1], *p_dico++);
+ temp = mult(wf1[1], temp);
+ dist = L_mac(dist, temp, temp);
+
+ temp = sub(lsf_r1[2], *p_dico++);
+ temp = mult(wf1[2], temp);
+ dist = L_mac(dist, temp, temp);
+
+ if (L_sub(dist, dist_min) < (Word32) 0) {
+ dist_min = dist;
+ index = i;
+ }
+ }
+ p_dico = &dico[add(index, add(index, index))];
+ }
+ else
+ {
+ for (i = 0; i < dico_size; i++)
+ {
+ temp = sub(lsf_r1[0], *p_dico++);
+ temp = mult(wf1[0], temp);
+ dist = L_mult(temp, temp);
+
+ temp = sub(lsf_r1[1], *p_dico++);
+ temp = mult(wf1[1], temp);
+ dist = L_mac(dist, temp, temp);
+
+ temp = sub(lsf_r1[2], *p_dico++);
+ temp = mult(wf1[2], temp);
+ dist = L_mac(dist, temp, temp);
+
+ if (L_sub(dist, dist_min) < (Word32) 0)
+ {
+ dist_min = dist;
+ index = i;
+ }
+ p_dico = p_dico + 3; add(0,0);
+ }
+ p_dico = &dico[shl(add(index, add(index, index)),1)];
+ }
+
+
+ // Reading the selected vector
+ lsf_r1[0] = *p_dico++;
+ lsf_r1[1] = *p_dico++;
+ lsf_r1[2] = *p_dico++;
+
+ return index;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 Vq_subvec3( /* o: quantization index, Q0 */
+ Word16 * lsf_r1, /* i: 1st LSF residual vector, Q15 */
+ const Word16 * dico, /* i: quantization codebook, Q15 */
+ Word16 * wf1, /* i: 1st LSF weighting factors, Q13 */
+ Word16 dico_size, /* i: size of quantization codebook, Q0 */
+ Flag use_half, /* i: use every second entry in codebook */
+ Flag *pOverflow) /* o : Flag set when overflow occurs */
+{
+ Word16 i;
+ Word16 temp;
+
+ const Word16 *p_dico;
+
+ Word16 p_dico_index = 0;
+ Word16 index = 0;
+
+ Word32 dist_min;
+ Word32 dist;
+
+ Word16 lsf_r1_0;
+ Word16 lsf_r1_1;
+ Word16 lsf_r1_2;
+
+ Word16 wf1_0;
+ Word16 wf1_1;
+ Word16 wf1_2;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ dist_min = MAX_32;
+ p_dico = dico;
+
+ lsf_r1_0 = lsf_r1[0];
+ lsf_r1_1 = lsf_r1[1];
+ lsf_r1_2 = lsf_r1[2];
+
+ wf1_0 = wf1[0];
+ wf1_1 = wf1[1];
+ wf1_2 = wf1[2];
+
+ if (use_half != 0)
+ {
+ p_dico_index = 3;
+ }
+
+ for (i = 0; i < dico_size; i++)
+ {
+ temp = lsf_r1_0 - (*p_dico++);
+ temp = (Word16)((((Word32) wf1_0) * temp) >> 15);
+ dist = ((Word32) temp) * temp;
+
+ temp = lsf_r1_1 - (*p_dico++);
+ temp = (Word16)((((Word32) wf1_1) * temp) >> 15);
+ dist += ((Word32) temp) * temp;
+
+ temp = lsf_r1_2 - (*p_dico++);
+ temp = (Word16)((((Word32) wf1_2) * temp) >> 15);
+ dist += ((Word32) temp) * temp;
+
+ if (dist < dist_min)
+ {
+ dist_min = dist;
+ index = i;
+ }
+
+ p_dico = p_dico + p_dico_index;
+ }
+
+ p_dico = dico + (3 * index);
+
+ if (use_half != 0)
+ {
+ p_dico += (3 * index);
+ }
+
+ /* Reading the selected vector */
+ *lsf_r1++ = *p_dico++;
+ *lsf_r1++ = *p_dico++;
+ *lsf_r1 = *p_dico;
+
+ return(index);
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Test_Vq_subvec3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16)
+ dico = pointer to the quantization codebook (Q15) (const Word16)
+ wf1 = pointer to the first LSF weighting factor (Q13) (Word16)
+ dico_size = size of quantization codebook (Q0) (Word16)
+ use_half = flag to indicate use of every second entry in the
+ codebook (Flag)
+
+ Outputs:
+ buffer pointed to by lsf_r1 contains the selected vector
+ pOverflow -- pointer to Flag -- Flag set when overflow occurs
+
+ Returns:
+ index = quantization index (Q0) (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calls the static function Vq_subvec3. It is used for testing
+ purposes only
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ CALL Vq_subvec3(lsf_r1 = lsf_r1
+ dico = dico
+ wf1 = wf1
+ dico_size = dico_size
+ use_half = use_half)
+ MODIFYING(nothing)
+ RETURNING(index = tst_index3)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Test_Vq_subvec3(
+ Word16 * lsf_r1,
+ const Word16 * dico,
+ Word16 * wf1,
+ Word16 dico_size,
+ Flag use_half,
+ Flag *pOverflow)
+{
+ Word16 tst_index3 = 0;
+
+ /*------------------------------------------------------------------------
+ CALL Vq_subvec3(lsf_r1 = lsf_r1
+ dico = dico
+ wf1 = wf1
+ dico_size = dico_size
+ use_half = use_half)
+ MODIFYING(nothing)
+ RETURNING(index = index)
+ ------------------------------------------------------------------------*/
+ tst_index3 =
+ Vq_subvec3(
+ lsf_r1,
+ dico,
+ wf1,
+ dico_size,
+ use_half,
+ pOverflow);
+
+ return(tst_index3);
+
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Q_plsf_3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structures of type Q_plsfState (Q_plsfState)
+ mode = coder mode (enum)
+ lsp1 = pointer to the first LSP vector (Word16)
+ lsp1_q = pointer to the quantized first LSP vector (Word16)
+ indice = pointer to the quantization indices of 3 vectors (Word16)
+ pred_init_i = pointer to the index of the initial value for
+ MA prediction in DTX mode (Word16)
+
+ Outputs:
+ lsp1_q points to a vector containing the new quantized LSPs
+ indice points to the new quantization indices of 3 vectors
+ pred_init_i points to the new initial index for MA prediction
+ in DTX mode
+ past_rq field of structure pointed to by st contains the current
+ quantized LSF parameters
+ pOverflow -- pointer to Flag -- Flag set when overflow occurs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ pred_fac = table containing prediction factors (const Word16)
+ dico1_lsf = quantization table for split_MQ of 2 sets of LSFs
+ in a 20 ms frame (const Word16)
+ dico2_lsf = quantization table for split_MQ of 2 sets of LSFs
+ in a 20 ms frame (const Word16)
+ dico3_lsf = quantization table for split_MQ of 2 sets of LSFs
+ in a 20 ms frame (const Word16)
+ mr515_3_lsf = third codebook for MR475 and MR515 modes (const Word16)
+ mr795_1_lsf = first codebook for MR795 mode (const Word16)
+ mean_lsf = table of mean LSFs (const Word16)
+ past_rq_init = initalization table for MA predictor in DTX mode
+ (const Word16)
+
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs quantization of LSF parameters with 1st order MA
+ prediction and split by 3 vector quantization (split-VQ)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Q_plsf_3(
+ Q_plsfState *st, // i/o: state struct
+ enum Mode mode, // i : coder mode
+ Word16 *lsp1, // i : 1st LSP vector Q15
+ Word16 *lsp1_q, // o : quantized 1st LSP vector Q15
+ Word16 *indice, // o : quantization indices of 3 vectors Q0
+ Word16 *pred_init_i // o : init index for MA prediction in DTX mode
+)
+{
+ Word16 i, j;
+ Word16 lsf1[M], wf1[M], lsf_p[M], lsf_r1[M];
+ Word16 lsf1_q[M];
+
+ Word32 L_pred_init_err;
+ Word32 L_min_pred_init_err;
+ Word16 temp_r1[M];
+ Word16 temp_p[M];
+
+ // convert LSFs to normalize frequency domain 0..16384
+
+ Lsp_lsf(lsp1, lsf1, M);
+
+ // compute LSF weighting factors (Q13)
+
+ Lsf_wt(lsf1, wf1);
+
+ // Compute predicted LSF and prediction error
+ if (test(), sub(mode, MRDTX) != 0)
+ {
+ for (i = 0; i < M; i++)
+ {
+ lsf_p[i] = add(mean_lsf[i],
+ mult(st->past_rq[i],
+ pred_fac[i]));
+ lsf_r1[i] = sub(lsf1[i], lsf_p[i]);
+ }
+ }
+ else
+ {
+ // DTX mode, search the init vector that yields
+ // lowest prediction resuidual energy
+ *pred_init_i = 0;
+ L_min_pred_init_err = 0x7fffffff; // 2^31 - 1
+ for (j = 0; j < PAST_RQ_INIT_SIZE; j++)
+ {
+ L_pred_init_err = 0;
+ for (i = 0; i < M; i++)
+ {
+ temp_p[i] = add(mean_lsf[i], past_rq_init[j*M+i]);
+ temp_r1[i] = sub(lsf1[i],temp_p[i]);
+ L_pred_init_err = L_mac(L_pred_init_err, temp_r1[i], temp_r1[i]);
+ } // next i
+
+
+ if (L_sub(L_pred_init_err, L_min_pred_init_err) < (Word32) 0)
+ {
+ L_min_pred_init_err = L_pred_init_err;
+ Copy(temp_r1, lsf_r1, M);
+ Copy(temp_p, lsf_p, M);
+ // Set zerom
+ Copy(&past_rq_init[j*M], st->past_rq, M);
+ *pred_init_i = j;
+ } // endif
+ } // next j
+ } // endif MRDTX
+
+ //---- Split-VQ of prediction error ----
+ if (sub (mode, MR475) == 0 || sub (mode, MR515) == 0)
+ { // MR475, MR515
+
+
+ indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0);
+
+ indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE/2, 1);
+
+ indice[2] = Vq_subvec4(&lsf_r1[6], mr515_3_lsf, &wf1[6], MR515_3_SIZE);
+
+ }
+ else if (sub (mode, MR795) == 0)
+ { // MR795
+
+
+ indice[0] = Vq_subvec3(&lsf_r1[0], mr795_1_lsf, &wf1[0], MR795_1_SIZE, 0);
+
+ indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0);
+
+ indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE);
+
+ }
+ else
+ { // MR59, MR67, MR74, MR102 , MRDTX
+
+
+ indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0);
+
+ indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0);
+
+ indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE);
+
+ }
+
+
+ // Compute quantized LSFs and update the past quantized residual
+
+ for (i = 0; i < M; i++)
+ {
+ lsf1_q[i] = add(lsf_r1[i], lsf_p[i]);
+ st->past_rq[i] = lsf_r1[i];
+ }
+
+ // verification that LSFs has mimimum distance of LSF_GAP Hz
+
+ Reorder_lsf(lsf1_q, LSF_GAP, M);
+
+ // convert LSFs to the cosine domain
+
+ Lsf_lsp(lsf1_q, lsp1_q, M);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Q_plsf_3(
+ Q_plsfState *st, /* i/o: state struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 *lsp1, /* i : 1st LSP vector Q15 */
+ Word16 *lsp1_q, /* o : quantized 1st LSP vector Q15 */
+ Word16 *indice, /* o : quantization indices of 3 vectors Q0 */
+ Word16 *pred_init_i,/* o : init index for MA prediction in DTX mode */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i, j;
+ Word16 lsf1[M];
+ Word16 wf1[M];
+ Word16 lsf_p[M];
+ Word16 lsf_r1[M];
+ Word16 lsf1_q[M];
+
+ Word32 L_pred_init_err;
+ Word32 L_min_pred_init_err;
+ Word32 L_temp;
+ Word16 temp_r1[M];
+ Word16 temp_p[M];
+ Word16 temp;
+
+ /* convert LSFs to normalize frequency domain 0..16384 */
+
+ Lsp_lsf(
+ lsp1,
+ lsf1,
+ M,
+ pOverflow);
+
+ /* compute LSF weighting factors (Q13) */
+
+ Lsf_wt(
+ lsf1,
+ wf1,
+ pOverflow);
+
+ /* Compute predicted LSF and prediction error */
+ if (mode != MRDTX)
+ {
+ for (i = 0; i < M; i++)
+ {
+ temp = (Word16)((((Word32) st->past_rq[i]) *
+ (*(pred_fac_3 + i))) >> 15);
+
+ *(lsf_p + i) = *(mean_lsf_3 + i) + temp;
+
+ *(lsf_r1 + i) = *(lsf1 + i) - *(lsf_p + i);
+ }
+ }
+ else
+ {
+ /* DTX mode, search the init vector that yields */
+ /* lowest prediction resuidual energy */
+ *pred_init_i = 0;
+ L_min_pred_init_err = 0x7fffffff; /* 2^31 - 1 */
+
+ for (j = 0; j < PAST_RQ_INIT_SIZE; j++)
+ {
+ L_pred_init_err = 0;
+ for (i = 0; i < M; i++)
+ {
+ *(temp_p + i) = *(mean_lsf_3 + i) + *(past_rq_init + j * M + i);
+
+ *(temp_r1 + i) = *(lsf1 + i) - *(temp_p + i);
+
+ L_temp = ((Word32) * (temp_r1 + i)) * *(temp_r1 + i);
+
+ L_pred_init_err = L_pred_init_err + (L_temp << 1);
+
+ } /* next i */
+
+
+ if (L_pred_init_err < L_min_pred_init_err)
+ {
+ L_min_pred_init_err = L_pred_init_err;
+
+ memcpy(
+ lsf_r1,
+ temp_r1,
+ M*sizeof(Word16));
+
+ memcpy(
+ lsf_p,
+ temp_p,
+ M*sizeof(Word16));
+
+ /* Set zerom */
+ memcpy(
+ st->past_rq,
+ &past_rq_init[j*M],
+ M*sizeof(Word16));
+
+ *pred_init_i = j;
+
+ } /* endif */
+ } /* next j */
+ } /* endif MRDTX */
+
+ /*---- Split-VQ of prediction error ----*/
+ if ((mode == MR475) || (mode == MR515))
+ { /* MR475, MR515 */
+
+ *indice =
+ Vq_subvec3(
+ lsf_r1,
+ dico1_lsf_3,
+ wf1,
+ DICO1_SIZE,
+ 0,
+ pOverflow);
+
+ *(indice + 1) =
+ Vq_subvec3(
+ lsf_r1 + 3,
+ dico2_lsf_3,
+ wf1 + 3,
+ DICO2_SIZE / 2,
+ 1,
+ pOverflow);
+
+ *(indice + 2) =
+ Vq_subvec4(
+ lsf_r1 + 6,
+ mr515_3_lsf,
+ wf1 + 6,
+ MR515_3_SIZE,
+ pOverflow);
+
+ }
+ else if (mode == MR795)
+ { /* MR795 */
+
+ *indice =
+ Vq_subvec3(
+ lsf_r1,
+ mr795_1_lsf,
+ wf1,
+ MR795_1_SIZE,
+ 0,
+ pOverflow);
+
+ *(indice + 1) =
+ Vq_subvec3(
+ lsf_r1 + 3,
+ dico2_lsf_3,
+ wf1 + 3,
+ DICO2_SIZE,
+ 0,
+ pOverflow);
+
+ *(indice + 2) =
+ Vq_subvec4(
+ lsf_r1 + 6,
+ dico3_lsf_3,
+ wf1 + 6,
+ DICO3_SIZE,
+ pOverflow);
+
+ }
+ else
+ { /* MR59, MR67, MR74, MR102 , MRDTX */
+
+ *indice =
+ Vq_subvec3(
+ lsf_r1,
+ dico1_lsf_3,
+ wf1,
+ DICO1_SIZE,
+ 0,
+ pOverflow);
+
+ *(indice + 1) =
+ Vq_subvec3(
+ lsf_r1 + 3,
+ dico2_lsf_3,
+ wf1 + 3,
+ DICO2_SIZE,
+ 0,
+ pOverflow);
+
+ *(indice + 2) =
+ Vq_subvec4(
+ lsf_r1 + 6,
+ dico3_lsf_3,
+ wf1 + 6,
+ DICO3_SIZE,
+ pOverflow);
+
+ }
+
+
+ /* Compute quantized LSFs and update the past quantized residual */
+
+ for (i = 0; i < M; i++)
+ {
+ *(lsf1_q + i) = *(lsf_r1 + i) + *(lsf_p + i);
+ st->past_rq[i] = *(lsf_r1 + i);
+ }
+
+ /* verification that LSFs has mimimum distance of LSF_GAP Hz */
+
+ Reorder_lsf(
+ lsf1_q,
+ LSF_GAP,
+ M,
+ pOverflow);
+
+ /* convert LSFs to the cosine domain */
+
+ Lsf_lsp(
+ lsf1_q,
+ lsp1_q,
+ M,
+ pOverflow);
+
+ return;
+
+}
diff --git a/media/codecs/amrnb/common/src/q_plsf_3_tbl.cpp b/media/codecs/amrnb/common/src/q_plsf_3_tbl.cpp
new file mode 100644
index 0000000..56c13e7
--- /dev/null
+++ b/media/codecs/amrnb/common/src/q_plsf_3_tbl.cpp
@@ -0,0 +1,2096 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/q_plsf_3_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created this file from the reference, q_plsf_3_tbl.tab
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "q_plsf_3_tbl.h"
+
+/*--------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : q_plsf_3.tab
+* Purpose : Table for routine LSF VQ.
+* $Id $
+*
+********************************************************************************
+*/
+
+
+/* initalization table for MA predictor in dtx mode */
+const Word16 past_rq_init[80] =
+{
+ -258, -318, -439, -634, -656, -773, -711, -502, -268, -193,
+ -2, 125, 122, -39, -9, 105, 129, 283, 372, 575,
+ -277, -324, -197, -487, -445, -362, -292, -27, 177, 543,
+ 342, 517, 516, 130, 27, -104, -120, -140, -74, -56,
+ -564, -943, -1520, -965, -814, -526, -322, -2, 159, 657,
+ -312, -284, -386, -597, -493, -526, -418, -229, 105, 449,
+ -557, -870, -1075, -919, -950, -752, -709, -316, 62, 486,
+ -314, -191, -203, -330, -160, -103, -51, 131, 338, 515
+};
+
+
+const Word16 mean_lsf_3[10] =
+{
+ 1546,
+ 2272,
+ 3778,
+ 5488,
+ 6972,
+ 8382,
+ 10047,
+ 11229,
+ 12766,
+ 13714
+};
+
+
+const Word16 pred_fac_3[10] =
+{
+ 9556,
+ 10769,
+ 12571,
+ 13292,
+ 14381,
+ 11651,
+ 10588,
+ 9767,
+ 8593,
+ 6484
+};
+
+
+
+/* first codebook from IS641 */
+
+const Word16 dico1_lsf_3[DICO1_SIZE*3] =
+{
+ 6, 82, -131,
+ 154, -56, -735,
+ 183, -65, -265,
+ 9, -210, -361,
+ 113, 718, 1817,
+ 1010, 1214, 1573,
+ 857, 1333, 2276,
+ 827, 1568, 1933,
+ 717, 1989, 2206,
+ 838, 1172, 1823,
+ 721, 1000, 2154,
+ 286, 476, 1509,
+ -247, -531, 230,
+ 147, -82, 569,
+ 26, -177, -944,
+ -27, -273, 692,
+ -164, -264, -183,
+ 224, 790, 1039,
+ 899, 946, 601,
+ 485, 771, 1150,
+ 524, 677, 903,
+ -140, 375, 778,
+ 410, 676, 429,
+ 301, 530, 1009,
+ 719, 646, 38,
+ 226, 367, 40,
+ 145, -45, -505,
+ 290, 121, -121,
+ 302, 127, 166,
+ -124, -383, -956,
+ -358, -455, -977,
+ 715, 878, 894,
+ 978, 923, 211,
+ 477, 272, 64,
+ 188, -78, 17,
+ -143, -65, 38,
+ 643, 586, 621,
+ -134, -426, -651,
+ 347, 545, 2820,
+ 1188, 2726, 2442,
+ 142, -80, 1735,
+ 283, 130, 461,
+ -262, -399, -1145,
+ -411, 155, 430,
+ 329, 375, 779,
+ 53, -226, -139,
+ -129, -236, 1682,
+ 285, 744, 1327,
+ 738, 697, 1664,
+ 312, 409, 266,
+ 325, 720, 135,
+ 1, 221, 453,
+ 8, 203, 145,
+ 299, 640, 760,
+ 29, 468, 638,
+ 103, 429, 379,
+ 420, 954, 932,
+ 1326, 1210, 1258,
+ 704, 1012, 1152,
+ -166, -444, -266,
+ -316, -130, -376,
+ 191, 1151, 1904,
+ -240, -543, -1260,
+ -112, 268, 1207,
+ 70, 1062, 1583,
+ 278, 1360, 1574,
+ -258, -272, -768,
+ 19, 563, 2240,
+ -3, -265, 135,
+ -295, -591, -388,
+ 140, 354, -206,
+ -260, -504, -795,
+ -433, -718, -1319,
+ 109, 331, 962,
+ -429, -87, 652,
+ -296, 426, 1019,
+ -239, 775, 851,
+ 489, 1334, 1073,
+ -334, -332, 25,
+ 543, 1206, 1807,
+ 326, 61, 727,
+ 578, 849, 1405,
+ -208, -277, 329,
+ -152, 64, 669,
+ -434, -678, -727,
+ -454, -71, 251,
+ 605, 480, 254,
+ -482, 11, 996,
+ -289, 395, 486,
+ 722, 1049, 1440,
+ -30, -316, -786,
+ -106, -115, -619,
+ 861, 1474, 1412,
+ 1055, 1366, 1184,
+ 812, 1237, 925,
+ 42, -251, -576,
+ 342, 141, -454,
+ -168, -80, 1359,
+ -342, -656, -1763,
+ 100, 821, 725,
+ 990, 747, 800,
+ 332, 440, 568,
+ 663, 379, 852,
+ 112, 165, -369,
+ 597, 910, 282,
+ -8, 834, 1281,
+ -352, 572, 695,
+ 462, 2246, 1806,
+ 345, 190, 1374,
+ 416, 915, 2166,
+ 168, -82, 280,
+ -516, -446, 840,
+ 47, 533, 44,
+ -362, -711, -1143,
+ 22, 193, 1472,
+ -85, 233, 1813,
+ -62, 579, 1504,
+ 550, 944, 1749,
+ 723, 650, 1148,
+ 972, 884, 1395,
+ -425, 643, 0,
+ 1000, 952, 1098,
+ 249, 1446, 672,
+ -334, -87, 2172,
+ -554, 1882, 2672,
+ 140, 1826, 1853,
+ 920, 1749, 2590,
+ 1076, 1933, 2038,
+ -137, -443, -1555,
+ 1269, 1174, 468,
+ -493, -122, 1521,
+ -451, 1033, 1214,
+ 482, 1695, 1118,
+ 815, 649, 384,
+ -446, -692, 107,
+ -319, -605, -118,
+ -207, -505, 525,
+ -468, -12, 2736,
+ 75, 1934, 1305,
+ 880, 2358, 2267,
+ 1285, 1575, 2004,
+ -48, -304, -1186,
+ -435, -461, -251,
+ -366, -404, -547,
+ -289, -605, -597,
+ -538, -810, -165,
+ -120, 3, 356,
+ 639, 1241, 1502,
+ 96, 177, 750,
+ -435, -585, -1174,
+ -356, 109, -79,
+ -485, 288, 2005,
+ 9, 1116, 731,
+ 880, 2134, 946,
+ -265, 1585, 1065,
+ 1157, 1210, 843,
+ -498, -668, 431,
+ 374, 321, -229,
+ 1440, 2101, 1381,
+ 449, 461, 1155,
+ -105, 39, -384,
+ -263, 367, 182,
+ -371, -660, 773,
+ -188, 1151, 971,
+ 1333, 1632, 1435,
+ 774, 1267, 1221,
+ -482, -832, -1489,
+ -237, -210, 860,
+ 890, 1615, 1064,
+ 472, 1062, 1192,
+ 185, 1077, 989,
+ -568, -992, -1704,
+ -449, -902, -2043,
+ -142, -377, -458,
+ -210, -554, -1029,
+ -11, 1133, 2265,
+ -329, -675, -893,
+ -250, 657, 1187,
+ 519, 1510, 1779,
+ 520, 539, 1403,
+ 527, 1421, 1302,
+ -563, -871, -1248,
+ -147, -463, 879,
+ -76, 2334, 2840,
+ 563, 2573, 2385,
+ 632, 1926, 2920,
+ 719, 2023, 1840,
+ -545, -723, 1108,
+ 129, -125, 884,
+ 1417, 1632, 925,
+ -94, 1566, 1751,
+ -341, 1533, 1551,
+ 591, 395, -274,
+ -76, 981, 2831,
+ 153, 2985, 1844,
+ 1032, 2565, 2749,
+ 1508, 2832, 1879,
+ 791, 1199, 538,
+ -190, -453, 1489,
+ -278, -548, 1158,
+ -245, 1941, 2044,
+ 1024, 1560, 1650,
+ 512, 253, 466,
+ -62, -323, 1151,
+ -473, -376, 507,
+ -433, 1380, 2162,
+ 899, 1943, 1445,
+ 134, 704, 440,
+ 460, 525, -28,
+ -450, 279, 1338,
+ 0, 971, 252,
+ -445, -627, -991,
+ -348, -602, -1424,
+ 398, 712, 1656,
+ -107, 314, -178,
+ 93, 2226, 2238,
+ 518, 849, 656,
+ -462, -711, -447,
+ 174, -34, 1191,
+ -119, 42, 1005,
+ -372, 274, 758,
+ 1036, 2352, 1838,
+ 675, 1724, 1498,
+ 430, 1286, 2133,
+ -129, -439, 0,
+ -373, 800, 2144,
+ 6, 1587, 2478,
+ 478, 596, 2128,
+ -428, -736, 1505,
+ 385, 178, 980,
+ 139, 449, 1225,
+ -526, -842, -982,
+ 145, 1554, 1242,
+ 623, 1448, 656,
+ 349, 1016, 1482,
+ 31, -280, 415,
+ -316, 724, 1641,
+ 360, 1058, 556,
+ -436, -358, 1201,
+ -355, 1123, 1939,
+ 401, 1584, 2248,
+ -527, -1012, 355,
+ 233, 238, 2233,
+ -550, -897, -639,
+ -365, -501, 1957,
+ 389, 1860, 1621,
+ 162, 1132, 1264,
+ -237, 1174, 1390,
+ -640, -411, 116,
+ -228, 1694, 2298,
+ 1639, 2186, 2267,
+ 562, 1273, 2658,
+ 323, 338, 1774,
+ 578, 1107, 852,
+ 22, 594, 934,
+ -143, 718, 446
+};
+
+
+/* second codebook from IS641 */
+
+const Word16 dico2_lsf_3[DICO2_SIZE*3] =
+{
+ 50, 71, -9,
+ -338, -698, -1407,
+ 102, -138, -820,
+ -310, -469, -1147,
+ 414, 67, -267,
+ 1060, 814, 1441,
+ 1548, 1360, 1272,
+ 1754, 1895, 1661,
+ 2019, 2133, 1820,
+ 1808, 2318, 1845,
+ 644, -93, 454,
+ 858, 329, -136,
+ 489, -258, -128,
+ -198, -745, -41,
+ -52, -265, -985,
+ 346, 137, 479,
+ -1741, -748, -684,
+ -1163, -1725, -367,
+ -895, -1145, -784,
+ -488, -946, -968,
+ -85, -390, -725,
+ 215, -340, -171,
+ 1020, 916, 1969,
+ 564, 179, 746,
+ 662, 977, 1734,
+ 887, 622, 914,
+ 939, 856, 1165,
+ 309, 688, 803,
+ 917, 161, 570,
+ 118, -20, -283,
+ -816, -42, 204,
+ -1228, -325, -462,
+ -963, -202, -143,
+ -988, -484, -361,
+ -702, -978, -477,
+ -302, -790, -1188,
+ -100, -786, -1088,
+ -1054, -947, -1684,
+ -202, -843, -782,
+ -1039, -1378, -901,
+ -624, -110, -85,
+ 356, 213, -10,
+ -493, 364, 774,
+ 425, 822, 479,
+ -83, 557, 520,
+ -992, -1560, -572,
+ -603, -741, -26,
+ -502, -638, -903,
+ 209, 306, 147,
+ -316, -593, -596,
+ -85, -211, -225,
+ -918, -529, 117,
+ 233, -439, -738,
+ 1101, 751, 633,
+ 1457, 1716, 1511,
+ 1765, 1457, 910,
+ 1122, 1156, 849,
+ 1354, 868, 470,
+ -871, -1150, -1796,
+ -871, -861, -992,
+ -118, 155, 212,
+ -1051, -849, -606,
+ -1117, -1849, -2750,
+ -1019, -1427, -1869,
+ 370, -184, -414,
+ 959, 493, 104,
+ 958, 1039, 543,
+ 154, 653, 201,
+ 1249, 507, 150,
+ 663, 503, 230,
+ 623, 777, 675,
+ 659, 88, -110,
+ 843, 244, 224,
+ 382, 541, 302,
+ 724, 433, 666,
+ 1166, 734, 341,
+ -138, 20, -397,
+ -1183, -424, -46,
+ -321, -352, -124,
+ 1333, 1021, 1080,
+ 262, 366, 723,
+ 922, 283, -551,
+ 31, -636, -611,
+ -689, -697, -415,
+ -952, -779, -201,
+ -1329, -598, -359,
+ -953, -1285, 166,
+ 493, 305, 221,
+ 846, 703, 610,
+ 840, 936, 774,
+ -723, -1324, -1261,
+ -357, -1025, -1388,
+ -1096, -1376, -365,
+ -1416, -1881, -608,
+ -1798, -1727, -674,
+ -545, -1173, -703,
+ 678, 786, 148,
+ -123, 696, 1288,
+ 644, 350, -10,
+ 414, 614, 15,
+ 137, 344, -211,
+ -814, -1512, -819,
+ -391, -930, -588,
+ 47, -591, -898,
+ -909, -1097, -163,
+ -1272, -1167, -157,
+ -1464, -1525, -389,
+ -1274, -1188, -624,
+ 671, 213, 454,
+ 124, -274, -525,
+ -729, -496, -152,
+ -1344, 122, 135,
+ -2905, -589, -394,
+ -1728, 441, -50,
+ 1476, 904, 787,
+ 316, 236, -440,
+ -347, 217, 413,
+ -911, -917, 121,
+ -455, -932, 202,
+ -92, -465, -375,
+ 488, 390, 474,
+ 876, 729, 316,
+ -1815, -1312, -669,
+ 87, 962, 432,
+ 563, -249, -1058,
+ 250, 285, 1105,
+ 1141, 427, 696,
+ -1038, -1664, -1582,
+ -948, 346, 160,
+ -309, -272, -858,
+ 670, 624, 1250,
+ -944, -408, -666,
+ -606, -320, -384,
+ -492, 230, 65,
+ 334, -50, -16,
+ -16, -690, -1397,
+ 1791, 1716, 1399,
+ 2478, 2063, 1404,
+ 1245, 1471, 1426,
+ -382, -1037, -2,
+ 173, -398, 1145,
+ 1491, 2024, 1801,
+ 772, 1274, 1506,
+ 1429, 1735, 2001,
+ 1079, 1218, 1273,
+ -1154, -1851, -1329,
+ -808, -1133, -1096,
+ -451, -1033, -1722,
+ 65, 578, -84,
+ -1476, -2434, -1778,
+ -765, -1366, -494,
+ -218, -594, -931,
+ 337, -236, 562,
+ 2357, 2662, 1938,
+ 1489, 1276, 874,
+ 189, 358, 374,
+ -1519, -2281, -2346,
+ -967, -1271, -2095,
+ -628, -1188, -1542,
+ 1661, 1043, 546,
+ 565, 1061, 732,
+ -64, -836, -434,
+ -436, -96, 203,
+ 1078, 1216, 1636,
+ 907, 1534, 986,
+ 326, 965, 845,
+ 142, -84, 197,
+ 470, 2379, 1570,
+ 1133, 470, 1214,
+ 395, 1376, 1200,
+ 1125, 1042, 348,
+ -543, -1234, -376,
+ -215, -181, 481,
+ -1947, -1621, -210,
+ -750, -1185, 390,
+ 29, -399, 27,
+ 820, 1236, 755,
+ 695, 979, 409,
+ -174, 1197, 1035,
+ 912, 1356, 1846,
+ -992, -1437, 484,
+ -1485, -1700, 208,
+ -412, 1204, 1432,
+ -271, 896, 1144,
+ -416, 1777, 1434,
+ -1696, -2644, -204,
+ -1789, -1551, 1033,
+ -1656, -1559, 1303,
+ -1253, -1589, 1081,
+ -669, -1095, -66,
+ -682, 320, -345,
+ 659, 305, 1069,
+ -1292, -804, -19,
+ -1635, -1291, 29,
+ -1683, -497, 71,
+ -287, -7, -100,
+ -494, -962, -237,
+ 852, 1881, 1740,
+ -1217, -1387, 227,
+ -660, 302, 373,
+ 96, 1087, 1257,
+ -1074, -1669, 160,
+ 485, 2076, 1798,
+ -934, -220, 552,
+ -596, -612, 237,
+ 336, 1720, 879,
+ 643, 629, 434,
+ 1267, 522, 1633,
+ 15, 244, -441,
+ 1475, 717, 184,
+ 1819, 1590, 1709,
+ 988, 261, 937,
+ 2093, 2345, 1520,
+ 2139, 1858, 1606,
+ -577, -579, -1203,
+ -956, 135, -488,
+ -464, 51, -338,
+ -629, -348, -723,
+ 1146, 2073, 1442,
+ 2192, 1466, 911,
+ -1444, -1572, -2278,
+ 1400, 710, 1297,
+ 1335, 633, 928,
+ 1434, 2194, 2594,
+ 2422, 2204, 1881,
+ 982, 2242, 1854,
+ 380, 792, 1145,
+ -63, -539, 414,
+ -252, -964, -314,
+ -1261, -683, -780,
+ -831, -526, -1005,
+ -1666, -1135, -424,
+ -1611, -452, -299,
+ 1268, 1048, 642,
+ 1147, 853, 856,
+ -675, -336, 139,
+ 2268, 1343, 1418,
+ 29, 768, 797,
+ -1224, 423, 564,
+ -1318, -1082, 245,
+ -1302, -812, 573,
+ -1298, -1617, 646,
+ -968, 834, 723,
+ 993, 1652, 2027,
+ -191, -817, 432,
+ 662, 60, 198,
+ 626, 997, 1330,
+ 1648, 1963, 1289,
+ -1597, -93, -45,
+ -1088, 37, -84,
+ 1653, 2607, 2337,
+ 1065, 2040, 2377,
+ 1139, 2326, 2118,
+ 859, 357, 1510,
+ 664, 1227, 1099,
+ 479, 1360, 912,
+ 1897, 1754, 2019,
+ 1168, 1909, 1784,
+ 399, 34, 256,
+ -593, -304, -1053,
+ 547, 1694, 1407,
+ 647, -99, -341,
+ 1492, 1647, 1190,
+ 38, -644, -212,
+ 395, 846, 222,
+ -704, -765, -716,
+ -724, -1964, -2804,
+ -150, 291, -82,
+ 1233, 1459, 1007,
+ -140, -155, 153,
+ 439, 297, 1568,
+ -1529, -410, -636,
+ 1536, 455, -237,
+ -1328, -139, -260,
+ 531, 554, 868,
+ 269, 1264, 606,
+ -233, 883, 463,
+ 742, 600, -120,
+ -73, 421, 212,
+ -439, -58, 804,
+ -1286, -1241, 728,
+ 294, -490, 50,
+ -591, -905, -1254,
+ 42, -687, 147,
+ -25, 273, 596,
+ -311, 1213, 601,
+ -754, 849, 584,
+ 429, 607, 587,
+ -602, -166, 461,
+ -796, -823, 777,
+ 1380, 910, 1755,
+ 119, 1417, 972,
+ -219, -880, -1596,
+ -1049, -1010, 438,
+ -713, -1379, 78,
+ 0, -447, -1179,
+ -1136, -1319, -1573,
+ 2248, 1767, 1309,
+ 946, 1583, 1432,
+ 1150, 482, 436,
+ -469, -1108, 618,
+ -447, -966, 1088,
+ -1252, -1515, -114,
+ -1104, -2008, -579,
+ 210, 613, 497,
+ -1975, -1437, 642,
+ -1269, -856, 1011,
+ -1646, -1185, 1063,
+ -1555, -672, 1204,
+ -1692, -1114, 623,
+ -979, -1326, -1277,
+ 539, -147, 894,
+ -1354, -897, -434,
+ 888, 475, 428,
+ 153, -384, 338,
+ -1492, -511, 359,
+ -974, -1115, -470,
+ 105, -550, 677,
+ -937, -1145, 877,
+ 380, -260, 210,
+ 1685, 924, 1256,
+ 1775, 1190, 1095,
+ 1419, 631, 533,
+ 627, 299, -347,
+ -411, -534, 647,
+ -650, 29, -595,
+ -378, -1367, 1563,
+ 1402, 1121, 1465,
+ 1089, 1410, 648,
+ -2096, -1090, -6,
+ 311, -194, -869,
+ -639, -831, 416,
+ -1162, -1224, 1349,
+ -1247, -941, 1813,
+ -2193, -1987, 453,
+ -619, -1367, -956,
+ -1606, -1972, -1507,
+ -1175, -1057, -1104,
+ -377, 601, 201,
+ 1876, 825, 374,
+ -430, -1323, 29,
+ -1397, -1249, -1331,
+ -1007, -1504, 960,
+ -1401, -2009, 197,
+ -1379, -1949, -236,
+ -1077, 123, 422,
+ 615, 1269, 546,
+ -306, 1526, 904,
+ 1194, 1788, 1177,
+ -626, -884, -1526,
+ 199, 766, 1504,
+ -1065, 862, 197,
+ -1034, -1773, -887,
+ -800, 145, 599,
+ -1134, -519, 626,
+ -1205, -1926, 500,
+ -910, -1041, -1395,
+ -1476, -1567, -969,
+ -523, 842, 34,
+ 1794, 646, 862,
+ -1207, -1888, -1002,
+ -78, -9, -672,
+ 1044, 759, 80,
+ -600, 1139, 1019,
+ 57, 2000, 1422,
+ -833, 1414, 1121,
+ -1202, 1630, 1260,
+ -461, 1420, 1244,
+ 1537, 975, 253,
+ -283, 324, -359,
+ 599, -195, 106,
+ 588, 62, -587,
+ -757, 645, 205,
+ 51, 1201, 758,
+ -1209, 673, -390,
+ -624, 1581, 941,
+ -151, 1023, 735,
+ 2820, 1301, 690,
+ -302, 524, -99,
+ -900, -1588, -1189,
+ 1084, 251, 238,
+ 2014, 1792, 1010,
+ 1245, 1633, 1741,
+ -1227, -1540, -1208,
+ -621, 456, -109,
+ 40, -65, 788,
+ -805, -699, -1350,
+ -583, 904, 832,
+ -801, 532, 594,
+ 1972, 1408, 1351,
+ -1177, -1880, -2114,
+ -773, 568, 948,
+ -1015, 1079, 1260,
+ -1111, 482, -130,
+ 1778, 1044, 780,
+ -1491, 245, 912,
+ -316, -1141, -917,
+ -536, -1442, -2346,
+ -785, -1546, -1988,
+ -2003, 257, 909,
+ -1849, -633, -1209,
+ -1538, -1918, -1054,
+ 1606, 2239, 1576,
+ -567, -1500, -1544,
+ -1279, 195, 1369,
+ -817, 293, 1219,
+ -525, 630, 1197,
+ -1698, -2425, -1840,
+ -303, 731, 747,
+ -1169, -251, 269,
+ -950, -75, 1684,
+ -1182, -453, 1005,
+ -1599, 585, 378,
+ -2075, -571, -427,
+ -529, -1159, -1171,
+ -283, -205, -564,
+ -796, 1246, 717,
+ 2277, 927, 539,
+ -454, 559, 440,
+ -717, 1460, 1615,
+ -1030, 1052, 1610,
+ -1169, -138, 847,
+ 226, 39, -612,
+ -1251, -106, -729,
+ -651, 968, 1302,
+ -714, -636, 1727,
+ 353, 1069, 410,
+ -798, -156, 1099,
+ -574, 918, 446,
+ -1310, 1012, 466,
+ 1408, 1591, 765,
+ 1429, 1380, 1757,
+ 1949, 1956, 2378,
+ 1578, 2047, 2148,
+ 916, 98, -7,
+ 1893, 1418, 2141,
+ 348, 1405, 1579,
+ 152, 1134, 1801,
+ -267, 154, 1395,
+ -1166, 469, 1054,
+ -1142, -405, -1073,
+ -1341, -2264, -1581,
+ -364, 869, 1706,
+ -1162, 549, 1550,
+ -1225, -1932, -1666,
+ -1485, -1977, -2055,
+ -1727, -906, -98,
+ -1897, 233, 1492,
+ 892, 108, -331,
+ -1728, -1170, -1700,
+ -1060, 1980, 1790,
+ -1070, -1741, -1909,
+ -11, 1539, 1317,
+ -1600, 94, 497,
+ 421, 443, -197,
+ -1578, -349, -994,
+ -599, -539, 1140,
+ -965, -1419, -129,
+ -1341, 175, -447,
+ -375, 1311, 2055,
+ -371, -650, -307,
+ -1073, 605, 365,
+ -2057, -113, 430,
+ 652, 914, 967,
+ -1012, -1586, -2323,
+ 1505, 1248, 559,
+ 262, -486, -401,
+ -1727, 1342, 1546,
+ 50, 56, 432,
+ -330, 119, -604,
+ -1517, -1080, -810,
+ 946, 1127, 1055,
+ -1400, -1703, -1712,
+ -1270, -704, -1317,
+ 807, 1821, 1143,
+ 2760, 1606, 2171,
+ 1120, 409, -150,
+ -147, 404, 959,
+ 2439, 1911, 2189,
+ -906, -141, -866,
+ -904, -142, -458,
+ -557, -708, -1679,
+ -830, -1431, -1583,
+ -1842, -1346, -1086,
+ -1604, -272, 915,
+ -1196, 772, 1056,
+ -638, -1234, -1897,
+ -500, -81, -822,
+ -1289, -1613, -735,
+ -117, 785, 168,
+ -1090, 1133, 922,
+ -1096, -746, 1384,
+ 287, -547, -1063,
+ -1376, -2201, -1204,
+ -2176, -1570, -1757,
+ -1511, -2241, -771,
+ -1737, 1099, 830,
+ -1588, 724, 1243,
+ -1542, 693, 805,
+ -1690, -240, 1665,
+ -1700, -4, -668,
+ 2149, 816, 1042,
+ -818, -1841, 22,
+ -764, -507, 449,
+ -1151, -617, 289,
+ -843, -1596, -240,
+ 498, -234, -657,
+ -752, 480, 1678,
+ -319, -481, 193,
+ -811, 171, -119,
+ -2128, -202, -848,
+ 1717, 1140, 1700
+};
+
+
+/* third codebook from IS641 */
+
+const Word16 dico3_lsf_3[DICO3_SIZE*4] =
+{
+ 67, -17, 66, -12,
+ -1690, -581, -104, -272,
+ -1076, -1186, -1845, -376,
+ -1140, -926, -420, -58,
+ -259, -656, -1134, -553,
+ 1788, 1227, 455, 129,
+ 462, 441, -240, -528,
+ 840, 514, 130, -75,
+ 1114, 623, 153, 216,
+ 1068, 564, -6, -276,
+ 1119, 727, 190, -68,
+ 704, 306, 119, -264,
+ 329, 61, -100, 156,
+ 364, 123, 183, -208,
+ -171, -123, 220, -65,
+ -306, -62, 402, 17,
+ -660, -938, -266, 0,
+ 385, 235, 276, 285,
+ 320, 268, -336, -200,
+ -724, 17, -84, 381,
+ -544, 429, 494, 519,
+ -117, 288, 304, 329,
+ 643, 157, 701, 508,
+ 1200, 625, 796, 608,
+ 998, 421, 492, 632,
+ 1204, 780, 446, 132,
+ 1257, 844, 547, 449,
+ 829, 658, 541, 470,
+ 1132, 1258, 918, 639,
+ 547, 51, 423, 279,
+ 9, 392, 83, 94,
+ 542, 543, 229, -147,
+ -198, 129, 194, -185,
+ -863, -1321, -302, 30,
+ -597, -629, -19, 114,
+ -900, -1081, 466, 353,
+ -1483, -1573, 15, -143,
+ -1708, -2059, -751, 196,
+ -1876, -2067, -642, -258,
+ -2335, -1470, -450, -564,
+ -584, -186, -872, -414,
+ -1805, -988, -1125, -1310,
+ -726, -1129, 28, 169,
+ -1039, -864, -718, -246,
+ 484, 36, -233, -49,
+ 265, 67, 289, 467,
+ 178, 543, 810, 540,
+ 84, 282, 672, 703,
+ -975, -777, 129, 287,
+ -938, -227, 955, 595,
+ -1617, -289, 836, 649,
+ -1847, -215, 1106, 718,
+ -2034, -1085, 650, 440,
+ -2101, -529, 907, 575,
+ -2011, -336, 670, 204,
+ -2389, -692, 360, 137,
+ -2156, -2204, -9, 280,
+ -266, 119, 39, 193,
+ 78, -59, -120, 226,
+ -975, -858, -781, -1095,
+ -619, -413, -451, -842,
+ -1216, -1321, -813, -883,
+ -1376, -1615, -394, -428,
+ -737, -1113, -549, -790,
+ -880, -975, -967, -642,
+ -985, -886, -1273, -1361,
+ -473, -804, -1401, -1407,
+ 160, -265, -919, -275,
+ -248, -250, -718, -380,
+ 97, -103, -375, -229,
+ -415, -193, -135, -555,
+ 628, 361, 119, 216,
+ 579, 364, 391, 209,
+ 634, 522, -154, -148,
+ 526, 389, 170, 33,
+ 105, 267, 64, 380,
+ -1503, -1000, -30, -369,
+ -1070, 58, 647, 223,
+ -1520, -291, 621, 307,
+ -1531, 156, 762, 404,
+ -2029, 141, 734, 499,
+ -1849, -650, 306, 512,
+ -187, -104, -59, 438,
+ 134, -230, 156, -186,
+ -61, -260, -16, 10,
+ -569, -3, -421, -297,
+ -1725, -521, -346, 178,
+ -1362, -59, -44, 157,
+ -2146, -461, -470, -349,
+ -2170, -1, -369, -121,
+ -1579, -373, -900, -1015,
+ -1117, -591, -613, -784,
+ -561, 122, -75, -449,
+ -4, -171, -123, -372,
+ 192, 168, -76, -132,
+ 252, -107, 340, 210,
+ 392, 509, 272, 181,
+ -109, 145, 218, 119,
+ -416, -263, 485, 265,
+ -181, -8, -286, 226,
+ -244, -218, 69, -290,
+ -158, 191, -1, -64,
+ -592, -90, 213, -96,
+ 255, 435, 178, -80,
+ -369, -18, -33, -80,
+ -42, 415, 140, -222,
+ 1143, 651, 649, 329,
+ 767, 556, 249, 235,
+ 948, 413, 442, 279,
+ 141, 339, 356, 557,
+ -470, -170, 99, 237,
+ -569, -800, 352, 565,
+ 282, 473, 470, 332,
+ -199, -690, -1284, -917,
+ -193, -426, -800, -1122,
+ -26, -371, -490, -193,
+ 637, 595, 519, 330,
+ 408, -115, 79, 12,
+ 477, 87, -103, -376,
+ -666, -347, -277, -291,
+ -510, -481, 169, 297,
+ -829, -738, -205, -171,
+ -320, -540, 328, 283,
+ -859, -958, 442, -2,
+ 556, 686, 130, 56,
+ 1383, 1012, 755, 427,
+ 612, 741, 628, 553,
+ -339, -796, 134, 277,
+ -633, -1085, -2, -246,
+ -880, -1035, -1607, -1064,
+ -994, -474, -1138, -488,
+ -414, -795, 73, -206,
+ -8, -139, 439, 204,
+ -176, -578, 23, 131,
+ -269, -757, -191, 245,
+ -109, -338, 112, 316,
+ 120, -406, -118, 611,
+ -180, -186, -645, 115,
+ -173, 34, -518, -489,
+ -151, 61, -583, -844,
+ 220, -138, -681, -1020,
+ 391, -17, -598, -321,
+ 157, -295, 129, 155,
+ -926, -875, -987, 285,
+ 241, -83, -125, -125,
+ 620, 597, 432, 92,
+ 393, 78, 409, 61,
+ -393, -739, -413, -748,
+ 83, 54, 361, 27,
+ -1084, 130, -337, -694,
+ -1565, 297, 318, -19,
+ -1873, 36, 51, -317,
+ -2323, -246, 231, -84,
+ -2306, -783, 40, -179,
+ -2233, -930, -474, -462,
+ -754, -86, -288, -626,
+ -2411, -455, -63, 171,
+ -1099, -1094, -26, -143,
+ -1193, -455, -406, -381,
+ -605, -210, -96, -51,
+ -580, -476, -276, -15,
+ -1195, -634, -1203, -881,
+ -378, -221, -669, -952,
+ 594, 178, -403, -676,
+ 763, 327, 601, 290,
+ 172, 300, 203, 157,
+ -56, -336, 356, 24,
+ -228, -296, -259, -29,
+ -186, 263, 416, 14,
+ -353, 373, -12, -216,
+ 257, 96, 174, 57,
+ -1526, -616, -954, -499,
+ -497, -152, -333, 125,
+ 105, 200, 179, -97,
+ -331, -224, 765, 697,
+ 760, 256, 301, 59,
+ 455, -85, 204, 288,
+ -514, 240, 251, -109,
+ 256, 417, -34, -413,
+ 101, 430, 384, 156,
+ -31, -10, 206, 426,
+ 589, 145, 143, 71,
+ 808, 906, 333, 349,
+ 986, 938, 589, 331,
+ 1300, 824, 187, 509,
+ 1062, 653, 379, 466,
+ 1462, 937, 401, 274,
+ 787, 861, 265, 2,
+ 609, 553, 28, 305,
+ 926, 340, 106, 386,
+ 241, -267, -147, 225,
+ -178, -534, 347, 502,
+ -643, -381, 397, 30,
+ -651, -733, -435, 398,
+ -407, -726, -484, -248,
+ -789, -914, -438, -476,
+ -498, -390, 75, -295,
+ -964, -590, -606, 150,
+ -121, -49, -155, -78,
+ 935, 550, 389, 38,
+ -321, 127, 424, 315,
+ -285, -113, 283, 259,
+ 658, 203, 322, 486,
+ 903, 505, 748, 417,
+ 611, 423, 555, 512,
+ 239, -83, -578, -19,
+ -339, -731, 349, 13,
+ -934, -1399, -114, -360,
+ 107, 692, 182, 90,
+ -1243, -1538, -1551, -725,
+ -568, -903, -1363, -525,
+ -517, -853, -861, -1004,
+ -168, -690, -835, 63,
+ -137, -556, -547, 144,
+ -286, -817, 485, 319,
+ -147, -408, 526, 246,
+ -347, -434, 297, -28,
+ -290, -471, -1110, -1285,
+ -460, -359, -988, -794,
+ 1347, 1299, 690, 523,
+ 1216, 1068, 1094, 757,
+ 825, 1140, 752, 494,
+ 1252, 1365, 1195, 898,
+ 521, 1053, 532, 432,
+ -334, -216, -313, -263,
+ -160, 52, -472, -155,
+ 127, 136, -380, 44,
+ 851, 410, -162, -489,
+ 123, -255, -796, -667,
+ 1090, 917, 789, 493,
+ 1397, 1197, 558, 202,
+ -51, -118, -342, -701,
+ 83, 108, -42, -441,
+ 61, 95, 287, 256,
+ -27, 89, 524, 531,
+ 351, 227, 592, 545,
+ 697, 155, -164, 307,
+ 638, 274, -489, -50,
+ 754, 240, -166, -124,
+ -116, -579, -1212, -63,
+ 190, -295, -1040, -1296,
+ 147, -376, -177, -113,
+ 841, 1241, 1051, 668,
+ 2, 293, 551, 304,
+ -1096, -953, -248, 376,
+ -750, -965, 87, 516,
+ -275, -516, 689, 391,
+ -379, -643, 876, 594,
+ -390, -1013, -645, 573,
+ -107, -568, -689, -826,
+ -1025, -27, -328, -203,
+ 861, 749, 548, 233,
+ -1660, -1043, 451, 108,
+ -660, -620, 430, 236,
+ 21, -396, -1158, -631,
+ 1372, 1298, 967, 577,
+ 1125, 1125, 589, 454,
+ -323, -865, -467, 153,
+ -468, -699, -804, -509,
+ -392, -718, -204, -35,
+ -603, -1093, -567, -162,
+ -505, -1004, -102, 350,
+ 219, 224, 423, 252,
+ 395, 591, 608, 363,
+ -746, -96, 373, 172,
+ 171, 295, 714, 339,
+ 233, 77, 107, 277,
+ 157, 153, -499, -356,
+ 1547, 1073, 576, 494,
+ -292, -339, -504, -592,
+ -903, -72, -619, -481,
+ -1594, -1117, -567, -254,
+ -793, -507, -564, -291,
+ -492, -532, 502, 560,
+ -382, 427, 600, 230,
+ -227, 477, 251, 75,
+ 285, 842, 813, 476,
+ -1310, -1333, 186, 377,
+ -587, -917, 643, 381,
+ -1186, -553, 411, 82,
+ -1127, -820, -174, -540,
+ -604, 119, 543, 205,
+ -380, 657, 909, 567,
+ 112, -298, -374, 114,
+ -857, -251, 56, 159,
+ 401, 345, -34, -140,
+ -111, -607, 41, 614,
+ 355, -114, -77, 474,
+ 578, 56, 1450, 924,
+ 1098, 1420, 741, 400,
+ 246, 22, 588, 313,
+ -121, 327, 831, 472,
+ -1138, -608, 856, 552,
+ -1241, -1072, 638, 600,
+ -358, 254, -333, -303,
+ -646, 739, 358, 74,
+ 1226, 1671, 1221, 849,
+ 2241, 1624, 983, 636,
+ 1841, 1477, 749, 384,
+ 350, 263, 87, 128,
+ -1902, -941, -144, -64,
+ -1734, -255, 288, -31,
+ -2644, -1238, 366, 235,
+ -1643, -1092, -1344, -304,
+ -541, -1075, -1116, 123,
+ -1178, -252, -816, -180,
+ -1016, 533, 565, 233,
+ -487, -430, -188, 334,
+ 867, 1236, 534, 171,
+ -1590, -1607, 635, 630,
+ -2196, 310, 924, 412,
+ -2358, -328, 956, 529,
+ -2639, -377, 630, 278,
+ -2602, 317, 799, 299,
+ -2406, 133, 340, 31,
+ -2156, -1468, 131, 125,
+ -1184, -490, -139, 46,
+ -744, 447, 891, 564,
+ 67, -451, 646, 604,
+ -553, -429, -876, 396,
+ 162, -66, 1305, 915,
+ 479, 579, 1088, 794,
+ 450, 278, 566, 324,
+ -1057, -154, 148, -177,
+ -2545, 168, 1070, 592,
+ -2351, -42, 819, 345,
+ -2344, -707, 721, 250,
+ -2175, -1497, -309, 122,
+ -78, -73, 120, 173,
+ -4, 262, -263, -261,
+ -431, -64, -405, -732,
+ -2609, 116, -83, -193,
+ -1525, -944, -477, -725,
+ -508, 307, 170, 172,
+ 832, 417, 832, 686,
+ -225, 177, 894, 818,
+ -482, -389, 1279, 1039,
+ -383, 201, -350, 40,
+ 730, 635, 226, 526,
+ 503, 462, 338, 398,
+ 535, 714, 40, -282,
+ 1482, 1471, 1085, 731,
+ 1561, 1072, 909, 693,
+ 1419, 1282, 889, 879,
+ 1153, 728, 1186, 840,
+ -226, 1130, 949, 689,
+ -494, -986, -1556, -128,
+ -568, -721, -713, -26,
+ 317, 524, 70, 135,
+ -405, -865, -1766, -652,
+ -174, -801, 885, 773,
+ -153, -91, 1099, 751,
+ -506, -1149, 853, 646,
+ 241, 782, 519, 539,
+ 1853, 1700, 1101, 684,
+ -1249, -1486, -464, 188,
+ -893, -1409, -1312, -341,
+ -135, 438, -175, 18,
+ 1111, 976, 319, 208,
+ -1430, -1768, 83, 458,
+ -530, -1000, 307, 129,
+ -840, -15, -29, -356,
+ -911, -924, -1147, -242,
+ -119, -528, 127, -133,
+ -761, -765, 190, -83,
+ -315, 895, 522, 231,
+ -222, 102, -63, -428,
+ 316, 699, 379, 70,
+ 25, 716, 314, -108,
+ 507, 874, 566, 238,
+ 108, 941, 519, 195,
+ 425, -60, -427, 257,
+ 139, -103, -630, 446,
+ 334, 370, 412, 48,
+ -172, -690, -283, 557,
+ 187, -286, 158, 483,
+ 140, 270, -344, -631,
+ 924, 579, -116, 132,
+ 142, 466, -68, -64,
+ 230, -145, -302, -542,
+ -803, -912, 1018, 737,
+ -773, 1015, 630, 297,
+ -2596, 95, 445, 336,
+ -2122, 491, 510, 191,
+ -1253, 161, -2, -324,
+ -1450, -633, -712, -105,
+ -842, -254, -411, 100,
+ -640, -290, 1010, 763,
+ -650, 313, 1169, 730,
+ 140, 505, 1030, 766,
+ 772, 287, 1067, 823,
+ 495, 749, 305, 323,
+ -164, 462, 78, 399,
+ -342, -874, 69, 597,
+ -16, 620, 621, 337,
+ -138, -444, -265, 218,
+ 84, -450, 953, 666,
+ -222, -803, 541, 604,
+ -921, -1376, 244, 116,
+ -841, -723, 630, 588,
+ 140, 663, 294, 368,
+ 935, 1046, 881, 759,
+ 1746, 1464, 916, 628,
+ 436, 963, 281, 1,
+ -119, 74, 542, 213,
+ 1, -567, 301, 241,
+ 260, 435, 222, 396,
+ 936, 957, 1108, 703,
+ 510, 506, 808, 478,
+ 601, 694, 960, 620,
+ 972, 741, 980, 600,
+ 834, 717, 767, 684,
+ 643, 972, 935, 638,
+ 501, 661, 720, 851,
+ -105, -632, -303, -117,
+ -429, 130, 789, 442,
+ -522, -188, 704, 373,
+ -759, 42, 814, 523,
+ -531, -1137, 373, 578,
+ -682, -1203, -455, 285,
+ -1163, -1577, -1098, 44,
+ 81, -82, 712, 363,
+ 477, 246, 954, 622,
+ 1604, 1622, 1277, 891,
+ 1409, 859, 924, 892,
+ 774, 1041, 947, 1142,
+ 40, -546, -75, 288,
+ -616, -106, -697, -26,
+ -169, -160, -891, -739,
+ -279, -384, -1029, -350,
+ 1781, 1308, 1046, 816,
+ 1580, 1533, 1472, 1178,
+ 1505, 1076, 1216, 899,
+ 890, 904, 564, 654,
+ 920, 692, 1021, 856,
+ -493, 132, 177, 505,
+ 71, 195, -28, 97,
+ 456, 351, -164, 88,
+ 439, 278, -40, 350,
+ 1395, 949, 234, -95,
+ -805, -472, 38, -163,
+ 367, -98, 489, 523,
+ 1025, 1178, 1212, 906,
+ 319, 1314, 814, 461,
+ -123, -543, -804, 447,
+ -748, -324, -897, -1127,
+ -737, -501, -789, -713,
+ 715, 777, 1239, 922,
+ 1949, 1939, 1368, 865,
+ 730, 880, 758, 388,
+ -871, 454, 17, -251,
+ -381, -810, -1583, 239,
+ -521, -966, -792, 259,
+ -890, -1358, -770, -73,
+ 166, 349, -212, 323,
+ -840, -301, 473, 435,
+ -679, -464, 728, 351,
+ -156, -199, 667, 432,
+ 29, -252, 415, 480,
+ -731, -379, 145, 559,
+ -528, -631, -1158, -159,
+ 445, 273, 123, 639,
+ 373, -126, 800, 568,
+ 84, -162, 720, 712,
+ -830, -536, -185, 222,
+ 408, 452, 501, 771,
+ -897, -1355, -67, 442,
+ -792, -1406, 566, 602,
+ 167, -326, 509, 330,
+ -95, -626, -730, -344,
+ 1668, 1217, 779, 455,
+ 1316, 828, 584, 719,
+ 404, -31, 1013, 789,
+ 89, 107, 891, 549,
+ 871, 1581, 917, 671,
+ 866, 1479, 1289, 854,
+ 391, 1068, 1122, 812,
+ 78, -562, 345, 563,
+ 429, -103, 417, 787,
+ -122, -437, 411, 788,
+ -913, -417, 602, 754,
+ -226, -16, 151, 760,
+ -700, 118, -104, -14,
+ -1128, 48, 284, 393,
+ -390, -419, -639, -116,
+ -910, 306, 316, -13,
+ 1207, 984, 821, 669,
+ -1195, -693, 140, -213,
+ -884, -416, -199, -558,
+ -616, 245, -404, -664,
+ 262, 56, -617, -724,
+ -85, -491, -320, -656,
+ -570, -831, -129, -528,
+ -1506, -63, -367, -385,
+ -358, -321, 4, 51,
+ -366, -214, 319, 511,
+ 146, 671, -17, -291,
+ -110, 464, -139, -496,
+ -202, 220, -312, -631,
+ -660, -73, -655, -820,
+ -662, -653, -1288, -857,
+ -430, -953, -959, -264,
+ -49, -468, -72, -381,
+ -350, -563, -193, -407,
+ 55, -408, -803, 11,
+ -309, 649, 188, -198,
+ -512, 461, -79, -458,
+ -1318, -263, -134, -523,
+ -1657, -435, -495, -765,
+ 57, -347, -414, 434,
+ -1141, -242, -664, -857,
+ 34, -68, -707, -338
+};
+
+
+
+/* third codebook for MR475, MR515 */
+
+const Word16 mr515_3_lsf[MR515_3_SIZE*4] =
+{
+ 419, 163, -30, -262,
+ -455, -789, -1430, -721,
+ 1006, 664, 269, 25,
+ 619, 260, 183, 96,
+ -968, -1358, -388, 135,
+ -693, 835, 456, 154,
+ 1105, 703, 569, 363,
+ 1625, 1326, 985, 748,
+ -220, 219, 76, -208,
+ -1455, -1662, 49, 149,
+ -964, -172, -752, -336,
+ 625, 209, -250, -66,
+ -1017, -838, -2, 317,
+ -2168, -1485, -138, 123,
+ -1876, -2099, -521, 85,
+ -967, -366, -695, -881,
+ -921, -1011, -763, -949,
+ -124, -256, -352, -660,
+ 178, 463, 354, 304,
+ -1744, -591, -282, 79,
+ -2249, 175, 867, 499,
+ -138, -180, -181, -21,
+ -2291, -1241, -460, -520,
+ -771, 451, -10, -308,
+ 271, -65, 4, 214,
+ -279, -435, -43, -348,
+ -670, 35, -65, -211,
+ 806, 535, 85, 297,
+ 57, 239, 722, 493,
+ 225, 661, 840, 547,
+ -540, -376, 14, 349,
+ 469, 721, 331, 162,
+ -544, -752, -62, -10,
+ 398, -88, 724, 701,
+ -19, -533, -94, 601,
+ 136, -71, -681, -747,
+ -166, -344, 261, -50,
+ 161, -52, 485, 337,
+ -1675, 50, 190, -93,
+ -2282, -231, -194, -82,
+ -95, -595, -154, 128,
+ 894, 501, 588, 457,
+ -345, 206, 122, 110,
+ -631, -227, -569, 3,
+ 408, 239, 397, 226,
+ -197, -2, 128, 491,
+ 1281, 904, 292, 215,
+ 538, 306, 259, 509,
+ -677, -1047, 13, 321,
+ -679, -588, -358, -212,
+ -558, 243, 646, 479,
+ 486, 342, 634, 532,
+ 107, 802, 331, 136,
+ -112, -398, -1031, -286,
+ -326, -705, 288, 272,
+ 1299, 1144, 1178, 860,
+ -423, 121, -385, -148,
+ -295, -302, -834, -819,
+ 16, -24, -201, -476,
+ 555, 91, -245, 294,
+ -38, -379, -962, -1221,
+ -1191, -1518, -273, -395,
+ -390, -1013, -645, 573,
+ -1843, -1030, 505, 468,
+ 744, 947, 609, 493,
+ -689, -1172, -628, -135,
+ -1026, 195, 411, 196,
+ 1582, 1147, 575, 337,
+ -1239, -777, -648, -142,
+ 595, 825, 967, 735,
+ -1206, -970, -81, -342,
+ -745, 13, -72, 375,
+ 454, 19, 1407, 921,
+ -1647, -172, 861, 562,
+ 928, 1537, 1063, 740,
+ -2472, -952, 264, 82,
+ -502, -965, -1334, 123,
+ 867, 1236, 534, 171,
+ -2320, -460, 780, 363,
+ -1190, -617, 252, -61,
+ -174, 34, 1011, 788,
+ -2333, 247, 423, 153,
+ -16, -355, 262, 449,
+ -1576, -1073, -544, -371,
+ -615, -305, 1051, 805,
+ 687, 528, 6, -182,
+ 935, 875, 1002, 809,
+ 199, 257, 126, 76,
+ -584, -1138, 599, 556,
+ -1105, -1391, -1591, -519,
+ -977, -1325, 108, 347,
+ -722, -975, 365, 101,
+ -145, 681, 249, -153,
+ 0, -334, -570, 159,
+ 412, 285, -336, -617,
+ -953, -966, 887, 689,
+ -1251, 84, -185, -398,
+ -592, 433, 1044, 653,
+ 85, 329, -40, 361,
+ -433, -705, 466, 574,
+ -154, 654, 592, 290,
+ -167, 72, 349, 175,
+ 674, 297, 977, 720,
+ 1235, 1204, 757, 488,
+ -400, -269, 538, 372,
+ -1350, -1387, -1194, -91,
+ 1262, 876, 775, 700,
+ -599, -38, -430, -722,
+ 1976, 1630, 991, 608,
+ 111, 276, -226, -96,
+ -947, -388, -11, -7,
+ -303, -531, -839, 338,
+ 1734, 1710, 1405, 1013,
+ -516, -855, -645, 210,
+ -688, -416, 513, 230,
+ -822, -637, -1146, -320,
+ -952, -658, -694, 183,
+ -114, -623, 818, 674,
+ -191, -204, 731, 635,
+ 51, 1221, 883, 576,
+ -954, -431, 826, 598,
+ -342, -755, -900, -407,
+ -1126, -354, -206, -512,
+ -547, -810, -357, -620,
+ 66, 515, -73, -410,
+ -872, -945, -1444, -1227,
+ 191, -17, -544, -231,
+ -1540, -544, -901, -886
+};
+
+/* first codebook for MR795 */
+
+const Word16 mr795_1_lsf[MR795_1_SIZE*3] =
+{
+ -890, -1550, -2541,
+ -819, -970, 175,
+ -826, -1234, -762,
+ -599, -22, 634,
+ -811, -987, -902,
+ -323, 203, 26,
+ -383, -235, -781,
+ -399, 1262, 906,
+ -932, -1399, -1380,
+ -624, 93, 87,
+ -414, -539, -691,
+ 37, 633, 510,
+ -387, -476, -1330,
+ 399, 66, 263,
+ -407, -49, -335,
+ -417, 1041, 1865,
+ -779, -1089, -1440,
+ -746, -858, 832,
+ -581, -759, -371,
+ -673, -506, 2088,
+ -560, -634, -1179,
+ 271, 241, 14,
+ -438, -244, -397,
+ 463, 1202, 1047,
+ -606, -797, -1438,
+ -51, -323, 481,
+ -224, -584, -527,
+ 494, 881, 682,
+ -433, -306, -1002,
+ 554, 659, 222,
+ 171, -160, -353,
+ 681, 1798, 1565,
+ -852, -1181, -1695,
+ -336, -666, 114,
+ -581, -756, -744,
+ -195, 375, 497,
+ -465, -804, -1098,
+ 154, 282, -131,
+ -50, -191, -719,
+ 323, 732, 1542,
+ -722, -819, -1404,
+ 105, -250, 185,
+ -178, -502, -742,
+ 321, 510, 1111,
+ -323, -567, -966,
+ 127, 484, 338,
+ -160, 52, -338,
+ 732, 1367, 1554,
+ -626, -802, -1696,
+ -286, -586, 676,
+ -695, -343, -370,
+ -490, 295, 1893,
+ -630, -574, -1014,
+ -80, 645, -69,
+ -6, -318, -364,
+ 782, 1450, 1038,
+ -313, -733, -1395,
+ 120, 60, 477,
+ -264, -585, -123,
+ 711, 1245, 633,
+ -91, -355, -1016,
+ 771, 758, 261,
+ 253, 81, -474,
+ 930, 2215, 1720,
+ -808, -1099, -1925,
+ -560, -782, 169,
+ -804, -1074, -188,
+ -626, -55, 1405,
+ -694, -716, -1194,
+ -660, 354, 329,
+ -514, -55, -543,
+ 366, 1033, 1182,
+ -658, -959, -1357,
+ -55, -184, 93,
+ -605, -286, -662,
+ 404, 449, 827,
+ -286, -350, -1263,
+ 628, 306, 227,
+ -16, 147, -623,
+ 186, 923, 2146,
+ -674, -890, -1606,
+ -443, -228, 339,
+ -369, -790, -409,
+ 231, 86, 1469,
+ -448, -581, -1061,
+ 594, 450, -177,
+ -124, -170, -447,
+ 671, 1159, 1404,
+ -476, -667, -1511,
+ -77, -138, 716,
+ -177, -372, -381,
+ 451, 934, 915,
+ -250, -432, -822,
+ 272, 828, 446,
+ 26, 19, -31,
+ 698, 1692, 2168,
+ -646, -977, -1924,
+ -179, -473, 268,
+ -379, -745, -691,
+ 11, 127, 1033,
+ -488, -917, -825,
+ 61, 323, 135,
+ 147, -145, -686,
+ 685, 786, 1682,
+ -506, -848, -1297,
+ 35, 90, 222,
+ -23, -346, -670,
+ 455, 591, 1287,
+ -203, -593, -1086,
+ 652, 352, 437,
+ 39, 63, -457,
+ 841, 1265, 2105,
+ -520, -882, -1584,
+ -328, -711, 1421,
+ -596, -342, -70,
+ 209, 173, 1928,
+ -423, -598, -921,
+ 421, 605, -38,
+ -2, -245, -127,
+ 896, 1969, 1135,
+ -379, -518, -1579,
+ 173, 118, 753,
+ -55, -381, -52,
+ 985, 1021, 753,
+ -2, -291, -891,
+ 753, 992, 423,
+ 264, 131, -196,
+ 895, 2274, 2543,
+ -635, -1088, -2499,
+ -529, -982, 526,
+ -764, -830, -548,
+ -436, 316, 599,
+ -675, -940, -746,
+ -57, 236, -11,
+ -201, -81, -798,
+ 16, 845, 1558,
+ -737, -985, -1212,
+ -468, 17, 290,
+ -279, -584, -700,
+ 183, 822, 705,
+ -265, -492, -1187,
+ 421, 152, 468,
+ -390, 166, -268,
+ 39, 1550, 1868,
+ -635, -966, -1571,
+ -453, -492, 910,
+ -284, -1027, -75,
+ -181, -133, 1852,
+ -445, -624, -1174,
+ 420, 367, -49,
+ -389, -212, -169,
+ 707, 1073, 1208,
+ -539, -710, -1449,
+ 83, -163, 484,
+ -236, -543, -355,
+ 338, 1175, 814,
+ -246, -309, -958,
+ 606, 760, 60,
+ 166, -8, -163,
+ -306, 1849, 2563,
+ -747, -1025, -1783,
+ -419, -446, 209,
+ -718, -566, -534,
+ -506, 693, 857,
+ -463, -697, -1082,
+ 325, 431, -206,
+ -15, -8, -763,
+ 545, 919, 1518,
+ -611, -783, -1313,
+ 256, -55, 208,
+ -165, -348, -662,
+ 321, 680, 930,
+ -326, -429, -951,
+ 484, 446, 570,
+ -197, 72, -73,
+ 909, 1455, 1741,
+ -563, -737, -1974,
+ -124, -416, 718,
+ -478, -404, -314,
+ -16, 446, 1636,
+ -551, -537, -750,
+ -58, 638, 214,
+ 55, -185, -271,
+ 1148, 1301, 1212,
+ -483, -671, -1264,
+ 117, 285, 543,
+ -204, -391, -111,
+ 513, 1538, 854,
+ -114, -190, -978,
+ 877, 595, 464,
+ 260, 260, -311,
+ 748, 2283, 2216,
+ -517, -945, -2171,
+ -326, -708, 378,
+ -812, -691, -232,
+ -560, 687, 1409,
+ -732, -690, -836,
+ -359, 645, 386,
+ -265, 62, -678,
+ 145, 1644, 1208,
+ -555, -988, -1233,
+ -78, 14, 114,
+ -327, -358, -489,
+ 392, 677, 697,
+ -201, -236, -1140,
+ 693, 449, 178,
+ -243, 256, -433,
+ 611, 1385, 2456,
+ -612, -901, -1464,
+ -307, -17, 499,
+ -315, -667, -254,
+ 256, 428, 1463,
+ -486, -422, -1056,
+ 655, 370, 18,
+ -102, -185, -276,
+ 755, 1578, 1335,
+ -488, -603, -1418,
+ 182, -93, 870,
+ -73, -458, -348,
+ 835, 862, 957,
+ -282, -333, -746,
+ 547, 839, 428,
+ 273, -89, 13,
+ 940, 1708, 2576,
+ -418, -1084, -1758,
+ -44, -358, 259,
+ -497, -643, -560,
+ 99, 557, 961,
+ -421, -766, -917,
+ 295, 326, 184,
+ 175, 15, -626,
+ 532, 878, 1981,
+ -443, -768, -1275,
+ 221, 156, 268,
+ 39, -363, -505,
+ 695, 772, 1140,
+ -162, -459, -912,
+ 709, 444, 658,
+ 25, 303, -312,
+ 1268, 1410, 1715,
+ -297, -766, -1836,
+ -263, -108, 1070,
+ -406, -13, -129,
+ 57, 438, 2734,
+ -374, -487, -835,
+ 304, 696, 164,
+ 104, -235, 5,
+ 1611, 1900, 1399,
+ -229, -582, -1325,
+ 405, 192, 817,
+ -87, -438, 111,
+ 1028, 1199, 993,
+ 68, -175, -934,
+ 1033, 1117, 451,
+ 478, 200, -248,
+ 2127, 2696, 2042,
+ -835, -1323, -2131,
+ -799, -692, 466,
+ -812, -1032, -469,
+ -622, 288, 920,
+ -701, -841, -1070,
+ -411, 512, 8,
+ -390, -91, -744,
+ -30, 1043, 1161,
+ -822, -1148, -1156,
+ -294, -46, 110,
+ -411, -374, -678,
+ 214, 531, 668,
+ -406, -420, -1194,
+ 487, 232, 303,
+ -318, 91, -472,
+ 123, 1232, 2445,
+ -722, -952, -1495,
+ -738, -675, 1332,
+ -543, -606, -211,
+ -95, -98, 1508,
+ -549, -514, -1193,
+ 473, 211, 73,
+ -288, -112, -389,
+ 537, 1332, 1258,
+ -567, -755, -1545,
+ 71, -283, 632,
+ -170, -481, -493,
+ 681, 1002, 817,
+ -356, -331, -877,
+ 419, 706, 346,
+ 241, -34, -326,
+ 377, 1950, 1883,
+ -727, -1075, -1625,
+ -233, -543, 116,
+ -524, -806, -585,
+ -73, 478, 729,
+ -288, -925, -1143,
+ 173, 447, -52,
+ 68, -229, -606,
+ 449, 529, 1797,
+ -591, -875, -1363,
+ 183, -144, 324,
+ -103, -452, -666,
+ 623, 488, 1176,
+ -238, -511, -1004,
+ 326, 552, 458,
+ 136, 108, -319,
+ 626, 1343, 1883,
+ -490, -646, -1730,
+ -186, -449, 984,
+ -738, -76, -170,
+ -550, 755, 2560,
+ -496, -510, -947,
+ 210, 694, -52,
+ 84, -322, -199,
+ 1090, 1625, 1224,
+ -376, -603, -1396,
+ 343, 74, 632,
+ -175, -502, -32,
+ 972, 1332, 734,
+ 52, -295, -1113,
+ 1065, 918, 160,
+ 393, 107, -397,
+ 1214, 2649, 1741,
+ -632, -1201, -1891,
+ -719, -277, 353,
+ -651, -880, -122,
+ -211, 209, 1338,
+ -562, -714, -1059,
+ -208, 388, 159,
+ -320, -61, -551,
+ 293, 1092, 1443,
+ -648, -865, -1253,
+ -49, -143, 305,
+ -401, -227, -585,
+ 561, 532, 927,
+ -117, -443, -1188,
+ 507, 436, 292,
+ -79, 233, -458,
+ 671, 1025, 2396,
+ -633, -842, -1525,
+ -308, -286, 640,
+ -373, -621, -407,
+ 418, 253, 1305,
+ -315, -581, -1137,
+ 572, 685, -281,
+ 61, -68, -371,
+ 991, 1101, 1498,
+ -493, -683, -1362,
+ -47, 164, 704,
+ -256, -314, -268,
+ 631, 949, 1052,
+ -118, -348, -833,
+ 68, 1180, 568,
+ 152, 117, 34,
+ 1113, 1902, 2239,
+ -601, -959, -1706,
+ -143, -489, 480,
+ -332, -655, -574,
+ 54, 353, 1192,
+ -462, -652, -796,
+ 150, 549, 112,
+ 195, -111, -515,
+ 679, 1108, 1647,
+ -558, -749, -1217,
+ -9, 272, 341,
+ -53, -265, -535,
+ 489, 843, 1298,
+ -120, -482, -1032,
+ 632, 543, 408,
+ 179, 306, -526,
+ 1124, 1464, 2244,
+ -417, -786, -1562,
+ -224, -384, 1364,
+ -377, -459, -25,
+ 385, 489, 2174,
+ -332, -651, -829,
+ 544, 553, 61,
+ 22, -113, -89,
+ 1128, 1725, 1524,
+ -216, -373, -1653,
+ 161, 316, 908,
+ -165, -222, -67,
+ 1362, 1175, 789,
+ 73, -252, -767,
+ 738, 932, 616,
+ 362, 246, -126,
+ 787, 2654, 3027,
+ -691, -1106, -2190,
+ -565, -588, 524,
+ -590, -979, -490,
+ -263, 397, 982,
+ -577, -837, -945,
+ -22, 435, -49,
+ -190, -118, -629,
+ -88, 1240, 1513,
+ -636, -1051, -1019,
+ -291, 189, 259,
+ -257, -470, -629,
+ 145, 945, 894,
+ -326, -364, -1094,
+ 543, 260, 630,
+ -202, 189, -209,
+ 357, 1379, 2091,
+ -569, -1075, -1449,
+ -714, -239, 919,
+ -420, -705, -84,
+ -109, -114, 2407,
+ -413, -529, -1177,
+ 482, 368, 131,
+ -186, -72, -131,
+ 861, 1255, 1220,
+ -611, -658, -1341,
+ 227, -121, 631,
+ -176, -489, -218,
+ 745, 1175, 957,
+ -321, -148, -936,
+ 671, 966, 216,
+ 340, -3, -143,
+ 469, 1848, 2437,
+ -729, -961, -1683,
+ -213, -254, 321,
+ -511, -438, -521,
+ -126, 725, 903,
+ -340, -685, -1032,
+ 316, 480, 20,
+ 23, -89, -551,
+ 353, 1051, 1789,
+ -544, -757, -1364,
+ 298, -25, 436,
+ -100, -392, -519,
+ 467, 754, 1078,
+ -210, -398, -1078,
+ 620, 658, 630,
+ 33, 147, -178,
+ 921, 1687, 1921,
+ -325, -528, -1978,
+ 2, -285, 910,
+ -371, -490, -230,
+ 0, 597, 2010,
+ -496, -395, -834,
+ 37, 945, 245,
+ 181, -160, -144,
+ 1481, 1373, 1357,
+ -355, -601, -1270,
+ 298, 322, 672,
+ -193, -336, 77,
+ 1089, 1533, 922,
+ 177, -39, -1125,
+ 996, 781, 536,
+ 456, 366, -432,
+ 1415, 2440, 2279,
+ -466, -758, -2325,
+ -303, -509, 387,
+ -727, -557, 66,
+ -145, 643, 1248,
+ -544, -676, -916,
+ -225, 862, 588,
+ -152, 40, -533,
+ 423, 1423, 1558,
+ -572, -843, -1145,
+ -128, 85, 461,
+ -238, -257, -584,
+ 605, 748, 861,
+ 24, -202, -1409,
+ 797, 487, 303,
+ -181, 364, -182,
+ 616, 1378, 2942,
+ -494, -852, -1441,
+ -292, 61, 812,
+ -84, -723, -182,
+ 555, 532, 1506,
+ -365, -493, -1057,
+ 822, 588, 11,
+ -14, -18, -230,
+ 1001, 1401, 1451,
+ -474, -569, -1292,
+ 302, 62, 1062,
+ -70, -376, -222,
+ 982, 974, 1149,
+ -196, -234, -795,
+ 479, 1098, 499,
+ 362, 58, 70,
+ 1147, 2069, 2857,
+ -487, -878, -1824,
+ 73, -288, 348,
+ -358, -500, -508,
+ 199, 721, 1242,
+ -78, -697, -795,
+ 361, 536, 196,
+ 374, 110, -735,
+ 847, 1051, 1896,
+ -366, -713, -1182,
+ 315, 320, 429,
+ 72, -215, -450,
+ 759, 886, 1363,
+ -30, -428, -834,
+ 861, 627, 796,
+ 118, 468, -279,
+ 1355, 1883, 1893,
+ -188, -642, -1612,
+ 63, -175, 1198,
+ -418, -211, 51,
+ 414, 587, 2601,
+ -234, -557, -858,
+ 424, 889, 222,
+ 136, -101, 83,
+ 1413, 2278, 1383,
+ -84, -445, -1389,
+ 414, 313, 1045,
+ 29, -343, 65,
+ 1552, 1647, 980,
+ 183, -91, -829,
+ 1273, 1413, 360,
+ 553, 272, -107,
+ 1587, 3149, 2603
+};
+
+
+
diff --git a/media/codecs/amrnb/common/src/q_plsf_5.cpp b/media/codecs/amrnb/common/src/q_plsf_5.cpp
new file mode 100644
index 0000000..2f9e40e
--- /dev/null
+++ b/media/codecs/amrnb/common/src/q_plsf_5.cpp
@@ -0,0 +1,691 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/q_plsf_5.c
+ Funtions:
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed code in the PV standard template format.
+ Updated to accept new parameter, Flag *pOverflow.
+
+ Description:
+ Eliminated unused include files.
+ For Vq_subvec()
+ 1. Eliminated math operations that unnecessary checked for
+ saturation (number are bounded to 2^12)
+ 2. Eliminated access to (slow) memory by using axiliar variables
+ 3. Because this routine is looking for the minimum distance,
+ introduced 3 check conditions inside the loop, so when the
+ partial distance is bigger than the minimun distance, the
+ loop is not completed and process continue with next iteration
+ For Vq_subvec_s()
+ 1. Eliminated math operations that unnecessary checked for
+ saturation (number are bounded to 2^12)
+ 2. Combined increasing and decreasing loops to avoid double
+ accesses to the same table element
+ 3. Eliminated access to (slow) memory by using axiliar variables
+ 4. Because this routine is looking for the minimum distance,
+ introduced 2 check conditions inside the loop, so when the
+ partial distance is bigger than the minimun distance, the
+ loop is not completed and process continue with next iteration
+ For Q_plsf_5()
+ 1. Eliminated math operations that unnecessary checked for
+ saturation (number are bounded to 2^12)
+ 2. Replaced array addressing by pointers
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "q_plsf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "lsp_lsf.h"
+#include "reorder.h"
+#include "lsfwt.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ /* Codebooks of LSF prediction residual */
+ extern const Word16 mean_lsf_5[];
+
+ extern const Word16 dico1_lsf_5[];
+ extern const Word16 dico2_lsf_5[];
+ extern const Word16 dico3_lsf_5[];
+ extern const Word16 dico4_lsf_5[];
+ extern const Word16 dico5_lsf_5[];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Vq_subvec
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf_r1 -- array of type Word16 -- 1st LSF residual vector, Q15
+ lsf_r2 -- array of type Word16 -- 2nd LSF residual vector, Q15
+ dico -- pointer to const Word16 -- quantization codebook, Q15
+ wf1 -- array of type Word16 -- 1st LSF weighting factors, Q13
+ wf2 -- array of type Word16 -- 2nd LSF weighting factors, Q13
+ dico_size -- Word16 -- size of quantization codebook, Q0
+ Outputs:
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ Word16 -- quantization index, Q0
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the quantization of a 4-dimensional subvector.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+/* Quantization of a 4 dimensional subvector */
+
+static Word16 Vq_subvec( /* o : quantization index, Q0 */
+ Word16 *lsf_r1, /* i : 1st LSF residual vector, Q15 */
+ Word16 *lsf_r2, /* i : 2nd LSF residual vector, Q15 */
+ const Word16 *dico, /* i : quantization codebook, Q15 */
+ Word16 *wf1, /* i : 1st LSF weighting factors Q13 */
+ Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */
+ Word16 dico_size, /* i : size of quantization codebook, Q0 */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 index = 0; /* initialization only needed to keep gcc silent */
+ Word16 i;
+ Word16 temp;
+ const Word16 *p_dico;
+ Word32 dist_min;
+ Word32 dist;
+ Word16 wf1_0;
+ Word16 wf1_1;
+ Word16 wf2_0;
+ Word16 wf2_1;
+ Word32 aux1;
+ Word32 aux2;
+ Word32 aux3;
+ Word32 aux4;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ dist_min = MAX_32;
+ p_dico = dico;
+
+ wf1_0 = wf1[0];
+ wf1_1 = wf1[1];
+ wf2_0 = wf2[0];
+ wf2_1 = wf2[1];
+
+ aux1 = ((Word32) lsf_r1[0] * wf1_0);
+ aux2 = ((Word32) lsf_r1[1] * wf1_1);
+ aux3 = ((Word32) lsf_r2[0] * wf2_0);
+ aux4 = ((Word32) lsf_r2[1] * wf2_1);
+
+ for (i = 0; i < dico_size; i++)
+ {
+ temp = (aux1 - ((Word32)wf1_0 * *(p_dico++))) >> 15;
+ dist = ((Word32)temp * temp);
+
+ if (dist >= dist_min)
+ {
+ p_dico += 3;
+ continue;
+ }
+
+ temp = (aux2 - ((Word32)wf1_1 * *(p_dico++))) >> 15;
+ dist += ((Word32)temp * temp);
+
+ if (dist >= dist_min)
+ {
+ p_dico += 2;
+ continue;
+ }
+
+ temp = (aux3 - ((Word32)wf2_0 * *(p_dico++))) >> 15;
+ dist += ((Word32)temp * temp);
+
+ if (dist >= dist_min)
+ {
+ p_dico += 1;
+ continue;
+ }
+
+ temp = (aux4 - ((Word32)wf2_1 * *(p_dico++))) >> 15;
+ dist += ((Word32)temp * temp);
+
+
+ if (dist < dist_min)
+ {
+ dist_min = dist;
+ index = i;
+ }
+ }
+
+
+
+ /* Reading the selected vector */
+
+ p_dico = &dico[ index<<2];
+ lsf_r1[0] = *p_dico++;
+ lsf_r1[1] = *p_dico++;
+ lsf_r2[0] = *p_dico++;
+ lsf_r2[1] = *p_dico;
+
+ return index;
+
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Vq_subvec_s
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf_r1 -- array of type Word16 -- 1st LSF residual vector, Q15
+ lsf_r2 -- array of type Word16 -- 2nd LSF residual vector, Q15
+ dico -- pointer to const Word16 -- quantization codebook, Q15
+ wf1 -- array of type Word16 -- 1st LSF weighting factors, Q13
+ wf2 -- array of type Word16 -- 2nd LSF weighting factors, Q13
+ dico_size -- Word16 -- size of quantization codebook, Q0
+
+ Outputs:
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ Word16 -- quantization index, Q0
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the quantization of a 4-dimensional subvector.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+/* Quantization of a 4 dimensional subvector with a signed codebook */
+
+static Word16 Vq_subvec_s( /* o : quantization index Q0 */
+ Word16 *lsf_r1, /* i : 1st LSF residual vector Q15 */
+ Word16 *lsf_r2, /* i : and LSF residual vector Q15 */
+ const Word16 *dico, /* i : quantization codebook Q15 */
+ Word16 *wf1, /* i : 1st LSF weighting factors Q13 */
+ Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */
+ Word16 dico_size, /* i : size of quantization codebook Q0 */
+ Flag *pOverflow) /* o : overflow indicator */
+{
+ Word16 index = 0; /* initialization only needed to keep gcc silent */
+ Word16 sign = 0; /* initialization only needed to keep gcc silent */
+ Word16 i;
+ Word16 temp;
+ Word16 temp1;
+ Word16 temp2;
+ const Word16 *p_dico;
+ Word32 dist_min;
+ Word32 dist1;
+ Word32 dist2;
+
+ Word16 lsf_r1_0;
+ Word16 lsf_r1_1;
+ Word16 lsf_r2_0;
+ Word16 lsf_r2_1;
+
+ Word16 wf1_0;
+ Word16 wf1_1;
+ Word16 wf2_0;
+ Word16 wf2_1;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ dist_min = MAX_32;
+ p_dico = dico;
+
+
+ lsf_r1_0 = lsf_r1[0];
+ lsf_r1_1 = lsf_r1[1];
+ lsf_r2_0 = lsf_r2[0];
+ lsf_r2_1 = lsf_r2[1];
+
+ wf1_0 = wf1[0];
+ wf1_1 = wf1[1];
+ wf2_0 = wf2[0];
+ wf2_1 = wf2[1];
+
+ for (i = 0; i < dico_size; i++)
+ {
+ /* test positive */
+ temp = *p_dico++;
+ temp1 = lsf_r1_0 - temp;
+ temp2 = lsf_r1_0 + temp;
+ temp1 = ((Word32)wf1_0 * temp1) >> 15;
+ temp2 = ((Word32)wf1_0 * temp2) >> 15;
+ dist1 = ((Word32)temp1 * temp1);
+ dist2 = ((Word32)temp2 * temp2);
+
+ temp = *p_dico++;
+ temp1 = lsf_r1_1 - temp;
+ temp2 = lsf_r1_1 + temp;
+ temp1 = ((Word32)wf1_1 * temp1) >> 15;
+ temp2 = ((Word32)wf1_1 * temp2) >> 15;
+ dist1 += ((Word32)temp1 * temp1);
+ dist2 += ((Word32)temp2 * temp2);
+
+ if ((dist1 >= dist_min) && (dist2 >= dist_min))
+ {
+ p_dico += 2;
+ continue;
+ }
+
+ temp = *p_dico++;
+ temp1 = lsf_r2_0 - temp;
+ temp2 = lsf_r2_0 + temp;
+ temp1 = ((Word32)wf2_0 * temp1) >> 15;
+ temp2 = ((Word32)wf2_0 * temp2) >> 15;
+ dist1 += ((Word32)temp1 * temp1);
+ dist2 += ((Word32)temp2 * temp2);
+
+ temp = *p_dico++;
+ temp1 = lsf_r2_1 - temp;
+ temp2 = lsf_r2_1 + temp;
+ temp1 = ((Word32)wf2_1 * temp1) >> 15;
+ temp2 = ((Word32)wf2_1 * temp2) >> 15;
+ dist1 += ((Word32)temp1 * temp1);
+ dist2 += ((Word32)temp2 * temp2);
+
+ if (dist1 < dist_min)
+ {
+ dist_min = dist1;
+ index = i;
+ sign = 0;
+ }
+
+ /* test negative */
+
+ if (dist2 < dist_min)
+ {
+ dist_min = dist2;
+ index = i;
+ sign = 1;
+ }
+ }
+
+ /* Reading the selected vector */
+
+ p_dico = &dico[index<<2];
+ index <<= 1;
+ if (sign)
+ {
+ lsf_r1[0] = - (*p_dico++);
+ lsf_r1[1] = - (*p_dico++);
+ lsf_r2[0] = - (*p_dico++);
+ lsf_r2[1] = - (*p_dico);
+ index += 1;
+ }
+ else
+ {
+ lsf_r1[0] = *p_dico++;
+ lsf_r1[1] = *p_dico++;
+ lsf_r2[0] = *p_dico++;
+ lsf_r2[1] = *p_dico;
+ }
+
+ return index;
+
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Q_plsf_5
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+ Inputs:
+ st -- pointer to Q_plsfState -- state information
+ lsp1 -- array of type Word16 -- 1st LSP vector, Q15
+ lsp2 -- array of type Word16 -- 2nd LSP vector, Q15
+
+ Outputs:
+ lps1_q -- array of type Word16 -- quantized 1st LSP vector, Q15
+ lps2_q -- array of type Word16 -- quantized 2nd LSP vector, Q15
+ indices -- array of type Word16 -- quantization indices of 5 matrics, Q0
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ mean_lsf_5[];
+
+ dico1_lsf_5[];
+ dico2_lsf_5[];
+ dico3_lsf_5[];
+ dico4_lsf_5[];
+ dico5_lsf_5[];
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Quantization of 2 sets of LSF parameters using 1st order MA
+ prediction and split by 5 matrix quantization (split-MQ)
+
+ DESCRIPTION:
+
+ p[i] = pred_factor*past_rq[i]; i=0,...,m-1
+ r1[i]= lsf1[i] - p[i]; i=0,...,m-1
+ r2[i]= lsf2[i] - p[i]; i=0,...,m-1
+ where:
+ lsf1[i] 1st mean-removed LSF vector.
+ lsf2[i] 2nd mean-removed LSF vector.
+ r1[i] 1st residual prediction vector.
+ r2[i] 2nd residual prediction vector.
+ past_r2q[i] Past quantized residual (2nd vector).
+
+ The residual vectors r1[i] and r2[i] are jointly quantized using
+ split-MQ with 5 codebooks. Each 4th dimension submatrix contains 2
+ elements from each residual vector. The 5 submatrices are as follows:
+ {r1[0], r1[1], r2[0], r2[1]}; {r1[2], r1[3], r2[2], r2[3]};
+ {r1[4], r1[5], r2[4], r2[5]}; {r1[6], r1[7], r2[6], r2[7]};
+ {r1[8], r1[9], r2[8], r2[9]}
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Q_plsf_5(
+ Q_plsfState *st,
+ Word16 *lsp1, /* i : 1st LSP vector, Q15 */
+ Word16 *lsp2, /* i : 2nd LSP vector, Q15 */
+ Word16 *lsp1_q, /* o : quantized 1st LSP vector, Q15 */
+ Word16 *lsp2_q, /* o : quantized 2nd LSP vector, Q15 */
+ Word16 *indice, /* o : quantization indices of 5 matrices, Q0 */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 i;
+ Word16 lsf1[M];
+ Word16 lsf2[M];
+ Word16 wf1[M];
+ Word16 wf2[M];
+ Word16 lsf_p[M];
+ Word16 lsf_r1[M];
+ Word16 lsf_r2[M];
+ Word16 lsf1_q[M];
+ Word16 lsf2_q[M];
+
+ Word16 *p_lsf_p;
+ Word16 *p_lsf1;
+ Word16 *p_lsf2;
+ Word16 *p_lsf_r1;
+ Word16 *p_lsf_r2;
+
+ /* convert LSFs to normalize frequency domain 0..16384 */
+
+ Lsp_lsf(lsp1, lsf1, M, pOverflow);
+ Lsp_lsf(lsp2, lsf2, M, pOverflow);
+
+ /* Compute LSF weighting factors (Q13) */
+
+ Lsf_wt(lsf1, wf1, pOverflow);
+ Lsf_wt(lsf2, wf2, pOverflow);
+
+ /* Compute predicted LSF and prediction error */
+
+ p_lsf_p = &lsf_p[0];
+ p_lsf1 = &lsf1[0];
+ p_lsf2 = &lsf2[0];
+ p_lsf_r1 = &lsf_r1[0];
+ p_lsf_r2 = &lsf_r2[0];
+
+ for (i = 0; i < M; i++)
+ {
+ *(p_lsf_p) = mean_lsf_5[i] +
+ (((Word32)st->past_rq[i] * LSP_PRED_FAC_MR122) >> 15);
+
+ *(p_lsf_r1++) = *(p_lsf1++) - *(p_lsf_p);
+ *(p_lsf_r2++) = *(p_lsf2++) - *(p_lsf_p++);
+ }
+
+ /*---- Split-MQ of prediction error ----*/
+
+ indice[0] = Vq_subvec(&lsf_r1[0], &lsf_r2[0], dico1_lsf_5,
+ &wf1[0], &wf2[0], DICO1_5_SIZE, pOverflow);
+
+ indice[1] = Vq_subvec(&lsf_r1[2], &lsf_r2[2], dico2_lsf_5,
+ &wf1[2], &wf2[2], DICO2_5_SIZE, pOverflow);
+
+ indice[2] = Vq_subvec_s(&lsf_r1[4], &lsf_r2[4], dico3_lsf_5,
+ &wf1[4], &wf2[4], DICO3_5_SIZE, pOverflow);
+
+ indice[3] = Vq_subvec(&lsf_r1[6], &lsf_r2[6], dico4_lsf_5,
+ &wf1[6], &wf2[6], DICO4_5_SIZE, pOverflow);
+
+ indice[4] = Vq_subvec(&lsf_r1[8], &lsf_r2[8], dico5_lsf_5,
+ &wf1[8], &wf2[8], DICO5_5_SIZE, pOverflow);
+
+ /* Compute quantized LSFs and update the past quantized residual */
+
+ p_lsf_r1 = &lsf_r1[0];
+ p_lsf_r2 = &lsf_r2[0];
+ p_lsf_p = &lsf_p[0];
+ p_lsf1 = &lsf1_q[0];
+ p_lsf2 = &lsf2_q[0];
+
+
+ for (i = 0; i < M; i++)
+ {
+ *(p_lsf1++) = *(p_lsf_r1++) + *(p_lsf_p);
+ *(p_lsf2++) = *(p_lsf_r2) + *(p_lsf_p++);
+ st->past_rq[i] = *(p_lsf_r2++);
+ }
+
+ /* verification that LSFs has minimum distance of LSF_GAP */
+
+ Reorder_lsf(lsf1_q, LSF_GAP, M, pOverflow);
+ Reorder_lsf(lsf2_q, LSF_GAP, M, pOverflow);
+
+ /* convert LSFs to the cosine domain */
+
+ Lsf_lsp(lsf1_q, lsp1_q, M, pOverflow);
+ Lsf_lsp(lsf2_q, lsp2_q, M, pOverflow);
+}
+
diff --git a/media/codecs/amrnb/common/src/q_plsf_5_tbl.cpp b/media/codecs/amrnb/common/src/q_plsf_5_tbl.cpp
new file mode 100644
index 0000000..caa81cb
--- /dev/null
+++ b/media/codecs/amrnb/common/src/q_plsf_5_tbl.cpp
@@ -0,0 +1,1164 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/q_plsf_5_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created this file from the reference, q_plsf_5_tbl.tab
+
+ Description: Changed #defines of DICO_SIZE to DICO_5_SIZE, to avoid name
+ conflicts.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "q_plsf_5_tbl.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+#define NB_QUA_PITCH 16
+#define NB_QUA_CODE 32
+
+
+#define DICO1_5_SIZE 128
+#define DICO2_5_SIZE 256
+#define DICO3_5_SIZE 256
+#define DICO4_5_SIZE 256
+#define DICO5_5_SIZE 64
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+ /* LSF means ->normalize frequency domain */
+
+ const Word16 mean_lsf_5[10] =
+ {
+ 1384,
+ 2077,
+ 3420,
+ 5108,
+ 6742,
+ 8122,
+ 9863,
+ 11092,
+ 12714,
+ 13701
+ };
+
+ const Word16 dico1_lsf_5[DICO1_5_SIZE * 4] =
+ {
+ -451, -1065, -529, -1305,
+ -450, -756, -497, -863,
+ -384, -619, -413, -669,
+ -317, -538, -331, -556,
+ -414, -508, -424, -378,
+ -274, -324, -434, -614,
+ -226, -500, -232, -514,
+ -263, -377, -298, -410,
+ -151, -710, -174, -818,
+ -149, -412, -156, -429,
+ -288, -462, -186, -203,
+ -170, -302, -191, -321,
+ -131, -147, -297, -395,
+ -228, -214, -245, -192,
+ -67, -316, -71, -327,
+ -104, -205, -94, -183,
+ -143, -38, -193, -95,
+ 16, -76, -124, -248,
+ 23, -237, 24, -244,
+ 18, -136, 44, -111,
+ -33, -24, -25, 0,
+ 149, 19, 23, -143,
+ 158, -169, 174, -181,
+ 133, -55, 165, -26,
+ 111, 84, 98, 75,
+ 87, 183, -115, -11,
+ -8, 130, 11, 170,
+ 254, 77, 205, 17,
+ 183, 112, 262, 194,
+ 202, 287, 95, 189,
+ -42, -105, 234, 179,
+ 39, 186, 163, 345,
+ 332, 199, 299, 161,
+ -54, 285, -78, 281,
+ -133, 141, -182, 111,
+ 249, 341, 271, 364,
+ 93, 403, 75, 391,
+ 92, 510, -138, 220,
+ -185, -29, -34, 361,
+ -115, 320, 3, 554,
+ 99, 286, 218, 591,
+ -245, 406, -268, 453,
+ 0, 580, 25, 606,
+ 275, 532, 148, 450,
+ -73, 739, -285, 518,
+ -288, 94, -203, 674,
+ -140, -74, 205, 714,
+ -114, 299, 176, 923,
+ 182, 557, 240, 705,
+ -16, 513, 485, 593,
+ 293, 384, 451, 617,
+ -38, 50, 563, 529,
+ 303, 209, 459, 363,
+ 433, 452, 450, 454,
+ 367, 606, 477, 741,
+ 432, 353, 368, 267,
+ 361, 716, 273, 583,
+ 453, 166, 510, 172,
+ 201, 629, 274, 191,
+ 568, 639, 302, 298,
+ 634, 387, 643, 350,
+ 587, 560, 612, 565,
+ 600, 788, 487, 672,
+ 512, 1015, 321, 333,
+ 357, 854, -125, 413,
+ 474, 712, 17, -151,
+ 564, 285, 270, -241,
+ 971, 889, 489, 220,
+ 510, 896, 549, 924,
+ 327, 825, 290, 911,
+ 540, 1108, 158, 805,
+ 199, 957, 511, 730,
+ 100, 874, 13, 791,
+ 435, 632, 676, 972,
+ 249, 900, 467, 1218,
+ 781, 1074, 585, 785,
+ -23, 669, 267, 1043,
+ 619, 1084, 615, 1145,
+ 622, 905, 916, 1049,
+ 80, 331, 584, 1075,
+ 89, 639, 988, 961,
+ 770, 720, 798, 699,
+ 492, 447, 899, 627,
+ 271, 1188, 725, 1333,
+ 87, 603, 832, 1603,
+ 616, 1127, 890, 1505,
+ 1000, 1156, 866, 1009,
+ 995, 827, 1149, 858,
+ 817, 1450, 773, 1320,
+ 500, 1389, 312, 1153,
+ -20, 1084, 64, 1283,
+ 2, 1172, 399, 1869,
+ 514, 1706, 502, 1636,
+ 886, 1522, 416, 600,
+ 1131, 1350, 1275, 1390,
+ 889, 1795, 914, 1766,
+ 227, 1183, 1250, 1826,
+ 505, 1854, 919, 2353,
+ -199, 431, 152, 1735,
+ -213, -28, 392, 1334,
+ -153, -52, 978, 1151,
+ -323, -400, 813, 1703,
+ -136, 84, 1449, 2015,
+ -331, -143, -137, 1192,
+ -256, 534, -157, 1031,
+ -307, -439, 542, 731,
+ -329, -420, -97, 616,
+ -362, -168, -322, 366,
+ -247, -110, -211, 89,
+ -196, -309, 20, 59,
+ -364, -463, -286, 89,
+ -336, 175, -432, 141,
+ -379, -190, -434, -196,
+ -79, 150, -278, -227,
+ -280, 166, -555, -422,
+ -155, 541, -366, 54,
+ -29, -83, -301, -774,
+ 186, 628, -397, -264,
+ 242, 293, -197, -585,
+ 124, 410, 53, -133,
+ 10, 340, -570, -1065,
+ 65, -446, 68, -493,
+ 383, 937, -357, -711,
+ -359, -250, -677, -1068,
+ 292, -26, 363, 6,
+ 607, 1313, -127, -10,
+ 1513, 1886, 713, 972,
+ 1469, 2181, 1443, 2016
+ };
+
+ const Word16 dico2_lsf_5[DICO2_5_SIZE * 4] =
+ {
+ -1631, -1600, -1796, -2290,
+ -1027, -1770, -1100, -2025,
+ -1277, -1388, -1367, -1534,
+ -947, -1461, -972, -1524,
+ -999, -1222, -1020, -1172,
+ -815, -987, -992, -1371,
+ -1216, -1006, -1289, -1094,
+ -744, -1268, -755, -1293,
+ -862, -923, -905, -984,
+ -678, -1051, -685, -1050,
+ -1087, -985, -1062, -679,
+ -989, -641, -1127, -976,
+ -762, -654, -890, -806,
+ -833, -1091, -706, -629,
+ -621, -806, -640, -812,
+ -775, -634, -779, -543,
+ -996, -565, -1075, -580,
+ -546, -611, -572, -619,
+ -760, -290, -879, -526,
+ -823, -462, -795, -253,
+ -553, -415, -589, -439,
+ -533, -340, -692, -935,
+ -505, -772, -702, -1131,
+ -263, -306, -971, -483,
+ -445, -74, -555, -548,
+ -614, -129, -693, -234,
+ -396, -246, -475, -250,
+ -265, -404, -376, -514,
+ -417, -510, -300, -313,
+ -334, -664, -463, -814,
+ -386, -704, -337, -615,
+ -234, -201, -233, -239,
+ -167, -567, -203, -619,
+ -147, -415, -115, -352,
+ -166, -750, -171, -761,
+ -270, -879, -264, -903,
+ -367, -744, 43, -475,
+ 14, -653, 43, -670,
+ 11, -448, -59, -521,
+ -126, -119, -155, -613,
+ -42, -863, -27, -931,
+ 136, -483, 183, -468,
+ 55, -298, 55, -304,
+ 313, -609, 313, -720,
+ 322, -167, 100, -541,
+ -3, -119, -111, -187,
+ 233, -236, 260, -234,
+ 26, -165, 134, -45,
+ -40, -549, 360, -203,
+ 378, -388, 450, -383,
+ 275, 20, 182, -103,
+ 246, -111, 431, 37,
+ 462, -146, 487, -157,
+ -284, -59, 503, -184,
+ 24, 53, -3, 54,
+ 122, 259, 333, 66,
+ 484, 104, 436, 68,
+ 195, 116, 190, 206,
+ 269, -9, 482, 352,
+ 382, 285, 399, 277,
+ 452, 256, 69, 186,
+ 13, 297, -13, 259,
+ -95, 30, 56, 394,
+ 196, 425, 205, 456,
+ 281, 577, 15, 191,
+ 375, 290, 407, 576,
+ -56, 227, 544, 405,
+ 0, 549, -92, 528,
+ -229, 351, -245, 338,
+ -362, 435, 167, 527,
+ -75, 302, 91, 824,
+ 129, 599, 496, 679,
+ 186, 749, 153, 737,
+ -281, 600, -348, 615,
+ -236, 769, 41, 881,
+ 38, 890, -220, 841,
+ -357, 883, -393, 903,
+ -634, 474, -444, 850,
+ -175, 678, -493, 242,
+ -519, 785, -714, 582,
+ -541, 366, -543, 434,
+ -597, 500, -765, 222,
+ -702, 917, -743, 962,
+ -869, 501, -899, 548,
+ -379, 200, -435, 157,
+ -819, 214, -861, 157,
+ -614, 40, -632, 94,
+ -883, -54, -741, 516,
+ -501, 298, -614, -171,
+ -870, -161, -865, -23,
+ -818, 93, -1015, -267,
+ -662, -359, -549, 2,
+ -442, -121, -377, 0,
+ -227, 33, -414, -126,
+ -129, 212, -934, 34,
+ -1082, -282, -1119, -268,
+ -710, -825, -420, -191,
+ -1076, -928, -917, -93,
+ -628, -358, 97, 7,
+ -206, -393, -101, 24,
+ -203, 38, -168, 83,
+ -599, -423, -279, 426,
+ -700, 118, -75, 206,
+ -981, -673, -680, 417,
+ -367, 37, -279, 474,
+ -129, -318, 319, 296,
+ -626, -39, 343, 602,
+ -696, -39, -303, 940,
+ 104, 233, -380, 137,
+ -36, 269, -75, -214,
+ 120, 43, -529, -477,
+ 459, 164, -202, -229,
+ -49, -167, 609, 792,
+ 98, -220, 915, 148,
+ 293, 283, 869, 91,
+ 575, 394, 326, -78,
+ 717, 67, 365, -323,
+ 616, -36, 731, 27,
+ 619, 238, 632, 273,
+ 448, 99, 801, 476,
+ 869, 273, 685, 64,
+ 789, 72, 1021, 217,
+ 793, 459, 734, 360,
+ 646, 480, 360, 322,
+ 429, 464, 638, 430,
+ 756, 363, 1000, 404,
+ 683, 528, 602, 615,
+ 655, 413, 946, 687,
+ 937, 602, 904, 604,
+ 555, 737, 786, 662,
+ 467, 654, 362, 589,
+ 929, 710, 498, 478,
+ 415, 420, 693, 883,
+ 813, 683, 781, 925,
+ 913, 939, 726, 732,
+ 491, 853, 531, 948,
+ 734, 963, 315, 808,
+ 761, 755, 1144, 760,
+ 655, 1076, 826, 1057,
+ 1091, 838, 1003, 808,
+ 1047, 1133, 659, 1101,
+ 992, 1050, 1074, 1075,
+ 971, 694, 1226, 1054,
+ 571, 841, 884, 1404,
+ 1379, 1096, 1080, 861,
+ 1231, 735, 1284, 760,
+ 1272, 991, 1367, 1053,
+ 1257, 700, 1050, 534,
+ 988, 453, 1264, 599,
+ 1140, 679, 1621, 815,
+ 1384, 521, 1317, 393,
+ 1564, 805, 1448, 686,
+ 1068, 648, 875, 307,
+ 1083, 361, 1047, 317,
+ 1417, 964, 675, 571,
+ 1152, 79, 1114, -47,
+ 1530, 311, 1721, 314,
+ 1166, 689, 514, -94,
+ 349, 282, 1412, 328,
+ 1025, 487, -65, 57,
+ 805, 970, 36, 62,
+ 769, -263, 791, -346,
+ 637, 699, -137, 620,
+ 534, 541, -735, 194,
+ 711, 300, -268, -863,
+ 926, 769, -708, -428,
+ 506, 174, -892, -630,
+ 435, 547, -1435, -258,
+ 621, 471, -1018, -1368,
+ -393, 521, -920, -686,
+ -25, 20, -982, -1156,
+ 340, 9, -1558, -1135,
+ -352, 48, -1579, -402,
+ -887, 6, -1156, -888,
+ -548, -352, -1643, -1168,
+ -159, 610, -2024, -963,
+ -225, 193, -1656, -1960,
+ -245, -493, -964, -1680,
+ -936, -635, -1299, -1744,
+ -1388, -604, -1540, -835,
+ -1397, -135, -1588, -290,
+ -1670, -712, -2011, -1632,
+ -1663, -27, -2258, -811,
+ -1157, 184, -1265, 189,
+ -1367, 586, -2011, 201,
+ -790, 712, -1210, 3,
+ -1033, 808, -1251, 830,
+ -111, 635, -1636, 447,
+ -463, -949, -445, -928,
+ -504, -1162, -501, -1211,
+ 144, -351, -372, -1052,
+ -283, -1059, -279, -1123,
+ -575, -1438, -587, -1614,
+ -935, -984, 229, 690,
+ -921, -719, -403, 1362,
+ -685, -465, 874, 397,
+ -509, -46, 317, 1334,
+ -485, 456, 813, 439,
+ -411, 339, 898, 1067,
+ -425, 46, 1441, 497,
+ -909, -800, 1465, 1046,
+ -254, -321, 1430, 1165,
+ 68, 350, 1034, 666,
+ 370, 11, 1311, 790,
+ 143, 232, 1041, 1562,
+ -114, 663, 1616, 1078,
+ 454, 579, 1275, 1040,
+ -76, 909, 752, 1067,
+ 153, 512, 348, 1214,
+ 614, 385, 1843, 808,
+ 269, 1034, 203, 1086,
+ 652, 1017, 1783, 1130,
+ 429, 1327, 387, 1384,
+ -49, 1183, -72, 1215,
+ -416, 1001, 544, 1749,
+ -352, 1223, -502, 1199,
+ -589, 569, -227, 1630,
+ -142, 1578, -230, 1715,
+ -714, 1288, -838, 1398,
+ 1131, 1357, -208, 1232,
+ 437, 965, -929, 818,
+ 811, 1410, 859, 1507,
+ 164, 1212, 1387, 1793,
+ 484, 1874, 456, 2063,
+ 996, 1170, 1326, 1402,
+ 1316, 1360, 1135, 1262,
+ 1234, 1618, 1361, 1768,
+ 1421, 1227, 1584, 1347,
+ 854, 672, 1685, 1566,
+ 1139, 1270, 2016, 1825,
+ 1773, 1581, 1532, 1460,
+ 1487, 946, 1659, 1021,
+ 1744, 1212, 1392, 977,
+ 1772, 1161, 1826, 1164,
+ 1718, 1429, 1973, 1591,
+ 1185, 864, 2132, 1061,
+ 1799, 814, 1838, 757,
+ 2104, 1315, 2054, 1258,
+ 2113, 915, 2331, 930,
+ 1467, 1147, 2590, 1439,
+ 2245, 1744, 2090, 1620,
+ 2358, 1454, 2666, 1506,
+ 1876, 1837, 2070, 1975,
+ 1739, 1577, 682, 1289,
+ 1584, 2045, 1454, 2098,
+ 2498, 2004, 2711, 2066,
+ 726, 1588, 2756, 2336,
+ 228, 847, 2456, 1659,
+ 36, 301, 1942, 1957,
+ -446, -96, 2154, 1396,
+ 1533, 1101, 14, 608,
+ -923, -732, 1383, 1982,
+ 1345, 952, -680, 321,
+ 1281, 1268, -1594, 365,
+ 941, 946, -1737, -822,
+ 2374, 2787, 1821, 2788
+ };
+
+ const Word16 dico3_lsf_5[DICO3_5_SIZE * 4] =
+ {
+ -1812, -2275, -1879, -2537,
+ -1640, -1848, -1695, -2004,
+ -1220, -1912, -1221, -2106,
+ -1559, -1588, -1573, -1556,
+ -1195, -1615, -1224, -1727,
+ -1359, -1151, -1616, -1948,
+ -1274, -1391, -1305, -1403,
+ -1607, -1179, -1676, -1311,
+ -1443, -1478, -1367, -898,
+ -1256, -1059, -1331, -1134,
+ -982, -1133, -1149, -1504,
+ -1080, -1308, -1020, -1183,
+ -980, -1486, -967, -1495,
+ -988, -922, -1047, -1077,
+ -838, -1179, -858, -1222,
+ -1131, -1041, -1064, -767,
+ -872, -1157, -701, -880,
+ -706, -906, -774, -1016,
+ -578, -1080, -801, -1478,
+ -591, -1111, -592, -1146,
+ -713, -1388, -640, -1376,
+ -597, -1059, -416, -903,
+ -686, -832, -661, -708,
+ -444, -868, -490, -921,
+ -374, -776, -619, -1170,
+ -585, -549, -769, -795,
+ -435, -659, -530, -741,
+ -498, -837, -357, -597,
+ -279, -871, -243, -887,
+ -282, -665, -280, -667,
+ -165, -560, -394, -903,
+ -362, -410, -448, -583,
+ -409, -574, -313, -357,
+ -637, -548, -570, -436,
+ -896, -504, -382, -757,
+ -58, -481, -165, -618,
+ -191, -374, -234, -382,
+ -222, -683, -25, -480,
+ -418, -359, -730, -353,
+ -324, -157, -432, -322,
+ -394, -303, -284, -104,
+ -601, -289, -556, -196,
+ -588, -150, -659, -608,
+ -473, -24, -68, -448,
+ -474, -8, -506, -45,
+ -748, -184, -844, -252,
+ -901, -91, -584, -97,
+ -652, 138, -764, -131,
+ -678, -12, -670, 165,
+ -259, -3, -840, -107,
+ -909, 37, -992, 44,
+ -854, -415, -839, 13,
+ -1001, -271, -1026, -309,
+ -798, -478, -832, -488,
+ -943, 168, -1112, -387,
+ -1185, -101, -1183, -40,
+ -941, -316, -1030, -770,
+ -1044, -625, -1081, -538,
+ -1224, -299, -1312, -436,
+ -1197, -663, -1167, -161,
+ -1216, -690, -1237, -831,
+ -1432, -720, -1403, -493,
+ -898, -740, -922, -801,
+ -1102, -402, -1579, -964,
+ -1061, -638, -1269, -1438,
+ -1499, -934, -1502, -895,
+ -1598, -564, -1723, -717,
+ -606, -597, -1166, -1085,
+ -1369, -468, -1946, -1493,
+ -1838, -953, -1932, -931,
+ -1499, -188, -1635, -421,
+ -1457, -338, -1448, -22,
+ -1942, -422, -2006, -249,
+ -496, -114, -1910, -755,
+ -1289, 174, -1451, -109,
+ -482, -257, -1221, -508,
+ -1617, 151, -1694, 208,
+ -654, 107, -1651, 29,
+ -1141, 279, -1215, 306,
+ -1228, -506, -730, -175,
+ -1236, -101, -969, 551,
+ -870, 278, -823, 315,
+ -563, 376, -1051, 228,
+ -507, 280, -599, 281,
+ -758, 253, -305, 379,
+ -755, -134, -611, 660,
+ -824, 536, -817, 646,
+ -413, 49, -341, 177,
+ -453, 526, -482, 589,
+ -71, 339, -657, 264,
+ -244, 295, -237, 315,
+ -387, 569, -506, -9,
+ -377, 14, -160, 661,
+ -216, 40, -308, -46,
+ 95, 214, -242, 167,
+ -86, 192, -56, 27,
+ -76, 31, 36, 309,
+ -106, -182, -113, 74,
+ -441, -22, 23, 139,
+ 81, -11, 44, 15,
+ -87, -137, -118, -207,
+ -158, -58, 272, -92,
+ -156, -441, 8, -136,
+ 128, -221, 101, -218,
+ 40, -197, -76, -456,
+ 9, -445, 33, -423,
+ 226, 60, 73, -222,
+ 156, -399, 280, -318,
+ 245, -341, 166, -499,
+ 339, -190, 327, -219,
+ 325, -137, -89, -596,
+ 100, -627, 144, -677,
+ 487, 28, 252, -391,
+ 214, -41, 282, -28,
+ 99, -286, 331, 49,
+ 459, -388, 565, -369,
+ 436, 28, 336, -9,
+ 397, -167, 618, 34,
+ 596, -17, 561, -140,
+ 299, 79, 522, 125,
+ 203, 2, 244, 288,
+ 255, 211, 175, 82,
+ 596, 187, 517, 108,
+ 381, 255, 365, 297,
+ 497, 352, 327, -82,
+ 25, 210, 371, 245,
+ 261, 3, 545, 449,
+ 140, 294, 44, 295,
+ 212, 347, 244, 494,
+ 331, 528, 201, 307,
+ 349, 411, 613, 284,
+ 614, 413, 464, 322,
+ 624, 397, 97, 200,
+ -160, 384, 149, 362,
+ 495, 525, 269, 585,
+ 33, 491, -121, 433,
+ 427, 611, 498, 516,
+ 171, 443, 497, 666,
+ 440, 275, 566, 575,
+ 146, 639, 155, 670,
+ -33, 173, 212, 696,
+ -166, 601, -191, 695,
+ -489, 503, 175, 742,
+ 214, 476, 372, 1083,
+ 578, 530, 586, 777,
+ 425, 874, 315, 841,
+ 374, 848, -165, 565,
+ 35, 991, -39, 1062,
+ 329, 712, 786, 840,
+ 645, 795, 661, 676,
+ 571, 918, 632, 1079,
+ 673, 817, 318, 388,
+ 874, 1012, 564, 848,
+ 880, 620, 557, 479,
+ 671, 453, 692, 468,
+ 840, 642, 844, 645,
+ 506, 428, 897, 567,
+ 837, 387, 962, 499,
+ 691, 561, 939, 926,
+ 783, 296, 790, 268,
+ 1028, 530, 874, 329,
+ 548, 143, 675, 291,
+ 503, 66, 1041, 359,
+ 786, 97, 805, 33,
+ 837, 470, 511, 49,
+ 1092, 327, 1174, 323,
+ 3, 242, 872, 474,
+ 689, 429, 1329, 678,
+ 1042, 620, 1109, 664,
+ 321, 193, 889, 950,
+ 1153, 874, 893, 635,
+ 877, 862, 948, 913,
+ 1293, 665, 1320, 639,
+ 997, 793, 1402, 1030,
+ 1176, 1012, 1110, 959,
+ 1410, 925, 1403, 915,
+ 543, 862, 1116, 1222,
+ 835, 1190, 835, 1190,
+ 959, 1148, 1147, 1376,
+ 1300, 1193, 1415, 1231,
+ 1335, 1341, 746, 1092,
+ 1711, 1283, 1389, 1073,
+ 1334, 1566, 1153, 1475,
+ 1645, 1137, 1825, 1220,
+ 1056, 1382, 1521, 1730,
+ 1632, 1545, 1620, 1542,
+ 855, 1596, 865, 1667,
+ 693, 885, 1716, 1519,
+ 1167, 1296, 2209, 1760,
+ 1952, 1493, 2020, 1482,
+ 1534, 1866, 1694, 2008,
+ 1566, 748, 1761, 825,
+ 294, 1392, 1084, 2058,
+ 621, 1315, 365, 1287,
+ 198, 1028, 488, 1408,
+ 249, 403, 1014, 1561,
+ 324, 363, 1645, 1044,
+ 193, 367, 2034, 1859,
+ -251, 579, 750, 994,
+ -243, 30, 1325, 879,
+ -28, -169, 624, 917,
+ -453, 159, 186, 1370,
+ -614, 6, 537, 392,
+ -94, -291, 781, 229,
+ -128, -298, 245, 491,
+ -701, -648, 972, 789,
+ -501, -640, 178, 255,
+ -365, -390, -255, 317,
+ -958, -294, -191, 228,
+ -775, -447, 157, -237,
+ -657, -720, -407, 92,
+ -117, -611, 334, -230,
+ -679, -1084, -144, -317,
+ -901, -861, -738, -360,
+ -85, -727, -90, -787,
+ 100, -22, -391, -263,
+ -56, -73, -337, -754,
+ 5, -189, -706, -624,
+ 89, -344, -135, -1113,
+ -353, -237, -684, -1135,
+ -275, -1102, -269, -1203,
+ 152, 145, -722, -1232,
+ 49, 80, -1248, -776,
+ -248, 391, -732, -547,
+ 469, 218, -255, -864,
+ 69, 366, -166, -485,
+ -688, 191, -1212, -1196,
+ -170, -169, -1308, -1631,
+ 321, 470, -1419, -1243,
+ -64, 272, -1361, -248,
+ 492, 565, -721, -609,
+ 195, 485, -573, -133,
+ 427, 202, -171, -118,
+ 199, 575, 2, -31,
+ 694, 755, -1366, -39,
+ 552, 557, -489, 271,
+ 680, 537, 13, -453,
+ 855, 954, -133, -52,
+ -81, 738, -1169, 637,
+ 1055, 1059, -95, 676,
+ 1259, 1081, 489, 305,
+ -449, 954, -534, 996,
+ -969, 866, -1058, 1059,
+ -1294, 618, -1416, 617,
+ -458, 1366, -159, 1821,
+ -774, -528, -14, 1110,
+ -1202, -901, -772, 433,
+ -1256, -1255, -1011, -302,
+ -602, -585, -759, -1618,
+ -760, -1549, -840, -1921,
+ -816, -539, -1769, -2235,
+ -227, -36, -2034, -1831,
+ -2107, -1126, -2471, -1816,
+ -1470, 252, -2701, -415,
+ -571, -467, 1509, 1554,
+ 2180, 1975, 2326, 2020
+ };
+
+ const Word16 dico4_lsf_5[DICO4_5_SIZE * 4] =
+ {
+ -1857, -1681, -1857, -1755,
+ -2056, -1150, -2134, -1654,
+ -1619, -1099, -1704, -1131,
+ -1345, -1608, -1359, -1638,
+ -1338, -1293, -1325, -1265,
+ -1664, -1649, -1487, -851,
+ -1346, -1832, -1413, -2188,
+ -1282, -681, -1785, -1649,
+ -966, -1082, -1183, -1676,
+ -1054, -1073, -1142, -1158,
+ -1207, -744, -1274, -997,
+ -934, -1383, -927, -1416,
+ -1010, -1305, -783, -955,
+ -1049, -900, -993, -817,
+ -737, -823, -972, -1189,
+ -738, -1094, -738, -1154,
+ -784, -801, -810, -786,
+ -892, -520, -1000, -818,
+ -644, -965, -577, -882,
+ -541, -694, -671, -917,
+ -595, -642, -646, -615,
+ -956, -621, -925, -515,
+ -727, -483, -815, -485,
+ -840, -578, -440, -713,
+ -578, -325, -657, -670,
+ -386, -570, -441, -666,
+ -514, -787, -392, -529,
+ -522, -453, -487, -423,
+ -616, -585, -617, -157,
+ -662, -268, -680, -348,
+ -322, -323, -632, -444,
+ -304, -430, -332, -458,
+ -277, -468, -659, -793,
+ -319, -636, -227, -554,
+ -373, -347, -334, -210,
+ -456, -192, -530, -242,
+ -216, -198, -366, -370,
+ -338, -161, -409, -748,
+ -107, -380, -294, -643,
+ -223, -665, -234, -741,
+ -141, -496, -130, -510,
+ -139, -327, -172, -305,
+ -306, -580, -164, -263,
+ -262, -172, -67, -402,
+ 31, -366, -10, -436,
+ -86, -527, 71, -377,
+ -22, -609, -12, -678,
+ -67, -319, 63, -191,
+ 35, -181, -39, -242,
+ 126, -167, -140, -544,
+ 155, -297, 174, -297,
+ 38, -8, 117, -380,
+ 197, -452, 240, -522,
+ 223, -103, 110, -187,
+ 87, -155, 169, -47,
+ 157, 26, -83, -100,
+ 128, 80, 209, -62,
+ 6, 7, 22, 5,
+ 318, -20, 248, -45,
+ -200, -63, 156, -69,
+ 250, -183, 369, -126,
+ -113, -76, -142, -122,
+ -64, -254, -31, 35,
+ -177, -71, -7, 171,
+ 93, 27, 108, 212,
+ -330, -209, -123, -70,
+ -279, 95, -96, 20,
+ -188, -61, -314, 87,
+ -300, -78, -354, -134,
+ 11, 122, -140, 122,
+ -275, 152, -293, 140,
+ -82, 138, -321, -111,
+ -480, -156, -359, 76,
+ -254, -40, -635, -96,
+ -522, 79, -507, 8,
+ -268, 303, -539, 68,
+ -446, 61, -522, 306,
+ 111, 189, -435, 122,
+ -379, 166, -571, -398,
+ -632, -74, -747, -95,
+ -455, 194, -952, 83,
+ -798, 192, -755, 192,
+ -781, -162, -619, 234,
+ -663, -297, -488, -109,
+ -964, -132, -838, -68,
+ -843, 58, -1112, -86,
+ -805, -299, -944, -253,
+ -778, -50, -965, -549,
+ -352, -98, -992, -343,
+ -1117, -315, -1117, -307,
+ -1155, -374, -637, -230,
+ -1166, -43, -1299, -100,
+ -925, -393, -1274, -600,
+ -689, -130, -1479, -312,
+ -1321, -254, -1464, -442,
+ -1292, -613, -1261, -503,
+ -1501, -368, -1322, 26,
+ -1432, -66, -1743, -161,
+ -1644, -467, -1760, -548,
+ -1393, -568, -1556, -871,
+ -1495, -1034, -1387, -571,
+ -1917, -528, -1783, -123,
+ -1897, -231, -2054, -323,
+ -2052, -906, -1976, -567,
+ -1917, -620, -2047, -989,
+ -1077, -370, -2031, -704,
+ -2355, -749, -2740, -1089,
+ -1909, 159, -2012, 248,
+ -626, -123, -2339, -962,
+ -669, -408, -1379, -1174,
+ -452, -364, -1044, -735,
+ -132, 183, -1620, -752,
+ -547, -307, -777, -1261,
+ -98, 41, -880, -1091,
+ -257, 97, -1602, -1833,
+ 31, -26, -644, -561,
+ -180, -546, -385, -1095,
+ -410, -802, -414, -827,
+ -457, -970, -490, -1109,
+ -215, -916, -144, -937,
+ -493, -1269, -517, -1507,
+ 181, 101, -332, -889,
+ -836, -937, -559, -429,
+ -629, -547, -183, -337,
+ -545, -82, -250, -286,
+ 5, -132, -348, -252,
+ -293, -472, -158, 100,
+ -29, 197, -236, -424,
+ -861, -213, -140, -7,
+ -427, -443, 187, -97,
+ -684, -736, -293, 258,
+ -368, -152, -150, 392,
+ -609, 175, -142, 299,
+ -138, 152, -119, 329,
+ -486, -52, 293, 198,
+ -183, 117, 175, 331,
+ -58, -274, 231, 300,
+ -288, 330, -305, 372,
+ -111, 409, -9, 423,
+ 83, 256, 67, 367,
+ -19, 248, 91, 113,
+ -35, 406, -191, 154,
+ 238, 296, 5, 197,
+ 141, 221, 313, 198,
+ 211, 421, 244, 334,
+ 88, 426, -243, 454,
+ 202, 552, -5, 403,
+ 291, 185, 219, 301,
+ 251, 138, 128, 69,
+ 197, 288, -140, -61,
+ 188, 361, 197, 598,
+ 442, 273, 290, 143,
+ 472, 482, 157, 370,
+ 415, 321, 372, 385,
+ 402, 552, 155, 24,
+ 550, 263, -11, 21,
+ 360, 227, 147, -254,
+ 424, 97, 366, -13,
+ 375, 141, 449, 232,
+ 396, 507, 474, 272,
+ 701, 324, 362, -47,
+ 587, 148, 543, 69,
+ 400, -51, 561, 59,
+ 220, -10, 352, 147,
+ 206, 211, 653, 185,
+ 563, 297, 565, 284,
+ 594, 121, 766, 192,
+ 398, 118, 642, 434,
+ 233, 264, 481, 467,
+ 129, -165, 699, 239,
+ 90, 26, 342, 474,
+ -55, 27, 388, 94,
+ -172, 0, 725, 379,
+ -60, 337, 370, 465,
+ 95, 319, 806, 595,
+ 78, 260, 497, 851,
+ 210, 560, 458, 574,
+ -464, 202, 497, 625,
+ -202, 152, 48, 712,
+ -20, 566, 100, 715,
+ 455, 468, 411, 605,
+ 319, 646, 195, 615,
+ 401, 538, 680, 739,
+ 201, 667, 434, 954,
+ 454, 425, 646, 491,
+ 606, 681, 416, 508,
+ 497, 822, 426, 815,
+ 660, 647, 628, 716,
+ 697, 466, 618, 457,
+ 685, 460, 365, 309,
+ 721, 567, 836, 601,
+ 609, 300, 825, 459,
+ 943, 687, 681, 533,
+ 915, 598, 591, 243,
+ 876, 451, 874, 420,
+ 786, 317, 732, 220,
+ 922, 317, 1108, 367,
+ 531, 466, 1028, 649,
+ 1053, 615, 1034, 553,
+ 829, 602, 1021, 799,
+ 927, 803, 878, 763,
+ 799, 496, 1373, 773,
+ 585, 770, 803, 930,
+ 1099, 793, 1222, 862,
+ 1209, 895, 1025, 727,
+ 772, 845, 1172, 1115,
+ 867, 1021, 830, 1013,
+ 841, 910, 506, 703,
+ 1239, 1077, 620, 819,
+ 1196, 1083, 1155, 1081,
+ 1142, 907, 1547, 1121,
+ 1309, 648, 1343, 612,
+ 1484, 988, 1479, 937,
+ 985, 1328, 955, 1341,
+ 429, 910, 841, 1338,
+ 564, 1179, 412, 1156,
+ 1427, 1320, 1434, 1330,
+ 640, 760, 1726, 1410,
+ 190, 555, 1073, 1005,
+ 426, 257, 839, 980,
+ 235, 231, 1520, 1167,
+ 109, 293, 1014, 1569,
+ 305, 142, 1148, 539,
+ -291, -108, 1213, 972,
+ 22, -216, 667, 828,
+ -482, 438, 453, 1431,
+ -581, -422, 789, 387,
+ -358, -454, 174, 780,
+ -36, -372, 390, -134,
+ -629, 160, -306, 751,
+ -1258, -331, 177, 522,
+ -248, 574, -251, 639,
+ -531, 407, -596, 394,
+ -419, 789, -617, 801,
+ -986, 399, -857, 727,
+ -7, 518, -703, 310,
+ -1143, -24, -1002, 287,
+ -960, 363, -1299, 312,
+ -1534, 245, -1557, 305,
+ 28, 153, -859, -175,
+ -33, 332, -1398, -154,
+ 212, 410, -593, -197,
+ -1092, -704, -904, -65,
+ 282, 367, -918, -686,
+ 345, 93, -258, -357,
+ 696, 644, -693, -28,
+ 448, 493, -273, 193,
+ 527, 546, -243, -513,
+ 384, -136, 273, -353,
+ 512, -142, 537, -198,
+ 941, 750, 83, 248,
+ 578, 861, -56, 592,
+ 842, 44, 892, 24,
+ 33, 890, -16, 982,
+ 831, 1398, 1535, 1898,
+ 1716, 1376, 1948, 1465
+ };
+
+ const Word16 dico5_lsf_5[DICO5_5_SIZE * 4] =
+ {
+ -1002, -929, -1096, -1203,
+ -641, -931, -604, -961,
+ -779, -673, -835, -788,
+ -416, -664, -458, -766,
+ -652, -521, -662, -495,
+ -1023, -509, -1023, -428,
+ -444, -552, -368, -449,
+ -479, -211, -1054, -903,
+ -316, -249, -569, -591,
+ -569, -275, -541, -191,
+ -716, -188, -842, -264,
+ -333, -248, -318, -228,
+ -275, 1, -567, -228,
+ -115, -221, -238, -374,
+ -197, -507, -222, -579,
+ -258, -432, -61, -244,
+ -345, 2, -338, 39,
+ -215, -169, -58, 0,
+ -56, -6, -203, -131,
+ 1, -186, -5, -211,
+ 6, -380, 11, -418,
+ -116, 131, -134, 113,
+ 89, -4, 71, -2,
+ -19, -192, 262, 24,
+ 189, 151, -133, -109,
+ 186, -153, 166, -219,
+ 37, 139, 193, 171,
+ 337, 124, 158, -61,
+ 141, 226, -13, 190,
+ 231, 34, 354, 109,
+ 316, 201, 244, 164,
+ 330, -85, 390, -84,
+ 254, 327, 257, 335,
+ 491, 147, 476, 105,
+ 54, 77, 437, 370,
+ 421, 314, 449, 342,
+ 329, 126, 673, 292,
+ 571, 388, 243, 193,
+ 653, 320, 621, 280,
+ 194, 380, 517, 581,
+ 45, 323, 111, 422,
+ 489, 395, 734, 534,
+ 622, 546, 486, 502,
+ 318, 572, 189, 550,
+ 385, 422, -157, 153,
+ -125, 382, -197, 386,
+ -263, 334, 228, 697,
+ -188, 1, 51, 297,
+ -507, 213, -376, 397,
+ -24, 255, -547, 89,
+ -502, -94, 387, 179,
+ -620, 68, -684, 112,
+ -642, -350, -260, 172,
+ -438, -324, 264, 648,
+ -964, -4, -1121, 7,
+ -134, 134, -1133, -306,
+ 143, 96, -420, -497,
+ -1221, -350, -1527, -685,
+ -161, 72, 873, 691,
+ 732, 283, 921, 353,
+ 334, 475, 1095, 821,
+ 864, 524, 843, 497,
+ 714, 711, 788, 750,
+ 1076, 714, 1204, 753
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] q_plsf_5.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
diff --git a/media/codecs/amrnb/common/src/qua_gain_tbl.cpp b/media/codecs/amrnb/common/src/qua_gain_tbl.cpp
new file mode 100644
index 0000000..2d913b8
--- /dev/null
+++ b/media/codecs/amrnb/common/src/qua_gain_tbl.cpp
@@ -0,0 +1,391 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/qua_gain_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created this file from the reference, qua_gain.tab
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "qua_gain.h"
+#include "qua_gain_tbl.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+ /* The tables contains the following data:
+ *
+ * g_pitch (Q14),
+ * g_fac (Q12), (g_code = g_code0*g_fac),
+ * qua_ener_MR122 (Q10), (log2(g_fac))
+ * qua_ener (Q10) (20*log10(g_fac))
+ *
+ * The log2() and log10() values are calculated on the fixed point value
+ * (g_fac Q12) and not on the original floating point value of g_fac
+ * to make the quantizer/MA predictdor use corresponding values.
+ */
+
+ /* table used in 'high' rates: MR67 MR74 */
+
+ const Word16 table_gain_highrates[VQ_SIZE_HIGHRATES*4] =
+ {
+
+ /*
+ * Note: column 4 (qua_ener) contains the original values from IS641
+ * to ensure bit-exactness; however, they are not exactly the
+ * rounded value of (20*log10(g_fac))
+ *
+ */
+
+ /*g_pit, g_fac, qua_ener_MR122, qua_ener */
+ 577, 662, -2692, -16214,
+ 806, 1836, -1185, -7135,
+ 3109, 1052, -2008, -12086,
+ 4181, 1387, -1600, -9629,
+ 2373, 1425, -1560, -9394,
+ 3248, 1985, -1070, -6442,
+ 1827, 2320, -840, -5056,
+ 941, 3314, -313, -1885,
+ 2351, 2977, -471, -2838,
+ 3616, 2420, -777, -4681,
+ 3451, 3096, -414, -2490,
+ 2955, 4301, 72, 434,
+ 1848, 4500, 139, 836,
+ 3884, 5416, 413, 2484,
+ 1187, 7210, 835, 5030,
+ 3083, 9000, 1163, 7002,
+ 7384, 883, -2267, -13647,
+ 5962, 1506, -1478, -8900,
+ 5155, 2134, -963, -5800,
+ 7944, 2009, -1052, -6335,
+ 6507, 2250, -885, -5327,
+ 7670, 2752, -588, -3537,
+ 5952, 3016, -452, -2724,
+ 4898, 3764, -125, -751,
+ 6989, 3588, -196, -1177,
+ 8174, 3978, -43, -260,
+ 6064, 4404, 107, 645,
+ 7709, 5087, 320, 1928,
+ 5523, 6021, 569, 3426,
+ 7769, 7126, 818, 4926,
+ 6060, 7938, 977, 5885,
+ 5594, 11487, 1523, 9172,
+ 10581, 1356, -1633, -9831,
+ 9049, 1597, -1391, -8380,
+ 9794, 2035, -1033, -6220,
+ 8946, 2415, -780, -4700,
+ 10296, 2584, -681, -4099,
+ 9407, 2734, -597, -3595,
+ 8700, 3218, -356, -2144,
+ 9757, 3395, -277, -1669,
+ 10177, 3892, -75, -454,
+ 9170, 4528, 148, 891,
+ 10152, 5004, 296, 1781,
+ 9114, 5735, 497, 2993,
+ 10500, 6266, 628, 3782,
+ 10110, 7631, 919, 5534,
+ 8844, 8727, 1117, 6728,
+ 8956, 12496, 1648, 9921,
+ 12924, 976, -2119, -12753,
+ 11435, 1755, -1252, -7539,
+ 12138, 2328, -835, -5024,
+ 11388, 2368, -810, -4872,
+ 10700, 3064, -429, -2580,
+ 12332, 2861, -530, -3192,
+ 11722, 3327, -307, -1848,
+ 11270, 3700, -150, -904,
+ 10861, 4413, 110, 663,
+ 12082, 4533, 150, 902,
+ 11283, 5205, 354, 2132,
+ 11960, 6305, 637, 3837,
+ 11167, 7534, 900, 5420,
+ 12128, 8329, 1049, 6312,
+ 10969, 10777, 1429, 8604,
+ 10300, 17376, 2135, 12853,
+ 13899, 1681, -1316, -7921,
+ 12580, 2045, -1026, -6179,
+ 13265, 2439, -766, -4610,
+ 14033, 2989, -465, -2802,
+ 13452, 3098, -413, -2482,
+ 12396, 3658, -167, -1006,
+ 13510, 3780, -119, -713,
+ 12880, 4272, 62, 374,
+ 13533, 4861, 253, 1523,
+ 12667, 5457, 424, 2552,
+ 13854, 6106, 590, 3551,
+ 13031, 6483, 678, 4084,
+ 13557, 7721, 937, 5639,
+ 12957, 9311, 1213, 7304,
+ 13714, 11551, 1532, 9221,
+ 12591, 15206, 1938, 11667,
+ 15113, 1540, -1445, -8700,
+ 15072, 2333, -832, -5007,
+ 14527, 2511, -723, -4352,
+ 14692, 3199, -365, -2197,
+ 15382, 3560, -207, -1247,
+ 14133, 3960, -50, -300,
+ 15102, 4236, 50, 298,
+ 14332, 4824, 242, 1454,
+ 14846, 5451, 422, 2542,
+ 15306, 6083, 584, 3518,
+ 14329, 6888, 768, 4623,
+ 15060, 7689, 930, 5602,
+ 14406, 9426, 1231, 7413,
+ 15387, 9741, 1280, 7706,
+ 14824, 14271, 1844, 11102,
+ 13600, 24939, 2669, 16067,
+ 16396, 1969, -1082, -6517,
+ 16817, 2832, -545, -3283,
+ 15713, 2843, -539, -3248,
+ 16104, 3336, -303, -1825,
+ 16384, 3963, -49, -294,
+ 16940, 4579, 165, 992,
+ 15711, 4599, 171, 1030,
+ 16222, 5448, 421, 2537,
+ 16832, 6382, 655, 3945,
+ 15745, 7141, 821, 4944,
+ 16326, 7469, 888, 5343,
+ 16611, 8624, 1100, 6622,
+ 17028, 10418, 1379, 8303,
+ 15905, 11817, 1565, 9423,
+ 16878, 14690, 1887, 11360,
+ 16515, 20870, 2406, 14483,
+ 18142, 2083, -999, -6013,
+ 19401, 3178, -375, -2257,
+ 17508, 3426, -264, -1589,
+ 20054, 4027, -25, -151,
+ 18069, 4249, 54, 326,
+ 18952, 5066, 314, 1890,
+ 17711, 5402, 409, 2461,
+ 19835, 6192, 610, 3676,
+ 17950, 7014, 795, 4784,
+ 21318, 7877, 966, 5816,
+ 17910, 9289, 1210, 7283,
+ 19144, 9290, 1210, 7284,
+ 20517, 11381, 1510, 9089,
+ 18075, 14485, 1866, 11234,
+ 19999, 17882, 2177, 13108,
+ 18842, 32764, 3072, 18494
+ };
+
+
+ /* table used in 'low' rates: MR475, MR515, MR59 */
+
+ const Word16 table_gain_lowrates[VQ_SIZE_LOWRATES*4] =
+ {
+ /*g_pit, g_fac, qua_ener_MR122, qua_ener */
+ 10813, 28753, 2879, 17333,
+ 20480, 2785, -570, -3431,
+ 18841, 6594, 703, 4235,
+ 6225, 7413, 876, 5276,
+ 17203, 10444, 1383, 8325,
+ 21626, 1269, -1731, -10422,
+ 21135, 4423, 113, 683,
+ 11304, 1556, -1430, -8609,
+ 19005, 12820, 1686, 10148,
+ 17367, 2498, -731, -4398,
+ 17858, 4833, 244, 1472,
+ 9994, 2498, -731, -4398,
+ 17530, 7864, 964, 5802,
+ 14254, 1884, -1147, -6907,
+ 15892, 3153, -387, -2327,
+ 6717, 1802, -1213, -7303,
+ 18186, 20193, 2357, 14189,
+ 18022, 3031, -445, -2678,
+ 16711, 5857, 528, 3181,
+ 8847, 4014, -30, -180,
+ 15892, 8970, 1158, 6972,
+ 18022, 1392, -1594, -9599,
+ 16711, 4096, 0, 0,
+ 8192, 655, -2708, -16305,
+ 15237, 13926, 1808, 10884,
+ 14254, 3112, -406, -2444,
+ 14090, 4669, 193, 1165,
+ 5406, 2703, -614, -3697,
+ 13434, 6553, 694, 4180,
+ 12451, 901, -2237, -13468,
+ 12451, 2662, -637, -3833,
+ 3768, 655, -2708, -16305,
+ 14745, 23511, 2582, 15543,
+ 19169, 2457, -755, -4546,
+ 20152, 5079, 318, 1913,
+ 6881, 4096, 0, 0,
+ 20480, 8560, 1089, 6556,
+ 19660, 737, -2534, -15255,
+ 19005, 4259, 58, 347,
+ 7864, 2088, -995, -5993,
+ 11468, 12288, 1623, 9771,
+ 15892, 1474, -1510, -9090,
+ 15728, 4628, 180, 1086,
+ 9175, 1433, -1552, -9341,
+ 16056, 7004, 793, 4772,
+ 14827, 737, -2534, -15255,
+ 15073, 2252, -884, -5321,
+ 5079, 1228, -1780, -10714,
+ 13271, 17326, 2131, 12827,
+ 16547, 2334, -831, -5002,
+ 15073, 5816, 518, 3118,
+ 3932, 3686, -156, -938,
+ 14254, 8601, 1096, 6598,
+ 16875, 778, -2454, -14774,
+ 15073, 3809, -107, -646,
+ 6062, 614, -2804, -16879,
+ 9338, 9256, 1204, 7251,
+ 13271, 1761, -1247, -7508,
+ 13271, 3522, -223, -1343,
+ 2457, 1966, -1084, -6529,
+ 11468, 5529, 443, 2668,
+ 10485, 737, -2534, -15255,
+ 11632, 3194, -367, -2212,
+ 1474, 778, -2454, -14774
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] qua_gain.tab, UMTS GSM AMR speech codec,
+ R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/common/src/reorder.cpp b/media/codecs/amrnb/common/src/reorder.cpp
new file mode 100644
index 0000000..b1e4711
--- /dev/null
+++ b/media/codecs/amrnb/common/src/reorder.cpp
@@ -0,0 +1,199 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Filename: /audio/gsm_amr/c/src/reorder.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ 1. Eliminated unused include file add.h.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation
+ 4. Replaced loop counter with decrement loops
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "reorder.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Reorder_lsf
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf = vector of LSFs (range: 0<=val<=0.5)(Word16)
+ min_dist = minimum required distance (Word16)
+ n = LPC order (Word16)
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the add operation called by Reorder_lsf() results in
+ overflow
+ lsf -> reordered vector of LSFs (Word16)
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function makes sure that the LSFs are properly ordered keeps a certain
+ minimum distance between adjacent LSFs.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] reorder.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Reorder_lsf (
+ Word16 *lsf, // (i/o) : vector of LSFs (range: 0<=val<=0.5)
+ Word16 min_dist, // (i) : minimum required distance
+ Word16 n // (i) : LPC order
+)
+{
+ Word16 i;
+ Word16 lsf_min;
+
+// The reference ETSI code uses a global flag for Overflow. In the actual
+// implementation a pointer to Overflow flag is passed into the function
+// for use by the math functions add() and sub()
+
+ lsf_min = min_dist;
+ for (i = 0; i < n; i++)
+ {
+ if (sub (lsf[i], lsf_min) < 0)
+ {
+ lsf[i] = lsf_min;
+ }
+ lsf_min = add (lsf[i], min_dist);
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void Reorder_lsf(
+ Word16 *lsf, /* (i/o) : vector of LSFs (range: 0<=val<=0.5) */
+ Word16 min_dist, /* (i) : minimum required distance */
+ Word16 n, /* (i) : LPC order */
+ Flag *pOverflow /* (i/o) : Overflow flag */
+)
+{
+ Word16 i;
+ Word16 lsf_min;
+ Word16 *p_lsf = &lsf[0];
+ OSCL_UNUSED_ARG(pOverflow);
+
+ lsf_min = min_dist;
+ for (i = 0; i < n; i++)
+ {
+ if (*(p_lsf) < lsf_min)
+ {
+ *(p_lsf++) = lsf_min;
+ lsf_min += min_dist;
+ }
+ else
+ {
+ lsf_min = *(p_lsf++) + min_dist;
+ }
+ }
+}
+
diff --git a/media/codecs/amrnb/common/src/residu.cpp b/media/codecs/amrnb/common/src/residu.cpp
new file mode 100644
index 0000000..2ad132f
--- /dev/null
+++ b/media/codecs/amrnb/common/src/residu.cpp
@@ -0,0 +1,255 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/residu.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing code.
+
+ Description: Deleted stores listed in the Local Stores Needed/Modified
+ section.
+
+ Description: Updated file per comments gathered from Phase 2/3 review.
+
+ Description: Updating to reflect variable name changes made in residu.asm
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Modified FOR loops to count down.
+ 2. Fixed typecasting issue with TI C compiler.
+
+ Description: Made the following changes
+ 1. Unrolled the convolutional loop.
+ 2. Performed 4 convolution per pass to avoid recalling the same
+ filter coefficient as many times.
+ 2. Eliminated math operations that check for saturation.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "residu.h"
+#include "typedef.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Residu
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ coef_ptr = pointer to buffer containing the prediction coefficients
+ input_ptr = pointer to buffer containing the speech signal
+ input_len = filter order
+ residual_ptr = pointer to buffer of residual signal
+
+ Outputs:
+ residual_ptr buffer contains the newly calculated the residual signal
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the LP residual by filtering the input speech through
+ the LP inverse filter A(z).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ residu.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Note: Input argument names were changed to be more descriptive. Shown below
+ are the original names. Shown below are the name changes:
+ a[] <--> coef_ptr[]
+ x[] <--> input_ptr[]
+ y[] <--> residual_ptr[]
+ lg <--> input_len
+
+
+void Residu (
+ Word16 a[], // (i) : prediction coefficients
+ Word16 x[], // (i) : speech signal
+ Word16 y[], // (o) : residual signal
+ Word16 lg // (i) : size of filtering
+)
+{
+ Word16 i, j;
+ Word32 s;
+
+ for (i = 0; i < lg; i++)
+ {
+ s = L_mult (x[i], a[0]);
+ for (j = 1; j <= M; j++)
+ {
+ s = L_mac (s, a[j], x[i - j]);
+ }
+ s = L_shl (s, 3);
+ y[i] = pv_round (s);
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Residu(
+ Word16 coef_ptr[], /* (i) : prediction coefficients*/
+ Word16 input_ptr[], /* (i) : speech signal */
+ Word16 residual_ptr[], /* (o) : residual signal */
+ Word16 input_len /* (i) : size of filtering */
+)
+{
+
+
+ Word16 i, j;
+ Word32 s1;
+ Word32 s2;
+ Word32 s3;
+ Word32 s4;
+ Word16 *p_input1;
+ Word16 *p_input2;
+ Word16 *p_input3;
+ Word16 *p_input4;
+ Word16 *p_coef;
+ Word16 *p_residual_ptr = &residual_ptr[input_len-1];
+ Word16 *p_input_ptr = &input_ptr[input_len-1-M];
+
+ for (i = input_len >> 2; i != 0; i--)
+ {
+ s1 = 0x0000800L;
+ s2 = 0x0000800L;
+ s3 = 0x0000800L;
+ s4 = 0x0000800L;
+ p_coef = &coef_ptr[M];
+ p_input1 = p_input_ptr--;
+ p_input2 = p_input_ptr--;
+ p_input3 = p_input_ptr--;
+ p_input4 = p_input_ptr--;
+
+ for (j = M >> 1; j != 0; j--)
+ {
+ s1 += ((Word32) * (p_coef) * *(p_input1++));
+ s2 += ((Word32) * (p_coef) * *(p_input2++));
+ s3 += ((Word32) * (p_coef) * *(p_input3++));
+ s4 += ((Word32) * (p_coef--) * *(p_input4++));
+ s1 += ((Word32) * (p_coef) * *(p_input1++));
+ s2 += ((Word32) * (p_coef) * *(p_input2++));
+ s3 += ((Word32) * (p_coef) * *(p_input3++));
+ s4 += ((Word32) * (p_coef--) * *(p_input4++));
+ }
+
+ s1 += (((Word32) * (p_coef)) * *(p_input1));
+ s2 += (((Word32) * (p_coef)) * *(p_input2));
+ s3 += (((Word32) * (p_coef)) * *(p_input3));
+ s4 += (((Word32) * (p_coef)) * *(p_input4));
+
+ *(p_residual_ptr--) = (Word16)(s1 >> 12);
+ *(p_residual_ptr--) = (Word16)(s2 >> 12);
+ *(p_residual_ptr--) = (Word16)(s3 >> 12);
+ *(p_residual_ptr--) = (Word16)(s4 >> 12);
+
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/round.cpp b/media/codecs/amrnb/common/src/round.cpp
new file mode 100644
index 0000000..633a8c9
--- /dev/null
+++ b/media/codecs/amrnb/common/src/round.cpp
@@ -0,0 +1,195 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/round.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the round function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Made changes based on review meeting:
+ 1. Removed long in Inputs Definitions.
+ 2. Changed L_var1 to var_out and description in
+ Output Definitions.
+
+ Description: Added a parameter to the function interface, pOverflow which is
+ a pointer to the overflow flag. This flag is required by the
+ L_add() function invoked by round().
+ Removed code that updates the MOPS counter.
+ Created a new return variable result.
+
+ Description: Removed embedded tabs. Included comment in the Pseudo code
+ Section about using pointer to overflow flag in the actual
+ implementation instead of using a global flag.
+
+ Description: Changed function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Rounding function with saturation.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: pv_round
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ None
+
+ Returns:
+ result = MS 16 bits of rounded input L_var1.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function rounds the lower 16 bits of the 32 bit input number into the
+ MS 16 bits with saturation. Shift the resulting bits right by 16 and return
+ the 16 bit number:
+ pv_round(L_var1) = extract_h(L_add(L_var1,32768))
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] round() function in basic_op2.c, UMTS GSM AMR speech codec, R99 -
+ Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 pv_round (Word32 L_var1)
+{
+ Word16 var_out;
+ Word32 L_rounded;
+
+* The reference ETSI code uses a global flag for Overflow in the L_add() function.
+* In the actual implementation a pointer to Overflow flag is passed in as a
+* parameter to the function.
+
+ L_rounded = L_add (L_var1, (Word32) 0x00008000L);
+#if (WMOPS)
+ multiCounter[currCounter].L_add--;
+#endif
+ var_out = extract_h (L_rounded);
+#if (WMOPS)
+ multiCounter[currCounter].extract_h--;
+ multiCounter[currCounter].round++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 pv_round(Word32 L_var1, Flag *pOverflow)
+{
+ Word16 result;
+
+ L_var1 = L_add(L_var1, (Word32) 0x00008000L, pOverflow);
+ result = (Word16)(L_var1 >> 16);
+
+ return (result);
+}
diff --git a/media/codecs/amrnb/common/src/set_zero.cpp b/media/codecs/amrnb/common/src/set_zero.cpp
new file mode 100644
index 0000000..be23b25
--- /dev/null
+++ b/media/codecs/amrnb/common/src/set_zero.cpp
@@ -0,0 +1,74 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : set_zero.h
+*
+********************************************************************************
+*/
+/*
+********************************************************************************
+* MODULE INCLUDE FILE AND VERSION ID
+********************************************************************************
+*/
+#include "set_zero.h"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "basic_op.h"
+
+/*
+********************************************************************************
+* PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+void Set_zero(
+ Word16 x[], /* (o) : vector to clear */
+ Word16 L /* (i) : length of vector */
+)
+{
+ Word16 i;
+
+ for (i = 0; i < L; i++)
+ {
+ x[i] = 0;
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/shr.cpp b/media/codecs/amrnb/common/src/shr.cpp
new file mode 100644
index 0000000..1018d9c
--- /dev/null
+++ b/media/codecs/amrnb/common/src/shr.cpp
@@ -0,0 +1,258 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/shr.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the shr function. Sync'ed up with
+ the current template and fixed tabs.
+
+ Description: 1. Modified code by seperating var2=0 condition.
+ 2. Changed Input range definitions.
+
+ Description: Made changes based on review meeting.
+ 1. Changed Overflow definition.
+ 2. Removed pseudo-code.
+ 3. Deleted (var2>15&&var1!=0) condition.
+ 4. Moved var2>0 condition in front of var2<0 condition.
+
+ Description: Changed the function prototype to pass in a pointer to the
+ overflow flag instead of using global data.
+
+ Description: Made changes per formal review. Updated template.
+ Removed code that updates MOPS counter.
+ Changed parameter name from "overflow" and "pOverflow".
+ Optimized code by eliminating unnecessary typecasting.
+ Filled in the PSEUDO CODE section
+
+ Description: Further optimized typecasting for overflow case
+
+ Who: Date:
+ Description:
+------------------------------------------------------------------------------
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+ Shift right function with overflow control
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: shr
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the shift operation resulted in overflow
+
+ Returns:
+ product = Shifted result limited to 16 bits (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function arithmetically shifts the 16 bit input var1 right var2 positions
+ with sign extension. If var2 is negative, arithmetically shift var1 left by
+ -var2 with sign extension. Saturate the result in case of underflows or
+ overflows.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+ None
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] shr() function in basic_op2.c, UMTS GSM AMR speech codec, R99 -
+ Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 shr_std (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ if (var2 < 0)
+ {
+ if (var2 < -16)
+ var2 = -16;
+ var_out = shl_std (var1, -var2);
+#if (WMOPS)
+ mult_stdiCounter[currCounter].shl_std--;
+#endif
+ }
+ else
+ {
+ if (var2 >= 15)
+ {
+ var_out = (var1 < 0) ? -1 : 0;
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var_out = ~((~var1) >> var2);
+ }
+ else
+ {
+ var_out = var1 >> var2;
+ }
+ }
+ }
+
+#if (WMOPS)
+ mult_stdiCounter[currCounter].shr_std++;
+#endif
+ return (var_out);
+}
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 shr(Word16 var1, Word16 var2, Flag *pOverflow)
+{
+ Word16 result;
+ Word32 temp_res;
+
+ if (var2 != 0)
+ {
+ if (var2 > 0)
+ {
+ if (var2 >= 15)
+ {
+ result = ((var1 < 0) ? -1 : 0);
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ result = (~((~var1) >> var2));
+ }
+ else
+ {
+ result = (var1 >> var2);
+ }
+ }
+ }
+ else
+ {
+ if (var2 < -16)
+ {
+ var2 = -16;
+ }
+
+ var2 = -var2; /* Shift right negative is equivalent */
+ /* to shifting left positive. */
+
+ temp_res = ((Word32) var1) << var2;
+ result = (Word16)(temp_res);
+
+ if (temp_res != (Word32) result)
+ {
+ *pOverflow = 1;
+ result = ((var1 > 0) ? MAX_16 : MIN_16);
+ }
+ }
+
+ }
+ else
+ {
+ result = var1;
+ }
+
+ return (result);
+}
+
diff --git a/media/codecs/amrnb/common/src/shr_r.cpp b/media/codecs/amrnb/common/src/shr_r.cpp
new file mode 100644
index 0000000..cdcc246
--- /dev/null
+++ b/media/codecs/amrnb/common/src/shr_r.cpp
@@ -0,0 +1,226 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./gsm-amr/c/src/shr_r.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the shr_r function. Sync'ed up
+ with the current template and fixed tabs.
+
+ Description: Passing around pOverflow as per EPOC changes.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ var_out = shifted input w/ rounding (Word16)
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function arithmetically shifts the 16 bit input var1 right var2 positions
+ with rounding. If var2 is negative, arithmetically shift var1 left by
+ -var2 with rounding. Saturate the result in case of underflows or
+ overflows.
+
+ - If var2 is greater than zero :
+ if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1))))
+ is equal to zero
+ then
+ shr_r(var1,var2) = shr(var1,var2)
+ else
+ shr_r(var1,var2) = add(shr(var1,var2),1)
+ - If var2 is less than or equal to zero :
+ shr_r(var1,var2) = shr(var1,var2).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 shr_r (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ if (var2 > 15)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ var_out = shr (var1, var2);
+#if (WMOPS)
+ multiCounter[currCounter].shr--;
+#endif
+
+ if (var2 > 0)
+ {
+ if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
+ {
+ var_out++;
+ }
+ }
+ }
+#if (WMOPS)
+ multiCounter[currCounter].shr_r++;
+#endif
+ return (var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 shr_r(Word16 var1, Word16 var2, Flag *pOverflow)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ Word16 var_out;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ if (var2 > 15)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ var_out = shr(var1, var2, pOverflow);
+ if (var2 > 0)
+ {
+ if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
+ {
+ var_out++;
+ }
+ }
+ }
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return (var_out);
+}
diff --git a/media/codecs/amrnb/common/src/sqrt_l.cpp b/media/codecs/amrnb/common/src/sqrt_l.cpp
new file mode 100644
index 0000000..8f74aa6
--- /dev/null
+++ b/media/codecs/amrnb/common/src/sqrt_l.cpp
@@ -0,0 +1,266 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/sqrt_l.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Updated template. Changed function interface to pass in a
+ pointer to overflow flag into the function instead of using a
+ global flag. Changed name of an input pointer from "exp" to "pExp"
+ for clarity. Removed inclusion of unwanted header files.
+
+ Description: Removed inclusion of sqrt_l.tab file. Changed the array name
+ "table" to "sqrt_l_tbl". Fixed typos.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "sqrt_l.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: sqrt_l_exp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_x = input value (Word32)
+ pExp = pointer to right shift to be applied to result
+ pOverflow = pointer to overflow flag
+
+ Outputs:
+ pOverflow -> if the Inv_sqrt operation resulted in an overflow.
+
+ Returns:
+ L_y = squareroot of L_x (Word32)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes sqrt(L_x), where L_x is positive.
+ If L_var is negative or zero, the result is 0
+
+ The function sqrt(L_x) is approximated by a table and linear
+ interpolation. The square root is computed using the
+ following steps:
+ 1- Normalization of L_x.
+ 2- If exponent is even then shift right once.
+ 3- exponent = exponent/2
+ 4- i = bit25-b31 of L_x; 16<=i<=63 because of normalization.
+ 5- a = bit10-b24
+ 6- i -=16
+ 7- L_y = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ 8- return L_y and exponent so caller can do denormalization
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sqrt_l.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 sqrt_l_exp ( // o : output value
+ Word32 L_x, // i : input value
+ Word16 *exp // o : right shift to be applied to result
+)
+{
+
+// y = sqrt(x)
+// x = f * 2^-e, 0.5 <= f < 1 (normalization)
+// y = sqrt(f) * 2^(-e/2)
+//
+// a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2,
+// 0.707 <= sqrt(f) < 1)
+// b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2,
+ 0.5 <= sqrt(f/2) < 0.707)
+
+
+ Word16 e, i, a, tmp;
+ Word32 L_y;
+
+ if (L_x <= (Word32) 0)
+ {
+ *exp = 0;
+ return (Word32) 0;
+ }
+
+* The reference ETSI code uses a global Overflow flag. In the actual
+* implementation a pointer to the overflow flag is passed into the function.
+* This pointer is in turn passed into the basic math functions such as add(),
+* L_shl(), L_shr(), sub() called by this module.
+
+ e = norm_l (L_x) & 0xFFFE; // get next lower EVEN norm. exp
+ L_x = L_shl (L_x, e); // L_x is normalized to [0.25..1)
+ *exp = e; // return 2*exponent (or Q1)
+
+ L_x = L_shr (L_x, 9);
+ i = extract_h (L_x); // Extract b25-b31, 16 <= i <= 63
+ because of normalization
+ L_x = L_shr (L_x, 1);
+ a = extract_l (L_x); // Extract b10-b24
+ a = a & (Word16) 0x7fff;
+
+ i = sub (i, 16); // 0 <= i <= 47
+
+ L_y = L_deposit_h (table[i]); // table[i] << 16
+ tmp = sub (table[i], table[i + 1]); // table[i] - table[i+1])
+ L_y = L_msu (L_y, tmp, a); // L_y -= tmp*a*2
+
+ return (L_y);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word32 sqrt_l_exp( /* o : output value, Q31 */
+ Word32 L_x, /* i : input value, Q31 */
+ Word16 *pExp, /* o : right shift to be applied to result, Q1 */
+ Flag *pOverflow /* i : pointer to overflow flag */
+)
+
+{
+ Word16 e;
+ Word16 i;
+ Word16 a;
+ Word16 tmp;
+ Word32 L_y;
+
+ /*
+ y = sqrt(x)
+ x = f * 2^-e, 0.5 <= f < 1 (normalization)
+ y = sqrt(f) * 2^(-e/2)
+ a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2,
+ 0.707 <= sqrt(f) < 1)
+ b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2,
+ 0.5 <= sqrt(f/2) < 0.707)
+ */
+
+ if (L_x <= (Word32) 0)
+ {
+ *pExp = 0;
+ return (Word32) 0;
+ }
+
+ e = norm_l(L_x) & 0xFFFE; /* get next lower EVEN norm. exp */
+ L_x = L_shl(L_x, e, pOverflow); /* L_x is normalized to [0.25..1) */
+ *pExp = e; /* return 2*exponent (or Q1) */
+
+ L_x >>= 10;
+ i = (Word16)(L_x >> 15) & 63; /* Extract b25-b31, 16<= i <=63 */
+ /* because of normalization */
+
+ a = (Word16)(L_x); /* Extract b10-b24 */
+ a &= (Word16) 0x7fff;
+
+ if (i > 15)
+ {
+ i -= 16; /* 0 <= i <= 47 */
+ }
+
+ L_y = L_deposit_h(sqrt_l_tbl[i]); /* sqrt_l_tbl[i] << 16 */
+
+ /* sqrt_l_tbl[i] - sqrt_l_tbl[i+1]) */
+ tmp = sub(sqrt_l_tbl[i], sqrt_l_tbl[i + 1], pOverflow);
+
+ L_y = L_msu(L_y, tmp, a, pOverflow); /* L_y -= tmp*a*2 */
+
+ /* L_y = L_shr (L_y, *exp); */ /* denormalization done by caller */
+
+ return (L_y);
+}
+
diff --git a/media/codecs/amrnb/common/src/sqrt_l_tbl.cpp b/media/codecs/amrnb/common/src/sqrt_l_tbl.cpp
new file mode 100644
index 0000000..5a84b63
--- /dev/null
+++ b/media/codecs/amrnb/common/src/sqrt_l_tbl.cpp
@@ -0,0 +1,171 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/sqrt_l_tbl.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed the table name to sqrt_l_tbl.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the declaration for sqrt_l_table[] used by the sqrt_l_exp
+ function.
+
+ sqrt_l_tbl[i] = sqrt((i+16)*2^-6) * 2^15, i.e. sqrt(x) scaled Q15
+
+ ------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "sqrt_l.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+ const Word16 sqrt_l_tbl[50] =
+ {
+ 16384, 16888, 17378, 17854, 18318, 18770, 19212, 19644, 20066, 20480,
+ 20886, 21283, 21674, 22058, 22435, 22806, 23170, 23530, 23884, 24232,
+ 24576, 24915, 25249, 25580, 25905, 26227, 26545, 26859, 27170, 27477,
+ 27780, 28081, 28378, 28672, 28963, 29251, 29537, 29819, 30099, 30377,
+ 30652, 30924, 31194, 31462, 31727, 31991, 32252, 32511, 32767, 32767
+ };
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] inv_sqrt.tab file, UMTS GSM AMR speech codec, R99 - Version 3.2.0,
+ March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/common/src/sub.cpp b/media/codecs/amrnb/common/src/sub.cpp
new file mode 100644
index 0000000..b956912
--- /dev/null
+++ b/media/codecs/amrnb/common/src/sub.cpp
@@ -0,0 +1,221 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: /audio/gsm_amr/c/src/sub.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate file for the sub function. Sync'ed up with the
+ current template and fixed tabs.
+
+ Description: Changed all occurrences of L_diff to diff, deleted "short" in
+ the definition of var1 and var2, and fixed the range values.
+
+ Description: Changed function prototype passing in a pointer to overflow flag
+ instead of using global data.
+
+ Description: Changes made per formal review comments.
+ 1. Changed the parameter name fron "overflow" to "pOverflow"
+ 2. Updated template
+ 3. Updated reference section
+
+ Description: Removed conditional code that updates WMOPS counter
+
+ Description:
+ 1. Modified if-else structure to save cycles by processing
+ the most common case faster.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Subtraction function with overflow control
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: sub
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ var1 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2 = 16 bit short signed integer (Word16) whose value falls in
+ the range : 0xffff 8000 <= var2 <= 0x0000 7fff.
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the subtract operation resulted in overflow
+
+ Returns:
+ diff = 16-bit limited difference between var1 and var2 (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the subtraction (var1-var2) with overflow control and
+ saturation; the 16 bit result is set at +32767 when overflow occurs or at
+ -32768 when underflow occurs.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] sub() function in basicop2.c, UMTS GSM AMR speech codec, R99 -
+ Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+
+ PSEUDO-CODE
+
+ Word16 sub (Word16 var1, Word16 var2)
+ {
+ Word16 var_out;
+ Word32 diff;
+
+ diff = (Word32) var1 - var2;
+
+* The reference ETSI code uses a global flag for Overflow inside the function
+* saturate(). In the actual implementation a pointer to Overflow flag is passed
+* in as a parameter to the function
+
+ var_out = saturate (diff);
+
+ #if (WMOPS)
+ multiCounter[currCounter].sub++;
+ #endif
+
+ return (var_out);
+ }
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+#ifdef __clang__
+__attribute__((no_sanitize("integer")))
+#endif
+Word16 sub(Word16 var1, Word16 var2, Flag *pOverflow)
+{
+
+ Word32 diff;
+
+ diff = (Word32) var1 - var2;
+
+ /* Saturate result (if necessary). */
+ /* Replaced function call with in-line code */
+ /* to conserve MIPS, i.e., var_out = saturate (diff) */
+
+
+ if ((UWord32)(diff - 0xFFFF8000L) > 0x000FFFF)
+ {
+ if (diff > (Word32) 0x0007FFFL)
+ {
+ diff = MAX_16;
+ }
+ else
+ {
+ diff = MIN_16;
+ }
+
+ *pOverflow = 1;
+ }
+
+
+ return ((Word16) diff);
+}
diff --git a/media/codecs/amrnb/common/src/syn_filt.cpp b/media/codecs/amrnb/common/src/syn_filt.cpp
new file mode 100644
index 0000000..36c1d84
--- /dev/null
+++ b/media/codecs/amrnb/common/src/syn_filt.cpp
@@ -0,0 +1,401 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/syn_filt.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Making changes based on comments from the review meeting.
+
+ Description: Added typedef to Input/Output Definition section.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template.
+
+ Description: Fixed typecasting issue with the TI C compiler.
+
+ Description: Modified FOR loops to count down.
+
+ Description: Modified FOR loop to count up again so that the correct values
+ are stored in the tmp buffer. Updated copyright year.
+
+ Description:
+ - Modified for loop and introduced pointers to avoid adding
+ offsets
+ - Eliminated check for saturation given that the max values of input
+ data and coefficients will not saturate the multiply and
+ accumulation
+ - eliminated memcpy to update history buffer in every pass. This is
+ done now just updating the pointers.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Unrolled loops to process twice as many samples as before,
+ this saves on memory accesses to the vector coeff. a[] and
+ elements in the history buffer of this recursive filter
+
+ Description:
+ 1. Added overflow check inside both loops. (this is needed just
+ to satisfy bit exactness on the decoder, a faster
+ implementation will add an extra shift, do the same,
+ but will not be bit exact, and it may have better audio
+ quality because will avoid clipping)
+ 2. Added include file for constant definitions
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Using fxp_arithmetic.h that includes inline assembly functions
+ for ARM and linux-arm.
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include <string.h>
+
+#include "syn_filt.h"
+#include "cnst.h"
+#include "basic_op.h"
+
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Syn_filt
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ a = buffer containing the prediction coefficients (Word16) max 2^12
+ x = input signal buffer (Word16) max 2^15
+ y = output signal buffer (Word16)
+ lg = size of filtering (Word16)
+ mem = memory buffer associated with this filtering (Word16)
+ update = flag to indicate memory update; 0=no update, 1=update memory
+ (Word16)
+
+ Outputs:
+ mem buffer is changed to be the last M data points of the output signal
+ if update was set to 1
+ y buffer contains the newly calculated filter output
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Perform synthesis filtering through 1/A(z)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ syn_filt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Syn_filt (
+ Word16 a[], // (i) : a[M+1] prediction coefficients (M=10)
+ Word16 x[], // (i) : input signal
+ Word16 y[], // (o) : output signal
+ Word16 lg, // (i) : size of filtering
+ Word16 mem[], // (i/o) : memory associated with this filtering.
+ Word16 update // (i) : 0=no update, 1=update of memory.
+)
+{
+ Word16 i, j;
+ Word32 s;
+ Word16 tmp[80]; // This is usually done by memory allocation (lg+M)
+ Word16 *yy;
+
+ // Copy mem[] to yy[]
+
+ yy = tmp;
+
+ for (i = 0; i < M; i++)
+ {
+ *yy++ = mem[i];
+ }
+
+ // Do the filtering.
+
+ for (i = 0; i < lg; i++)
+ {
+ s = L_mult (x[i], a[0]);
+ for (j = 1; j <= M; j++)
+ {
+ s = L_msu (s, a[j], yy[-j]);
+ }
+ s = L_shl (s, 3);
+ *yy++ = pv_round (s);
+ }
+
+ for (i = 0; i < lg; i++)
+ {
+ y[i] = tmp[i + M];
+ }
+
+ // Update of memory if update==1
+
+ if (update != 0)
+ {
+ for (i = 0; i < M; i++)
+ {
+ mem[i] = y[lg - M + i];
+ }
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+#ifdef __clang__
+__attribute__((no_sanitize("integer")))
+#endif
+void Syn_filt(
+ Word16 a[], /* (i) : a[M+1] prediction coefficients (M=10) */
+ Word16 x[], /* (i) : input signal */
+ Word16 y[], /* (o) : output signal */
+ Word16 lg, /* (i) : size of filtering (40) */
+ Word16 mem[], /* (i/o) : memory associated with this filtering. */
+ Word16 update /* (i) : 0=no update, 1=update of memory. */
+)
+{
+ Word16 i, j;
+ Word32 s1;
+ Word32 s2;
+ Word16 tmp[2*M]; /* This is usually done by memory allocation (lg+M) */
+ Word16 *yy;
+
+ Word16 *p_a;
+ Word16 *p_yy1;
+ Word16 *p_y;
+ Word16 *p_x;
+ Word16 temp;
+ /* Copy mem[] to yy[] */
+
+ yy = tmp;
+
+ memcpy(yy, mem, M*sizeof(Word16));
+
+ yy = yy + M;
+
+ /* Do the filtering. */
+
+ p_y = y;
+ p_x = x;
+ p_yy1 = &yy[-1];
+
+ for (i = M >> 1; i != 0; i--)
+ {
+ p_a = a;
+
+ s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a), 0x00000800L);
+ s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a++), 0x00000800L);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+
+ for (j = (M >> 1) - 2; j != 0; j--)
+ {
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+ }
+
+ /* check for overflow on s1 */
+ if ((UWord32)(s1 - 0xf8000000L) < 0x0fffffffL)
+ {
+ temp = (Word16)(s1 >> 12);
+ }
+ else if (s1 > 0x07ffffffL)
+ {
+ temp = MAX_16;
+ }
+ else
+ {
+ temp = MIN_16;
+ }
+
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32)a[1], (Word32)temp, s2);
+
+ *(yy++) = temp;
+ *(p_y++) = temp;
+
+ p_yy1 = yy;
+
+ /* check for overflow on s2 */
+ if ((UWord32)(s2 - 0xf8000000L) < 0x0fffffffL)
+ {
+ temp = (Word16)(s2 >> 12);
+ }
+ else if (s2 > 0x07ffffffL)
+ {
+ temp = MAX_16;
+ }
+ else
+ {
+ temp = MIN_16;
+ }
+
+ *(yy++) = temp;
+ *(p_y++) = temp;
+ }
+
+ p_yy1 = &y[M-1];
+
+ for (i = (lg - M) >> 1; i != 0; i--)
+ {
+ p_a = a;
+
+ s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a), 0x00000800L);
+ s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_a++), 0x00000800L);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+
+ for (j = (M >> 1) - 2; j != 0; j--)
+ {
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a), (Word32) * (p_yy1--), s2);
+ s1 = amrnb_fxp_msu_16_by_16bb((Word32) * (p_a++), (Word32) * (p_yy1), s1);
+ }
+
+ if ((UWord32)(s1 - 0xf8000000L) < 0x0fffffffL)
+ {
+ temp = (Word16)(s1 >> 12);
+ }
+ else if (s1 > 0x07ffffffL)
+ {
+ temp = MAX_16;
+ }
+ else
+ {
+ temp = MIN_16;
+ }
+
+ s2 = amrnb_fxp_msu_16_by_16bb((Word32)a[1], (Word32)temp, s2);
+
+ *(p_y++) = temp;
+ p_yy1 = p_y;
+
+ if ((UWord32)(s2 - 0xf8000000L) < 0x0fffffffL)
+ {
+ *(p_y++) = (Word16)(s2 >> 12);
+ }
+ else if (s2 > 0x07ffffffL)
+ {
+ *(p_y++) = MAX_16;
+ }
+ else
+ {
+ *(p_y++) = MIN_16;
+ }
+ }
+
+ /* Update of memory if update==1 */
+ if (update != 0)
+ {
+ memcpy(mem, &y[lg-M], M*sizeof(Word16));
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/common/src/vad1.cpp b/media/codecs/amrnb/common/src/vad1.cpp
new file mode 100644
index 0000000..a6e1131
--- /dev/null
+++ b/media/codecs/amrnb/common/src/vad1.cpp
@@ -0,0 +1,2330 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: ./audio/gsm-amr/c/src/vad1.c
+ Functions:
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Made changes per review comments
+ (1) Removed include of "count.h"
+ (2) Replaced "basic_op.h" with individual include files
+ (3) Removed some unnecessary instances of sub().
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "vad.h"
+#include "typedef.h"
+#include "shr.h"
+#include "basic_op.h"
+#include "cnst_vad.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: first_filter_stage
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ data -- array of type Word16 -- filter memory
+ in -- array of type Word16 -- input signal
+
+ Outputs:
+ data -- array of type Word16 -- filter memory
+ out -- array of type Word16 -- output values, every other
+ output is low-pass part and
+ other is high-pass part every
+
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Scale input down by one bit. Calculate 5th order
+ half-band lowpass/highpass filter pair with
+ decimation.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void first_filter_stage(
+ Word16 in[], /* i : input signal */
+ Word16 out[], /* o : output values, every other */
+ /* output is low-pass part and */
+ /* other is high-pass part every */
+ Word16 data[], /* i/o : filter memory */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 temp0;
+ Word16 temp1;
+ Word16 temp2;
+ Word16 temp3;
+ Word16 i;
+ Word16 data0;
+ Word16 data1;
+
+ data0 = data[0];
+ data1 = data[1];
+
+ for (i = 0; i < FRAME_LEN / 4; i++)
+ {
+ temp0 = mult(COEFF5_1, data0, pOverflow);
+ temp1 = shr(in[4*i+0], 2, pOverflow);
+ temp0 = sub(temp1, temp0, pOverflow);
+
+ temp1 = mult(COEFF5_1, temp0, pOverflow);
+ temp1 = add(data0, temp1, pOverflow);
+
+ temp3 = mult(COEFF5_2, data1, pOverflow);
+ temp2 = shr(in[4*i+1], 2, pOverflow);
+
+ temp3 = sub(temp2, temp3, pOverflow);
+
+ temp2 = mult(COEFF5_2, temp3, pOverflow);
+ temp2 = add(data1, temp2, pOverflow);
+
+ out[4*i+0] = add(temp1, temp2, pOverflow);
+ out[4*i+1] = sub(temp1, temp2, pOverflow);
+
+ temp1 = mult(COEFF5_1, temp0, pOverflow);
+ temp2 = shr(in[4*i+2], 2, pOverflow);
+ data0 = sub(temp2, temp1, pOverflow);
+
+ temp1 = mult(COEFF5_1, data0, pOverflow);
+ temp1 = add(temp0, temp1, pOverflow);
+
+ data1 = mult(COEFF5_2, temp3, pOverflow);
+ temp2 = shr(in[4*i+3], 2, pOverflow);
+ data1 = sub(temp2, data1, pOverflow);
+
+ temp2 = mult(COEFF5_2, data1, pOverflow);
+ temp2 = add(temp3, temp2, pOverflow);
+
+ out[4*i+2] = add(temp1, temp2, pOverflow);
+ out[4*i+3] = sub(temp1, temp2, pOverflow);
+ }
+
+ data[0] = data0;
+ data[1] = data1;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: filter5
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ in0 -- array of type Word16 -- input values; output low-pass part
+ in1 -- array of type Word16 -- input values; output high-pass part
+ data -- array of type Word16 -- updated filter memory
+
+ Outputs:
+ in0 -- array of type Word16 -- input values; output low-pass part
+ in1 -- array of type Word16 -- input values; output high-pass part
+ data -- array of type Word16 -- updated filter memory
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Fifth-order half-band lowpass/highpass filter pair with
+ decimation.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void filter5(Word16 *in0, /* i/o : input values; output low-pass part */
+ Word16 *in1, /* i/o : input values; output high-pass part */
+ Word16 data[], /* i/o : updated filter memory */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ )
+{
+ Word16 temp0;
+ Word16 temp1;
+ Word16 temp2;
+
+ temp0 = mult(COEFF5_1, data[0], pOverflow);
+ temp0 = sub(*in0, temp0, pOverflow);
+
+ temp1 = mult(COEFF5_1, temp0, pOverflow);
+ temp1 = add(data[0], temp1, pOverflow);
+ data[0] = temp0;
+
+ temp0 = mult(COEFF5_2, data[1], pOverflow);
+ temp0 = sub(*in1, temp0, pOverflow);
+
+ temp2 = mult(COEFF5_2, temp0, pOverflow);
+ temp2 = add(data[1], temp2, pOverflow);
+
+ data[1] = temp0;
+
+ temp0 = add(temp1, temp2, pOverflow);
+ *in0 = shr(temp0, 1, pOverflow);
+
+ temp0 = sub(temp1, temp2, pOverflow);
+ *in1 = shr(temp0, 1, pOverflow);
+}
+
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: filter3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+ Inputs:
+ in0 -- array of type Word16 -- input values; output low-pass part
+ in1 -- array of type Word16 -- input values; output high-pass part
+ data -- array of type Word16 -- updated filter memory
+
+ Outputs:
+ in0 -- array of type Word16 -- input values; output low-pass part
+ in1 -- array of type Word16 -- input values; output high-pass part
+ data -- array of type Word16 -- updated filter memory
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Third-order half-band lowpass/highpass filter pair with
+ decimation.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void filter3(
+ Word16 *in0, /* i/o : input values; output low-pass part */
+ Word16 *in1, /* i/o : input values; output high-pass part */
+ Word16 *data, /* i/o : updated filter memory */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 temp1;
+ Word16 temp2;
+
+ temp1 = mult(COEFF3, *data, pOverflow);
+ temp1 = sub(*in1, temp1, pOverflow);
+
+ temp2 = mult(COEFF3, temp1, pOverflow);
+ temp2 = add(*data, temp2, pOverflow);
+
+ *data = temp1;
+
+ temp1 = sub(*in0, temp2, pOverflow);
+
+ *in1 = shr(temp1, 1, pOverflow);
+
+ temp1 = add(*in0, temp2, pOverflow);
+
+ *in0 = shr(temp1, 1, pOverflow);
+}
+
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: level_calculation
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ data -- array of type Word16 -- signal buffer
+ sub_level -- pointer to type Word16 -- level calculated at the end of
+ the previous frame
+
+ count1 -- Word16 -- number of samples to be counted
+ count2 -- Word16 -- number of samples to be counted
+ ind_m -- Word16 -- step size for the index of the data buffer
+ ind_a -- Word16 -- starting index of the data buffer
+ scale -- Word16 -- scaling for the level calculation
+
+ Outputs:
+ sub_level -- pointer to tyep Word16 -- level of signal calculated from the
+ last (count2 - count1) samples.
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ signal level
+
+ Global Variables Used:
+
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Calculate signal level in a sub-band. Level is calculated
+ by summing absolute values of the input data.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 level_calculation(
+ Word16 data[], /* i : signal buffer */
+ Word16 *sub_level, /* i : level calculate at the end of */
+ /* the previous frame */
+ /* o : level of signal calculated from the last */
+ /* (count2 - count1) samples */
+ Word16 count1, /* i : number of samples to be counted */
+ Word16 count2, /* i : number of samples to be counted */
+ Word16 ind_m, /* i : step size for the index of the data buffer */
+ Word16 ind_a, /* i : starting index of the data buffer */
+ Word16 scale, /* i : scaling for the level calculation */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word32 l_temp1;
+ Word32 l_temp2;
+ Word16 level;
+ Word16 i;
+
+ l_temp1 = 0L;
+
+ for (i = count1; i < count2; i++)
+ {
+ l_temp1 = L_mac(l_temp1, 1, abs_s(data[ind_m*i+ind_a]), pOverflow);
+ }
+
+ l_temp2 = L_add(l_temp1, L_shl(*sub_level, sub(16, scale, pOverflow), pOverflow), pOverflow);
+ *sub_level = extract_h(L_shl(l_temp1, scale, pOverflow));
+
+ for (i = 0; i < count1; i++)
+ {
+ l_temp2 = L_mac(l_temp2, 1, abs_s(data[ind_m*i+ind_a]), pOverflow);
+ }
+ level = extract_h(L_shl(l_temp2, scale, pOverflow));
+
+ return level;
+}
+
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: filter_bank
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ in -- array of type Word16 -- input frame
+
+ Outputs:
+ level -- array of type Word16 -- signal levels at each band
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Divides input signal into 9-bands and calculas level of
+ the signal in each band
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void filter_bank(
+ vadState1 *st, /* i/o : State struct */
+ Word16 in[], /* i : input frame */
+ Word16 level[], /* 0 : signal levels at each band */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 tmp_buf[FRAME_LEN];
+
+ /* calculate the filter bank */
+
+ first_filter_stage(in, tmp_buf, st->a_data5[0], pOverflow);
+
+ for (i = 0; i < FRAME_LEN / 4; i++)
+ {
+ filter5(&tmp_buf[4*i], &tmp_buf[4*i+2], st->a_data5[1], pOverflow);
+ filter5(&tmp_buf[4*i+1], &tmp_buf[4*i+3], st->a_data5[2], pOverflow);
+ }
+ for (i = 0; i < FRAME_LEN / 8; i++)
+ {
+ filter3(&tmp_buf[8*i+0], &tmp_buf[8*i+4], &st->a_data3[0], pOverflow);
+ filter3(&tmp_buf[8*i+2], &tmp_buf[8*i+6], &st->a_data3[1], pOverflow);
+ filter3(&tmp_buf[8*i+3], &tmp_buf[8*i+7], &st->a_data3[4], pOverflow);
+ }
+
+ for (i = 0; i < FRAME_LEN / 16; i++)
+ {
+ filter3(&tmp_buf[16*i+0], &tmp_buf[16*i+8], &st->a_data3[2], pOverflow);
+ filter3(&tmp_buf[16*i+4], &tmp_buf[16*i+12], &st->a_data3[3], pOverflow);
+ }
+
+ /* calculate levels in each frequency band */
+
+ /* 3000 - 4000 Hz*/
+ level[8] = level_calculation(tmp_buf, &st->sub_level[8], FRAME_LEN / 4 - 8,
+ FRAME_LEN / 4, 4, 1, 15, pOverflow);
+ /* 2500 - 3000 Hz*/
+ level[7] = level_calculation(tmp_buf, &st->sub_level[7], FRAME_LEN / 8 - 4,
+ FRAME_LEN / 8, 8, 7, 16, pOverflow);
+ /* 2000 - 2500 Hz*/
+ level[6] = level_calculation(tmp_buf, &st->sub_level[6], FRAME_LEN / 8 - 4,
+ FRAME_LEN / 8, 8, 3, 16, pOverflow);
+ /* 1500 - 2000 Hz*/
+ level[5] = level_calculation(tmp_buf, &st->sub_level[5], FRAME_LEN / 8 - 4,
+ FRAME_LEN / 8, 8, 2, 16, pOverflow);
+ /* 1000 - 1500 Hz*/
+ level[4] = level_calculation(tmp_buf, &st->sub_level[4], FRAME_LEN / 8 - 4,
+ FRAME_LEN / 8, 8, 6, 16, pOverflow);
+ /* 750 - 1000 Hz*/
+ level[3] = level_calculation(tmp_buf, &st->sub_level[3], FRAME_LEN / 16 - 2,
+ FRAME_LEN / 16, 16, 4, 16, pOverflow);
+ /* 500 - 750 Hz*/
+ level[2] = level_calculation(tmp_buf, &st->sub_level[2], FRAME_LEN / 16 - 2,
+ FRAME_LEN / 16, 16, 12, 16, pOverflow);
+ /* 250 - 500 Hz*/
+ level[1] = level_calculation(tmp_buf, &st->sub_level[1], FRAME_LEN / 16 - 2,
+ FRAME_LEN / 16, 16, 8, 16, pOverflow);
+ /* 0 - 250 Hz*/
+ level[0] = level_calculation(tmp_buf, &st->sub_level[0], FRAME_LEN / 16 - 2,
+ FRAME_LEN / 16, 16, 0, 16, pOverflow);
+}
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: update_cntrl
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ level -- array of type Word16 -- sub-band levels of the input frame
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Control update of the background noise estimate.
+ Inputs : pitch: flags for pitch detection
+ stat_count: stationary counter
+ tone: flags indicating presence of a tone
+ complex: flags for complex detection
+ vadreg: intermediate VAD flags
+ Output : stat_count: stationary counter
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void update_cntrl(
+ vadState1 *st, /* i/o : State struct */
+ Word16 level[], /* i : sub-band levels of the input frame */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 temp;
+ Word16 stat_rat;
+ Word16 exp;
+ Word16 num;
+ Word16 denom;
+ Word16 alpha;
+
+ /* handle highband complex signal input separately */
+ /* if ther has been highband correlation for some time */
+ /* make sure that the VAD update speed is low for a while */
+ if (st->complex_warning != 0)
+ {
+ if (st->stat_count < CAD_MIN_STAT_COUNT)
+ {
+ st->stat_count = CAD_MIN_STAT_COUNT;
+ }
+ }
+ /* NB stat_count is allowed to be decreased by one below again */
+ /* deadlock in speech is not possible unless the signal is very */
+ /* complex and need a high rate */
+
+ /* if fullband pitch or tone have been detected for a while, initialize stat_count */
+ if (((Word16)(st->pitch & 0x6000) == 0x6000) ||
+ ((Word16)(st->tone & 0x7c00) == 0x7c00))
+ {
+ st->stat_count = STAT_COUNT;
+ }
+ else
+ {
+ /* if 8 last vad-decisions have been "0", reinitialize stat_count */
+ if ((st->vadreg & 0x7f80) == 0)
+ {
+ st->stat_count = STAT_COUNT;
+ }
+ else
+ {
+ stat_rat = 0;
+ for (i = 0; i < COMPLEN; i++)
+ {
+ if (level[i] > st->ave_level[i])
+ {
+ num = level[i];
+ denom = st->ave_level[i];
+ }
+ else
+ {
+ num = st->ave_level[i];
+ denom = level[i];
+ }
+ /* Limit nimimum value of num and denom to STAT_THR_LEVEL */
+ if (num < STAT_THR_LEVEL)
+ {
+ num = STAT_THR_LEVEL;
+ }
+ if (denom < STAT_THR_LEVEL)
+ {
+ denom = STAT_THR_LEVEL;
+ }
+
+ exp = norm_s(denom);
+
+ denom = shl(denom, exp, pOverflow);
+
+ /* stat_rat = num/denom * 64 */
+ temp = shr(num, 1, pOverflow);
+ temp = div_s(temp, denom);
+
+ stat_rat = add(stat_rat, shr(temp, sub(8, exp, pOverflow), pOverflow), pOverflow);
+ }
+
+ /* compare stat_rat with a threshold and update stat_count */
+ if (stat_rat > STAT_THR)
+ {
+ st->stat_count = STAT_COUNT;
+ }
+ else
+ {
+ if ((st->vadreg & 0x4000) != 0)
+ {
+ if (st->stat_count != 0)
+ {
+ st->stat_count = sub(st->stat_count, 1, pOverflow);
+ }
+ }
+ }
+ }
+ }
+
+ /* Update average amplitude estimate for stationarity estimation */
+ alpha = ALPHA4;
+ if (st->stat_count == STAT_COUNT)
+ {
+ alpha = 32767;
+ }
+ else if ((st->vadreg & 0x4000) == 0)
+ {
+ alpha = ALPHA5;
+ }
+
+ for (i = 0; i < COMPLEN; i++)
+ {
+ temp = sub(level[i], st->ave_level[i], pOverflow);
+ temp = mult_r(alpha, temp, pOverflow);
+
+ st->ave_level[i] =
+ add(
+ st->ave_level[i],
+ temp,
+ pOverflow);
+ }
+}
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: hangover_addition
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ noise_level -- Word16 -- average level of the noise estimates
+ low_power -- Word16 -- flag power of the input frame
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicato
+
+ Returns:
+ VAD_flag indicating final VAD decision (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function : hangover_addition
+ Purpose : Add hangover for complex signal or after speech bursts
+ Inputs : burst_count: counter for the length of speech bursts
+ hang_count: hangover counter
+ vadreg: intermediate VAD decision
+ Outputs : burst_count: counter for the length of speech bursts
+ hang_count: hangover counter
+ Return value : VAD_flag indicating final VAD decision
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 hangover_addition(
+ vadState1 *st, /* i/o : State struct */
+ Word16 noise_level, /* i : average level of the noise */
+ /* estimates */
+ Word16 low_power, /* i : flag power of the input frame */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 hang_len;
+ Word16 burst_len;
+
+ /*
+ Calculate burst_len and hang_len
+ burst_len: number of consecutive intermediate vad flags with "1"-decision
+ required for hangover addition
+ hang_len: length of the hangover
+ */
+
+ if (noise_level > HANG_NOISE_THR)
+ {
+ burst_len = BURST_LEN_HIGH_NOISE;
+ hang_len = HANG_LEN_HIGH_NOISE;
+ }
+ else
+ {
+ burst_len = BURST_LEN_LOW_NOISE;
+ hang_len = HANG_LEN_LOW_NOISE;
+ }
+
+ /* if the input power (pow_sum) is lower than a threshold, clear
+ counters and set VAD_flag to "0" "fast exit" */
+ if (low_power != 0)
+ {
+ st->burst_count = 0;
+ st->hang_count = 0;
+ st->complex_hang_count = 0;
+ st->complex_hang_timer = 0;
+ return 0;
+ }
+
+ if (st->complex_hang_timer > CVAD_HANG_LIMIT)
+ {
+ if (st->complex_hang_count < CVAD_HANG_LENGTH)
+ {
+ st->complex_hang_count = CVAD_HANG_LENGTH;
+ }
+ }
+
+ /* long time very complex signal override VAD output function */
+ if (st->complex_hang_count != 0)
+ {
+ st->burst_count = BURST_LEN_HIGH_NOISE;
+ st->complex_hang_count = sub(st->complex_hang_count, 1, pOverflow);
+ return 1;
+ }
+ else
+ {
+ /* let hp_corr work in from a noise_period indicated by the VAD */
+ if (((st->vadreg & 0x3ff0) == 0) &&
+ (st->corr_hp_fast > CVAD_THRESH_IN_NOISE))
+ {
+ return 1;
+ }
+ }
+
+ /* update the counters (hang_count, burst_count) */
+ if ((st->vadreg & 0x4000) != 0)
+ {
+ st->burst_count = add(st->burst_count, 1, pOverflow);
+
+ if (st->burst_count >= burst_len)
+ {
+ st->hang_count = hang_len;
+ }
+ return 1;
+ }
+ else
+ {
+ st->burst_count = 0;
+ if (st->hang_count > 0)
+ {
+ st->hang_count = sub(st->hang_count, 1, pOverflow);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: noise_estimate_update
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ level -- array of type Word16 -- sub-band levels of the input frame
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Update of background noise estimate
+ Inputs : bckr_est: background noise estimate
+ pitch: flags for pitch detection
+ stat_count: stationary counter
+ Outputs : bckr_est: background noise estimate
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void noise_estimate_update(
+ vadState1 *st, /* i/o : State struct */
+ Word16 level[], /* i : sub-band levels of the input frame */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 alpha_up;
+ Word16 alpha_down;
+ Word16 bckr_add;
+
+ /* Control update of bckr_est[] */
+ update_cntrl(st, level, pOverflow);
+
+ /* Choose update speed */
+ bckr_add = 2;
+
+ if (((0x7800 & st->vadreg) == 0) &&
+ ((st->pitch & 0x7800) == 0)
+ && (st->complex_hang_count == 0))
+ {
+ alpha_up = ALPHA_UP1;
+ alpha_down = ALPHA_DOWN1;
+ }
+ else
+ {
+ if ((st->stat_count == 0)
+ && (st->complex_hang_count == 0))
+ {
+ alpha_up = ALPHA_UP2;
+ alpha_down = ALPHA_DOWN2;
+ }
+ else
+ {
+ alpha_up = 0;
+ alpha_down = ALPHA3;
+ bckr_add = 0;
+ }
+ }
+
+ /* Update noise estimate (bckr_est) */
+ for (i = 0; i < COMPLEN; i++)
+ {
+ Word16 temp;
+
+ temp = sub(st->old_level[i], st->bckr_est[i], pOverflow);
+
+ if (temp < 0)
+ { /* update downwards*/
+ temp = mult_r(alpha_down, temp, pOverflow);
+ temp = add(st->bckr_est[i], temp, pOverflow);
+
+ st->bckr_est[i] = add(-2, temp, pOverflow);
+
+ /* limit minimum value of the noise estimate to NOISE_MIN */
+ if (st->bckr_est[i] < NOISE_MIN)
+ {
+ st->bckr_est[i] = NOISE_MIN;
+ }
+ }
+ else
+ { /* update upwards */
+ temp = mult_r(alpha_up, temp, pOverflow);
+ temp = add(st->bckr_est[i], temp, pOverflow);
+ st->bckr_est[i] = add(bckr_add, temp, pOverflow);
+
+ /* limit maximum value of the noise estimate to NOISE_MAX */
+ if (st->bckr_est[i] > NOISE_MAX)
+ {
+ st->bckr_est[i] = NOISE_MAX;
+ }
+ }
+ }
+
+ /* Update signal levels of the previous frame (old_level) */
+ for (i = 0; i < COMPLEN; i++)
+ {
+ st->old_level[i] = level[i];
+ }
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: complex_estimate_adapt
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ low_power -- Word16 -- very low level flag of the input frame
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function : complex_estimate_adapt
+ Purpose : Update/adapt of complex signal estimate
+ Inputs : low_power: low signal power flag
+ Outputs : st->corr_hp_fast: long term complex signal estimate
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void complex_estimate_adapt(
+ vadState1 *st, /* i/o : VAD state struct */
+ Word16 low_power, /* i : very low level flag of the input frame */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 alpha; /* Q15 */
+ Word32 L_tmp; /* Q31 */
+
+
+ /* adapt speed on own state */
+ if (st->best_corr_hp < st->corr_hp_fast) /* decrease */
+ {
+ if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH)
+ { /* low state */
+ alpha = CVAD_ADAPT_FAST;
+ }
+ else
+ { /* high state */
+ alpha = CVAD_ADAPT_REALLY_FAST;
+ }
+ }
+ else /* increase */
+ {
+ if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH)
+ {
+ alpha = CVAD_ADAPT_FAST;
+ }
+ else
+ {
+ alpha = CVAD_ADAPT_SLOW;
+ }
+ }
+
+ L_tmp = L_deposit_h(st->corr_hp_fast);
+ L_tmp = L_msu(L_tmp, alpha, st->corr_hp_fast, pOverflow);
+ L_tmp = L_mac(L_tmp, alpha, st->best_corr_hp, pOverflow);
+ st->corr_hp_fast = pv_round(L_tmp, pOverflow); /* Q15 */
+
+ if (st->corr_hp_fast < CVAD_MIN_CORR)
+ {
+ st->corr_hp_fast = CVAD_MIN_CORR;
+ }
+
+ if (low_power != 0)
+ {
+ st->corr_hp_fast = CVAD_MIN_CORR;
+ }
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: complex_vad
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ low_power -- Word16 -- flag power of the input frame
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+
+ Returns:
+ the complex background decision
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : complex background decision
+ Return value : the complex background decision
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 complex_vad(
+ vadState1 *st, /* i/o : VAD state struct */
+ Word16 low_power, /* i : flag power of the input frame */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ st->complex_high = shr(st->complex_high, 1, pOverflow);
+ st->complex_low = shr(st->complex_low, 1, pOverflow);
+
+ if (low_power == 0)
+ {
+ if (st->corr_hp_fast > CVAD_THRESH_ADAPT_HIGH)
+ {
+ st->complex_high |= 0x4000;
+ }
+
+ if (st->corr_hp_fast > CVAD_THRESH_ADAPT_LOW)
+ {
+ st->complex_low |= 0x4000;
+ }
+ }
+
+ if (st->corr_hp_fast > CVAD_THRESH_HANG)
+ {
+ st->complex_hang_timer = add(st->complex_hang_timer, 1, pOverflow);
+ }
+ else
+ {
+ st->complex_hang_timer = 0;
+ }
+
+ return ((Word16)(st->complex_high & 0x7f80) == 0x7f80 ||
+ (Word16)(st->complex_low & 0x7fff) == 0x7fff);
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad_decision
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ level -- array of type Word16 -- sub-band levels of the input frame
+ pow_sum -- Word32 -- power of the input frame
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ VAD_flag (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Calculates VAD_flag
+ Inputs : bckr_est: background noise estimate
+ vadreg: intermediate VAD flags
+ Outputs : noise_level: average level of the noise estimates
+ vadreg: intermediate VAD flags
+ Return value : VAD_flag
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 vad_decision(
+ vadState1 *st, /* i/o : State struct */
+ Word16 level[COMPLEN], /* i : sub-band levels of the input frame */
+ Word32 pow_sum, /* i : power of the input frame */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 snr_sum;
+ Word32 L_temp;
+ Word16 vad_thr;
+ Word16 temp;
+ Word16 noise_level;
+ Word16 low_power_flag;
+ Word16 temp1;
+
+ /*
+ Calculate squared sum of the input levels (level)
+ divided by the background noise components (bckr_est).
+ */
+ L_temp = 0;
+
+ for (i = 0; i < COMPLEN; i++)
+ {
+ Word16 exp;
+
+ exp = norm_s(st->bckr_est[i]);
+ temp = shl(st->bckr_est[i], exp, pOverflow);
+ temp = div_s(shr(level[i], 1, pOverflow), temp);
+ temp = shl(temp, sub(exp, UNIRSHFT - 1, pOverflow), pOverflow);
+ L_temp = L_mac(L_temp, temp, temp, pOverflow);
+ }
+
+ snr_sum = extract_h(L_shl(L_temp, 6, pOverflow));
+ snr_sum = mult(snr_sum, INV_COMPLEN, pOverflow);
+
+ /* Calculate average level of estimated background noise */
+ L_temp = 0;
+ for (i = 0; i < COMPLEN; i++)
+ {
+ L_temp = L_add(L_temp, st->bckr_est[i], pOverflow);
+ }
+
+ noise_level = extract_h(L_shl(L_temp, 13, pOverflow));
+
+ /* Calculate VAD threshold */
+ temp1 = sub(noise_level, VAD_P1, pOverflow);
+ temp1 = mult(VAD_SLOPE, temp1, pOverflow);
+ vad_thr = add(temp1, VAD_THR_HIGH, pOverflow);
+
+ if (vad_thr < VAD_THR_LOW)
+ {
+ vad_thr = VAD_THR_LOW;
+ }
+
+ /* Shift VAD decision register */
+ st->vadreg = shr(st->vadreg, 1, pOverflow);
+
+ /* Make intermediate VAD decision */
+ if (snr_sum > vad_thr)
+ {
+ st->vadreg |= 0x4000;
+ }
+ /* primary vad decsion made */
+
+ /* check if the input power (pow_sum) is lower than a threshold" */
+ if (L_sub(pow_sum, VAD_POW_LOW, pOverflow) < 0)
+ {
+ low_power_flag = 1;
+ }
+ else
+ {
+ low_power_flag = 0;
+ }
+
+ /* update complex signal estimate st->corr_hp_fast and hangover reset timer using */
+ /* low_power_flag and corr_hp_fast and various adaptation speeds */
+ complex_estimate_adapt(st, low_power_flag, pOverflow);
+
+ /* check multiple thresholds of the st->corr_hp_fast value */
+ st->complex_warning = complex_vad(st, low_power_flag, pOverflow);
+
+ /* Update speech subband vad background noise estimates */
+ noise_estimate_update(st, level, pOverflow);
+
+ /* Add speech and complex hangover and return speech VAD_flag */
+ /* long term complex hangover may be added */
+ st->speech_vad_decision = hangover_addition(st, noise_level, low_power_flag, pOverflow);
+
+ return (st->speech_vad_decision);
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad1_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state -- double pointer to type vadState1 -- pointer to memory to
+ be initialized.
+
+ Outputs:
+ state -- points to initalized area in memory.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Allocates state memory and initializes state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 vad1_init(vadState1 **state)
+{
+ vadState1* s;
+
+ if (state == (vadState1 **) NULL)
+ {
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (vadState1 *) malloc(sizeof(vadState1))) == NULL)
+ {
+ return -1;
+ }
+
+ vad1_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad1_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state -- pointer to type vadState1 -- State struct
+
+ Outputs:
+ state -- pointer to type vadState1 -- State struct
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose: Resets state memory to zero
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 vad1_reset(vadState1 *state)
+{
+ Word16 i;
+ Word16 j;
+
+ if (state == (vadState1 *) NULL)
+ {
+ return -1;
+ }
+
+ /* Initialize pitch detection variables */
+ state->oldlag_count = 0;
+ state->oldlag = 0;
+ state->pitch = 0;
+ state->tone = 0;
+
+ state->complex_high = 0;
+ state->complex_low = 0;
+ state->complex_hang_timer = 0;
+
+ state->vadreg = 0;
+
+ state->stat_count = 0;
+ state->burst_count = 0;
+ state->hang_count = 0;
+ state->complex_hang_count = 0;
+
+ /* initialize memory used by the filter bank */
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 2; j++)
+ {
+ state->a_data5[i][j] = 0;
+ }
+ }
+
+ for (i = 0; i < 5; i++)
+ {
+ state->a_data3[i] = 0;
+ }
+
+ /* initialize the rest of the memory */
+ for (i = 0; i < COMPLEN; i++)
+ {
+ state->bckr_est[i] = NOISE_INIT;
+ state->old_level[i] = NOISE_INIT;
+ state->ave_level[i] = NOISE_INIT;
+ state->sub_level[i] = 0;
+ }
+
+ state->best_corr_hp = CVAD_LOWPOW_RESET;
+
+ state->speech_vad_decision = 0;
+ state->complex_warning = 0;
+ state->sp_burst_count = 0;
+
+ state->corr_hp_fast = CVAD_LOWPOW_RESET;
+
+ return 0;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad1_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state -- pointer to type vadState1 -- State struct
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The memory used for state memory is freed
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void vad1_exit(vadState1 **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad_complex_detection_update
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ best_corr_hp -- Word16 -- best Corr
+ state -- pointer to type vadState1 -- State struct
+
+ Outputs:
+ state -- pointer to type vadState1 -- State struct
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : update vad->bestCorr_hp complex signal feature state
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void vad_complex_detection_update(
+ vadState1 *st, /* i/o : State struct */
+ Word16 best_corr_hp) /* i : best Corr */
+{
+ st->best_corr_hp = best_corr_hp;
+}
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad_tone_detection
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ t0 -- Word32 -- autocorrelation maxima
+ t1 -- Word32 -- energy
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Set tone flag if pitch gain is high. This is used to detect
+ signaling tones and other signals with high pitch gain.
+ Inputs : tone: flags indicating presence of a tone
+ Outputs : tone: flags indicating presence of a tone
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void vad_tone_detection(
+ vadState1 *st, /* i/o : State struct */
+ Word32 t0, /* i : autocorrelation maxima */
+ Word32 t1, /* i : energy */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 temp;
+ /*
+ if (t0 > TONE_THR * t1)
+ set tone flag
+ */
+ temp = pv_round(t1, pOverflow);
+
+ if ((temp > 0) && (L_msu(t0, temp, TONE_THR, pOverflow) > 0))
+ {
+ st->tone |= 0x4000;
+ }
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad_tone_detection_update
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ one_lag_per_frame -- Word16 -- 1 if one open-loop lag is calculated per
+ each frame, otherwise 0
+ st -- pointer to type vadState1 -- State struct
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Update the tone flag register. Tone flags are shifted right
+ by one bit. This function should be called from the speech
+ encoder before call to Vad_tone_detection() function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void vad_tone_detection_update(
+ vadState1 *st, /* i/o : State struct */
+ Word16 one_lag_per_frame, /* i : 1 if one open-loop lag */
+ /* is calculated per each */
+ /* frame, otherwise 0 */
+ Flag *pOverflow /* o : Flags overflow */
+)
+{
+ /* Shift tone flags right by one bit */
+ st->tone = shr(st->tone, 1, pOverflow);
+
+ /* If open-loop lag is calculated only once in each frame, do extra update
+ and assume that the other tone flag of the frame is one. */
+ if (one_lag_per_frame != 0)
+ {
+ st->tone = shr(st->tone, 1, pOverflow);
+ st->tone |= 0x2000;
+ }
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad_pitch_detection
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ T_op -- array of type Word16 -- speech encoder open loop lags
+ st -- pointer to type vadState1 -- State struct
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Test whether signal contains pitch or other periodic
+ component.
+ Return value : Boolean voiced / unvoiced decision in state variable
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void vad_pitch_detection(
+ vadState1 *st, /* i/o : State struct */
+ Word16 T_op[], /* i : speech encoder open loop lags */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 lagcount;
+ Word16 i;
+ Word16 temp;
+
+ lagcount = 0;
+
+ for (i = 0; i < 2; i++)
+ {
+ temp = sub(st->oldlag, T_op[i], pOverflow);
+ temp = abs_s(temp);
+
+ if (temp < LTHRESH)
+ {
+ lagcount = add(lagcount, 1, pOverflow);
+ }
+
+ /* Save the current LTP lag */
+ st->oldlag = T_op[i];
+ }
+
+ /* Make pitch decision.
+ Save flag of the pitch detection to the variable pitch.
+ */
+ st->pitch = shr(st->pitch, 1, pOverflow);
+
+ temp =
+ add(
+ st->oldlag_count,
+ lagcount,
+ pOverflow);
+
+ if (temp >= NTHRESH)
+ {
+ st->pitch |= 0x4000;
+ }
+
+ /* Update oldlagcount */
+ st->oldlag_count = lagcount;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: vad1
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to type vadState1 -- State struct
+ in_buf -- array of type Word16 -- samples of the input frame
+
+ Outputs:
+ st -- pointer to type vadState1 -- State struct
+ pOverflow -- pointer to type Flag -- overflow indicator
+
+ Returns:
+ VAD Decision, 1 = speech, 0 = noise
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Main program for Voice Activity Detection (VAD) for AMR
+ Return value : VAD Decision, 1 = speech, 0 = noise
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 vad1(
+ vadState1 *st, /* i/o : State struct */
+ Word16 in_buf[], /* i : samples of the input frame */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 level[COMPLEN];
+ Word32 pow_sum;
+ Word16 i;
+
+ /* Calculate power of the input frame. */
+ pow_sum = 0L;
+
+ for (i = 0; i < FRAME_LEN; i++)
+ {
+ pow_sum = L_mac(pow_sum, in_buf[i-LOOKAHEAD], in_buf[i-LOOKAHEAD], pOverflow);
+ }
+
+ /*
+ If input power is very low, clear pitch flag of the current frame
+ */
+ if (L_sub(pow_sum, POW_PITCH_THR, pOverflow) < 0)
+ {
+ st->pitch = st->pitch & 0x3fff;
+ }
+
+ /*
+ If input power is very low, clear complex flag of the "current" frame
+ */
+ if (L_sub(pow_sum, POW_COMPLEX_THR, pOverflow) < 0)
+ {
+ st->complex_low = st->complex_low & 0x3fff;
+ }
+
+ /*
+ Run the filter bank which calculates signal levels at each band
+ */
+ filter_bank(st, in_buf, level, pOverflow);
+
+ return (vad_decision(st, level, pow_sum, pOverflow));
+}
+
+
diff --git a/media/codecs/amrnb/common/src/weight_a.cpp b/media/codecs/amrnb/common/src/weight_a.cpp
new file mode 100644
index 0000000..ee821ef
--- /dev/null
+++ b/media/codecs/amrnb/common/src/weight_a.cpp
@@ -0,0 +1,196 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Pathname: ./audio/gsm-amr/c/src/weight_a.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Put file into template and first pass at optimization.
+
+ Description: Made changes based on comments from the review meeting. Used
+ pointers instead of index addressing in the arrays.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Fixed typecasting issue with TI C compiler.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Modified FOR loop to count down.
+ 2. Used address pre-increment instead of address offsets.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "weight_a.h"
+#include "typedef.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Weight_Ai
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ a = LPC coefficients (Word16)
+ fac = Spectral expansion factors (Word16)
+ a_exp = Spectral expanded LPC coefficients (Word16)
+
+ Outputs:
+ a_exp points to the updated spectral expanded LPC coefficients
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates the spectral expansion for the LP coefficients of
+ order M.
+ a_exp[i] = a[i] * fac[i-1] ; i=1..M
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ weight_a.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Weight_Ai (
+ Word16 a[], // (i) : a[M+1] LPC coefficients (M=10)
+ const Word16 fac[], // (i) : Spectral expansion factors.
+ Word16 a_exp[] // (o) : Spectral expanded LPC coefficients
+)
+{
+ Word16 i;
+ a_exp[0] = a[0];
+
+ for (i = 1; i <= M; i++)
+ {
+ a_exp[i] = pv_round (L_mult (a[i], fac[i - 1]));
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Weight_Ai(
+ Word16 a[], /* (i) : a[M+1] LPC coefficients (M=10) */
+ const Word16 fac[], /* (i) : Spectral expansion factors. */
+ Word16 a_exp[] /* (o) : Spectral expanded LPC coefficients */
+)
+{
+ Word16 i;
+
+ *(a_exp) = *(a);
+
+ for (i = M; i >= 1; i--)
+ {
+ a_exp += 1;
+ a += 1;
+ fac += 1;
+ *(a_exp) = (Word16)((((Word32) * (a)) * *(fac - 1)
+ + 0x00004000L) >> 15);
+ }
+
+ return;
+}
+
diff --git a/media/codecs/amrnb/common/src/window_tab.cpp b/media/codecs/amrnb/common/src/window_tab.cpp
new file mode 100644
index 0000000..d8fc8cc
--- /dev/null
+++ b/media/codecs/amrnb/common/src/window_tab.cpp
@@ -0,0 +1,281 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ Pathname: .audio/gsm-amr/c/src/window_tab.c
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed tables from static const to just const.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Who: Date:
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : window.tab
+ Purpose : Hamming_cos window for LPC analysis.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "window_tab.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ /*************************************************************************
+ *
+ * Hamming_cos windows for LPC analysis.
+ *
+ *************************************************************************/
+
+ /* window for non-EFR modesm; uses 40 samples lookahead */
+
+ const Word16 window_200_40[L_WINDOW] =
+ {
+ 2621, 2623, 2629, 2638, 2651, 2668, 2689, 2713, 2741, 2772,
+ 2808, 2847, 2890, 2936, 2986, 3040, 3097, 3158, 3223, 3291,
+ 3363, 3438, 3517, 3599, 3685, 3774, 3867, 3963, 4063, 4166,
+ 4272, 4382, 4495, 4611, 4731, 4853, 4979, 5108, 5240, 5376,
+ 5514, 5655, 5800, 5947, 6097, 6250, 6406, 6565, 6726, 6890,
+ 7057, 7227, 7399, 7573, 7750, 7930, 8112, 8296, 8483, 8672,
+ 8863, 9057, 9252, 9450, 9650, 9852, 10055, 10261, 10468, 10677,
+ 10888, 11101, 11315, 11531, 11748, 11967, 12187, 12409, 12632, 12856,
+ 13082, 13308, 13536, 13764, 13994, 14225, 14456, 14688, 14921, 15155,
+ 15389, 15624, 15859, 16095, 16331, 16568, 16805, 17042, 17279, 17516,
+ 17754, 17991, 18228, 18465, 18702, 18939, 19175, 19411, 19647, 19882,
+ 20117, 20350, 20584, 20816, 21048, 21279, 21509, 21738, 21967, 22194,
+ 22420, 22644, 22868, 23090, 23311, 23531, 23749, 23965, 24181, 24394,
+ 24606, 24816, 25024, 25231, 25435, 25638, 25839, 26037, 26234, 26428,
+ 26621, 26811, 26999, 27184, 27368, 27548, 27727, 27903, 28076, 28247,
+ 28415, 28581, 28743, 28903, 29061, 29215, 29367, 29515, 29661, 29804,
+ 29944, 30081, 30214, 30345, 30472, 30597, 30718, 30836, 30950, 31062,
+ 31170, 31274, 31376, 31474, 31568, 31659, 31747, 31831, 31911, 31988,
+ 32062, 32132, 32198, 32261, 32320, 32376, 32428, 32476, 32521, 32561,
+ 32599, 32632, 32662, 32688, 32711, 32729, 32744, 32755, 32763, 32767,
+ 32767, 32741, 32665, 32537, 32359, 32129, 31850, 31521, 31143, 30716,
+ 30242, 29720, 29151, 28538, 27879, 27177, 26433, 25647, 24821, 23957,
+ 23055, 22117, 21145, 20139, 19102, 18036, 16941, 15820, 14674, 13505,
+ 12315, 11106, 9879, 8637, 7381, 6114, 4838, 3554, 2264, 971
+ };
+
+
+ /* window for EFR, first two subframes, no lookahead */
+
+ const Word16 window_160_80[L_WINDOW] =
+ {
+ 2621, 2624, 2633, 2648, 2668, 2695, 2727, 2765, 2809, 2859,
+ 2915, 2976, 3043, 3116, 3194, 3279, 3368, 3464, 3565, 3671,
+ 3783, 3900, 4023, 4151, 4285, 4423, 4567, 4716, 4870, 5029,
+ 5193, 5362, 5535, 5714, 5897, 6084, 6277, 6473, 6674, 6880,
+ 7089, 7303, 7521, 7742, 7968, 8197, 8430, 8667, 8907, 9151,
+ 9398, 9648, 9902, 10158, 10417, 10680, 10945, 11212, 11482, 11755,
+ 12030, 12307, 12586, 12867, 13150, 13435, 13722, 14010, 14299, 14590,
+ 14882, 15175, 15469, 15764, 16060, 16356, 16653, 16950, 17248, 17546,
+ 17844, 18141, 18439, 18736, 19033, 19330, 19625, 19920, 20214, 20507,
+ 20799, 21090, 21380, 21668, 21954, 22239, 22522, 22803, 23083, 23360,
+ 23635, 23907, 24177, 24445, 24710, 24972, 25231, 25488, 25741, 25991,
+ 26238, 26482, 26722, 26959, 27192, 27422, 27647, 27869, 28087, 28300,
+ 28510, 28715, 28916, 29113, 29305, 29493, 29676, 29854, 30028, 30197,
+ 30361, 30519, 30673, 30822, 30966, 31105, 31238, 31366, 31489, 31606,
+ 31718, 31825, 31926, 32021, 32111, 32195, 32273, 32346, 32413, 32475,
+ 32530, 32580, 32624, 32662, 32695, 32721, 32742, 32756, 32765, 32767,
+ 32767, 32756, 32720, 32661, 32578, 32471, 32341, 32188, 32012, 31813,
+ 31592, 31349, 31084, 30798, 30492, 30165, 29818, 29453, 29068, 28666,
+ 28247, 27810, 27358, 26891, 26408, 25913, 25404, 24883, 24350, 23807,
+ 23255, 22693, 22124, 21548, 20965, 20378, 19786, 19191, 18593, 17994,
+ 17395, 16796, 16199, 15604, 15012, 14424, 13842, 13265, 12696, 12135,
+ 11582, 11039, 10507, 9986, 9477, 8981, 8499, 8031, 7579, 7143,
+ 6723, 6321, 5937, 5571, 5225, 4898, 4591, 4305, 4041, 3798,
+ 3577, 3378, 3202, 3048, 2918, 2812, 2729, 2669, 2633, 2621
+ };
+
+ /* window for EFR, last two subframes, no lookahead */
+
+ const Word16 window_232_8[L_WINDOW] =
+ {
+ 2621, 2623, 2627, 2634, 2644, 2656, 2671, 2689, 2710, 2734,
+ 2760, 2789, 2821, 2855, 2893, 2933, 2975, 3021, 3069, 3120,
+ 3173, 3229, 3288, 3350, 3414, 3481, 3550, 3622, 3697, 3774,
+ 3853, 3936, 4021, 4108, 4198, 4290, 4385, 4482, 4582, 4684,
+ 4788, 4895, 5004, 5116, 5230, 5346, 5464, 5585, 5708, 5833,
+ 5960, 6090, 6221, 6355, 6491, 6629, 6769, 6910, 7054, 7200,
+ 7348, 7498, 7649, 7803, 7958, 8115, 8274, 8434, 8597, 8761,
+ 8926, 9093, 9262, 9432, 9604, 9778, 9952, 10129, 10306, 10485,
+ 10665, 10847, 11030, 11214, 11399, 11586, 11773, 11962, 12152, 12342,
+ 12534, 12727, 12920, 13115, 13310, 13506, 13703, 13901, 14099, 14298,
+ 14497, 14698, 14898, 15100, 15301, 15504, 15706, 15909, 16112, 16316,
+ 16520, 16724, 16928, 17132, 17337, 17541, 17746, 17950, 18155, 18359,
+ 18564, 18768, 18972, 19175, 19379, 19582, 19785, 19987, 20189, 20390,
+ 20591, 20792, 20992, 21191, 21390, 21588, 21785, 21981, 22177, 22372,
+ 22566, 22759, 22951, 23143, 23333, 23522, 23710, 23897, 24083, 24268,
+ 24451, 24633, 24814, 24994, 25172, 25349, 25525, 25699, 25871, 26042,
+ 26212, 26380, 26546, 26711, 26874, 27035, 27195, 27353, 27509, 27664,
+ 27816, 27967, 28115, 28262, 28407, 28550, 28691, 28830, 28967, 29102,
+ 29234, 29365, 29493, 29619, 29743, 29865, 29985, 30102, 30217, 30330,
+ 30440, 30548, 30654, 30757, 30858, 30956, 31052, 31146, 31237, 31326,
+ 31412, 31495, 31576, 31655, 31730, 31804, 31874, 31942, 32008, 32071,
+ 32131, 32188, 32243, 32295, 32345, 32392, 32436, 32477, 32516, 32552,
+ 32585, 32615, 32643, 32668, 32690, 32709, 32726, 32740, 32751, 32759,
+ 32765, 32767, 32767, 32097, 30112, 26895, 22576, 17333, 11380, 4962
+ };
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/dec/Android.bp b/media/codecs/amrnb/dec/Android.bp
new file mode 100644
index 0000000..944ff75
--- /dev/null
+++ b/media/codecs/amrnb/dec/Android.bp
@@ -0,0 +1,106 @@
+cc_library_static {
+ name: "libstagefright_amrnbdec",
+ vendor_available: true,
+ host_supported: true,
+ min_sdk_version: "29",
+
+ srcs: [
+ "src/a_refl.cpp",
+ "src/agc.cpp",
+ "src/amrdecode.cpp",
+ "src/b_cn_cod.cpp",
+ "src/bgnscd.cpp",
+ "src/c_g_aver.cpp",
+ "src/d1035pf.cpp",
+ "src/d2_11pf.cpp",
+ "src/d2_9pf.cpp",
+ "src/d3_14pf.cpp",
+ "src/d4_17pf.cpp",
+ "src/d8_31pf.cpp",
+ "src/d_gain_c.cpp",
+ "src/d_gain_p.cpp",
+ "src/d_plsf.cpp",
+ "src/d_plsf_3.cpp",
+ "src/d_plsf_5.cpp",
+ "src/dec_amr.cpp",
+ "src/dec_gain.cpp",
+ "src/dec_input_format_tab.cpp",
+ "src/dec_lag3.cpp",
+ "src/dec_lag6.cpp",
+ "src/dtx_dec.cpp",
+ "src/ec_gains.cpp",
+ "src/ex_ctrl.cpp",
+ "src/if2_to_ets.cpp",
+ "src/int_lsf.cpp",
+ "src/lsp_avg.cpp",
+ "src/ph_disp.cpp",
+ "src/post_pro.cpp",
+ "src/preemph.cpp",
+ "src/pstfilt.cpp",
+ "src/qgain475_tab.cpp",
+ "src/sp_dec.cpp",
+ "src/wmf_to_ets.cpp",
+ ],
+
+ export_include_dirs: ["src"],
+
+ cflags: [
+ "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+ "-DOSCL_IMPORT_REF=",
+
+ "-Werror",
+ ],
+
+ //sanitize: {
+ // misc_undefined: [
+ // "signed-integer-overflow",
+ // ],
+ //},
+
+ shared_libs: [
+ "libstagefright_amrnb_common",
+ "liblog",
+ ],
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+//###############################################################################
+cc_test {
+ name: "libstagefright_amrnbdec_test",
+ gtest: false,
+ host_supported: true,
+
+ srcs: ["test/amrnbdec_test.cpp"],
+
+ cflags: ["-Wall", "-Werror"],
+
+ local_include_dirs: ["src"],
+
+ static_libs: [
+ "libstagefright_amrnbdec",
+ "libsndfile",
+ ],
+
+ shared_libs: [
+ "libstagefright_amrnb_common",
+ "libaudioutils",
+ "liblog",
+ ],
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+
+ //sanitize: {
+ // misc_undefined: [
+ // "signed-integer-overflow",
+ // ],
+ //},
+}
diff --git a/media/codecs/amrnb/dec/MODULE_LICENSE_APACHE2 b/media/codecs/amrnb/dec/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/amrnb/dec/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/amrnb/dec/NOTICE b/media/codecs/amrnb/dec/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/amrnb/dec/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/amrnb/dec/src/a_refl.cpp b/media/codecs/amrnb/dec/src/a_refl.cpp
new file mode 100644
index 0000000..5a47510
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/a_refl.cpp
@@ -0,0 +1,317 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/src/a_refl.c
+ Functions: a_refl
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Removing unneeded include files and the goto statement.
+
+
+ Description: Changed function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Using inline functions from basic_op.h .
+ Removing unneeded include files.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#define LOG_TAG "a_refl"
+#include <log/log.h>
+
+#include "a_refl.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS [optional]
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES [optional]
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: AMREncode
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ a[] = pointer to directform coefficients of type Word16
+ refl[] = pointer to reflection coefficients of type Word16
+
+ Outputs:
+ pOverflow = 1 if overflow exists in the math operations else zero.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : a_refl.c
+ Purpose : Convert from direct form coefficients to
+ reflection coefficients
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] a_refl.c , 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+void A_Refl(
+ Word16 a[], // i : Directform coefficients
+ Word16 refl[] // o : Reflection coefficients
+)
+{
+ // local variables
+ Word16 i,j;
+ Word16 aState[M];
+ Word16 bState[M];
+ Word16 normShift;
+ Word16 normProd;
+ Word32 L_acc;
+ Word16 scale;
+ Word32 L_temp;
+ Word16 temp;
+ Word16 mult;
+
+ // initialize states
+ for (i = 0; i < M; i++)
+ {
+ aState[i] = a[i];
+ }
+
+ // backward Levinson recursion
+ for (i = M-1; i >= 0; i--)
+ {
+ if (sub(abs_s(aState[i]), 4096) >= 0)
+ {
+ goto ExitRefl;
+ }
+
+ refl[i] = shl(aState[i], 3);
+
+ L_temp = L_mult(refl[i], refl[i]);
+ L_acc = L_sub(MAX_32, L_temp);
+
+ normShift = norm_l(L_acc);
+ scale = sub(15, normShift);
+
+ L_acc = L_shl(L_acc, normShift);
+ normProd = pv_round(L_acc);
+
+ mult = div_s(16384, normProd);
+
+ for (j = 0; j < i; j++)
+ {
+ L_acc = L_deposit_h(aState[j]);
+ L_acc = L_msu(L_acc, refl[i], aState[i-j-1]);
+
+ temp = pv_round(L_acc);
+ L_temp = L_mult(mult, temp);
+ L_temp = L_shr_r(L_temp, scale);
+
+ if (L_sub(L_abs(L_temp), 32767) > 0)
+ {
+ goto ExitRefl;
+ }
+
+ bState[j] = extract_l(L_temp);
+ }
+
+ for (j = 0; j < i; j++)
+ {
+ aState[j] = bState[j];
+ }
+ }
+ return;
+
+ExitRefl:
+ for (i = 0; i < M; i++)
+ {
+ refl[i] = 0;
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void A_Refl(
+ Word16 a[], /* i : Directform coefficients */
+ Word16 refl[], /* o : Reflection coefficients */
+ Flag *pOverflow
+)
+{
+ /* local variables */
+ Word16 i;
+ Word16 j;
+ Word16 aState[M];
+ Word16 bState[M];
+ Word16 normShift;
+ Word16 normProd;
+ Word32 L_acc;
+ Word16 scale;
+ Word32 L_temp;
+ Word16 temp;
+ Word16 mult;
+
+ /* initialize states */
+ for (i = 0; i < M; i++)
+ {
+ aState[i] = a[i];
+ }
+
+ /* backward Levinson recursion */
+ for (i = M - 1; i >= 0; i--)
+ {
+ if (abs_s(aState[i]) >= 4096)
+ {
+ for (i = 0; i < M; i++)
+ {
+ refl[i] = 0;
+ }
+ break;
+ }
+
+ refl[i] = shl(aState[i], 3, pOverflow);
+
+ L_temp = L_mult(refl[i], refl[i], pOverflow);
+ L_acc = L_sub(MAX_32, L_temp, pOverflow);
+
+ normShift = norm_l(L_acc);
+ scale = sub(15, normShift, pOverflow);
+
+ L_acc = L_shl(L_acc, normShift, pOverflow);
+ normProd = pv_round(L_acc, pOverflow);
+
+ mult = div_s(16384, normProd);
+
+ for (j = 0; j < i; j++)
+ {
+ L_acc = L_deposit_h(aState[j]);
+ L_acc = L_msu(L_acc, refl[i], aState[i-j-1], pOverflow);
+
+ temp = pv_round(L_acc, pOverflow);
+ L_temp = L_mult(mult, temp, pOverflow);
+ L_temp = L_shr_r(L_temp, scale, pOverflow);
+
+ if (L_abs(L_temp) > 32767)
+ {
+ for (i = 0; i < M; i++)
+ {
+ refl[i] = 0;
+ }
+ ALOGE("b/23609206");
+ return;
+ }
+
+ bState[j] = extract_l(L_temp);
+ }
+
+ for (j = 0; j < i; j++)
+ {
+ aState[j] = bState[j];
+ }
+ }
+ return;
+}
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/dec/src/a_refl.h b/media/codecs/amrnb/dec/src/a_refl.h
new file mode 100644
index 0000000..4028e1e
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/a_refl.h
@@ -0,0 +1,124 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/a_refl.h
+
+ Date: 08/11/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : a_refl.h
+ Purpose : Convert from direct form coefficients to
+ reflection coefficients
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef A_REFL_H
+#define A_REFL_H
+#define a_refl_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ /*
+ * FUNCTION: A_Refl()
+ * PURPOSE: Convert from direct form coefficients to reflection coefficients
+ * DESCRIPTION:
+ * Directform coeffs in Q12 are converted to
+ * reflection coefficients Q15
+ */
+ void A_Refl(
+ Word16 a[], /* i : Directform coefficients */
+ Word16 refl[], /* o : Reflection coefficients */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _A_REFL_H_ */
+
+
+
diff --git a/media/codecs/amrnb/dec/src/agc.cpp b/media/codecs/amrnb/dec/src/agc.cpp
new file mode 100644
index 0000000..4c66d54
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/agc.cpp
@@ -0,0 +1,1066 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/agc.c
+ Funtions: energy_old
+ energy_new
+ agc_init
+ agc_reset
+ agc_exit
+ agc
+ agc2
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This set of modules scale the excitation level and output of the speech
+ signals.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "agc.h"
+#include "cnst.h"
+#include "inv_sqrt.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: energy_old
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ in = input signal (Word16)
+ l_trm = input signal length (Word16)
+ pOverflow = address of overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the energy computation saturates
+
+ Returns:
+ s = return energy of signal (Word32)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns the energy of the signal.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ agc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static Word32 energy_old( // o : return energy of signal
+ Word16 in[], // i : input signal (length l_trm)
+ Word16 l_trm // i : signal length
+)
+{
+ Word32 s;
+ Word16 i, temp;
+
+ temp = shr (in[0], 2);
+ s = L_mult (temp, temp);
+
+ for (i = 1; i < l_trm; i++)
+ {
+ temp = shr (in[i], 2);
+ s = L_mac (s, temp, temp);
+ }
+
+ return s;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word32 energy_old( /* o : return energy of signal */
+ Word16 in[], /* i : input signal (length l_trm) */
+ Word16 l_trm, /* i : signal length */
+ Flag *pOverflow /* overflow: flag to indicate overflow */
+)
+
+{
+ Word32 s = 0;
+ Word16 i;
+ Word16 temp;
+
+ for (i = 0; i < l_trm; i++)
+ {
+ temp = in[i] >> 2;
+ s = L_mac(s, temp, temp, pOverflow);
+ }
+
+ return(s);
+}
+
+/*----------------------------------------------------------------------------*/
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: energy_old__Wrapper
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ in = input signal (Word16)
+ l_trm = input signal length (Word16)
+ pOverflow = address of overflow (Flag)
+ Outputs:
+ pOverflow -> 1 if the energy computation saturates
+
+ Returns:
+ s = return energy of signal (Word32)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function provides external access to the static function energy_old.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ CALL energy_old ( in = in
+ l_trm = l_trm
+ pOverflow = pOverflow )
+ MODIFYING(nothing)
+ RETURNING(energy_old_value = s)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word32 energy_old_Wrapper(Word16 in[], Word16 l_trm, Flag *pOverflow)
+{
+ Word32 energy_old_value;
+
+ /*----------------------------------------------------------------------------
+ CALL energy_old ( in = in
+ l_trm = l_trm
+ pOverflow = pOverflow )
+
+ MODIFYING(nothing)
+ RETURNING(energy_old_value = s)
+ ----------------------------------------------------------------------------*/
+ energy_old_value = energy_old(in, l_trm, pOverflow);
+ return(energy_old_value);
+}
+/*--------------------------------------------------------------------------*/
+
+/*
+-----------------------------------------------------------------------------
+ FUNCTION NAME: energy_new
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ in = input signal
+ l_trm = input signal length
+ pOverflow = address of overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the energy computation saturates
+
+ Returns:
+ s = return energy of signal
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns the energy of the signal.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ agc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static Word32 energy_new( // o : return energy of signal
+ Word16 in[], // i : input signal (length l_trm)
+ Word16 l_trm ) // i : signal length
+
+{
+ Word32 s;
+ Word16 i;
+ Flag ov_save;
+
+ ov_save = Overflow; //save overflow flag in case energy_old
+ // must be called
+ s = L_mult(in[0], in[0]);
+ for (i = 1; i < l_trm; i++)
+ {
+ s = L_mac(s, in[i], in[i]);
+ }
+
+ // check for overflow
+ if (L_sub (s, MAX_32) == 0L)
+ {
+ Overflow = ov_save; // restore overflow flag
+ s = energy_old (in, l_trm); // function result
+ }
+ else
+ {
+ s = L_shr(s, 4);
+ }
+
+ return(s);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word32 energy_new( /* o : return energy of signal */
+ Word16 in[], /* i : input signal (length l_trm) */
+ Word16 l_trm, /* i : signal length */
+ Flag *pOverflow /* i : overflow flag */
+)
+
+{
+ Word32 s = 0;
+ Word16 i;
+ Flag ov_save;
+
+ ov_save = *(pOverflow); /* save overflow flag in case energy_old */
+ /* must be called */
+
+
+ for (i = 0; i < l_trm; i++)
+ {
+ s = L_mac(s, in[i], in[i], pOverflow);
+ }
+
+ /* check for overflow */
+ if (s != MAX_32)
+ {
+ /* s is a sum of squares, so it won't be negative */
+ s = s >> 4;
+ }
+ else
+ {
+ *(pOverflow) = ov_save; /* restore overflow flag */
+ s = energy_old(in, l_trm, pOverflow); /* function result */
+ }
+
+ return (s);
+}
+
+/*--------------------------------------------------------------------------*/
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: energy_new__Wrapper
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ in = input signal (Word16)
+ l_trm = input signal length (Word16)
+ overflow = address of overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the energy computation saturates
+
+ Returns:
+ s = return energy of signal (Word32)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function provides external access to the static function energy_new.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ CALL energy_new ( in = in
+ l_trm = l_trm
+ pOverflow = pOverflow )
+
+ MODIFYING(nothing)
+
+ RETURNING(energy_new_value = s)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word32 energy_new_Wrapper(Word16 in[], Word16 l_trm, Flag *pOverflow)
+{
+ Word32 energy_new_value;
+
+ /*----------------------------------------------------------------------------
+ CALL energy_new ( in = in
+ l_trm = l_trm
+ pOverflow = pOverflow )
+
+ MODIFYING(nothing)
+ RETURNING(energy_new_value = s)
+
+ ----------------------------------------------------------------------------*/
+ energy_new_value = energy_new(in, l_trm, pOverflow);
+
+ return(energy_new_value);
+
+}
+
+/*--------------------------------------------------------------------------*/
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: agc_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type agcState
+
+ Outputs:
+ Structure pointed to by state is initialized to zeros
+
+ Returns:
+ Returns 0 if memory was successfully initialized,
+ otherwise returns -1.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Reset of agc (i.e. set state memory to 1.0).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ agc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int agc_reset (agcState *state)
+{
+ if (state == (agcState *) NULL)
+ {
+ fprintf(stderr, "agc_reset: invalid parameter\n");
+ return -1;
+ }
+
+ state->past_gain = 4096; // initial value of past_gain = 1.0
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 agc_reset(agcState *state)
+{
+ if (state == (agcState *) NULL)
+ {
+ /* fprintf(stderr, "agc_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ state->past_gain = 4096; /* initial value of past_gain = 1.0 */
+
+ return(0);
+}
+
+/*--------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: agc
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to agc state
+ sig_in = pointer to a buffer containing the postfilter input signal
+ sig_out = pointer to a buffer containing the postfilter output signal
+ agc_fac = AGC factor
+ l_trm = subframe size
+ pOverflow = pointer to the overflow flag
+
+ Outputs:
+ st->past_gain = gain
+ buffer pointed to by sig_out contains the new postfilter output signal
+ pOverflow -> 1 if the agc computation saturates
+
+ Returns:
+ return = 0
+
+ Global Variables Used:
+ none.
+
+ Local Variables Needed:
+ none.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Scales the postfilter output on a subframe basis using:
+
+ sig_out[n] = sig_out[n] * gain[n]
+ gain[n] = agc_fac * gain[n-1] + (1 - agc_fac) g_in/g_out
+
+ where: gain[n] = gain at the nth sample given by
+ g_in/g_out = square root of the ratio of energy at
+ the input and output of the postfilter.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ agc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int agc (
+ agcState *st, // i/o : agc state
+ Word16 *sig_in, // i : postfilter input signal (l_trm)
+ Word16 *sig_out, // i/o : postfilter output signal (l_trm)
+ Word16 agc_fac, // i : AGC factor
+ Word16 l_trm // i : subframe size
+)
+{
+ Word16 i, exp;
+ Word16 gain_in, gain_out, g0, gain;
+ Word32 s;
+
+ // calculate gain_out with exponent
+ s = energy_new(sig_out, l_trm); // function result
+
+ if (s == 0)
+ {
+ st->past_gain = 0;
+ return 0;
+ }
+ exp = sub (norm_l (s), 1);
+ gain_out = pv_round (L_shl (s, exp));
+
+ // calculate gain_in with exponent
+ s = energy_new(sig_in, l_trm); // function result
+
+ if (s == 0)
+ {
+ g0 = 0;
+ }
+ else
+ {
+ i = norm_l (s);
+ gain_in = pv_round (L_shl (s, i));
+ exp = sub (exp, i);
+
+ *---------------------------------------------------*
+ * g0 = (1-agc_fac) * sqrt(gain_in/gain_out); *
+ *---------------------------------------------------*
+
+ s = L_deposit_l (div_s (gain_out, gain_in));
+ s = L_shl (s, 7); // s = gain_out / gain_in
+ s = L_shr (s, exp); // add exponent
+
+ s = Inv_sqrt (s); // function result
+ i = pv_round (L_shl (s, 9));
+
+ // g0 = i * (1-agc_fac)
+ g0 = mult (i, sub (32767, agc_fac));
+ }
+
+ // compute gain[n] = agc_fac * gain[n-1]
+ + (1-agc_fac) * sqrt(gain_in/gain_out)
+ // sig_out[n] = gain[n] * sig_out[n]
+
+ gain = st->past_gain;
+
+ for (i = 0; i < l_trm; i++)
+ {
+ gain = mult (gain, agc_fac);
+ gain = add (gain, g0);
+ sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], gain), 3));
+ }
+
+ st->past_gain = gain;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void agc(
+ agcState *st, /* i/o : agc state */
+ Word16 *sig_in, /* i : postfilter input signal (l_trm) */
+ Word16 *sig_out, /* i/o : postfilter output signal (l_trm) */
+ Word16 agc_fac, /* i : AGC factor */
+ Word16 l_trm, /* i : subframe size */
+ Flag *pOverflow /* i : overflow Flag */
+
+)
+
+{
+ Word16 i;
+ Word16 exp;
+ Word16 gain_in;
+ Word16 gain_out;
+ Word16 g0;
+ Word16 gain;
+ Word32 s;
+ Word32 L_temp;
+ Word16 temp;
+
+ Word16 *p_sig_out;
+
+ /* calculate gain_out with exponent */
+ s = energy_new(sig_out, l_trm, pOverflow); /* function result */
+
+ if (s == 0)
+ {
+ st->past_gain = 0;
+ return;
+ }
+ exp = norm_l(s) - 1;
+
+ L_temp = L_shl(s, exp, pOverflow);
+ gain_out = pv_round(L_temp, pOverflow);
+
+ /* calculate gain_in with exponent */
+ s = energy_new(sig_in, l_trm, pOverflow); /* function result */
+
+ if (s == 0)
+ {
+ g0 = 0;
+ }
+ else
+ {
+ i = norm_l(s);
+
+ /* L_temp = L_shl(s, i, pOverflow); */
+ L_temp = s << i;
+
+ gain_in = pv_round(L_temp, pOverflow);
+
+ exp -= i;
+
+ /*---------------------------------------------------*
+ * g0 = (1-agc_fac) * sqrt(gain_in/gain_out); *
+ *---------------------------------------------------*/
+
+ /* s = gain_out / gain_in */
+ temp = div_s(gain_out, gain_in);
+
+ /* s = L_deposit_l (temp); */
+ s = (Word32) temp;
+ s = s << 7;
+ s = L_shr(s, exp, pOverflow); /* add exponent */
+
+ s = Inv_sqrt(s, pOverflow); /* function result */
+ L_temp = s << 9;
+
+ i = (Word16)((L_temp + (Word32) 0x00008000L) >> 16);
+
+ /* g0 = i * (1-agc_fac) */
+ temp = 32767 - agc_fac;
+
+ g0 = (Word16)(((Word32) i * temp) >> 15);
+
+ }
+
+ /* compute gain[n] = agc_fac * gain[n-1]
+ + (1-agc_fac) * sqrt(gain_in/gain_out) */
+ /* sig_out[n] = gain[n] * sig_out[n] */
+
+ gain = st->past_gain;
+ p_sig_out = sig_out;
+
+ for (i = 0; i < l_trm; i++)
+ {
+ /* gain = mult (gain, agc_fac, pOverflow); */
+ gain = (Word16)(((Word32) gain * agc_fac) >> 15);
+
+ /* gain = add (gain, g0, pOverflow); */
+ gain += g0;
+
+ /* L_temp = L_mult (sig_out[i], gain, pOverflow); */
+ L_temp = ((Word32)(*(p_sig_out)) * gain) << 1;
+
+ *(p_sig_out++) = (Word16)(L_temp >> 13);
+ }
+
+ st->past_gain = gain;
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: agc2
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ sig_in = pointer to a buffer containing the postfilter input signal
+ sig_out = pointer to a buffer containing the postfilter output signal
+ l_trm = subframe size
+ pOverflow = pointer to overflow flag
+
+ Outputs:
+ sig_out points to a buffer containing the new scaled output signal.
+ pOverflow -> 1 if the agc computation saturates
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Scales the excitation on a subframe basis.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ agc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void agc2 (
+ Word16 *sig_in, // i : postfilter input signal
+ Word16 *sig_out, // i/o : postfilter output signal
+ Word16 l_trm // i : subframe size
+)
+{
+ Word16 i, exp;
+ Word16 gain_in, gain_out, g0;
+ Word32 s;
+
+ // calculate gain_out with exponent
+ s = energy_new(sig_out, l_trm); // function result
+
+ if (s == 0)
+ {
+ return;
+ }
+ exp = sub (norm_l (s), 1);
+ gain_out = pv_round (L_shl (s, exp));
+
+ // calculate gain_in with exponent
+ s = energy_new(sig_in, l_trm); // function result
+
+ if (s == 0)
+ {
+ g0 = 0;
+ }
+ else
+ {
+ i = norm_l (s);
+ gain_in = pv_round (L_shl (s, i));
+ exp = sub (exp, i);
+
+ *---------------------------------------------------*
+ * g0 = sqrt(gain_in/gain_out); *
+ *---------------------------------------------------*
+
+ s = L_deposit_l (div_s (gain_out, gain_in));
+ s = L_shl (s, 7); // s = gain_out / gain_in
+ s = L_shr (s, exp); // add exponent
+
+ s = Inv_sqrt (s); // function result
+ g0 = pv_round (L_shl (s, 9));
+ }
+
+ // sig_out(n) = gain(n) sig_out(n)
+
+ for (i = 0; i < l_trm; i++)
+ {
+ sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], g0), 3));
+ }
+
+ return;
+}
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void agc2(
+ Word16 *sig_in, /* i : postfilter input signal */
+ Word16 *sig_out, /* i/o : postfilter output signal */
+ Word16 l_trm, /* i : subframe size */
+ Flag *pOverflow /* i : overflow flag */
+)
+
+{
+ Word16 i;
+ Word16 exp;
+ Word16 gain_in;
+ Word16 gain_out;
+ Word16 g0;
+ Word32 s;
+ Word32 L_temp;
+ Word16 temp;
+
+ /* calculate gain_out with exponent */
+ s = energy_new(sig_out, l_trm, pOverflow); /* function result */
+
+ if (s == 0)
+ {
+ return;
+ }
+ exp = norm_l(s) - 1;
+ L_temp = L_shl(s, exp, pOverflow);
+ gain_out = pv_round(L_temp, pOverflow);
+
+ /* calculate gain_in with exponent */
+ s = energy_new(sig_in, l_trm, pOverflow); /* function result */
+
+ if (s == 0)
+ {
+ g0 = 0;
+ }
+ else
+ {
+ i = norm_l(s);
+ L_temp = L_shl(s, i, pOverflow);
+ gain_in = pv_round(L_temp, pOverflow);
+ exp -= i;
+
+ /*---------------------------------------------------*
+ * g0 = sqrt(gain_in/gain_out); *
+ *---------------------------------------------------*/
+
+ /* s = gain_out / gain_in */
+ temp = div_s(gain_out, gain_in);
+
+ /* s = L_deposit_l (temp); */
+ s = (Word32)temp;
+
+ if (s > (Word32) 0x00FFFFFFL)
+ {
+ s = MAX_32;
+ }
+ else if (s < (Word32) 0xFF000000L)
+ {
+ s = MIN_32;
+ }
+ else
+ {
+ s = s << 7;
+ }
+ s = L_shr(s, exp, pOverflow); /* add exponent */
+
+ s = Inv_sqrt(s, pOverflow); /* function result */
+
+ if (s > (Word32) 0x003FFFFFL)
+ {
+ L_temp = MAX_32;
+ }
+ else if (s < (Word32) 0xFFC00000L)
+ {
+ L_temp = MIN_32;
+ }
+ else
+ {
+ L_temp = s << 9;
+ }
+ g0 = pv_round(L_temp, pOverflow);
+ }
+
+ /* sig_out(n) = gain(n) sig_out(n) */
+
+ for (i = l_trm - 1; i >= 0; i--)
+ {
+ L_temp = L_mult(sig_out[i], g0, pOverflow);
+ if (L_temp > (Word32) 0x0FFFFFFFL)
+ {
+ sig_out[i] = MAX_16;
+ }
+ else if (L_temp < (Word32) 0xF0000000L)
+ {
+ sig_out[i] = MIN_16;
+ }
+ else
+ {
+ sig_out[i] = (Word16)(L_temp >> 13);
+ }
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/agc.h b/media/codecs/amrnb/dec/src/agc.h
new file mode 100644
index 0000000..b6e3249
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/agc.h
@@ -0,0 +1,163 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/agc.h
+
+ Date: 12/07/2001
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Removed unneeded sections of the standard template.
+ Updated function prototype for agc() and agc2() to match new
+ interface
+
+ Description: Changed paramter name from "overflow" to "pOverflow" for
+ functions agc() and agc2()
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : agc.h
+ Purpose : Scales the postfilter output on a subframe basis
+ : by automatic control of the subframe gain.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _AGC_H_
+#define _AGC_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 past_gain;
+ } agcState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function : agc_reset
+ ; Purpose : Reset of agc (i.e. set state memory to 1.0)
+ ; Returns : 0 on success
+ ;
+ ----------------------------------------------------------------------------*/
+ Word16 agc_reset(agcState *st);
+
+
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function : agc
+ ; Purpose : Scales the postfilter output on a subframe basis
+ ; Description : sig_out[n] = sig_out[n] * gain[n];
+ ; where gain[n] is the gain at the nth sample given by
+ ; gain[n] = agc_fac * gain[n-1] + (1 - agc_fac) g_in/g_out
+ ; g_in/g_out is the square root of the ratio of energy at
+ ; the input and output of the postfilter.
+ ;
+ ----------------------------------------------------------------------------*/
+ void agc(
+ agcState *st, /* i/o : agc state */
+ Word16 *sig_in, /* i : postfilter input signal, (l_trm) */
+ Word16 *sig_out, /* i/o : postfilter output signal, (l_trm) */
+ Word16 agc_fac, /* i : AGC factor */
+ Word16 l_trm, /* i : subframe size */
+ Flag *pOverflow /* i : overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function: agc2
+ ; Purpose: Scales the excitation on a subframe basis
+ ;
+ ----------------------------------------------------------------------------*/
+ void agc2(
+ Word16 *sig_in, /* i : postfilter input signal */
+ Word16 *sig_out, /* i/o : postfilter output signal */
+ Word16 l_trm, /* i : subframe size */
+ Flag *pOverflow /* i : overflow flag */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _AGC_H_ */
+
+
diff --git a/media/codecs/amrnb/dec/src/amrdecode.cpp b/media/codecs/amrnb/dec/src/amrdecode.cpp
new file mode 100644
index 0000000..873d7af
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/amrdecode.cpp
@@ -0,0 +1,544 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+ Pathname: ./audio/gsm-amr/c/src/amrdecode.c
+
+ Date: 05/23/2001
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: AMRDecode now doesn't call getbits() or put_header_in().
+ It also now obtains a new bit_offset value from a constant
+ rather than from the returned value of getbits().
+
+ Description: AMRDecode now returns byte_offset rather than bit_offset,
+ so the program can access the next frame that is byte
+ aligned rather than packed without padding.
+
+ Description: The structure types Speech_Decode_FrameState are now
+ passed into amrdecode( ) using void pointers, so that
+ higher level functions don't need to know anything about
+ this structure type.
+
+ Description: Changed input argument list. Added code to handle incoming DTX
+ frames, and added call to wmf_to_ets function prior to calling
+ GSMFrameDecode.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Changed all references to bit_offset to byte_offset.
+
+ Description: Added input_type to the function interface and modified code
+ to check type of conversion that needs to be made.
+
+ Description: Modified pseudo-code to include IF2 and ETS input formats.
+ Removed byte_offset from input list. Renamed speech_bits
+ to speech_bits_ptr.
+
+ Description: Added dec_input_format_tab.h in Include section. Modified
+ pseudo-code to use correct table names. Renamed input_type to
+ input_format and speech_bits to speech_bits_ptr.
+
+ Description: Removed *prev_mode_ptr in the input argument list.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Removed dec_input_format_tab.h from Include section.
+ 2. Changed type definition of raw_pcm_buffer in the I/O
+ definition section.
+
+ Description: Renamed WmfBytesPerFrame to WmfDecBytesPerFrame, and
+ If2BytesPerFrame to If2DecBytesPerFrame.
+
+ Description: Modified code so that the ETS testvectors could be fed directly
+ to this function.
+
+ Description: Changed '&' to '&&' in the setting of rx_type and mode for
+ AMR_SID < frame_type < NO_DATA case.
+
+ Description: Added code comments and made some code optimizations per Phase
+ 2/3 review comments.
+
+ Description: Added conditional compile around the call to GSMFrameDecode to
+ allow amrdecode.c to be used in the ETS reference console.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "amrdecode.h"
+#include "cnst.h"
+#include "typedef.h"
+#include "frame.h"
+#include "sp_dec.h"
+#include "wmf_to_ets.h"
+#include "if2_to_ets.h"
+#include "frame_type_3gpp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: AMRDecode
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state_data = pointer to a structure (type void)
+
+ frame_type = 3GPP frame type (enum Frame_Type_3GPP)
+
+ speech_bits_ptr = pointer to the beginning of the raw encoded speech bits
+ for the current frame to be decoded (unsigned char)
+
+ raw_pcm_buffer = pointer to the output pcm outputs array (Word16)
+
+ input_format = input format used; valid values are AMR_WMF, AMR_IF2,
+ and AMR_ETS (Word16)
+
+ Outputs:
+ raw_pcm_buffer contains the newly decoded linear PCM speech samples
+ state_data->prev_mode contains the new mode
+
+ Returns:
+ byte_offset = address offset of the next frame to be processed or
+ error condition flag (-1) (int)
+
+ Global Variables Used:
+ WmfDecBytesPerFrame = table containing the number of core AMR data bytes
+ used by each codec mode for WMF input format (const
+ int)
+
+ If2DecBytesPerFrame = table containing the number of core AMR data bytes
+ used by each codec mode for IF2 input format (const
+ int)
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function is the top level entry function to the GSM AMR Decoder library.
+
+ First, it checks the input format type (input_format) to determine the type
+ of de-formattting that needs to be done. If input_format is AMR_WMF, the input
+ data is in WMF (aka, non-IF2) format and the function wmf_to_ets will be
+ called to convert to the ETS format (1 bit/word, where 1 word = 16 bits),
+ and byte_offset will be updated according to the contents of WmfDecBytesPerFrame
+ table.
+
+ If input_format is AMR_IF2, the input data is in IF2 format [1] and the
+ function if2_to_ets will be called to convert to the ETS format, and
+ byte_offset will be updated according to the contents of If2DecBytesPerFrame
+ table.
+
+ The codec mode and receive frame type is initialized based on the incoming
+ frame_type.
+
+ If input_format is AMR_ETS, the input data is in the ETS format. The receive
+ frame type is set to the value in the first location of the buffer pointed to
+ by speech_bits_ptr. Then, the encoded speech parameters in the buffer pointed
+ to by speech_bits is copied to dec_ets_input_bfr and the type will be changed
+ from unsigned char to Word16. Lastly, if the receive frame type is not
+ RX_NO_DATA, the mode is obtained from the buffer pointed to by
+ speech_bits_ptr, offset by MAX_SERIAL_SIZE+1, otherwise, the mode is set to
+ the previous mode (found the in state_data->prev_mode).
+
+ If input_format is an unsupported format, byte_offset will be set to -1, to
+ indicate an error condition has occurred, and the function will exit.
+
+ If there are no errors, GSMFrameDecode is called to decode a 20 ms frame. It
+ puts the decoded linear PCM samples in the buffer pointed to by
+ raw_pcm_buffer. Then, the prev_mode field of the structure pointed to by
+ state_data is updated to the current mode.
+
+ This function returns the new byte_offset value to indicate the address
+ offset of the next speech frame to be decoded.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] "AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0
+ Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Note: AMRSID_RXTYPE_BIT_OFFSET = 35
+ AMRSID_RXMODE_BIT_OFFSET = 36
+ NUM_AMRSID_RXMODE_BITS = 3
+
+
+ // Set up Decoder state structure pointer
+ Speech_Decode_FrameState *decoder_state
+ = (Speech_Decode_FrameState *) state_data
+
+ // Determine type of de-formatting
+
+ // Decode WMF or IF2 frames
+ IF ((input_format == AMR_RX_WMF) | (input_format == AMR_RX_IF2))
+ THEN
+ IF (input_format == AMR_RX_WMF)
+ THEN
+ // Convert incoming packetized raw WMF data to ETS format
+ CALL wmf_to_ets(frame_type = frame_type
+ input_ptr = speech_bits_ptr
+ output_ptr = &dec_ets_input_bfr)
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ // Address offset of the start of next frame
+ byte_offset = WmfDecBytesPerFrame[frame_type]
+
+ ELSEIF (input_format == AMR_RX_IF2)
+ THEN
+ // Convert incoming packetized raw IF2 data to ETS format
+ CALL if2_to_ets(frame_type = frame_type
+ input_ptr = speech_bits_ptr
+ output_ptr = &dec_ets_input_bfr)
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ // Address offset of the start of next frame
+ byte_offset = If2DecBytesPerFrame[frame_type]
+
+ ENDIF
+
+ // Determine AMR codec mode and AMR RX frame type
+ IF (frame_type <= AMR_122)
+ THEN
+ mode = (enum Mode) frame_type;
+ rx_type = RX_SPEECH_GOOD;
+
+ ELSEIF (frame_type == AMR_SID)
+ THEN
+ // Clear mode store prior to reading mode info from input buffer
+ mode = 0
+
+ FOR i = 0 TO NUM_AMRSID_RXMODE_BITS-1
+
+ mode |= (dec_ets_input_bfr[AMRSID_RXMODE_BIT_OFFSET+i] << i)
+
+ ENDFOR
+
+ IF (dec_ets_input_bfr[AMRSID_RXTYPE_BIT_OFFSET] == 0)
+ THEN
+ rx_type = RX_SID_FIRST
+
+ ELSE
+ rx_type = RX_SID_UPDATE
+
+ ENDIF
+
+ ELSEIF ((frame_type > AMR_SID) && (frame_type < NO_DATA))
+ THEN
+ // Use previous mode
+ mode = decoder_state->prev_mode
+
+ // Unsupported SID frames
+ rx_type = RX_SPEECH_BAD;
+
+ ELSE
+ // Use previous mode
+ mode = decoder_state->prev_mode
+
+ // No data received
+ rx_type = RX_NO_DATA;
+
+ ENDIF
+
+ // Decode ETS frames
+ ELSEIF (input_format == AMR_RX_ETS)
+ THEN
+ // Change type of pointer to incoming raw ETS data
+ ets_word_ptr = (Word16 *) speech_bits_ptr
+
+ // Get RX frame type
+ rx_type = (enum RXFrameType) *ets_word_ptr
+ ets_word_ptr = ets_word_ptr + 1
+
+ // Copy incoming raw ETS data to dec_ets_input_bfr
+ FOR i = 0 TO MAX_SERIAL_SIZE-1
+
+ dec_ets_input_bfr[i] = *ets_word_ptr
+ ets_word_ptr = ets_word_ptr + 1
+
+ ENDFOR
+
+ // Get codec mode
+ IF (rx_type != RX_NO_DATA)
+ THEN
+ mode = (enum Mode) *ets_word_ptr
+
+ ELSE
+ //Use previous mode if no received data
+ mode = decoder_state->prev_mode
+
+ ENDIF
+
+ // Set up byte_offset
+ byte_offset = 2*(MAX_SERIAL_SIZE+2)
+
+ ELSE
+ // Invalid format, return error code
+ byte_offset = -1
+
+ ENDIF
+
+ // Proceed with decoding frame, if there are no errors
+ IF (byte_offset != -1)
+ THEN
+ // Decode a 20 ms frame
+ CALL GSMFrameDecode( st = decoder_state
+ mode = mode
+ serial = dec_ets_input_bfr,
+ frame_type = rx_type,
+ synth = (Word16 *)raw_pcm_buffer);
+ MODIFYING (nothing)
+ RETURNING (Nothing)
+
+ // Save mode for next frame
+ decoder_state->prev_mode = mode
+
+ ENDIF
+
+ RETURN (byte_offset)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 AMRDecode(
+ void *state_data,
+ enum Frame_Type_3GPP frame_type,
+ UWord8 *speech_bits_ptr,
+ Word16 *raw_pcm_buffer,
+ bitstream_format input_format
+)
+{
+ Word16 *ets_word_ptr;
+ enum Mode mode = (enum Mode)MR475;
+ int modeStore;
+ int tempInt;
+ enum RXFrameType rx_type = RX_NO_DATA;
+ Word16 dec_ets_input_bfr[MAX_SERIAL_SIZE];
+ Word16 i;
+ Word16 byte_offset = -1;
+
+ /* Type cast state_data to Speech_Decode_FrameState rather than passing
+ * that structure type to this function so the structure make up can't
+ * be viewed from higher level functions than this.
+ */
+ Speech_Decode_FrameState *decoder_state
+ = (Speech_Decode_FrameState *) state_data;
+
+ /* Determine type of de-formatting */
+ /* WMF or IF2 frames */
+ if ((input_format == MIME_IETF) | (input_format == IF2))
+ {
+ if (input_format == MIME_IETF)
+ {
+ /* Convert incoming packetized raw WMF data to ETS format */
+ wmf_to_ets(frame_type, speech_bits_ptr, dec_ets_input_bfr);
+
+ /* Address offset of the start of next frame */
+ byte_offset = WmfDecBytesPerFrame[frame_type];
+ }
+ else /* else has to be input_format IF2 */
+ {
+ /* Convert incoming packetized raw IF2 data to ETS format */
+ if2_to_ets(frame_type, speech_bits_ptr, dec_ets_input_bfr);
+
+ /* Address offset of the start of next frame */
+ byte_offset = If2DecBytesPerFrame[frame_type];
+ }
+
+ /* At this point, input data is in ETS format */
+ /* Determine AMR codec mode and AMR RX frame type */
+ if (frame_type <= AMR_122)
+ {
+ mode = (enum Mode) frame_type;
+ rx_type = RX_SPEECH_GOOD;
+ }
+ else if (frame_type == AMR_SID)
+ {
+ /* Clear mode store prior to reading mode info from input buffer */
+ modeStore = 0;
+
+ for (i = 0; i < NUM_AMRSID_RXMODE_BITS; i++)
+ {
+ tempInt = dec_ets_input_bfr[AMRSID_RXMODE_BIT_OFFSET+i] << i;
+ modeStore |= tempInt;
+ }
+ mode = (enum Mode) modeStore;
+
+ /* Get RX frame type */
+ if (dec_ets_input_bfr[AMRSID_RXTYPE_BIT_OFFSET] == 0)
+ {
+ rx_type = RX_SID_FIRST;
+ }
+ else
+ {
+ rx_type = RX_SID_UPDATE;
+ }
+ }
+ else if (frame_type < AMR_NO_DATA)
+ {
+ /* Invalid frame_type, return error code */
+ byte_offset = -1; /* !!! */
+ }
+ else
+ {
+ mode = decoder_state->prev_mode;
+
+ /*
+ * RX_NO_DATA, generate exponential decay from latest valid frame for the first 6 frames
+ * after that, create silent frames
+ */
+ rx_type = RX_NO_DATA;
+
+ }
+
+ }
+
+ /* ETS frames */
+ else if (input_format == ETS)
+ {
+ /* Change type of pointer to incoming raw ETS data */
+ ets_word_ptr = (Word16 *) speech_bits_ptr;
+
+ /* Get RX frame type */
+ rx_type = (enum RXFrameType) * ets_word_ptr;
+ ets_word_ptr++;
+
+ /* Copy incoming raw ETS data to dec_ets_input_bfr */
+ for (i = 0; i < MAX_SERIAL_SIZE; i++)
+ {
+ dec_ets_input_bfr[i] = *ets_word_ptr;
+ ets_word_ptr++;
+ }
+
+ /* Get codec mode */
+ if (rx_type != RX_NO_DATA)
+ {
+ /* Get mode from input bitstream */
+ mode = (enum Mode) * ets_word_ptr;
+ }
+ else
+ {
+ /* Use previous mode if no received data */
+ mode = decoder_state->prev_mode;
+ }
+
+ /* Set up byte_offset */
+ byte_offset = 2 * (MAX_SERIAL_SIZE + 2);
+ }
+ else
+ {
+ /* Invalid input format, return error code */
+ byte_offset = -1;
+ }
+
+ /* Proceed with decoding frame, if there are no errors */
+ if (byte_offset != -1)
+ {
+ /* Decode a 20 ms frame */
+
+#ifndef CONSOLE_DECODER_REF
+ /* Use PV version of sp_dec.c */
+ GSMFrameDecode(decoder_state, mode, dec_ets_input_bfr, rx_type,
+ raw_pcm_buffer);
+
+#else
+ /* Use ETS version of sp_dec.c */
+ Speech_Decode_Frame(decoder_state, mode, dec_ets_input_bfr, rx_type,
+ raw_pcm_buffer);
+
+#endif
+
+ /* Save mode for next frame */
+ decoder_state->prev_mode = mode;
+ }
+
+ return (byte_offset);
+}
+
+
+
diff --git a/media/codecs/amrnb/dec/src/amrdecode.h b/media/codecs/amrnb/dec/src/amrdecode.h
new file mode 100644
index 0000000..f224fb6
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/amrdecode.h
@@ -0,0 +1,164 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./gsm-amr/c/include/amrdecode.h
+
+ Date: 05/23/2001
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added BytesUsed table so that the code can allow for padding
+ at the end of each frame.
+
+ Description: Removed function prototypes for getbits, putbits,
+ put_frame_header_in, and get_frame_header_off. Removed
+ basicop_malloc.h and replaced it with typedef.h in the include
+ section. Fixed table entries for various SID modes. Removed
+ #defines because they are not used by AMRDecode function.
+ Removed tables not used by AMRDecode function.
+
+ Description: The data type Speech_Decode_FrameState is now being passed into
+ this function as a void pointer rather than a structure of type
+ Speech_Decode_FrameState.
+
+ Description: The variable decoder_state was renamed to state_data.
+
+ Description: Updated function prototype and header template.
+
+ Description: Added mode.h and frame_type_3gpp.h to include section, and
+ removed sp_dec.h.
+
+ Description: Removed definition of Changed BytesThisFrame[] table. Added
+ extern declaration for BytesThisFrame[] table.
+
+ Description: Added #define for WMF and IF2. Updated function prototype.
+
+ Description: Moved input format #defines and BytesThisFrame table to
+ dec_input_format_tab.h and dec_input_format_tab.c, respectively.
+ Updated function prototype.
+
+ Description: Updated function prototype of AMRDecode due to the removal of
+ *prev_mode_ptr. Added extern of If2BytesPerFrame
+
+ Description: Added #defines for WMF, IF2, and ETS input formats.
+
+ Description: Changed WmfBytesPerFrame to WmfDecBytesPerFrame, and
+ If2BytesPerFrame to If2DecBytesPerFrame.
+
+ Description: Renamed #defines for input format types to make it unique to the
+ decoder.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the norm_s function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef ARMDECODE_H
+#define ARMDECODE_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "frame_type_3gpp.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define NUM_AMRSID_RXMODE_BITS 3
+#define AMRSID_RXMODE_BIT_OFFSET 36
+#define AMRSID_RXTYPE_BIT_OFFSET 35
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 WmfDecBytesPerFrame[];
+ extern const Word16 If2DecBytesPerFrame[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word16 AMRDecode(
+ void *state_data,
+ enum Frame_Type_3GPP frame_type,
+ UWord8 *speech_bits_ptr,
+ Word16 *raw_pcm_buffer,
+ bitstream_format input_format
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _AMRDECODE_H_ */
diff --git a/media/codecs/amrnb/dec/src/b_cn_cod.cpp b/media/codecs/amrnb/dec/src/b_cn_cod.cpp
new file mode 100644
index 0000000..e62e483
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/b_cn_cod.cpp
@@ -0,0 +1,516 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/b_cn_cod.c
+ Functions: pseudonoise
+ build_CN_code
+ build_CN_param
+
+ Date: 09/28/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Cleaned up code. Passing in a pointer to
+ overflow flag for build_CN_code() and build_CN_param() functions.
+ Removed unnecessary header files.
+ Description: Make chnages per formal review. Fix error introduced during
+ optimization in pseudonoise().
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This module contains functions for comfort noise(CN) generation.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "b_cn_cod.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+#define NB_PULSE 10 /* number of random pulses in DTX operation */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: pseudonoise
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pShift_reg = pointer to Old CN generator shift register state (Word32)
+ no_bits = Number of bits (Word16)
+
+ Outputs:
+ pShift_reg -> Updated CN generator shift register state
+
+ Returns:
+ noise_bits = Generated random integer value (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Generate a random integer value to use in comfort noise generation. The
+ algorithm uses polynomial x^31 + x^3 + 1. Length of the PN sequence
+ is 2^31 - 1
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ b_cn_cod.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 pseudonoise (
+ Word32 *shift_reg, // i/o : Old CN generator shift register state
+ Word16 no_bits // i : Number of bits
+)
+{
+ Word16 noise_bits, Sn, i;
+
+ noise_bits = 0;
+ for (i = 0; i < no_bits; i++)
+ {
+ // State n == 31
+ if ((*shift_reg & 0x00000001L) != 0)
+ {
+ Sn = 1;
+ }
+ else
+ {
+ Sn = 0;
+ }
+
+ // State n == 3
+ if ((*shift_reg & 0x10000000L) != 0)
+ {
+ Sn = Sn ^ 1;
+ }
+ else
+ {
+ Sn = Sn ^ 0;
+ }
+
+ noise_bits = shl (noise_bits, 1);
+ noise_bits = noise_bits | (extract_l (*shift_reg) & 1);
+
+ *shift_reg = L_shr (*shift_reg, 1);
+ if (Sn & 1)
+ {
+ *shift_reg = *shift_reg | 0x40000000L;
+ }
+ }
+ return noise_bits;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+Word16 pseudonoise(
+ Word32 *pShift_reg, /* i/o : Old CN generator shift register state */
+ Word16 no_bits /* i : Number of bits */
+)
+{
+ Word16 noise_bits;
+ Word16 Sn;
+ Word16 i;
+ Word16 temp;
+
+ noise_bits = 0;
+
+ for (i = 0; i < no_bits; i++)
+ {
+ /* State n == 31 */
+ if ((*pShift_reg & 0x00000001L) != 0)
+ {
+ Sn = 1;
+ }
+ else
+ {
+ Sn = 0;
+ }
+
+ /* State n == 3 */
+ if ((*pShift_reg & 0x10000000L) != 0)
+ {
+ Sn ^= 1;
+ }
+ else
+ {
+ Sn ^= 0;
+ }
+
+ noise_bits <<= 1;
+
+ temp = (Word16)((*pShift_reg) & 1);
+ noise_bits |= temp;
+
+ *pShift_reg >>= 1;
+ if (Sn & 1)
+ {
+ *pShift_reg |= 0x40000000L;
+ }
+ }
+ return noise_bits;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: build_CN_code
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pSeed = pointer to the Old CN generator shift register state (Word32)
+ cod[] = array to hold the generated CN fixed code vector (Word16)
+ pOverflow = pointer to overflow flag (Flag)
+
+ Outputs:
+ cod[] = generated CN fixed code vector (Word16)
+ pSeed = Updated CN generator shift register state (Word16)
+ pOverflow -> 1 if overflow occured
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+This function computes the comfort noise fixed codebook excitation. The gains
+of the pulses are always +/-1.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ b_cn_cod.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void build_CN_code (
+ Word32 *seed, // i/o : Old CN generator shift register state
+ Word16 cod[] // o : Generated CN fixed codebook vector
+)
+{
+ Word16 i, j, k;
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ cod[i] = 0;
+ }
+
+// The reference ETSI code uses a global flag for Overflow. However in the
+// actual implementation a pointer to the overflow flag is passed into the
+// function so that it can be passed into the basic math functions L_mult()
+// and add()
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ i = pseudonoise (seed, 2); // generate pulse position
+ i = shr (extract_l (L_mult (i, 10)), 1);
+ i = add (i, k);
+
+ j = pseudonoise (seed, 1); // generate sign
+
+ if (j > 0)
+ {
+ cod[i] = 4096;
+ }
+ else
+ {
+ cod[i] = -4096;
+ }
+ }
+
+ return;
+}
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void build_CN_code(
+ Word32 *pSeed, /* i/o : Old CN generator shift register state */
+ Word16 cod[], /* o : Generated CN fixed codebook vector */
+ Flag *pOverflow /* i/o : Overflow flag */
+)
+{
+ Word16 i, j, k;
+ Word16 temp;
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ cod[i] = 0;
+ }
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ i = pseudonoise(pSeed, 2); /* generate pulse position */
+
+ temp = (Word16)(L_mult(i, 10, pOverflow));
+ i = temp >> 1;
+ i = add(i, k, pOverflow);
+
+ j = pseudonoise(pSeed, 1); /* generate sign */
+
+ if (j > 0)
+ {
+ cod[i] = 4096;
+ }
+ else
+ {
+ cod[i] = -4096;
+ }
+ }
+
+ return;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: build_CN_param
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pSeed = pointer to the Old CN generator shift register state (Word32)
+ n_param = Number of parameters to randomize (Word16)
+ param_size_table = table holding paameter sizes (Word16)
+ param[] = array to hold CN generated paramters (Word16)
+ pOverflow = pointer to overflow flag (Flag)
+
+ Outputs:
+ param[] = CN generated parameters (Word16)
+ pSeed = Updated CN generator shift register state (Word16)
+ pOverflow -> 1 if overflow occured
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+This function randomizes the speech parameters, so that they do not produce
+tonal artifacts if used by ECU.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ b_cn_cod.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+void build_CN_param (
+ Word16 *seed, // i/o : Old CN generator shift register state
+ const Word16 n_param, // i : number of params
+ const Word16 param_size_table[],// i : size of params
+ Word16 parm[] // o : CN Generated params
+ )
+{
+ Word16 i;
+ const Word16 *p;
+
+// The reference ETSI code uses a global flag for Overflow. However in the
+// actual implementation a pointer to the overflow flag is passed into the
+// function so that it can be passed into the basic math functions L_add()
+// and L_mult()
+
+ *seed = extract_l(L_add(L_shr(L_mult(*seed, 31821), 1), 13849L));
+
+ p = &window_200_40[*seed & 0x7F];
+ for(i=0; i< n_param;i++){
+ parm[i] = *p++ & ~(0xFFFF<<param_size_table[i]);
+ }
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void build_CN_param(
+ Word16 *pSeed, /* i/o : Old CN generator shift register state */
+ const Word16 n_param, /* i : number of params */
+ const Word16 param_size_table[],/* i : size of params */
+ Word16 parm[], /* o : CN Generated params */
+ Flag *pOverflow /* i/o : Overflow Flag */
+)
+
+{
+ Word16 i;
+ const Word16 *pTemp;
+ Word32 L_temp;
+ Word16 temp;
+
+ L_temp = L_mult(*pSeed, 31821, pOverflow);
+ L_temp >>= 1;
+
+ *pSeed = (Word16)(L_add(L_temp, 13849L, pOverflow));
+
+ pTemp = &window_200_40[*pSeed & 0x7F];
+
+ for (i = 0; i < n_param; i++)
+ {
+ temp = ~(0xFFFF << param_size_table[i]);
+ parm[i] = *pTemp++ & temp;
+ }
+}
+
diff --git a/media/codecs/amrnb/dec/src/b_cn_cod.h b/media/codecs/amrnb/dec/src/b_cn_cod.h
new file mode 100644
index 0000000..743237c
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/b_cn_cod.h
@@ -0,0 +1,171 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/add.h
+
+
+
+
+ Date: 08/11/2000
+
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Created separate header file for add function.
+
+ Description: Changed function prototype; pointer to overflow flag is passed
+ in as a parameter.
+
+ Description: Updated copyright section.
+ Changed "overflow" to "pOverflow" in the function prototype.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the comfort noise(CN) generator functions
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef B_CN_COD_H
+#define B_CN_COD_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern Word16 window_200_40[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+
+ ; FUNCTION NAME: pseudonoise
+ ;
+ ; PURPOSE: Generate a random integer value to use in comfort noise
+ ; generation. The algorithm uses polynomial x^31 + x^3 + 1
+ ; (length of PN sequence is 2^31 - 1).
+ ;
+ ----------------------------------------------------------------------------*/
+
+ Word16 pseudonoise(
+ Word32 *pShift_reg, /* i/o : Old CN generator shift register state */
+ Word16 no_bits /* i : Number of bits */
+ );
+
+ /*----------------------------------------------------------------------------
+
+ ; FUNCTION NAME: build_CN_code
+ ;
+ ; PURPOSE: Compute the comfort noise fixed codebook excitation. The
+ ; gains of the pulses are always +/-1.
+ ;
+ ----------------------------------------------------------------------------*/
+
+ void build_CN_code(
+ Word32 *pSeed, /* i/o : Old CN generator shift register state */
+ Word16 cod[], /* o : Generated CN fixed codebook vector */
+ Flag *pOverflow /* i/o : Overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+
+ ; FUNCTION NAME: build_CN_param
+ ;
+ ; PURPOSE: Randomize the speech parameters. So that they
+ ; do not produce tonal artifacts if used by ECU.
+ ;
+ ----------------------------------------------------------------------------*/
+
+ void build_CN_param(
+ Word16 *pSeed, /* i/o : Old CN generator shift register state */
+ const Word16 n_param, /* i : number of params */
+ const Word16 param_size_table[], /* i : size of params */
+ Word16 parm[], /* o : CN Generated params */
+ Flag *pOverflow /* i/o : Overflow Flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _B_CN_COD_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/bgnscd.cpp b/media/codecs/amrnb/dec/src/bgnscd.cpp
new file mode 100644
index 0000000..e732007
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/bgnscd.cpp
@@ -0,0 +1,589 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: ./audio/gsm-amr/c/src/bgnscd.c
+ Functions:
+ Bgn_scd_reset
+ Bgn_scd
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Background noise source characteristic detector (SCD)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "bgnscd.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "copy.h"
+#include "gmed_n.h"
+#include "sqrt_l.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define TRUE 1
+#define FALSE 0
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Bgn_scd_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = points to memory of type Bgn_scdState.
+
+ Outputs:
+ The memory of type Bgn_scdState pointed to by state is set to all
+ zeros.
+
+ Returns:
+ Returns 0 if memory was successfully initialized,
+ otherwise returns -1.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Resets state memory.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ bgnscd.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Bgn_scd_reset (Bgn_scdState *state)
+{
+ if (state == (Bgn_scdState *) NULL){
+ fprintf(stderr, "Bgn_scd_reset: invalid parameter\n");
+ return -1;
+ }
+
+ // Static vectors to zero
+ Set_zero (state->frameEnergyHist, L_ENERGYHIST);
+
+ // Initialize hangover handling
+ state->bgHangover = 0;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Bgn_scd_reset(Bgn_scdState *state)
+{
+ if (state == (Bgn_scdState *) NULL)
+ {
+ /* fprintf(stderr, "Bgn_scd_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ /* Static vectors to zero */
+ memset(state->frameEnergyHist, 0, L_ENERGYHIST*sizeof(Word16));
+
+ /* Initialize hangover handling */
+ state->bgHangover = 0;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Bgn_scd
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to state variables of type Bgn_scdState
+ ltpGainHist[] = LTP gain history (Word16)
+ speech[] = synthesis speech frame (Word16)
+ voicedHangover = pointer to # of frames after last voiced frame (Word16)
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ st = function updates the state variables of type Bgn_scdState
+ pointed to by st.
+ voicedHangover = function updates the # of frames after last voiced
+ frame pointed to by voicedHangover.
+ pOverflow = 1 if the basic math function L_add() results in saturation.
+ else pOverflow is zero.
+
+ Returns:
+ inbgNoise = flag if background noise is present (Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Characterize synthesis speech and detect background noise.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ bgnscd.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Bgn_scd (Bgn_scdState *st, // i : State variables for bgn SCD
+ Word16 ltpGainHist[], // i : LTP gain history
+ Word16 speech[], // o : synthesis speech frame
+ Word16 *voicedHangover // o : # of frames after last
+ voiced frame
+ )
+{
+ Word16 i;
+ Word16 prevVoiced, inbgNoise;
+ Word16 temp;
+ Word16 ltpLimit, frameEnergyMin;
+ Word16 currEnergy, noiseFloor, maxEnergy, maxEnergyLastPart;
+ Word32 s;
+
+ // Update the inBackgroundNoise flag (valid for use in next frame if BFI)
+ // it now works as a energy detector floating on top
+ // not as good as a VAD.
+
+ currEnergy = 0;
+ s = (Word32) 0;
+
+ for (i = 0; i < L_FRAME; i++)
+ {
+ s = L_mac (s, speech[i], speech[i]);
+ }
+
+ s = L_shl(s, 2);
+
+ currEnergy = extract_h (s);
+
+ frameEnergyMin = 32767;
+
+ for (i = 0; i < L_ENERGYHIST; i++)
+ {
+ if (sub(st->frameEnergyHist[i], frameEnergyMin) < 0)
+ frameEnergyMin = st->frameEnergyHist[i];
+ }
+
+ noiseFloor = shl (frameEnergyMin, 4); // Frame Energy Margin of 16
+
+ maxEnergy = st->frameEnergyHist[0];
+ for (i = 1; i < L_ENERGYHIST-4; i++)
+ {
+ if ( sub (maxEnergy, st->frameEnergyHist[i]) < 0)
+ {
+ maxEnergy = st->frameEnergyHist[i];
+ }
+ }
+
+ maxEnergyLastPart = st->frameEnergyHist[2*L_ENERGYHIST/3];
+ for (i = 2*L_ENERGYHIST/3+1; i < L_ENERGYHIST; i++)
+ {
+ if ( sub (maxEnergyLastPart, st->frameEnergyHist[i] ) < 0)
+ {
+ maxEnergyLastPart = st->frameEnergyHist[i];
+ }
+ }
+
+ inbgNoise = 0; // false
+
+ // Do not consider silence as noise
+ // Do not consider continuous high volume as noise
+ // Or if the current noise level is very low
+ // Mark as noise if under current noise limit
+ // OR if the maximum energy is below the upper limit
+
+ if ( (sub(maxEnergy, LOWERNOISELIMIT) > 0) &&
+ (sub(currEnergy, FRAMEENERGYLIMIT) < 0) &&
+ (sub(currEnergy, LOWERNOISELIMIT) > 0) &&
+ ( (sub(currEnergy, noiseFloor) < 0) ||
+ (sub(maxEnergyLastPart, UPPERNOISELIMIT) < 0)))
+ {
+ if (sub(add(st->bgHangover, 1), 30) > 0)
+ {
+ st->bgHangover = 30;
+ } else
+ {
+ st->bgHangover = add(st->bgHangover, 1);
+ }
+ }
+ else
+ {
+ st->bgHangover = 0;
+ }
+
+ // make final decision about frame state , act somewhat cautiosly
+ if (sub(st->bgHangover,1) > 0)
+ inbgNoise = 1; // true
+
+ for (i = 0; i < L_ENERGYHIST-1; i++)
+ {
+ st->frameEnergyHist[i] = st->frameEnergyHist[i+1];
+ }
+ st->frameEnergyHist[L_ENERGYHIST-1] = currEnergy;
+
+ // prepare for voicing decision; tighten the threshold after some
+ time in noise
+ ltpLimit = 13926; // 0.85 Q14
+ if (sub(st->bgHangover, 8) > 0)
+ {
+ ltpLimit = 15565; // 0.95 Q14
+ }
+ if (sub(st->bgHangover, 15) > 0)
+ {
+ ltpLimit = 16383; // 1.00 Q14
+ }
+
+ // weak sort of voicing indication.
+ prevVoiced = 0; // false
+
+ if (sub(gmed_n(<pGainHist[4], 5), ltpLimit) > 0)
+ {
+ prevVoiced = 1; // true
+ }
+ if (sub(st->bgHangover, 20) > 0) {
+ if (sub(gmed_n(ltpGainHist, 9), ltpLimit) > 0)
+ {
+ prevVoiced = 1; // true
+ }
+ else
+ {
+ prevVoiced = 0; // false
+ }
+ }
+
+ if (prevVoiced)
+ {
+ *voicedHangover = 0;
+ }
+ else
+ {
+ temp = add(*voicedHangover, 1);
+ if (sub(temp, 10) > 0)
+ {
+ *voicedHangover = 10;
+ }
+ else
+ {
+ *voicedHangover = temp;
+ }
+ }
+
+ return inbgNoise;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Bgn_scd(Bgn_scdState *st, /* i : State variables for bgn SCD */
+ Word16 ltpGainHist[], /* i : LTP gain history */
+ Word16 speech[], /* o : synthesis speech frame */
+ Word16 *voicedHangover,/* o : # of frames after last
+ voiced frame */
+ Flag *pOverflow
+ )
+{
+ Word16 i;
+ Word16 prevVoiced, inbgNoise;
+ Word16 temp;
+ Word16 ltpLimit, frameEnergyMin;
+ Word16 currEnergy, noiseFloor, maxEnergy, maxEnergyLastPart;
+ Word32 s, L_temp;
+
+
+ /* Update the inBackgroundNoise flag (valid for use in next frame if BFI) */
+ /* it now works as a energy detector floating on top */
+ /* not as good as a VAD. */
+
+ s = (Word32) 0;
+
+ for (i = L_FRAME - 1; i >= 0; i--)
+ {
+ L_temp = ((Word32) speech[i]) * speech[i];
+ if (L_temp != (Word32) 0x40000000L)
+ {
+ L_temp = L_temp << 1;
+ }
+ else
+ {
+ L_temp = MAX_32;
+ }
+ s = L_add(s, L_temp, pOverflow);
+ }
+
+ /* s is a sum of squares, so don't need to check for neg overflow */
+ if (s > (Word32)0x1fffffffL)
+ {
+ currEnergy = MAX_16;
+ }
+ else
+ {
+ currEnergy = (Word16)(s >> 14);
+ }
+
+ frameEnergyMin = 32767;
+ for (i = L_ENERGYHIST - 1; i >= 0; i--)
+ {
+ if (st->frameEnergyHist[i] < frameEnergyMin)
+ {
+ frameEnergyMin = st->frameEnergyHist[i];
+ }
+ }
+
+ /* Frame Energy Margin of 16 */
+ L_temp = (Word32)frameEnergyMin << 4;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ if (L_temp > 0)
+ {
+ noiseFloor = MAX_16;
+ }
+ else
+ {
+ noiseFloor = MIN_16;
+ }
+ }
+ else
+ {
+ noiseFloor = (Word16)(L_temp);
+ }
+
+ maxEnergy = st->frameEnergyHist[0];
+ for (i = L_ENERGYHIST - 5; i >= 1; i--)
+ {
+ if (maxEnergy < st->frameEnergyHist[i])
+ {
+ maxEnergy = st->frameEnergyHist[i];
+ }
+ }
+
+ maxEnergyLastPart = st->frameEnergyHist[2*L_ENERGYHIST/3];
+ for (i = 2 * L_ENERGYHIST / 3 + 1; i < L_ENERGYHIST; i++)
+ {
+ if (maxEnergyLastPart < st->frameEnergyHist[i])
+ {
+ maxEnergyLastPart = st->frameEnergyHist[i];
+ }
+ }
+
+ /* Do not consider silence as noise */
+ /* Do not consider continuous high volume as noise */
+ /* Or if the current noise level is very low */
+ /* Mark as noise if under current noise limit */
+ /* OR if the maximum energy is below the upper limit */
+
+ if ((maxEnergy > LOWERNOISELIMIT) &&
+ (currEnergy < FRAMEENERGYLIMIT) &&
+ (currEnergy > LOWERNOISELIMIT) &&
+ ((currEnergy < noiseFloor) ||
+ (maxEnergyLastPart < UPPERNOISELIMIT)))
+ {
+ if ((st->bgHangover + 1) > 30)
+ {
+ st->bgHangover = 30;
+ }
+ else
+ {
+ st->bgHangover += 1;
+ }
+ }
+ else
+ {
+ st->bgHangover = 0;
+ }
+
+ /* make final decision about frame state , act somewhat cautiosly */
+
+ if (st->bgHangover > 1)
+ {
+ inbgNoise = TRUE;
+ }
+ else
+ {
+ inbgNoise = FALSE;
+ }
+
+ for (i = 0; i < L_ENERGYHIST - 1; i++)
+ {
+ st->frameEnergyHist[i] = st->frameEnergyHist[i+1];
+ }
+ st->frameEnergyHist[L_ENERGYHIST-1] = currEnergy;
+
+ /* prepare for voicing decision; tighten the threshold after some
+ time in noise */
+
+ if (st->bgHangover > 15)
+ {
+ ltpLimit = 16383; /* 1.00 Q14 */
+ }
+ else if (st->bgHangover > 8)
+ {
+ ltpLimit = 15565; /* 0.95 Q14 */
+ }
+ else
+ {
+ ltpLimit = 13926; /* 0.85 Q14 */
+ }
+
+ /* weak sort of voicing indication. */
+ prevVoiced = FALSE;
+
+ if (gmed_n(<pGainHist[4], 5) > ltpLimit)
+ {
+ prevVoiced = TRUE;
+ }
+
+ if (st->bgHangover > 20)
+ {
+ if (gmed_n(ltpGainHist, 9) > ltpLimit)
+ {
+ prevVoiced = TRUE;
+ }
+ else
+ {
+ prevVoiced = FALSE;
+ }
+ }
+
+
+ if (prevVoiced)
+ {
+ *voicedHangover = 0;
+ }
+ else
+ {
+ temp = *voicedHangover + 1;
+
+ if (temp > 10)
+ {
+ *voicedHangover = 10;
+ }
+ else
+ {
+ *voicedHangover = temp;
+ }
+ }
+
+ return(inbgNoise);
+}
diff --git a/media/codecs/amrnb/dec/src/bgnscd.h b/media/codecs/amrnb/dec/src/bgnscd.h
new file mode 100644
index 0000000..41349d9
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/bgnscd.h
@@ -0,0 +1,159 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/bgnscd.h
+
+ Date: 12/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : bgnscd.h
+ Purpose : Background noise source charateristic detector (SCD)
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _BGNSCD_H_
+#define _BGNSCD_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+#define L_ENERGYHIST 60
+#define INV_L_FRAME 102
+
+
+ /* 2*(160*x)^2 / 65536 where x is FLP values 150,5 and 50 */
+#define FRAMEENERGYLIMIT 17578 /* 150 */
+#define LOWERNOISELIMIT 20 /* 5 */
+#define UPPERNOISELIMIT 1953 /* 50 */
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ /* history vector of past synthesis speech energy */
+ Word16 frameEnergyHist[L_ENERGYHIST];
+
+ /* state flags */
+ Word16 bgHangover; /* counter; number of frames after last speech frame */
+
+ } Bgn_scdState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /*
+ * Function : Bgn_scd_init
+ * Purpose : Allocates initializes state memory
+ * Description : Stores pointer to filter status struct in *st. This
+ * pointer has to be passed to Bgn_scd in each call.
+ * Returns : 0 on success
+ */
+ Word16 Bgn_scd_init(Bgn_scdState **st);
+
+ /*
+ * Function : Bgn_scd_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ */
+ Word16 Bgn_scd_reset(Bgn_scdState *st);
+
+ /*
+ * Function : Bgn_scd_exit
+ * Purpose : The memory used for state memory is freed
+ * Description : Stores NULL in *s
+ * Returns : void
+ */
+ void Bgn_scd_exit(Bgn_scdState **st);
+
+ /*
+ * Function : Bgn_scd
+ * Purpose : Charaterice synthesis speech and detect background noise
+ * Returns : background noise decision; 0 = bgn, 1 = no bgn
+ */
+ Word16 Bgn_scd(Bgn_scdState *st, /* i : State variables for bgn SCD */
+ Word16 ltpGainHist[], /* i : LTP gain history */
+ Word16 speech[], /* o : synthesis speech frame */
+ Word16 *voicedHangover,/* o : # of frames after last voiced frame */
+ Flag *pOverflow
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BGNSCD_H_ */
diff --git a/media/codecs/amrnb/dec/src/c_g_aver.cpp b/media/codecs/amrnb/dec/src/c_g_aver.cpp
new file mode 100644
index 0000000..91d3982
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/c_g_aver.cpp
@@ -0,0 +1,648 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/c_g_aver.c
+ Functions:
+ Cb_gain_average_reset
+ Cb_gain_average
+
+ Date: 03/28/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Made some changes to the comments to match the comments from
+ other modules.
+
+ Description: Made changes based on comments from the review meeting.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Defined one local variable per line.
+
+ Description: Removed the functions Cb_gain_average_init and
+ Cb_gain_average_exit. The Cb_gain_average related structure is no longer
+ dynamically allocated.
+
+ Description: Passing in pOverflow to comply with changes needed for EPOC
+ Updated the include files for the module.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description:
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains functions that reset and perform
+ codebook gain calculations.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "c_g_aver.h"
+#include "typedef.h"
+#include "mode.h"
+#include "cnst.h"
+
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Cb_gain_average_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type Cb_gain_averageState
+
+ Outputs:
+ Structure pointed to by state is initialized to zeros
+
+ Returns:
+ Returns 0 if memory was successfully initialized,
+ otherwise returns -1.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Resets state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c_g_aver.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Cb_gain_average_reset (Cb_gain_averageState *state)
+{
+ if (state == (Cb_gain_averageState *) NULL){
+ fprintf(stderr, "Cb_gain_average_reset: invalid parameter\n");
+ return -1;
+ }
+
+ // Static vectors to zero
+ Set_zero (state->cbGainHistory, L_CBGAINHIST);
+
+ // Initialize hangover handling
+ state->hangVar = 0;
+ state->hangCount= 0;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Cb_gain_average_reset(Cb_gain_averageState *state)
+{
+ if (state == (Cb_gain_averageState *) NULL)
+ {
+ /* fprint(stderr, "Cb_gain_average_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ /* Static vectors to zero */
+ memset(state->cbGainHistory, 0, L_CBGAINHIST*sizeof(Word16));
+
+ /* Initialize hangover handling */
+ state->hangVar = 0;
+ state->hangCount = 0;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Cb_gain_average
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structure of type Cb_gain_averageState
+ mode = AMR mode (enum Mode)
+ gain_code = CB gain (Word16)
+ lsp = the LSP for the current frame (Word16)
+ lspAver = the average of LSP for 8 frames (Word16)
+ bfi = bad frame indication flag (Word16)
+ prev_bf = previous bad frame indication flag (Word16)
+ pdfi = potential degraded bad frame ind flag (Word16)
+ prev_pdf = prev pot. degraded bad frame ind flag (Word16)
+ inBackgroundNoise = background noise decision (Word16)
+ voicedHangover = # of frames after last voiced frame (Word16)
+ pOverflow = address of overflow (Flag)
+
+ Returns:
+ cbGainMix = codebook gain (Word16)
+
+ Outputs:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The mix cb gains for MR475, MR515, MR59, MR67, MR102; gain_code other modes
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c_g_aver.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Cb_gain_average (
+ Cb_gain_averageState *st, // i/o : State variables for CB gain avergeing
+ enum Mode mode, // i : AMR mode
+ Word16 gain_code, // i : CB gain Q1
+ Word16 lsp[], // i : The LSP for the current frame Q15
+ Word16 lspAver[], // i : The average of LSP for 8 frames Q15
+ Word16 bfi, // i : bad frame indication flag
+ Word16 prev_bf, // i : previous bad frame indication flag
+ Word16 pdfi, // i : potential degraded bad frame ind flag
+ Word16 prev_pdf, // i : prev pot. degraded bad frame ind flag
+ Word16 inBackgroundNoise, // i : background noise decision
+ Word16 voicedHangover // i : # of frames after last voiced frame
+ )
+{
+ //---------------------------------------------------------*
+ * Compute mixed cb gain, used to make cb gain more *
+ * smooth in background noise for modes 5.15, 5.9 and 6.7 *
+ * states that needs to be updated by all *
+ *---------------------------------------------------------
+ Word16 i;
+ Word16 cbGainMix, diff, tmp_diff, bgMix, cbGainMean;
+ Word32 L_sum;
+ Word16 tmp[M], tmp1, tmp2, shift1, shift2, shift;
+
+ // set correct cbGainMix for MR74, MR795, MR122
+ cbGainMix = gain_code;
+
+ *-------------------------------------------------------*
+ * Store list of CB gain needed in the CB gain *
+ * averaging *
+ *-------------------------------------------------------*
+ for (i = 0; i < (L_CBGAINHIST-1); i++)
+ {
+ st->cbGainHistory[i] = st->cbGainHistory[i+1];
+ }
+ st->cbGainHistory[L_CBGAINHIST-1] = gain_code;
+
+ // compute lsp difference
+ for (i = 0; i < M; i++) {
+ tmp1 = abs_s(sub(lspAver[i], lsp[i])); // Q15
+ shift1 = sub(norm_s(tmp1), 1); // Qn
+ tmp1 = shl(tmp1, shift1); // Q15+Qn
+ shift2 = norm_s(lspAver[i]); // Qm
+ tmp2 = shl(lspAver[i], shift2); // Q15+Qm
+ tmp[i] = div_s(tmp1, tmp2); // Q15+(Q15+Qn)-(Q15+Qm)
+ shift = sub(add(2, shift1), shift2);
+ if (shift >= 0)
+ {
+ tmp[i] = shr(tmp[i], shift); // Q15+Qn-Qm-Qx=Q13
+ }
+ else
+ {
+ tmp[i] = shl(tmp[i], negate(shift)); // Q15+Qn-Qm-Qx=Q13
+ }
+ }
+
+ diff = tmp[0];
+ for (i = 1; i < M; i++) {
+ diff = add(diff, tmp[i]); // Q13
+ }
+
+ // Compute hangover
+ if (sub(diff, 5325) > 0) // 0.65 in Q11
+ {
+ st->hangVar = add(st->hangVar, 1);
+ }
+ else
+ {
+ st->hangVar = 0;
+ }
+
+ if (sub(st->hangVar, 10) > 0)
+ {
+ st->hangCount = 0; // Speech period, reset hangover variable
+ }
+
+ // Compute mix constant (bgMix)
+ bgMix = 8192; // 1 in Q13
+ if ((sub(mode, MR67) <= 0) || (sub(mode, MR102) == 0))
+ // MR475, MR515, MR59, MR67, MR102
+ {
+ // if errors and presumed noise make smoothing probability stronger
+ if (((((pdfi != 0) && (prev_pdf != 0)) || (bfi != 0) || (prev_bf != 0)) &&
+ (sub(voicedHangover, 1) > 0) && (inBackgroundNoise != 0) &&
+ ((sub(mode, MR475) == 0) ||
+ (sub(mode, MR515) == 0) ||
+ (sub(mode, MR59) == 0)) ))
+ {
+ // bgMix = min(0.25, max(0.0, diff-0.55)) / 0.25;
+ tmp_diff = sub(diff, 4506); // 0.55 in Q13
+
+ // max(0.0, diff-0.55)
+ if (tmp_diff > 0)
+ {
+ tmp1 = tmp_diff;
+ }
+ else
+ {
+ tmp1 = 0;
+ }
+
+ // min(0.25, tmp1)
+ if (sub(2048, tmp1) < 0)
+ {
+ bgMix = 8192;
+ }
+ else
+ {
+ bgMix = shl(tmp1, 2);
+ }
+ }
+ else
+ {
+ // bgMix = min(0.25, max(0.0, diff-0.40)) / 0.25;
+ tmp_diff = sub(diff, 3277); // 0.4 in Q13
+
+ // max(0.0, diff-0.40)
+ if (tmp_diff > 0)
+ {
+ tmp1 = tmp_diff;
+ }
+ else
+ {
+ tmp1 = 0;
+ }
+
+ // min(0.25, tmp1)
+ if (sub(2048, tmp1) < 0)
+ {
+ bgMix = 8192;
+ }
+ else
+ {
+ bgMix = shl(tmp1, 2);
+ }
+ }
+
+ if ((sub(st->hangCount, 40) < 0) || (sub(diff, 5325) > 0)) // 0.65 in Q13
+ {
+ bgMix = 8192; // disable mix if too short time since
+ }
+
+ // Smoothen the cb gain trajectory
+ // smoothing depends on mix constant bgMix
+ L_sum = L_mult(6554, st->cbGainHistory[2]); // 0.2 in Q15; L_sum in Q17
+ for (i = 3; i < L_CBGAINHIST; i++)
+ {
+ L_sum = L_mac(L_sum, 6554, st->cbGainHistory[i]);
+ }
+ cbGainMean = pv_round(L_sum); // Q1
+
+ // more smoothing in error and bg noise (NB no DFI used here)
+ if (((bfi != 0) || (prev_bf != 0)) && (inBackgroundNoise != 0) &&
+ ((sub(mode, MR475) == 0) ||
+ (sub(mode, MR515) == 0) ||
+ (sub(mode, MR59) == 0)) )
+ {
+ L_sum = L_mult(4681, st->cbGainHistory[0]); // 0.143 in Q15; L_sum in Q17
+ for (i = 1; i < L_CBGAINHIST; i++)
+ {
+ L_sum = L_mac(L_sum, 4681, st->cbGainHistory[i]);
+ }
+ cbGainMean = pv_round(L_sum); // Q1
+ }
+
+ // cbGainMix = bgMix*cbGainMix + (1-bgMix)*cbGainMean;
+ L_sum = L_mult(bgMix, cbGainMix); // L_sum in Q15
+ L_sum = L_mac(L_sum, 8192, cbGainMean);
+ L_sum = L_msu(L_sum, bgMix, cbGainMean);
+ cbGainMix = pv_round(L_shl(L_sum, 2)); // Q1
+ }
+
+ st->hangCount = add(st->hangCount, 1);
+ return cbGainMix;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Cb_gain_average(
+ Cb_gain_averageState *st, /* i/o : State variables for CB gain averaging */
+ enum Mode mode, /* i : AMR mode */
+ Word16 gain_code, /* i : CB gain Q1 */
+ Word16 lsp[], /* i : The LSP for the current frame Q15 */
+ Word16 lspAver[], /* i : The average of LSP for 8 frames Q15 */
+ Word16 bfi, /* i : bad frame indication flag */
+ Word16 prev_bf, /* i : previous bad frame indication flag */
+ Word16 pdfi, /* i : potential degraded bad frame ind flag */
+ Word16 prev_pdf, /* i : prev pot. degraded bad frame ind flag */
+ Word16 inBackgroundNoise, /* i : background noise decision */
+ Word16 voicedHangover, /* i : # of frames after last voiced frame */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 cbGainMix;
+ Word16 diff;
+ Word16 tmp_diff;
+ Word16 bgMix;
+ Word16 cbGainMean;
+ Word32 L_sum;
+ Word16 tmp[M];
+ Word16 tmp1;
+ Word16 tmp2;
+ Word16 shift1;
+ Word16 shift2;
+ Word16 shift;
+
+ /*---------------------------------------------------------*
+ * Compute mixed cb gain, used to make cb gain more *
+ * smooth in background noise for modes 5.15, 5.9 and 6.7 *
+ * states that needs to be updated by all *
+ *---------------------------------------------------------*/
+
+ /* set correct cbGainMix for MR74, MR795, MR122 */
+ cbGainMix = gain_code;
+
+ /*-------------------------------------------------------*
+ * Store list of CB gain needed in the CB gain *
+ * averaging *
+ *-------------------------------------------------------*/
+ for (i = 0; i < (L_CBGAINHIST - 1); i++)
+ {
+ st->cbGainHistory[i] = st->cbGainHistory[i+1];
+ }
+ st->cbGainHistory[L_CBGAINHIST-1] = gain_code;
+
+ diff = 0;
+
+ /* compute lsp difference */
+ for (i = 0; i < M; i++)
+ {
+ tmp1 = abs_s(sub(*(lspAver + i), *(lsp + i), pOverflow));
+ /* Q15 */
+ shift1 = sub(norm_s(tmp1), 1, pOverflow); /* Qn */
+ tmp1 = shl(tmp1, shift1, pOverflow); /* Q15+Qn */
+ shift2 = norm_s(*(lspAver + i)); /* Qm */
+ tmp2 = shl(*(lspAver + i), shift2, pOverflow); /* Q15+Qm */
+ tmp[i] = div_s(tmp1, tmp2); /* Q15+(Q15+Qn)-(Q15+Qm) */
+
+ shift = 2 + shift1 - shift2;
+
+ if (shift >= 0)
+ {
+ *(tmp + i) = shr(*(tmp + i), shift, pOverflow);
+ /* Q15+Qn-Qm-Qx=Q13 */
+ }
+ else
+ {
+ *(tmp + i) = shl(*(tmp + i), negate(shift), pOverflow);
+ /* Q15+Qn-Qm-Qx=Q13 */
+ }
+
+ diff = add(diff, *(tmp + i), pOverflow); /* Q13 */
+ }
+
+ /* Compute hangover */
+
+ if (diff > 5325) /* 0.65 in Q11 */
+ {
+ st->hangVar += 1;
+ }
+ else
+ {
+ st->hangVar = 0;
+ }
+
+
+ if (st->hangVar > 10)
+ {
+ /* Speech period, reset hangover variable */
+ st->hangCount = 0;
+ }
+
+ /* Compute mix constant (bgMix) */
+ bgMix = 8192; /* 1 in Q13 */
+
+ if ((mode <= MR67) || (mode == MR102))
+ /* MR475, MR515, MR59, MR67, MR102 */
+ {
+ /* if errors and presumed noise make smoothing probability stronger */
+
+ if (((((pdfi != 0) && (prev_pdf != 0)) || (bfi != 0) ||
+ (prev_bf != 0))
+ && (voicedHangover > 1)
+ && (inBackgroundNoise != 0)
+ && ((mode == MR475) || (mode == MR515) ||
+ (mode == MR59))))
+ {
+ /* bgMix = min(0.25, max(0.0, diff-0.55)) / 0.25; */
+ tmp_diff = sub(diff, 4506, pOverflow); /* 0.55 in Q13 */
+ }
+ else
+ {
+ /* bgMix = min(0.25, max(0.0, diff-0.40)) / 0.25; */
+ tmp_diff = sub(diff, 3277, pOverflow); /* 0.4 in Q13 */
+ }
+
+ /* max(0.0, diff-0.55) or */
+ /* max(0.0, diff-0.40) */
+ if (tmp_diff > 0)
+ {
+ tmp1 = tmp_diff;
+ }
+ else
+ {
+ tmp1 = 0;
+ }
+
+ /* min(0.25, tmp1) */
+ if (2048 < tmp1)
+ {
+ bgMix = 8192;
+ }
+ else
+ {
+ bgMix = shl(tmp1, 2, pOverflow);
+ }
+
+ if ((st->hangCount < 40) || (diff > 5325)) /* 0.65 in Q13 */
+ {
+ /* disable mix if too short time since */
+ bgMix = 8192;
+ }
+
+ /* Smoothen the cb gain trajectory */
+ /* smoothing depends on mix constant bgMix */
+ L_sum = L_mult(6554, st->cbGainHistory[2], pOverflow);
+ /* 0.2 in Q15; L_sum in Q17 */
+
+ for (i = 3; i < L_CBGAINHIST; i++)
+ {
+ L_sum = L_mac(L_sum, 6554, st->cbGainHistory[i], pOverflow);
+ }
+ cbGainMean = pv_round(L_sum, pOverflow); /* Q1 */
+
+ /* more smoothing in error and bg noise (NB no DFI used here) */
+
+ if (((bfi != 0) || (prev_bf != 0)) && (inBackgroundNoise != 0)
+ && ((mode == MR475) || (mode == MR515)
+ || (mode == MR59)))
+ {
+ /* 0.143 in Q15; L_sum in Q17 */
+ L_sum = L_mult(4681, st->cbGainHistory[0], pOverflow);
+ for (i = 1; i < L_CBGAINHIST; i++)
+ {
+ L_sum =
+ L_mac(L_sum, 4681, st->cbGainHistory[i], pOverflow);
+ }
+ cbGainMean = pv_round(L_sum, pOverflow); /* Q1 */
+ }
+
+ /* cbGainMix = bgMix*cbGainMix + (1-bgMix)*cbGainMean; */
+ /* L_sum in Q15 */
+ L_sum = L_mult(bgMix, cbGainMix, pOverflow);
+ L_sum = L_mac(L_sum, 8192, cbGainMean, pOverflow);
+ L_sum = L_msu(L_sum, bgMix, cbGainMean, pOverflow);
+ cbGainMix = pv_round(L_shl(L_sum, 2, pOverflow), pOverflow); /* Q1 */
+ }
+
+ st->hangCount += 1;
+
+ return (cbGainMix);
+}
+
diff --git a/media/codecs/amrnb/dec/src/c_g_aver.h b/media/codecs/amrnb/dec/src/c_g_aver.h
new file mode 100644
index 0000000..0b53753
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/c_g_aver.h
@@ -0,0 +1,163 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/c_g_aver.h
+
+ Date: 12/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : c_g_aver.h
+ Purpose : Background noise source charateristic detector (SCD)
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _C_G_AVER_H_
+#define _C_G_AVER_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+#define L_CBGAINHIST 7
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ /* history vector of past synthesis speech energy */
+ Word16 cbGainHistory[L_CBGAINHIST];
+
+ /* state flags */
+ Word16 hangVar; /* counter; */
+ Word16 hangCount; /* counter; */
+
+ } Cb_gain_averageState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /*
+ * Function : Cb_gain_average_init
+ * Purpose : Allocates initializes state memory
+ * Description : Stores pointer to filter status struct in *st. This
+ * pointer has to be passed to Cb_gain_average in each call.
+ * Returns : 0 on success
+ */
+ Word16 Cb_gain_average_init(Cb_gain_averageState **st);
+
+ /*
+ * Function : Cb_gain_average_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ */
+ Word16 Cb_gain_average_reset(Cb_gain_averageState *st);
+
+ /*
+ * Function : Cb_gain_average_exit
+ * Purpose : The memory used for state memory is freed
+ * Description : Stores NULL in *s
+ * Returns : void
+ */
+ void Cb_gain_average_exit(Cb_gain_averageState **st);
+
+ /*
+ * Function : Cb_gain_average
+ * Purpose : Charaterice synthesis speech and detect background noise
+ * Returns : background noise decision; 0 = bgn, 1 = no bgn
+ */
+ Word16 Cb_gain_average(
+ Cb_gain_averageState *st, /* i/o : State variables for CB gain avergeing */
+ enum Mode mode, /* i : AMR mode */
+ Word16 gain_code, /* i : CB gain Q1 */
+ Word16 lsp[], /* i : The LSP for the current frame Q15 */
+ Word16 lspAver[], /* i : The average of LSP for 8 frames Q15 */
+ Word16 bfi, /* i : bad frame indication flag */
+ Word16 prev_bf, /* i : previous bad frame indication flag */
+ Word16 pdfi, /* i : potential degraded bad frame ind flag */
+ Word16 prev_pdf, /* i : prev pot. degraded bad frame ind flag */
+ Word16 inBackgroundNoise, /* i : background noise decision */
+ Word16 voicedHangover, /* i : # of frames after last voiced frame */
+ Flag *pOverflow
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _C_G_AVER_H_ */
+
+
diff --git a/media/codecs/amrnb/dec/src/d1035pf.cpp b/media/codecs/amrnb/dec/src/d1035pf.cpp
new file mode 100644
index 0000000..861b3e6
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d1035pf.cpp
@@ -0,0 +1,263 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d1035pf.c
+
+ Date: 04/14/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Updated file per comments gathered from Phase 2/3 review.
+
+ Description: Synchronized file with UTMS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Removed inclusion of "gray.tab".
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d1035pf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NB_PULSE 10 /* number of pulses */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dec_10i40_35bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ index = buffer containing index of 10 pulses; each element is
+ represented by sign+position
+ cod = buffer of algebraic (fixed) codebook excitation
+
+ Outputs:
+ cod buffer contains the new algebraic codebook excitation
+
+ Returns:
+ None
+
+ Global Variables Used:
+ dgray = gray decoding table
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function builds the innovative codevector from the received index of
+ algebraic codebook. See c1035pf.c for more details about the algebraic
+ codebook structure.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d1035pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void dec_10i40_35bits (
+ Word16 index[], // (i) : index of 10 pulses (sign+position)
+ Word16 cod[] // (o) : algebraic (fixed) codebook excitation
+)
+{
+ Word16 i, j, pos1, pos2, sign, tmp;
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ cod[i] = 0;
+ }
+
+ // decode the positions and signs of pulses and build the codeword
+
+ for (j = 0; j < NB_TRACK; j++)
+ {
+ // compute index i
+
+ tmp = index[j];
+ i = tmp & 7;
+ i = dgray[i];
+
+ i = extract_l (L_shr (L_mult (i, 5), 1));
+ pos1 = add (i, j); // position of pulse "j"
+
+ i = shr (tmp, 3) & 1;
+ if (i == 0)
+ {
+ sign = 4096; // +1.0
+ }
+ else
+ {
+ sign = -4096; // -1.0
+ }
+
+ cod[pos1] = sign;
+
+ // compute index i
+
+ i = index[add (j, 5)] & 7;
+ i = dgray[i];
+ i = extract_l (L_shr (L_mult (i, 5), 1));
+
+ pos2 = add (i, j); // position of pulse "j+5"
+
+ if (sub (pos2, pos1) < 0)
+ {
+ sign = negate (sign);
+ }
+ cod[pos2] = add (cod[pos2], sign);
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void dec_10i40_35bits(
+ Word16 index[], /* (i) : index of 10 pulses (sign+position) */
+ Word16 cod[] /* (o) : algebraic (fixed) codebook excitation */
+)
+{
+ Word16 i, j, pos1, pos2;
+ Word16 sign, tmp;
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ *(cod + i) = 0;
+ }
+
+ /* decode the positions and signs of pulses and build the codeword */
+
+ for (j = 0; j < NB_TRACK; j++)
+ {
+ /* compute index i */
+
+ tmp = *(index + j);
+ i = tmp & 7;
+ i = *(dgray + i);
+
+ i = (Word16)(i * 5);
+ pos1 = i + j; /* position of pulse "j" */
+
+ i = (tmp >> 3) & 1;
+
+ if (i == 0)
+ {
+ sign = 4096; /* +1.0 */
+ }
+ else
+ {
+ sign = -4096; /* -1.0 */
+ }
+
+ *(cod + pos1) = sign;
+
+ /* compute index i */
+
+ i = *(index + j + 5) & 7;
+ i = *(dgray + i);
+ i = (Word16)(i * 5);
+
+ pos2 = i + j; /* position of pulse "j+5" */
+
+
+ if (pos2 < pos1)
+ {
+ sign = negate(sign);
+ }
+ *(cod + pos2) += sign;
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/d1035pf.h b/media/codecs/amrnb/dec/src/d1035pf.h
new file mode 100644
index 0000000..51f1f42
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d1035pf.h
@@ -0,0 +1,117 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/d1035pf.h
+
+ Date: 09/28/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Added extern declaration for dgray[] defined
+ in gray_tbl.c
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the prototype declaration for dec_10i40_35bits function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef D1035PF_H
+#define D1035PF_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern Word16 dgray[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void dec_10i40_35bits(
+ Word16 index[], /* (i) : index of 10 pulses (sign+position) */
+ Word16 cod[] /* (o) : algebraic (fixed) codebook excitation */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _D1035PF_H_ */
diff --git a/media/codecs/amrnb/dec/src/d2_11pf.cpp b/media/codecs/amrnb/dec/src/d2_11pf.cpp
new file mode 100644
index 0000000..e1e544f
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d2_11pf.cpp
@@ -0,0 +1,224 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d2_11pf.c
+ Functions:
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to place file in the correct template format. Eliminated
+ use of special functions to perform simple mathematical operations.
+
+ Description: Per review comments...
+ (1) Removed include of "count.h" and "basic_op.h"
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d2_11pf.h"
+#include "typedef.h"
+#include "cnst.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NB_PULSE 2
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: decode_2i40_11bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ sign -- Word16 -- signs of 2 pulses.
+ index -- Word16 -- Positions of the 2 pulses.
+
+ Outputs:
+ cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void decode_2i40_11bits(
+ Word16 sign, /* i : signs of 2 pulses. */
+ Word16 index, /* i : Positions of the 2 pulses. */
+ Word16 cod[] /* o : algebraic (fixed) codebook excitation */
+)
+
+{
+ Word16 i;
+ Word16 j;
+
+ Word16 pos[NB_PULSE];
+
+ /* Decode the positions */
+
+ j = index & 0x1;
+
+ index >>= 1;
+
+ i = index & 0x7;
+
+ pos[0] = i * 5 + j * 2 + 1;
+
+
+
+
+ index >>= 3;
+
+ j = index & 0x3;
+
+ index >>= 2;
+
+ i = index & 0x7;
+
+ if (j == 3)
+ {
+ pos[1] = i * 5 + 4;
+ }
+ else
+ {
+ pos[1] = i * 5 + j;
+ }
+
+
+
+
+ /* decode the signs and build the codeword */
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ cod[i] = 0;
+ }
+
+ for (j = 0; j < NB_PULSE; j++)
+ {
+ i = sign & 1;
+
+ /* This line is equivalent to...
+ *
+ *
+ * if (i == 1)
+ * {
+ * cod[pos[j]] = 8191;
+ * }
+ * if (i == 0)
+ * {
+ * cod[pos[j]] = -8192;
+ * }
+ */
+
+ cod[pos[j]] = i * 16383 - 8192;
+
+ sign >>= 1;
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/d2_11pf.h b/media/codecs/amrnb/dec/src/d2_11pf.h
new file mode 100644
index 0000000..aaf2e08
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d2_11pf.h
@@ -0,0 +1,93 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : d2_11pf.h
+* Purpose : Algebraic codebook decoder
+*
+********************************************************************************
+*/
+#ifndef d2_11pf_h
+#define d2_11pf_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * LOCAL VARIABLES AND TABLES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ /*************************************************************************
+ *
+ * FUNCTION: decode_2i40_11bits (decod_ACELP())
+ *
+ * PURPOSE: Algebraic codebook decoder for 2 pulses coded with 11 bits
+ *
+ *************************************************************************/
+
+ void decode_2i40_11bits(
+ Word16 sign, /* i : signs of 2 pulses. */
+ Word16 index, /* i : Positions of the 2 pulses. */
+ Word16 cod[] /* o : algebraic (fixed) codebook excitation */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/dec/src/d2_9pf.cpp b/media/codecs/amrnb/dec/src/d2_9pf.cpp
new file mode 100644
index 0000000..2c36706
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d2_9pf.cpp
@@ -0,0 +1,248 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d2_9pf.c
+ Functions: decode_2i40_9bits
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to place file in the correct template format. Eliminated
+ use of special functions to perform simple mathematical operations, where
+ possible. Added the parameter pOverflow for the basic math operations.
+
+ Description: Per review comments...
+ (1) Removed include of basic_op.h, replaced with shl.h
+ (2) Added pOverflow to the output section of the template
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+ FUNCTION: decode_2i40_9bits (decod_ACELP())
+
+ PURPOSE: Algebraic codebook decoder. For details about the encoding see
+ c2_9pf.c
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d2_9pf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NB_PULSE 2
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ extern const Word16 startPos[];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: decode_2i40_11bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ sign -- Word16 -- signs of 2 pulses.
+ index -- Word16 -- Positions of the 2 pulses.
+
+ Outputs:
+ cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
+ pOverflow = pointer to overflow flag
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void decode_2i40_9bits(
+ Word16 subNr, /* i : subframe number */
+ Word16 sign, /* i : signs of 2 pulses. */
+ Word16 index, /* i : Positions of the 2 pulses. */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+
+ Word16 pos[NB_PULSE];
+
+ /* Decode the positions */
+ /* table bit is the MSB */
+
+ j = (Word16)(index & 64);
+
+ j >>= 3;
+
+ i = index & 7;
+
+ k =
+ shl(
+ subNr,
+ 1,
+ pOverflow);
+
+ k += j;
+
+ /* pos0 =i*5+startPos[j*8+subNr*2] */
+ pos[0] = i * 5 + startPos[k++];
+
+
+ index >>= 3;
+
+ i = index & 7;
+
+ /* pos1 =i*5+startPos[j*8+subNr*2 + 1] */
+ pos[1] = i * 5 + startPos[k];
+
+
+ /* decode the signs and build the codeword */
+
+ for (i = L_SUBFR - 1; i >= 0; i--)
+ {
+ cod[i] = 0;
+ }
+
+ for (j = 0; j < NB_PULSE; j++)
+ {
+ i = sign & 0x1;
+
+ /* This line is equivalent to...
+ *
+ *
+ * if (i == 1)
+ * {
+ * cod[pos[j]] = 8191;
+ * }
+ * if (i == 0)
+ * {
+ * cod[pos[j]] = -8192;
+ * }
+ */
+
+ cod[pos[j]] = i * 16383 - 8192;
+
+ sign >>= 1;
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/d2_9pf.h b/media/codecs/amrnb/dec/src/d2_9pf.h
new file mode 100644
index 0000000..38076d8
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d2_9pf.h
@@ -0,0 +1,122 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/d2_9pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the d2_9pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef d2_9pf_h
+#define d2_9pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void decode_2i40_9bits(
+ Word16 subNr, /* i : subframe number */
+ Word16 sign, /* i : signs of 2 pulses. */
+ Word16 index, /* i : Positions of the 2 pulses. */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _d2_9PF_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/d3_14pf.cpp b/media/codecs/amrnb/dec/src/d3_14pf.cpp
new file mode 100644
index 0000000..d1912cf
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d3_14pf.cpp
@@ -0,0 +1,233 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d3_14pf.c
+ Functions: decode_3i40_14bits
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to place file in the correct template format. Eliminated
+ use of special functions to perform simple mathematical operations.
+
+ Description: Per review comments...
+ (1) Removed include of "count.h" and "basic_op.h"
+ (2) Updated the pathname to indicate the correct file. (Line 39)
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+ FUNCTION: decode_3i40_14bits (decod_ACELP())
+
+ PURPOSE: Algebraic codebook decoder. For details about the encoding see
+ c3_14pf.c
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "d3_14pf.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NB_PULSE 3 /* number of pulses */
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: decode_3i40_14bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ sign -- Word16 -- signs of 3 pulses.
+ index -- Word16 -- Positions of the 3 pulses.
+
+ Outputs:
+ cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void decode_3i40_14bits(
+ Word16 sign, /* i : signs of 3 pulses. */
+ Word16 index, /* i : Positions of the 3 pulses. */
+ Word16 cod[] /* o : algebraic (fixed) codebook excitation */
+)
+{
+ Word16 i;
+ Word16 j;
+
+ Word16 pos[NB_PULSE];
+
+ /* Decode the positions */
+
+ i = index & 0x7;
+
+ pos[0] = i * 5;
+
+
+
+
+
+ index >>= 3;
+
+ j = index & 0x1;
+
+ index >>= 1;
+
+ i = index & 0x7;
+
+ pos[1] = i * 5 + j * 2 + 1;
+
+
+
+
+
+ index >>= 3;
+
+ j = index & 0x1;
+
+ index >>= 1;
+
+ i = index & 0x7;
+
+ pos[2] = i * 5 + j * 2 + 2;
+
+
+ /* decode the signs and build the codeword */
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ cod[i] = 0;
+ }
+
+ for (j = 0; j < NB_PULSE; j++)
+ {
+ i = sign & 1;
+
+ /* This line is equivalent to...
+ *
+ *
+ * if (i == 1)
+ * {
+ * cod[pos[j]] = 8191;
+ * }
+ * if (i == 0)
+ * {
+ * cod[pos[j]] = -8192;
+ * }
+ */
+
+ cod[pos[j]] = i * 16383 - 8192;
+
+ sign >>= 1;
+
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/d3_14pf.h b/media/codecs/amrnb/dec/src/d3_14pf.h
new file mode 100644
index 0000000..1e2e0cd
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d3_14pf.h
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/d2_9pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the d3_14pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef d3_14pf_h
+#define d3_14pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void decode_3i40_14bits(
+ Word16 sign, /* i : signs of 3 pulses. */
+ Word16 index, /* i : Positions of the 3 pulses. */
+ Word16 cod[] /* o : algebraic (fixed) codebook excitation */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _d3_14PF_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/d4_17pf.cpp b/media/codecs/amrnb/dec/src/d4_17pf.cpp
new file mode 100644
index 0000000..ece82c0
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d4_17pf.cpp
@@ -0,0 +1,271 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d4_17pf.c
+ Functions: decode_4i40_17bits
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to place file in the correct template format. Eliminated
+ use of special functions to perform simple mathematical operations.
+
+ Description: An incorrect comment in the original source lead me to implement
+ the calculation of pos[2] incorrectly. The correct formula is pos2 =i*5+2,
+ not pos2 = i*5 + 1.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+ FUNCTION: decode_4i40_17bits (decod_ACELP())
+
+ PURPOSE: Algebraic codebook decoder. For details about the encoding see
+ c4_17pf.c
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "d4_17pf.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NB_PULSE 4 /* number of pulses */
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 dgray[];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: decode_4i40_17bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ sign -- Word16 -- signs of 3 pulses.
+ index -- Word16 -- Positions of the 3 pulses.
+
+ Outputs:
+ cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d4_17pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void decode_4i40_17bits(
+ Word16 sign, /* i : signs of 4 pulses. */
+ Word16 index, /* i : Positions of the 4 pulses. */
+ Word16 cod[] /* o : algebraic (fixed) codebook excitation */
+)
+{
+ Word16 i;
+ Word16 j;
+
+ Word16 pos[NB_PULSE];
+
+ /* Index is a 13-bit value. 3 bits each correspond to the
+ * positions 0-2, with 4 bits allocated for position 3.
+ *
+ *
+ * [][][][] [][][] [][][] [][][]
+ * | | | |
+ * | | | |
+ * pos3 pos2 pos1 pos0
+ */
+
+ /* Decode the positions */
+
+ i = index & 0x7;
+
+ i = dgray[i];
+
+ pos[0] = i * 5; /* pos0 =i*5 */
+
+
+ index >>= 3;
+
+ i = index & 0x7;
+
+ i = dgray[i];
+
+ pos[1] = i * 5 + 1; /* pos1 =i*5+1 */
+
+
+
+ index >>= 3;
+
+ i = index & 0x7;
+
+ i = dgray[i];
+
+ pos[2] = i * 5 + 2; /* pos2 =i*5+2 */
+
+
+
+
+
+ index >>= 3;
+
+ j = index & 0x1;
+
+ index >>= 1;
+
+ i = index & 0x7;
+
+ i = dgray[i];
+
+ pos[3] = i * 5 + 3 + j; /* pos3 =i*5+3+j */
+
+
+ /* decode the signs and build the codeword */
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ cod[i] = 0;
+ }
+
+ for (j = 0; j < NB_PULSE; j++)
+ {
+ i = sign & 0x1;
+
+ /* This line is equivalent to...
+ *
+ *
+ * if (i == 1)
+ * {
+ * cod[pos[j]] = 8191;
+ * }
+ * if (i == 0)
+ * {
+ * cod[pos[j]] = -8192;
+ * }
+ */
+
+ cod[pos[j]] = i * 16383 - 8192;
+
+ sign >>= 1;
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/d4_17pf.h b/media/codecs/amrnb/dec/src/d4_17pf.h
new file mode 100644
index 0000000..5dc43f3
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d4_17pf.h
@@ -0,0 +1,119 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/d4_17pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the d4_17pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef d4_17pf_h
+#define d4_17pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void decode_4i40_17bits(
+ Word16 sign, /* i : signs of 4 pulses. */
+ Word16 index, /* i : Positions of the 4 pulses. */
+ Word16 cod[] /* o : algebraic (fixed) codebook excitation */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _d4_17PF_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/d8_31pf.cpp b/media/codecs/amrnb/dec/src/d8_31pf.cpp
new file mode 100644
index 0000000..917c47f
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d8_31pf.cpp
@@ -0,0 +1,626 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d8_31pf.c
+ Functions:
+
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to pass overflow flag through to basic math function.
+ The flag is passed back to the calling function by pointer reference.
+
+ Description: Per review comments...
+ (1) Removed include of "count.h" and "basic_op.h"
+ (2) Added includes of mult.h, shl.h, shr.h, add.h, sub.h, negate.h,
+ L_mult.h, and L_shr.h
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d8_31pf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NB_PULSE 8 /* number of pulses */
+
+/* define values/representation for output codevector and sign */
+#define POS_CODE 8191
+#define NEG_CODE 8191
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: decompress10
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ MSBs -- Word16 -- MSB part of the index
+ LSBs -- Word16 -- LSB part of the index
+ index1 -- Word16 -- index for first pos in pos_index[]
+ index2 -- Word16 -- index for second pos in pos_index[]
+ index3 -- Word16 -- index for third pos in pos_index[]
+
+ Outputs:
+ pos_indx[] -- array of type Word16 -- position of 3 pulses (decompressed)
+
+ pOverflow Flag set when overflow occurs, pointer of type Flag *
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void decompress10(
+ Word16 MSBs, /* i : MSB part of the index */
+ Word16 LSBs, /* i : LSB part of the index */
+ Word16 index1, /* i : index for first pos in pos_index[] */
+ Word16 index2, /* i : index for second pos in pos_index[] */
+ Word16 index3, /* i : index for third pos in pos_index[] */
+ Word16 pos_indx[], /* o : position of 3 pulses (decompressed) */
+ Flag *pOverflow) /* o : Flag set when overflow occurs */
+{
+ Word16 ia;
+ Word16 ib;
+ Word16 ic;
+ Word32 tempWord32;
+
+ /*
+ pos_indx[index1] = ((MSBs-25*(MSBs/25))%5)*2 + (LSBs-4*(LSBs/4))%2;
+ pos_indx[index2] = ((MSBs-25*(MSBs/25))/5)*2 + (LSBs-4*(LSBs/4))/2;
+ pos_indx[index3] = (MSBs/25)*2 + LSBs/4;
+ */
+
+ if (MSBs > 124)
+ {
+ MSBs = 124;
+ }
+
+ ia =
+ mult(
+ MSBs,
+ 1311,
+ pOverflow);
+
+ tempWord32 =
+ L_mult(
+ ia,
+ 25,
+ pOverflow);
+
+
+ ia = (Word16)(MSBs - (tempWord32 >> 1));
+ ib =
+ mult(
+ ia,
+ 6554,
+ pOverflow);
+
+ tempWord32 =
+ L_mult(
+ ib,
+ 5,
+ pOverflow);
+
+ ib = ia - (Word16)(tempWord32 >> 1);
+
+ ib =
+ shl(
+ ib,
+ 1,
+ pOverflow);
+
+
+ ic = LSBs - ((LSBs >> 2) << 2);
+
+
+ pos_indx[index1] = ib + (ic & 1);
+
+
+ ib =
+ mult(
+ ia,
+ 6554,
+ pOverflow);
+
+ ib =
+ shl(
+ ib,
+ 1,
+ pOverflow);
+
+
+ pos_indx[index2] = ib + (ic >> 1);
+
+
+ ib = LSBs >> 2;
+
+ ic =
+ mult(
+ MSBs,
+ 1311,
+ pOverflow);
+
+ ic =
+ shl(
+ ic,
+ 1,
+ pOverflow);
+
+ pos_indx[index3] =
+ add(
+ ib,
+ ic,
+ pOverflow);
+
+ return;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: decompress_code
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ indx[] -- array of type Word16 -- position and sign of
+ 8 pulses (compressed)
+
+ Outputs:
+ sign_indx[] -- array of type Word16 -- signs of 4 pulses (signs only)
+ pos_indx[] -- array of type Word16 -- position index of 8 pulses
+ (position only)
+ pOverflow pointer to type Flag -- Flag set when overflow occurs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: decompression of the linear codewords to 4+three indeces
+ one bit from each pulse is made robust to errors by
+ minimizing the phase shift of a bit error.
+ 4 signs (one for each track)
+ i0,i4,i1 => one index (7+3) bits, 3 LSBs more robust
+ i2,i6,i5 => one index (7+3) bits, 3 LSBs more robust
+ i3,i7 => one index (5+2) bits, 2-3 LSbs more robust
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void decompress_code(
+ Word16 indx[], /* i : position and sign of 8 pulses (compressed) */
+ Word16 sign_indx[], /* o : signs of 4 pulses (signs only) */
+ Word16 pos_indx[], /* o : position index of 8 pulses (position only) */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 ia;
+ Word16 ib;
+ Word16 MSBs;
+ Word16 LSBs;
+ Word16 MSBs0_24;
+ Word32 tempWord32;
+
+ for (i = 0; i < NB_TRACK_MR102; i++)
+ {
+ sign_indx[i] = indx[i];
+ }
+
+ /*
+ First index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
+ MSBs = indx[NB_TRACK]/8;
+ LSBs = indx[NB_TRACK]%8;
+ */
+ MSBs = indx[NB_TRACK_MR102] >> 3;
+
+ LSBs = indx[NB_TRACK_MR102] & 0x7;
+
+ decompress10(
+ MSBs,
+ LSBs,
+ 0,
+ 4,
+ 1,
+ pos_indx,
+ pOverflow);
+
+ /*
+ Second index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
+ MSBs = indx[NB_TRACK+1]/8;
+ LSBs = indx[NB_TRACK+1]%8;
+ */
+ MSBs = indx[NB_TRACK_MR102+1] >> 3;
+
+ LSBs = indx[NB_TRACK_MR102+1] & 0x7;
+
+ decompress10(
+ MSBs,
+ LSBs,
+ 2,
+ 6,
+ 5,
+ pos_indx,
+ pOverflow);
+
+ /*
+ Third index: 10x10 -> 2x5x2x5-> 25x2x2 -> 5+1x2 bits
+ MSBs = indx[NB_TRACK+2]/4;
+ LSBs = indx[NB_TRACK+2]%4;
+ MSBs0_24 = (MSBs*25+12)/32;
+ if ((MSBs0_24/5)%2==1)
+ pos_indx[3] = (4-(MSBs0_24%5))*2 + LSBs%2;
+ else
+ pos_indx[3] = (MSBs0_24%5)*2 + LSBs%2;
+ pos_indx[7] = (MSBs0_24/5)*2 + LSBs/2;
+ */
+
+ MSBs = indx[NB_TRACK_MR102+2] >> 2;
+
+ LSBs = indx[NB_TRACK_MR102+2] & 0x3;
+
+ tempWord32 =
+ L_mult(
+ MSBs,
+ 25,
+ pOverflow);
+
+ ia =
+ (Word16)
+ L_shr(
+ tempWord32,
+ 1,
+ pOverflow);
+
+ ia += 12;
+
+ MSBs0_24 = ia >> 5;
+
+
+ ia =
+ mult(
+ MSBs0_24,
+ 6554,
+ pOverflow);
+
+ ia &= 1;
+
+
+ ib =
+ mult(
+ MSBs0_24,
+ 6554,
+ pOverflow);
+
+ tempWord32 =
+ L_mult(
+ ib,
+ 5,
+ pOverflow);
+
+
+ ib = MSBs0_24 - (Word16)(tempWord32 >> 1);
+
+ if (ia == 1)
+ {
+ ib = 4 - ib;
+
+ }
+
+
+ ib =
+ shl(
+ ib,
+ 1,
+ pOverflow);
+
+ ia = LSBs & 0x1;
+
+ pos_indx[3] =
+ add(
+ ib,
+ ia,
+ pOverflow);
+
+ ia =
+ mult(
+ MSBs0_24,
+ 6554,
+ pOverflow);
+
+ ia =
+ shl(
+ ia,
+ 1,
+ pOverflow);
+
+ pos_indx[7] = ia + (LSBs >> 1);
+
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dec_8i40_31bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ index array of type Word16 -- index of 8 pulses (sign+position)
+
+ Outputs:
+ cod array of type Word16 -- algebraic (fixed) codebook excitation
+ pOverflow pointer to type Flag -- Flag set when overflow occurs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Builds the innovative codevector from the received
+ index of algebraic codebook.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void dec_8i40_31bits(
+ Word16 index[], /* i : index of 8 pulses (sign+position) */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 pos1;
+ Word16 pos2;
+ Word16 sign;
+
+ Word16 linear_signs[NB_TRACK_MR102];
+ Word16 linear_codewords[NB_PULSE];
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ cod[i] = 0;
+ }
+
+ decompress_code(
+ index,
+ linear_signs,
+ linear_codewords,
+ pOverflow);
+
+ /* decode the positions and signs of pulses and build the codeword */
+ for (j = 0; j < NB_TRACK_MR102; j++) /* NB_TRACK_MR102 = 4 */
+ {
+ /* position of pulse "j" */
+
+ pos1 = (linear_codewords[j] << 2) + j;
+
+
+ if (linear_signs[j] == 0)
+ {
+ sign = POS_CODE; /* +1.0 */
+ }
+ else
+ {
+ sign = -NEG_CODE; /* -1.0 */
+ }
+
+ if (pos1 < L_SUBFR)
+ {
+ cod[pos1] = sign; /* avoid buffer overflow */
+ }
+
+ /* compute index i */
+ /* position of pulse "j+4" */
+
+ pos2 = (linear_codewords[j + 4] << 2) + j;
+
+
+ if (pos2 < pos1)
+ {
+ sign = negate(sign);
+ }
+
+ if (pos2 < L_SUBFR)
+ {
+ cod[pos2] += sign; /* avoid buffer overflow */
+ }
+
+
+ } /* for (j = 0; j < NB_TRACK_MR102; j++) */
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/d8_31pf.h b/media/codecs/amrnb/dec/src/d8_31pf.h
new file mode 100644
index 0000000..162685f
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d8_31pf.h
@@ -0,0 +1,120 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/d2_9pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the d8_31pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef d8_31pf_h
+#define d8_31pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void dec_8i40_31bits(
+ Word16 index[], /* i : index of 8 pulses (sign+position) */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _d8_31PF_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/d_gain_c.cpp b/media/codecs/amrnb/dec/src/d_gain_c.cpp
new file mode 100644
index 0000000..b6c62f8
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d_gain_c.cpp
@@ -0,0 +1,254 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d_gain_c.c
+ Functions: d_gain_c
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated include files and intput/output section. Changed .tab
+ files to .c files.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pred_state = pointer to sturcture type gc_predState. MA predictor state
+ mode = AMR mode (MR795 or MR122) of type enum Mode
+ index = received quantization index of type Word16
+ code[] = pointer to innovation codevector of type Word16
+ pOverflow= pointer to value indicating existence of overflow (Flag)
+
+ Outputs:
+ pred_state = pointer to sturcture type gc_predState. MA predictor state
+ gain_code = pointer to decoded innovation gain of type Word16
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function : d_gain_code
+ Purpose : Decode the fixed codebook gain using the received index.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d_gain_c.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d_gain_c.h"
+#include "typedef.h"
+#include "mode.h"
+
+#include "oper_32b.h"
+#include "cnst.h"
+#include "log2.h"
+#include "pow2.h"
+#include "gc_pred.h"
+
+#include "basic_op.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 qua_gain_code[];
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void d_gain_code(
+ gc_predState *pred_state, /* i/o : MA predictor state */
+ enum Mode mode, /* i : AMR mode (MR795 or MR122) */
+ Word16 index, /* i : received quantization index */
+ Word16 code[], /* i : innovation codevector */
+ Word16 *gain_code, /* o : decoded innovation gain */
+ Flag *pOverflow
+)
+{
+ Word16 gcode0, exp, frac;
+ const Word16 *p;
+ Word16 qua_ener_MR122, qua_ener;
+ Word16 exp_inn_en;
+ Word16 frac_inn_en;
+ Word32 L_tmp;
+ Word16 tbl_tmp;
+ Word16 temp;
+ /*-------------- Decode codebook gain ---------------*/
+
+ /*-------------------------------------------------------------------*
+ * predict codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = Pow2(int(d)+frac(d)) *
+ * = 2^exp + 2^frac *
+ * *
+ *-------------------------------------------------------------------*/
+
+ gc_pred(pred_state, mode, code, &exp, &frac,
+ &exp_inn_en, &frac_inn_en, pOverflow);
+
+ index &= 31; /* index < 32, to avoid buffer overflow */
+ tbl_tmp = index + (index << 1);
+
+ p = &qua_gain_code[tbl_tmp];
+
+ /* Different scalings between MR122 and the other modes */
+ temp = sub((Word16)mode, (Word16)MR122, pOverflow);
+ if (temp == 0)
+ {
+ gcode0 = (Word16)(Pow2(exp, frac, pOverflow)); /* predicted gain */
+ gcode0 = shl(gcode0, 4, pOverflow);
+ *gain_code = shl(mult(gcode0, *p++, pOverflow), 1, pOverflow);
+ }
+ else
+ {
+ gcode0 = (Word16)(Pow2(14, frac, pOverflow));
+ L_tmp = L_mult(*p++, gcode0, pOverflow);
+ L_tmp = L_shr(L_tmp, sub(9, exp, pOverflow), pOverflow);
+ *gain_code = extract_h(L_tmp); /* Q1 */
+ }
+
+ /*-------------------------------------------------------------------*
+ * update table of past quantized energies *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ *-------------------------------------------------------------------*/
+ qua_ener_MR122 = *p++;
+ qua_ener = *p++;
+ gc_pred_update(pred_state, qua_ener_MR122, qua_ener);
+
+ return;
+}
+
+
+
+
diff --git a/media/codecs/amrnb/dec/src/d_gain_p.cpp b/media/codecs/amrnb/dec/src/d_gain_p.cpp
new file mode 100644
index 0000000..99446db
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d_gain_p.cpp
@@ -0,0 +1,192 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d_gain_p.c
+ Functions: d_gain_p
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ (1) Removed extra includes
+ (2) Replaced function calls to basic math operations with ANSI C standard
+ mathemtical operations.
+ (3) Placed code in the proper software template.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode -- enumerated type -- AMR mode
+ index -- Word16 -- index of quantization
+ Outputs:
+ None
+
+ Returns:
+ Word16 gain -- (Q14)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function : d_gain_pitch
+ Purpose : Decodes the pitch gain using the received index.
+ output is in Q14
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d_gain_p.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d_gain_p.h"
+#include "typedef.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 qua_gain_pitch[];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+Word16 d_gain_pitch( /* return value: gain (Q14) */
+ enum Mode mode, /* i : AMR mode */
+ Word16 index /* i : index of quantization */
+)
+{
+ Word16 gain;
+
+ gain = qua_gain_pitch[index];
+
+ if (mode == MR122)
+ {
+ /* clear 2 LSBits */
+ gain &= 0xFFFC;
+ }
+
+ return gain;
+}
diff --git a/media/codecs/amrnb/dec/src/d_plsf.cpp b/media/codecs/amrnb/dec/src/d_plsf.cpp
new file mode 100644
index 0000000..138193f
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d_plsf.cpp
@@ -0,0 +1,207 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d_plsf.c
+ Functions:
+
+
+ Date: 04/14/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Removed the functions d_plsf_init and d_plsf_exit.
+ The d_plsf related structure is no longer dynamically allocated.
+
+ Description: Removed q_plsf_5.tab from Include section and added
+ q_plsf_5_tbl.h to Include section. Changed "mean_lsf"
+ to "mean_lsf_5" in D_plsf_reset().
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ common part (reset) of LSF decoder
+ module (rest in d_plsf_3.c and d_plsf_5.c)
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "copy.h"
+#include "d_plsf.h"
+#include "q_plsf_5_tbl.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: D_plsf_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to structure of type D_plsf_reset
+
+ Outputs:
+ fields of the structure pointed to by state is initialized to zero
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Resets state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d_plsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int D_plsf_reset (D_plsfState *state)
+{
+ Word16 i;
+
+ if (state == (D_plsfState *) NULL){
+ // fprintf(stderr, "D_plsf_reset: invalid parameter\n");
+ return -1;
+ }
+
+ for (i = 0; i < M; i++){
+ state->past_r_q[i] = 0; // Past quantized prediction error
+ }
+
+ // Past dequantized lsfs
+ Copy(mean_lsf, &state->past_lsf_q[0], M);
+
+ return 0;
+}
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 D_plsf_reset(D_plsfState *state)
+{
+ Word16 i;
+
+ if (state == (D_plsfState *) NULL)
+ {
+ /* fprintf(stderr, "D_plsf_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ for (i = 0; i < M; i++)
+ {
+ state->past_r_q[i] = 0; /* Past quantized prediction error */
+ }
+
+ /* Past dequantized lsfs */
+ Copy(mean_lsf_5, &state->past_lsf_q[0], M);
+
+ return 0;
+
+}
diff --git a/media/codecs/amrnb/dec/src/d_plsf_3.cpp b/media/codecs/amrnb/dec/src/d_plsf_3.cpp
new file mode 100644
index 0000000..7b31d04
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d_plsf_3.cpp
@@ -0,0 +1,496 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d_plsf_3.c
+ Functions: D_plsf_3
+
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- Pointer to type struct D_plsfState
+ mode -- enum Mode -- coder mode
+ bfi -- Word16 -- bad frame indicator (set to 1 if a bad frame is received)
+ indice -- Pointer to type Word16 -- quantization indices of
+ 3 submatrices, Q0
+
+ Outputs:
+ st -- Pointer to type struct D_plsfState
+ lsp1_q -- Pointer to type Word16 -- quantized 1st LSP vector Q15
+ pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Decodes the LSP parameters using the received quantization
+ indices.1st order MA prediction and split by 3 vector
+ quantization (split-VQ)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d_plsf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "lsp_lsf.h"
+#include "reorder.h"
+#include "copy.h"
+#include "q_plsf_3_tbl.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define ALPHA 29491 /* ALPHA -> 0.9 */
+#define ONE_ALPHA 3277 /* ONE_ALPHA-> (1.0-ALPHA) */
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void D_plsf_3(
+ D_plsfState *st, /* i/o: State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 bfi, /* i : bad frame indicator (set to 1 if a */
+ /* bad frame is received) */
+ Word16 * indice, /* i : quantization indices of 3 submatrices, Q0 */
+ Word16 * lsp1_q, /* o : quantized 1st LSP vector, Q15 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 temp;
+ Word16 index;
+
+ Word16 lsf1_r[M];
+ Word16 lsf1_q[M];
+
+ if (bfi != 0) /* if bad frame */
+ {
+ /* use the past LSFs slightly shifted towards their mean */
+
+ for (i = 0; i < M; i++)
+ {
+ /* lsfi_q[i] = ALPHA*past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */
+ temp =
+ mult(
+ st->past_lsf_q[i],
+ ALPHA,
+ pOverflow);
+
+ index =
+ mult(
+ mean_lsf_3[i],
+ ONE_ALPHA,
+ pOverflow);
+
+ lsf1_q[i] =
+ add(
+ index,
+ temp,
+ pOverflow);
+ }
+
+ /* estimate past quantized residual to be used in next frame */
+ if (mode != MRDTX)
+ {
+ for (i = 0; i < M; i++)
+ {
+ /* temp = mean_lsf[i] + past_r2_q[i] * PRED_FAC; */
+
+ temp =
+ mult(
+ st->past_r_q[i],
+ pred_fac_3[i],
+ pOverflow);
+
+ temp =
+ add(
+ mean_lsf_3[i],
+ temp,
+ pOverflow);
+
+ st->past_r_q[i] =
+ sub(
+ lsf1_q[i],
+ temp,
+ pOverflow);
+ }
+
+ } /* if (mode == MRDTX) */
+ else
+ {
+ for (i = 0; i < M; i++)
+ {
+ /* temp = mean_lsf[i] + past_r2_q[i]; */
+
+ temp =
+ add(
+ mean_lsf_3[i],
+ st->past_r_q[i],
+ pOverflow);
+
+ st->past_r_q[i] =
+ sub(
+ lsf1_q[i],
+ temp,
+ pOverflow);
+ }
+ }
+
+ } /* if (bfi != 0) */
+
+ else /* if good LSFs received */
+ {
+
+ Word16 index_limit_1 = 0;
+ Word16 index_limit_2 = (DICO2_SIZE - 1) * 3;
+ Word16 index_limit_3 = 0;
+
+ const Word16 *p_cb1;
+ const Word16 *p_cb2;
+ const Word16 *p_cb3;
+ const Word16 *p_dico;
+
+
+ p_cb2 = dico2_lsf_3; /* size DICO2_SIZE*3 */
+
+ if ((mode == MR475) || (mode == MR515))
+ { /* MR475, MR515 */
+ p_cb1 = dico1_lsf_3; /* size DICO1_SIZE*3 */
+ p_cb3 = mr515_3_lsf; /* size MR515_3_SIZE*4 */
+
+ index_limit_1 = (DICO1_SIZE - 1) * 3;
+ index_limit_3 = (MR515_3_SIZE - 1) * 4;
+
+ }
+ else if (mode == MR795)
+ { /* MR795 */
+ p_cb1 = mr795_1_lsf; /* size MR795_1_SIZE*3 */
+ p_cb3 = dico3_lsf_3; /* size DICO3_SIZE*4 */
+
+ index_limit_1 = (MR795_1_SIZE - 1) * 3;
+ index_limit_3 = (DICO3_SIZE - 1) * 4;
+
+ }
+ else
+ { /* MR59, MR67, MR74, MR102, MRDTX */
+ p_cb1 = dico1_lsf_3; /* size DICO1_SIZE*3 */
+ p_cb3 = dico3_lsf_3; /* size DICO3_SIZE*4 */
+
+ index_limit_1 = (DICO1_SIZE - 1) * 3;
+ index_limit_3 = (DICO3_SIZE - 1) * 4;
+
+ }
+
+ /* decode prediction residuals from 3 received indices */
+
+ index = *indice++;
+
+ /* temp = 3*index; */
+ temp = index + (index << 1);
+
+ if (temp > index_limit_1)
+ {
+ temp = index_limit_1; /* avoid buffer overrun */
+ }
+
+ p_dico = &p_cb1[temp];
+
+ lsf1_r[0] = *p_dico++;
+ lsf1_r[1] = *p_dico++;
+ lsf1_r[2] = *p_dico++;
+
+ index = *indice++;
+
+ if (mode == MR475 || mode == MR515)
+ { /* MR475, MR515 only using every second entry */
+ index <<= 1;
+ }
+
+ /* temp = 3*index */
+ temp = index + (index << 1);
+
+ if (temp > index_limit_2)
+ {
+ temp = index_limit_2; /* avoid buffer overrun */
+ }
+
+ p_dico = &p_cb2[temp];
+
+ lsf1_r[3] = *p_dico++;
+ lsf1_r[4] = *p_dico++;
+ lsf1_r[5] = *p_dico++;
+
+ index = *indice++;
+
+ temp = index << 2;
+
+ if (temp > index_limit_3)
+ {
+ temp = index_limit_3; /* avoid buffer overrun */
+ }
+
+
+ p_dico = &p_cb3[temp];
+
+ lsf1_r[6] = *p_dico++;
+ lsf1_r[7] = *p_dico++;
+ lsf1_r[8] = *p_dico++;
+ lsf1_r[9] = *p_dico++;
+
+ /* Compute quantized LSFs and update the past quantized residual */
+
+ if (mode != MRDTX)
+ {
+ for (i = 0; i < M; i++)
+ {
+ temp =
+ mult(
+ st->past_r_q[i],
+ pred_fac_3[i],
+ pOverflow);
+
+ temp =
+ add(
+ mean_lsf_3[i],
+ temp,
+ pOverflow);
+
+ lsf1_q[i] =
+ add(
+ lsf1_r[i],
+ temp,
+ pOverflow);
+
+ st->past_r_q[i] = lsf1_r[i];
+ }
+ }
+ else
+ {
+ for (i = 0; i < M; i++)
+ {
+ temp =
+ add(
+ mean_lsf_3[i],
+ st->past_r_q[i],
+ pOverflow);
+
+ lsf1_q[i] =
+ add(
+ lsf1_r[i],
+ temp,
+ pOverflow);
+
+ st->past_r_q[i] = lsf1_r[i];
+ }
+ }
+
+ }
+
+ /* verification that LSFs has minimum distance of LSF_GAP Hz */
+
+ Reorder_lsf(
+ lsf1_q,
+ LSF_GAP,
+ M,
+ pOverflow);
+
+ Copy(
+ lsf1_q,
+ st->past_lsf_q,
+ M);
+
+ /* convert LSFs to the cosine domain */
+
+ Lsf_lsp(
+ lsf1_q,
+ lsp1_q,
+ M,
+ pOverflow);
+
+ return;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Init_D_plsf_3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type D_plsfState
+ index = Word16, past_rq_init[] index [0, 7]
+
+ Outputs:
+ st = pointer to a structure of type D_plsfState
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes the D_plsfState structure.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void Init_D_plsf_3(
+ D_plsfState *st, /* i/o: State struct */
+ Word16 index /* i : past_rq_init[] index [0, 7] */)
+{
+ Copy(
+ &past_rq_init[index * M],
+ st->past_r_q,
+ M);
+}
diff --git a/media/codecs/amrnb/dec/src/d_plsf_5.cpp b/media/codecs/amrnb/dec/src/d_plsf_5.cpp
new file mode 100644
index 0000000..7068c0a
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/d_plsf_5.cpp
@@ -0,0 +1,539 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/d_plsf_5.c
+
+ Date: 04/24/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Made changes based on review meeting.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Updated to accept new parameter, Flag *pOverflow.
+
+ Description:
+ (1) Removed "count.h" and "basic_op.h" and replaced with individual include
+ files (add.h, sub.h, etc.)
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "d_plsf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "lsp_lsf.h"
+#include "reorder.h"
+#include "cnst.h"
+#include "copy.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+ /* ALPHA -> 0.95 */
+ /* ONE_ALPHA-> (1.0-ALPHA) */
+#define ALPHA 31128
+#define ONE_ALPHA 1639
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /* These tables are defined in q_plsf_5_tbl.c */
+ extern const Word16 mean_lsf_5[];
+ extern const Word16 dico1_lsf_5[];
+ extern const Word16 dico2_lsf_5[];
+ extern const Word16 dico3_lsf_5[];
+ extern const Word16 dico4_lsf_5[];
+ extern const Word16 dico5_lsf_5[];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: D_plsf_5
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type D_plsfState
+ bfi = bad frame indicator; set to 1 if a bad frame is received (Word16)
+ indice = pointer to quantization indices of 5 submatrices (Word16)
+ lsp1_q = pointer to the quantized 1st LSP vector (Word16)
+ lsp2_q = pointer to the quantized 2nd LSP vector (Word16)
+
+ Outputs:
+ lsp1_q points to the updated quantized 1st LSP vector
+ lsp2_q points to the updated quantized 2nd LSP vector
+ Flag *pOverflow -- Flag set when overflow occurs.
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function decodes the 2 sets of LSP parameters in a frame using the
+ received quantization indices.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ d_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int D_plsf_5 (
+ D_plsfState *st, // i/o: State variables
+ Word16 bfi, // i : bad frame indicator (set to 1 if a bad
+ frame is received)
+ Word16 *indice, // i : quantization indices of 5 submatrices, Q0
+ Word16 *lsp1_q, // o : quantized 1st LSP vector (M), Q15
+ Word16 *lsp2_q // o : quantized 2nd LSP vector (M), Q15
+)
+{
+ Word16 i;
+ const Word16 *p_dico;
+ Word16 temp, sign;
+ Word16 lsf1_r[M], lsf2_r[M];
+ Word16 lsf1_q[M], lsf2_q[M];
+
+ if (bfi != 0) // if bad frame
+ {
+ // use the past LSFs slightly shifted towards their mean
+
+ for (i = 0; i < M; i++)
+ {
+ // lsfi_q[i] = ALPHA*st->past_lsf_q[i] + ONE_ALPHA*mean_lsf[i];
+
+ lsf1_q[i] = add (mult (st->past_lsf_q[i], ALPHA),
+ mult (mean_lsf[i], ONE_ALPHA));
+
+ lsf2_q[i] = lsf1_q[i];
+ }
+
+ // estimate past quantized residual to be used in next frame
+
+ for (i = 0; i < M; i++)
+ {
+ // temp = mean_lsf[i] + st->past_r_q[i] * LSP_PRED_FAC_MR122;
+
+ temp = add (mean_lsf[i], mult (st->past_r_q[i],
+ LSP_PRED_FAC_MR122));
+
+ st->past_r_q[i] = sub (lsf2_q[i], temp);
+ }
+ }
+ else
+ // if good LSFs received
+ {
+ // decode prediction residuals from 5 received indices
+
+ p_dico = &dico1_lsf[shl (indice[0], 2)];
+ lsf1_r[0] = *p_dico++;
+ lsf1_r[1] = *p_dico++;
+ lsf2_r[0] = *p_dico++;
+ lsf2_r[1] = *p_dico++;
+
+ p_dico = &dico2_lsf[shl (indice[1], 2)];
+ lsf1_r[2] = *p_dico++;
+ lsf1_r[3] = *p_dico++;
+ lsf2_r[2] = *p_dico++;
+ lsf2_r[3] = *p_dico++;
+
+ sign = indice[2] & 1;
+ i = shr (indice[2], 1);
+ p_dico = &dico3_lsf[shl (i, 2)];
+
+ if (sign == 0)
+ {
+ lsf1_r[4] = *p_dico++;
+ lsf1_r[5] = *p_dico++;
+ lsf2_r[4] = *p_dico++;
+ lsf2_r[5] = *p_dico++;
+ }
+ else
+ {
+ lsf1_r[4] = negate (*p_dico++);
+ lsf1_r[5] = negate (*p_dico++);
+ lsf2_r[4] = negate (*p_dico++);
+ lsf2_r[5] = negate (*p_dico++);
+ }
+
+ p_dico = &dico4_lsf[shl (indice[3], 2)];
+ lsf1_r[6] = *p_dico++;
+ lsf1_r[7] = *p_dico++;
+ lsf2_r[6] = *p_dico++;
+ lsf2_r[7] = *p_dico++;
+
+ p_dico = &dico5_lsf[shl (indice[4], 2)];
+ lsf1_r[8] = *p_dico++;
+ lsf1_r[9] = *p_dico++;
+ lsf2_r[8] = *p_dico++;
+ lsf2_r[9] = *p_dico++;
+
+ // Compute quantized LSFs and update the past quantized residual
+ for (i = 0; i < M; i++)
+ {
+ temp = add (mean_lsf[i], mult (st->past_r_q[i],
+ LSP_PRED_FAC_MR122));
+ lsf1_q[i] = add (lsf1_r[i], temp);
+ lsf2_q[i] = add (lsf2_r[i], temp);
+ st->past_r_q[i] = lsf2_r[i];
+ }
+ }
+
+ // verification that LSFs have minimum distance of LSF_GAP Hz
+
+ Reorder_lsf (lsf1_q, LSF_GAP, M);
+ Reorder_lsf (lsf2_q, LSF_GAP, M);
+
+ Copy (lsf2_q, st->past_lsf_q, M);
+
+ // convert LSFs to the cosine domain
+
+ Lsf_lsp (lsf1_q, lsp1_q, M);
+ Lsf_lsp (lsf2_q, lsp2_q, M);
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void D_plsf_5(
+ D_plsfState *st, /* i/o: State variables */
+ Word16 bfi, /* i : bad frame indicator (set to 1 if a bad
+ frame is received) */
+ Word16 *indice, /* i : quantization indices of 5 submatrices, Q0 */
+ Word16 *lsp1_q, /* o : quantized 1st LSP vector (M), Q15 */
+ Word16 *lsp2_q, /* o : quantized 2nd LSP vector (M), Q15 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 temp;
+ Word16 sign;
+
+ const Word16 *p_dico;
+
+ Word16 lsf1_r[M];
+ Word16 lsf2_r[M];
+ Word16 lsf1_q[M];
+ Word16 lsf2_q[M];
+
+ if (bfi != 0) /* if bad frame */
+ {
+ /* use the past LSFs slightly shifted towards their mean */
+
+ for (i = 0; i < M; i++)
+ {
+ /*
+ * lsfi_q[i] = ALPHA*st->past_lsf_q[i] +
+ * ONE_ALPHA*mean_lsf[i];
+ */
+
+ temp =
+ mult(
+ st->past_lsf_q[i],
+ ALPHA,
+ pOverflow);
+
+ sign =
+ mult(
+ *(mean_lsf_5 + i),
+ ONE_ALPHA,
+ pOverflow);
+
+ *(lsf1_q + i) =
+ add(
+ sign,
+ temp,
+ pOverflow);
+
+ *(lsf2_q + i) = *(lsf1_q + i);
+
+ /*
+ * estimate past quantized residual to be used in
+ * next frame
+ */
+
+ /*
+ * temp = mean_lsf[i] +
+ * st->past_r_q[i] * LSP_PRED_FAC_MR122;
+ */
+
+ temp =
+ mult(
+ st->past_r_q[i],
+ LSP_PRED_FAC_MR122,
+ pOverflow);
+
+ temp =
+ add(
+ *(mean_lsf_5 + i),
+ temp,
+ pOverflow);
+
+ st->past_r_q[i] =
+ sub(
+ *(lsf2_q + i),
+ temp,
+ pOverflow);
+ }
+ }
+ else
+ /* if good LSFs received */
+ {
+ /* decode prediction residuals from 5 received indices */
+
+ temp =
+ shl(
+ *(indice),
+ 2,
+ pOverflow);
+
+ p_dico = &dico1_lsf_5[temp];
+
+ *(lsf1_r + 0) = *p_dico++;
+ *(lsf1_r + 1) = *p_dico++;
+ *(lsf2_r + 0) = *p_dico++;
+ *(lsf2_r + 1) = *p_dico++;
+
+ temp =
+ shl(
+ *(indice + 1),
+ 2,
+ pOverflow);
+
+ p_dico = &dico2_lsf_5[temp];
+
+ *(lsf1_r + 2) = *p_dico++;
+ *(lsf1_r + 3) = *p_dico++;
+ *(lsf2_r + 2) = *p_dico++;
+ *(lsf2_r + 3) = *p_dico++;
+
+ sign = *(indice + 2) & 1;
+
+ if (*(indice + 2) < 0)
+ {
+ i = ~(~(*(indice + 2)) >> 1);
+ }
+ else
+ {
+ i = *(indice + 2) >> 1;
+ }
+
+ temp =
+ shl(
+ i,
+ 2,
+ pOverflow);
+
+ p_dico = &dico3_lsf_5[temp];
+
+ if (sign == 0)
+ {
+ *(lsf1_r + 4) = *p_dico++;
+ *(lsf1_r + 5) = *p_dico++;
+ *(lsf2_r + 4) = *p_dico++;
+ *(lsf2_r + 5) = *p_dico++;
+ }
+ else
+ {
+ *(lsf1_r + 4) = negate(*p_dico++);
+ *(lsf1_r + 5) = negate(*p_dico++);
+ *(lsf2_r + 4) = negate(*p_dico++);
+ *(lsf2_r + 5) = negate(*p_dico++);
+ }
+
+ temp =
+ shl(
+ *(indice + 3),
+ 2,
+ pOverflow);
+
+ p_dico = &dico4_lsf_5[temp];
+
+ *(lsf1_r + 6) = *p_dico++;
+ *(lsf1_r + 7) = *p_dico++;
+ *(lsf2_r + 6) = *p_dico++;
+ *(lsf2_r + 7) = *p_dico++;
+
+ temp =
+ shl(
+ *(indice + 4),
+ 2,
+ pOverflow);
+
+ p_dico = &dico5_lsf_5[temp];
+
+ *(lsf1_r + 8) = *p_dico++;
+ *(lsf1_r + 9) = *p_dico++;
+ *(lsf2_r + 8) = *p_dico++;
+ *(lsf2_r + 9) = *p_dico++;
+
+ /* Compute quantized LSFs and update the past quantized
+ residual */
+ for (i = 0; i < M; i++)
+ {
+ temp =
+ mult(
+ st->past_r_q[i],
+ LSP_PRED_FAC_MR122,
+ pOverflow);
+
+ temp =
+ add(
+ *(mean_lsf_5 + i),
+ temp,
+ pOverflow);
+
+ *(lsf1_q + i) =
+ add(
+ *(lsf1_r + i),
+ temp,
+ pOverflow);
+
+ *(lsf2_q + i) =
+ add(
+ *(lsf2_r + i),
+ temp,
+ pOverflow);
+
+ st->past_r_q[i] = *(lsf2_r + i);
+ }
+ }
+
+ /* verification that LSFs have minimum distance of LSF_GAP Hz */
+
+ Reorder_lsf(
+ lsf1_q,
+ LSF_GAP,
+ M,
+ pOverflow);
+
+ Reorder_lsf(
+ lsf2_q,
+ LSF_GAP,
+ M,
+ pOverflow);
+
+ Copy(
+ lsf2_q,
+ st->past_lsf_q,
+ M);
+
+ /* convert LSFs to the cosine domain */
+
+ Lsf_lsp(
+ lsf1_q,
+ lsp1_q,
+ M,
+ pOverflow);
+
+ Lsf_lsp(
+ lsf2_q,
+ lsp2_q,
+ M,
+ pOverflow);
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/dec_amr.cpp b/media/codecs/amrnb/dec/src/dec_amr.cpp
new file mode 100644
index 0000000..be15475
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_amr.cpp
@@ -0,0 +1,2374 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: ./audio/gsm-amr/c/src/dec_amr.c
+ Funtions: Decoder_amr_init
+ Decoder_amr_reset
+ Decoder_amr
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the function used to decode one speech frame using a given
+ codec mode. The functions used to initialize, reset, and exit are also
+ included in this file.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "dec_amr.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "copy.h"
+#include "set_zero.h"
+#include "syn_filt.h"
+#include "d_plsf.h"
+#include "agc.h"
+#include "int_lpc.h"
+#include "dec_gain.h"
+#include "dec_lag3.h"
+#include "dec_lag6.h"
+#include "d2_9pf.h"
+#include "d2_11pf.h"
+#include "d3_14pf.h"
+#include "d4_17pf.h"
+#include "d8_31pf.h"
+#include "d1035pf.h"
+#include "pred_lt.h"
+#include "d_gain_p.h"
+#include "d_gain_c.h"
+#include "dec_gain.h"
+#include "ec_gains.h"
+#include "ph_disp.h"
+#include "c_g_aver.h"
+#include "int_lsf.h"
+#include "lsp_lsf.h"
+#include "lsp_avg.h"
+#include "bgnscd.h"
+#include "ex_ctrl.h"
+#include "sqrt_l.h"
+#include "frame.h"
+#include "bitno_tab.h"
+#include "b_cn_cod.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Decoder_amr_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer to structures of type Decoder_amrState
+
+ Outputs:
+ structure pointed to by the pointer which is pointed to by state is
+ initialized to each field's initial values
+
+ state pointer points to the address of the memory allocated by
+ Decoder_amr_init function
+
+ Returns:
+ return_value = 0, if the initialization was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function allocates and initializes state memory used by the Decoder_amr
+ function. It stores the pointer to the filter status structure in state. This
+ pointer has to be passed to Decoder_amr in each call. The function returns
+ 0, if initialization was successful and -1, otherwise.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dec_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Decoder_amr_init (Decoder_amrState **state)
+{
+ Decoder_amrState* s;
+ Word16 i;
+
+ if (state == (Decoder_amrState **) NULL){
+ fprintf(stderr, "Decoder_amr_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (Decoder_amrState *) malloc(sizeof(Decoder_amrState))) == NULL){
+ fprintf(stderr, "Decoder_amr_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ s->T0_lagBuff = 40;
+ s->inBackgroundNoise = 0;
+ s->voicedHangover = 0;
+ for (i = 0; i < 9; i++)
+ s->ltpGainHistory[i] = 0;
+
+ s->lsfState = NULL;
+ s->ec_gain_p_st = NULL;
+ s->ec_gain_c_st = NULL;
+ s->pred_state = NULL;
+ s->ph_disp_st = NULL;
+ s->dtxDecoderState = NULL;
+
+ if (D_plsf_init(&s->lsfState) ||
+ ec_gain_pitch_init(&s->ec_gain_p_st) ||
+ ec_gain_code_init(&s->ec_gain_c_st) ||
+ gc_pred_init(&s->pred_state) ||
+ Cb_gain_average_init(&s->Cb_gain_averState) ||
+ lsp_avg_init(&s->lsp_avg_st) ||
+ Bgn_scd_init(&s->background_state) ||
+ ph_disp_init(&s->ph_disp_st) ||
+ dtx_dec_init(&s->dtxDecoderState)) {
+ Decoder_amr_exit(&s);
+ return -1;
+ }
+
+ Decoder_amr_reset(s, (enum Mode)0);
+ *state = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Decoder_amr_init(Decoder_amrState *s)
+{
+ Word16 i;
+
+ if (s == (Decoder_amrState *) NULL)
+ {
+ /* fprint(stderr, "Decoder_amr_init: invalid parameter\n"); */
+ return(-1);
+ }
+
+ s->T0_lagBuff = 40;
+ s->inBackgroundNoise = 0;
+ s->voicedHangover = 0;
+
+ /* Initialize overflow Flag */
+
+ s->overflow = 0;
+
+ for (i = 0; i < LTP_GAIN_HISTORY_LEN; i++)
+ {
+ s->ltpGainHistory[i] = 0;
+ }
+
+ D_plsf_reset(&s->lsfState);
+ ec_gain_pitch_reset(&s->ec_gain_p_st);
+ ec_gain_code_reset(&s->ec_gain_c_st);
+ Cb_gain_average_reset(&s->Cb_gain_averState);
+ lsp_avg_reset(&s->lsp_avg_st);
+ Bgn_scd_reset(&s->background_state);
+ ph_disp_reset(&s->ph_disp_st);
+ dtx_dec_reset(&s->dtxDecoderState);
+ gc_pred_reset(&s->pred_state);
+
+ Decoder_amr_reset(s, MR475);
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Decoder_amr_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type Decoder_amrState
+ mode = codec mode (enum Mode)
+
+ Outputs:
+ structure pointed to by state is initialized to its reset value
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets the state memory used by the Decoder_amr function. It
+ returns a 0, if reset was successful and -1, otherwise.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dec_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Decoder_amr_reset (Decoder_amrState *state, enum Mode mode)
+{
+ Word16 i;
+
+ if (state == (Decoder_amrState *) NULL){
+ fprintf(stderr, "Decoder_amr_reset: invalid parameter\n");
+ return -1;
+ }
+
+ // Initialize static pointer
+ state->exc = state->old_exc + PIT_MAX + L_INTERPOL;
+
+ // Static vectors to zero
+ Set_zero (state->old_exc, PIT_MAX + L_INTERPOL);
+
+ if (mode != MRDTX)
+ Set_zero (state->mem_syn, M);
+
+ // initialize pitch sharpening
+ state->sharp = SHARPMIN;
+ state->old_T0 = 40;
+
+ // Initialize state->lsp_old []
+
+ if (mode != MRDTX) {
+ Copy(lsp_init_data, &state->lsp_old[0], M);
+ }
+
+ // Initialize memories of bad frame handling
+ state->prev_bf = 0;
+ state->prev_pdf = 0;
+ state->state = 0;
+
+ state->T0_lagBuff = 40;
+ state->inBackgroundNoise = 0;
+ state->voicedHangover = 0;
+ if (mode != MRDTX) {
+ for (i=0;i<9;i++)
+ state->excEnergyHist[i] = 0;
+ }
+
+ for (i = 0; i < 9; i++)
+ state->ltpGainHistory[i] = 0;
+
+ Cb_gain_average_reset(state->Cb_gain_averState);
+ if (mode != MRDTX)
+ lsp_avg_reset(state->lsp_avg_st);
+ D_plsf_reset(state->lsfState);
+ ec_gain_pitch_reset(state->ec_gain_p_st);
+ ec_gain_code_reset(state->ec_gain_c_st);
+
+ if (mode != MRDTX)
+ gc_pred_reset(state->pred_state);
+
+ Bgn_scd_reset(state->background_state);
+ state->nodataSeed = 21845;
+ ph_disp_reset(state->ph_disp_st);
+ if (mode != MRDTX)
+ dtx_dec_reset(state->dtxDecoderState);
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Decoder_amr_reset(Decoder_amrState *state, enum Mode mode)
+{
+ Word16 i;
+
+ if (state == (Decoder_amrState *) NULL)
+ {
+ /* fprint(stderr, "Decoder_amr_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ /* Initialize static pointer */
+ state->exc = state->old_exc + PIT_MAX + L_INTERPOL;
+
+ /* Static vectors to zero */
+ memset(state->old_exc, 0, sizeof(Word16)*(PIT_MAX + L_INTERPOL));
+
+ if (mode != MRDTX)
+ {
+ memset(state->mem_syn, 0, sizeof(Word16)*M);
+ }
+ /* initialize pitch sharpening */
+ state->sharp = SHARPMIN;
+ state->old_T0 = 40;
+
+ /* Initialize overflow Flag */
+
+ state->overflow = 0;
+
+ /* Initialize state->lsp_old [] */
+
+ if (mode != MRDTX)
+ {
+ state->lsp_old[0] = 30000;
+ state->lsp_old[1] = 26000;
+ state->lsp_old[2] = 21000;
+ state->lsp_old[3] = 15000;
+ state->lsp_old[4] = 8000;
+ state->lsp_old[5] = 0;
+ state->lsp_old[6] = -8000;
+ state->lsp_old[7] = -15000;
+ state->lsp_old[8] = -21000;
+ state->lsp_old[9] = -26000;
+ }
+
+ /* Initialize memories of bad frame handling */
+ state->prev_bf = 0;
+ state->prev_pdf = 0;
+ state->state = 0;
+
+ state->T0_lagBuff = 40;
+ state->inBackgroundNoise = 0;
+ state->voicedHangover = 0;
+ if (mode != MRDTX)
+ {
+ for (i = 0; i < EXC_ENERGY_HIST_LEN; i++)
+ {
+ state->excEnergyHist[i] = 0;
+ }
+ }
+
+ for (i = 0; i < LTP_GAIN_HISTORY_LEN; i++)
+ {
+ state->ltpGainHistory[i] = 0;
+ }
+
+ Cb_gain_average_reset(&(state->Cb_gain_averState));
+ if (mode != MRDTX)
+ {
+ lsp_avg_reset(&(state->lsp_avg_st));
+ }
+ D_plsf_reset(&(state->lsfState));
+ ec_gain_pitch_reset(&(state->ec_gain_p_st));
+ ec_gain_code_reset(&(state->ec_gain_c_st));
+
+ if (mode != MRDTX)
+ {
+ gc_pred_reset(&(state->pred_state));
+ }
+
+ Bgn_scd_reset(&(state->background_state));
+ state->nodataSeed = 21845;
+ ph_disp_reset(&(state->ph_disp_st));
+ if (mode != MRDTX)
+ {
+ dtx_dec_reset(&(state->dtxDecoderState));
+ }
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Decoder_amr
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type Decoder_amrState
+ mode = codec mode (enum Mode)
+ parm = buffer of synthesis parameters (Word16)
+ frame_type = received frame type (enum RXFrameType)
+ synth = buffer containing synthetic speech (Word16)
+ A_t = buffer containing decoded LP filter in 4 subframes (Word16)
+
+ Outputs:
+ structure pointed to by st contains the newly calculated decoder
+ parameters
+ synth buffer contains the decoded speech samples
+ A_t buffer contains the decoded LP filter parameters
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the decoding of one speech frame for a given codec
+ mode.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dec_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Decoder_amr (
+ Decoder_amrState *st, // i/o : State variables
+ enum Mode mode, // i : AMR mode
+ Word16 parm[], // i : vector of synthesis parameters
+ (PRM_SIZE)
+ enum RXFrameType frame_type, // i : received frame type
+ Word16 synth[], // o : synthesis speech (L_FRAME)
+ Word16 A_t[] // o : decoded LP filter in 4 subframes
+ (AZ_SIZE)
+)
+{
+ // LPC coefficients
+
+ Word16 *Az; // Pointer on A_t
+
+ // LSPs
+
+ Word16 lsp_new[M];
+ Word16 lsp_mid[M];
+
+ // LSFs
+
+ Word16 prev_lsf[M];
+ Word16 lsf_i[M];
+
+ // Algebraic codevector
+
+ Word16 code[L_SUBFR];
+
+ // excitation
+
+ Word16 excp[L_SUBFR];
+ Word16 exc_enhanced[L_SUBFR];
+
+ // Scalars
+
+ Word16 i, i_subfr;
+ Word16 T0, T0_frac, index, index_mr475 = 0;
+ Word16 gain_pit, gain_code, gain_code_mix, pit_sharp, pit_flag, pitch_fac;
+ Word16 t0_min, t0_max;
+ Word16 delta_frc_low, delta_frc_range;
+ Word16 tmp_shift;
+ Word16 temp;
+ Word32 L_temp;
+ Word16 flag4;
+ Word16 carefulFlag;
+ Word16 excEnergy;
+ Word16 subfrNr;
+ Word16 evenSubfr = 0;
+
+ Word16 bfi = 0; // bad frame indication flag
+ Word16 pdfi = 0; // potential degraded bad frame flag
+
+ enum DTXStateType newDTXState; // SPEECH , DTX, DTX_MUTE
+
+ // find the new DTX state SPEECH OR DTX
+ newDTXState = rx_dtx_handler(st->dtxDecoderState, frame_type);
+
+ // DTX actions
+ if (sub(newDTXState, SPEECH) != 0 )
+ {
+ Decoder_amr_reset (st, MRDTX);
+
+ dtx_dec(st->dtxDecoderState,
+ st->mem_syn,
+ st->lsfState,
+ st->pred_state,
+ st->Cb_gain_averState,
+ newDTXState,
+ mode,
+ parm, synth, A_t);
+ // update average lsp
+
+ Lsf_lsp(st->lsfState->past_lsf_q, st->lsp_old, M);
+ lsp_avg(st->lsp_avg_st, st->lsfState->past_lsf_q);
+ goto the_end;
+ }
+
+ // SPEECH action state machine
+ if ((sub(frame_type, RX_SPEECH_BAD) == 0) ||
+ (sub(frame_type, RX_NO_DATA) == 0) ||
+ (sub(frame_type, RX_ONSET) == 0))
+ {
+ bfi = 1;
+ if ((sub(frame_type, RX_NO_DATA) == 0) ||
+ (sub(frame_type, RX_ONSET) == 0))
+ {
+ build_CN_param(&st->nodataSeed,
+ prmno[mode],
+ bitno[mode],
+ parm);
+ }
+ }
+ else if (sub(frame_type, RX_SPEECH_DEGRADED) == 0)
+ {
+ pdfi = 1;
+ }
+
+ if (bfi != 0)
+ {
+ st->state = add (st->state, 1);
+ }
+ else if (sub (st->state, 6) == 0)
+
+ {
+ st->state = 5;
+ }
+ else
+ {
+ st->state = 0;
+ }
+
+ if (sub (st->state, 6) > 0)
+ {
+ st->state = 6;
+ }
+
+ // If this frame is the first speech frame after CNI period,
+ // set the BFH state machine to an appropriate state depending
+ // on whether there was DTX muting before start of speech or not
+ // If there was DTX muting, the first speech frame is muted.
+ // If there was no DTX muting, the first speech frame is not
+ // muted. The BFH state machine starts from state 5, however, to
+ // keep the audible noise resulting from a SID frame which is
+ // erroneously interpreted as a good speech frame as small as
+ // possible (the decoder output in this case is quickly muted)
+
+ if (sub(st->dtxDecoderState->dtxGlobalState, DTX) == 0)
+ {
+ st->state = 5;
+ st->prev_bf = 0;
+ }
+ else if (sub(st->dtxDecoderState->dtxGlobalState, DTX_MUTE) == 0)
+ {
+ st->state = 5;
+ st->prev_bf = 1;
+ }
+
+ // save old LSFs for CB gain smoothing
+ Copy (st->lsfState->past_lsf_q, prev_lsf, M);
+
+ // decode LSF parameters and generate interpolated lpc coefficients
+ for the 4 subframes
+ if (sub (mode, MR122) != 0)
+ {
+ D_plsf_3(st->lsfState, mode, bfi, parm, lsp_new);
+
+ // Advance synthesis parameters pointer
+ parm += 3;
+
+ Int_lpc_1to3(st->lsp_old, lsp_new, A_t);
+ }
+ else
+ {
+ D_plsf_5 (st->lsfState, bfi, parm, lsp_mid, lsp_new);
+
+ // Advance synthesis parameters pointer
+ parm += 5;
+
+ Int_lpc_1and3 (st->lsp_old, lsp_mid, lsp_new, A_t);
+ }
+
+ // update the LSPs for the next frame
+ for (i = 0; i < M; i++)
+ {
+ st->lsp_old[i] = lsp_new[i];
+ }
+
+ *------------------------------------------------------------------------*
+ * Loop for every subframe in the analysis frame *
+ *------------------------------------------------------------------------*
+ * The subframe size is L_SUBFR and the loop is repeated L_FRAME/L_SUBFR *
+ * times *
+ * - decode the pitch delay *
+ * - decode algebraic code *
+ * - decode pitch and codebook gains *
+ * - find the excitation and compute synthesis speech *
+ *------------------------------------------------------------------------*
+
+ // pointer to interpolated LPC parameters
+ Az = A_t;
+
+ evenSubfr = 0;
+ subfrNr = -1;
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ subfrNr = add(subfrNr, 1);
+ evenSubfr = sub(1, evenSubfr);
+
+ // flag for first and 3th subframe
+ pit_flag = i_subfr;
+
+ if (sub (i_subfr, L_FRAME_BY2) == 0)
+ {
+ if (sub(mode, MR475) != 0 && sub(mode, MR515) != 0)
+ {
+ pit_flag = 0;
+ }
+ }
+
+ // pitch index
+ index = *parm++;
+
+ *-------------------------------------------------------*
+ * - decode pitch lag and find adaptive codebook vector. *
+ *-------------------------------------------------------*
+
+ if (sub(mode, MR122) != 0)
+ {
+ // flag4 indicates encoding with 4 bit resolution;
+ // this is needed for mode MR475, MR515, MR59 and MR67
+
+ flag4 = 0;
+ if ((sub (mode, MR475) == 0) ||
+ (sub (mode, MR515) == 0) ||
+ (sub (mode, MR59) == 0) ||
+ (sub (mode, MR67) == 0) ) {
+ flag4 = 1;
+ }
+
+ *-------------------------------------------------------*
+ * - get ranges for the t0_min and t0_max *
+ * - only needed in delta decoding *
+ *-------------------------------------------------------*
+
+ delta_frc_low = 5;
+ delta_frc_range = 9;
+
+ if ( sub(mode, MR795) == 0 )
+ {
+ delta_frc_low = 10;
+ delta_frc_range = 19;
+ }
+
+ t0_min = sub(st->old_T0, delta_frc_low);
+ if (sub(t0_min, PIT_MIN) < 0)
+ {
+ t0_min = PIT_MIN;
+ }
+ t0_max = add(t0_min, delta_frc_range);
+ if (sub(t0_max, PIT_MAX) > 0)
+ {
+ t0_max = PIT_MAX;
+ t0_min = sub(t0_max, delta_frc_range);
+ }
+
+ Dec_lag3 (index, t0_min, t0_max, pit_flag, st->old_T0,
+ &T0, &T0_frac, flag4);
+
+ st->T0_lagBuff = T0;
+
+ if (bfi != 0)
+ {
+ if (sub (st->old_T0, PIT_MAX) < 0)
+ { // Graceful pitch
+ st->old_T0 = add(st->old_T0, 1); // degradation
+ }
+ T0 = st->old_T0;
+ T0_frac = 0;
+
+ if ( st->inBackgroundNoise != 0 &&
+ sub(st->voicedHangover, 4) > 0 &&
+ ((sub(mode, MR475) == 0 ) ||
+ (sub(mode, MR515) == 0 ) ||
+ (sub(mode, MR59) == 0) )
+ )
+ {
+ T0 = st->T0_lagBuff;
+ }
+ }
+
+ Pred_lt_3or6 (st->exc, T0, T0_frac, L_SUBFR, 1);
+ }
+ else
+ {
+ Dec_lag6 (index, PIT_MIN_MR122,
+ PIT_MAX, pit_flag, &T0, &T0_frac);
+
+ if ( bfi == 0 && (pit_flag == 0 || sub (index, 61) < 0))
+ {
+ }
+ else
+ {
+ st->T0_lagBuff = T0;
+ T0 = st->old_T0;
+ T0_frac = 0;
+ }
+
+ Pred_lt_3or6 (st->exc, T0, T0_frac, L_SUBFR, 0);
+ }
+
+ *-------------------------------------------------------*
+ * - (MR122 only: Decode pitch gain.) *
+ * - Decode innovative codebook. *
+ * - set pitch sharpening factor *
+ *-------------------------------------------------------*
+
+ if (sub (mode, MR475) == 0 || sub (mode, MR515) == 0)
+ { // MR475, MR515
+ index = *parm++; // index of position
+ i = *parm++; // signs
+
+ decode_2i40_9bits (subfrNr, i, index, code);
+
+ pit_sharp = shl (st->sharp, 1);
+ }
+ else if (sub (mode, MR59) == 0)
+ { // MR59
+ index = *parm++; // index of position
+ i = *parm++; // signs
+
+ decode_2i40_11bits (i, index, code);
+
+ pit_sharp = shl (st->sharp, 1);
+ }
+ else if (sub (mode, MR67) == 0)
+ { // MR67
+ index = *parm++; // index of position
+ i = *parm++; // signs
+
+ decode_3i40_14bits (i, index, code);
+
+ pit_sharp = shl (st->sharp, 1);
+ }
+ else if (sub (mode, MR795) <= 0)
+ { // MR74, MR795
+ index = *parm++; // index of position
+ i = *parm++; // signs
+
+ decode_4i40_17bits (i, index, code);
+
+ pit_sharp = shl (st->sharp, 1);
+ }
+ else if (sub (mode, MR102) == 0)
+ { // MR102
+ dec_8i40_31bits (parm, code);
+ parm += 7;
+
+ pit_sharp = shl (st->sharp, 1);
+ }
+ else
+ { // MR122
+ index = *parm++;
+ if (bfi != 0)
+ {
+ ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit);
+ }
+ else
+ {
+ gain_pit = d_gain_pitch (mode, index);
+ }
+ ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf,
+ &gain_pit);
+
+ dec_10i40_35bits (parm, code);
+ parm += 10;
+
+ // pit_sharp = gain_pit;
+ // if (pit_sharp > 1.0) pit_sharp = 1.0;
+
+ pit_sharp = shl (gain_pit, 1);
+ }
+
+ *-------------------------------------------------------*
+ * - Add the pitch contribution to code[]. *
+ *-------------------------------------------------------*
+ for (i = T0; i < L_SUBFR; i++)
+ {
+ temp = mult (code[i - T0], pit_sharp);
+ code[i] = add (code[i], temp);
+ }
+
+ *------------------------------------------------------------*
+ * - Decode codebook gain (MR122) or both pitch *
+ * gain and codebook gain (all others) *
+ * - Update pitch sharpening "sharp" with quantized gain_pit *
+ *------------------------------------------------------------*
+
+ if (sub (mode, MR475) == 0)
+ {
+ // read and decode pitch and code gain
+ if (evenSubfr != 0)
+ {
+ index_mr475 = *parm++; // index of gain(s)
+ }
+
+ if (bfi == 0)
+ {
+ Dec_gain(st->pred_state, mode, index_mr475, code,
+ evenSubfr, &gain_pit, &gain_code);
+ }
+ else
+ {
+ ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit);
+ ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state,
+ &gain_code);
+ }
+ ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf,
+ &gain_pit);
+ ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf,
+ &gain_code);
+
+ pit_sharp = gain_pit;
+ if (sub (pit_sharp, SHARPMAX) > 0)
+ {
+ pit_sharp = SHARPMAX;
+ }
+
+ }
+ else if ((sub (mode, MR74) <= 0) ||
+ (sub (mode, MR102) == 0))
+ {
+ // read and decode pitch and code gain
+ index = *parm++; // index of gain(s)
+
+ if (bfi == 0)
+ {
+ Dec_gain(st->pred_state, mode, index, code,
+ evenSubfr, &gain_pit, &gain_code);
+ }
+ else
+ {
+ ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit);
+ ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state,
+ &gain_code);
+ }
+ ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf,
+ &gain_pit);
+ ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf,
+ &gain_code);
+
+ pit_sharp = gain_pit;
+ if (sub (pit_sharp, SHARPMAX) > 0)
+ {
+ pit_sharp = SHARPMAX;
+ }
+
+ if (sub (mode, MR102) == 0)
+ {
+ if (sub (st->old_T0, add(L_SUBFR, 5)) > 0)
+ {
+ pit_sharp = shr(pit_sharp, 2);
+ }
+ }
+ }
+ else
+ {
+ // read and decode pitch gain
+ index = *parm++; // index of gain(s)
+
+ if (sub (mode, MR795) == 0)
+ {
+ // decode pitch gain
+ if (bfi != 0)
+ {
+ ec_gain_pitch (st->ec_gain_p_st, st->state, &gain_pit);
+ }
+ else
+ {
+ gain_pit = d_gain_pitch (mode, index);
+ }
+ ec_gain_pitch_update (st->ec_gain_p_st, bfi, st->prev_bf,
+ &gain_pit);
+
+ // read and decode code gain
+ index = *parm++;
+ if (bfi == 0)
+ {
+ d_gain_code (st->pred_state, mode, index, code, &gain_code);
+ }
+ else
+ {
+ ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state,
+ &gain_code);
+ }
+ ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf,
+ &gain_code);
+
+ pit_sharp = gain_pit;
+ if (sub (pit_sharp, SHARPMAX) > 0)
+ {
+ pit_sharp = SHARPMAX;
+ }
+ }
+ else
+ { // MR122
+ if (bfi == 0)
+ {
+ d_gain_code (st->pred_state, mode, index, code, &gain_code);
+ }
+ else
+ {
+ ec_gain_code (st->ec_gain_c_st, st->pred_state, st->state,
+ &gain_code);
+ }
+ ec_gain_code_update (st->ec_gain_c_st, bfi, st->prev_bf,
+ &gain_code);
+
+ pit_sharp = gain_pit;
+ }
+ }
+
+ // store pitch sharpening for next subframe
+ // (for modes which use the previous pitch gain for
+ // pitch sharpening in the search phase)
+ // do not update sharpening in even subframes for MR475
+ if (sub(mode, MR475) != 0 || evenSubfr == 0)
+ {
+ st->sharp = gain_pit;
+ if (sub (st->sharp, SHARPMAX) > 0)
+ {
+ st->sharp = SHARPMAX;
+ }
+ }
+
+ pit_sharp = shl (pit_sharp, 1);
+ if (sub (pit_sharp, 16384) > 0)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ temp = mult (st->exc[i], pit_sharp);
+ L_temp = L_mult (temp, gain_pit);
+ if (sub(mode, MR122)==0)
+ {
+ L_temp = L_shr (L_temp, 1);
+ }
+ excp[i] = pv_round (L_temp);
+ }
+ }
+
+ *-------------------------------------------------------*
+ * - Store list of LTP gains needed in the source *
+ * characteristic detector (SCD) *
+ *-------------------------------------------------------*
+ if ( bfi == 0 )
+ {
+ for (i = 0; i < 8; i++)
+ {
+ st->ltpGainHistory[i] = st->ltpGainHistory[i+1];
+ }
+ st->ltpGainHistory[8] = gain_pit;
+ }
+
+ *-------------------------------------------------------*
+ * - Limit gain_pit if in background noise and BFI *
+ * for MR475, MR515, MR59 *
+ *-------------------------------------------------------*
+
+ if ( (st->prev_bf != 0 || bfi != 0) && st->inBackgroundNoise != 0 &&
+ ((sub(mode, MR475) == 0) ||
+ (sub(mode, MR515) == 0) ||
+ (sub(mode, MR59) == 0))
+ )
+ {
+ if ( sub (gain_pit, 12288) > 0) // if (gain_pit > 0.75) in Q14
+ gain_pit = add( shr( sub(gain_pit, 12288), 1 ), 12288 );
+ // gain_pit = (gain_pit-0.75)/2.0 + 0.75;
+
+ if ( sub (gain_pit, 14745) > 0) // if (gain_pit > 0.90) in Q14
+ {
+ gain_pit = 14745;
+ }
+ }
+
+ *-------------------------------------------------------*
+ * Calculate CB mixed gain *
+ *-------------------------------------------------------*
+ Int_lsf(prev_lsf, st->lsfState->past_lsf_q, i_subfr, lsf_i);
+ gain_code_mix = Cb_gain_average(
+ st->Cb_gain_averState, mode, gain_code,
+ lsf_i, st->lsp_avg_st->lsp_meanSave, bfi,
+ st->prev_bf, pdfi, st->prev_pdf,
+ st->inBackgroundNoise, st->voicedHangover);
+
+ // make sure that MR74, MR795, MR122 have original code_gain
+ if ((sub(mode, MR67) > 0) && (sub(mode, MR102) != 0) )
+ // MR74, MR795, MR122
+ {
+ gain_code_mix = gain_code;
+ }
+
+ *-------------------------------------------------------*
+ * - Find the total excitation. *
+ * - Find synthesis speech corresponding to st->exc[]. *
+ *-------------------------------------------------------*
+ if (sub(mode, MR102) <= 0) // MR475, MR515, MR59, MR67, MR74, MR795, MR102
+ {
+ pitch_fac = gain_pit;
+ tmp_shift = 1;
+ }
+ else // MR122
+ {
+ pitch_fac = shr (gain_pit, 1);
+ tmp_shift = 2;
+ }
+
+ // copy unscaled LTP excitation to exc_enhanced (used in phase
+ * dispersion below) and compute total excitation for LTP feedback
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ exc_enhanced[i] = st->exc[i];
+
+ // st->exc[i] = gain_pit*st->exc[i] + gain_code*code[i];
+ L_temp = L_mult (st->exc[i], pitch_fac);
+ // 12.2: Q0 * Q13
+ // 7.4: Q0 * Q14
+ L_temp = L_mac (L_temp, code[i], gain_code);
+ // 12.2: Q12 * Q1
+ // 7.4: Q13 * Q1
+ L_temp = L_shl (L_temp, tmp_shift); // Q16
+ st->exc[i] = pv_round (L_temp);
+ }
+
+ *-------------------------------------------------------*
+ * - Adaptive phase dispersion *
+ *-------------------------------------------------------*
+ ph_disp_release(st->ph_disp_st); // free phase dispersion adaption
+
+ if ( ((sub(mode, MR475) == 0) ||
+ (sub(mode, MR515) == 0) ||
+ (sub(mode, MR59) == 0)) &&
+ sub(st->voicedHangover, 3) > 0 &&
+ st->inBackgroundNoise != 0 &&
+ bfi != 0 )
+ {
+ ph_disp_lock(st->ph_disp_st); // Always Use full Phase Disp.
+ } // if error in bg noise
+
+ // apply phase dispersion to innovation (if enabled) and
+ compute total excitation for synthesis part
+ ph_disp(st->ph_disp_st, mode,
+ exc_enhanced, gain_code_mix, gain_pit, code,
+ pitch_fac, tmp_shift);
+
+ *-------------------------------------------------------*
+ * - The Excitation control module are active during BFI.*
+ * - Conceal drops in signal energy if in bg noise. *
+ *-------------------------------------------------------*
+
+ L_temp = 0;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ L_temp = L_mac (L_temp, exc_enhanced[i], exc_enhanced[i] );
+ }
+
+ L_temp = L_shr (L_temp, 1); // excEnergy = sqrt(L_temp) in Q0
+ L_temp = sqrt_l_exp(L_temp, &temp); // function result
+ L_temp = L_shr(L_temp, add( shr(temp, 1), 15));
+ L_temp = L_shr(L_temp, 2); // To cope with 16-bit and
+ excEnergy = extract_l(L_temp); // scaling in ex_ctrl()
+
+ if ( ((sub (mode, MR475) == 0) ||
+ (sub (mode, MR515) == 0) ||
+ (sub (mode, MR59) == 0)) &&
+ sub(st->voicedHangover, 5) > 0 &&
+ st->inBackgroundNoise != 0 &&
+ sub(st->state, 4) < 0 &&
+ ( (pdfi != 0 && st->prev_pdf != 0) ||
+ bfi != 0 ||
+ st->prev_bf != 0) )
+ {
+ carefulFlag = 0;
+ if ( pdfi != 0 && bfi == 0 )
+ {
+ carefulFlag = 1;
+ }
+
+ Ex_ctrl(exc_enhanced,
+ excEnergy,
+ st->excEnergyHist,
+ st->voicedHangover,
+ st->prev_bf,
+ carefulFlag);
+ }
+
+ if ( st->inBackgroundNoise != 0 &&
+ ( bfi != 0 || st->prev_bf != 0 ) &&
+ sub(st->state, 4) < 0 )
+ {
+ ; // do nothing!
+ }
+ else
+ {
+ // Update energy history for all modes
+ for (i = 0; i < 8; i++)
+ {
+ st->excEnergyHist[i] = st->excEnergyHist[i+1];
+ }
+ st->excEnergyHist[8] = excEnergy;
+ }
+ *-------------------------------------------------------*
+ * Excitation control module end. *
+ *-------------------------------------------------------*
+
+ if (sub (pit_sharp, 16384) > 0)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ excp[i] = add (excp[i], exc_enhanced[i]);
+ }
+ agc2 (exc_enhanced, excp, L_SUBFR);
+ Overflow = 0;
+ Syn_filt (Az, excp, &synth[i_subfr], L_SUBFR,
+ st->mem_syn, 0);
+ }
+ else
+ {
+ Overflow = 0;
+ Syn_filt (Az, exc_enhanced, &synth[i_subfr], L_SUBFR,
+ st->mem_syn, 0);
+ }
+
+ if (Overflow != 0) // Test for overflow
+ {
+ for (i = 0; i < PIT_MAX + L_INTERPOL + L_SUBFR; i++)
+ {
+ st->old_exc[i] = shr(st->old_exc[i], 2);
+ }
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ exc_enhanced[i] = shr(exc_enhanced[i], 2);
+ }
+ Syn_filt(Az, exc_enhanced, &synth[i_subfr], L_SUBFR, st->mem_syn, 1);
+ }
+ else
+ {
+ Copy(&synth[i_subfr+L_SUBFR-M], st->mem_syn, M);
+ }
+
+ *--------------------------------------------------*
+ * Update signal for next frame. *
+ * -> shift to the left by L_SUBFR st->exc[] *
+ *--------------------------------------------------*
+
+ Copy (&st->old_exc[L_SUBFR], &st->old_exc[0], PIT_MAX + L_INTERPOL);
+
+ // interpolated LPC parameters for next subframe
+ Az += MP1;
+
+ // store T0 for next subframe
+ st->old_T0 = T0;
+ }
+
+ *-------------------------------------------------------*
+ * Call the Source Characteristic Detector which updates *
+ * st->inBackgroundNoise and st->voicedHangover. *
+ *-------------------------------------------------------*
+
+ st->inBackgroundNoise = Bgn_scd(st->background_state,
+ &(st->ltpGainHistory[0]),
+ &(synth[0]),
+ &(st->voicedHangover) );
+
+ dtx_dec_activity_update(st->dtxDecoderState,
+ st->lsfState->past_lsf_q,
+ synth);
+
+ // store bfi for next subframe
+ st->prev_bf = bfi;
+ st->prev_pdf = pdfi;
+
+ *--------------------------------------------------*
+ * Calculate the LSF averages on the eight *
+ * previous frames *
+ *--------------------------------------------------*
+
+ lsp_avg(st->lsp_avg_st, st->lsfState->past_lsf_q);
+
+the_end:
+ st->dtxDecoderState->dtxGlobalState = newDTXState;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Decoder_amr(
+ Decoder_amrState *st, /* i/o : State variables */
+ enum Mode mode, /* i : AMR mode */
+ Word16 parm[], /* i : vector of synthesis parameters
+ (PRM_SIZE) */
+ enum RXFrameType frame_type, /* i : received frame type */
+ Word16 synth[], /* o : synthesis speech (L_FRAME) */
+ Word16 A_t[] /* o : decoded LP filter in 4 subframes
+ (AZ_SIZE) */
+)
+{
+ /* LPC coefficients */
+
+ Word16 *Az; /* Pointer on A_t */
+
+ /* LSPs */
+
+ Word16 lsp_new[M];
+ Word16 lsp_mid[M];
+
+ /* LSFs */
+
+ Word16 prev_lsf[M];
+ Word16 lsf_i[M];
+
+ /* Algebraic codevector */
+
+ Word16 code[L_SUBFR];
+
+ /* excitation */
+
+ Word16 excp[L_SUBFR];
+ Word16 exc_enhanced[L_SUBFR];
+
+ /* Scalars */
+
+ Word16 i;
+ Word16 i_subfr;
+ Word16 T0;
+ Word16 T0_frac;
+ Word16 index;
+ Word16 index_mr475 = 0;
+ Word16 gain_pit;
+ Word16 gain_code;
+ Word16 gain_code_mix;
+ Word16 pit_sharp;
+ Word16 pit_flag;
+ Word16 pitch_fac;
+ Word16 t0_min;
+ Word16 t0_max;
+ Word16 delta_frc_low;
+ Word16 delta_frc_range;
+ Word16 tmp_shift;
+ Word16 temp;
+ Word32 L_temp;
+ Word16 flag4;
+ Word16 carefulFlag;
+ Word16 excEnergy;
+ Word16 subfrNr;
+ Word16 evenSubfr = 0;
+
+ Word16 bfi = 0; /* bad frame indication flag */
+ Word16 pdfi = 0; /* potential degraded bad frame flag */
+
+ enum DTXStateType newDTXState; /* SPEECH , DTX, DTX_MUTE */
+ Flag *pOverflow = &(st->overflow); /* Overflow flag */
+
+
+ /* find the new DTX state SPEECH OR DTX */
+ newDTXState = rx_dtx_handler(&(st->dtxDecoderState), frame_type, pOverflow);
+
+ /* DTX actions */
+
+ if (newDTXState != SPEECH)
+ {
+ Decoder_amr_reset(st, MRDTX);
+
+ dtx_dec(&(st->dtxDecoderState),
+ st->mem_syn,
+ &(st->lsfState),
+ &(st->pred_state),
+ &(st->Cb_gain_averState),
+ newDTXState,
+ mode,
+ parm, synth, A_t, pOverflow);
+
+ /* update average lsp */
+ Lsf_lsp(
+ st->lsfState.past_lsf_q,
+ st->lsp_old,
+ M,
+ pOverflow);
+
+ lsp_avg(
+ &(st->lsp_avg_st),
+ st->lsfState.past_lsf_q,
+ pOverflow);
+
+ goto the_end;
+ }
+
+ /* SPEECH action state machine */
+ if ((frame_type == RX_SPEECH_BAD) || (frame_type == RX_NO_DATA) ||
+ (frame_type == RX_ONSET))
+ {
+ bfi = 1;
+
+ if ((frame_type == RX_NO_DATA) || (frame_type == RX_ONSET))
+ {
+ build_CN_param(&st->nodataSeed,
+ prmno[mode],
+ bitno[mode],
+ parm,
+ pOverflow);
+ }
+ }
+ else if (frame_type == RX_SPEECH_DEGRADED)
+ {
+ pdfi = 1;
+ }
+
+ if (bfi != 0)
+ {
+ st->state += 1;
+ }
+ else if (st->state == 6)
+
+ {
+ st->state = 5;
+ }
+ else
+ {
+ st->state = 0;
+ }
+
+
+ if (st->state > 6)
+ {
+ st->state = 6;
+ }
+
+ /* If this frame is the first speech frame after CNI period, */
+ /* set the BFH state machine to an appropriate state depending */
+ /* on whether there was DTX muting before start of speech or not */
+ /* If there was DTX muting, the first speech frame is muted. */
+ /* If there was no DTX muting, the first speech frame is not */
+ /* muted. The BFH state machine starts from state 5, however, to */
+ /* keep the audible noise resulting from a SID frame which is */
+ /* erroneously interpreted as a good speech frame as small as */
+ /* possible (the decoder output in this case is quickly muted) */
+
+ if (st->dtxDecoderState.dtxGlobalState == DTX)
+ {
+ st->state = 5;
+ st->prev_bf = 0;
+ }
+ else if (st->dtxDecoderState.dtxGlobalState == DTX_MUTE)
+ {
+ st->state = 5;
+ st->prev_bf = 1;
+ }
+
+ /* save old LSFs for CB gain smoothing */
+ Copy(st->lsfState.past_lsf_q, prev_lsf, M);
+
+ /* decode LSF parameters and generate interpolated lpc coefficients
+ for the 4 subframes */
+
+ if (mode != MR122)
+ {
+ D_plsf_3(
+ &(st->lsfState),
+ mode,
+ bfi,
+ parm,
+ lsp_new,
+ pOverflow);
+
+ /* Advance synthesis parameters pointer */
+ parm += 3;
+
+ Int_lpc_1to3(
+ st->lsp_old,
+ lsp_new,
+ A_t,
+ pOverflow);
+ }
+ else
+ {
+ D_plsf_5(
+ &(st->lsfState),
+ bfi,
+ parm,
+ lsp_mid,
+ lsp_new,
+ pOverflow);
+
+ /* Advance synthesis parameters pointer */
+ parm += 5;
+
+ Int_lpc_1and3(
+ st->lsp_old,
+ lsp_mid,
+ lsp_new,
+ A_t,
+ pOverflow);
+ }
+
+ /* update the LSPs for the next frame */
+ for (i = 0; i < M; i++)
+ {
+ st->lsp_old[i] = lsp_new[i];
+ }
+
+ /*------------------------------------------------------------------------*
+ * Loop for every subframe in the analysis frame *
+ *------------------------------------------------------------------------*
+ * The subframe size is L_SUBFR and the loop is repeated L_FRAME/L_SUBFR *
+ * times *
+ * - decode the pitch delay *
+ * - decode algebraic code *
+ * - decode pitch and codebook gains *
+ * - find the excitation and compute synthesis speech *
+ *------------------------------------------------------------------------*/
+
+ /* pointer to interpolated LPC parameters */
+ Az = A_t;
+
+ evenSubfr = 0;
+ subfrNr = -1;
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ subfrNr += 1;
+ evenSubfr = 1 - evenSubfr;
+
+ /* flag for first and 3th subframe */
+ pit_flag = i_subfr;
+
+
+ if (i_subfr == L_FRAME_BY2)
+ {
+ if ((mode != MR475) && (mode != MR515))
+ {
+ pit_flag = 0;
+ }
+ }
+
+ /* pitch index */
+ index = *parm++;
+
+ /*-------------------------------------------------------*
+ * - decode pitch lag and find adaptive codebook vector. *
+ *-------------------------------------------------------*/
+
+ if (mode != MR122)
+ {
+ /* flag4 indicates encoding with 4 bit resolution; */
+ /* this is needed for mode MR475, MR515, MR59 and MR67 */
+
+ flag4 = 0;
+
+ if ((mode == MR475) || (mode == MR515) || (mode == MR59) ||
+ (mode == MR67))
+ {
+ flag4 = 1;
+ }
+
+ /*-------------------------------------------------------*
+ * - get ranges for the t0_min and t0_max *
+ * - only needed in delta decoding *
+ *-------------------------------------------------------*/
+
+ delta_frc_low = 5;
+ delta_frc_range = 9;
+
+ if (mode == MR795)
+ {
+ delta_frc_low = 10;
+ delta_frc_range = 19;
+ }
+
+ t0_min = sub(st->old_T0, delta_frc_low, pOverflow);
+
+ if (t0_min < PIT_MIN)
+ {
+ t0_min = PIT_MIN;
+ }
+ t0_max = add(t0_min, delta_frc_range, pOverflow);
+
+ if (t0_max > PIT_MAX)
+ {
+ t0_max = PIT_MAX;
+ t0_min = t0_max - delta_frc_range;
+ }
+
+ Dec_lag3(index, t0_min, t0_max, pit_flag, st->old_T0,
+ &T0, &T0_frac, flag4, pOverflow);
+
+ st->T0_lagBuff = T0;
+
+ if (bfi != 0)
+ {
+ if (st->old_T0 < PIT_MAX)
+ { /* Graceful pitch */
+ st->old_T0 += 0; /* degradation */
+ }
+ T0 = st->old_T0;
+ T0_frac = 0;
+
+ if ((st->inBackgroundNoise != 0) && (st->voicedHangover > 4) &&
+ ((mode == MR475) || (mode == MR515) || (mode == MR59)))
+ {
+ T0 = st->T0_lagBuff;
+ }
+ }
+
+ Pred_lt_3or6(st->exc, T0, T0_frac, L_SUBFR, 1, pOverflow);
+ }
+ else
+ {
+ Dec_lag6(index, PIT_MIN_MR122,
+ PIT_MAX, pit_flag, &T0, &T0_frac, pOverflow);
+
+
+ if (!(bfi == 0 && (pit_flag == 0 || index < 61)))
+ {
+ st->T0_lagBuff = T0;
+ T0 = st->old_T0;
+ T0_frac = 0;
+ }
+
+ Pred_lt_3or6(st->exc, T0, T0_frac, L_SUBFR, 0, pOverflow);
+ }
+
+ /*-------------------------------------------------------*
+ * - (MR122 only: Decode pitch gain.) *
+ * - Decode innovative codebook. *
+ * - set pitch sharpening factor *
+ *-------------------------------------------------------*/
+ if ((mode == MR475) || (mode == MR515))
+ { /* MR475, MR515 */
+ index = *parm++; /* index of position */
+ i = *parm++; /* signs */
+
+ decode_2i40_9bits(subfrNr, i, index, code, pOverflow);
+
+ L_temp = (Word32)st->sharp << 1;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ pit_sharp = (st->sharp > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ pit_sharp = (Word16) L_temp;
+ }
+ }
+ else if (mode == MR59)
+ { /* MR59 */
+ index = *parm++; /* index of position */
+ i = *parm++; /* signs */
+
+ decode_2i40_11bits(i, index, code);
+
+ L_temp = (Word32)st->sharp << 1;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ pit_sharp = (st->sharp > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ pit_sharp = (Word16) L_temp;
+ }
+ }
+ else if (mode == MR67)
+ { /* MR67 */
+ index = *parm++; /* index of position */
+ i = *parm++; /* signs */
+
+ decode_3i40_14bits(i, index, code);
+
+ L_temp = (Word32)st->sharp << 1;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ pit_sharp = (st->sharp > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ pit_sharp = (Word16) L_temp;
+ }
+ }
+ else if (mode <= MR795)
+ { /* MR74, MR795 */
+ index = *parm++; /* index of position */
+ i = *parm++; /* signs */
+
+ decode_4i40_17bits(i, index, code);
+
+ L_temp = (Word32)st->sharp << 1;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ pit_sharp = (st->sharp > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ pit_sharp = (Word16) L_temp;
+ }
+ }
+ else if (mode == MR102)
+ { /* MR102 */
+ dec_8i40_31bits(parm, code, pOverflow);
+ parm += 7;
+
+ L_temp = (Word32)st->sharp << 1;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ pit_sharp = (st->sharp > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ pit_sharp = (Word16) L_temp;
+ }
+ }
+ else
+ { /* MR122 */
+ index = *parm++;
+
+ if (bfi != 0)
+ {
+ ec_gain_pitch(
+ &(st->ec_gain_p_st),
+ st->state,
+ &gain_pit,
+ pOverflow);
+ }
+ else
+ {
+ gain_pit = d_gain_pitch(mode, index);
+ }
+ ec_gain_pitch_update(
+ &(st->ec_gain_p_st),
+ bfi,
+ st->prev_bf,
+ &gain_pit,
+ pOverflow);
+
+
+ dec_10i40_35bits(parm, code);
+ parm += 10;
+
+ /* pit_sharp = gain_pit; */
+ /* if (pit_sharp > 1.0) pit_sharp = 1.0; */
+
+ L_temp = (Word32)gain_pit << 1;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ pit_sharp = (gain_pit > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ pit_sharp = (Word16) L_temp;
+ }
+ }
+ /*-------------------------------------------------------*
+ * - Add the pitch contribution to code[]. *
+ *-------------------------------------------------------*/
+ for (i = T0; i < L_SUBFR; i++)
+ {
+ temp = mult(*(code + i - T0), pit_sharp, pOverflow);
+ *(code + i) = add(*(code + i), temp, pOverflow);
+
+ }
+
+ /*------------------------------------------------------------*
+ * - Decode codebook gain (MR122) or both pitch *
+ * gain and codebook gain (all others) *
+ * - Update pitch sharpening "sharp" with quantized gain_pit *
+ *------------------------------------------------------------*/
+ if (mode == MR475)
+ {
+ /* read and decode pitch and code gain */
+
+ if (evenSubfr != 0)
+ {
+ index_mr475 = *parm++; /* index of gain(s) */
+ }
+
+ if (bfi == 0)
+ {
+ Dec_gain(
+ &(st->pred_state),
+ mode,
+ index_mr475,
+ code,
+ evenSubfr,
+ &gain_pit,
+ &gain_code,
+ pOverflow);
+ }
+ else
+ {
+ ec_gain_pitch(
+ &(st->ec_gain_p_st),
+ st->state,
+ &gain_pit,
+ pOverflow);
+
+ ec_gain_code(
+ &(st->ec_gain_c_st),
+ &(st->pred_state),
+ st->state,
+ &gain_code,
+ pOverflow);
+ }
+ ec_gain_pitch_update(
+ &st->ec_gain_p_st,
+ bfi,
+ st->prev_bf,
+ &gain_pit,
+ pOverflow);
+
+ ec_gain_code_update(
+ &st->ec_gain_c_st,
+ bfi,
+ st->prev_bf,
+ &gain_code,
+ pOverflow);
+
+ pit_sharp = gain_pit;
+
+ if (pit_sharp > SHARPMAX)
+ {
+ pit_sharp = SHARPMAX;
+ }
+
+ }
+ else if ((mode <= MR74) || (mode == MR102))
+ {
+ /* read and decode pitch and code gain */
+ index = *parm++; /* index of gain(s) */
+
+ if (bfi == 0)
+ {
+ Dec_gain(
+ &(st->pred_state),
+ mode,
+ index,
+ code,
+ evenSubfr,
+ &gain_pit,
+ &gain_code,
+ pOverflow);
+ }
+ else
+ {
+ ec_gain_pitch(
+ &(st->ec_gain_p_st),
+ st->state,
+ &gain_pit,
+ pOverflow);
+
+ ec_gain_code(
+ &(st->ec_gain_c_st),
+ &(st->pred_state),
+ st->state,
+ &gain_code,
+ pOverflow);
+ }
+
+ ec_gain_pitch_update(
+ &(st->ec_gain_p_st),
+ bfi,
+ st->prev_bf,
+ &gain_pit,
+ pOverflow);
+
+ ec_gain_code_update(
+ &(st->ec_gain_c_st),
+ bfi,
+ st->prev_bf,
+ &gain_code,
+ pOverflow);
+
+ pit_sharp = gain_pit;
+
+ if (pit_sharp > SHARPMAX)
+ {
+ pit_sharp = SHARPMAX;
+ }
+
+ if (mode == MR102)
+ {
+ if (st->old_T0 > (L_SUBFR + 5))
+ {
+ if (pit_sharp < 0)
+ {
+ pit_sharp = ~((~pit_sharp) >> 2);
+ }
+ else
+ {
+ pit_sharp = pit_sharp >> 2;
+ }
+ }
+ }
+ }
+ else
+ {
+ /* read and decode pitch gain */
+ index = *parm++; /* index of gain(s) */
+
+ if (mode == MR795)
+ {
+ /* decode pitch gain */
+ if (bfi != 0)
+ {
+ ec_gain_pitch(
+ &(st->ec_gain_p_st),
+ st->state,
+ &gain_pit,
+ pOverflow);
+ }
+ else
+ {
+ gain_pit = d_gain_pitch(mode, index);
+ }
+ ec_gain_pitch_update(
+ &(st->ec_gain_p_st),
+ bfi,
+ st->prev_bf,
+ &gain_pit,
+ pOverflow);
+
+ /* read and decode code gain */
+ index = *parm++;
+
+ if (bfi == 0)
+ {
+ d_gain_code(
+ &(st->pred_state),
+ mode,
+ index,
+ code,
+ &gain_code,
+ pOverflow);
+ }
+ else
+ {
+ ec_gain_code(
+ &(st->ec_gain_c_st),
+ &(st->pred_state),
+ st->state,
+ &gain_code,
+ pOverflow);
+ }
+
+ ec_gain_code_update(
+ &(st->ec_gain_c_st),
+ bfi,
+ st->prev_bf,
+ &gain_code,
+ pOverflow);
+
+ pit_sharp = gain_pit;
+
+ if (pit_sharp > SHARPMAX)
+ {
+ pit_sharp = SHARPMAX;
+ }
+ }
+ else
+ { /* MR122 */
+
+ if (bfi == 0)
+ {
+ d_gain_code(
+ &(st->pred_state),
+ mode,
+ index,
+ code,
+ &gain_code,
+ pOverflow);
+ }
+ else
+ {
+ ec_gain_code(
+ &(st->ec_gain_c_st),
+ &(st->pred_state),
+ st->state,
+ &gain_code,
+ pOverflow);
+ }
+
+ ec_gain_code_update(
+ &(st->ec_gain_c_st),
+ bfi,
+ st->prev_bf,
+ &gain_code,
+ pOverflow);
+
+ pit_sharp = gain_pit;
+ }
+ }
+
+ /* store pitch sharpening for next subframe */
+ /* (for modes which use the previous pitch gain for */
+ /* pitch sharpening in the search phase) */
+ /* do not update sharpening in even subframes for MR475 */
+ if ((mode != MR475) || (evenSubfr == 0))
+ {
+ st->sharp = gain_pit;
+
+ if (st->sharp > SHARPMAX)
+ {
+ st->sharp = SHARPMAX;
+ }
+ }
+
+ pit_sharp = shl(pit_sharp, 1, pOverflow);
+
+ if (pit_sharp > 16384)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ temp = mult(st->exc[i], pit_sharp, pOverflow);
+ L_temp = L_mult(temp, gain_pit, pOverflow);
+
+ if (mode == MR122)
+ {
+ if (L_temp < 0)
+ {
+ L_temp = ~((~L_temp) >> 1);
+ }
+ else
+ {
+ L_temp = L_temp >> 1;
+ }
+ }
+ *(excp + i) = pv_round(L_temp, pOverflow);
+ }
+ }
+
+ /*-------------------------------------------------------*
+ * - Store list of LTP gains needed in the source *
+ * characteristic detector (SCD) *
+ *-------------------------------------------------------*/
+
+ if (bfi == 0)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ st->ltpGainHistory[i] = st->ltpGainHistory[i+1];
+ }
+ st->ltpGainHistory[8] = gain_pit;
+ }
+
+ /*-------------------------------------------------------*
+ * - Limit gain_pit if in background noise and BFI *
+ * for MR475, MR515, MR59 *
+ *-------------------------------------------------------*/
+
+
+ if ((st->prev_bf != 0 || bfi != 0) && st->inBackgroundNoise != 0 &&
+ ((mode == MR475) || (mode == MR515) || (mode == MR59)))
+ {
+
+ if (gain_pit > 12288) /* if (gain_pit > 0.75) in Q14*/
+ {
+ gain_pit = ((gain_pit - 12288) >> 1) + 12288;
+ /* gain_pit = (gain_pit-0.75)/2.0 + 0.75; */
+ }
+
+ if (gain_pit > 14745) /* if (gain_pit > 0.90) in Q14*/
+ {
+ gain_pit = 14745;
+ }
+ }
+
+ /*-------------------------------------------------------*
+ * Calculate CB mixed gain *
+ *-------------------------------------------------------*/
+ Int_lsf(
+ prev_lsf,
+ st->lsfState.past_lsf_q,
+ i_subfr,
+ lsf_i,
+ pOverflow);
+
+ gain_code_mix =
+ Cb_gain_average(
+ &(st->Cb_gain_averState),
+ mode,
+ gain_code,
+ lsf_i,
+ st->lsp_avg_st.lsp_meanSave,
+ bfi,
+ st->prev_bf,
+ pdfi,
+ st->prev_pdf,
+ st->inBackgroundNoise,
+ st->voicedHangover,
+ pOverflow);
+
+ /* make sure that MR74, MR795, MR122 have original code_gain*/
+ if ((mode > MR67) && (mode != MR102))
+ /* MR74, MR795, MR122 */
+ {
+ gain_code_mix = gain_code;
+ }
+
+ /*-------------------------------------------------------*
+ * - Find the total excitation. *
+ * - Find synthesis speech corresponding to st->exc[]. *
+ *-------------------------------------------------------*/
+ if (mode <= MR102) /* MR475, MR515, MR59, MR67, MR74, MR795, MR102*/
+ {
+ pitch_fac = gain_pit;
+ tmp_shift = 1;
+ }
+ else /* MR122 */
+ {
+ if (gain_pit < 0)
+ {
+ pitch_fac = ~((~gain_pit) >> 1);
+ }
+ else
+ {
+ pitch_fac = gain_pit >> 1;
+ }
+ tmp_shift = 2;
+ }
+
+ /* copy unscaled LTP excitation to exc_enhanced (used in phase
+ * dispersion below) and compute total excitation for LTP feedback
+ */
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ exc_enhanced[i] = st->exc[i];
+
+ /* st->exc[i] = gain_pit*st->exc[i] + gain_code*code[i]; */
+ L_temp = L_mult(st->exc[i], pitch_fac, pOverflow);
+ /* 12.2: Q0 * Q13 */
+ /* 7.4: Q0 * Q14 */
+ L_temp = L_mac(L_temp, code[i], gain_code, pOverflow);
+ /* 12.2: Q12 * Q1 */
+ /* 7.4: Q13 * Q1 */
+ L_temp = L_shl(L_temp, tmp_shift, pOverflow); /* Q16 */
+ st->exc[i] = pv_round(L_temp, pOverflow);
+ }
+
+ /*-------------------------------------------------------*
+ * - Adaptive phase dispersion *
+ *-------------------------------------------------------*/
+ ph_disp_release(&(st->ph_disp_st)); /* free phase dispersion adaption */
+
+
+ if (((mode == MR475) || (mode == MR515) || (mode == MR59)) &&
+ (st->voicedHangover > 3) && (st->inBackgroundNoise != 0) &&
+ (bfi != 0))
+ {
+ ph_disp_lock(&(st->ph_disp_st)); /* Always Use full Phase Disp. */
+ } /* if error in bg noise */
+
+ /* apply phase dispersion to innovation (if enabled) and
+ compute total excitation for synthesis part */
+ ph_disp(
+ &(st->ph_disp_st),
+ mode,
+ exc_enhanced,
+ gain_code_mix,
+ gain_pit,
+ code,
+ pitch_fac,
+ tmp_shift,
+ pOverflow);
+
+ /*-------------------------------------------------------*
+ * - The Excitation control module are active during BFI.*
+ * - Conceal drops in signal energy if in bg noise. *
+ *-------------------------------------------------------*/
+ L_temp = 0;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ L_temp = L_mac(L_temp, *(exc_enhanced + i), *(exc_enhanced + i), pOverflow);
+ }
+
+ /* excEnergy = sqrt(L_temp) in Q0 */
+ if (L_temp < 0)
+ {
+ L_temp = ~((~L_temp) >> 1);
+ }
+ else
+ {
+ L_temp = L_temp >> 1;
+ }
+
+ L_temp = sqrt_l_exp(L_temp, &temp, pOverflow);
+ /* To cope with 16-bit and scaling in ex_ctrl() */
+ L_temp = L_shr(L_temp, (Word16)((temp >> 1) + 15), pOverflow);
+ if (L_temp < 0)
+ {
+ excEnergy = (Word16)(~((~L_temp) >> 2));
+ }
+ else
+ {
+ excEnergy = (Word16)(L_temp >> 2);
+ }
+
+ if (((mode == MR475) || (mode == MR515) || (mode == MR59)) &&
+ (st->voicedHangover > 5) && (st->inBackgroundNoise != 0) &&
+ (st->state < 4) &&
+ ((pdfi != 0 && st->prev_pdf != 0) || bfi != 0 || st->prev_bf != 0))
+ {
+ carefulFlag = 0;
+
+ if (pdfi != 0 && bfi == 0)
+ {
+ carefulFlag = 1;
+ }
+
+ Ex_ctrl(exc_enhanced,
+ excEnergy,
+ st->excEnergyHist,
+ st->voicedHangover,
+ st->prev_bf,
+ carefulFlag, pOverflow);
+ }
+
+ if (!((st->inBackgroundNoise != 0) && (bfi != 0 || st->prev_bf != 0) &&
+ (st->state < 4)))
+ {
+ /* Update energy history for all modes */
+ for (i = 0; i < 8; i++)
+ {
+ st->excEnergyHist[i] = st->excEnergyHist[i+1];
+ }
+ st->excEnergyHist[8] = excEnergy;
+ }
+ /*-------------------------------------------------------*
+ * Excitation control module end. *
+ *-------------------------------------------------------*/
+ if (pit_sharp > 16384)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ *(excp + i) = add(*(excp + i), *(exc_enhanced + i), pOverflow);
+
+ }
+ agc2(exc_enhanced, excp, L_SUBFR, pOverflow);
+ *pOverflow = 0;
+ Syn_filt(Az, excp, &synth[i_subfr], L_SUBFR,
+ st->mem_syn, 0);
+ }
+ else
+ {
+ *pOverflow = 0;
+ Syn_filt(Az, exc_enhanced, &synth[i_subfr], L_SUBFR,
+ st->mem_syn, 0);
+ }
+
+ if (*pOverflow != 0) /* Test for overflow */
+ {
+ for (i = PIT_MAX + L_INTERPOL + L_SUBFR - 1; i >= 0; i--)
+ {
+ if (st->old_exc[i] < 0)
+ {
+ st->old_exc[i] = ~((~st->old_exc[i]) >> 2);
+ }
+ else
+ {
+ st->old_exc[i] = st->old_exc[i] >> 2;
+ }
+
+ }
+
+ for (i = L_SUBFR - 1; i >= 0; i--)
+ {
+ if (*(exc_enhanced + i) < 0)
+ {
+ *(exc_enhanced + i) = ~((~(*(exc_enhanced + i))) >> 2);
+ }
+ else
+ {
+ *(exc_enhanced + i) = *(exc_enhanced + i) >> 2;
+ }
+ }
+ Syn_filt(Az, exc_enhanced, &synth[i_subfr], L_SUBFR, st->mem_syn, 1);
+ }
+ else
+ {
+ Copy(&synth[i_subfr+L_SUBFR-M], st->mem_syn, M);
+ }
+
+ /*--------------------------------------------------*
+ * Update signal for next frame. *
+ * -> shift to the left by L_SUBFR st->exc[] *
+ *--------------------------------------------------*/
+
+ Copy(&st->old_exc[L_SUBFR], &st->old_exc[0], PIT_MAX + L_INTERPOL);
+
+ /* interpolated LPC parameters for next subframe */
+ Az += MP1;
+
+ /* store T0 for next subframe */
+ st->old_T0 = T0;
+ }
+
+ /*-------------------------------------------------------*
+ * Call the Source Characteristic Detector which updates *
+ * st->inBackgroundNoise and st->voicedHangover. *
+ *-------------------------------------------------------*/
+
+ st->inBackgroundNoise =
+ Bgn_scd(
+ &(st->background_state),
+ &(st->ltpGainHistory[0]),
+ &(synth[0]),
+ &(st->voicedHangover),
+ pOverflow);
+
+ dtx_dec_activity_update(
+ &(st->dtxDecoderState),
+ st->lsfState.past_lsf_q,
+ synth,
+ pOverflow);
+
+ /* store bfi for next subframe */
+ st->prev_bf = bfi;
+ st->prev_pdf = pdfi;
+
+ /*--------------------------------------------------*
+ * Calculate the LSF averages on the eight *
+ * previous frames *
+ *--------------------------------------------------*/
+ lsp_avg(
+ &(st->lsp_avg_st),
+ st->lsfState.past_lsf_q,
+ pOverflow);
+
+the_end:
+ st->dtxDecoderState.dtxGlobalState = newDTXState;
+
+// return(0);
+}
diff --git a/media/codecs/amrnb/dec/src/dec_amr.h b/media/codecs/amrnb/dec/src/dec_amr.h
new file mode 100644
index 0000000..b04137d
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_amr.h
@@ -0,0 +1,206 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/dec_amr.h
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Update function prototype for Decoder_amr(). Include overflow
+ flag in Decode_amrState structure
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : dec_amr.h
+ Purpose : Speech decoder routine.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef DEC_AMR_H
+#define DEC_AMR_H "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "mode.h"
+#include "dtx_dec.h"
+#include "d_plsf.h"
+#include "gc_pred.h"
+#include "ec_gains.h"
+#include "ph_disp.h"
+#include "c_g_aver.h"
+#include "bgnscd.h"
+#include "lsp_avg.h"
+#include "frame.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define EXC_ENERGY_HIST_LEN 9
+#define LTP_GAIN_HISTORY_LEN 9
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct Decoder_amrState
+ {
+ /* Excitation vector */
+ Word16 old_exc[L_SUBFR + PIT_MAX + L_INTERPOL];
+ Word16 *exc;
+
+ /* Lsp (Line spectral pairs) */
+ /* Word16 lsp[M]; */ /* Used by CN codec */
+ Word16 lsp_old[M];
+
+ /* Filter's memory */
+ Word16 mem_syn[M];
+
+ /* pitch sharpening */
+ Word16 sharp;
+ Word16 old_T0;
+
+ /* Memories for bad frame handling */
+ Word16 prev_bf;
+ Word16 prev_pdf;
+ Word16 state;
+ Word16 excEnergyHist[EXC_ENERGY_HIST_LEN];
+
+ /* Variable holding received ltpLag, used in background noise and BFI */
+ Word16 T0_lagBuff;
+
+ /* Variables for the source characteristic detector (SCD) */
+ Word16 inBackgroundNoise;
+ Word16 voicedHangover;
+ Word16 ltpGainHistory[LTP_GAIN_HISTORY_LEN];
+
+ Bgn_scdState background_state;
+ Word16 nodataSeed;
+
+ Cb_gain_averageState Cb_gain_averState;
+ lsp_avgState lsp_avg_st;
+
+ D_plsfState lsfState;
+ ec_gain_pitchState ec_gain_p_st;
+ ec_gain_codeState ec_gain_c_st;
+ gc_predState pred_state;
+ ph_dispState ph_disp_st;
+ dtx_decState dtxDecoderState;
+ Flag overflow;
+ } Decoder_amrState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ /*
+ * Function : Decoder_amr_init
+ * Purpose : Allocates initializes state memory
+ * Description : Stores pointer to filter status struct in *st. This
+ * pointer has to be passed to Decoder_amr in each call.
+ * Returns : 0 on success
+ */
+ Word16 Decoder_amr_init(Decoder_amrState *st);
+
+ /*
+ * Function : Decoder_amr_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ */
+ Word16 Decoder_amr_reset(Decoder_amrState *st, enum Mode mode);
+
+ /*
+ * Function : Decoder_amr
+ * Purpose : Speech decoder routine.
+ * Returns : 0
+ */
+ void Decoder_amr(
+ Decoder_amrState *st, /* i/o : State variables */
+ enum Mode mode, /* i : AMR mode */
+ Word16 parm[], /* i : vector of synthesis parameters
+ (PRM_SIZE) */
+ enum RXFrameType frame_type, /* i : received frame type */
+ Word16 synth[], /* o : synthesis speech (L_FRAME) */
+ Word16 A_t[] /* o : decoded LP filter in 4 subframes
+ (AZ_SIZE) */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DEC_AMR_H_ */
+
+
+
diff --git a/media/codecs/amrnb/dec/src/dec_gain.cpp b/media/codecs/amrnb/dec/src/dec_gain.cpp
new file mode 100644
index 0000000..ceab48d
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_gain.cpp
@@ -0,0 +1,305 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/dec_gain.c
+ Funtions: dec_gain
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updating include file lists, and other things as per review
+ comments.
+
+ Description: Added fixes to the code as per review comments. Removed nested
+ function calls and declared temp2 as a variable.
+
+ Description: A Word32 was being stored improperly in a Word16.
+
+ Description: Removed qua_gain.tab and qgain475.tab from Include section and
+ added qua_gain_tbl.h and qgain475_tab.h to Include section.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Added casting to eliminate warnings
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "dec_gain.h"
+#include "typedef.h"
+#include "mode.h"
+#include "cnst.h"
+#include "pow2.h"
+#include "log2.h"
+#include "gc_pred.h"
+#include "basic_op.h"
+#include "qua_gain_tbl.h"
+#include "qgain475_tab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dec_gain
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pred_state = pointer to MA predictor state of type gc_predState
+ index = AMR mode of type enum Mode
+ code[] = pointer to innovative vector of type Word16
+ evenSubfr = Flag for even subframes of type Word16
+ pOverflow = pointer to overflow flag
+
+
+ Outputs:
+ pred_state = pointer to MA predictor state of type gc_predState
+ gain_pit = pointer to pitch gain of type Word16
+ gain_cod = pointer to code gain of type Word16
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : dec_gain.c
+ Purpose : Decode the pitch and codebook gains
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ agc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+
+
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+void Dec_gain(
+ gc_predState *pred_state, /* i/o: MA predictor state */
+ enum Mode mode, /* i : AMR mode */
+ Word16 index, /* i : index of quantization. */
+ Word16 code[], /* i : Innovative vector. */
+ Word16 evenSubfr, /* i : Flag for even subframes */
+ Word16 * gain_pit, /* o : Pitch gain. */
+ Word16 * gain_cod, /* o : Code gain. */
+ Flag * pOverflow
+)
+{
+ const Word16 *p;
+ Word16 frac;
+ Word16 gcode0;
+ Word16 exp;
+ Word16 qua_ener;
+ Word16 qua_ener_MR122;
+ Word16 g_code;
+ Word32 L_tmp;
+ Word16 temp1;
+ Word16 temp2;
+
+ /* Read the quantized gains (table depends on mode) */
+ index = shl(index, 2, pOverflow);
+
+ if (mode == MR102 || mode == MR74 || mode == MR67)
+ {
+ p = &table_gain_highrates[index];
+
+ *gain_pit = *p++;
+ g_code = *p++;
+ qua_ener_MR122 = *p++;
+ qua_ener = *p;
+ }
+ else
+ {
+ if (mode == MR475)
+ {
+ index += (1 ^ evenSubfr) << 1; /* evenSubfr is 0 or 1 */
+
+ if (index > (MR475_VQ_SIZE*4 - 2))
+ {
+ index = (MR475_VQ_SIZE * 4 - 2); /* avoid possible buffer overflow */
+ }
+
+ p = &table_gain_MR475[index];
+
+ *gain_pit = *p++;
+ g_code = *p++;
+
+ /*---------------------------------------------------------*
+ * calculate predictor update values (not stored in 4.75 *
+ * quantizer table to save space): *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * qua_ener = log2(g) *
+ * qua_ener_MR122 = 20*log10(g) *
+ *---------------------------------------------------------*/
+
+ /* Log2(x Q12) = log2(x) + 12 */
+ temp1 = (Word16) L_deposit_l(g_code);
+ Log2(temp1, &exp, &frac, pOverflow);
+ exp = sub(exp, 12, pOverflow);
+
+ temp1 = shr_r(frac, 5, pOverflow);
+ temp2 = shl(exp, 10, pOverflow);
+ qua_ener_MR122 = add(temp1, temp2, pOverflow);
+
+ /* 24660 Q12 ~= 6.0206 = 20*log10(2) */
+ L_tmp = Mpy_32_16(exp, frac, 24660, pOverflow);
+ L_tmp = L_shl(L_tmp, 13, pOverflow);
+ qua_ener = pv_round(L_tmp, pOverflow);
+ /* Q12 * Q0 = Q13 -> Q10 */
+ }
+ else
+ {
+ p = &table_gain_lowrates[index];
+
+ *gain_pit = *p++;
+ g_code = *p++;
+ qua_ener_MR122 = *p++;
+ qua_ener = *p;
+ }
+ }
+
+ /*-------------------------------------------------------------------*
+ * predict codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = Pow2(int(d)+frac(d)) *
+ * = 2^exp + 2^frac *
+ * *
+ * gcode0 (Q14) = 2^14*2^frac = gc0 * 2^(14-exp) *
+ *-------------------------------------------------------------------*/
+
+ gc_pred(pred_state, mode, code, &exp, &frac, NULL, NULL, pOverflow);
+
+ gcode0 = (Word16) Pow2(14, frac, pOverflow);
+
+ /*------------------------------------------------------------------*
+ * read quantized gains, update table of past quantized energies *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * st->past_qua_en(Q10) = 20 * Log10(g_fac) / constant *
+ * = Log2(g_fac) *
+ * = qua_ener *
+ * constant = 20*Log10(2) *
+ *------------------------------------------------------------------*/
+
+ L_tmp = L_mult(g_code, gcode0, pOverflow);
+ temp1 = sub(10, exp, pOverflow);
+ L_tmp = L_shr(L_tmp, temp1, pOverflow);
+ *gain_cod = extract_h(L_tmp);
+
+ /* update table of past quantized energies */
+
+ gc_pred_update(pred_state, qua_ener_MR122, qua_ener);
+
+ return;
+}
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/dec/src/dec_gain.h b/media/codecs/amrnb/dec/src/dec_gain.h
new file mode 100644
index 0000000..b9c6a8d
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_gain.h
@@ -0,0 +1,127 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/dec_gain.h
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : dec_gain.h
+ Purpose : Decode the pitch and codebook gains
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _DEC_GAIN_H_
+#define _DEC_GAIN_H_
+#define dec_gain_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "gc_pred.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*
+ * FUNCTION: Dec_gain()
+ * PURPOSE: Decode the pitch and codebook gains
+ */
+ void Dec_gain(
+ gc_predState *pred_state, /* i/o: MA predictor state */
+ enum Mode mode, /* i : AMR mode */
+ Word16 index, /* i : index of quantization. */
+ Word16 code[], /* i : Innovative vector. */
+ Word16 evenSubfr, /* i : Flag for even subframes */
+ Word16 * gain_pit, /* o : Pitch gain. */
+ Word16 * gain_cod, /* o : Code gain. */
+ Flag * pOverflow
+ );
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _DEC_GAIN_H_ */
+
+
+
diff --git a/media/codecs/amrnb/dec/src/dec_input_format_tab.cpp b/media/codecs/amrnb/dec/src/dec_input_format_tab.cpp
new file mode 100644
index 0000000..fffbbfd
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_input_format_tab.cpp
@@ -0,0 +1,233 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+ Pathname: .audio/gsm-amr/c/src/dec_input_format_tab.c
+
+ Date: 03/01/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Renamed BytesThisFrame to WmfBytesPerFrame, changed its type
+ from 'const short' to 'const int'. Added If2BytesPerFrame
+ table for IF2 input format. Updated copyright year and I/O
+ definition sections, and added reference document for IF2.
+
+ Description: Renamed WmfBytesPerFrame to WmfDecBytesPerFrame, and
+ If2BytesPerFrame to If2DecBytesPerFrame.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This file contains the tables of the number of data bytes per codec mode in
+ both WMF and IF2 input formats.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] AMR Speech Codec Frame Structure, 3GPP TS 26.101 version 4.1.0 Release 4,
+ June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "amrdecode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ /* Table containing the number of core AMR data bytes for */
+ /* each codec mode for WMF input format(number excludes frame type byte) */
+ const Word16 WmfDecBytesPerFrame[16] =
+ {
+ 12, /* 4.75 */
+ 13, /* 5.15 */
+ 15, /* 5.90 */
+ 17, /* 6.70 */
+ 19, /* 7.40 */
+ 20, /* 7.95 */
+ 26, /* 10.2 */
+ 31, /* 12.2 */
+ 5, /* GsmAmr comfort noise */
+ 6, /* Gsm-Efr comfort noise */
+ 5, /* IS-641 comfort noise */
+ 5, /* Pdc-Efr comfort noise */
+ 0, /* future use */
+ 0, /* future use */
+ 0, /* future use */
+ 0 /* No transmission */
+ };
+
+ /* Table containing the number of core AMR data bytes for */
+ /* each codec mode for IF2 input format. */
+ const Word16 If2DecBytesPerFrame[16] =
+ {
+ 13, /* 4.75 */
+ 14, /* 5.15 */
+ 16, /* 5.90 */
+ 18, /* 6.70 */
+ 19, /* 7.40 */
+ 21, /* 7.95 */
+ 26, /* 10.2 */
+ 31, /* 12.2 */
+ 6, /* GsmAmr comfort noise */
+ 6, /* Gsm-Efr comfort noise */
+ 6, /* IS-641 comfort noise */
+ 6, /* Pdc-Efr comfort noise */
+ 0, /* future use */
+ 0, /* future use */
+ 0, /* future use */
+ 1 /* No transmission */
+ };
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
diff --git a/media/codecs/amrnb/dec/src/dec_lag3.cpp b/media/codecs/amrnb/dec/src/dec_lag3.cpp
new file mode 100644
index 0000000..70baaba
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_lag3.cpp
@@ -0,0 +1,407 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/dec_lag3.c
+ Functions: Dec_lag3
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ (1) Updated to accept new parameter, Flag *pOverflow.
+ (2) Placed file in the proper PV Software template.
+
+ Description:
+ (1) Removed "count.h" and "basic_op.h" and replaced with individual include
+ files (add.h, sub.h, etc.)
+
+ Description:
+ (1) Removed optimization -- mult(i, 3, pOverflow) is NOT the same as adding
+ i to itself 3 times. The reason is because the mult function does a
+ right shift by 15, which will obliterate smaller numbers.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ index -- Word16 -- received pitch index
+ t0_min -- Word16 -- minimum of search range
+ t0_max -- Word16 -- maximum of search range
+ i_subfr -- Word16 -- subframe flag
+ T0_prev -- Word16 -- integer pitch delay of last subframe
+ used in 2nd and 4th subframes
+ flag4 -- Word16 -- flag for encoding with 4 bits
+
+ Outputs:
+
+ T0 -- Pointer to type Word16 -- integer part of pitch lag
+ T0_frac -- Pointer to type Word16 -- fractional part of pitch lag
+ pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+
+ )
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Decoding of fractional pitch lag with 1/3 resolution.
+ Extract the integer and fraction parts of the pitch lag from
+ the received adaptive codebook index.
+
+ See "Enc_lag3.c" for more details about the encoding procedure.
+
+ The fractional lag in 1st and 3rd subframes is encoded with 8 bits
+ while that in 2nd and 4th subframes is relatively encoded with 4, 5
+ and 6 bits depending on the mode.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dec_lag3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "dec_lag3.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Dec_lag3(Word16 index, /* i : received pitch index */
+ Word16 t0_min, /* i : minimum of search range */
+ Word16 t0_max, /* i : maximum of search range */
+ Word16 i_subfr, /* i : subframe flag */
+ Word16 T0_prev, /* i : integer pitch delay of last subframe
+ used in 2nd and 4th subframes */
+ Word16 * T0, /* o : integer part of pitch lag */
+ Word16 * T0_frac, /* o : fractional part of pitch lag */
+ Word16 flag4, /* i : flag for encoding with 4 bits */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ )
+{
+ Word16 i;
+ Word16 tmp_lag;
+
+ if (i_subfr == 0) /* if 1st or 3rd subframe */
+ {
+
+ if (index < 197)
+ {
+
+ tmp_lag = index + 2;
+
+ tmp_lag =
+ mult(
+ tmp_lag,
+ 10923,
+ pOverflow);
+
+ i =
+ add(
+ tmp_lag,
+ 19,
+ pOverflow);
+
+ *T0 = i;
+
+ /* i = 3 * (*T0) */
+
+ i = add(i, i, pOverflow);
+ i = add(i, *T0, pOverflow);
+
+ tmp_lag =
+ sub(
+ index,
+ i,
+ pOverflow);
+
+ *T0_frac =
+ add(
+ tmp_lag,
+ 58,
+ pOverflow);
+ }
+ else
+ {
+ *T0 = index - 112;
+
+ *T0_frac = 0;
+ }
+
+ }
+ else
+ { /* 2nd or 4th subframe */
+
+ if (flag4 == 0)
+ {
+
+ /* 'normal' decoding: either with 5 or 6 bit resolution */
+
+ i =
+ add(
+ index,
+ 2,
+ pOverflow);
+
+ i =
+ mult(
+ i,
+ 10923,
+ pOverflow);
+
+ i =
+ sub(
+ i,
+ 1,
+ pOverflow);
+
+ *T0 =
+ add(
+ i,
+ t0_min,
+ pOverflow);
+
+ /* i = 3* (*T0) */
+ i = add(add(i, i, pOverflow), i, pOverflow);
+
+ tmp_lag =
+ sub(
+ index,
+ 2,
+ pOverflow);
+
+ *T0_frac =
+ sub(
+ tmp_lag,
+ i,
+ pOverflow);
+ }
+ else
+ {
+
+ /* decoding with 4 bit resolution */
+
+ tmp_lag = T0_prev;
+
+ i =
+ sub(
+ tmp_lag,
+ t0_min,
+ pOverflow);
+
+ if (i > 5)
+ {
+ tmp_lag =
+ add(
+ t0_min,
+ 5,
+ pOverflow);
+ }
+
+ i =
+ sub(
+ t0_max,
+ tmp_lag,
+ pOverflow);
+
+ if (i > 4)
+ {
+ tmp_lag =
+ sub(
+ t0_max,
+ 4,
+ pOverflow);
+ }
+
+ if (index < 4)
+ {
+ i =
+ sub(
+ tmp_lag,
+ 5,
+ pOverflow);
+
+ *T0 =
+ add(
+ i,
+ index,
+ pOverflow);
+
+ *T0_frac = 0;
+ }
+ else
+ {
+ /* 4 >= index < 12 */
+ if (index < 12)
+ {
+ i = index - 5;
+
+ i = mult(
+ i,
+ 10923,
+ pOverflow);
+
+ i--;
+
+ *T0 = add(
+ i,
+ tmp_lag,
+ pOverflow);
+
+ i = add(
+ add(
+ i,
+ i,
+ pOverflow),
+ i,
+ pOverflow);
+
+ tmp_lag = index - 9;
+
+ *T0_frac =
+ sub(
+ tmp_lag,
+ i,
+ pOverflow);
+ }
+ else
+ {
+ i = index - 12;
+
+ i =
+ add(
+ i,
+ tmp_lag,
+ pOverflow);
+
+ *T0 =
+ add(
+ i,
+ 1,
+ pOverflow);
+
+ *T0_frac = 0;
+ }
+ }
+
+ } /* end if (decoding with 4 bit resolution) */
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/dec_lag3.h b/media/codecs/amrnb/dec/src/dec_lag3.h
new file mode 100644
index 0000000..e758b92
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_lag3.h
@@ -0,0 +1,127 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/dec_lag3.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the dec_lag3.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef dec_lag3_h
+#define dec_lag3_h "$Id $"
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void Dec_lag3(Word16 index, /* i : received pitch index */
+ Word16 T0_min, /* i : minimum of search range */
+ Word16 T0_max, /* i : maximum of search range */
+ Word16 i_subfr, /* i : subframe flag */
+ Word16 T0_prev, /* i : integer pitch delay of last subframe
+ used in 2nd and 4th subframes */
+ Word16 * T0, /* o : integer part of pitch lag */
+ Word16 * T0_frac, /* o : fractional part of pitch lag */
+ Word16 flag4, /* i : flag for encoding with 4 bits */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _DEC_LAG_3_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/dec_lag6.cpp b/media/codecs/amrnb/dec/src/dec_lag6.cpp
new file mode 100644
index 0000000..7dc7a8d
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_lag6.cpp
@@ -0,0 +1,337 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/dec_lag6.c
+ Functions: Dec_lag6
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ (1) Updated to accept new parameter, Flag *pOverflow.
+ (2) Placed file in the proper PV Software template.
+
+ Description:
+ (1) Removed "count.h" and "basic_op.h" and replaced with individual include
+ files (add.h, sub.h, etc.)
+
+ Description:
+ (1) Removed optimization -- mult(i, 3, pOverflow) is NOT the same as adding
+ i to itself 3 times. The reason is because the mult function does a
+ right shift by 15, which will obliterate smaller numbers.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ index -- Word16 -- received pitch index
+ pit_min -- Word16 -- minimum pitch lag
+ pit_max -- Word16 -- maximum pitch lag
+ i_subfr -- Word16 -- subframe flag
+ T0 -- Pointer to type Word16 -- integer part of pitch lag
+
+ Outputs:
+
+ T0 -- Pointer to type Word16 -- integer part of pitch lag
+ T0_frac -- Pointer to type Word16 -- fractional part of pitch lag
+ pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Decoding of fractional pitch lag with 1/6 resolution.
+ Extract the integer and fraction parts of the pitch lag from
+ the received adaptive codebook index.
+
+ See "Enc_lag6.c" for more details about the encoding procedure.
+
+ The fractional lag in 1st and 3rd subframes is encoded with 9 bits
+ while that in 2nd and 4th subframes is relatively encoded with 6 bits.
+ Note that in relative encoding only 61 values are used. If the
+ decoder receives 61, 62, or 63 as the relative pitch index, it means
+ that a transmission error occurred. In this case, the pitch lag from
+ previous subframe (actually from previous frame) is used.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dec_lag6.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "dec_lag6.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Dec_lag6(
+ Word16 index, /* input : received pitch index */
+ Word16 pit_min, /* input : minimum pitch lag */
+ Word16 pit_max, /* input : maximum pitch lag */
+ Word16 i_subfr, /* input : subframe flag */
+ Word16 *T0, /* in/out: integer part of pitch lag */
+ Word16 *T0_frac, /* output: fractional part of pitch lag */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 T0_min;
+ Word16 T0_max;
+ Word16 k;
+ Word16 w;
+
+ if (i_subfr == 0) /* if 1st or 3rd subframe */
+ {
+ if (index < 463)
+ {
+ /* T0 = (index+5)/6 + 17 */
+ i = index + 5;
+ i =
+ mult(
+ i,
+ 5462,
+ pOverflow);
+
+ i =
+ add(
+ i,
+ 17,
+ pOverflow);
+
+ *T0 = i;
+
+ /* i = 3* (*T0) */
+
+ i = add(i, i, pOverflow);
+ i = add(i, *T0, pOverflow);
+
+ /* *T0_frac = index - T0*6 + 105 */
+
+ i =
+ add(
+ i,
+ i,
+ pOverflow);
+
+ i =
+ sub(
+ index,
+ i,
+ pOverflow);
+
+ *T0_frac =
+ add(
+ i,
+ 105,
+ pOverflow);
+ }
+ else
+ {
+ *T0 =
+ sub(
+ index,
+ 368,
+ pOverflow);
+
+ *T0_frac = 0;
+ }
+ }
+ else /* second or fourth subframe */
+ {
+ /* find T0_min and T0_max for 2nd (or 4th) subframe */
+
+ T0_min =
+ sub(
+ *T0,
+ 5,
+ pOverflow);
+
+ if (T0_min < pit_min)
+ {
+ T0_min = pit_min;
+ }
+
+ T0_max =
+ add(
+ T0_min,
+ 9,
+ pOverflow);
+
+ if (T0_max > pit_max)
+ {
+ T0_max = pit_max;
+
+ T0_min =
+ sub(
+ T0_max,
+ 9,
+ pOverflow);
+ }
+
+ /* i = (index+5)/6 - 1 */
+ i =
+ add(
+ index,
+ 5,
+ pOverflow);
+
+ i =
+ mult(
+ i,
+ 5462,
+ pOverflow);
+
+ i =
+ sub(
+ i,
+ 1,
+ pOverflow);
+
+ *T0 =
+ add(
+ i,
+ T0_min,
+ pOverflow);
+
+ /* i = 3* (*T0) */
+
+ w = add(i, i, pOverflow);
+ i = add(i, w, pOverflow);
+
+ i =
+ add(
+ i,
+ i,
+ pOverflow);
+
+ k =
+ sub(
+ index,
+ 3,
+ pOverflow);
+
+ *T0_frac =
+ sub(
+ k,
+ i,
+ pOverflow);
+ }
+}
diff --git a/media/codecs/amrnb/dec/src/dec_lag6.h b/media/codecs/amrnb/dec/src/dec_lag6.h
new file mode 100644
index 0000000..7322bc8
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dec_lag6.h
@@ -0,0 +1,124 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/dec_lag6.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the dec_lag6.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef dec_lag6_h
+#define dec_lag6_h "$Id $"
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void Dec_lag6(
+ Word16 index, /* input : received pitch index */
+ Word16 pit_min, /* input : minimum pitch lag */
+ Word16 pit_max, /* input : maximum pitch lag */
+ Word16 i_subfr, /* input : subframe flag */
+ Word16 *T0, /* in/out: integer part of pitch lag */
+ Word16 *T0_frac, /* output: fractional part of pitch lag */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _DEC_LAG_6_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/dtx_dec.cpp b/media/codecs/amrnb/dec/src/dtx_dec.cpp
new file mode 100644
index 0000000..9d04373
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dtx_dec.cpp
@@ -0,0 +1,1956 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/dtx_dec.c
+ Functions:
+ dtx_dec_reset
+ dtx_dec
+ dtx_dec_activity_update
+ rx_dtx_handler
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ These modules decode the comfort noise when in DTX.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "dtx_dec.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "copy.h"
+#include "set_zero.h"
+#include "mode.h"
+#include "log2.h"
+#include "lsp_az.h"
+#include "pow2.h"
+#include "a_refl.h"
+#include "b_cn_cod.h"
+#include "syn_filt.h"
+#include "lsp_lsf.h"
+#include "reorder.h"
+#include "lsp_tab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define PN_INITIAL_SEED 0x70816958L /* Pseudo noise generator seed value */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/***************************************************
+ * Scaling factors for the lsp variability operation *
+ ***************************************************/
+static const Word16 lsf_hist_mean_scale[M] =
+{
+ 20000,
+ 20000,
+ 20000,
+ 20000,
+ 20000,
+ 18000,
+ 16384,
+ 8192,
+ 0,
+ 0
+};
+
+/*************************************************
+ * level adjustment for different modes Q11 *
+ *************************************************/
+static const Word16 dtx_log_en_adjust[9] =
+{
+ -1023, /* MR475 */
+ -878, /* MR515 */
+ -732, /* MR59 */
+ -586, /* MR67 */
+ -440, /* MR74 */
+ -294, /* MR795 */
+ -148, /* MR102 */
+ 0, /* MR122 */
+ 0, /* MRDTX */
+};
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_dec_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type dtx_decState
+
+ Outputs:
+ Structure pointed to by st is initialized to a set of initial values.
+
+ Returns:
+ return_value = 0 if memory was successfully initialized,
+ otherwise returns -1 (int)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Reset of state memory for dtx_dec.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.3.0, December 12, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int dtx_dec_reset (dtx_decState *st)
+{
+ int i;
+
+ if (st == (dtx_decState *) NULL){
+ fprintf(stderr, "dtx_dec_reset: invalid parameter\n");
+ return -1;
+ }
+
+ st->since_last_sid = 0;
+ st->true_sid_period_inv = (1 << 13);
+
+ st->log_en = 3500;
+ st->old_log_en = 3500;
+ // low level noise for better performance in DTX handover cases
+
+ st->L_pn_seed_rx = PN_INITIAL_SEED;
+
+ // Initialize state->lsp [] and state->lsp_old []
+ Copy(lsp_init_data, &st->lsp[0], M);
+ Copy(lsp_init_data, &st->lsp_old[0], M);
+
+ st->lsf_hist_ptr = 0;
+ st->log_pg_mean = 0;
+ st->log_en_hist_ptr = 0;
+
+ // initialize decoder lsf history
+ Copy(mean_lsf, &st->lsf_hist[0], M);
+
+ for (i = 1; i < DTX_HIST_SIZE; i++)
+ {
+ Copy(&st->lsf_hist[0], &st->lsf_hist[M*i], M);
+ }
+ Set_zero(st->lsf_hist_mean, M*DTX_HIST_SIZE);
+
+ // initialize decoder log frame energy
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ st->log_en_hist[i] = st->log_en;
+ }
+
+ st->log_en_adjust = 0;
+
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ st->decAnaElapsedCount = 32767;
+
+ st->sid_frame = 0;
+ st->valid_data = 0;
+ st->dtxHangoverAdded = 0;
+
+ st->dtxGlobalState = DTX;
+ st->data_updated = 0;
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 dtx_dec_reset(dtx_decState *st)
+{
+ Word16 i;
+
+ if (st == (dtx_decState *) NULL)
+ {
+ /* fprint(stderr, "dtx_dec_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ st->since_last_sid = 0;
+ st->true_sid_period_inv = (1 << 13);
+
+ st->log_en = 3500;
+ st->old_log_en = 3500;
+ /* low level noise for better performance in DTX handover cases*/
+
+ st->L_pn_seed_rx = PN_INITIAL_SEED;
+
+ /* Initialize state->lsp [] */
+ st->lsp[0] = 30000;
+ st->lsp[1] = 26000;
+ st->lsp[2] = 21000;
+ st->lsp[3] = 15000;
+ st->lsp[4] = 8000;
+ st->lsp[5] = 0;
+ st->lsp[6] = -8000;
+ st->lsp[7] = -15000;
+ st->lsp[8] = -21000;
+ st->lsp[9] = -26000;
+
+ /* Initialize state->lsp_old [] */
+ st->lsp_old[0] = 30000;
+ st->lsp_old[1] = 26000;
+ st->lsp_old[2] = 21000;
+ st->lsp_old[3] = 15000;
+ st->lsp_old[4] = 8000;
+ st->lsp_old[5] = 0;
+ st->lsp_old[6] = -8000;
+ st->lsp_old[7] = -15000;
+ st->lsp_old[8] = -21000;
+ st->lsp_old[9] = -26000;
+
+ st->lsf_hist_ptr = 0;
+ st->log_pg_mean = 0;
+ st->log_en_hist_ptr = 0;
+
+ /* initialize decoder lsf history */
+ st->lsf_hist[0] = 1384;
+ st->lsf_hist[1] = 2077;
+ st->lsf_hist[2] = 3420;
+ st->lsf_hist[3] = 5108;
+ st->lsf_hist[4] = 6742;
+ st->lsf_hist[5] = 8122;
+ st->lsf_hist[6] = 9863;
+ st->lsf_hist[7] = 11092;
+ st->lsf_hist[8] = 12714;
+ st->lsf_hist[9] = 13701;
+
+ for (i = 1; i < DTX_HIST_SIZE; i++)
+ {
+ Copy(&st->lsf_hist[0], &st->lsf_hist[M*i], M);
+ }
+ memset(st->lsf_hist_mean, 0, sizeof(Word16)*M*DTX_HIST_SIZE);
+
+ /* initialize decoder log frame energy */
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ st->log_en_hist[i] = st->log_en;
+ }
+
+ st->log_en_adjust = 0;
+
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ st->decAnaElapsedCount = 32767;
+
+ st->sid_frame = 0;
+ st->valid_data = 0;
+ st->dtxHangoverAdded = 0;
+
+ st->dtxGlobalState = DTX;
+ st->data_updated = 0;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_dec
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type dtx_decState
+ mem_syn = AMR decoder state
+ lsfState = decoder lsf states
+ predState = prediction states
+ averState = CB gain average states
+ new_state = new DTX state
+ mode = AMR mode
+ parm = Vector of synthesis parameters
+
+ Outputs:
+ st points to an updated structure of type dtx_decState
+ mem_syn = AMR decoder state
+ lsfState = decoder lsf states
+ predState = prediction states
+ averState = CB gain average states
+ synth = synthesised speech
+ A_t = decoded LP filter in 4 subframes
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Decode comfort noise when in DTX.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.3.0, December 12, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int dtx_dec(
+ dtx_decState *st, // i/o : State struct
+ Word16 mem_syn[], // i/o : AMR decoder state
+ D_plsfState* lsfState, // i/o : decoder lsf states
+ gc_predState* predState, // i/o : prediction states
+ Cb_gain_averageState* averState, // i/o : CB gain average states
+ enum DTXStateType new_state, // i : new DTX state
+ enum Mode mode, // i : AMR mode
+ Word16 parm[], // i : Vector of synthesis parameters
+ Word16 synth[], // o : synthesised speech
+ Word16 A_t[] // o : decoded LP filter in 4 subframes
+ )
+{
+ Word16 log_en_index;
+ Word16 i, j;
+ Word16 int_fac;
+ Word32 L_log_en_int;
+ Word16 lsp_int[M];
+ Word16 log_en_int_e;
+ Word16 log_en_int_m;
+ Word16 level;
+ Word16 acoeff[M + 1];
+ Word16 refl[M];
+ Word16 pred_err;
+ Word16 ex[L_SUBFR];
+ Word16 ma_pred_init;
+ Word16 log_pg_e, log_pg_m;
+ Word16 log_pg;
+ Flag negative;
+ Word16 lsf_mean;
+ Word32 L_lsf_mean;
+ Word16 lsf_variab_index;
+ Word16 lsf_variab_factor;
+ Word16 lsf_int[M];
+ Word16 lsf_int_variab[M];
+ Word16 lsp_int_variab[M];
+ Word16 acoeff_variab[M + 1];
+
+ Word16 lsf[M];
+ Word32 L_lsf[M];
+ Word16 ptr;
+ Word16 tmp_int_length;
+
+
+ // This function is called if synthesis state is not SPEECH
+ // the globally passed inputs to this function are
+ // st->sid_frame
+ // st->valid_data
+ // st->dtxHangoverAdded
+ // new_state (SPEECH, DTX, DTX_MUTE)
+
+ if ((st->dtxHangoverAdded != 0) &&
+ (st->sid_frame != 0))
+ {
+ // sid_first after dtx hangover period
+ // or sid_upd after dtxhangover
+
+ // set log_en_adjust to correct value
+ st->log_en_adjust = dtx_log_en_adjust[mode];
+
+ ptr = add(st->lsf_hist_ptr, M);
+ if (sub(ptr, 80) == 0)
+ {
+ ptr = 0;
+ }
+ Copy( &st->lsf_hist[st->lsf_hist_ptr],&st->lsf_hist[ptr],M);
+
+ ptr = add(st->log_en_hist_ptr,1);
+ if (sub(ptr, DTX_HIST_SIZE) == 0)
+ {
+ ptr = 0;
+ }
+ st->log_en_hist[ptr] = st->log_en_hist[st->log_en_hist_ptr]; // Q11
+
+ // compute mean log energy and lsp
+ // from decoded signal (SID_FIRST)
+ st->log_en = 0;
+ for (i = 0; i < M; i++)
+ {
+ L_lsf[i] = 0;
+ }
+
+ // average energy and lsp
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ st->log_en = add(st->log_en,
+ shr(st->log_en_hist[i],3));
+ for (j = 0; j < M; j++)
+ {
+ L_lsf[j] = L_add(L_lsf[j],
+ L_deposit_l(st->lsf_hist[i * M + j]));
+ }
+ }
+
+ for (j = 0; j < M; j++)
+ {
+ lsf[j] = extract_l(L_shr(L_lsf[j],3)); // divide by 8
+ }
+
+ Lsf_lsp(lsf, st->lsp, M);
+
+ // make log_en speech coder mode independent
+ // added again later before synthesis
+ st->log_en = sub(st->log_en, st->log_en_adjust);
+
+ // compute lsf variability vector
+ Copy(st->lsf_hist, st->lsf_hist_mean, 80);
+
+ for (i = 0; i < M; i++)
+ {
+ L_lsf_mean = 0;
+ // compute mean lsf
+ for (j = 0; j < 8; j++)
+ {
+ L_lsf_mean = L_add(L_lsf_mean,
+ L_deposit_l(st->lsf_hist_mean[i+j*M]));
+ }
+
+ lsf_mean = extract_l(L_shr(L_lsf_mean, 3));
+ // subtract mean and limit to within reasonable limits
+ // moreover the upper lsf's are attenuated
+ for (j = 0; j < 8; j++)
+ {
+ // subtract mean
+ st->lsf_hist_mean[i+j*M] =
+ sub(st->lsf_hist_mean[i+j*M], lsf_mean);
+
+ // attenuate deviation from mean, especially for upper lsf's
+ st->lsf_hist_mean[i+j*M] =
+ mult(st->lsf_hist_mean[i+j*M], lsf_hist_mean_scale[i]);
+
+ // limit the deviation
+ if (st->lsf_hist_mean[i+j*M] < 0)
+ {
+ negative = 1;
+ }
+ else
+ {
+ negative = 0;
+ }
+ st->lsf_hist_mean[i+j*M] = abs_s(st->lsf_hist_mean[i+j*M]);
+
+ // apply soft limit
+ if (sub(st->lsf_hist_mean[i+j*M], 655) > 0)
+ {
+ st->lsf_hist_mean[i+j*M] =
+ add(655, shr(sub(st->lsf_hist_mean[i+j*M], 655), 2));
+ }
+
+ // apply hard limit
+ if (sub(st->lsf_hist_mean[i+j*M], 1310) > 0)
+ {
+ st->lsf_hist_mean[i+j*M] = 1310;
+ }
+ if (negative != 0)
+ {
+ st->lsf_hist_mean[i+j*M] = -st->lsf_hist_mean[i+j*M];
+ }
+
+ }
+ }
+ }
+
+ if (st->sid_frame != 0 )
+ {
+ // Set old SID parameters, always shift
+ // even if there is no new valid_data
+ Copy(st->lsp, st->lsp_old, M);
+ st->old_log_en = st->log_en;
+
+ if (st->valid_data != 0 ) // new data available (no CRC)
+ {
+ // Compute interpolation factor, since the division only works
+ // for values of since_last_sid < 32 we have to limit the
+ // interpolation to 32 frames
+ tmp_int_length = st->since_last_sid;
+ st->since_last_sid = 0;
+
+ if (sub(tmp_int_length, 32) > 0)
+ {
+ tmp_int_length = 32;
+ }
+ if (sub(tmp_int_length, 2) >= 0)
+ {
+ st->true_sid_period_inv = div_s(1 << 10, shl(tmp_int_length, 10));
+ }
+ else
+ {
+ st->true_sid_period_inv = 1 << 14; // 0.5 it Q15
+ }
+
+ Init_D_plsf_3(lsfState, parm[0]); // temporay initialization
+ D_plsf_3(lsfState, MRDTX, 0, &parm[1], st->lsp);
+ Set_zero(lsfState->past_r_q, M); // reset for next speech frame
+
+ log_en_index = parm[4];
+ // Q11 and divide by 4
+ st->log_en = shl(log_en_index, (11 - 2));
+
+ // Subtract 2.5 in Q11
+ st->log_en = sub(st->log_en, (2560 * 2));
+
+ // Index 0 is reserved for silence
+ if (log_en_index == 0)
+ {
+ st->log_en = MIN_16;
+ }
+
+ // no interpolation at startup after coder reset
+ // or when SID_UPD has been received right after SPEECH
+ if ((st->data_updated == 0) ||
+ (sub(st->dtxGlobalState, SPEECH) == 0)
+ )
+ {
+ Copy(st->lsp, st->lsp_old, M);
+ st->old_log_en = st->log_en;
+ }
+ } // endif valid_data
+
+ // initialize gain predictor memory of other modes
+ ma_pred_init = sub(shr(st->log_en,1), 9000);
+ if (ma_pred_init > 0)
+ {
+ ma_pred_init = 0;
+ }
+ if (sub(ma_pred_init, -14436) < 0)
+ {
+ ma_pred_init = -14436;
+ }
+
+ predState->past_qua_en[0] = ma_pred_init;
+ predState->past_qua_en[1] = ma_pred_init;
+ predState->past_qua_en[2] = ma_pred_init;
+ predState->past_qua_en[3] = ma_pred_init;
+
+ // past_qua_en for other modes than MR122
+ ma_pred_init = mult(5443, ma_pred_init);
+ // scale down by factor 20*log10(2) in Q15
+ predState->past_qua_en_MR122[0] = ma_pred_init;
+ predState->past_qua_en_MR122[1] = ma_pred_init;
+ predState->past_qua_en_MR122[2] = ma_pred_init;
+ predState->past_qua_en_MR122[3] = ma_pred_init;
+ } // endif sid_frame
+
+ // CN generation
+ // recompute level adjustment factor Q11
+ // st->log_en_adjust = 0.9*st->log_en_adjust +
+ // 0.1*dtx_log_en_adjust[mode]);
+ st->log_en_adjust = add(mult(st->log_en_adjust, 29491),
+ shr(mult(shl(dtx_log_en_adjust[mode],5),3277),5));
+
+ // Interpolate SID info
+ int_fac = shl(add(1,st->since_last_sid), 10); // Q10
+ int_fac = mult(int_fac, st->true_sid_period_inv); // Q10 * Q15 -> Q10
+
+ // Maximize to 1.0 in Q10
+ if (sub(int_fac, 1024) > 0)
+ {
+ int_fac = 1024;
+ }
+ int_fac = shl(int_fac, 4); // Q10 -> Q14
+
+ L_log_en_int = L_mult(int_fac, st->log_en); // Q14 * Q11->Q26
+ for(i = 0; i < M; i++)
+ {
+ lsp_int[i] = mult(int_fac, st->lsp[i]);// Q14 * Q15 -> Q14
+ }
+
+ int_fac = sub(16384, int_fac); // 1-k in Q14
+
+ // (Q14 * Q11 -> Q26) + Q26 -> Q26
+ L_log_en_int = L_mac(L_log_en_int, int_fac, st->old_log_en);
+ for(i = 0; i < M; i++)
+ {
+ // Q14 + (Q14 * Q15 -> Q14) -> Q14
+ lsp_int[i] = add(lsp_int[i], mult(int_fac, st->lsp_old[i]));
+ lsp_int[i] = shl(lsp_int[i], 1); // Q14 -> Q15
+ }
+
+ // compute the amount of lsf variability
+ lsf_variab_factor = sub(st->log_pg_mean,2457); // -0.6 in Q12
+ // *0.3 Q12*Q15 -> Q12
+ lsf_variab_factor = sub(4096, mult(lsf_variab_factor, 9830));
+
+ // limit to values between 0..1 in Q12
+ if (sub(lsf_variab_factor, 4096) > 0)
+ {
+ lsf_variab_factor = 4096;
+ }
+ if (lsf_variab_factor < 0)
+ {
+ lsf_variab_factor = 0;
+ }
+ lsf_variab_factor = shl(lsf_variab_factor, 3); // -> Q15
+
+ // get index of vector to do variability with
+ lsf_variab_index = pseudonoise(&st->L_pn_seed_rx, 3);
+
+ // convert to lsf
+ Lsp_lsf(lsp_int, lsf_int, M);
+
+ // apply lsf variability
+ Copy(lsf_int, lsf_int_variab, M);
+ for(i = 0; i < M; i++)
+ {
+ lsf_int_variab[i] = add(lsf_int_variab[i],
+ mult(lsf_variab_factor,
+ st->lsf_hist_mean[i+lsf_variab_index*M]));
+ }
+
+ // make sure that LSP's are ordered
+ Reorder_lsf(lsf_int, LSF_GAP, M);
+ Reorder_lsf(lsf_int_variab, LSF_GAP, M);
+
+ // copy lsf to speech decoders lsf state
+ Copy(lsf_int, lsfState->past_lsf_q, M);
+
+ // convert to lsp
+ Lsf_lsp(lsf_int, lsp_int, M);
+ Lsf_lsp(lsf_int_variab, lsp_int_variab, M);
+
+ // Compute acoeffs Q12 acoeff is used for level
+ // normalization and postfilter, acoeff_variab is
+ // used for synthesis filter
+ // by doing this we make sure that the level
+ // in high frequenncies does not jump up and down
+
+ Lsp_Az(lsp_int, acoeff);
+ Lsp_Az(lsp_int_variab, acoeff_variab);
+
+ // For use in postfilter
+ Copy(acoeff, &A_t[0], M + 1);
+ Copy(acoeff, &A_t[M + 1], M + 1);
+ Copy(acoeff, &A_t[2 * (M + 1)], M + 1);
+ Copy(acoeff, &A_t[3 * (M + 1)], M + 1);
+
+ // Compute reflection coefficients Q15
+ A_Refl(&acoeff[1], refl);
+
+ // Compute prediction error in Q15
+ pred_err = MAX_16; // 0.99997 in Q15
+ for (i = 0; i < M; i++)
+ {
+ pred_err = mult(pred_err, sub(MAX_16, mult(refl[i], refl[i])));
+ }
+
+ // compute logarithm of prediction gain
+ Log2(L_deposit_l(pred_err), &log_pg_e, &log_pg_m);
+
+ // convert exponent and mantissa to Word16 Q12
+ log_pg = shl(sub(log_pg_e,15), 12); // Q12
+ log_pg = shr(sub(0,add(log_pg, shr(log_pg_m, 15-12))), 1);
+ st->log_pg_mean = add(mult(29491,st->log_pg_mean),
+ mult(3277, log_pg));
+
+ // Compute interpolated log energy
+ L_log_en_int = L_shr(L_log_en_int, 10); // Q26 -> Q16
+
+ // Add 4 in Q16
+ L_log_en_int = L_add(L_log_en_int, 4 * 65536L);
+
+ // subtract prediction gain
+ L_log_en_int = L_sub(L_log_en_int, L_shl(L_deposit_l(log_pg), 4));
+
+ // adjust level to speech coder mode
+ L_log_en_int = L_add(L_log_en_int,
+ L_shl(L_deposit_l(st->log_en_adjust), 5));
+
+ log_en_int_e = extract_h(L_log_en_int);
+ log_en_int_m = extract_l(L_shr(L_sub(L_log_en_int,
+ L_deposit_h(log_en_int_e)), 1));
+ level = extract_l(Pow2(log_en_int_e, log_en_int_m)); // Q4
+
+ for (i = 0; i < 4; i++)
+ {
+ // Compute innovation vector
+ build_CN_code(&st->L_pn_seed_rx, ex);
+ for (j = 0; j < L_SUBFR; j++)
+ {
+ ex[j] = mult(level, ex[j]);
+ }
+ // Synthesize
+ Syn_filt(acoeff_variab, ex, &synth[i * L_SUBFR], L_SUBFR,
+ mem_syn, 1);
+
+ } // next i
+
+ // reset codebook averaging variables
+ averState->hangVar = 20;
+ averState->hangCount = 0;
+
+ if (sub(new_state, DTX_MUTE) == 0)
+ {
+ // mute comfort noise as it has been quite a long time since
+ * last SID update was performed
+
+ tmp_int_length = st->since_last_sid;
+ if (sub(tmp_int_length, 32) > 0)
+ {
+ tmp_int_length = 32;
+ }
+
+ // safety guard against division by zero
+ if(tmp_int_length <= 0) {
+ tmp_int_length = 8;
+ }
+
+ st->true_sid_period_inv = div_s(1 << 10, shl(tmp_int_length, 10));
+
+ st->since_last_sid = 0;
+ Copy(st->lsp, st->lsp_old, M);
+ st->old_log_en = st->log_en;
+ // subtract 1/8 in Q11 i.e -6/8 dB
+ st->log_en = sub(st->log_en, 256);
+ }
+
+ // reset interpolation length timer
+ // if data has been updated.
+ if ((st->sid_frame != 0) &&
+ ((st->valid_data != 0) ||
+ ((st->valid_data == 0) && (st->dtxHangoverAdded) != 0)))
+ {
+ st->since_last_sid = 0;
+ st->data_updated = 1;
+ }
+
+ return 0;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void dtx_dec(
+ dtx_decState *st, /* i/o : State struct */
+ Word16 mem_syn[], /* i/o : AMR decoder state */
+ D_plsfState* lsfState, /* i/o : decoder lsf states */
+ gc_predState* predState, /* i/o : prediction states */
+ Cb_gain_averageState* averState, /* i/o : CB gain average states */
+ enum DTXStateType new_state, /* i : new DTX state */
+ enum Mode mode, /* i : AMR mode */
+ Word16 parm[], /* i : Vector of synthesis parameters */
+ Word16 synth[], /* o : synthesised speech */
+ Word16 A_t[], /* o : decoded LP filter in 4 subframes*/
+ Flag *pOverflow
+)
+{
+ Word16 log_en_index;
+ Word16 i;
+ Word16 j;
+ Word16 int_fac;
+ Word32 L_log_en_int;
+ Word16 lsp_int[M];
+ Word16 log_en_int_e;
+ Word16 log_en_int_m;
+ Word16 level;
+ Word16 acoeff[M + 1];
+ Word16 refl[M];
+ Word16 pred_err;
+ Word16 ex[L_SUBFR];
+ Word16 ma_pred_init;
+ Word16 log_pg_e;
+ Word16 log_pg_m;
+ Word16 log_pg;
+ Flag negative;
+ Word16 lsf_mean;
+ Word32 L_lsf_mean;
+ Word16 lsf_variab_index;
+ Word16 lsf_variab_factor;
+ Word16 lsf_int[M];
+ Word16 lsf_int_variab[M];
+ Word16 lsp_int_variab[M];
+ Word16 acoeff_variab[M + 1];
+
+ Word16 lsf[M];
+ Word32 L_lsf[M];
+ Word16 ptr;
+ Word16 tmp_int_length;
+
+ Word32 L_temp;
+ Word16 temp;
+
+ /* This function is called if synthesis state is not SPEECH
+ * the globally passed inputs to this function are
+ * st->sid_frame
+ * st->valid_data
+ * st->dtxHangoverAdded
+ * new_state (SPEECH, DTX, DTX_MUTE)
+ */
+
+ if ((st->dtxHangoverAdded != 0) &&
+ (st->sid_frame != 0))
+ {
+ /* sid_first after dtx hangover period */
+ /* or sid_upd after dtxhangover */
+
+ /* set log_en_adjust to correct value */
+ st->log_en_adjust = dtx_log_en_adjust[mode];
+
+ ptr = st->lsf_hist_ptr + M;
+
+ if (ptr == 80)
+ {
+ ptr = 0;
+ }
+ Copy(&st->lsf_hist[st->lsf_hist_ptr], &st->lsf_hist[ptr], M);
+
+ ptr = st->log_en_hist_ptr + 1;
+
+ if (ptr == DTX_HIST_SIZE)
+ {
+ ptr = 0;
+ }
+
+ st->log_en_hist[ptr] = st->log_en_hist[st->log_en_hist_ptr]; /* Q11 */
+
+ /* compute mean log energy and lsp *
+ * from decoded signal (SID_FIRST) */
+ st->log_en = 0;
+ for (i = M - 1; i >= 0; i--)
+ {
+ L_lsf[i] = 0;
+ }
+
+ /* average energy and lsp */
+ for (i = DTX_HIST_SIZE - 1; i >= 0; i--)
+ {
+ if (st->log_en_hist[i] < 0)
+ {
+ temp = ~((~st->log_en_hist[i]) >> 3);
+ }
+ else
+ {
+ temp = st->log_en_hist[i] >> 3;
+ }
+ st->log_en = add(st->log_en, temp, pOverflow);
+ for (j = M - 1; j >= 0; j--)
+ {
+ L_lsf[j] = L_add(L_lsf[j],
+ L_deposit_l(st->lsf_hist[i * M + j]), pOverflow);
+ }
+ }
+
+ for (j = M - 1; j >= 0; j--)
+ {
+ if (L_lsf[j] < 0)
+ {
+ lsf[j] = (Word16)(~((~L_lsf[j]) >> 3));
+ }
+ else
+ {
+ lsf[j] = (Word16)(L_lsf[j] >> 3);
+ }
+ }
+
+ Lsf_lsp(lsf, st->lsp, M, pOverflow);
+
+ /* make log_en speech coder mode independent */
+ /* added again later before synthesis */
+ st->log_en = sub(st->log_en, st->log_en_adjust, pOverflow);
+
+ /* compute lsf variability vector */
+ Copy(st->lsf_hist, st->lsf_hist_mean, 80);
+
+ for (i = M - 1; i >= 0; i--)
+ {
+ L_lsf_mean = 0;
+ /* compute mean lsf */
+ for (j = 8 - 1; j >= 0; j--)
+ {
+ L_lsf_mean = L_add(L_lsf_mean,
+ L_deposit_l(st->lsf_hist_mean[i+j*M]), pOverflow);
+ }
+
+ if (L_lsf_mean < 0)
+ {
+ lsf_mean = (Word16)(~((~L_lsf_mean) >> 3));
+ }
+ else
+ {
+ lsf_mean = (Word16)(L_lsf_mean >> 3);
+ }
+ /* subtract mean and limit to within reasonable limits *
+ * moreover the upper lsf's are attenuated */
+ for (j = 8 - 1; j >= 0; j--)
+ {
+ /* subtract mean */
+ st->lsf_hist_mean[i+j*M] =
+ sub(st->lsf_hist_mean[i+j*M], lsf_mean, pOverflow);
+
+ /* attenuate deviation from mean, especially for upper lsf's */
+ st->lsf_hist_mean[i+j*M] =
+ mult(st->lsf_hist_mean[i+j*M], lsf_hist_mean_scale[i], pOverflow);
+
+ /* limit the deviation */
+ if (st->lsf_hist_mean[i+j*M] < 0)
+ {
+ negative = 1;
+ }
+ else
+ {
+ negative = 0;
+ }
+ st->lsf_hist_mean[i+j*M] = abs_s(st->lsf_hist_mean[i+j*M]);
+
+ /* apply soft limit */
+ if (st->lsf_hist_mean[i+j*M] > 655)
+ {
+ st->lsf_hist_mean[i+j*M] = 655 + ((st->lsf_hist_mean[i+j*M]
+ - 655) >> 2);
+ }
+
+ /* apply hard limit */
+ if (st->lsf_hist_mean[i+j*M] > 1310)
+ {
+ st->lsf_hist_mean[i+j*M] = 1310;
+ }
+
+ if (negative != 0)
+ {
+ st->lsf_hist_mean[i+j*M] = -st->lsf_hist_mean[i+j*M];
+ }
+ }
+ }
+ }
+
+
+ if (st->sid_frame != 0)
+ {
+ /* Set old SID parameters, always shift */
+ /* even if there is no new valid_data */
+ Copy(st->lsp, st->lsp_old, M);
+ st->old_log_en = st->log_en;
+
+ if (st->valid_data != 0) /* new data available (no CRC) */
+ {
+ /* Compute interpolation factor, since the division only works *
+ * for values of since_last_sid < 32 we have to limit the *
+ * interpolation to 32 frames */
+ tmp_int_length = st->since_last_sid;
+ st->since_last_sid = 0;
+
+ if (tmp_int_length >= 32)
+ {
+ tmp_int_length = 32;
+ }
+
+ L_temp = ((Word32) tmp_int_length) << 10;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *pOverflow = 1;
+ L_temp = (Word32)((tmp_int_length > 0) ? MAX_16 : MIN_16);
+ }
+ temp = (Word16) L_temp;
+
+ if (tmp_int_length >= 2)
+ {
+ st->true_sid_period_inv = div_s(1 << 10, temp);
+ }
+ else
+ {
+ st->true_sid_period_inv = 1 << 14; /* 0.5 it Q15 */
+ }
+
+ Init_D_plsf_3(lsfState, parm[0]);
+ D_plsf_3(lsfState, MRDTX, 0, &parm[1], st->lsp, pOverflow);
+ Set_zero(lsfState->past_r_q, M); /* reset for next speech frame */
+
+ log_en_index = parm[4];
+ /* Q11 and divide by 4 */
+ if ((log_en_index > 63) || (log_en_index < -64))
+ {
+ st->log_en = (log_en_index > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ st->log_en = (log_en_index) << (11 - 2);
+ }
+
+ /* Subtract 2.5 in Q11 */
+ st->log_en = sub(st->log_en, (2560 * 2), pOverflow);
+
+ /* Index 0 is reserved for silence */
+ if (log_en_index == 0)
+ {
+ st->log_en = MIN_16;
+ }
+
+ /* no interpolation at startup after coder reset */
+ /* or when SID_UPD has been received right after SPEECH */
+
+ if ((st->data_updated == 0) ||
+ (st->dtxGlobalState == SPEECH))
+ {
+ Copy(st->lsp, st->lsp_old, M);
+ st->old_log_en = st->log_en;
+ }
+ } /* endif valid_data */
+
+ /* initialize gain predictor memory of other modes */
+ if (st->log_en < 0)
+ {
+ temp = ~((~st->log_en) >> 1);
+ }
+ else
+ {
+ temp = st->log_en >> 1;
+ }
+ ma_pred_init = sub(temp, 9000, pOverflow);
+
+ if (ma_pred_init > 0)
+ {
+ ma_pred_init = 0;
+ }
+ else if (ma_pred_init < -14436)
+ {
+ ma_pred_init = -14436;
+ }
+
+ predState->past_qua_en[0] = ma_pred_init;
+ predState->past_qua_en[1] = ma_pred_init;
+ predState->past_qua_en[2] = ma_pred_init;
+ predState->past_qua_en[3] = ma_pred_init;
+
+ /* past_qua_en for other modes than MR122 */
+ ma_pred_init = mult(5443, ma_pred_init, pOverflow);
+ /* scale down by factor 20*log10(2) in Q15 */
+ predState->past_qua_en_MR122[0] = ma_pred_init;
+ predState->past_qua_en_MR122[1] = ma_pred_init;
+ predState->past_qua_en_MR122[2] = ma_pred_init;
+ predState->past_qua_en_MR122[3] = ma_pred_init;
+ } /* endif sid_frame */
+
+ /* CN generation */
+ /* recompute level adjustment factor Q11 *
+ * st->log_en_adjust = 0.9*st->log_en_adjust + *
+ * 0.1*dtx_log_en_adjust[mode]); */
+ if (dtx_log_en_adjust[mode] > 1023)
+ {
+ temp = MAX_16;
+ }
+ else if (dtx_log_en_adjust[mode] < -1024)
+ {
+ temp = MIN_16;
+ }
+ else
+ {
+ temp = mult((Word16)((Word32)dtx_log_en_adjust[mode] << 5), 3277, pOverflow);
+ }
+
+ if (temp < 0)
+ {
+ temp = ~((~temp) >> 5);
+ }
+ else
+ {
+ temp >>= 5;
+ }
+ st->log_en_adjust = add(mult(st->log_en_adjust, 29491, pOverflow), temp, pOverflow);
+
+ /* Interpolate SID info */
+ int_fac = shl(add(1, st->since_last_sid, pOverflow), 10, pOverflow); /* Q10 */
+ int_fac = mult(int_fac, st->true_sid_period_inv, pOverflow); /* Q10 * Q15 -> Q10 */
+
+ /* Maximize to 1.0 in Q10 */
+ if (int_fac > 1024)
+ {
+ int_fac = 16384;
+ }
+ else if (int_fac < -2048)
+ {
+ int_fac = MIN_16;
+ }
+ else
+ {
+ int_fac <<= 4; /* Q10 -> Q14 */
+ }
+
+ L_log_en_int = L_mult(int_fac, st->log_en, pOverflow); /* Q14 * Q11->Q26 */
+ for (i = M - 1; i >= 0; i--)
+ {
+ lsp_int[i] = mult(int_fac, st->lsp[i], pOverflow);/* Q14 * Q15 -> Q14 */
+ }
+
+ int_fac = sub(16384, int_fac, pOverflow); /* 1-k in Q14 */
+
+ /* (Q14 * Q11 -> Q26) + Q26 -> Q26 */
+ L_log_en_int = L_mac(L_log_en_int, int_fac, st->old_log_en, pOverflow);
+ for (i = M - 1; i >= 0; i--)
+ {
+ /* Q14 + (Q14 * Q15 -> Q14) -> Q14 */
+ lsp_int[i] = add(lsp_int[i], mult(int_fac, st->lsp_old[i], pOverflow), pOverflow);
+
+ L_temp = ((Word32) lsp_int[i]) << 1; /* Q14 -> Q15 */
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *pOverflow = 1;
+ L_temp = (Word32)((lsp_int[i] > 0) ? MAX_16 : MIN_16);
+ }
+ lsp_int[i] = (Word16) L_temp;
+ }
+
+ /* compute the amount of lsf variability */
+ lsf_variab_factor = sub(st->log_pg_mean, 2457, pOverflow); /* -0.6 in Q12 */
+ /* *0.3 Q12*Q15 -> Q12 */
+ lsf_variab_factor = sub(4096, mult(lsf_variab_factor, 9830, pOverflow), pOverflow);
+
+ /* limit to values between 0..1 in Q12 */
+ if (lsf_variab_factor > 4095)
+ {
+ lsf_variab_factor = MAX_16;
+ }
+ else if (lsf_variab_factor < 0)
+ {
+ lsf_variab_factor = 0;
+ }
+ else
+ {
+ lsf_variab_factor <<= 3; /* -> Q15 */
+ }
+
+ /* get index of vector to do variability with */
+ lsf_variab_index = pseudonoise(&st->L_pn_seed_rx, 3);
+
+ /* convert to lsf */
+ Lsp_lsf(lsp_int, lsf_int, M, pOverflow);
+
+ /* apply lsf variability */
+ Copy(lsf_int, lsf_int_variab, M);
+ for (i = M - 1; i >= 0; i--)
+ {
+ lsf_int_variab[i] = add(lsf_int_variab[i],
+ mult(lsf_variab_factor,
+ st->lsf_hist_mean[i+lsf_variab_index*M], pOverflow)
+ , pOverflow);
+ }
+
+ /* make sure that LSP's are ordered */
+ Reorder_lsf(lsf_int, LSF_GAP, M, pOverflow);
+ Reorder_lsf(lsf_int_variab, LSF_GAP, M, pOverflow);
+
+ /* copy lsf to speech decoders lsf state */
+ Copy(lsf_int, lsfState->past_lsf_q, M);
+
+ /* convert to lsp */
+ Lsf_lsp(lsf_int, lsp_int, M, pOverflow);
+ Lsf_lsp(lsf_int_variab, lsp_int_variab, M, pOverflow);
+
+ /* Compute acoeffs Q12 acoeff is used for level *
+ * normalization and postfilter, acoeff_variab is *
+ * used for synthesis filter *
+ * by doing this we make sure that the level *
+ * in high frequenncies does not jump up and down */
+
+ Lsp_Az(lsp_int, acoeff, pOverflow);
+ Lsp_Az(lsp_int_variab, acoeff_variab, pOverflow);
+
+ /* For use in postfilter */
+ Copy(acoeff, &A_t[0], M + 1);
+ Copy(acoeff, &A_t[M + 1], M + 1);
+ Copy(acoeff, &A_t[2 *(M + 1)], M + 1);
+ Copy(acoeff, &A_t[3 *(M + 1)], M + 1);
+
+ /* Compute reflection coefficients Q15 */
+ A_Refl(&acoeff[1], refl, pOverflow);
+
+ /* Compute prediction error in Q15 */
+ pred_err = MAX_16; /* 0.99997 in Q15 */
+ for (i = 0; i < M; i++)
+ {
+ L_temp = (((Word32) refl[i]) * refl[i]) >> 15;
+ if (L_temp <= 0x00007fffL)
+ {
+ temp = MAX_16 - (Word16) L_temp;
+ }
+ else
+ {
+ *pOverflow = 1;
+ temp = 0;
+ }
+ pred_err = mult(pred_err, temp, pOverflow);
+ }
+
+ /* compute logarithm of prediction gain */
+ Log2(L_deposit_l(pred_err), &log_pg_e, &log_pg_m, pOverflow);
+
+ /* convert exponent and mantissa to Word16 Q12 */
+ log_pg = shl(sub(log_pg_e, 15, pOverflow), 12, pOverflow); /* Q12 */
+ log_pg = shr(sub(0, add(log_pg, shr(log_pg_m, 15 - 12, pOverflow),
+ pOverflow), pOverflow), 1, pOverflow);
+ st->log_pg_mean = add(mult(29491, st->log_pg_mean, pOverflow),
+ mult(3277, log_pg, pOverflow), pOverflow);
+
+ /* Compute interpolated log energy */
+ L_log_en_int = L_shr(L_log_en_int, 10, pOverflow); /* Q26 -> Q16 */
+
+ /* Add 4 in Q16 */
+ L_log_en_int = L_add(L_log_en_int, 4 * 65536L, pOverflow);
+
+ /* subtract prediction gain */
+ L_log_en_int = L_sub(L_log_en_int, L_shl(L_deposit_l(log_pg), 4, pOverflow), pOverflow);
+
+ /* adjust level to speech coder mode */
+ L_log_en_int = L_add(L_log_en_int,
+ L_shl(L_deposit_l(st->log_en_adjust), 5, pOverflow), pOverflow);
+
+ log_en_int_e = (Word16)(L_log_en_int >> 16);
+
+ log_en_int_m = (Word16)(L_shr(L_sub(L_log_en_int,
+ L_deposit_h(log_en_int_e), pOverflow), 1, pOverflow));
+ level = (Word16)(Pow2(log_en_int_e, log_en_int_m, pOverflow)); /* Q4 */
+
+ for (i = 0; i < 4; i++)
+ {
+ /* Compute innovation vector */
+ build_CN_code(&st->L_pn_seed_rx, ex, pOverflow);
+ for (j = L_SUBFR - 1; j >= 0; j--)
+ {
+ ex[j] = mult(level, ex[j], pOverflow);
+ }
+ /* Synthesize */
+ Syn_filt(acoeff_variab, ex, &synth[i * L_SUBFR], L_SUBFR,
+ mem_syn, 1);
+
+ } /* next i */
+
+ /* reset codebook averaging variables */
+ averState->hangVar = 20;
+ averState->hangCount = 0;
+
+ if (new_state == DTX_MUTE)
+ {
+ /* mute comfort noise as it has been quite a long time since
+ * last SID update was performed */
+
+ tmp_int_length = st->since_last_sid;
+
+ if (tmp_int_length > 32)
+ {
+ tmp_int_length = 32;
+ }
+ else if (tmp_int_length <= 0)
+ {
+ /* safety guard against division by zero */
+ tmp_int_length = 8;
+ }
+
+ L_temp = ((Word32) tmp_int_length) << 10;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *pOverflow = 1;
+ L_temp = (Word32)((tmp_int_length > 0) ? MAX_16 : MIN_16);
+ }
+ temp = (Word16) L_temp;
+
+ st->true_sid_period_inv = div_s(1 << 10, temp);
+
+ st->since_last_sid = 0;
+ Copy(st->lsp, st->lsp_old, M);
+ st->old_log_en = st->log_en;
+ /* subtract 1/8 in Q11 i.e -6/8 dB */
+ st->log_en = sub(st->log_en, 256, pOverflow);
+ }
+
+ /* reset interpolation length timer
+ * if data has been updated. */
+ if ((st->sid_frame != 0) &&
+ ((st->valid_data != 0) ||
+ ((st->valid_data == 0) && (st->dtxHangoverAdded) != 0)))
+ {
+ st->since_last_sid = 0;
+ st->data_updated = 1;
+ }
+
+ return;
+}
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_dec_activity_update
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type dtx_decState
+ lsf =
+ frame =
+
+ Outputs:
+ st points to an updated structure of type dtx_decState
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function updates the DTX parameters.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.3.0, December 12, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void dtx_dec_activity_update(dtx_decState *st,
+ Word16 lsf[],
+ Word16 frame[])
+{
+ Word16 i;
+
+ Word32 L_frame_en;
+ Word16 log_en_e, log_en_m, log_en;
+
+ // update lsp history
+ st->lsf_hist_ptr = add(st->lsf_hist_ptr,M);
+ if (sub(st->lsf_hist_ptr, 80) == 0)
+ {
+ st->lsf_hist_ptr = 0;
+ }
+ Copy(lsf, &st->lsf_hist[st->lsf_hist_ptr], M);
+
+ // compute log energy based on frame energy
+ L_frame_en = 0; // Q0
+ for (i=0; i < L_FRAME; i++)
+ {
+ L_frame_en = L_mac(L_frame_en, frame[i], frame[i]);
+ }
+ Log2(L_frame_en, &log_en_e, &log_en_m);
+
+ // convert exponent and mantissa to Word16 Q10
+ log_en = shl(log_en_e, 10); // Q10
+ log_en = add(log_en, shr(log_en_m, 15-10));
+
+ // divide with L_FRAME i.e subtract with log2(L_FRAME) = 7.32193
+ log_en = sub(log_en, 7497+1024);
+
+ // insert into log energy buffer, no division by two as *
+ * log_en in decoder is Q11
+ st->log_en_hist_ptr = add(st->log_en_hist_ptr, 1);
+ if (sub(st->log_en_hist_ptr, DTX_HIST_SIZE) == 0)
+ {
+ st->log_en_hist_ptr = 0;
+ }
+ st->log_en_hist[st->log_en_hist_ptr] = log_en; // Q11
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void dtx_dec_activity_update(dtx_decState *st,
+ Word16 lsf[],
+ Word16 frame[],
+ Flag *pOverflow)
+{
+ Word16 i;
+
+ Word32 L_frame_en;
+ Word32 L_temp;
+ Word16 log_en_e;
+ Word16 log_en_m;
+ Word16 log_en;
+
+ /* update lsp history */
+ st->lsf_hist_ptr += M;
+
+ if (st->lsf_hist_ptr == 80)
+ {
+ st->lsf_hist_ptr = 0;
+ }
+ Copy(lsf, &st->lsf_hist[st->lsf_hist_ptr], M);
+
+ /* compute log energy based on frame energy */
+ L_frame_en = 0; /* Q0 */
+ for (i = L_FRAME - 1; i >= 0; i--)
+ {
+ L_temp = ((Word32) frame[i]) * frame[i];
+ if (L_temp != (Word32) 0x40000000L)
+ {
+ L_temp = L_temp << 1;
+ }
+ else
+ {
+ L_temp = MAX_32;
+ }
+ L_frame_en = L_add(L_frame_en, L_temp, pOverflow);
+ }
+ Log2(L_frame_en, &log_en_e, &log_en_m, pOverflow);
+
+ /* convert exponent and mantissa to Word16 Q10 */
+ L_temp = ((Word32) log_en_e) << 10;
+
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *pOverflow = 1;
+ L_temp = (Word32)((log_en_e > 0) ? MAX_16 : MIN_16);
+ }
+ log_en_e = (Word16) L_temp;
+
+ if (log_en_m < 0)
+ {
+ log_en_m = ~((~log_en_m) >> 5);
+ }
+ else
+ {
+ log_en_m >>= 5;
+ }
+ log_en = add(log_en_e, log_en_m, pOverflow);
+
+ /* divide with L_FRAME i.e subtract with log2(L_FRAME) = 7.32193 */
+ log_en = sub(log_en, 7497 + 1024, pOverflow);
+
+ /* insert into log energy buffer, no division by two as *
+ * log_en in decoder is Q11 */
+ st->log_en_hist_ptr += 1;
+
+ if (st->log_en_hist_ptr == DTX_HIST_SIZE)
+ {
+ st->log_en_hist_ptr = 0;
+ }
+ st->log_en_hist[st->log_en_hist_ptr] = log_en; /* Q11 */
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: rx_dtx_handler
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type dtx_decState
+ frame_type = RX frame type
+
+ Returns:
+ newState = variable of type DTXStateType
+
+ Outputs:
+ st points to an updated structure of type dtx_decState
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function determines the new state of the decoder based on the frame_type
+ and sets up the decoder parameters according to newState.
+
+ Table of new SPD synthesis states
+
+ | previous SPD_synthesis_state
+ Incoming |
+ frame_type | SPEECH | DTX | DTX_MUTE
+ ---------------------------------------------------------------
+ RX_SPEECH_GOOD , | | |
+ RX_SPEECH_PR_DEGRADED | SPEECH | SPEECH | SPEECH
+ ----------------------------------------------------------------
+ RX_SPEECH_PR_BAD, | | |
+ RX_SPEECH_BAD, | SPEECH | DTX | DTX_MUTE
+ ----------------------------------------------------------------
+ RX_SID_FIRST, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
+ ----------------------------------------------------------------
+ RX_SID_UPDATE, | DTX | DTX | DTX
+ ----------------------------------------------------------------
+ RX_SID_BAD, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
+ ----------------------------------------------------------------
+ RX_NO_DATA | SPEECH | DTX/(DTX_MUTE)| DTX_MUTE
+ |(class2 garb.)| |
+ ----------------------------------------------------------------
+ RX_ONSET | SPEECH | DTX/(DTX_MUTE)| DTX_MUTE
+ |(class2 garb.)| |
+ ----------------------------------------------------------------
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.3.0, December 12, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+enum DTXStateType rx_dtx_handler(
+ dtx_decState *st, // i/o : State struct
+ enum RXFrameType frame_type // i : Frame type
+ )
+{
+ enum DTXStateType newState;
+ enum DTXStateType encState;
+
+ // DTX if SID frame or previously in DTX{_MUTE} and (NO_RX OR BAD_SPEECH)
+ if ((sub(frame_type, RX_SID_FIRST) == 0) ||
+ (sub(frame_type, RX_SID_UPDATE) == 0) ||
+ (sub(frame_type, RX_SID_BAD) == 0) ||
+ (((sub(st->dtxGlobalState, DTX) == 0) ||
+ (sub(st->dtxGlobalState, DTX_MUTE) == 0)) &&
+ ((sub(frame_type, RX_NO_DATA) == 0) ||
+ (sub(frame_type, RX_SPEECH_BAD) == 0) ||
+ (sub(frame_type, RX_ONSET) == 0))))
+ {
+ newState = DTX;
+
+ // stay in mute for these input types
+ if ((sub(st->dtxGlobalState, DTX_MUTE) == 0) &&
+ ((sub(frame_type, RX_SID_BAD) == 0) ||
+ (sub(frame_type, RX_SID_FIRST) == 0) ||
+ (sub(frame_type, RX_ONSET) == 0) ||
+ (sub(frame_type, RX_NO_DATA) == 0)))
+ {
+ newState = DTX_MUTE;
+ }
+
+ // evaluate if noise parameters are too old
+ // since_last_sid is reset when CN parameters have been updated
+ st->since_last_sid = add(st->since_last_sid, 1);
+
+ // no update of sid parameters in DTX for a long while
+ // Due to the delayed update of st->since_last_sid counter
+ // SID_UPDATE frames need to be handled separately to avoid
+ // entering DTX_MUTE for late SID_UPDATE frames
+ if((sub(frame_type, RX_SID_UPDATE) != 0) &&
+ (sub(st->since_last_sid, DTX_MAX_EMPTY_THRESH) > 0))
+ {
+ newState = DTX_MUTE;
+ }
+ }
+ else
+ {
+ newState = SPEECH;
+ st->since_last_sid = 0;
+ }
+
+ // reset the decAnaElapsed Counter when receiving CNI data the first
+ // time, to robustify counter missmatch after handover
+ // this might delay the bwd CNI analysis in the new decoder slightly.
+
+ if ((st->data_updated == 0) &&
+ (sub(frame_type, RX_SID_UPDATE) == 0))
+ {
+ st->decAnaElapsedCount = 0;
+ }
+
+ // update the SPE-SPD DTX hangover synchronization
+ // to know when SPE has added dtx hangover
+ st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1);
+ st->dtxHangoverAdded = 0;
+
+ if ((sub(frame_type, RX_SID_FIRST) == 0) ||
+ (sub(frame_type, RX_SID_UPDATE) == 0) ||
+ (sub(frame_type, RX_SID_BAD) == 0) ||
+ (sub(frame_type, RX_ONSET) == 0) ||
+ (sub(frame_type, RX_NO_DATA) == 0))
+ {
+ encState = DTX;
+
+ // In frame errors simulations RX_NO_DATA may occasionally mean that
+ // a speech packet was probably sent by the encoder,
+ // the assumed _encoder_ state should be SPEECH in such cases.
+ if((sub(frame_type, RX_NO_DATA) == 0) &&
+ (sub(newState, SPEECH) == 0))
+ {
+ encState = SPEECH;
+ }
+
+ // Note on RX_ONSET operation differing from RX_NO_DATA operation:
+ // If a RX_ONSET is received in the decoder (by "accident")
+ // it is still most likely that the encoder state
+ // for the "ONSET frame" was DTX.
+
+ }
+ else
+ {
+ encState = SPEECH;
+ }
+
+ if (sub(encState, SPEECH) == 0)
+ {
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ }
+ else
+ {
+ if (sub(st->decAnaElapsedCount, DTX_ELAPSED_FRAMES_THRESH) > 0)
+ {
+ st->dtxHangoverAdded = 1;
+ st->decAnaElapsedCount = 0;
+ st->dtxHangoverCount = 0;
+ }
+ else if (st->dtxHangoverCount == 0)
+ {
+ st->decAnaElapsedCount = 0;
+ }
+ else
+ {
+ st->dtxHangoverCount = sub(st->dtxHangoverCount, 1);
+ }
+ }
+
+ if (sub(newState, SPEECH) != 0)
+ {
+ // DTX or DTX_MUTE
+ // CN data is not in a first SID, first SIDs are marked as SID_BAD
+ // but will do backwards analysis if a hangover period has been added
+ // according to the state machine above
+
+ st->sid_frame = 0;
+ st->valid_data = 0;
+
+ if (sub(frame_type, RX_SID_FIRST) == 0)
+ {
+ st->sid_frame = 1;
+ }
+ else if (sub(frame_type, RX_SID_UPDATE) == 0)
+ {
+ st->sid_frame = 1;
+ st->valid_data = 1;
+ }
+ else if (sub(frame_type, RX_SID_BAD) == 0)
+ {
+ st->sid_frame = 1;
+ st->dtxHangoverAdded = 0; // use old data
+ }
+ }
+
+ return newState;
+ // newState is used by both SPEECH AND DTX synthesis routines
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+enum DTXStateType rx_dtx_handler(
+ dtx_decState *st, /* i/o : State struct */
+ enum RXFrameType frame_type,/* i : Frame type */
+ Flag *pOverflow)
+{
+ enum DTXStateType newState;
+ enum DTXStateType encState;
+
+
+ /* DTX if SID frame or previously in DTX{_MUTE} and (NO_RX OR BAD_SPEECH) */
+
+ if ((frame_type == RX_SID_FIRST) ||
+ (frame_type == RX_SID_UPDATE) ||
+ (frame_type == RX_SID_BAD) ||
+ (((st->dtxGlobalState == DTX) || (st->dtxGlobalState == DTX_MUTE)) &&
+ ((frame_type == RX_NO_DATA) || (frame_type == RX_SPEECH_BAD) ||
+ (frame_type == RX_ONSET))))
+ {
+ newState = DTX;
+
+ /* stay in mute for these input types */
+
+ if ((st->dtxGlobalState == DTX_MUTE) &&
+ ((frame_type == RX_SID_BAD) ||
+ (frame_type == RX_SID_FIRST) ||
+ (frame_type == RX_ONSET) ||
+ (frame_type == RX_NO_DATA)))
+ {
+ newState = DTX_MUTE;
+ }
+
+ /* evaluate if noise parameters are too old */
+ /* since_last_sid is reset when CN parameters have been updated */
+ st->since_last_sid = add(st->since_last_sid, 1, pOverflow);
+
+ /* no update of sid parameters in DTX for a long while */
+ /* Due to the delayed update of st->since_last_sid counter */
+ /* SID_UPDATE frames need to be handled separately to avoid */
+ /* entering DTX_MUTE for late SID_UPDATE frames */
+ if ((frame_type != RX_SID_UPDATE) &&
+ (st->since_last_sid > DTX_MAX_EMPTY_THRESH))
+ {
+ newState = DTX_MUTE;
+ }
+ }
+ else
+ {
+ newState = SPEECH;
+ st->since_last_sid = 0;
+ }
+
+ /*
+ reset the decAnaElapsed Counter when receiving CNI data the first
+ time, to robustify counter missmatch after handover
+ this might delay the bwd CNI analysis in the new decoder slightly.
+ */
+
+ if ((st->data_updated == 0) &&
+ (frame_type == RX_SID_UPDATE))
+ {
+ st->decAnaElapsedCount = 0;
+ }
+
+ /* update the SPE-SPD DTX hangover synchronization */
+ /* to know when SPE has added dtx hangover */
+ st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1, pOverflow);
+ st->dtxHangoverAdded = 0;
+
+ if ((frame_type == RX_SID_FIRST) ||
+ (frame_type == RX_SID_UPDATE) ||
+ (frame_type == RX_SID_BAD) ||
+ (frame_type == RX_ONSET) ||
+ (frame_type == RX_NO_DATA))
+ {
+ encState = DTX;
+
+ /*
+ In frame errors simulations RX_NO_DATA may occasionally mean that
+ a speech packet was probably sent by the encoder,
+ the assumed _encoder_ state should be SPEECH in such cases.
+ */
+ if ((frame_type == RX_NO_DATA) &&
+ (newState == SPEECH))
+ {
+ encState = SPEECH;
+ }
+
+ /*
+ Note on RX_ONSET operation differing from RX_NO_DATA operation:
+ If a RX_ONSET is received in the decoder (by "accident")
+ it is still most likely that the encoder state
+ for the "ONSET frame" was DTX.
+ */
+ }
+ else
+ {
+ encState = SPEECH;
+ }
+
+
+ if (encState == SPEECH)
+ {
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ }
+ else
+ {
+
+ if (st->decAnaElapsedCount > DTX_ELAPSED_FRAMES_THRESH)
+ {
+ st->dtxHangoverAdded = 1;
+ st->decAnaElapsedCount = 0;
+ st->dtxHangoverCount = 0;
+ }
+ else if (st->dtxHangoverCount == 0)
+ {
+ st->decAnaElapsedCount = 0;
+ }
+ else
+ {
+ st->dtxHangoverCount -= 1;
+ }
+ }
+
+ if (newState != SPEECH)
+ {
+ /* DTX or DTX_MUTE
+ * CN data is not in a first SID, first SIDs are marked as SID_BAD
+ * but will do backwards analysis if a hangover period has been added
+ * according to the state machine above
+ */
+
+ st->sid_frame = 0;
+ st->valid_data = 0;
+
+ if (frame_type == RX_SID_FIRST)
+ {
+ st->sid_frame = 1;
+ }
+ else if (frame_type == RX_SID_UPDATE)
+ {
+ st->sid_frame = 1;
+ st->valid_data = 1;
+ }
+ else if (frame_type == RX_SID_BAD)
+ {
+ st->sid_frame = 1;
+ st->dtxHangoverAdded = 0; /* use old data */
+ }
+ }
+
+ /* newState is used by both SPEECH AND DTX synthesis routines */
+ return(newState);
+}
diff --git a/media/codecs/amrnb/dec/src/dtx_dec.h b/media/codecs/amrnb/dec/src/dtx_dec.h
new file mode 100644
index 0000000..2b5a614
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/dtx_dec.h
@@ -0,0 +1,191 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/dtx_dec.h
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : dtx_dec.h
+ Purpose : Decode comfort noice when in DTX
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef DTX_DEC_H
+#define DTX_DEC_H
+#define dtx_dec_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "d_plsf.h"
+#include "gc_pred.h"
+#include "c_g_aver.h"
+#include "frame.h"
+#include "dtx_common_def.h"
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ enum DTXStateType {SPEECH = 0, DTX, DTX_MUTE};
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 since_last_sid;
+ Word16 true_sid_period_inv;
+ Word16 log_en;
+ Word16 old_log_en;
+ Word32 L_pn_seed_rx;
+ Word16 lsp[M];
+ Word16 lsp_old[M];
+
+ Word16 lsf_hist[M*DTX_HIST_SIZE];
+ Word16 lsf_hist_ptr;
+ Word16 lsf_hist_mean[M*DTX_HIST_SIZE];
+ Word16 log_pg_mean;
+ Word16 log_en_hist[DTX_HIST_SIZE];
+ Word16 log_en_hist_ptr;
+
+ Word16 log_en_adjust;
+
+ Word16 dtxHangoverCount;
+ Word16 decAnaElapsedCount;
+
+ Word16 sid_frame;
+ Word16 valid_data;
+ Word16 dtxHangoverAdded;
+
+ enum DTXStateType dtxGlobalState; /* contains previous state */
+ /* updated in main decoder */
+
+ Word16 data_updated; /* marker to know if CNI data is ever renewed */
+
+ } dtx_decState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*
+ * Function : dtx_dec_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ */
+ Word16 dtx_dec_reset(dtx_decState *st);
+
+ /*
+ * Function : dtx_dec
+ * Purpose :
+ * Description :
+ */
+ void dtx_dec(
+ dtx_decState *st, /* i/o : State struct */
+ Word16 mem_syn[], /* i/o : AMR decoder state */
+ D_plsfState* lsfState, /* i/o : decoder lsf states */
+ gc_predState* predState, /* i/o : prediction states */
+ Cb_gain_averageState* averState, /* i/o : CB gain average states */
+ enum DTXStateType new_state, /* i : new DTX state */
+ enum Mode mode, /* i : AMR mode */
+ Word16 parm[], /* i : Vector of synthesis parameters */
+ Word16 synth[], /* o : synthesised speech */
+ Word16 A_t[], /* o : decoded LP filter in 4 subframes*/
+ Flag *pOverflow
+ );
+
+ void dtx_dec_activity_update(dtx_decState *st,
+ Word16 lsf[],
+ Word16 frame[],
+ Flag *pOverflow);
+
+ /*
+ * Function : rx_dtx_handler
+ * Purpose : reads the frame type and checks history
+ * Description : to decide what kind of DTX/CNI action to perform
+ */
+ enum DTXStateType rx_dtx_handler(dtx_decState *st, /* i/o : State struct */
+ enum RXFrameType frame_type,/* i : Frame type */
+ Flag *pOverflow);
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DEC_AMR_H_ */
diff --git a/media/codecs/amrnb/dec/src/ec_gains.cpp b/media/codecs/amrnb/dec/src/ec_gains.cpp
new file mode 100644
index 0000000..e73db62
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/ec_gains.cpp
@@ -0,0 +1,842 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/ec_gain.c
+ Funtions:
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Removed the functions ec_gain_code_init, ec_gain_pitch_init,
+ ech_gain_code_exit, and ec_gain_pitch_exit.
+
+ The ec_gains related structures are no longer dynamically allocated.
+
+ Description: Updated include files and input/output sections.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ These modules execute the code book gains for error concealment. This module
+ contains the init, reset, exit, and "main" functions in this process.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "ec_gains.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "gmed_n.h"
+#include "gc_pred.h"
+#include "basic_op.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ extern const Word16 qua_gain_pitch[];
+ extern const Word16 qua_gain_code[];
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ec_gain_code_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer to a structure containing code state data of
+ stucture type ec_gain_codeState
+
+ Outputs:
+ None.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets the state data for the ec_gain module.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int ec_gain_code_reset (ec_gain_codeState *state)
+{
+ Word16 i;
+
+ if (state == (ec_gain_codeState *) NULL){
+ // fprintf(stderr, "ec_gain_code_reset: invalid parameter\n");
+ return -1;
+ }
+
+ for ( i = 0; i < 5; i++)
+ state->gbuf[i] = 1;
+ state->past_gain_code = 0;
+ state->prev_gc = 1;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 ec_gain_code_reset(ec_gain_codeState *state)
+{
+ Word16 i;
+
+ if (state == (ec_gain_codeState *) NULL)
+ {
+ /* fprintf(stderr, "ec_gain_code_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ for (i = 0; i < 5; i++)
+ state->gbuf[i] = 1;
+ state->past_gain_code = 0;
+ state->prev_gc = 1;
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ec_gain_code
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a pointer to a structure containing code state data of
+ stucture type ec_gain_codeState
+ pred_state = pointer to MA predictor state of type gc_predState
+ state = state of the state machine of type Word16
+ gain_code = pointer to decoded innovation gain of type Word16
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ st = pointer to a pointer to a structure containing code state data of
+ stucture type ec_gain_codeState
+ pred_state = pointer to MA predictor state of type gc_predState
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+This function does error concealment using the codebook. Call this function
+only in BFI (instead of normal gain decoding function).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ec_gain.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ static const Word16 cdown[7] =
+ {
+ 32767, 32112, 32112, 32112,
+ 32112, 32112, 22937
+ };
+
+ Word16 tmp;
+ Word16 qua_ener_MR122;
+ Word16 qua_ener;
+
+ // calculate median of last five gain values
+ tmp = gmed_n (st->gbuf,5);
+
+ // new gain = minimum(median, past_gain) * cdown[state]
+ if (sub (tmp, st->past_gain_code) > 0)
+ {
+ tmp = st->past_gain_code;
+ }
+ tmp = mult (tmp, cdown[state]);
+ *gain_code = tmp;
+
+ // update table of past quantized energies with average of
+ // current values
+
+ gc_pred_average_limited(pred_state, &qua_ener_MR122, &qua_ener);
+ gc_pred_update(pred_state, qua_ener_MR122, qua_ener);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void ec_gain_code(
+ ec_gain_codeState *st, /* i/o : State struct */
+ gc_predState *pred_state, /* i/o : MA predictor state */
+ Word16 state, /* i : state of the state machine */
+ Word16 *gain_code, /* o : decoded innovation gain */
+ Flag *pOverflow
+)
+{
+ static const Word16 cdown[7] =
+ {
+ 32767, 32112, 32112, 32112,
+ 32112, 32112, 22937
+ };
+
+ Word16 tmp;
+ Word16 qua_ener_MR122;
+ Word16 qua_ener;
+
+ /* calculate median of last five gain values */
+ tmp = gmed_n(st->gbuf, 5);
+
+ /* new gain = minimum(median, past_gain) * cdown[state] */
+ if (sub(tmp, st->past_gain_code, pOverflow) > 0)
+ {
+ tmp = st->past_gain_code;
+ }
+ tmp = mult(tmp, cdown[state], pOverflow);
+ *gain_code = tmp;
+
+ /* update table of past quantized energies with average of
+ * current values
+ */
+ gc_pred_average_limited(pred_state, &qua_ener_MR122, &qua_ener, pOverflow);
+ gc_pred_update(pred_state, qua_ener_MR122, qua_ener);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ec_gain_code_update
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a pointer to a structure containing code state data of
+ stucture type ec_gain_codeState
+ bfi = a flag that indicates if the frame is bad of type Word16
+ prev_bf = a flag that indicates if the previous frame was bad of type Word16
+ gain_code = pointer to decoded innovation gain of type Word16
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ st = pointer to a pointer to a structure containing code state data of
+ stucture type ec_gain_codeState
+ gain_code = pointer to decoded innovation gain of type Word16
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : update the codebook gain concealment state;
+ limit gain_code if the previous frame was bad
+ Call this function always after decoding (or concealing)
+ the gain
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ec_gain.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 i;
+
+ // limit gain_code by previous good gain if previous frame was bad
+ if (bfi == 0)
+ {
+ if (prev_bf != 0)
+ {
+ if (sub (*gain_code, st->prev_gc) > 0)
+ {
+ *gain_code = st->prev_gc;
+ }
+ }
+ st->prev_gc = *gain_code;
+ }
+
+ // update EC states: previous gain, gain buffer
+ st->past_gain_code = *gain_code;
+
+ for (i = 1; i < 5; i++)
+ {
+ st->gbuf[i - 1] = st->gbuf[i];
+ }
+ st->gbuf[4] = *gain_code;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void ec_gain_code_update(
+ ec_gain_codeState *st, /* i/o : State struct */
+ Word16 bfi, /* i : flag: frame is bad */
+ Word16 prev_bf, /* i : flag: previous frame was bad */
+ Word16 *gain_code, /* i/o : decoded innovation gain */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+
+ /* limit gain_code by previous good gain if previous frame was bad */
+ if (bfi == 0)
+ {
+ if (prev_bf != 0)
+ {
+ if (sub(*gain_code, st->prev_gc, pOverflow) > 0)
+ {
+ *gain_code = st->prev_gc;
+ }
+ }
+ st->prev_gc = *gain_code;
+ }
+
+ /* update EC states: previous gain, gain buffer */
+ st->past_gain_code = *gain_code;
+
+ for (i = 1; i < 5; i++)
+ {
+ st->gbuf[i - 1] = st->gbuf[i];
+ }
+ st->gbuf[4] = *gain_code;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ec_gain_pitch
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a pointer to a structure containing code
+ state data of stucture type ec_gain_pitchState
+ state = state of the state machine of type Word16
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ state = pointer to a pointer to a structure containing code
+ state data of stucture type ec_gain_pitchState
+ gain_pitch = pointer to pitch gain (Q14) of type Word16
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function conceals the error using code gain implementation in this
+ function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ec_gain.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+ static const Word16 pdown[7] =
+ {
+ 32767, 32112, 32112, 26214,
+ 9830, 6553, 6553
+ };
+
+ Word16 tmp;
+
+ // calculate median of last five gains
+ tmp = gmed_n (st->pbuf, 5);
+
+ // new gain = minimum(median, past_gain) * pdown[state]
+ if (sub (tmp, st->past_gain_pit) > 0)
+ {
+ tmp = st->past_gain_pit;
+ }
+ *gain_pitch = mult (tmp, pdown[state]);
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void ec_gain_pitch(
+ ec_gain_pitchState *st, /* i/o : state variables */
+ Word16 state, /* i : state of the state machine */
+ Word16 *gain_pitch, /* o : pitch gain (Q14) */
+ Flag *pOverflow
+)
+{
+ static const Word16 pdown[7] =
+ {
+ 32767, 32112, 32112, 26214,
+ 9830, 6553, 6553
+ };
+
+ Word16 tmp;
+
+ /* calculate median of last five gains */
+ tmp = gmed_n(st->pbuf, 5);
+
+ /* new gain = minimum(median, past_gain) * pdown[state] */
+ if (sub(tmp, st->past_gain_pit, pOverflow) > 0)
+ {
+ tmp = st->past_gain_pit;
+ }
+ *gain_pitch = mult(tmp, pdown[state], pOverflow);
+}
+
+/****************************************************************************/
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ec_gain_pitch_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = state of the state machine of type Word16
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ state = pointer to a pointer to a structure containing code
+ state data of stucture type ec_gain_pitchState
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: ec_gain_pitch_reset
+ Purpose: Resets state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ec_gain.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int ec_gain_pitch_reset (ec_gain_pitchState *state)
+{
+ Word16 i;
+
+ if (state == (ec_gain_pitchState *) NULL){
+ // fprintf(stderr, "ec_gain_pitch_reset: invalid parameter\n");
+ return -1;
+ }
+
+ for(i = 0; i < 5; i++)
+ state->pbuf[i] = 1640;
+ state->past_gain_pit = 0;
+ state->prev_gp = 16384;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 ec_gain_pitch_reset(ec_gain_pitchState *state)
+{
+ Word16 i;
+
+ if (state == (ec_gain_pitchState *) NULL)
+ {
+ /* fprintf(stderr, "ec_gain_pitch_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ for (i = 0; i < 5; i++)
+ state->pbuf[i] = 1640;
+ state->past_gain_pit = 0;
+ state->prev_gp = 16384;
+
+ return 0;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ec_gain_pitch_update
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a pointer to a structure containing code
+ state data of stucture type ec_gain_pitchState
+ bfi = flag indicating the frame is bad of type Word16
+ prev_bf = flag indicating the previous frame was bad of type Word16
+ gain_pitch = pointer to pitch gain of type Word16
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ state = pointer to a pointer to a structure containing code
+ state data of stucture type ec_gain_pitchState
+ gain_pitch = pointer to pitch gain of type Word16
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : update the pitch gain concealment state;
+ limit gain_pitch if the previous frame was bad
+ Call this function always after decoding (or concealing)
+ the gain
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ec_gain.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 i;
+
+ if (bfi == 0)
+ {
+ if (prev_bf != 0)
+ {
+ if (sub (*gain_pitch, st->prev_gp) > 0)
+ {
+ *gain_pitch = st->prev_gp;
+ }
+ }
+ st->prev_gp = *gain_pitch;
+ }
+
+ st->past_gain_pit = *gain_pitch;
+
+ if (sub (st->past_gain_pit, 16384) > 0) // if (st->past_gain_pit > 1.0)
+ {
+ st->past_gain_pit = 16384;
+ }
+ for (i = 1; i < 5; i++)
+ {
+ st->pbuf[i - 1] = st->pbuf[i];
+ }
+ st->pbuf[4] = st->past_gain_pit;
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void ec_gain_pitch_update(
+ ec_gain_pitchState *st, /* i/o : state variables */
+ Word16 bfi, /* i : flag: frame is bad */
+ Word16 prev_bf, /* i : flag: previous frame was bad */
+ Word16 *gain_pitch, /* i/o : pitch gain */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+
+ if (bfi == 0)
+ {
+ if (prev_bf != 0)
+ {
+ if (sub(*gain_pitch, st->prev_gp, pOverflow) > 0)
+ {
+ *gain_pitch = st->prev_gp;
+ }
+ }
+ st->prev_gp = *gain_pitch;
+ }
+
+ st->past_gain_pit = *gain_pitch;
+
+ if (sub(st->past_gain_pit, 16384, pOverflow) > 0)
+ /* if (st->past_gain_pit > 1.0) */
+ {
+ st->past_gain_pit = 16384;
+ }
+ for (i = 1; i < 5; i++)
+ {
+ st->pbuf[i - 1] = st->pbuf[i];
+ }
+ st->pbuf[4] = st->past_gain_pit;
+}
+
+
diff --git a/media/codecs/amrnb/dec/src/ec_gains.h b/media/codecs/amrnb/dec/src/ec_gains.h
new file mode 100644
index 0000000..e05a0af
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/ec_gains.h
@@ -0,0 +1,209 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/ec_gains.h
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : ec_gains.c
+ Purpose: : Error concealment for pitch and codebook gains
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _EC_GAINS_H_
+#define _EC_GAINS_H_
+#define ec_gains_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "gc_pred.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 pbuf[5];
+ Word16 past_gain_pit;
+ Word16 prev_gp;
+ } ec_gain_pitchState;
+
+ typedef struct
+ {
+ Word16 gbuf[5];
+ Word16 past_gain_code;
+ Word16 prev_gc;
+ } ec_gain_codeState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*
+ * Function : ec_gain_code_reset
+ * Purpose : Resets state memory
+ *
+ */
+ Word16 ec_gain_code_reset(
+ ec_gain_codeState *state
+ );
+
+
+ /*
+ * Function : ec_gain_code
+ * Purpose : conceal the codebook gain
+ * Call this function only in BFI (instead of normal gain
+ * decoding function)
+ */
+ void ec_gain_code(
+ ec_gain_codeState *st, /* i/o : State struct */
+ gc_predState *pred_state, /* i/o : MA predictor state */
+ Word16 state, /* i : state of the state machine */
+ Word16 *gain_code, /* o : decoded innovation gain */
+ Flag *pOverflow
+ );
+
+ /*
+ * Function : ec_gain_code_update
+ * Purpose : update the codebook gain concealment state;
+ * limit gain_code if the previous frame was bad
+ * Call this function always after decoding (or concealing)
+ * the gain
+ */
+ void ec_gain_code_update(
+ ec_gain_codeState *st, /* i/o : State struct */
+ Word16 bfi, /* i : flag: frame is bad */
+ Word16 prev_bf, /* i : flag: previous frame was bad */
+ Word16 *gain_code, /* i/o : decoded innovation gain */
+ Flag *pOverflow
+ );
+
+
+ /*
+ * Function: ec_gain_pitch_reset
+ * Purpose: Resets state memory
+ */
+ Word16 ec_gain_pitch_reset(
+ ec_gain_pitchState *state
+ );
+
+ /*
+ * Function : ec_gain_pitch_exit
+ * Purpose : The memory used for state memory is freed
+ */
+ void ec_gain_pitch_exit(
+ ec_gain_pitchState **state
+ );
+
+ /*
+ * Function : ec_gain_pitch
+ * Purpose : conceal the pitch gain
+ * Call this function only in BFI (instead of normal gain
+ * decoding function)
+ */
+ void ec_gain_pitch(
+ ec_gain_pitchState *st, /* i/o : state variables */
+ Word16 state, /* i : state of the state machine */
+ Word16 *gain_pitch, /* o : pitch gain (Q14) */
+ Flag *pOverflow
+ );
+
+ /*
+ * Function : ec_gain_pitch_update
+ * Purpose : update the pitch gain concealment state;
+ * limit gain_pitch if the previous frame was bad
+ * Call this function always after decoding (or concealing)
+ * the gain
+ */
+ void ec_gain_pitch_update(
+ ec_gain_pitchState *st, /* i/o : state variables */
+ Word16 bfi, /* i : flag: frame is bad */
+ Word16 prev_bf, /* i : flag: previous frame was bad */
+ Word16 *gain_pitch, /* i/o : pitch gain */
+ Flag *pOverflow
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _EC_GAINS_H_ */
+
+
diff --git a/media/codecs/amrnb/dec/src/ex_ctrl.cpp b/media/codecs/amrnb/dec/src/ex_ctrl.cpp
new file mode 100644
index 0000000..f18054b
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/ex_ctrl.cpp
@@ -0,0 +1,219 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/ex_ctrl.c
+ Funtions: ex_ctrl
+
+ Date: 02/08/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "ex_ctrl.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "copy.h"
+#include "set_zero.h"
+#include "gmed_n.h"
+#include "sqrt_l.h"
+#include "basic_op.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ex_ctrl
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ excitation = pointer to current subframe excitation of type Word16
+ excEnergy = Exc. Energy, sqrt(totEx*totEx) of type Word16
+ exEnergyHist = pointer to history of subframe energies of type Word16
+ voicedHangover = # of fr. after last voiced fr of type Word16
+ carefulFlag = restrict dynamic in scaling of type Word16
+ pOverflow = pointer to overflow indicator
+
+ Outputs:
+ pOverflow = 1 if overflow exists in the math functions called by this function.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function : Ex_ctrl
+ Purpose : Charaterice synthesis speech and detect background noise
+ Returns : background noise decision; 0 = no bgn, 1 = bgn
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ex_ctrl.c, 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 Ex_ctrl(Word16 excitation[], /*i/o: Current subframe excitation */
+ Word16 excEnergy, /* i : Exc. Energy, sqrt(totEx*totEx)*/
+ Word16 exEnergyHist[], /* i : History of subframe energies */
+ Word16 voicedHangover, /* i : # of fr. after last voiced fr.*/
+ Word16 prevBFI, /* i : Set i previous BFI */
+ Word16 carefulFlag, /* i : Restrict dymamic in scaling */
+ Flag *pOverflow
+ )
+{
+ Word16 i, exp;
+ Word16 testEnergy, scaleFactor, avgEnergy, prevEnergy;
+ Word32 t0;
+
+ /* get target level */
+ avgEnergy = gmed_n(exEnergyHist, 9);
+
+ prevEnergy = shr(add(exEnergyHist[7], exEnergyHist[8], pOverflow) , 1, pOverflow);
+
+ if (exEnergyHist[8] < prevEnergy)
+ {
+ prevEnergy = exEnergyHist[8];
+ }
+
+ /* upscaling to avoid too rapid energy rises for some cases */
+ if ((excEnergy < avgEnergy) && (excEnergy > 5))
+ {
+ testEnergy = shl(prevEnergy, 2, pOverflow); /* testEnergy = 4*prevEnergy; */
+
+ if ((voicedHangover < 7) || prevBFI != 0)
+ {
+ /* testEnergy = 3*prevEnergy */
+ testEnergy = sub(testEnergy, prevEnergy, pOverflow);
+ }
+
+ if (avgEnergy > testEnergy)
+ {
+ avgEnergy = testEnergy;
+ }
+
+ /* scaleFactor=avgEnergy/excEnergy in Q0 (const 29 below)*/
+ exp = norm_s(excEnergy);
+ excEnergy = shl(excEnergy, exp, pOverflow);
+ excEnergy = div_s((Word16) 16383, excEnergy);
+ t0 = L_mult(avgEnergy, excEnergy, pOverflow);
+ t0 = L_shr(t0, sub(20, exp, pOverflow), pOverflow);
+ /* const=30 for t0 in Q0, 20 for Q10 */
+ if (t0 > 32767)
+ {
+ t0 = 32767; /* saturate */
+ }
+ scaleFactor = extract_l(t0);
+
+ /* test if scaleFactor > 3.0 */
+ if (carefulFlag != 0 && (scaleFactor > 3072))
+ {
+ scaleFactor = 3072;
+ }
+
+ /* scale the excitation by scaleFactor */
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ t0 = L_mult(scaleFactor, excitation[i], pOverflow);
+ t0 = L_shr(t0, 11, pOverflow);
+ excitation[i] = extract_l(t0);
+ }
+ }
+
+ return 0;
+}
diff --git a/media/codecs/amrnb/dec/src/ex_ctrl.h b/media/codecs/amrnb/dec/src/ex_ctrl.h
new file mode 100644
index 0000000..11c632e
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/ex_ctrl.h
@@ -0,0 +1,131 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/ex_ctrl.h
+
+ Date: 02/08/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : ex_ctrl.h
+ Purpose : Excitation Control module in background noise
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef ex_ctrl_h
+#define ex_ctrl_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define L_ENERGYHIST 60
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ /*
+ * Function : Ex_ctrl
+ * Purpose : Charaterice synthesis speech and detect background noise
+ * Returns : background noise decision; 0 = bgn, 1 = no bgn
+ */
+ Word16 Ex_ctrl(Word16 excitation[], /*i/o: Current subframe excitation */
+ Word16 excEnergy, /* i : Exc. Energy, sqrt(totEx*totEx)*/
+ Word16 exEnergyHist[], /* i : History of subframe energies */
+ Word16 voicedHangover, /* i : # of fr. after last voiced fr.*/
+ Word16 prevBFI, /* i : Set i previous BFI */
+ Word16 carefulFlag, /* i : Restrict dymamic in scaling */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ex_ctrl_h_ */
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/dec/src/gsmamr_dec.h b/media/codecs/amrnb/dec/src/gsmamr_dec.h
new file mode 100644
index 0000000..dc64d67
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/gsmamr_dec.h
@@ -0,0 +1,157 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/include/gsmamr_dec.h
+
+ Date: 09/10/2001
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Adding comments and removing some tables as per review comments.
+
+ Description: Replace enum Mode with enum Frame_Type_3GPP and updated function
+ prototype of AMRDecode().
+
+ Description: Added back the enum Mode type definition, removed RXFrameType
+ type definition, and updated AMRDecode and GSMInitDecode function
+ prototypes.
+
+ Description: Added #defines for WMF and IF2. Updated AMRDecode function
+ prototype.
+
+ Description: Removed enum Mode type definition and updated AMRDecode function
+ prototype.
+
+ Description: Renamed WMF and IF2 to AMR_WMF and AMR_IF2, respectively. Added
+ #define for AMR_ETS format.
+
+ Description: Rename input format defines to make it unique to the decoder.
+
+ Description: Added comment to describe L_FRAME.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description: Included file "typedefs.h" to avoid re-declaring similar typedef
+ this for OSCL-ed compatibility
+
+ Description: Included file "gsm_amr_typedefs.h" and eliminated re-definition
+ of types UWord8, Word8, Word16
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This header contains all the necessary information needed to allow the gsm amr
+ decoder library to be used properly upon release.
+
+------------------------------------------------------------------------------
+*/
+#ifndef _GSMAMR_DEC_H_
+#define _GSMAMR_DEC_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "gsm_amr_typedefs.h"
+#include "frame_type_3gpp.h"
+#include "amrdecode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ----------------------------------------------------------------------------*/
+ /* Number of 13-bit linear PCM samples per 20 ms frame */
+ /* L_FRAME = (8 kHz) * (20 msec) = 160 samples */
+#define L_FRAME 160
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ----------------------------------------------------------------------------*/
+ /*
+ * This function allocates memory for filter structure and initializes state
+ * memory used by the GSM AMR decoder. This function returns zero. It will
+ * return negative one if there is an error.
+ */
+ Word16 GSMInitDecode(void **state_data,
+ Word8 *id);
+
+ /*
+ * This function resets the state memory used by the GSM AMR decoder. This
+ * function returns zero. It will return negative one if there is an error.
+ */
+ Word16 Speech_Decode_Frame_reset(void *state_data);
+
+ /*
+ * This function frees up the memory used for the state memory of the
+ * GSM AMR decoder.
+ */
+ void GSMDecodeFrameExit(void **state_data);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GSMAMR_DEC_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/if2_to_ets.cpp b/media/codecs/amrnb/dec/src/if2_to_ets.cpp
new file mode 100644
index 0000000..733c8b8
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/if2_to_ets.cpp
@@ -0,0 +1,196 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: ./audio/gsm-amr/c/src/if2_to_ets.c
+ Funtions: if2_to_ets
+
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "frame_type_3gpp.h"
+#include "if2_to_ets.h"
+#include "typedef.h"
+#include "bitreorder_tab.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: if2_to_ets
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
+ if2_input_ptr = pointer to input encoded speech bits in IF2 format (Word8)
+ ets_output_ptr = pointer to output encoded speech bits in ETS format (Word16)
+
+ Outputs:
+ ets_output_ptr = pointer to encoded speech bits in the ETS format (Word16)
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs a transformation on the data buffers. It converts the
+ data format from IF2 to ETS. IF2 is the storage format where the frame type
+ is in the first four bits of the first byte. The upper four bits of that byte
+ contain the first four encoded speech bits for the frame. The following bytes
+ contain the rest of the encoded speech bits. The final byte has padded zeros
+ to make the frame byte aligned. ETS format has the encoded speech
+ bits each separate with only one bit stored in each word.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void if2_to_ets(
+ enum Frame_Type_3GPP frame_type_3gpp,
+ UWord8 *if2_input_ptr,
+ Word16 *ets_output_ptr)
+{
+
+ Word16 i;
+ Word16 j;
+ Word16 x = 0;
+
+ /*
+ * The following section of code accesses bits in the IF2 method of
+ * bit ordering. Each bit is given its own location in the buffer pointed
+ * to by ets_output_ptr. The bits (for modes less than AMR_SID) are
+ * reordered using the tables in bitreorder.c before the data is stored
+ * into the buffer pointed to by ets_output_ptr.
+ */
+
+ if (frame_type_3gpp < AMR_SID)
+ {
+ for (j = 4; j < 8; j++)
+ {
+ ets_output_ptr[reorderBits[frame_type_3gpp][x++]] =
+ (if2_input_ptr[0] >> j) & 0x01;
+ }
+ for (i = 1; i < numCompressedBytes[frame_type_3gpp]; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+ if (x >= numOfBits[frame_type_3gpp])
+ {
+ break;
+ }
+ ets_output_ptr[reorderBits[frame_type_3gpp][x++]] =
+ (if2_input_ptr[i] >> j) & 0x01;
+ }
+ }
+ }
+ else
+ {
+ for (j = 4; j < 8; j++)
+ {
+ ets_output_ptr[x++] =
+ (if2_input_ptr[0] >> j) & 0x01;
+ }
+ for (i = 1; i < numCompressedBytes[frame_type_3gpp]; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+ ets_output_ptr[x++] =
+ (if2_input_ptr[i] >> j) & 0x01;
+ }
+ }
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/if2_to_ets.h b/media/codecs/amrnb/dec/src/if2_to_ets.h
new file mode 100644
index 0000000..490565d
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/if2_to_ets.h
@@ -0,0 +1,124 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/include/src/if2_to_ets.h
+
+ Date: 01/22/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed mode to frame_type_3gpp
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the if2_to_ets function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef IF2_TO_ETS_H
+#define IF2_TO_ETS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "frame_type_3gpp.h"
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void if2_to_ets(enum Frame_Type_3GPP frame_type_3gpp,
+ UWord8 *if2_input_ptr,
+ Word16 *ets_output_ptr);
+
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/dec/src/int_lsf.cpp b/media/codecs/amrnb/dec/src/int_lsf.cpp
new file mode 100644
index 0000000..2ca30de
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/int_lsf.cpp
@@ -0,0 +1,315 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/int_lsf.c
+
+ Date: 04/20/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Put file into template and first pass at optimization.
+
+ Description: Made changes based on comments from the review meeting. Used
+ pointers instead of index addressing in the arrays.
+
+ Description: Added type definition to the input/output section. Fixed tabs.
+ Deleted pseudo-code.
+
+ Description: Synchronized file with UMTS versin 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Modified FOR loops to count down.
+ 2. Made some cosmetic changes in the Pseudo-code section.
+
+ Description: Changed to pass in overflow flag pointer to the add() routine.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "int_lsf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Int_lsf
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lsf_old = LSF vector at the 4th SF of past frame (Word16)
+ lsf_new = LSF vector at the 4th SF of present frame (Word16)
+ i_subfr = Current subframe (equal to 0,40,80 or 120) (Word16)
+ lsf_out = interpolated LSF parameters for current subframe (Word16)
+
+ Outputs:
+ lsf_out = new interpolated LSF parameters for current subframe
+ pOverflow = pointer of type Flag * to overflow indicator.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function interpolates the LSFs for selected subframe.
+ The 20 ms speech frame is divided into 4 subframes. The LSFs are
+ interpolated at the 1st, 2nd and 3rd subframe and only forwarded
+ at the 4th subframe.
+
+ |------|------|------|------|
+ sf1 sf2 sf3 sf4
+ F0 F1
+
+ sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1
+ sf2: 1/2 F0 + 1/2 F1 sf4: F1
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ int_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Int_lsf(
+ Word16 lsf_old[], // i : LSF vector at the 4th SF of past frame
+ Word16 lsf_new[], // i : LSF vector at the 4th SF of present frame
+ Word16 i_subfr, // i : Pointer to current sf (equal to 0,40,80 or 120)
+ Word16 lsf_out[] // o : interpolated LSF parameters for current sf
+)
+{
+ Word16 i;
+
+ if ( i_subfr == 0 )
+ {
+ for (i = 0; i < M; i++) {
+ lsf_out[i] = add(sub(lsf_old[i], shr(lsf_old[i], 2)),
+ shr(lsf_new[i], 2));
+ }
+ }
+ else if ( sub(i_subfr, 40) == 0 )
+ {
+ for (i = 0; i < M; i++) {
+ lsf_out[i] = add(shr(lsf_old[i],1), shr(lsf_new[i], 1) );
+ }
+ }
+ else if ( sub(i_subfr, 80) == 0 )
+ {
+ for (i = 0; i < M; i++) {
+ lsf_out[i] = add(shr(lsf_old[i], 2),
+ sub(lsf_new[i], shr(lsf_new[i], 2)));
+ }
+ }
+ else if ( sub(i_subfr, 120) == 0 )
+ {
+ for (i = 0; i < M; i++) {
+ lsf_out[i] = lsf_new[i];
+ }
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Int_lsf(
+ Word16 lsf_old[], /* i : LSF vector at the 4th SF of past frame */
+ Word16 lsf_new[], /* i : LSF vector at the 4th SF of present frame */
+ Word16 i_subfr, /* i : Current sf (equal to 0,40,80 or 120) */
+ Word16 lsf_out[], /* o : interpolated LSF parameters for current sf */
+ Flag *pOverflow /* o : flag set if overflow occurs */
+)
+{
+ Word16 i;
+ Word16 temp1;
+ Word16 temp2;
+
+ if (i_subfr == 0)
+ {
+ for (i = M - 1; i >= 0; i--)
+ {
+ if (*(lsf_old + i) < 0)
+ {
+ temp1 = ~(~(*(lsf_old + i)) >> 2);
+ }
+ else
+ {
+ temp1 = *(lsf_old + i) >> 2;
+ }
+ if (*(lsf_new + i) < 0)
+ {
+ temp2 = ~(~(*(lsf_new + i)) >> 2);
+ }
+ else
+ {
+ temp2 = *(lsf_new + i) >> 2;
+ }
+ *(lsf_out + i) = add((Word16)(*(lsf_old + i) - temp1),
+ (Word16)temp2,
+ pOverflow);
+ }
+ }
+
+ else if (i_subfr == 40)
+ {
+ for (i = M - 1; i >= 0; i--)
+ {
+ if (*(lsf_old + i) < 0)
+ {
+ temp1 = ~(~(*(lsf_old + i)) >> 1);
+ }
+ else
+ {
+ temp1 = *(lsf_old + i) >> 1;
+ }
+ if (*(lsf_new + i) < 0)
+ {
+ temp2 = ~(~(*(lsf_new + i)) >> 1);
+ }
+ else
+ {
+ temp2 = *(lsf_new + i) >> 1;
+ }
+ *(lsf_out + i) = add(
+ temp1,
+ temp2,
+ pOverflow);
+ }
+ }
+
+ else if (i_subfr == 80)
+ {
+ for (i = M - 1; i >= 0; i--)
+ {
+ if (*(lsf_old + i) < 0)
+ {
+ temp1 = ~(~(*(lsf_old + i)) >> 2);
+ }
+ else
+ {
+ temp1 = *(lsf_old + i) >> 2;
+ }
+ if (*(lsf_new + i) < 0)
+ {
+ temp2 = ~(~(*(lsf_new + i)) >> 2);
+ }
+ else
+ {
+ temp2 = *(lsf_new + i) >> 2;
+ }
+ *(lsf_out + i) = add((Word16)temp1,
+ (Word16)(*(lsf_new + i) - temp2),
+ pOverflow);
+
+ }
+ }
+
+ else if (i_subfr == 120)
+ {
+ for (i = M - 1; i >= 0; i--)
+ {
+ *(lsf_out + i) = *(lsf_new + i);
+ }
+ }
+
+ return;
+}
+
diff --git a/media/codecs/amrnb/dec/src/lsp_avg.cpp b/media/codecs/amrnb/dec/src/lsp_avg.cpp
new file mode 100644
index 0000000..9b65c7a
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/lsp_avg.cpp
@@ -0,0 +1,317 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/lsp_avg.c
+ Functions:
+
+
+ Date: 04/14/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Removed the functions lsp_avg_init and lsp_avg_exit.
+ The lsp_avg related structure is no longer dynamically allocated.
+
+ Also, placed code in the proper PV Software Template.
+
+ Description: Per review comments, updated the inputs/outputs section
+ for the function lsp_avg.
+
+ Description: Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Per review comments, I added a description of pOverflow
+ to the input/output section of the template. I also removed an unnecessary
+ include file, <stdio.h>
+
+ Description: Removed q_plsf_5.tab from Include section and added
+ q_plsf_5_tbl.h to Include section. Changed "mean_lsf"
+ to "mean_lsf_5" in lsp_avg_reset().
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ LSP averaging and history
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "lsp_avg.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "copy.h"
+#include "q_plsf_5_tbl.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lsp_avg_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structure of type lsp_avgState
+
+ Outputs:
+ fields of the structure pointed to by state are initialized.
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+lsp_avg.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int lsp_avg_reset (lsp_avgState *st)
+{
+ if (st == (lsp_avgState *) NULL){
+ // fprintf(stderr, "lsp_avg_reset: invalid parameter\n");
+ return -1;
+ }
+
+ Copy(mean_lsf, &st->lsp_meanSave[0], M);
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 lsp_avg_reset(lsp_avgState *st)
+{
+ if (st == (lsp_avgState *) NULL)
+ {
+ /* fprintf(stderr, "lsp_avg_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ Copy(mean_lsf_5, &st->lsp_meanSave[0], M);
+
+ return 0;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lsp_avg
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structure of type lsp_avgState
+ lsp = pointer to Word16, which reflects the state of the state machine
+
+ Outputs:
+ st = pointer to structure of type lsp_avgState
+ pOverflow = pointer to type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+lsp_avg.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+void lsp_avg (
+ lsp_avgState *st, // i/o : State struct Q15
+ Word16 *lsp // i : state of the state machine Q15
+)
+{
+ Word16 i;
+ Word32 L_tmp; // Q31
+
+ for (i = 0; i < M; i++) {
+
+ // mean = 0.84*mean
+ L_tmp = L_deposit_h(st->lsp_meanSave[i]);
+ L_tmp = L_msu(L_tmp, EXPCONST, st->lsp_meanSave[i]);
+
+ // Add 0.16 of newest LSPs to mean
+ L_tmp = L_mac(L_tmp, EXPCONST, lsp[i]);
+
+ // Save means
+ st->lsp_meanSave[i] = pv_round(L_tmp); // Q15
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void lsp_avg(
+ lsp_avgState *st, /* i/o : State struct Q15 */
+ Word16 *lsp, /* i : state of the state machine Q15 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word32 L_tmp; /* Q31 */
+
+ for (i = 0; i < M; i++)
+ {
+
+ /* mean = 0.84*mean */
+ L_tmp = L_deposit_h(st->lsp_meanSave[i]);
+ L_tmp = L_msu(L_tmp, EXPCONST, st->lsp_meanSave[i], pOverflow);
+
+ /* Add 0.16 of newest LSPs to mean */
+ L_tmp = L_mac(L_tmp, EXPCONST, lsp[i], pOverflow);
+
+ /* Save means */
+ st->lsp_meanSave[i] = pv_round(L_tmp, pOverflow); /* Q15 */
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/lsp_avg.h b/media/codecs/amrnb/dec/src/lsp_avg.h
new file mode 100644
index 0000000..b289c08
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/lsp_avg.h
@@ -0,0 +1,136 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/lsp_avg.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Per review comments, I removed the prototype definition
+ of lsp_avg_init and lsp_avg_exit.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the lsp_avg.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef lsp_avg_h
+#define lsp_avg_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define EXPCONST 5243 /* 0.16 in Q15 */
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 lsp_meanSave[M]; /* Averaged LSPs saved for efficiency */
+ } lsp_avgState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word16 lsp_avg_reset(
+ lsp_avgState *state
+ );
+
+
+ void lsp_avg(
+ lsp_avgState *st, /* i/o : State struct Q15 */
+ Word16 *lsp, /* i : LSP vector Q15 */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LSP_LSF_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/ph_disp.cpp b/media/codecs/amrnb/dec/src/ph_disp.cpp
new file mode 100644
index 0000000..285465f
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/ph_disp.cpp
@@ -0,0 +1,898 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/ph_disp.c
+ Functions:
+ ph_disp_reset
+ ph_disp_lock
+ ph_disp_release
+ ph_disp
+
+ Date: 04/05/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Updated file per comments gathered from Phase 2/3 review.
+
+ Description: Clarified grouping in the equation to calculated L_temp from the
+ product of state->prevCbGain and ONFACTPLUS1 in the ph_disp
+ function.
+
+ Description: Added setting of Overflow flag in inlined code.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ coding template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h with the header file of the math functions
+ used in the file.
+
+ Description: Removed the functions ph_disp_init and ph_disp_exit.
+ The ph_disp related structure is no longer dynamically allocated.
+
+ Description: Pass in pointer to overflow flag for EPOC compatibility.
+ Change code for ph_disp() function to reflect this. Remove
+ inclusion of ph_disp.tab. This table will now be referenced
+ externally.
+
+ Description: Optimized ph_disp() to reduce clock cycle usage. Updated
+ copyright year and removed unused files in Include section.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with defined types.
+ Added proper casting (Word32) to some left shifting operations
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the function that performs adaptive phase dispersion of
+ the excitation signal. The phase dispersion initialization, reset, and
+ exit functions are included in this file, as well as, the phase dispersion
+ lock and release functions.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "ph_disp.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ph_disp_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type ph_dispState
+
+ Outputs:
+ Structure pointed to by state is initialized to zeros
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets the variables used by the phase dispersion function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ph_disp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int ph_disp_reset (ph_dispState *state)
+{
+ Word16 i;
+
+ if (state == (ph_dispState *) NULL){
+ fprint(stderr, "ph_disp_reset: invalid parameter\n");
+ return -1;
+ }
+ for (i=0; i<PHDGAINMEMSIZE; i++)
+ {
+ state->gainMem[i] = 0;
+ }
+ state->prevState = 0;
+ state->prevCbGain = 0;
+ state->lockFull = 0;
+ state->onset = 0; // assume no onset in start
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 ph_disp_reset(ph_dispState *state)
+{
+ Word16 i;
+
+ if (state == (ph_dispState *) NULL)
+ {
+ /* fprint(stderr, "ph_disp_reset: invalid parameter\n"); */
+ return(-1);
+ }
+ for (i = 0; i < PHDGAINMEMSIZE; i++)
+ {
+ state->gainMem[i] = 0;
+ }
+ state->prevState = 0;
+ state->prevCbGain = 0;
+ state->lockFull = 0;
+ state->onset = 0; /* assume no onset in start */
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ph_disp_lock
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type ph_dispState
+
+ Outputs:
+ lockFull field of the structure pointed to by state is set to 1
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function sets the lockFull flag to indicate a lock condition.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ph_disp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void ph_disp_lock (ph_dispState *state)
+{
+ state->lockFull = 1;
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void ph_disp_lock(ph_dispState *state)
+{
+ state->lockFull = 1;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ph_disp_release
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type ph_dispState
+
+ Outputs:
+ lockFull field of the structure pointed to by state is set to 0
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function clears the lockFull flag to indicate an unlocked state.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ph_disp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void ph_disp_release (ph_dispState *state)
+{
+ state->lockFull = 0;
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void ph_disp_release(ph_dispState *state)
+{
+ state->lockFull = 0;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ph_disp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type ph_dispState
+ mode = codec mode (enum Mode)
+ x = LTP excitation signal buffer (Word16)
+ cbGain = codebook gain (Word16)
+ ltpGain = LTP gain (Word16)
+ inno = innovation buffer (Word16)
+ pitch_fac = pitch factor used to scale the LTP excitation (Word16)
+ tmp_shift = shift factor applied to sum of scaled LTP excitation and
+ innovation before rounding (Word16)
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ structure pointed to by state contains the updated gainMem array,
+ prevState, prevCbGain, and onset fields
+ x buffer contains the new excitation signal
+ inno buffer contains the new innovation signal
+ pOverflow -> 1 if there is overflow
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs adaptive phase dispersion, i.e., forming of total
+ excitation for the synthesis part of the decoder.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ph_disp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void ph_disp (
+ ph_dispState *state, // i/o : State struct
+ enum Mode mode, // i : codec mode
+ Word16 x[], // i/o Q0 : in: LTP excitation signal
+ // out: total excitation signal
+ Word16 cbGain, // i Q1 : Codebook gain
+ Word16 ltpGain, // i Q14 : LTP gain
+ Word16 inno[], // i/o Q13 : Innovation vector (Q12 for 12.2)
+ Word16 pitch_fac, // i Q14 : pitch factor used to scale the
+ LTP excitation (Q13 for 12.2)
+ Word16 tmp_shift // i Q0 : shift factor applied to sum of
+ scaled LTP ex & innov. before
+ rounding
+)
+{
+ Word16 i, i1;
+ Word16 tmp1;
+ Word32 L_temp;
+ Word16 impNr; // indicator for amount of disp./filter used
+
+ Word16 inno_sav[L_SUBFR];
+ Word16 ps_poss[L_SUBFR];
+ Word16 j, nze, nPulse, ppos;
+ const Word16 *ph_imp; // Pointer to phase dispersion filter
+
+ // Update LTP gain memory
+ for (i = PHDGAINMEMSIZE-1; i > 0; i--)
+ {
+ state->gainMem[i] = state->gainMem[i-1];
+ }
+ state->gainMem[0] = ltpGain;
+
+ // basic adaption of phase dispersion
+ if (sub(ltpGain, PHDTHR2LTP) < 0) { // if (ltpGain < 0.9)
+ if (sub(ltpGain, PHDTHR1LTP) > 0)
+ { // if (ltpGain > 0.6
+ impNr = 1; // medium dispersion
+ }
+ else
+ {
+ impNr = 0; // maximum dispersion
+ }
+ }
+ else
+ {
+ impNr = 2; // no dispersion
+ }
+
+ // onset indicator
+ // onset = (cbGain > onFact * cbGainMem[0])
+ tmp1 = pv_round(L_shl(L_mult(state->prevCbGain, ONFACTPLUS1), 2));
+ if (sub(cbGain, tmp1) > 0)
+ {
+ state->onset = ONLENGTH;
+ }
+ else
+ {
+ if (state->onset > 0)
+ {
+ state->onset = sub (state->onset, 1);
+ }
+ }
+
+ // if not onset, check ltpGain buffer and use max phase dispersion if
+ half or more of the ltpGain-parameters say so
+ if (state->onset == 0)
+ {
+ // Check LTP gain memory and set filter accordingly
+ i1 = 0;
+ for (i = 0; i < PHDGAINMEMSIZE; i++)
+ {
+ if (sub(state->gainMem[i], PHDTHR1LTP) < 0)
+ {
+ i1 = add (i1, 1);
+ }
+ }
+ if (sub(i1, 2) > 0)
+ {
+ impNr = 0;
+ }
+
+ }
+ // Restrict decrease in phase dispersion to one step if not onset
+ if ((sub(impNr, add(state->prevState, 1)) > 0) && (state->onset == 0))
+ {
+ impNr = sub (impNr, 1);
+ }
+ // if onset, use one step less phase dispersion
+ if((sub(impNr, 2) < 0) && (state->onset > 0))
+ {
+ impNr = add (impNr, 1);
+ }
+
+ // disable for very low levels
+ if(sub(cbGain, 10) < 0)
+ {
+ impNr = 2;
+ }
+
+ if(sub(state->lockFull, 1) == 0)
+ {
+ impNr = 0;
+ }
+
+ // update static memory
+ state->prevState = impNr;
+ state->prevCbGain = cbGain;
+
+ // do phase dispersion for all modes but 12.2 and 7.4;
+ // don't modify the innovation if impNr >=2 (= no phase disp)
+ if (sub(mode, MR122) != 0 &&
+ sub(mode, MR102) != 0 &&
+ sub(mode, MR74) != 0 &&
+ sub(impNr, 2) < 0)
+ {
+ // track pulse positions, save innovation,
+ and initialize new innovation
+ nze = 0;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ if (inno[i] != 0)
+ {
+ ps_poss[nze] = i;
+ nze = add (nze, 1);
+ }
+ inno_sav[i] = inno[i];
+ inno[i] = 0;
+ }
+ // Choose filter corresponding to codec mode and dispersion criterium
+ if (sub (mode, MR795) == 0)
+ {
+ if (impNr == 0)
+ {
+ ph_imp = ph_imp_low_MR795;
+ }
+ else
+ {
+ ph_imp = ph_imp_mid_MR795;
+ }
+ }
+ else
+ {
+ if (impNr == 0)
+ {
+ ph_imp = ph_imp_low;
+ }
+ else
+ {
+ ph_imp = ph_imp_mid;
+ }
+ }
+
+ // Do phase dispersion of innovation
+ for (nPulse = 0; nPulse < nze; nPulse++)
+ {
+ ppos = ps_poss[nPulse];
+
+ // circular convolution with impulse response
+ j = 0;
+ for (i = ppos; i < L_SUBFR; i++)
+ {
+ // inno[i1] += inno_sav[ppos] * ph_imp[i1-ppos]
+ tmp1 = mult(inno_sav[ppos], ph_imp[j++]);
+ inno[i] = add(inno[i], tmp1);
+ }
+
+ for (i = 0; i < ppos; i++)
+ {
+ // inno[i] += inno_sav[ppos] * ph_imp[L_SUBFR-ppos+i]
+ tmp1 = mult(inno_sav[ppos], ph_imp[j++]);
+ inno[i] = add(inno[i], tmp1);
+ }
+ }
+ }
+
+ // compute total excitation for synthesis part of decoder
+ // (using modified innovation if phase dispersion is active)
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ // x[i] = gain_pit*x[i] + cbGain*code[i];
+ L_temp = L_mult ( x[i], pitch_fac);
+ // 12.2: Q0 * Q13
+ // 7.4: Q0 * Q14
+ L_temp = L_mac (L_temp, inno[i], cbGain);
+ // 12.2: Q12 * Q1
+ // 7.4: Q13 * Q1
+ L_temp = L_shl (L_temp, tmp_shift); // Q16
+ x[i] = pv_round (L_temp);
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void ph_disp(
+ ph_dispState *state, /* i/o : State struct */
+ enum Mode mode, /* i : codec mode */
+ Word16 x[], /* i/o Q0 : in: LTP excitation signal */
+ /* out: total excitation signal */
+ Word16 cbGain, /* i Q1 : Codebook gain */
+ Word16 ltpGain, /* i Q14 : LTP gain */
+ Word16 inno[], /* i/o Q13 : Innovation vector (Q12 for 12.2) */
+ Word16 pitch_fac, /* i Q14 : pitch factor used to scale the
+ LTP excitation (Q13 for 12.2) */
+ Word16 tmp_shift, /* i Q0 : shift factor applied to sum of
+ scaled LTP ex & innov. before
+ rounding */
+ Flag *pOverflow /* i/o : oveflow indicator */
+)
+{
+ Word16 i, i1;
+ Word16 tmp1;
+ Word32 L_temp;
+ Word32 L_temp2;
+ Word16 impNr; /* indicator for amount of disp./filter used */
+
+ Word16 inno_sav[L_SUBFR];
+ Word16 ps_poss[L_SUBFR];
+ Word16 nze, nPulse;
+ Word16 ppos;
+ const Word16 *ph_imp; /* Pointer to phase dispersion filter */
+
+ Word16 *p_inno;
+ Word16 *p_inno_sav;
+ Word16 *p_x;
+ const Word16 *p_ph_imp;
+ Word16 c_inno_sav;
+
+ /* Update LTP gain memory */
+ /* Unrolled FOR loop below since PHDGAINMEMSIZE is assumed to stay */
+ /* the same. */
+ /* for (i = PHDGAINMEMSIZE-1; i > 0; i--) */
+ /* { */
+ /* state->gainMem[i] = state->gainMem[i-1]; */
+ /* } */
+ state->gainMem[4] = state->gainMem[3];
+ state->gainMem[3] = state->gainMem[2];
+ state->gainMem[2] = state->gainMem[1];
+ state->gainMem[1] = state->gainMem[0];
+ state->gainMem[0] = ltpGain;
+
+ /* basic adaption of phase dispersion */
+
+ if (ltpGain < PHDTHR2LTP) /* if (ltpGain < 0.9) */
+ {
+ if (ltpGain > PHDTHR1LTP)
+ { /* if (ltpGain > 0.6 */
+ impNr = 1; /* medium dispersion */
+ }
+ else
+ {
+ impNr = 0; /* maximum dispersion */
+ }
+ }
+ else
+ {
+ impNr = 2; /* no dispersion */
+ }
+
+ /* onset indicator */
+ /* onset = (cbGain > onFact * cbGainMem[0]) */
+
+ L_temp = ((Word32) state->prevCbGain * ONFACTPLUS1) << 1;
+
+ /* (L_temp << 2) calculation with saturation check */
+ if (L_temp > (Word32) 0X1fffffffL)
+ {
+ *pOverflow = 1;
+ L_temp = MAX_32;
+ }
+ else if (L_temp < (Word32) 0xe0000000L)
+ {
+ *pOverflow = 1;
+ L_temp = MIN_32;
+ }
+ else
+ {
+ L_temp <<= 2;
+ }
+
+ tmp1 = pv_round(L_temp, pOverflow);
+
+ if (cbGain > tmp1)
+ {
+ state->onset = ONLENGTH;
+ }
+ else
+ {
+
+ if (state->onset > 0)
+ {
+ state->onset -= 1;
+ }
+ }
+
+ /* if not onset, check ltpGain buffer and use max phase dispersion if
+ half or more of the ltpGain-parameters say so */
+ if (state->onset == 0)
+ {
+ /* Check LTP gain memory and set filter accordingly */
+ i1 = 0;
+ for (i = 0; i < PHDGAINMEMSIZE; i++)
+ {
+ if (state->gainMem[i] < PHDTHR1LTP)
+ {
+ i1 += 1;
+ }
+ }
+
+ if (i1 > 2)
+ {
+ impNr = 0;
+ }
+ }
+ /* Restrict decrease in phase dispersion to one step if not onset */
+ if ((impNr > ((state->prevState) + 1)) && (state->onset == 0))
+ {
+ impNr -= 1;
+ }
+
+ /* if onset, use one step less phase dispersion */
+ if ((impNr < 2) && (state->onset > 0))
+ {
+ impNr += 1;
+ }
+
+ /* disable for very low levels */
+ if (cbGain < 10)
+ {
+ impNr = 2;
+ }
+
+ if (state->lockFull == 1)
+ {
+ impNr = 0;
+ }
+
+ /* update static memory */
+ state->prevState = impNr;
+ state->prevCbGain = cbGain;
+
+ /* do phase dispersion for all modes but 12.2 and 7.4;
+ don't modify the innovation if impNr >=2 (= no phase disp) */
+ if ((mode != MR122) && (mode != MR102) && (mode != MR74) && (impNr < 2))
+ {
+ /* track pulse positions, save innovation,
+ and initialize new innovation */
+ nze = 0;
+ p_inno = &inno[0];
+ p_inno_sav = &inno_sav[0];
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ if (*(p_inno) != 0)
+ {
+ ps_poss[nze] = i;
+ nze += 1;
+ }
+ *(p_inno_sav++) = *(p_inno);
+ *(p_inno++) = 0;
+ }
+
+ /* Choose filter corresponding to codec mode and dispersion criterium */
+ if (mode == MR795)
+ {
+ if (impNr == 0)
+ {
+ ph_imp = ph_imp_low_MR795;
+ }
+ else
+ {
+ ph_imp = ph_imp_mid_MR795;
+ }
+ }
+ else
+ {
+ if (impNr == 0)
+ {
+ ph_imp = ph_imp_low;
+ }
+ else
+ {
+ ph_imp = ph_imp_mid;
+ }
+ }
+
+ /* Do phase dispersion of innovation */
+ for (nPulse = 0; nPulse < nze; nPulse++)
+ {
+ ppos = ps_poss[nPulse];
+
+ /* circular convolution with impulse response */
+ c_inno_sav = inno_sav[ppos];
+ p_inno = &inno[ppos];
+ p_ph_imp = ph_imp;
+
+ for (i = ppos; i < L_SUBFR; i++)
+ {
+ /* inno[i1] += inno_sav[ppos] * ph_imp[i1-ppos] */
+ L_temp = ((Word32) c_inno_sav * *(p_ph_imp++)) >> 15;
+ tmp1 = (Word16) L_temp;
+ *(p_inno) = add(*(p_inno), tmp1, pOverflow);
+ p_inno += 1;
+ }
+
+ p_inno = &inno[0];
+
+ for (i = 0; i < ppos; i++)
+ {
+ /* inno[i] += inno_sav[ppos] * ph_imp[L_SUBFR-ppos+i] */
+ L_temp = ((Word32) c_inno_sav * *(p_ph_imp++)) >> 15;
+ tmp1 = (Word16) L_temp;
+ *(p_inno) = add(*(p_inno), tmp1, pOverflow);
+ p_inno += 1;
+ }
+ }
+ }
+
+ /* compute total excitation for synthesis part of decoder
+ (using modified innovation if phase dispersion is active) */
+ p_inno = &inno[0];
+ p_x = &x[0];
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ /* x[i] = gain_pit*x[i] + cbGain*code[i]; */
+ L_temp = L_mult(x[i], pitch_fac, pOverflow);
+ /* 12.2: Q0 * Q13 */
+ /* 7.4: Q0 * Q14 */
+ L_temp2 = ((Word32) * (p_inno++) * cbGain) << 1;
+ L_temp = L_add(L_temp, L_temp2, pOverflow);
+ /* 12.2: Q12 * Q1 */
+ /* 7.4: Q13 * Q1 */
+ L_temp = L_shl(L_temp, tmp_shift, pOverflow); /* Q16 */
+ *(p_x++) = pv_round(L_temp, pOverflow);
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/ph_disp.h b/media/codecs/amrnb/dec/src/ph_disp.h
new file mode 100644
index 0000000..58e2e4f
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/ph_disp.h
@@ -0,0 +1,192 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/ph_disp.h
+
+
+ Date: 08/11/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Updated function prototype declaration for
+ ph_disp(). Included extern declaration for ph_imp_low_MR795 and
+ ph_imp_mid_MR795
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the Phase dispersion of excitation signal ph_disp() function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PH_DISP_H
+#define PH_DISP_H "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define PHDGAINMEMSIZE 5
+#define PHDTHR1LTP 9830 /* 0.6 in Q14 */
+#define PHDTHR2LTP 14746 /* 0.9 in Q14 */
+#define ONFACTPLUS1 16384 /* 2.0 in Q13 */
+#define ONLENGTH 2
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern Word16 ph_imp_low_MR795[];
+ extern Word16 ph_imp_mid_MR795[];
+ extern Word16 ph_imp_low[];
+ extern Word16 ph_imp_mid[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 gainMem[PHDGAINMEMSIZE];
+ Word16 prevState;
+ Word16 prevCbGain;
+ Word16 lockFull;
+ Word16 onset;
+ } ph_dispState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function: ph_disp_reset
+ ; Purpose: Initializes state memory
+ ;
+ ----------------------------------------------------------------------------*/
+ Word16 ph_disp_reset(ph_dispState *state);
+
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function: ph_disp_exit
+ ; Purpose: The memory used for state memory is freed
+ ;
+ ----------------------------------------------------------------------------*/
+ void ph_disp_exit(ph_dispState **state);
+
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function: ph_disp_lock
+ ; Purpose: mark phase dispersion as locked in state struct
+ ;
+ ----------------------------------------------------------------------------*/
+ void ph_disp_lock(ph_dispState *state);
+
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function: ph_disp_release
+ ; Purpose: mark phase dispersion as unlocked in state struct
+ ;
+ ----------------------------------------------------------------------------*/
+
+ void ph_disp_release(ph_dispState *state);
+
+ /*----------------------------------------------------------------------------
+ ;
+ ; Function: ph_disp
+ ; Purpose: perform phase dispersion according to the specified codec
+ ; mode and computes total excitation for synthesis part
+ ; if decoder
+ ;
+ ----------------------------------------------------------------------------*/
+
+ void ph_disp(
+ ph_dispState *state, /* i/o : State struct */
+ enum Mode mode, /* i : codec mode */
+ Word16 x[], /* i/o Q0 : in: LTP excitation signal */
+ /* out: total excitation signal */
+ Word16 cbGain, /* i Q1 : Codebook gain */
+ Word16 ltpGain, /* i Q14 : LTP gain */
+ Word16 inno[], /* i/o Q13 : Innovation vector (Q12 for 12.2) */
+ Word16 pitch_fac, /* i Q14 : pitch factor used to scale the
+ LTP excitation (Q13 for 12.2) */
+ Word16 tmp_shift, /* i Q0 : shift factor applied to sum of
+ scaled LTP ex & innov. before
+ rounding */
+ Flag *pOverflow /* i/o : oveflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PH_DISP_H_ */
+
diff --git a/media/codecs/amrnb/dec/src/post_pro.cpp b/media/codecs/amrnb/dec/src/post_pro.cpp
new file mode 100644
index 0000000..8201e54
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/post_pro.cpp
@@ -0,0 +1,395 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/post_pro.c
+ Functions:
+ Post_Process_reset
+ Post_Process
+
+ Date: 04/03/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Deleted variables listed in the Local Stores Needed/Modified
+ sections. Optimized the "else" portion of the first "if"
+ statement in Post_Process function.
+
+ Description: Made grouping more explicit in the calculation of
+ signal[i] << 1 in the Post_Process function.
+
+ Description: Added setting of Overflow flag in inlined code.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h with the header file of the math functions
+ used in the file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Updated copyright year.
+ 2. Fixed typecasting issue with TI C compiler.
+ 3. Used short-hand notation for math operations, e.g., "+=",
+ in the code.
+
+ Description: Removed the functions post_pro_init and post_pro_exit.
+ The post_pro related structure is no longer dynamically allocated.
+
+ Description: Added pOverflow as a passed in variable as per changes needed
+ for the EPOC release.
+
+ Description: Optimized file to reduce clock cycle usage. Updated copyright
+ year and removed unused files in Include section.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the function that performs post-processing on the output
+ speech. Post-processing include filtering the output speech through a second
+ order high pass filter with cutoff frequency of 60 Hz, and up-scaling the
+ output speech by a factor of 2. In addition to the post-processing function
+ itself, a post-processing initialization function, post-processing reset
+ function, and post-processing exit function are also included in this file.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "post_pro.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* filter coefficients (fc = 60 Hz) */
+static const Word16 b[3] = {7699, -15398, 7699};
+static const Word16 a[3] = {8192, 15836, -7667};
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Post_Process_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type Post_ProcessState
+
+ Outputs:
+ structure pointed to by state will have all its fields initialized
+ to zero
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes state memory to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ post_pro.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Post_Process_reset (Post_ProcessState *state)
+{
+ if (state == (Post_ProcessState *) NULL){
+ fprint(stderr, "Post_Process_reset: invalid parameter\n");
+ return -1;
+ }
+
+ state->y2_hi = 0;
+ state->y2_lo = 0;
+ state->y1_hi = 0;
+ state->y1_lo = 0;
+ state->x0 = 0;
+ state->x1 = 0;
+
+ return 0;
+}
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Post_Process_reset(Post_ProcessState *state)
+{
+ if (state == (Post_ProcessState *) NULL)
+ {
+ /* fprint(stderr, "Post_Process_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ state->y2_hi = 0;
+ state->y2_lo = 0;
+ state->y1_hi = 0;
+ state->y1_lo = 0;
+ state->x0 = 0;
+ state->x1 = 0;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Post_Process
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type Post_ProcessState
+ signal = buffer containing the input signal (Word16)
+ lg = length of the input signal (Word16)
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ structure pointed to by st contains new filter input and output values
+ signal buffer contains the HP filtered and up-scaled input signal
+ pOverflow points to 1 if overflow occurs in the math functions called
+ else it points to 0.
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ a = buffer containing filter coefficients
+ b = buffer containing filter coefficients
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs post-processing on the output speech signal. First,
+ the output speech goes through a second order high pass filter with a
+ cutoff frequency of 60 Hz. Then, the filtered output speech is multiplied
+ by a factor of 2. The algorithm implemented follows the following difference
+ equation:
+
+ y[i] = b[0]*x[i]*2 + b[1]*x[i-1]*2 + b[2]*x[i-2]*2 + a[1]*y[i-1] + a[2]*y[i-2];
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ post_pro.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Post_Process (
+ Post_ProcessState *st, //i/o : post process state
+ Word16 signal[], //i/o : signal
+ Word16 lg //i : length of signal
+ )
+{
+ Word16 i, x2;
+ Word32 L_tmp;
+
+ for (i = 0; i < lg; i++)
+ {
+ x2 = st->x1;
+ st->x1 = st->x0;
+ st->x0 = signal[i];
+
+ // y[i] = b[0]*x[i]*2 + b[1]*x[i-1]*2 + b140[2]*x[i-2]/2
+ // + a[1]*y[i-1] + a[2] * y[i-2];
+
+ L_tmp = Mpy_32_16 (st->y1_hi, st->y1_lo, a[1]);
+ L_tmp = L_add (L_tmp, Mpy_32_16 (st->y2_hi, st->y2_lo, a[2]));
+ L_tmp = L_mac (L_tmp, st->x0, b[0]);
+ L_tmp = L_mac (L_tmp, st->x1, b[1]);
+ L_tmp = L_mac (L_tmp, x2, b[2]);
+ L_tmp = L_shl (L_tmp, 2);
+
+ //Multiplication by two of output speech with saturation.
+ signal[i] = pv_round(L_shl(L_tmp, 1));
+
+ st->y2_hi = st->y1_hi;
+ st->y2_lo = st->y1_lo;
+ L_Extract (L_tmp, &st->y1_hi, &st->y1_lo);
+ }
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Post_Process(
+ Post_ProcessState *st, /* i/o : post process state */
+ Word16 signal[], /* i/o : signal */
+ Word16 lg, /* i : length of signal */
+ Flag *pOverflow
+)
+{
+ Word16 i, x2;
+ Word32 L_tmp;
+
+ Word16 *p_signal;
+ Word16 c_a1 = a[1];
+ Word16 c_a2 = a[2];
+ Word16 c_b0 = b[0];
+ Word16 c_b1 = b[1];
+ Word16 c_b2 = b[2];
+
+ p_signal = &signal[0];
+
+ for (i = 0; i < lg; i++)
+ {
+ x2 = st->x1;
+ st->x1 = st->x0;
+ st->x0 = *(p_signal);
+
+ /* y[i] = b[0]*x[i]*2 + b[1]*x[i-1]*2 + b140[2]*x[i-2]/2 */
+ /* + a[1]*y[i-1] + a[2] * y[i-2]; */
+
+ L_tmp = ((Word32) st->y1_hi) * c_a1;
+ L_tmp += (((Word32) st->y1_lo) * c_a1) >> 15;
+ L_tmp += ((Word32) st->y2_hi) * c_a2;
+ L_tmp += (((Word32) st->y2_lo) * c_a2) >> 15;
+ L_tmp += ((Word32) st->x0) * c_b0;
+ L_tmp += ((Word32) st->x1) * c_b1;
+ L_tmp += ((Word32) x2) * c_b2;
+ L_tmp = L_shl(L_tmp, 3, pOverflow);
+
+
+ /* Multiplication by two of output speech with saturation. */
+
+ *(p_signal++) = pv_round(L_shl(L_tmp, 1, pOverflow), pOverflow);
+
+ st->y2_hi = st->y1_hi;
+ st->y2_lo = st->y1_lo;
+
+ st->y1_hi = (Word16)(L_tmp >> 16);
+ st->y1_lo = (Word16)((L_tmp >> 1) - ((Word32) st->y1_hi << 15));
+
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/post_pro.h b/media/codecs/amrnb/dec/src/post_pro.h
new file mode 100644
index 0000000..85e5888
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/post_pro.h
@@ -0,0 +1,140 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/post_pro.h
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : post_pro.h
+ Purpose : Postprocessing of output speech.
+
+ - 2nd order high pass filtering with cut
+ off frequency at 60 Hz.
+ - Multiplication of output by two.
+------------------------------------------------------------------------------
+*/
+
+#ifndef _POST_PRO_H_
+#define _POST_PRO_H_
+#define post_pro_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 y2_hi;
+ Word16 y2_lo;
+ Word16 y1_hi;
+ Word16 y1_lo;
+ Word16 x0;
+ Word16 x1;
+ } Post_ProcessState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ Word16 Post_Process_reset(Post_ProcessState *st);
+ /* reset of Post processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void Post_Process_exit(Post_ProcessState **st);
+ /* de-initialize Post processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void Post_Process(
+ Post_ProcessState *st, /* i/o : post process state */
+ Word16 signal[], /* i/o : signal */
+ Word16 lg, /* i : lenght of signal */
+ Flag *pOverflow
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _POST_PRO_H_ */
+
+
+
+
+
diff --git a/media/codecs/amrnb/dec/src/preemph.cpp b/media/codecs/amrnb/dec/src/preemph.cpp
new file mode 100644
index 0000000..9864325
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/preemph.cpp
@@ -0,0 +1,272 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/preemph.c
+ Functions:
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Removed the functions preemphasis_init and preemphasis_exit.
+ The preemphasis related structure is no longer dynamically allocated.
+ Placed file in the appropriate PV Software Template format.
+
+ Description: Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Purpose : Preemphasis filtering
+ Description : Filtering through 1 - g z^-1
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "preemph.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: preemphasis_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to preemphasisState
+
+ Outputs:
+ st -- double ponter to preemphasisState
+
+ Returns:
+ -1 if an error occurs
+ 0 if OK
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Initializes state memory to zero
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 preemphasis_reset(preemphasisState *state)
+{
+ if (state == (preemphasisState *) NULL)
+ {
+ /* fprintf(stderr, "preemphasis_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ state->mem_pre = 0;
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: preemphasis
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- Pointer to preemphasisState -- preemphasis filter state
+ signal -- array of type Word16 -- input signal overwritten by the output
+ g -- Word16 -- preemphasis coefficient
+ L -- Word16 -- size of filtering
+
+ Outputs:
+ st -- Pointer to preemphasisState -- preemphasis filter state
+ signal -- array of type Word16 -- input signal overwritten by the output
+ pOverflow -- pointer to type Flag -- overflow indicator
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Filtering through 1 - g z^-1
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+void preemphasis(
+ preemphasisState *st, /* (i/o) : preemphasis filter state */
+ Word16 *signal, /* (i/o) : input signal overwritten by the output */
+ Word16 g, /* (i) : preemphasis coefficient */
+ Word16 L, /* (i) : size of filtering */
+ Flag *pOverflow /* (o) : overflow indicator */
+)
+{
+ Word16 *p1;
+ Word16 *p2;
+ Word16 temp;
+ Word16 temp2;
+ Word16 i;
+
+ p1 = signal + L - 1;
+ p2 = p1 - 1;
+ temp = *p1;
+
+ for (i = 0; i <= L - 2; i++)
+ {
+ temp2 = mult(g, *(p2--), pOverflow);
+ *p1 = sub(*p1, temp2, pOverflow);
+
+ p1--;
+ }
+
+ temp2 = mult(g, st->mem_pre, pOverflow);
+
+ *p1 = sub(*p1, temp2, pOverflow);
+
+ st->mem_pre = temp;
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrnb/dec/src/preemph.h b/media/codecs/amrnb/dec/src/preemph.h
new file mode 100644
index 0000000..20bab71
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/preemph.h
@@ -0,0 +1,140 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/preemph.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, preemph.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef preemph_h
+#define preemph_h "$Id $"
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 mem_pre; /* filter state */
+ } preemphasisState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word16 preemphasis_reset(preemphasisState *st);
+ /* reset of preemphasis filter (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void preemphasis_exit(preemphasisState **st);
+ /* de-initialize preemphasis filter (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void preemphasis(
+ preemphasisState *st, /* (i/o): preemphasis filter state */
+ Word16 *signal, /* (i/o): input signal overwritten by the output */
+ Word16 g, /* (i) : preemphasis coefficient */
+ Word16 L, /* (i) : size of filtering */
+ Flag *pOverflow /* (o) : overflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* preemph_H_ */
+
+
diff --git a/media/codecs/amrnb/dec/src/pstfilt.cpp b/media/codecs/amrnb/dec/src/pstfilt.cpp
new file mode 100644
index 0000000..39e01a2
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/pstfilt.cpp
@@ -0,0 +1,578 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/pstfilt.c
+ Functions:
+ Post_Filter_reset
+ Post_Filter
+
+ Date: 04/14/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Updated file per comments gathered from Phase 2/3 review.
+
+ Description: Added setting of Overflow flag in inlined code.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h with the header file of the math functions
+ used in the file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Updated copyright year.
+ 2. Modified FOR loops to count down.
+ 3. Fixed typecasting issue with TI C compiler.
+ 4. Added "break" statement after overflow condition occurs.
+
+ Description: Removed the functions pstfilt_init and pstfilt_exit.
+ The pst_filt related structure is no longer dynamically allocated.
+
+ Description: Modified code for EPOC changes where pOverflow is passed in
+ rather than allowing overflow to be a global variable.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with defined types.
+ Added proper casting (Word32) to some left shifting operations
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the function that performs adaptive post-filtering on the
+ synthesized speech. It also contains the functions that initialize, reset,
+ and exit the post-filtering function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "pstfilt.h"
+#include "typedef.h"
+#include "mode.h"
+#include "basicop_malloc.h"
+#include "basic_op.h"
+#include "weight_a.h"
+#include "residu.h"
+#include "copy.h"
+#include "syn_filt.h"
+#include "preemph.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define L_H 22 /* size of truncated impulse response of A(z/g1)/A(z/g2) */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* Spectral expansion factors */
+static const Word16 gamma3_MR122[M] =
+{
+ 22938, 16057, 11240, 7868, 5508,
+ 3856, 2699, 1889, 1322, 925
+};
+
+static const Word16 gamma3[M] =
+{
+ 18022, 9912, 5451, 2998, 1649, 907, 499, 274, 151, 83
+};
+
+static const Word16 gamma4_MR122[M] =
+{
+ 24576, 18432, 13824, 10368, 7776,
+ 5832, 4374, 3281, 2461, 1846
+};
+
+static const Word16 gamma4[M] =
+{
+ 22938, 16057, 11240, 7868, 5508, 3856, 2699, 1889, 1322, 925
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Post_Filter_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to structure of type Post_FilterState
+
+ Outputs:
+ fields of the structure pointed to by state is initialized to zero
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes the state memory used by the Post_Filter function
+ to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pstfilt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Post_Filter_reset (Post_FilterState *state)
+{
+ if (state == (Post_FilterState *) NULL){
+ fprintf(stderr, "Post_Filter_reset: invalid parameter\n");
+ return -1;
+ }
+
+ Set_zero (state->mem_syn_pst, M);
+ Set_zero (state->res2, L_SUBFR);
+ Set_zero (state->synth_buf, L_FRAME + M);
+ agc_reset(state->agc_state);
+ preemphasis_reset(state->preemph_state);
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Post_Filter_reset(Post_FilterState *state)
+{
+ if (state == (Post_FilterState *) NULL)
+ {
+ /*fprintf(stderr, "Post_Filter_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ memset(state->mem_syn_pst, 0, sizeof(Word16)*M);
+ memset(state->res2, 0, sizeof(Word16)*L_SUBFR);
+ memset(state->synth_buf, 0, sizeof(Word16)*(L_FRAME + M));
+ agc_reset(&(state->agc_state));
+ preemphasis_reset(&(state->preemph_state));
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Post_Filter
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type Post_FilterState
+ mode = AMR mode
+ syn = pointer to a buffer containing synthesized speech; upon
+ exiting this function, it will contain the post-filtered
+ synthesized speech
+ Az_4 = pointer to the interpolated LPC parameters for all subframes
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ fields of the structure pointed to by st contains the updated field
+ values
+ syn buffer contains the post-filtered synthesized speech
+ pOverflow = 1 if overflow occurrs in the math functions called else
+ it is zero.
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs the post-filtering on the synthesized speech. The
+ post-filtering process is described as follows:
+ (1) inverse filtering of syn[] through A(z/0.7) to get res2[]
+ (2) tilt compensation filtering; 1 - MU*k*z^-1
+ (3) synthesis filtering through 1/A(z/0.75)
+ (4) adaptive gain control
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pstfilt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Post_Filter (
+ Post_FilterState *st, // i/o : post filter states
+ enum Mode mode, // i : AMR mode
+ Word16 *syn, // i/o : synthesis speech (postfiltered is output)
+ Word16 *Az_4 // i : interpolated LPC parameters in all subfr.
+)
+{
+ *-------------------------------------------------------------------*
+ * Declaration of parameters *
+ *-------------------------------------------------------------------*
+
+ Word16 Ap3[MP1], Ap4[MP1]; // bandwidth expanded LP parameters
+ Word16 *Az; // pointer to Az_4:
+ // LPC parameters in each subframe
+ Word16 i_subfr; // index for beginning of subframe
+ Word16 h[L_H];
+
+ Word16 i;
+ Word16 temp1, temp2;
+ Word32 L_tmp;
+ Word16 *syn_work = &st->synth_buf[M];
+
+
+ *-----------------------------------------------------*
+ * Post filtering *
+ *-----------------------------------------------------*
+
+ Copy (syn, syn_work , L_FRAME);
+
+ Az = Az_4;
+
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ // Find weighted filter coefficients Ap3[] and ap[4]
+
+ if (sub(mode, MR122) == 0 || sub(mode, MR102) == 0)
+ {
+ Weight_Ai (Az, gamma3_MR122, Ap3);
+ Weight_Ai (Az, gamma4_MR122, Ap4);
+ }
+ else
+ {
+ Weight_Ai (Az, gamma3, Ap3);
+ Weight_Ai (Az, gamma4, Ap4);
+ }
+
+ // filtering of synthesis speech by A(z/0.7) to find res2[]
+
+ Residu (Ap3, &syn_work[i_subfr], st->res2, L_SUBFR);
+
+ // tilt compensation filter
+
+ // impulse response of A(z/0.7)/A(z/0.75)
+
+ Copy (Ap3, h, M + 1);
+ Set_zero (&h[M + 1], L_H - M - 1);
+ Syn_filt (Ap4, h, h, L_H, &h[M + 1], 0);
+
+ // 1st correlation of h[]
+
+ L_tmp = L_mult (h[0], h[0]);
+ for (i = 1; i < L_H; i++)
+ {
+ L_tmp = L_mac (L_tmp, h[i], h[i]);
+ }
+ temp1 = extract_h (L_tmp);
+
+ L_tmp = L_mult (h[0], h[1]);
+ for (i = 1; i < L_H - 1; i++)
+ {
+ L_tmp = L_mac (L_tmp, h[i], h[i + 1]);
+ }
+ temp2 = extract_h (L_tmp);
+
+ if (temp2 <= 0)
+ {
+ temp2 = 0;
+ }
+ else
+ {
+ temp2 = mult (temp2, MU);
+ temp2 = div_s (temp2, temp1);
+ }
+
+ preemphasis (st->preemph_state, st->res2, temp2, L_SUBFR);
+
+ // filtering through 1/A(z/0.75)
+
+ Syn_filt (Ap4, st->res2, &syn[i_subfr], L_SUBFR, st->mem_syn_pst, 1);
+
+ // scale output to input
+
+ agc (st->agc_state, &syn_work[i_subfr], &syn[i_subfr],
+ AGC_FAC, L_SUBFR);
+
+ Az += MP1;
+ }
+
+ // update syn_work[] buffer
+
+ Copy (&syn_work[L_FRAME - M], &syn_work[-M], M);
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Post_Filter(
+ Post_FilterState *st, /* i/o : post filter states */
+ enum Mode mode, /* i : AMR mode */
+ Word16 *syn, /* i/o : synthesis speech (postfiltered is output) */
+ Word16 *Az_4, /* i : interpolated LPC parameters in all subfr. */
+ Flag *pOverflow
+)
+{
+ Word16 Ap3[MP1];
+ Word16 Ap4[MP1]; /* bandwidth expanded LP parameters */
+ Word16 *Az; /* pointer to Az_4: */
+ /* LPC parameters in each subframe */
+ Word16 i_subfr; /* index for beginning of subframe */
+ Word16 h[L_H];
+
+ Word16 i;
+ Word16 temp1;
+ Word16 temp2;
+ Word32 L_tmp;
+ Word32 L_tmp2;
+ Word16 *syn_work = &st->synth_buf[M];
+
+
+ /*-----------------------------------------------------*
+ * Post filtering *
+ *-----------------------------------------------------*/
+
+ Copy(syn, syn_work , L_FRAME);
+
+ Az = Az_4;
+
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ /* Find weighted filter coefficients Ap3[] and ap[4] */
+
+ if (mode == MR122 || mode == MR102)
+ {
+ Weight_Ai(Az, gamma3_MR122, Ap3);
+ Weight_Ai(Az, gamma4_MR122, Ap4);
+ }
+ else
+ {
+ Weight_Ai(Az, gamma3, Ap3);
+ Weight_Ai(Az, gamma4, Ap4);
+ }
+
+ /* filtering of synthesis speech by A(z/0.7) to find res2[] */
+
+ Residu(Ap3, &syn_work[i_subfr], st->res2, L_SUBFR);
+
+ /* tilt compensation filter */
+
+ /* impulse response of A(z/0.7)/A(z/0.75) */
+
+ Copy(Ap3, h, M + 1);
+ memset(&h[M + 1], 0, sizeof(Word16)*(L_H - M - 1));
+ Syn_filt(Ap4, h, h, L_H, &h[M + 1], 0);
+
+ /* 1st correlation of h[] */
+
+ L_tmp = 0;
+
+ for (i = L_H - 1; i >= 0; i--)
+ {
+ L_tmp2 = ((Word32) h[i]) * h[i];
+
+ if (L_tmp2 != (Word32) 0x40000000L)
+ {
+ L_tmp2 = L_tmp2 << 1;
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_tmp2 = MAX_32;
+ break;
+ }
+
+ L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
+ }
+ temp1 = (Word16)(L_tmp >> 16);
+
+ L_tmp = 0;
+
+ for (i = L_H - 2; i >= 0; i--)
+ {
+ L_tmp2 = ((Word32) h[i]) * h[i + 1];
+
+ if (L_tmp2 != (Word32) 0x40000000L)
+ {
+ L_tmp2 = L_tmp2 << 1;
+ }
+ else
+ {
+ *pOverflow = 1;
+ L_tmp2 = MAX_32;
+ break;
+ }
+
+ L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
+ }
+ temp2 = (Word16)(L_tmp >> 16);
+
+ if (temp2 <= 0)
+ {
+ temp2 = 0;
+ }
+ else
+ {
+ L_tmp = (((Word32) temp2) * MU) >> 15;
+
+ /* Sign-extend product */
+ if (L_tmp & (Word32) 0x00010000L)
+ {
+ L_tmp = L_tmp | (Word32) 0xffff0000L;
+ }
+ temp2 = (Word16) L_tmp;
+
+ temp2 = div_s(temp2, temp1);
+ }
+
+ preemphasis(&(st->preemph_state), st->res2, temp2, L_SUBFR, pOverflow);
+
+ /* filtering through 1/A(z/0.75) */
+
+ Syn_filt(Ap4, st->res2, &syn[i_subfr], L_SUBFR, st->mem_syn_pst, 1);
+
+ /* scale output to input */
+
+ agc(&(st->agc_state), &syn_work[i_subfr], &syn[i_subfr],
+ AGC_FAC, L_SUBFR, pOverflow);
+
+ Az += MP1;
+ }
+
+ /* update syn_work[] buffer */
+
+ Copy(&syn_work[L_FRAME - M], &syn_work[-M], M);
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/src/pstfilt.h b/media/codecs/amrnb/dec/src/pstfilt.h
new file mode 100644
index 0000000..29c0d84
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/pstfilt.h
@@ -0,0 +1,143 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/pstfilt.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : pstfilt.h
+ Purpose : Performs adaptive postfiltering on the synthesis
+ : speech
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _PSTFILT_H_
+#define _PSTFILT_H_
+#define pstfilt_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "cnst.h"
+#include "preemph.h"
+#include "agc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 res2[L_SUBFR];
+ Word16 mem_syn_pst[M];
+ preemphasisState preemph_state;
+ agcState agc_state;
+ Word16 synth_buf[M + L_FRAME];
+ } Post_FilterState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 Post_Filter_reset(Post_FilterState *st);
+ /* reset post filter (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void Post_Filter(
+ Post_FilterState *st, /* i/o : post filter states */
+ enum Mode mode, /* i : AMR mode */
+ Word16 *syn, /* i/o : synthesis speech (postfiltered is output) */
+ Word16 *Az_4, /* i : interpolated LPC parameters in all subfr. */
+ Flag *pOverflow
+ );
+ /* filters the signal syn using the parameters in Az_4 to calculate filter
+ coefficients.
+ The filter must be set up using Post_Filter_init prior to the first call
+ to Post_Filter. Post_FilterState is updated to mirror the current state
+ of the filter
+
+ return 0 on success
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PSTFILT_H_ */
+
+
+
diff --git a/media/codecs/amrnb/dec/src/qgain475_tab.cpp b/media/codecs/amrnb/dec/src/qgain475_tab.cpp
new file mode 100644
index 0000000..1a08efa
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/qgain475_tab.cpp
@@ -0,0 +1,435 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+
+
+ Filename: /audio/gsm_amr/c/src/qgain475_tab.c
+
+ Date: 12/09/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created this file from the reference, qgain475.tab.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "qgain475_tab.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+
+ /* The table contains the following data:
+ *
+ * g_pitch(0) (Q14) // for sub-
+ * g_fac(0) (Q12) // frame 0 and 2
+ * g_pitch(1) (Q14) // for sub-
+ * g_fac(2) (Q12) // frame 1 and 3
+ *
+ */
+ const Word16 table_gain_MR475[MR475_VQ_SIZE*4] =
+ {
+ /*g_pit(0), g_fac(0), g_pit(1), g_fac(1) */
+ 812, 128, 542, 140,
+ 2873, 1135, 2266, 3402,
+ 2067, 563, 12677, 647,
+ 4132, 1798, 5601, 5285,
+ 7689, 374, 3735, 441,
+ 10912, 2638, 11807, 2494,
+ 20490, 797, 5218, 675,
+ 6724, 8354, 5282, 1696,
+ 1488, 428, 5882, 452,
+ 5332, 4072, 3583, 1268,
+ 2469, 901, 15894, 1005,
+ 14982, 3271, 10331, 4858,
+ 3635, 2021, 2596, 835,
+ 12360, 4892, 12206, 1704,
+ 13432, 1604, 9118, 2341,
+ 3968, 1538, 5479, 9936,
+ 3795, 417, 1359, 414,
+ 3640, 1569, 7995, 3541,
+ 11405, 645, 8552, 635,
+ 4056, 1377, 16608, 6124,
+ 11420, 700, 2007, 607,
+ 12415, 1578, 11119, 4654,
+ 13680, 1708, 11990, 1229,
+ 7996, 7297, 13231, 5715,
+ 2428, 1159, 2073, 1941,
+ 6218, 6121, 3546, 1804,
+ 8925, 1802, 8679, 1580,
+ 13935, 3576, 13313, 6237,
+ 6142, 1130, 5994, 1734,
+ 14141, 4662, 11271, 3321,
+ 12226, 1551, 13931, 3015,
+ 5081, 10464, 9444, 6706,
+ 1689, 683, 1436, 1306,
+ 7212, 3933, 4082, 2713,
+ 7793, 704, 15070, 802,
+ 6299, 5212, 4337, 5357,
+ 6676, 541, 6062, 626,
+ 13651, 3700, 11498, 2408,
+ 16156, 716, 12177, 751,
+ 8065, 11489, 6314, 2256,
+ 4466, 496, 7293, 523,
+ 10213, 3833, 8394, 3037,
+ 8403, 966, 14228, 1880,
+ 8703, 5409, 16395, 4863,
+ 7420, 1979, 6089, 1230,
+ 9371, 4398, 14558, 3363,
+ 13559, 2873, 13163, 1465,
+ 5534, 1678, 13138, 14771,
+ 7338, 600, 1318, 548,
+ 4252, 3539, 10044, 2364,
+ 10587, 622, 13088, 669,
+ 14126, 3526, 5039, 9784,
+ 15338, 619, 3115, 590,
+ 16442, 3013, 15542, 4168,
+ 15537, 1611, 15405, 1228,
+ 16023, 9299, 7534, 4976,
+ 1990, 1213, 11447, 1157,
+ 12512, 5519, 9475, 2644,
+ 7716, 2034, 13280, 2239,
+ 16011, 5093, 8066, 6761,
+ 10083, 1413, 5002, 2347,
+ 12523, 5975, 15126, 2899,
+ 18264, 2289, 15827, 2527,
+ 16265, 10254, 14651, 11319,
+ 1797, 337, 3115, 397,
+ 3510, 2928, 4592, 2670,
+ 7519, 628, 11415, 656,
+ 5946, 2435, 6544, 7367,
+ 8238, 829, 4000, 863,
+ 10032, 2492, 16057, 3551,
+ 18204, 1054, 6103, 1454,
+ 5884, 7900, 18752, 3468,
+ 1864, 544, 9198, 683,
+ 11623, 4160, 4594, 1644,
+ 3158, 1157, 15953, 2560,
+ 12349, 3733, 17420, 5260,
+ 6106, 2004, 2917, 1742,
+ 16467, 5257, 16787, 1680,
+ 17205, 1759, 4773, 3231,
+ 7386, 6035, 14342, 10012,
+ 4035, 442, 4194, 458,
+ 9214, 2242, 7427, 4217,
+ 12860, 801, 11186, 825,
+ 12648, 2084, 12956, 6554,
+ 9505, 996, 6629, 985,
+ 10537, 2502, 15289, 5006,
+ 12602, 2055, 15484, 1653,
+ 16194, 6921, 14231, 5790,
+ 2626, 828, 5615, 1686,
+ 13663, 5778, 3668, 1554,
+ 11313, 2633, 9770, 1459,
+ 14003, 4733, 15897, 6291,
+ 6278, 1870, 7910, 2285,
+ 16978, 4571, 16576, 3849,
+ 15248, 2311, 16023, 3244,
+ 14459, 17808, 11847, 2763,
+ 1981, 1407, 1400, 876,
+ 4335, 3547, 4391, 4210,
+ 5405, 680, 17461, 781,
+ 6501, 5118, 8091, 7677,
+ 7355, 794, 8333, 1182,
+ 15041, 3160, 14928, 3039,
+ 20421, 880, 14545, 852,
+ 12337, 14708, 6904, 1920,
+ 4225, 933, 8218, 1087,
+ 10659, 4084, 10082, 4533,
+ 2735, 840, 20657, 1081,
+ 16711, 5966, 15873, 4578,
+ 10871, 2574, 3773, 1166,
+ 14519, 4044, 20699, 2627,
+ 15219, 2734, 15274, 2186,
+ 6257, 3226, 13125, 19480,
+ 7196, 930, 2462, 1618,
+ 4515, 3092, 13852, 4277,
+ 10460, 833, 17339, 810,
+ 16891, 2289, 15546, 8217,
+ 13603, 1684, 3197, 1834,
+ 15948, 2820, 15812, 5327,
+ 17006, 2438, 16788, 1326,
+ 15671, 8156, 11726, 8556,
+ 3762, 2053, 9563, 1317,
+ 13561, 6790, 12227, 1936,
+ 8180, 3550, 13287, 1778,
+ 16299, 6599, 16291, 7758,
+ 8521, 2551, 7225, 2645,
+ 18269, 7489, 16885, 2248,
+ 17882, 2884, 17265, 3328,
+ 9417, 20162, 11042, 8320,
+ 1286, 620, 1431, 583,
+ 5993, 2289, 3978, 3626,
+ 5144, 752, 13409, 830,
+ 5553, 2860, 11764, 5908,
+ 10737, 560, 5446, 564,
+ 13321, 3008, 11946, 3683,
+ 19887, 798, 9825, 728,
+ 13663, 8748, 7391, 3053,
+ 2515, 778, 6050, 833,
+ 6469, 5074, 8305, 2463,
+ 6141, 1865, 15308, 1262,
+ 14408, 4547, 13663, 4515,
+ 3137, 2983, 2479, 1259,
+ 15088, 4647, 15382, 2607,
+ 14492, 2392, 12462, 2537,
+ 7539, 2949, 12909, 12060,
+ 5468, 684, 3141, 722,
+ 5081, 1274, 12732, 4200,
+ 15302, 681, 7819, 592,
+ 6534, 2021, 16478, 8737,
+ 13364, 882, 5397, 899,
+ 14656, 2178, 14741, 4227,
+ 14270, 1298, 13929, 2029,
+ 15477, 7482, 15815, 4572,
+ 2521, 2013, 5062, 1804,
+ 5159, 6582, 7130, 3597,
+ 10920, 1611, 11729, 1708,
+ 16903, 3455, 16268, 6640,
+ 9306, 1007, 9369, 2106,
+ 19182, 5037, 12441, 4269,
+ 15919, 1332, 15357, 3512,
+ 11898, 14141, 16101, 6854,
+ 2010, 737, 3779, 861,
+ 11454, 2880, 3564, 3540,
+ 9057, 1241, 12391, 896,
+ 8546, 4629, 11561, 5776,
+ 8129, 589, 8218, 588,
+ 18728, 3755, 12973, 3149,
+ 15729, 758, 16634, 754,
+ 15222, 11138, 15871, 2208,
+ 4673, 610, 10218, 678,
+ 15257, 4146, 5729, 3327,
+ 8377, 1670, 19862, 2321,
+ 15450, 5511, 14054, 5481,
+ 5728, 2888, 7580, 1346,
+ 14384, 5325, 16236, 3950,
+ 15118, 3744, 15306, 1435,
+ 14597, 4070, 12301, 15696,
+ 7617, 1699, 2170, 884,
+ 4459, 4567, 18094, 3306,
+ 12742, 815, 14926, 907,
+ 15016, 4281, 15518, 8368,
+ 17994, 1087, 2358, 865,
+ 16281, 3787, 15679, 4596,
+ 16356, 1534, 16584, 2210,
+ 16833, 9697, 15929, 4513,
+ 3277, 1085, 9643, 2187,
+ 11973, 6068, 9199, 4462,
+ 8955, 1629, 10289, 3062,
+ 16481, 5155, 15466, 7066,
+ 13678, 2543, 5273, 2277,
+ 16746, 6213, 16655, 3408,
+ 20304, 3363, 18688, 1985,
+ 14172, 12867, 15154, 15703,
+ 4473, 1020, 1681, 886,
+ 4311, 4301, 8952, 3657,
+ 5893, 1147, 11647, 1452,
+ 15886, 2227, 4582, 6644,
+ 6929, 1205, 6220, 799,
+ 12415, 3409, 15968, 3877,
+ 19859, 2109, 9689, 2141,
+ 14742, 8830, 14480, 2599,
+ 1817, 1238, 7771, 813,
+ 19079, 4410, 5554, 2064,
+ 3687, 2844, 17435, 2256,
+ 16697, 4486, 16199, 5388,
+ 8028, 2763, 3405, 2119,
+ 17426, 5477, 13698, 2786,
+ 19879, 2720, 9098, 3880,
+ 18172, 4833, 17336, 12207,
+ 5116, 996, 4935, 988,
+ 9888, 3081, 6014, 5371,
+ 15881, 1667, 8405, 1183,
+ 15087, 2366, 19777, 7002,
+ 11963, 1562, 7279, 1128,
+ 16859, 1532, 15762, 5381,
+ 14708, 2065, 20105, 2155,
+ 17158, 8245, 17911, 6318,
+ 5467, 1504, 4100, 2574,
+ 17421, 6810, 5673, 2888,
+ 16636, 3382, 8975, 1831,
+ 20159, 4737, 19550, 7294,
+ 6658, 2781, 11472, 3321,
+ 19397, 5054, 18878, 4722,
+ 16439, 2373, 20430, 4386,
+ 11353, 26526, 11593, 3068,
+ 2866, 1566, 5108, 1070,
+ 9614, 4915, 4939, 3536,
+ 7541, 878, 20717, 851,
+ 6938, 4395, 16799, 7733,
+ 10137, 1019, 9845, 964,
+ 15494, 3955, 15459, 3430,
+ 18863, 982, 20120, 963,
+ 16876, 12887, 14334, 4200,
+ 6599, 1220, 9222, 814,
+ 16942, 5134, 5661, 4898,
+ 5488, 1798, 20258, 3962,
+ 17005, 6178, 17929, 5929,
+ 9365, 3420, 7474, 1971,
+ 19537, 5177, 19003, 3006,
+ 16454, 3788, 16070, 2367,
+ 8664, 2743, 9445, 26358,
+ 10856, 1287, 3555, 1009,
+ 5606, 3622, 19453, 5512,
+ 12453, 797, 20634, 911,
+ 15427, 3066, 17037, 10275,
+ 18883, 2633, 3913, 1268,
+ 19519, 3371, 18052, 5230,
+ 19291, 1678, 19508, 3172,
+ 18072, 10754, 16625, 6845,
+ 3134, 2298, 10869, 2437,
+ 15580, 6913, 12597, 3381,
+ 11116, 3297, 16762, 2424,
+ 18853, 6715, 17171, 9887,
+ 12743, 2605, 8937, 3140,
+ 19033, 7764, 18347, 3880,
+ 20475, 3682, 19602, 3380,
+ 13044, 19373, 10526, 23124
+ };
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] qua_gain.tab, UMTS GSM AMR speech codec,
+ R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/dec/src/sp_dec.cpp b/media/codecs/amrnb/dec/src/sp_dec.cpp
new file mode 100644
index 0000000..49cafff
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/sp_dec.cpp
@@ -0,0 +1,693 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/sp_dec.c
+ Functions: GSMInitDecode
+ Speech_Decode_Frame_reset
+ GSMDecodeFrameExit
+ GSMFrameDecode
+
+ Date: 08/03/2001
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Add PV coding template. Filled out template sections and
+ reformatted code to follow C coding standard. Removed code that
+ handles SID in GSMFrameDecode.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Updated to more recent PV C coding template.
+ 2. Took out all the tabs in the file and replaced with spaces.
+ 3. Deleted bit_offset from input list of GSMFrameDecode.
+
+ Description: Changing several variables passed into these functions of type
+ Speech_Decode_FrameState to type void.
+
+ Description: Cleaning up brackets and line spacing for statements with
+ brackets as per a review comments.
+
+ Description: Synchronized file with UMTS version 3.2.0. Removed unnecessary
+ include files.
+
+ Description: Removed all references to malloc/free, except for the top-level
+ malloc in GSMInitDecode, and corresponding free in GSMDecodeFrameExit.
+
+ Also, modified function calls throughout to reflect the fact that the members
+ of the structure Decoder_amrState are no longer pointers to be set via
+ malloc, but full-blown structures. (Changes of the type D_plsfState *lsfState
+ to D_plsfState lsfState)
+
+ Description: Created overflow and pass the variable into the decoder.
+
+ Description: Changed inititlaization of the pointer to overflow flag. Removed
+ code related to MOPS counter.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with defined types.
+ Added proper casting (Word32) to some left shifting operations
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that initialize, invoke, reset, and exit
+ the GSM AMR decoder.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "sp_dec.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "dec_amr.h"
+#include "pstfilt.h"
+#include "bits2prm.h"
+#include "mode.h"
+#include "post_pro.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: GSMInitDecode
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to an array of pointers to structures of type
+ Speech_Decode_FrameState
+ no_hp_post_MR122 = flag to turn off high-pass post filter for 12.2 kbps
+ mode (Flag)
+ id = pointer to an array whose contents are of type char
+
+ Outputs:
+ decoder_amrState field of the structure pointed to by the pointer pointed
+ to by state is set to NULL
+ post_state field of the structure pointed to by the pointer pointed to
+ by state is set to NULL
+ postHP_state field of the structure pointed to by the pointer pointed to
+ by state is set to NULL
+ no_hp_post_MR122 field of the structure pointed to by the pointer pointed
+ to by state is set to the input no_hp_post_MR122
+
+ Returns:
+ return_value = set to zero, if initialization was successful; -1,
+ otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function allocates memory for filter structure and initializes state
+ memory used by the GSM AMR decoder.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Note: Original function name of Speech_Decode_Frame_init was changed to
+ GSMInitDecode in the Code section.
+
+int Speech_Decode_Frame_init (Speech_Decode_FrameState **state,
+ char *id)
+{
+ Speech_Decode_FrameState* s;
+
+ if (state == (Speech_Decode_FrameState **) NULL){
+ fprintf(stderr, "Speech_Decode_Frame_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (Speech_Decode_FrameState *)
+ malloc(sizeof(Speech_Decode_FrameState))) == NULL) {
+ fprintf(stderr, "Speech_Decode_Frame_init: can not malloc state "
+ "structure\n");
+ return -1;
+ }
+ s->decoder_amrState = NULL;
+ s->post_state = NULL;
+ s->postHP_state = NULL;
+
+ if (Decoder_amr_init(&s->decoder_amrState) ||
+ Post_Filter_init(&s->post_state) ||
+ Post_Process_init(&s->postHP_state) ) {
+ Speech_Decode_Frame_exit(&s);
+ return -1;
+ }
+
+ s->complexityCounter = getCounterId(id);
+
+ Speech_Decode_Frame_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 GSMInitDecode(void **state_data,
+ Word8 * id)
+{
+ Speech_Decode_FrameState* s;
+ OSCL_UNUSED_ARG(id);
+
+ if (state_data == NULL)
+ {
+ /* fprintf(stderr, "Speech_Decode_Frame_init:
+ invalid parameter\n"); */
+ return (-1);
+ }
+ *state_data = NULL;
+
+ /* allocate memory */
+ if ((s = (Speech_Decode_FrameState *)
+ malloc(sizeof(Speech_Decode_FrameState))) == NULL)
+ {
+ /* fprintf(stderr, "Speech_Decode_Frame_init: can not malloc state "
+ "structure\n"); */
+ return (-1);
+ }
+
+ if (Decoder_amr_init(&s->decoder_amrState)
+ || Post_Process_reset(&s->postHP_state))
+ {
+ free(s);
+ return (-1);
+ }
+
+
+ Speech_Decode_Frame_reset(s);
+ *state_data = (void *)s;
+
+ return (0);
+}
+
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Speech_Decode_Frame_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to structures of type Speech_Decode_FrameState
+
+ Outputs:
+ None
+
+ Returns:
+ return_value = set to zero if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets the state memory used by the GSM AMR decoder.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Speech_Decode_Frame_reset (Speech_Decode_FrameState *state)
+{
+ if (state == (Speech_Decode_FrameState *) NULL){
+ fprintf(stderr, "Speech_Decode_Frame_reset: invalid parameter\n");
+ return -1;
+ }
+
+ Decoder_amr_reset(state->decoder_amrState, (enum Mode)0);
+ Post_Filter_reset(state->post_state);
+ Post_Process_reset(state->postHP_state);
+
+ state->prev_mode = (enum Mode)0;
+
+ setCounter(state->complexityCounter);
+ Init_WMOPS_counter();
+ setCounter(0); // set counter to global counter
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 Speech_Decode_Frame_reset(void *state_data)
+{
+
+ Speech_Decode_FrameState *state =
+ (Speech_Decode_FrameState *) state_data;
+
+ if (state_data == NULL)
+ {
+ /* fprintf(stderr, "Speech_Decode_Frame_reset:
+ invalid parameter\n"); */
+ return (-1);
+ }
+
+ Decoder_amr_reset(&(state->decoder_amrState), MR475);
+ Post_Filter_reset(&(state->post_state));
+ Post_Process_reset(&(state->postHP_state));
+
+ state->prev_mode = MR475;
+
+ return (0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: GSMDecodeFrameExit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to an array of pointers to structures of type
+ Speech_Decode_FrameState
+
+ Outputs:
+ state contents is set to NULL
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function frees up the memory used for the state memory of the GSM AMR
+ decoder.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Note: The original function name of Speech_Decode_Frame_exit was changed to
+ GSMDecodeFrameExit in the Code section.
+
+void Speech_Decode_Frame_exit (Speech_Decode_FrameState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ Decoder_amr_exit(&(*state)->decoder_amrState);
+ Post_Filter_exit(&(*state)->post_state);
+ Post_Process_exit(&(*state)->postHP_state);
+
+ setCounter((*state)->complexityCounter);
+ WMOPS_output(0);
+ setCounter(0); // set counter to global counter
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void GSMDecodeFrameExit(void **state_data)
+{
+
+ Speech_Decode_FrameState **state =
+ (Speech_Decode_FrameState **) state_data;
+
+ if (state == NULL || *state == NULL)
+ {
+ return;
+ }
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: GSMFrameDecode
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structures of type Speech_Decode_FrameState
+ mode = GSM AMR codec mode (enum Mode)
+ serial = pointer to the serial bit stream buffer (unsigned char)
+ frame_type = GSM AMR receive frame type (enum RXFrameType)
+ synth = pointer to the output synthesis speech buffer (Word16)
+
+ Outputs:
+ synth contents are truncated to 13 bits if NO13BIT is not defined,
+ otherwise, its contents are left at 16 bits
+
+ Returns:
+ return_value = set to zero (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function is the entry point to the GSM AMR decoder. The following
+ operations are performed on one received frame: First, the codec
+ parameters are parsed from the buffer pointed to by serial according to
+ frame_type. Then the AMR decoder is invoked via a call to Decoder_amr. Post
+ filtering of the decoded data is done via a call to Post_Filter function.
+ Lastly, the decoded data is post-processed via a call to Post_Process
+ function. If NO13BIT is not defined, the contents of the buffer pointed to
+ by synth is truncated to 13 bits. It remains unchanged otherwise.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Note: The original function name of Speech_Decode_Frame_exit was changed to
+ GSMFrameDecode in the Code section.
+
+int Speech_Decode_Frame (
+ Speech_Decode_FrameState *st, // io: post filter states
+ enum Mode mode, // i : AMR mode
+ Word16 *serial, // i : serial bit stream
+ enum RXFrameType frame_type, // i : Frame type
+ Word16 *synth // o : synthesis speech (postfiltered
+ // output)
+)
+{
+ Word16 parm[MAX_PRM_SIZE + 1]; // Synthesis parameters
+ Word16 Az_dec[AZ_SIZE]; // Decoded Az for post-filter
+ // in 4 subframes
+
+#if !defined(NO13BIT)
+ Word16 i;
+#endif
+
+ setCounter(st->complexityCounter);
+ Reset_WMOPS_counter (); // reset WMOPS counter for the new frame
+
+ // Serial to parameters
+ if ((frame_type == RX_SID_BAD) ||
+ (frame_type == RX_SID_UPDATE)) {
+ // Override mode to MRDTX
+ Bits2prm (MRDTX, serial, parm);
+ } else {
+ Bits2prm (mode, serial, parm);
+ }
+
+ // Synthesis
+ Decoder_amr(st->decoder_amrState, mode, parm, frame_type,
+ synth, Az_dec);
+
+ Post_Filter(st->post_state, mode, synth, Az_dec); // Post-filter
+
+ // post HP filter, and 15->16 bits
+ Post_Process(st->postHP_state, synth, L_FRAME);
+
+#if !defined(NO13BIT)
+ // Truncate to 13 bits
+ for (i = 0; i < L_FRAME; i++)
+ {
+ synth[i] = synth[i] & 0xfff8;
+ }
+#endif
+
+ setCounter(0); // set counter to global counter
+
+ return 0;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void GSMFrameDecode(
+ Speech_Decode_FrameState *st, /* io: post filter states */
+ enum Mode mode, /* i : AMR mode */
+ Word16 *serial, /* i : serial bit stream */
+ enum RXFrameType frame_type, /* i : Frame type */
+ Word16 *synth) /* o : synthesis speech (postfiltered */
+/* output) */
+
+{
+ Word16 parm[MAX_PRM_SIZE + 1]; /* Synthesis parameters */
+ Word16 Az_dec[AZ_SIZE]; /* Decoded Az for post-filter */
+ /* in 4 subframes */
+ Flag *pOverflow = &(st->decoder_amrState.overflow); /* Overflow flag */
+
+#if !defined(NO13BIT)
+ Word16 i;
+#endif
+
+ /* Serial to parameters */
+ if ((frame_type == RX_SID_BAD) ||
+ (frame_type == RX_SID_UPDATE))
+ {
+ /* Override mode to MRDTX */
+ Bits2prm(MRDTX, serial, parm);
+ }
+ else
+ {
+ Bits2prm(mode, serial, parm);
+ }
+
+ /* Synthesis */
+ Decoder_amr(
+ &(st->decoder_amrState),
+ mode,
+ parm,
+ frame_type,
+ synth,
+ Az_dec);
+
+ /* Post-filter */
+ Post_Filter(
+ &(st->post_state),
+ mode,
+ synth,
+ Az_dec,
+ pOverflow);
+
+ /* post HP filter, and 15->16 bits */
+ Post_Process(
+ &(st->postHP_state),
+ synth,
+ L_FRAME,
+ pOverflow);
+
+#if !defined(NO13BIT)
+ /* Truncate to 13 bits */
+ for (i = 0; i < L_FRAME; i++)
+ {
+ synth[i] = synth[i] & 0xfff8;
+ }
+#endif
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrnb/dec/src/sp_dec.h b/media/codecs/amrnb/dec/src/sp_dec.h
new file mode 100644
index 0000000..3150feb
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/sp_dec.h
@@ -0,0 +1,113 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+*****************************************************************************
+*
+* GSM AMR speech codec Version 2.0.0 February 8, 1999
+*
+*****************************************************************************
+*
+* File : sp_dec.h
+* Purpose : Decoding and post filtering of one speech frame.
+*
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+*****************************************************************************
+*/
+#ifndef sp_dec_h
+#define sp_dec_h "$Id $"
+
+/*
+*****************************************************************************
+* INCLUDE FILES
+*****************************************************************************
+*/
+#include "typedef.h"
+#include "cnst.h"
+#include "dec_amr.h"
+#include "pstfilt.h"
+#include "post_pro.h"
+#include "mode.h"
+
+/*
+*****************************************************************************
+* DEFINITION OF DATA TYPES
+*****************************************************************************
+*/
+typedef struct
+{
+ Decoder_amrState decoder_amrState;
+ Post_FilterState post_state;
+ Post_ProcessState postHP_state;
+ enum Mode prev_mode;
+} Speech_Decode_FrameState;
+
+/*
+*****************************************************************************
+* DECLARATION OF PROTOTYPES
+*****************************************************************************
+*/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+ Word16 GSMInitDecode(void **state_data,
+ Word8 *id);
+ /* initialize one instance of the speech decoder
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to Speech_Decode_Frame in each call.
+ returns 0 on success
+ */
+
+ Word16 Speech_Decode_Frame_reset(void *state_data);
+ /* reset speech decoder (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void GSMDecodeFrameExit(void **state_data);
+ /* de-initialize speech decoder (i.e. free status struct)
+ stores NULL in *s
+ */
+
+ void GSMFrameDecode(
+ Speech_Decode_FrameState *st, /* io: post filter states */
+ enum Mode mode, /* i : AMR mode */
+ Word16 *serial, /* i : serial bit stream */
+ enum RXFrameType frame_type, /* i : Frame type */
+ Word16 *synth /* o : synthesis speech (postfiltered */
+ /* output) */
+ );
+ /* return 0 on success
+ */
+#if defined(__cplusplus)
+}
+#endif
+#endif
diff --git a/media/codecs/amrnb/dec/src/wmf_to_ets.cpp b/media/codecs/amrnb/dec/src/wmf_to_ets.cpp
new file mode 100644
index 0000000..4dfbb67
--- /dev/null
+++ b/media/codecs/amrnb/dec/src/wmf_to_ets.cpp
@@ -0,0 +1,190 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/wmf_to_ets.c
+ Funtions: wmf_to_ets
+
+ Date: 01/21/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changing mode to frame_type_3gpp for DTX support. Modifying for
+ loops for optimized code. Updating as per review comments.
+
+ Description: Changed MRDTX to AMR_SID in the code and added bitreorder_tab.h
+ in the Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "frame_type_3gpp.h"
+#include "wmf_to_ets.h"
+#include "typedef.h"
+#include "bitreorder_tab.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: wmf_to_ets
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
+ wmf_input_ptr = pointer to input encoded speech bits in WMF (non-IF2) format
+ (Word8)
+ ets_output_ptr = pointer to output encoded speech bits in ETS format (Word16)
+
+ Outputs:
+ ets_output_ptr = pointer to encoded speech bits in the ETS format (Word16)
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs a transformation on the data buffers. It converts the
+ data format from WMF (non-IF2) (Wireless Multi-media Forum) to ETS (European
+ Telecommunication Standard). WMF format has the encoded speech bits byte
+ aligned with MSB to LSB going left to right. ETS format has the encoded speech
+ bits each separate with only one bit stored in each word.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void wmf_to_ets(
+ enum Frame_Type_3GPP frame_type_3gpp,
+ UWord8 *wmf_input_ptr,
+ Word16 *ets_output_ptr)
+{
+
+ Word16 i;
+
+ /*
+ * The following section of code accesses bits in the WMF method of
+ * bit ordering. Each bit is given its own location in the buffer pointed
+ * to by ets_output_ptr. If the frame_type_3gpp is less than MRDTX then
+ * the elements are reordered within the buffer pointed to by ets_output_ptr.
+ */
+
+ if (frame_type_3gpp < AMR_SID)
+ {
+ /* The table numOfBits[] can be found in bitreorder.c. */
+ for (i = numOfBits[frame_type_3gpp] - 1; i >= 0; i--)
+ {
+ /* The table reorderBits[][] can be found in bitreorder.c. */
+ ets_output_ptr[reorderBits[frame_type_3gpp][i]] =
+ (wmf_input_ptr[i>>3] >> ((~i) & 0x7)) & 0x01;
+ }
+ }
+ else
+ {
+ /* The table numOfBits[] can be found in bitreorder.c. */
+ for (i = numOfBits[frame_type_3gpp] - 1; i >= 0; i--)
+ {
+ ets_output_ptr[i] = (wmf_input_ptr[i>>3] >> ((~i) & 0x7)) & 0x01;
+ }
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/dec/test/AmrnbDecTestEnvironment.h b/media/codecs/amrnb/dec/test/AmrnbDecTestEnvironment.h
new file mode 100644
index 0000000..0344ac5
--- /dev/null
+++ b/media/codecs/amrnb/dec/test/AmrnbDecTestEnvironment.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AMRNBDEC_TEST_ENVIRONMENT_H__
+#define __AMRNBDEC_TEST_ENVIRONMENT_H__
+
+#include <gtest/gtest.h>
+
+#include <getopt.h>
+
+using namespace std;
+
+class AmrnbDecTestEnvironment : public ::testing::Environment {
+ public:
+ AmrnbDecTestEnvironment() : res("/data/local/tmp/") {}
+
+ // Parses the command line arguments
+ int initFromOptions(int argc, char **argv);
+
+ void setRes(const char *_res) { res = _res; }
+
+ const string getRes() const { return res; }
+
+ private:
+ string res;
+};
+
+int AmrnbDecTestEnvironment::initFromOptions(int argc, char **argv) {
+ static struct option options[] = {{"res", required_argument, 0, 'P'}, {0, 0, 0, 0}};
+
+ while (true) {
+ int index = 0;
+ int c = getopt_long(argc, argv, "P:", options, &index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'P':
+ setRes(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr,
+ "unrecognized option: %s\n\n"
+ "usage: %s <gtest options> <test options>\n\n"
+ "test options are:\n\n"
+ "-P, --path: Resource files directory location\n",
+ argv[optind ?: 1], argv[0]);
+ return 2;
+ }
+ return 0;
+}
+
+#endif // __AMRNBDEC_TEST_ENVIRONMENT_H__
diff --git a/media/codecs/amrnb/dec/test/AmrnbDecoderTest.cpp b/media/codecs/amrnb/dec/test/AmrnbDecoderTest.cpp
new file mode 100644
index 0000000..af62074
--- /dev/null
+++ b/media/codecs/amrnb/dec/test/AmrnbDecoderTest.cpp
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "AmrnbDecoderTest"
+#define OUTPUT_FILE "/data/local/tmp/amrnbDecode.out"
+
+#include <utils/Log.h>
+
+#include <audio_utils/sndfile.h>
+#include <stdio.h>
+
+#include "gsmamr_dec.h"
+
+#include "AmrnbDecTestEnvironment.h"
+
+// Constants for AMR-NB
+constexpr int32_t kInputBufferSize = 64;
+constexpr int32_t kSamplesPerFrame = L_FRAME;
+constexpr int32_t kBitsPerSample = 16;
+constexpr int32_t kSampleRate = 8000;
+constexpr int32_t kChannels = 1;
+constexpr int32_t kOutputBufferSize = kSamplesPerFrame * kBitsPerSample / 8;
+const int32_t kFrameSizes[] = {12, 13, 15, 17, 19, 20, 26, 31, -1, -1, -1, -1, -1, -1, -1, -1};
+
+constexpr int32_t kNumFrameReset = 150;
+
+static AmrnbDecTestEnvironment *gEnv = nullptr;
+
+class AmrnbDecoderTest : public ::testing::TestWithParam<string> {
+ public:
+ AmrnbDecoderTest() : mFpInput(nullptr) {}
+
+ ~AmrnbDecoderTest() {
+ if (mFpInput) {
+ fclose(mFpInput);
+ mFpInput = nullptr;
+ }
+ }
+
+ FILE *mFpInput;
+ SNDFILE *openOutputFile(SF_INFO *sfInfo);
+ int32_t DecodeFrames(void *amrHandle, SNDFILE *outFileHandle, int32_t frameCount = INT32_MAX);
+};
+
+SNDFILE *AmrnbDecoderTest::openOutputFile(SF_INFO *sfInfo) {
+ memset(sfInfo, 0, sizeof(SF_INFO));
+ sfInfo->channels = kChannels;
+ sfInfo->format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ sfInfo->samplerate = kSampleRate;
+ SNDFILE *outFileHandle = sf_open(OUTPUT_FILE, SFM_WRITE, sfInfo);
+ return outFileHandle;
+}
+
+int32_t AmrnbDecoderTest::DecodeFrames(void *amrHandle, SNDFILE *outFileHandle,
+ int32_t frameCount) {
+ uint8_t inputBuf[kInputBufferSize];
+ int16_t outputBuf[kOutputBufferSize];
+
+ while (frameCount > 0) {
+ uint8_t mode;
+ int32_t bytesRead = fread(&mode, 1, 1, mFpInput);
+ if (bytesRead != 1) break;
+
+ // Find frame type
+ Frame_Type_3GPP frameType = (Frame_Type_3GPP)((mode >> 3) & 0x0f);
+ int32_t frameSize = kFrameSizes[frameType];
+ if (frameSize < 0) {
+ ALOGE("Illegal frame type");
+ return -1;
+ }
+ bytesRead = fread(inputBuf, 1, frameSize, mFpInput);
+ if (bytesRead != frameSize) break;
+
+ int32_t bytesDecoded = AMRDecode(amrHandle, frameType, inputBuf, outputBuf, MIME_IETF);
+ if (bytesDecoded == -1) {
+ ALOGE("Failed to decode the input file");
+ return -1;
+ }
+
+ sf_writef_short(outFileHandle, outputBuf, kSamplesPerFrame);
+ frameCount--;
+ }
+ return 0;
+}
+
+TEST_F(AmrnbDecoderTest, CreateAmrnbDecoderTest) {
+ void *amrHandle;
+ int32_t status = GSMInitDecode(&amrHandle, (Word8 *)"AMRNBDecoder");
+ ASSERT_EQ(status, 0) << "Error creating AMR-NB decoder";
+ GSMDecodeFrameExit(&amrHandle);
+ ASSERT_EQ(amrHandle, nullptr) << "Error deleting AMR-NB decoder";
+}
+
+TEST_P(AmrnbDecoderTest, DecodeTest) {
+ string inputFile = gEnv->getRes() + GetParam();
+ mFpInput = fopen(inputFile.c_str(), "rb");
+ ASSERT_NE(mFpInput, nullptr) << "Error opening input file " << inputFile;
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ SNDFILE *outFileHandle = openOutputFile(&sfInfo);
+ ASSERT_NE(outFileHandle, nullptr) << "Error opening output file for writing decoded output";
+
+ void *amrHandle;
+ int32_t status = GSMInitDecode(&amrHandle, (Word8 *)"AMRNBDecoder");
+ ASSERT_EQ(status, 0) << "Error creating AMR-NB decoder";
+
+ // Decode
+ int32_t decoderErr = DecodeFrames(amrHandle, outFileHandle);
+ ASSERT_EQ(decoderErr, 0) << "DecodeFrames returned error";
+
+ sf_close(outFileHandle);
+ GSMDecodeFrameExit(&amrHandle);
+ ASSERT_EQ(amrHandle, nullptr) << "Error deleting AMR-NB decoder";
+}
+
+TEST_P(AmrnbDecoderTest, ResetDecodeTest) {
+ string inputFile = gEnv->getRes() + GetParam();
+ mFpInput = fopen(inputFile.c_str(), "rb");
+ ASSERT_NE(mFpInput, nullptr) << "Error opening input file " << inputFile;
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ SNDFILE *outFileHandle = openOutputFile(&sfInfo);
+ ASSERT_NE(outFileHandle, nullptr) << "Error opening output file for writing decoded output";
+
+ void *amrHandle;
+ int32_t status = GSMInitDecode(&amrHandle, (Word8 *)"AMRNBDecoder");
+ ASSERT_EQ(status, 0) << "Error creating AMR-NB decoder";
+
+ // Decode kNumFrameReset first
+ int32_t decoderErr = DecodeFrames(amrHandle, outFileHandle, kNumFrameReset);
+ ASSERT_EQ(decoderErr, 0) << "DecodeFrames returned error";
+
+ status = Speech_Decode_Frame_reset(amrHandle);
+ ASSERT_EQ(status, 0) << "Error resting AMR-NB decoder";
+
+ // Start decoding again
+ decoderErr = DecodeFrames(amrHandle, outFileHandle);
+ ASSERT_EQ(decoderErr, 0) << "DecodeFrames returned error";
+
+ sf_close(outFileHandle);
+ GSMDecodeFrameExit(&amrHandle);
+ ASSERT_EQ(amrHandle, nullptr) << "Error deleting AMR-NB decoder";
+}
+
+INSTANTIATE_TEST_SUITE_P(AmrnbDecoderTestAll, AmrnbDecoderTest,
+ ::testing::Values(("bbb_8000hz_1ch_8kbps_amrnb_30sec.amrnb"),
+ ("sine_amrnb_1ch_12kbps_8000hz.amrnb")));
+
+int main(int argc, char **argv) {
+ gEnv = new AmrnbDecTestEnvironment();
+ ::testing::AddGlobalTestEnvironment(gEnv);
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = gEnv->initFromOptions(argc, argv);
+ if (status == 0) {
+ status = RUN_ALL_TESTS();
+ ALOGV("Test result = %d\n", status);
+ }
+ return status;
+}
diff --git a/media/codecs/amrnb/dec/test/Android.bp b/media/codecs/amrnb/dec/test/Android.bp
new file mode 100644
index 0000000..7a95cfa
--- /dev/null
+++ b/media/codecs/amrnb/dec/test/Android.bp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_test {
+ name: "AmrnbDecoderTest",
+ gtest: true,
+
+ srcs: [
+ "AmrnbDecoderTest.cpp",
+ ],
+
+ static_libs: [
+ "libstagefright_amrnb_common",
+ "libstagefright_amrnbdec",
+ "libaudioutils",
+ "libsndfile",
+ ],
+
+ shared_libs: [
+ "liblog",
+ ],
+
+ cflags: [
+ "-Werror",
+ "-Wall",
+ ],
+
+ sanitize: {
+ cfi: true,
+ misc_undefined: [
+ "unsigned-integer-overflow",
+ "signed-integer-overflow",
+ ],
+ },
+}
diff --git a/media/codecs/amrnb/dec/test/AndroidTest.xml b/media/codecs/amrnb/dec/test/AndroidTest.xml
new file mode 100644
index 0000000..1a9e678
--- /dev/null
+++ b/media/codecs/amrnb/dec/test/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for Amr-nb Decoder unit test">
+ <option name="test-suite-tag" value="AmrnbDecoderTest" />
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="AmrnbDecoderTest->/data/local/tmp/AmrnbDecoderTest" />
+ <option name="push-file"
+ key="https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrnb/dec/test/AmrnbDecoderTest.zip?unzip=true"
+ value="/data/local/tmp/AmrnbDecoderTestRes/" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="AmrnbDecoderTest" />
+ <option name="native-test-flag" value="-P /data/local/tmp/AmrnbDecoderTestRes/" />
+ </test>
+</configuration>
diff --git a/media/codecs/amrnb/dec/test/README.md b/media/codecs/amrnb/dec/test/README.md
new file mode 100644
index 0000000..e9073e4
--- /dev/null
+++ b/media/codecs/amrnb/dec/test/README.md
@@ -0,0 +1,39 @@
+## Media Testing ##
+---
+#### AMR-NB Decoder :
+The Amr-Nb Decoder Test Suite validates the amrnb decoder available in libstagefright.
+
+Run the following steps to build the test suite:
+```
+m AmrnbDecoderTest
+```
+
+The 32-bit binaries will be created in the following path : ${OUT}/data/nativetest/
+
+The 64-bit binaries will be created in the following path : ${OUT}/data/nativetest64/
+
+To test 64-bit binary push binaries from nativetest64.
+```
+adb push ${OUT}/data/nativetest64/AmrnbDecoderTest/AmrnbDecoderTest /data/local/tmp/
+```
+
+To test 32-bit binary push binaries from nativetest.
+```
+adb push ${OUT}/data/nativetest/AmrnbDecoderTest/AmrnbDecoderTest /data/local/tmp/
+```
+
+The resource file for the tests is taken from [here](https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrnb/dec/test/AmrnbDecoderTest.zip). Download, unzip and push these files into device for testing.
+
+```
+adb push AmrnbDecoderTestRes/. /data/local/tmp/
+```
+
+usage: AmrnbDecoderTest -P \<path_to_folder\>
+```
+adb shell /data/local/tmp/AmrnbDecoderTest -P /data/local/tmp/AmrnbDecoderTestRes/
+```
+Alternatively, the test can also be run using atest command.
+
+```
+atest AmrnbDecoderTest -- --enable-module-dynamic-download=true
+```
diff --git a/media/codecs/amrnb/dec/test/amrnbdec_test.cpp b/media/codecs/amrnb/dec/test/amrnbdec_test.cpp
new file mode 100644
index 0000000..621fda8
--- /dev/null
+++ b/media/codecs/amrnb/dec/test/amrnbdec_test.cpp
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <malloc.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+#include "gsmamr_dec.h"
+#include <audio_utils/sndfile.h>
+
+// Constants for AMR-NB
+enum {
+ kInputBufferSize = 64,
+ kSamplesPerFrame = 160,
+ kBitsPerSample = 16,
+ kOutputBufferSize = kSamplesPerFrame * kBitsPerSample/8,
+ kSampleRate = 8000,
+ kChannels = 1,
+ kFileHeaderSize = 6
+};
+const uint32_t kFrameSizes[] = {12, 13, 15, 17, 19, 20, 26, 31};
+
+
+int main(int argc, char *argv[]) {
+
+ if(argc != 3) {
+ fprintf(stderr, "Usage %s <input file> <output file>\n", argv[0]);
+ return 1;
+ }
+
+ // Open the input file
+ FILE* fpInput = fopen(argv[1], "rb");
+ if (!fpInput) {
+ fprintf(stderr, "Could not open %s\n", argv[1]);
+ return 1;
+ }
+
+ // Validate the input AMR file
+ char header[kFileHeaderSize];
+ int bytesRead = fread(header, 1, kFileHeaderSize, fpInput);
+ if (bytesRead != kFileHeaderSize || memcmp(header, "#!AMR\n", kFileHeaderSize)) {
+ fprintf(stderr, "Invalid AMR-NB file\n");
+ fclose(fpInput);
+ return 1;
+ }
+
+ // Open the output file
+ SF_INFO sfInfo;
+ memset(&sfInfo, 0, sizeof(SF_INFO));
+ sfInfo.channels = kChannels;
+ sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ sfInfo.samplerate = kSampleRate;
+ SNDFILE *handle = sf_open(argv[2], SFM_WRITE, &sfInfo);
+ if(!handle){
+ fprintf(stderr, "Could not create %s\n", argv[2]);
+ fclose(fpInput);
+ return 1;
+ }
+
+ // Create AMR-NB decoder instance
+ void* amrHandle;
+ int err = GSMInitDecode(&amrHandle, (Word8*)"AMRNBDecoder");
+ if(err != 0){
+ fprintf(stderr, "Error creating AMR-NB decoder instance\n");
+ fclose(fpInput);
+ sf_close(handle);
+ return 1;
+ }
+
+ //Allocate input buffer
+ void *inputBuf = malloc(kInputBufferSize);
+ assert(inputBuf != NULL);
+
+ //Allocate output buffer
+ void *outputBuf = malloc(kOutputBufferSize);
+ assert(outputBuf != NULL);
+
+
+ // Decode loop
+ uint32_t retVal = 0;
+ while (1) {
+ // Read mode
+ uint8_t mode;
+ bytesRead = fread(&mode, 1, 1, fpInput);
+ if (bytesRead != 1) break;
+
+ // Find frame type
+ Frame_Type_3GPP frameType = (Frame_Type_3GPP)((mode >> 3) & 0x0f);
+ if (frameType >= AMR_SID){
+ fprintf(stderr, "Frame type %d not supported\n",frameType);
+ retVal = 1;
+ break;
+ }
+
+ // Find frame type
+ int32_t frameSize = kFrameSizes[frameType];
+ bytesRead = fread(inputBuf, 1, frameSize, fpInput);
+ if (bytesRead != frameSize) break;
+
+ //Decode frame
+ int32_t decodeStatus;
+ decodeStatus = AMRDecode(amrHandle, frameType, (uint8_t*)inputBuf,
+ (int16_t*)outputBuf, MIME_IETF);
+ if(decodeStatus == -1) {
+ fprintf(stderr, "Decoder encountered error\n");
+ retVal = 1;
+ break;
+ }
+
+ //Write output to wav
+ sf_writef_short(handle, (int16_t*)outputBuf, kSamplesPerFrame);
+
+ }
+
+ // Close input and output file
+ fclose(fpInput);
+ sf_close(handle);
+
+ //Free allocated memory
+ free(inputBuf);
+ free(outputBuf);
+
+ // Close decoder instance
+ GSMDecodeFrameExit(&amrHandle);
+
+ return retVal;
+}
diff --git a/media/codecs/amrnb/enc/Android.bp b/media/codecs/amrnb/enc/Android.bp
new file mode 100644
index 0000000..534ce04
--- /dev/null
+++ b/media/codecs/amrnb/enc/Android.bp
@@ -0,0 +1,113 @@
+cc_library_static {
+ name: "libstagefright_amrnbenc",
+ vendor_available: true,
+ min_sdk_version: "29",
+
+ srcs: [
+ "src/amrencode.cpp",
+ "src/autocorr.cpp",
+ "src/c1035pf.cpp",
+ "src/c2_11pf.cpp",
+ "src/c2_9pf.cpp",
+ "src/c3_14pf.cpp",
+ "src/c4_17pf.cpp",
+ "src/c8_31pf.cpp",
+ "src/calc_cor.cpp",
+ "src/calc_en.cpp",
+ "src/cbsearch.cpp",
+ "src/cl_ltp.cpp",
+ "src/cod_amr.cpp",
+ "src/convolve.cpp",
+ "src/cor_h.cpp",
+ "src/cor_h_x.cpp",
+ "src/cor_h_x2.cpp",
+ "src/corrwght_tab.cpp",
+ "src/dtx_enc.cpp",
+ "src/enc_lag3.cpp",
+ "src/enc_lag6.cpp",
+ "src/enc_output_format_tab.cpp",
+ "src/ets_to_if2.cpp",
+ "src/ets_to_wmf.cpp",
+ "src/g_adapt.cpp",
+ "src/g_code.cpp",
+ "src/g_pitch.cpp",
+ "src/gain_q.cpp",
+ "src/hp_max.cpp",
+ "src/inter_36.cpp",
+ "src/inter_36_tab.cpp",
+ "src/l_comp.cpp",
+ "src/l_extract.cpp",
+ "src/l_negate.cpp",
+ "src/lag_wind.cpp",
+ "src/lag_wind_tab.cpp",
+ "src/levinson.cpp",
+ "src/lpc.cpp",
+ "src/ol_ltp.cpp",
+ "src/p_ol_wgh.cpp",
+ "src/pitch_fr.cpp",
+ "src/pitch_ol.cpp",
+ "src/pre_big.cpp",
+ "src/pre_proc.cpp",
+ "src/prm2bits.cpp",
+ "src/q_gain_c.cpp",
+ "src/q_gain_p.cpp",
+ "src/qgain475.cpp",
+ "src/qgain795.cpp",
+ "src/qua_gain.cpp",
+ "src/s10_8pf.cpp",
+ "src/set_sign.cpp",
+ "src/sid_sync.cpp",
+ "src/sp_enc.cpp",
+ "src/spreproc.cpp",
+ "src/spstproc.cpp",
+ "src/ton_stab.cpp",
+ ],
+
+ header_libs: ["libstagefright_headers"],
+ export_include_dirs: ["src"],
+
+ cflags: [
+ "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+ "-Werror",
+ ],
+
+ //addressing b/25409744
+ //sanitize: {
+ // misc_undefined: [
+ // "signed-integer-overflow",
+ // ],
+ //},
+
+ shared_libs: ["libstagefright_amrnb_common"],
+
+ host_supported: true,
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+//###############################################################################
+
+cc_test {
+ name: "libstagefright_amrnbenc_test",
+ gtest: false,
+
+ srcs: ["test/amrnb_enc_test.cpp"],
+
+ cflags: ["-Wall", "-Werror"],
+
+ local_include_dirs: ["src"],
+
+ static_libs: ["libstagefright_amrnbenc"],
+
+ shared_libs: ["libstagefright_amrnb_common"],
+
+ //addressing b/25409744
+ //sanitize: {
+ // misc_undefined: [
+ // "signed-integer-overflow",
+ // ],
+ //},
+}
diff --git a/media/codecs/amrnb/enc/MODULE_LICENSE_APACHE2 b/media/codecs/amrnb/enc/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/amrnb/enc/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/amrnb/enc/NOTICE b/media/codecs/amrnb/enc/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/amrnb/enc/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/amrnb/enc/fuzzer/Android.bp b/media/codecs/amrnb/enc/fuzzer/Android.bp
new file mode 100644
index 0000000..e88e5eb
--- /dev/null
+++ b/media/codecs/amrnb/enc/fuzzer/Android.bp
@@ -0,0 +1,41 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+
+cc_fuzz {
+ name: "amrnb_enc_fuzzer",
+ host_supported: true,
+
+ srcs: [
+ "amrnb_enc_fuzzer.cpp",
+ ],
+
+ static_libs: [
+ "liblog",
+ "libstagefright_amrnbenc",
+ "libstagefright_amrnb_common",
+ ],
+
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
diff --git a/media/codecs/amrnb/enc/fuzzer/README.md b/media/codecs/amrnb/enc/fuzzer/README.md
new file mode 100644
index 0000000..239b4a8
--- /dev/null
+++ b/media/codecs/amrnb/enc/fuzzer/README.md
@@ -0,0 +1,60 @@
+# Fuzzer for libstagefright_amrnbenc encoder
+
+## Plugin Design Considerations
+The fuzzer plugin for AMR-NB is designed based on the understanding of the
+codec and tries to achieve the following:
+
+##### Maximize code coverage
+The configuration parameters are not hardcoded, but instead selected based on
+incoming data. This ensures more code paths are reached by the fuzzer.
+
+AMR-WB supports the following parameters:
+1. Output Format (parameter name: `outputFormat`)
+2. Mode (parameter name: `mode`)
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `outputFormat` | 0. `AMR_TX_WMF` 1. `AMR_TX_IF2` 2. `AMR_TX_ETS` | Bits 0, 1 and 2 of 1st byte of data. |
+| `mode` | 0. `MR475` 1. `MR515` 2. `MR59` 3. `MR67` 4. `MR74 ` 5. `MR795` 6. `MR102` 7. `MR122` 8. `MRDTX` | Bits 3, 4, 5 and 6 of 1st byte of data. |
+
+This also ensures that the plugin is always deterministic for any given input.
+
+##### Maximize utilization of input data
+The plugin feeds the entire input data to the codec using a loop.
+If the encode operation was successful, the input is advanced by the frame size.
+If the encode operation was un-successful, the input is still advanced by frame size so
+that the fuzzer can proceed to feed the next frame.
+
+This ensures that the plugin tolerates any kind of input (empty, huge,
+malformed, etc) and doesnt `exit()` on any input and thereby increasing the
+chance of identifying vulnerabilities.
+
+## Build
+
+This describes steps to build amrnb_enc_fuzzer binary.
+
+### Android
+
+#### Steps to build
+Build the fuzzer
+```
+ $ mm -j$(nproc) amrnb_enc_fuzzer
+```
+
+#### Steps to run
+Create a directory CORPUS_DIR and copy some pcm files to that folder
+Push this directory to device.
+
+To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/amrnb_enc_fuzzer/amrnb_enc_fuzzer CORPUS_DIR
+```
+To run on host
+```
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/amrnb_enc_fuzzer/amrnb_enc_fuzzer CORPUS_DIR
+```
+
+## References:
+ * http://llvm.org/docs/LibFuzzer.html
+ * https://github.com/google/oss-fuzz
diff --git a/media/codecs/amrnb/enc/fuzzer/amrnb_enc_fuzzer.cpp b/media/codecs/amrnb/enc/fuzzer/amrnb_enc_fuzzer.cpp
new file mode 100644
index 0000000..2fcbf24
--- /dev/null
+++ b/media/codecs/amrnb/enc/fuzzer/amrnb_enc_fuzzer.cpp
@@ -0,0 +1,105 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+#include <string.h>
+#include <utils/Log.h>
+#include <algorithm>
+#include "gsmamr_enc.h"
+
+// Constants for AMR-NB
+const int32_t kNumInputSamples = L_FRAME; // 160 samples
+const int32_t kOutputBufferSize = 2 * kNumInputSamples * sizeof(Word16);
+const Mode kModes[9] = {MR475, /* 4.75 kbps */
+ MR515, /* 5.15 kbps */
+ MR59, /* 5.90 kbps */
+ MR67, /* 6.70 kbps */
+ MR74, /* 7.40 kbps */
+ MR795, /* 7.95 kbps */
+ MR102, /* 10.2 kbps */
+ MR122, /* 12.2 kbps */
+ MRDTX, /* DTX */};
+const Word16 kOutputFormat[3] = {AMR_TX_WMF, AMR_TX_IF2, AMR_TX_ETS};
+
+class Codec {
+ public:
+ Codec() = default;
+ ~Codec() { deInitEncoder(); }
+ Word16 initEncoder(const uint8_t *data);
+ void deInitEncoder();
+ void encodeFrames(const uint8_t *data, size_t size);
+
+ private:
+ void *mEncState = nullptr;
+ void *mSidState = nullptr;
+};
+
+Word16 Codec::initEncoder(const uint8_t *data) {
+ return AMREncodeInit(&mEncState, &mSidState, (*data >> 1) & 0x01 /* dtx_enable flag */);
+}
+
+void Codec::deInitEncoder() {
+ if (mEncState) {
+ AMREncodeExit(&mEncState, &mSidState);
+ mEncState = nullptr;
+ mSidState = nullptr;
+ }
+}
+
+void Codec::encodeFrames(const uint8_t *data, size_t size) {
+ AMREncodeReset(mEncState, mSidState);
+ uint8_t startByte = *data;
+ int modeIndex = ((startByte >> 3) % 9);
+ int outputFormatIndex = (startByte % 3);
+ Mode mode = kModes[modeIndex];
+ Word16 outputFormat = kOutputFormat[outputFormatIndex];
+
+ // Consume startByte
+ data++;
+ size--;
+
+ while (size > 0) {
+ Frame_Type_3GPP frameType = (Frame_Type_3GPP)mode;
+
+ Word16 inputBuf[kNumInputSamples] = {};
+ int32_t minSize = std::min(size, sizeof(inputBuf));
+
+ uint8_t outputBuf[kOutputBufferSize] = {};
+ memcpy(inputBuf, data, minSize);
+
+ AMREncode(mEncState, mSidState, mode, inputBuf, outputBuf, &frameType, outputFormat);
+
+ data += minSize;
+ size -= minSize;
+ }
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size < 1) {
+ return 0;
+ }
+ Codec *codec = new Codec();
+ if (!codec) {
+ return 0;
+ }
+ if (codec->initEncoder(data) == 0) {
+ codec->encodeFrames(data, size);
+ }
+ delete codec;
+ return 0;
+}
diff --git a/media/codecs/amrnb/enc/src/amrencode.cpp b/media/codecs/amrnb/enc/src/amrencode.cpp
new file mode 100644
index 0000000..d07c846
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/amrencode.cpp
@@ -0,0 +1,897 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/src/amrencode.c
+ Functions: AMREncode
+ AMREncodeInit
+ AMREncodeReset
+ AMREncodeExit
+
+ Date: 01/26/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added input_type in the parameter list and updated code to
+ check the type of output formatting to use.
+
+ Description: Corrected typo in Include section.
+
+ Description: Added code to support ETS format.
+
+ Description: Modified file by adding the return of the number of encoder
+ frame bytes.
+
+ Description: Added call to sid_sync function to support TX_NO_DATA case.
+ Added SID type and mode info to ets_output_bfr for ETS SID
+ frames. Created AMREncodeInit, AMREncodeReset, and AMREncodeExit
+ functions.
+
+ Description: Modified design of handling of ETS outputs such that the ETS
+ testvectors could be compared directly to the output of this
+ function.
+
+ Description: Added conditional compile around calls to AMR Encoder interface
+ functions to allow amrencode.c to be used in the ETS reference
+ console.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions required to initialize, reset, exit, and
+ invoke the ETS 3GPP GSM AMR encoder.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "cnst.h"
+#include "mode.h"
+#include "frame_type_3gpp.h"
+#include "typedef.h"
+
+#include "amrencode.h"
+#include "ets_to_if2.h"
+#include "ets_to_wmf.h"
+#include "sid_sync.h"
+#include "sp_enc.h"
+
+/*----------------------------------------------------------------------------
+; MACROS [optional]
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES [optional]
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: AMREncodeInit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pEncStructure = pointer containing the pointer to a structure used by
+ the encoder (void)
+ pSidSyncStructure = pointer containing the pointer to a structure used for
+ SID synchronization (void)
+ dtx_enable = flag to turn off or turn on DTX (Flag)
+
+ Outputs:
+ None
+
+ Returns:
+ init_status = 0, if initialization was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ speech_encoder_state = pointer to encoder frame structure
+ (Speech_Encode_FrameState)
+ sid_state = pointer to SID sync structure (sid_syncState)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes the GSM AMR Encoder library by calling
+ GSMInitEncode and sid_sync_init. If initialization was successful,
+ init_status is set to zero, otherwise, it is set to -1.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ // Initialize GSM AMR Encoder
+ CALL GSMInitEncode(state_data = &pEncStructure,
+ dtx = dtx_enable,
+ id = char_id )
+ MODIFYING(nothing)
+ RETURNING(return_value = enc_init_status)
+
+ // Initialize SID synchronization
+ CALL sid_sync_init(state = &pSidSyncStructure)
+ MODIFYING(nothing)
+ RETURNING(return_value = sid_sync_init_status)
+
+ IF ((enc_init_status != 0) || (sid_sync_init != 0))
+ THEN
+ init_status = -1
+
+ ENDIF
+
+ MODIFY(nothing)
+ RETURN(init_status)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 AMREncodeInit(
+ void **pEncStructure,
+ void **pSidSyncStructure,
+ Flag dtx_enable)
+{
+ Word16 enc_init_status = 0;
+ Word16 sid_sync_init_status = 0;
+ Word16 init_status = 0;
+
+ /* Initialize GSM AMR Encoder */
+#ifdef CONSOLE_ENCODER_REF
+ /* Change to original ETS input types */
+ Speech_Encode_FrameState **speech_encode_frame =
+ (Speech_Encode_FrameState **)(pEncStructure);
+
+ sid_syncState **sid_sync_state = (sid_syncState **)(pSidSyncStructure);
+
+ /* Use ETS version of sp_enc.c */
+ enc_init_status = Speech_Encode_Frame_init(speech_encode_frame,
+ dtx_enable,
+ (Word8*)"encoder");
+
+ /* Initialize SID synchronization */
+ sid_sync_init_status = sid_sync_init(sid_sync_state);
+
+#else
+ /* Use PV version of sp_enc.c */
+ enc_init_status = GSMInitEncode(pEncStructure,
+ dtx_enable,
+ (Word8*)"encoder");
+
+ /* Initialize SID synchronization */
+ sid_sync_init_status = sid_sync_init(pSidSyncStructure);
+
+
+#endif
+
+ if ((enc_init_status != 0) || (sid_sync_init_status != 0))
+ {
+ init_status = -1;
+ }
+
+ return(init_status);
+}
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: AMREncodeReset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pEncStructure = pointer to a structure used by the encoder (void)
+ pSidSyncStructure = pointer to a structure used for SID synchronization
+ (void)
+
+ Outputs:
+ None
+
+ Returns:
+ reset_status = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ speech_encoder_state = pointer to encoder frame structure
+ (Speech_Encode_FrameState)
+ sid_state = pointer to SID sync structure (sid_syncState)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets the state memory used by the Encoder and SID sync
+ function. If reset was successful, reset_status is set to zero, otherwise,
+ it is set to -1.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ // Reset GSM AMR Encoder
+ CALL Speech_Encode_Frame_reset(state_data = pEncStructure)
+ MODIFYING(nothing)
+ RETURNING(return_value = enc_reset_status)
+
+ // Reset SID synchronization
+ CALL sid_sync_reset(state = pSidSyncStructure)
+ MODIFYING(nothing)
+ RETURNING(return_value = sid_sync_reset_status)
+
+ IF ((enc_reset_status != 0) || (sid_sync_reset_status != 0))
+ THEN
+ reset_status = -1
+
+ ENDIF
+
+ MODIFY(nothing)
+ RETURN(reset_status)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 AMREncodeReset(
+ void *pEncStructure,
+ void *pSidSyncStructure)
+{
+ Word16 enc_reset_status = 0;
+ Word16 sid_sync_reset_status = 0;
+ Word16 reset_status = 0;
+
+ /* Reset GSM AMR Encoder */
+ enc_reset_status = Speech_Encode_Frame_reset(pEncStructure);
+
+
+ /* Reset SID synchronization */
+ sid_sync_reset_status = sid_sync_reset(pSidSyncStructure);
+
+ if ((enc_reset_status != 0) || (sid_sync_reset_status != 0))
+ {
+ reset_status = -1;
+ }
+
+ return(reset_status);
+}
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: AMREncodeExit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pEncStructure = pointer containing the pointer to a structure used by
+ the encoder (void)
+ pSidSyncStructure = pointer containing the pointer to a structure used for
+ SID synchronization (void)
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ speech_encoder_state = pointer to encoder frame structure
+ (Speech_Encode_FrameState)
+ sid_state = pointer to SID sync structure (sid_syncState)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function frees up the state memory used by the Encoder and SID
+ synchronization function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ // Exit GSM AMR Encoder
+ CALL GSMEncodeFrameExit(state_data = &pEncStructure)
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ // Exit SID synchronization
+ CALL sid_sync_exit(state = &pSidSyncStructure)
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ MODIFY(nothing)
+ RETURN(nothing)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void AMREncodeExit(
+ void **pEncStructure,
+ void **pSidSyncStructure)
+{
+ /* Exit GSM AMR Encoder */
+
+#ifdef CONSOLE_ENCODER_REF
+ /* Change to original ETS input types */
+ Speech_Encode_FrameState ** speech_encode_frame =
+ (Speech_Encode_FrameState **)(pEncStructure);
+
+ sid_syncState ** sid_sync_state = (sid_syncState **)(pSidSyncStructure);
+
+ /* Use ETS version of sp_enc.c */
+ Speech_Encode_Frame_exit(speech_encode_frame);
+
+
+ /* Exit SID synchronization */
+ sid_sync_exit(sid_sync_state);
+
+#else
+
+ /* Use PV version of sp_enc.c */
+ GSMEncodeFrameExit(pEncStructure);
+
+ /* Exit SID synchronization */
+ sid_sync_exit(pSidSyncStructure);
+
+#endif
+
+ return;
+}
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: AMREncode
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pEncState = pointer to encoder state structure (void)
+ pSidSyncState = pointer to SID sync state structure (void)
+ mode = codec mode (enum Mode)
+ pEncInput = pointer to the input speech samples (Word16)
+ pEncOutput = pointer to the encoded bit stream (unsigned char)
+ p3gpp_frame_type = pointer to the 3GPP frame type (enum Frame_Type_3GPP)
+ output_format = output format type (Word16); valid values are AMR_WMF,
+ AMR_IF2, and AMR_ETS
+
+ Outputs:
+ pEncOutput buffer contains to the newly encoded bit stream
+ p3gpp_frame_type store contains the new 3GPP frame type
+
+ Returns:
+ num_enc_bytes = number of encoded bytes for a particular
+ mode or -1, if an error occurred (int)
+
+ Global Variables Used:
+ WmfEncBytesPerFrame = table containing the number of encoder frame
+ data bytes per codec mode for WMF output
+ format (const int)
+ If2EncBytesPerFrame = table containing the number of encoder frame
+ data bytes per codec mode for IF2 output
+ format (const int)
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function is the top-level entry point to the GSM AMR Encoder library.
+
+ The following describes the encoding process for WMF or IF2 formatted output
+ data. This functions calls GSMEncodeFrame to encode one frame's worth of
+ input speech samples, and returns the newly encoded bit stream in the buffer
+ pointed to by pEncOutput.Then the function sid_sync is called to determine
+ the transmit frame type. If the transmit frame type is TX_SPEECH_GOOD or
+ TX_SID_FIRST or TX_SID_UPDATE, p3gpp_frame_type will be set to the encoder
+ used mode. For SID frames, the SID type information and mode information are
+ added to the encoded parameter bitstream according to the SID frame format
+ described in [1]. If the transmit frame type is TX_NO_DATA, the store
+ pointed to by p3gpp_frame_type will be set to NO_DATA. Then the output
+ format type (output_format) will be checked to determine the format of the
+ encoded data.
+
+ If output_format is AMR_TX_WMF, the function ets_to_wmf will be called to
+ convert from ETS format (1 bit/word, where 1 word = 16 bits, information in
+ least significant bit) to WMF (aka, non-IF2). The WMF format stores the data
+ in octets. The least significant 4 bits of the first octet contains the 3GPP
+ frame type information and the most significant 4 bits are zeroed out. The
+ succeeding octets contain the packed encoded speech bits. The total number of
+ WMF bytes encoded is obtained from WmfEncBytesPerFrame table and returned via
+ num_enc_bytes.
+
+ If output_format is AMR_TX_IF2, the function if2_to_ets will be called to
+ convert from ETS format to IF2 [1]. The IF2 format stores the data in octets.
+ The least significant nibble of the first octet contains the 3GPP frame type
+ and the most significant nibble contains the first 4 encoded speech bits. The
+ suceeding octets contain the packed encoded speech bits. The total number of
+ IF2 bytes encoded is obtained from If2EncBytesPerFrame table and returned via
+ num_enc_bytes.
+
+ If output_format is AMR_TX_ETS, GSMFrameEncode is called to generate the
+ encoded speech parameters, then, sid_sync is called to determine the transmit
+ frame type. If the transmit frame type is not TX_NO_DATA, then the transmit
+ frame type information is saved in the first location of the ets_output_bfr,
+ followed by the encoded speech parameters. The codec mode information is
+ stored immediately after the MAX_SERIAL_SIZE encoded speech parameters. If
+ the transmit frame type is TX_NO_DATA, the transmit frame type, encoded
+ speech parameters, and codec mode are stored in the same order as before
+ in ets_output_bfr. However, for the no data case, the codec mode is set to
+ -1.
+
+ After all the required information is generated, the 16-bit data generated
+ by the Encoder (in ets_output_bfr) is copied to the buffer pointed to by
+ pEncOutput in the little endian configuration, i.e., least significant byte,
+ followed by most significant byte. The num_enc_bytes is set to
+ 2*(MAX_SERIAL_SIZE+2).
+
+ If output_format is invalid, this function flags the error and sets
+ num_enc_bytes to -1.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] "AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0
+ Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ IF ((output_format == AMR_TX_WMF) | (output_format == AMR_TX_IF2))
+ THEN
+ // Encode one speech frame (20 ms)
+ CALL GSMEncodeFrame( state_data = pEncState,
+ mode = mode,
+ new_speech = pEncInput,
+ serial = &ets_output_bfr[0],
+ usedMode = &usedMode )
+ MODIFYING(nothing)
+ RETURNING(return_value = 0)
+
+ // Determine transmit frame type
+ CALL sid_sync(st = pSidSyncState,
+ mode = usedMode
+ tx_frame_type = &tx_frame_type)
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ IF (tx_frame_type != TX_NO_DATA)
+ THEN
+ // There is data to transmit
+ *p3gpp_frame_type = (enum Frame_Type_3GPP) usedMode
+
+ // Add SID type and mode info for SID frames
+ IF (*p3gpp_frame_type == AMR_SID)
+ THEN
+ // Add SID type to encoder output buffer
+ IF (tx_frame_type == TX_SID_FIRST)
+ THEN
+ ets_output_bfr[AMRSID_TXTYPE_BIT_OFFSET] &= 0x7f
+
+ ELSEIF (tx_frame_type == TX_SID_UPDATE )
+ THEN
+ ets_output_bfr[AMRSID_TXTYPE_BIT_OFFSET] |= 0x80
+
+ ENDIF
+
+ // Add mode information bits
+ FOR i = 0 TO NUM_AMRSID_TXMODE_BITS-1
+
+ ets_output_bfr[AMRSID_TXMODE_BIT_OFFSET+i] = (mode>>i)&&0x0001
+
+ ENDFOR
+
+ ENDIF
+
+ ELSE
+ // There is no data to transmit
+ *p3gpp_frame_type = NO_DATA
+
+ ENDIF
+
+ // Determine the output format to use
+ IF (output_format == AMR_TX_WMF)
+ THEN
+ // Change output data format to WMF
+ CALL ets_to_wmf( frame_type_3gpp = *p3gpp_frame_type,
+ ets_input_ptr = &ets_output_bfr[0],
+ wmf_output_ptr = pEncOutput )
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ // Set up the number of encoded WMF bytes
+ num_enc_bytes = WmfEncBytesPerFrame[(int) *p3gpp_frame_type]
+
+ ELSEIF (output_format == AMR_TX_IF2)
+ THEN
+ // Change output data format to IF2
+ CALL ets_to_if2( frame_type_3gpp = *p3gpp_frame_type,
+ ets_input_ptr = &ets_output_bfr[0],
+ if2_output_ptr = pEncOutput )
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ // Set up the number of encoded IF2 bytes
+ num_enc_bytes = If2EncBytesPerFrame[(int) *p3gpp_frame_type]
+
+ ENDIF
+
+ ELSEIF (output_format = AMR_TX_ETS)
+ THEN
+ // Encode one speech frame (20 ms)
+ CALL GSMEncodeFrame( state_data = pEncState,
+ mode = mode,
+ new_speech = pEncInput,
+ serial = &ets_output_bfr[1],
+ usedMode = &usedMode )
+ MODIFYING(nothing)
+ RETURNING(return_value = 0)
+
+ // Save used mode
+ *p3gpp_frame_type = (enum Frame_Type_3GPP) usedMode
+
+ // Determine transmit frame type
+ CALL sid_sync(st = pSidSyncState,
+ mode = usedMode
+ tx_frame_type = &tx_frame_type)
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ // Put TX frame type in output buffer
+ ets_output_bfr[0] = tx_frame_type
+
+ // Put mode information after the encoded speech parameters
+ IF (tx_frame_type != TX_NO_DATA)
+ THEN
+ ets_output_bfr[MAX_SERIAL_SIZE+1] = mode
+
+ ELSE
+ ets_output_bfr[MAX_SERIAL_SIZE+1] = -1
+
+ ENDIF
+
+ // Copy output of encoder to pEncOutput buffer
+ ets_output_ptr = (unsigned char *) &ets_output_bfr[0]
+
+ // Copy 16-bit data in 8-bit chunks using Little Endian configuration
+ FOR i = 0 TO (2*(MAX_SERIAL_SIZE+6))-1
+
+ *(pEncOutput+i) = *ets_output_ptr
+ ets_output_ptr = ets_output_ptr + 1
+
+ ENDFOR
+
+ // Set up number of encoded bytes
+ num_enc_bytes = 2*(MAX_SERIAL_SIZE+6)
+
+ ELSE
+ // Invalid output_format, set up error code
+ num_enc_bytes = -1
+
+ ENDIF
+
+ MODIFY (nothing)
+ RETURN (num_enc_bytes)
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 AMREncode(
+ void *pEncState,
+ void *pSidSyncState,
+ enum Mode mode,
+ Word16 *pEncInput,
+ UWord8 *pEncOutput,
+ enum Frame_Type_3GPP *p3gpp_frame_type,
+ Word16 output_format
+)
+{
+ Word16 ets_output_bfr[MAX_SERIAL_SIZE+2];
+ UWord8 *ets_output_ptr;
+ Word16 num_enc_bytes = -1;
+ Word16 i;
+ enum TXFrameType tx_frame_type;
+ enum Mode usedMode = MR475;
+
+ /* Encode WMF or IF2 frames */
+ if ((output_format == AMR_TX_WMF) | (output_format == AMR_TX_IF2))
+ {
+ /* Encode one speech frame (20 ms) */
+
+#ifndef CONSOLE_ENCODER_REF
+
+ /* Use PV version of sp_enc.c */
+ GSMEncodeFrame(pEncState, mode, pEncInput, ets_output_bfr, &usedMode);
+
+#else
+ /* Use ETS version of sp_enc.c */
+ Speech_Encode_Frame(pEncState, mode, pEncInput, ets_output_bfr, &usedMode);
+
+#endif
+
+ /* Determine transmit frame type */
+ sid_sync(pSidSyncState, usedMode, &tx_frame_type);
+
+ if (tx_frame_type != TX_NO_DATA)
+ {
+ /* There is data to transmit */
+ *p3gpp_frame_type = (enum Frame_Type_3GPP) usedMode;
+
+ /* Add SID type and mode info for SID frames */
+ if (*p3gpp_frame_type == AMR_SID)
+ {
+ /* Add SID type to encoder output buffer */
+ if (tx_frame_type == TX_SID_FIRST)
+ {
+ ets_output_bfr[AMRSID_TXTYPE_BIT_OFFSET] &= 0x0000;
+ }
+ else if (tx_frame_type == TX_SID_UPDATE)
+ {
+ ets_output_bfr[AMRSID_TXTYPE_BIT_OFFSET] |= 0x0001;
+ }
+
+ /* Add mode information bits */
+ for (i = 0; i < NUM_AMRSID_TXMODE_BITS; i++)
+ {
+ ets_output_bfr[AMRSID_TXMODE_BIT_OFFSET+i] =
+ (mode >> i) & 0x0001;
+ }
+ }
+ }
+ else
+ {
+ /* This is no data to transmit */
+ *p3gpp_frame_type = (enum Frame_Type_3GPP)AMR_NO_DATA;
+ }
+
+ /* At this point, output format is ETS */
+ /* Determine the output format to use */
+ if (output_format == AMR_TX_WMF)
+ {
+ /* Change output data format to WMF */
+ ets_to_wmf(*p3gpp_frame_type, ets_output_bfr, pEncOutput);
+
+ /* Set up the number of encoded WMF bytes */
+ num_enc_bytes = WmfEncBytesPerFrame[(Word16) *p3gpp_frame_type];
+
+ }
+ else if (output_format == AMR_TX_IF2)
+ {
+ /* Change output data format to IF2 */
+ ets_to_if2(*p3gpp_frame_type, ets_output_bfr, pEncOutput);
+
+ /* Set up the number of encoded IF2 bytes */
+ num_enc_bytes = If2EncBytesPerFrame[(Word16) *p3gpp_frame_type];
+
+ }
+ }
+
+ /* Encode ETS frames */
+ else if (output_format == AMR_TX_ETS)
+ {
+ /* Encode one speech frame (20 ms) */
+
+#ifndef CONSOLE_ENCODER_REF
+
+ /* Use PV version of sp_enc.c */
+ GSMEncodeFrame(pEncState, mode, pEncInput, &ets_output_bfr[1], &usedMode);
+
+#else
+ /* Use ETS version of sp_enc.c */
+ Speech_Encode_Frame(pEncState, mode, pEncInput, &ets_output_bfr[1], &usedMode);
+
+#endif
+
+ /* Save used mode */
+ *p3gpp_frame_type = (enum Frame_Type_3GPP) usedMode;
+
+ /* Determine transmit frame type */
+ sid_sync(pSidSyncState, usedMode, &tx_frame_type);
+
+ /* Put TX frame type in output buffer */
+ ets_output_bfr[0] = tx_frame_type;
+
+ /* Put mode information after the encoded speech parameters */
+ if (tx_frame_type != TX_NO_DATA)
+ {
+ ets_output_bfr[1+MAX_SERIAL_SIZE] = (Word16) mode;
+ }
+ else
+ {
+ ets_output_bfr[1+MAX_SERIAL_SIZE] = -1;
+ }
+
+ /* Copy output of encoder to pEncOutput buffer */
+ ets_output_ptr = (UWord8 *) & ets_output_bfr[0];
+
+ /* Copy 16-bit data in 8-bit chunks */
+ /* using Little Endian configuration */
+ for (i = 0; i < 2*(MAX_SERIAL_SIZE + 2); i++)
+ {
+ *(pEncOutput + i) = *ets_output_ptr;
+ ets_output_ptr += 1;
+ }
+
+ /* Set up the number of encoded bytes */
+ num_enc_bytes = 2 * (MAX_SERIAL_SIZE + 2);
+
+ }
+
+ /* Invalid frame format */
+ else
+ {
+ /* Invalid output format, set up error code */
+ num_enc_bytes = -1;
+ }
+
+ return(num_enc_bytes);
+}
+
+
diff --git a/media/codecs/amrnb/enc/src/amrencode.h b/media/codecs/amrnb/enc/src/amrencode.h
new file mode 100644
index 0000000..1e85db1
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/amrencode.h
@@ -0,0 +1,156 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/include/amrencode.h
+
+ Date: 02/01/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Removed hard tabs from file.
+
+ Description: Added #define for WMF and IF2, and updated function prototype.
+
+ Description: Renamed WMF to AMR_WMF, IF2 to AMR_IF2, and added AMR_ETS.
+
+ Description: Changed output_type to output_format.
+
+ Description: Added external reference to WmfEncBytesPerFrame and
+ If2EncBytesPerFrame tables.
+
+ Description: Updated function prototype for AMREncode(). Added function
+ prototype for AMREncodeInit, AMREncodeReset, and AMREncodeExit.
+ Added #defines for TX SID frame formatting.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the function prototype of AMREncode.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _AMRENCODE_H_
+#define _AMRENCODE_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "frame_type_3gpp.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+#define NUM_AMRSID_TXMODE_BITS 3
+#define AMRSID_TXMODE_BIT_OFFSET 36
+#define AMRSID_TXTYPE_BIT_OFFSET 35
+
+ /* Output format types */
+#define AMR_TX_WMF 0
+#define AMR_TX_IF2 1
+#define AMR_TX_ETS 2
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+ extern const Word16 WmfEncBytesPerFrame[];
+ extern const Word16 If2EncBytesPerFrame[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 AMREncodeInit(
+ void **pEncStructure,
+ void **pSidSyncStructure,
+ Flag dtx_enable);
+
+ Word16 AMREncodeReset(
+ void *pEncStructure,
+ void *pSidSyncStructure);
+
+ void AMREncodeExit(
+ void **pEncStructure,
+ void **pSidSyncStructure);
+
+ Word16 AMREncode(
+ void *pEncState,
+ void *pSidSyncState,
+ enum Mode mode,
+ Word16 *pEncInput,
+ UWord8 *pEncOutput,
+ enum Frame_Type_3GPP *p3gpp_frame_type,
+ Word16 output_format
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _AMRENCODE_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/autocorr.cpp b/media/codecs/amrnb/enc/src/autocorr.cpp
new file mode 100644
index 0000000..c71811d
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/autocorr.cpp
@@ -0,0 +1,459 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/autocorr.c
+
+ Date: 05/15/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Put into template...starting optimization.
+
+ Description: Removed call to mult_r routine.
+
+ Description: Modified Input/Output Definitions section to comply with the
+ current template. Fixed tabs.
+
+ Description: Updated Input/Output definitions by making them more
+ descriptive.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Added full pathname of file.
+ 2. Fixed typecasting issue with TI compiler.
+ 3. Modified FOR loops to count down.
+ 4. Added comment to the code.
+
+ Description: Removed extern to global paramter (Flag Overflow) and replaced
+ by passing in a pointer to Overflow. Also, made several small changes to
+ bring code more in line with PV Standards.
+
+ Description:
+ 1. Added pointer to avoid adding offsets in every pass
+ 2. Break last loop in two nested loop to speed up processing
+ 3. Removed extra check for overflow by doing scaling right
+ after overflow is detected.
+ 4. Eliminated calls to basic operations (like extract) not
+ needed because of the nature of the number (all bounded)
+
+ Description:
+ 1. Fixed for:
+ overflow check was looking for positive number before a left
+ shift. When numbers were big enough, positive numbers after
+ shifted became negative, causing a 1/0 division).
+ Fixed so now it checks for numbers lesser than 0x40000000
+ before the left shift
+
+ Description:
+ 1.Modified check for saturation to match bit exact test.
+ Also, when saturation is reached, a faster loop is used
+ (with no energy accumulation) to speed up processing
+
+
+ Description:
+ 1.Added pointer initialization to for loop when saturation
+ is found. This because some compiler ( like Vcpp in release
+ mode) when optimizing code, may remove pointer information
+ once the loop is broken.
+
+ Description: Added casting to eliminate warnings
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Using inlines from fxp_arithmetic.h.
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "autocorr.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Autocorr
+----------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x = buffer of input signals of type Word16
+ m = LPC order of type Word16
+ wind = buffer of window signals of type Word16
+ r_h = buffer containing the high word of the autocorrelation values
+ of type Word16
+ r_l = buffer containing the low word of the autocorrelation values
+ of type Word16
+
+ pOverflow = pointer to variable of type Flag *, which indicates if
+ overflow occurs.
+
+ Outputs:
+ r_h buffer contains the high word of the new autocorrelation values
+ r_l buffer contains the low word of the new autocorrelation values
+ pOverflow -> 1 if overflow occurs.
+
+ Returns:
+ norm = normalized autocorrelation at lag zero of type Word16
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function windows the input signal with the provided window
+ then calculates the autocorrelation values for lags of 0,1,...m,
+ where m is the passed in LPC order.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ autocorr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Autocorr (
+ Word16 x[], // (i) : Input signal (L_WINDOW)
+ Word16 m, // (i) : LPC order
+ Word16 r_h[], // (o) : Autocorrelations (msb)
+ Word16 r_l[], // (o) : Autocorrelations (lsb)
+ const Word16 wind[] // (i) : window for LPC analysis (L_WINDOW)
+)
+{
+ Word16 i, j, norm;
+ Word16 y[L_WINDOW];
+ Word32 sum;
+ Word16 overfl, overfl_shft;
+
+ // Windowing of signal
+
+ for (i = 0; i < L_WINDOW; i++)
+ {
+ y[i] = mult_r (x[i], wind[i]);
+ }
+
+ // Compute r[0] and test for overflow
+
+ overfl_shft = 0;
+
+ do
+ {
+ overfl = 0;
+ sum = 0L;
+
+ for (i = 0; i < L_WINDOW; i++)
+ {
+ sum = L_mac (sum, y[i], y[i]);
+ }
+
+ // If overflow divide y[] by 4
+
+ if (L_sub (sum, MAX_32) == 0L)
+ {
+ overfl_shft = add (overfl_shft, 4);
+ overfl = 1; // Set the overflow flag
+
+ for (i = 0; i < L_WINDOW; i++)
+ {
+ y[i] = shr (y[i], 2);
+ }
+ }
+ }
+ while (overfl != 0);
+
+ sum = L_add (sum, 1L); // Avoid the case of all zeros
+
+ // Normalization of r[0]
+
+ norm = norm_l (sum);
+ sum = L_shl (sum, norm);
+ L_Extract (sum, &r_h[0], &r_l[0]); // Put in DPF format (see oper_32b)
+
+ // r[1] to r[m]
+
+ for (i = 1; i <= m; i++)
+ {
+ sum = 0;
+
+ for (j = 0; j < L_WINDOW - i; j++)
+ {
+ sum = L_mac (sum, y[j], y[j + i]);
+ }
+
+ sum = L_shl (sum, norm);
+ L_Extract (sum, &r_h[i], &r_l[i]);
+ }
+
+ norm = sub (norm, overfl_shft);
+
+ return norm;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Autocorr(
+ Word16 x[], /* (i) : Input signal (L_WINDOW) */
+ Word16 m, /* (i) : LPC order */
+ Word16 r_h[], /* (o) : Autocorrelations (msb) */
+ Word16 r_l[], /* (o) : Autocorrelations (lsb) */
+ const Word16 wind[], /* (i) : window for LPC analysis (L_WINDOW) */
+ Flag *pOverflow /* (o) : indicates overflow */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 norm;
+
+ Word16 y[L_WINDOW];
+ Word32 sum;
+ Word16 overfl_shft;
+
+
+ /* Added for optimization */
+
+
+ Word16 temp;
+ Word16 *p_x;
+ Word16 *p_y;
+ Word16 *p_y_1;
+ Word16 *p_y_ref;
+ Word16 *p_rh;
+ Word16 *p_rl;
+ const Word16 *p_wind;
+ p_y = y;
+ p_x = x;
+ p_wind = wind;
+ /*
+ * Windowing of the signal
+ */
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ sum = 0L;
+ j = 0;
+
+ for (i = L_WINDOW; i != 0; i--)
+ {
+ temp = (amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_wind++), 0x04000)) >> 15;
+ *(p_y++) = temp;
+
+ sum += ((Word32)temp * temp) << 1;
+ if (sum < 0)
+ {
+ /*
+ * if oveflow exist, then stop accumulation
+ */
+ j = 1;
+ break;
+ }
+
+ }
+ /*
+ * if oveflow existed, complete windowing operation
+ * without computing energy
+ */
+
+ if (j)
+ {
+ p_y = &y[L_WINDOW-i];
+ p_x = &x[L_WINDOW-i];
+ p_wind = &wind[L_WINDOW-i];
+
+ for (; i != 0; i--)
+ {
+ temp = (amrnb_fxp_mac_16_by_16bb((Word32) * (p_x++), (Word32) * (p_wind++), 0x04000)) >> 15;
+ *(p_y++) = temp;
+ }
+ }
+
+
+ /*
+ * Compute r[0] and test for overflow
+ */
+
+ overfl_shft = 0;
+
+ /*
+ * scale down by 1/4 only when needed
+ */
+ while (j == 1)
+ {
+ /* If overflow divide y[] by 4 */
+ /* FYI: For better resolution, we could */
+ /* divide y[] by 2 */
+ overfl_shft += 4;
+ p_y = &y[0];
+ sum = 0L;
+
+ for (i = (L_WINDOW >> 1); i != 0 ; i--)
+ {
+ temp = *p_y >> 2;
+ *(p_y++) = temp;
+ sum += ((Word32)temp * temp) << 1;
+ temp = *p_y >> 2;
+ *(p_y++) = temp;
+ sum += ((Word32)temp * temp) << 1;
+ }
+ if (sum > 0)
+ {
+ j = 0;
+ }
+
+ }
+
+ sum += 1L; /* Avoid the case of all zeros */
+
+ /* Normalization of r[0] */
+
+ norm = norm_l(sum);
+
+ sum <<= norm;
+
+ /* Put in DPF format (see oper_32b) */
+ r_h[0] = (Word16)(sum >> 16);
+ r_l[0] = (Word16)((sum >> 1) - ((Word32)(r_h[0]) << 15));
+
+ /* r[1] to r[m] */
+
+ p_y_ref = &y[L_WINDOW - 1 ];
+ p_rh = &r_h[m];
+ p_rl = &r_l[m];
+
+ for (i = m; i > 0; i--)
+ {
+ sum = 0;
+
+ p_y = &y[L_WINDOW - i - 1];
+ p_y_1 = p_y_ref;
+
+ for (j = (L_WINDOW - i - 1) >> 1; j != 0; j--)
+ {
+ sum = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y--), (Word32) * (p_y_1--), sum);
+ sum = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y--), (Word32) * (p_y_1--), sum);
+ }
+
+ sum = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y--), (Word32) * (p_y_1--), sum);
+
+ if (((L_WINDOW - i - 1) & 1))
+ {
+ sum = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y--), (Word32) * (p_y_1--), sum);
+ }
+
+ sum <<= (norm + 1);
+
+ *(p_rh) = (Word16)(sum >> 16);
+ *(p_rl--) = (Word16)((sum >> 1) - ((Word32) * (p_rh--) << 15));
+
+ }
+
+ norm -= overfl_shft;
+
+ return (norm);
+
+} /* Autocorr */
diff --git a/media/codecs/amrnb/enc/src/autocorr.h b/media/codecs/amrnb/enc/src/autocorr.h
new file mode 100644
index 0000000..6045d6e
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/autocorr.h
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/autocorr.h
+
+ Date: 01/23/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the autocorr function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef autocorr_h
+#define autocorr_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 Autocorr(
+ Word16 x[], /* (i) : Input signal (L_WINDOW) */
+ Word16 m, /* (i) : LPC order */
+ Word16 r_h[], /* (o) : Autocorrelations (msb) */
+ Word16 r_l[], /* (o) : Autocorrelations (lsb) */
+ const Word16 wind[], /* (i) : window for LPC analysis (L_WINDOW) */
+ Flag *pOverflow /* (o) : indicates overflow */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _AUTO_CORR_H_ */
diff --git a/media/codecs/amrnb/enc/src/c1035pf.cpp b/media/codecs/amrnb/enc/src/c1035pf.cpp
new file mode 100644
index 0000000..d95995c
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c1035pf.cpp
@@ -0,0 +1,676 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/c1035pf.c
+ Functions: q_p
+ build_code
+ code_10i40_35bits
+
+
+ Date: 09/28/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Cleaned up code. Passing in a pointer to
+ overflow flag for build_code() and code_10i40_35bits() functions.
+ Removed unnecessary header files.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation
+ 4. Replaced for-loops with memset()
+
+ Description: Changed function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the function that searches a 35 bit algebraic codebook
+ containing 10 pulses in a frame of 40 samples.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "c1035pf.h"
+#include "cnst.h"
+#include "basic_op.h"
+#include "inv_sqrt.h"
+#include "set_sign.h"
+#include "cor_h.h"
+#include "cor_h_x.h"
+#include "s10_8pf.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+#define NB_PULSE 10
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: q_p
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pShift_reg = pointer to Old CN generator shift register state (Word32)
+ no_bits = Number of bits (Word16)
+
+ Outputs:
+ pShift_reg -> Updated CN generator shift register state
+
+ Returns:
+ noise_bits = Generated random integer value (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This is a local function that determnes the index of the pulses by looking up
+ the gray encoder table
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c1035pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void q_p (
+ Word16 *ind, // Pulse position
+ Word16 n // Pulse number
+)
+{
+ Word16 tmp;
+
+ tmp = *ind;
+
+ if (sub (n, 5) < 0)
+ {
+ *ind = (tmp & 0x8) | gray[tmp & 0x7];
+ }
+ else
+ {
+ *ind = gray[tmp & 0x7];
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void q_p(
+ Word16 *pInd, /* Pulse position */
+ Word16 n /* Pulse number */
+)
+{
+ Word16 tmp;
+
+ tmp = *pInd;
+
+ if (n < 5)
+ {
+ *pInd = (tmp & 0x8) | gray[tmp & 0x7];
+ }
+ else
+ {
+ *pInd = gray[tmp & 0x7];
+ }
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: build_code
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pSeed = pointer to the Old CN generator shift register state (Word32)
+ n_param = Number of parameters to randomize (Word16)
+ param_size_table = table holding paameter sizes (Word16)
+ param[] = array to hold CN generated paramters (Word16)
+ pOverflow = pointer to overflow flag (Flag)
+
+ Outputs:
+ param[] = CN generated parameters (Word16)
+ pSeed = Updated CN generator shift register state (Word16)
+ pOverflow -> 1 if overflow occured
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function builds the codeword, the filtered codeword and index of the
+ codevector, based on the signs and positions of 10 pulses.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c1035pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+static void build_code (
+ Word16 codvec[], // (i) : position of pulses
+ Word16 sign[], // (i) : sign of d[n]
+ Word16 cod[], // (o) : innovative code vector
+ Word16 h[], // (i) : impulse response of weighted synthesis filter
+ Word16 y[], // (o) : filtered innovative code
+ Word16 indx[] // (o) : index of 10 pulses (sign+position)
+)
+{
+ Word16 i, j, k, track, index, _sign[NB_PULSE];
+ Word16 *p0, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
+ Word32 s;
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ cod[i] = 0;
+ }
+ for (i = 0; i < NB_TRACK; i++)
+ {
+ indx[i] = -1;
+ }
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ // read pulse position
+ i = codvec[k];
+ // read sign
+ j = sign[i];
+
+ index = mult (i, 6554); // index = pos/5
+ // track = pos%5
+ track = sub (i, extract_l (L_shr (L_mult (index, 5), 1)));
+
+ if (j > 0)
+ {
+ cod[i] = add (cod[i], 4096);
+ _sign[k] = 8192;
+
+ }
+ else
+ {
+ cod[i] = sub (cod[i], 4096);
+ _sign[k] = -8192;
+ index = add (index, 8);
+ }
+
+ if (indx[track] < 0)
+ {
+ indx[track] = index;
+ }
+ else
+ {
+ if (((index ^ indx[track]) & 8) == 0)
+ {
+ // sign of 1st pulse == sign of 2nd pulse
+
+ if (sub (indx[track], index) <= 0)
+ {
+ indx[track + 5] = index;
+ }
+ else
+ {
+ indx[track + 5] = indx[track];
+ indx[track] = index;
+ }
+ }
+ else
+ {
+ // sign of 1st pulse != sign of 2nd pulse
+
+ if (sub ((Word16)(indx[track] & 7), (Word16)(index & 7)) <= 0)
+ {
+ indx[track + 5] = indx[track];
+ indx[track] = index;
+ }
+ else
+ {
+ indx[track + 5] = index;
+ }
+ }
+ }
+ }
+
+ p0 = h - codvec[0];
+ p1 = h - codvec[1];
+ p2 = h - codvec[2];
+ p3 = h - codvec[3];
+ p4 = h - codvec[4];
+ p5 = h - codvec[5];
+ p6 = h - codvec[6];
+ p7 = h - codvec[7];
+ p8 = h - codvec[8];
+ p9 = h - codvec[9];
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = 0;
+ s = L_mac (s, *p0++, _sign[0]);
+ s = L_mac (s, *p1++, _sign[1]);
+ s = L_mac (s, *p2++, _sign[2]);
+ s = L_mac (s, *p3++, _sign[3]);
+ s = L_mac (s, *p4++, _sign[4]);
+ s = L_mac (s, *p5++, _sign[5]);
+ s = L_mac (s, *p6++, _sign[6]);
+ s = L_mac (s, *p7++, _sign[7]);
+ s = L_mac (s, *p8++, _sign[8]);
+ s = L_mac (s, *p9++, _sign[9]);
+ y[i] = pv_round (s);
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+static void build_code(
+ Word16 codvec[], /* (i) : position of pulses */
+ Word16 sign[], /* (i) : sign of d[n] */
+ Word16 cod[], /* (o) : innovative code vector */
+ Word16 h[], /* (i) : impulse response of weighted synthesis filter*/
+ Word16 y[], /* (o) : filtered innovative code */
+ Word16 indx[], /* (o) : index of 10 pulses (sign+position) */
+ Flag *pOverflow /* i/o : overflow Flag */
+)
+{
+ Word16 i, k, track, index, _sign[NB_PULSE];
+ Word16 *p0, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
+ Word32 s;
+ Word16 temp;
+ Word16 *p__sign;
+ Word16 *p_y;
+ Word16 *p_codvec;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ memset(cod, 0, L_CODE*sizeof(*cod));
+ memset(indx, 0xFF, NB_TRACK*sizeof(*indx));
+
+ p__sign = _sign;
+
+ p0 = &codvec[0];
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ /* read pulse position */
+ i = *(p0++);
+ /* read sign */
+
+ index = ((Word32)i * 6554) >> 15; /* index = pos/5 */
+
+ /* track = pos%5 */
+ /* track = sub (i, extract_l (L_shr (L_mult (index, 5), 1))); */
+ track = i - (index * 5);
+
+ if (sign[i] > 0)
+ {
+ cod[i] += 4096;
+ *(p__sign++) = 8192;
+
+ }
+ else
+ {
+ cod[i] -= 4096;
+ *(p__sign++) = -8192;
+ /* index = add (index, 8); */
+ index += 8;
+ }
+
+ p1 = &indx[track];
+
+ temp = *p1;
+
+ if (temp < 0)
+ {
+ *p1 = index;
+ }
+ else
+ {
+ if (((index ^ temp) & 8) == 0)
+ {
+ /* sign of 1st pulse == sign of 2nd pulse */
+
+ /* if (sub (indx[track], index) <= 0) */
+ if (temp <= index)
+ {
+ *(p1 + 5) = index;
+ }
+ else
+ {
+ *(p1 + 5) = temp;
+ *p1 = index;
+ }
+ }
+ else
+ {
+ /* sign of 1st pulse != sign of 2nd pulse */
+
+ /* if (sub ((Word16)(indx[track] & 7), (Word16)(index & 7)) <= 0) */
+ if ((temp & 7) <= (index & 7))
+ {
+ *(p1 + 5) = temp;
+ *p1 = index;
+ }
+ else
+ {
+ *(p1 + 5) = index;
+ }
+ }
+ }
+ }
+
+ p_codvec = &codvec[0];
+
+ p0 = h - *(p_codvec++);
+ p1 = h - *(p_codvec++);
+ p2 = h - *(p_codvec++);
+ p3 = h - *(p_codvec++);
+ p4 = h - *(p_codvec++);
+ p5 = h - *(p_codvec++);
+ p6 = h - *(p_codvec++);
+ p7 = h - *(p_codvec++);
+ p8 = h - *(p_codvec++);
+ p9 = h - *(p_codvec++);
+
+ p_y = y;
+
+ for (i = L_CODE; i != 0; i--)
+ {
+ p__sign = _sign;
+
+ s = (*p0++ * *(p__sign++)) >> 7;
+ s += (*p1++ * *(p__sign++)) >> 7;
+ s += (*p2++ * *(p__sign++)) >> 7;
+ s += (*p3++ * *(p__sign++)) >> 7;
+ s += (*p4++ * *(p__sign++)) >> 7;
+ s += (*p5++ * *(p__sign++)) >> 7;
+ s += (*p6++ * *(p__sign++)) >> 7;
+ s += (*p7++ * *(p__sign++)) >> 7;
+ s += (*p8++ * *(p__sign++)) >> 7;
+ s += (*p9++ * *(p__sign++)) >> 7;
+
+ *(p_y++) = (s + 0x080) >> 8;
+ }
+
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: code_10i40_35bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pSeed = pointer to the Old CN generator shift register state (Word32)
+ n_param = Number of parameters to randomize (Word16)
+ param_size_table = table holding paameter sizes (Word16)
+ param[] = array to hold CN generated paramters (Word16)
+ pOverflow = pointer to overflow flag (Flag)
+
+ Outputs:
+ param[] = CN generated parameters (Word16)
+ pSeed = Updated CN generator shift register state (Word16)
+ pOverflow -> 1 if overflow occured
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function searches a 35 bit algebraic codebook containing 10 pulses in a
+ frame of 40 samples.
+
+ The code contains 10 nonzero pulses: i0...i9.
+ All pulses can have two possible amplitudes: +1 or -1.
+ The 40 positions in a subframe are divided into 5 tracks of
+ interleaved positions. Each track contains two pulses.
+ The pulses can have the following possible positions:
+
+ i0, i5 : 0, 5, 10, 15, 20, 25, 30, 35.
+ i1, i6 : 1, 6, 11, 16, 21, 26, 31, 36.
+ i2, i7 : 2, 7, 12, 17, 22, 27, 32, 37.
+ i3, i8 : 3, 8, 13, 18, 23, 28, 33, 38.
+ i4, i9 : 4, 9, 14, 19, 24, 29, 34, 39.
+
+ Each pair of pulses require 1 bit for their signs and 6 bits for their
+ positions (3 bits + 3 bits). This results in a 35 bit codebook.
+ The function determines the optimal pulse signs and positions, builds
+ the codevector, and computes the filtered codevector.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c1035pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+void code_10i40_35bits (
+ Word16 x[], // (i) : target vector
+ Word16 cn[], // (i) : residual after long term prediction
+ Word16 h[], // (i) : impulse response of weighted synthesis filter
+ // h[-L_subfr..-1] must be set to zero
+ Word16 cod[], // (o) : algebraic (fixed) codebook excitation
+ Word16 y[], // (o) : filtered fixed codebook excitation
+ Word16 indx[] // (o) : index of 10 pulses (sign + position)
+)
+{
+ Word16 ipos[NB_PULSE], pos_max[NB_TRACK], codvec[NB_PULSE];
+ Word16 dn[L_CODE], sign[L_CODE];
+ Word16 rr[L_CODE][L_CODE], i;
+
+ cor_h_x (h, x, dn, 2);
+ set_sign12k2 (dn, cn, sign, pos_max, NB_TRACK, ipos, STEP);
+ cor_h (h, sign, rr);
+
+ search_10and8i40 (NB_PULSE, STEP, NB_TRACK,
+ dn, rr, ipos, pos_max, codvec);
+
+ build_code (codvec, sign, cod, h, y, indx);
+ for (i = 0; i < 10; i++)
+ {
+ q_p (&indx[i], i);
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void code_10i40_35bits(
+ Word16 x[], /* (i) : target vector */
+ Word16 cn[], /* (i) : residual after long term prediction */
+ Word16 h[], /* (i) : impulse response of weighted synthesis filter
+ h[-L_subfr..-1] must be set to zero */
+ Word16 cod[], /* (o) : algebraic (fixed) codebook excitation */
+ Word16 y[], /* (o) : filtered fixed codebook excitation */
+ Word16 indx[], /* (o) : index of 10 pulses (sign + position) */
+ Flag *pOverflow /* (i/o) : overflow Flag */
+)
+{
+ Word16 ipos[NB_PULSE], pos_max[NB_TRACK], codvec[NB_PULSE];
+ Word16 dn[L_CODE], sign[L_CODE];
+ Word16 rr[L_CODE][L_CODE], i;
+
+ cor_h_x(h, x, dn, 2, pOverflow);
+ set_sign12k2(dn, cn, sign, pos_max, NB_TRACK, ipos, STEP, pOverflow);
+ cor_h(h, sign, rr, pOverflow);
+
+ search_10and8i40(NB_PULSE, STEP, NB_TRACK,
+ dn, rr, ipos, pos_max, codvec, pOverflow);
+
+ build_code(codvec, sign, cod, h, y, indx, pOverflow);
+ for (i = 0; i < 10; i++)
+ {
+ q_p(&indx[i], i);
+ }
+ return;
+}
+
diff --git a/media/codecs/amrnb/enc/src/c1035pf.h b/media/codecs/amrnb/enc/src/c1035pf.h
new file mode 100644
index 0000000..be45cbb
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c1035pf.h
@@ -0,0 +1,124 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/c1035pf.h
+
+ Date: 09/28/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Updated function prototype for
+ code_10i40_35bits(). Added extern declaration for gray[] defined
+ in gray_tbl.c
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the prototype declaration for code_10i40_35bits function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef C1035PF_H
+#define C1035PF_H "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern Word16 gray[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void code_10i40_35bits(
+ Word16 x[], /* (i) : target vector */
+ Word16 cn[], /* (i) : residual after long term prediction */
+ Word16 h[], /* (i) : impulse response of weighted synthesis filter
+ h[-L_subfr..-1] must be set to zero */
+ Word16 cod[], /* (o) : algebraic (fixed) codebook excitation */
+ Word16 y[], /* (o) : filtered fixed codebook excitation */
+ Word16 indx[], /* (o) : index of 10 pulses (sign + position) */
+ Flag *pOverflow /* (i/o) : overflow Flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _C1035PF_H_ */
diff --git a/media/codecs/amrnb/enc/src/c2_11pf.cpp b/media/codecs/amrnb/enc/src/c2_11pf.cpp
new file mode 100644
index 0000000..87fa9b8
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c2_11pf.cpp
@@ -0,0 +1,841 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/c2_11pf.c
+ Functions:
+ code_2i40_11bits
+ search_2i40
+ build_code
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to pass overflow flag through to basic math function.
+ The flag is passed back to the calling function by pointer reference.
+
+ Description: Fixed tabs prior to optimization to make diff'ing easier.
+ Optimized search_2i40() to reduce clock cycle usage.
+
+ Description: Optimized build_code() to reduce clock cycle usage.
+
+ Description: Changed function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Added casting to eliminate warnings
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ *************************************************************************
+ *
+ * FUNCTION: code_2i40_11bits()
+ *
+ * PURPOSE: Searches a 11 bit algebraic codebook containing 2 pulses
+ * in a frame of 40 samples.
+ *
+ * DESCRIPTION:
+ * The code length is 40, containing 2 nonzero pulses: i0...i1.
+ * All pulses can have two possible amplitudes: +1 or -1.
+ * Pulse i0 can have 2x8=16 possible positions, pulse i1 can have
+ * 4x8=32 positions.
+ *
+ * i0 : 1, 6, 11, 16, 21, 26, 31, 36.
+ * 3, 8, 13, 18, 23, 28, 33, 38.
+ * i1 : 0, 5, 10, 15, 20, 25, 30, 35.
+ * 1, 6, 11, 16, 21, 26, 31, 36.
+ * 2, 7, 12, 17, 22, 27, 32, 37.
+ * 4, 9, 14, 19, 24, 29, 34, 39.
+ *
+ *************************************************************************
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "c2_11pf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "inv_sqrt.h"
+#include "cnst.h"
+#include "cor_h.h"
+#include "set_sign.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NB_PULSE 2
+
+#define _1_2 (Word16)(32768L/2)
+#define _1_4 (Word16)(32768L/4)
+#define _1_8 (Word16)(32768L/8)
+#define _1_16 (Word16)(32768L/16)
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+static void search_2i40(
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 rr[][L_CODE],/* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow
+);
+
+static Word16 build_code(
+ Word16 codvec[], /* i : algebraic codebook vector */
+ Word16 dn_sign[], /* i : sign of dn[] */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 sign[], /* o : sign of 2 pulses */
+ Flag * pOverflow
+);
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+const Word16 startPos1[2] = {1, 3};
+const Word16 startPos2[4] = {0, 1, 2, 4};
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: code_2i40_11bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x, target vector, array of type Word16
+ h, impulse response of weighted synthesis filter, array of type Word16
+ T0, Pitch lag, variable of type Word16
+ pitch_sharp, Last quantized pitch gain, variable of type Word16
+
+ Outputs:
+ code[], Innovative codebook, array of type Word16
+ y[], filtered fixed codebook excitation, array of type Word16
+ sign, Signs of 2 pulses, pointer of type Word16 *
+ pOverflow Flag set when overflow occurs, pointer of type Flag *
+
+ Returns:
+ index
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Searches a 11 bit algebraic codebook containing 2 pulses
+ in a frame of 40 samples.
+
+ The code length is 40, containing 2 nonzero pulses: i0...i1.
+ All pulses can have two possible amplitudes: +1 or -1.
+ Pulse i0 can have 2x8=16 possible positions, pulse i1 can have
+ 4x8=32 positions.
+
+ i0 : 1, 6, 11, 16, 21, 26, 31, 36.
+ 3, 8, 13, 18, 23, 28, 33, 38.
+ i1 : 0, 5, 10, 15, 20, 25, 30, 35.
+ 1, 6, 11, 16, 21, 26, 31, 36.
+ 2, 7, 12, 17, 22, 27, 32, 37.
+ 4, 9, 14, 19, 24, 29, 34, 39.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 code_2i40_11bits(
+ Word16 x[], /* i : target vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ /* h[-L_subfr..-1] must be set to zero. */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp, /* i : Last quantized pitch gain */
+ Word16 code[], /* o : Innovative codebook */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 * sign, /* o : Signs of 2 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 codvec[NB_PULSE];
+ Word16 dn[L_CODE];
+ Word16 dn2[L_CODE];
+ Word16 dn_sign[L_CODE];
+
+ Word16 rr[L_CODE][L_CODE];
+
+ Word16 i;
+ Word16 index;
+ Word16 sharp;
+ Word16 tempWord;
+
+ sharp = pitch_sharp << 1;
+
+ if (T0 < L_CODE)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ tempWord =
+ mult(
+ h[i - T0],
+ sharp,
+ pOverflow);
+
+ h[i] =
+ add(
+ h[i],
+ tempWord,
+ pOverflow);
+ }
+
+ }
+
+ cor_h_x(
+ h,
+ x,
+ dn,
+ 1,
+ pOverflow);
+
+ set_sign(
+ dn,
+ dn_sign,
+ dn2,
+ 8); /* dn2[] not used in this codebook search */
+
+ cor_h(
+ h,
+ dn_sign,
+ rr,
+ pOverflow);
+
+ search_2i40(
+ dn,
+ rr,
+ codvec,
+ pOverflow);
+
+ /* function result */
+
+ index =
+ build_code(
+ codvec,
+ dn_sign,
+ code,
+ h,
+ y,
+ sign,
+ pOverflow);
+
+ /*
+ * Compute innovation vector gain.
+ * Include fixed-gain pitch contribution into code[].
+ */
+
+ if (T0 < L_CODE)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ tempWord =
+ mult(
+ code[i - T0],
+ sharp,
+ pOverflow);
+
+ code[i] =
+ add(
+ code[i],
+ tempWord,
+ pOverflow);
+ }
+ }
+
+ return index;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: search_2i40
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ dn, correlation between target and h[], array of type Word16
+ rr, matrix of autocorrelation, double-array of type Word16
+
+ Outputs:
+ codvec[], algebraic codebook vector, array of type Word16
+ pOverflow, Flag set when overflow occurs, pointer of type Flag *
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Search the best codevector; determine positions of the 2 pulses
+ in the 40-sample frame.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void search_2i40(
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i0;
+ Word16 i1;
+ Word16 ix = 0; /* initialization only needed to keep gcc silent */
+ Word16 track1;
+ Word16 track2;
+ Word16 ipos[NB_PULSE];
+
+ Word16 psk;
+ Word16 ps0;
+ Word16 ps1;
+ Word16 sq;
+ Word16 sq1;
+
+ Word16 alpk;
+ Word16 alp;
+ Word16 alp_16;
+
+ Word32 s;
+ Word32 alp0;
+ Word32 alp1;
+
+ Word16 i;
+ Word16 *p_codvec = &codvec[0];
+
+ psk = -1;
+ alpk = 1;
+
+ for (i = 0; i < NB_PULSE; i++)
+ {
+ *(p_codvec++) = i;
+ }
+
+ /*------------------------------------------------------------------*
+ * main loop: try 2x4 tracks. *
+ *------------------------------------------------------------------*/
+
+ for (track1 = 0; track1 < 2; track1++)
+ {
+ for (track2 = 0; track2 < 4; track2++)
+ {
+ /* fix starting position */
+ ipos[0] = startPos1[track1];
+ ipos[1] = startPos2[track2];
+
+ /*----------------------------------------------------------------*
+ * i0 loop: try 8 positions. *
+ *----------------------------------------------------------------*/
+ for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP)
+ {
+ ps0 = dn[i0];
+
+ /* alp0 = L_mult(rr[i0][i0], _1_4, pOverflow); */
+ alp0 = (Word32) rr[i0][i0] << 14;
+
+ /*-------------------------------------------------------------*
+ * i1 loop: 8 positions. *
+ *-------------------------------------------------------------*/
+
+ sq = -1;
+ alp = 1;
+ ix = ipos[1];
+
+ /*---------------------------------------------------------------*
+ * These index have low complexity address computation because *
+ * they are, in fact, pointers with fixed increment. For example,*
+ * "rr[i0][i2]" is a pointer initialized to "&rr[i0][ipos[2]]" *
+ * and incremented by "STEP". *
+ *---------------------------------------------------------------*/
+
+ for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP)
+ {
+ /* idx increment = STEP */
+ ps1 = add(ps0, dn[i1], pOverflow);
+
+ /* alp1 = alp0 + rr[i0][i1] + 1/2*rr[i1][i1]; */
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp0, rr[i1][i1], _1_4, pOverflow); */
+ alp1 = alp0 + ((Word32) rr[i1][i1] << 14);
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp1, rr[i0][i1], _1_2, pOverflow); */
+ alp1 += (Word32) rr[i0][i1] << 15;
+
+ /* sq1 = mult(ps1, ps1, pOverflow); */
+ sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);
+
+ /* alp_16 = pv_round(alp1, pOverflow); */
+ alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);
+
+ /* s = L_mult(alp, sq1, pOverflow); */
+ s = ((Word32) alp * sq1) << 1;
+
+ /* s =L_msu(s, sq, alp_16, pOverflow); */
+ s -= (((Word32) sq * alp_16) << 1);
+
+ if (s > 0)
+ {
+ sq = sq1;
+ alp = alp_16;
+ ix = i1;
+ }
+
+ } /* for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP) */
+
+ /* memorize codevector if this one is better than the last one. */
+
+ /* s = L_mult(alpk, sq, pOverflow); */
+ s = ((Word32) alpk * sq) << 1;
+
+ /* s = L_msu(s, psk, alp, pOverflow); */
+ s -= (((Word32) psk * alp) << 1);
+
+ if (s > 0)
+ {
+ psk = sq;
+ alpk = alp;
+ p_codvec = &codvec[0];
+
+ *(p_codvec++) = i0;
+ *(p_codvec) = ix;
+ }
+
+ } /* for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP) */
+
+ } /* for (track2 = 0; track2 < 4; track2++) */
+
+ } /* for (track1 = 0; track1 < 2; track1++) */
+
+ return;
+
+} /* search_2i40 */
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: build_code
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ codvec, position of pulses, array of type Word16
+ dn_sign, sign of pulses, array of type Word16
+ h, impulse response of weighted synthesis filter, Word16 array
+
+ Outputs:
+
+ cod, innovative code vector, array of type Word16
+ y[], filtered innovative code, array of type Word16
+ sign[], sign of 2 pulses, array of type Word16
+ pOverflow, Flag set when overflow occurs, pointer of type Flag *
+
+ Returns:
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Builds the codeword, the filtered codeword and index of the
+ codevector, based on the signs and positions of 2 pulses.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ c2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+static Word16 build_code(
+ Word16 codvec[], /* i : position of pulses */
+ Word16 dn_sign[], /* i : sign of pulses */
+ Word16 cod[], /* o : innovative code vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ Word16 y[], /* o : filtered innovative code */
+ Word16 sign[], /* o : sign of 2 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+ Word16 track;
+ Word16 index;
+ Word16 _sign[NB_PULSE];
+ Word16 indx;
+ Word16 rsign;
+ Word16 tempWord;
+
+ Word16 *p0;
+ Word16 *p1;
+
+ Word32 s;
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ cod[i] = 0;
+ }
+
+ indx = 0;
+ rsign = 0;
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ i = codvec[k]; /* read pulse position */
+ j = dn_sign[i]; /* read sign */
+
+ /* index = pos/5 */
+ /* index = mult(i, 6554, pOverflow); */
+ index = (Word16)(((Word32) i * 6554) >> 15);
+
+ /* track = pos%5 */
+ /* tempWord =
+ L_mult(
+ index,
+ 5,
+ pOverflow); */
+ tempWord = ((Word32) index * 5) << 1;
+
+ /* tempWord =
+ L_shr(
+ tempWord,
+ 1,
+ pOverflow); */
+ tempWord >>= 1;
+
+
+ /* track =
+ sub(
+ i,
+ tempWord,
+ pOverflow); */
+ track = i - tempWord;
+
+ tempWord = track;
+
+ if (tempWord == 0)
+ {
+ track = 1;
+
+ /* index =
+ shl(
+ index,
+ 6,
+ pOverflow); */
+ index <<= 6;
+ }
+ else if (track == 1)
+ {
+ tempWord = k;
+
+ if (tempWord == 0)
+ {
+ track = 0;
+ /* index =
+ shl(
+ index,
+ 1,
+ pOverflow); */
+ index <<= 1;
+ }
+ else
+ {
+ track = 1;
+
+ /* tempWord =
+ shl(
+ index,
+ 6,
+ pOverflow); */
+ tempWord = index << 6;
+
+ /* index =
+ add(
+ tempWord,
+ 16,
+ pOverflow); */
+ index = tempWord + 16;
+ }
+ }
+ else if (track == 2)
+ {
+ track = 1;
+
+ /* tempWord =
+ shl(
+ index,
+ 6,
+ pOverflow); */
+ tempWord = index << 6;
+
+ /* index =
+ add(
+ tempWord,
+ 32,
+ pOverflow); */
+ index = tempWord + 32;
+ }
+ else if (track == 3)
+ {
+ track = 0;
+
+ /* tempWord =
+ shl(
+ index,
+ 1,
+ pOverflow); */
+ tempWord = index << 1;
+
+ /* index =
+ add(
+ tempWord,
+ 1,
+ pOverflow); */
+ index = tempWord + 1;
+ }
+ else if (track == 4)
+ {
+ track = 1;
+
+ /* tempWord =
+ shl(
+ index,
+ 6,
+ pOverflow); */
+ tempWord = index << 6;
+
+ /* index =
+ add(
+ tempWord,
+ 48,
+ pOverflow); */
+ index = tempWord + 48;
+ }
+
+ if (j > 0)
+ {
+ cod[i] = 8191;
+ _sign[k] = 32767;
+
+ tempWord =
+ shl(
+ 1,
+ track,
+ pOverflow);
+
+ rsign =
+ add(
+ rsign,
+ tempWord,
+ pOverflow);
+ }
+ else
+ {
+ cod[i] = -8192;
+ _sign[k] = (Word16) - 32768L;
+ }
+
+ indx =
+ add(
+ indx,
+ index,
+ pOverflow);
+ }
+ *sign = rsign;
+
+ p0 = h - codvec[0];
+ p1 = h - codvec[1];
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = 0;
+
+ s =
+ L_mac(
+ s,
+ *p0++,
+ _sign[0],
+ pOverflow);
+
+ s =
+ L_mac(
+ s,
+ *p1++,
+ _sign[1],
+ pOverflow);
+
+ y[i] =
+ pv_round(
+ s,
+ pOverflow);
+ }
+
+ return indx;
+}
+
+
diff --git a/media/codecs/amrnb/enc/src/c2_11pf.h b/media/codecs/amrnb/enc/src/c2_11pf.h
new file mode 100644
index 0000000..f963ae1
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c2_11pf.h
@@ -0,0 +1,121 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/c2_11pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the c2_11pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef c2_11pf_h
+#define c2_11pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 code_2i40_11bits(
+ Word16 x[], /* i : target vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ /* h[-L_subfr..-1] must be set to zero. */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp, /* i : Last quantized pitch gain */
+ Word16 code[], /* o : Innovative codebook */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 * sign, /* o : Signs of 2 pulses */
+ Flag * pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _c2_11PF_H_ */
diff --git a/media/codecs/amrnb/enc/src/c2_9pf.cpp b/media/codecs/amrnb/enc/src/c2_9pf.cpp
new file mode 100644
index 0000000..b211032
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c2_9pf.cpp
@@ -0,0 +1,1219 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/c2_9pf.c
+ Funtions: code_2i40_9bits
+ search_2i40
+ Test_search_2i40
+ build_code
+ Test_build_code
+
+ Date: 05/26/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Updated file per comments gathered from Phase 2/3 review.
+
+ Description: Added setting of Overflow flag in inlined code.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template.
+
+ Description: Replaced basic_op.h with the header files of the math functions
+ used by the file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Defined one local variable per line.
+
+ Description: Passed in pOverflow flag for EPOC compatibility.
+
+ Description: Optimized search_2i40() to reduce clock cycle usage.
+
+ Description: Removed unnecessary include files and #defines.
+
+ Description: Changed function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that search a 9 bit algebraic codebook
+ containing 2 pulses in a frame of 40 samples.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "c2_9pf.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "inv_sqrt.h"
+#include "cnst.h"
+#include "cor_h.h"
+#include "cor_h_x.h"
+#include "set_sign.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NB_PULSE 2
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ static void search_2i40(
+ Word16 subNr, /* i : subframe number */
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 rr[][L_CODE],/* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ static Word16 build_code(
+ Word16 subNr, /* i : subframe number */
+ Word16 codvec[], /* i : algebraic codebook vector */
+ Word16 dn_sign[], /* i : sign of dn[] */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 sign[], /* o : sign of 2 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ const Word16 trackTable[4*5] =
+ {
+ 0, 1, 0, 1, -1, /* subframe 1; track to code;
+ * -1 do not code this position
+ */
+ 0, -1, 1, 0, 1, /* subframe 2 */
+ 0, 1, 0, -1, 1, /* subframe 3 */
+ 0, 1, -1, 0, 1
+ };/* subframe 4 */
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 startPos[];
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: code_2i40_9bits
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ subNr = subframe number (Word16)
+ x = target buffer (Word16)
+ h = buffer containing the impulse response of the
+ weighted synthesis filter; h[-L_subfr .. -1] must be
+ set to zero (Word16)
+ T0 = pitch lag (Word16)
+ pitch_sharp = last quantized pitch gain (Word16)
+ code = buffer containing the innovative codebook (Word16)
+ y = buffer containing the filtered fixed codebook excitation (Word16)
+ sign = pointer to the signs of 2 pulses (Word16)
+
+ Outputs:
+ code buffer contains the new innovation vector gains
+
+ Returns:
+ index = code index (Word16)
+
+ Global Variables Used:
+ Overflow = overflow flag (Flag)
+
+ Local Variables Needed:
+ None
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function searches a 9 bit algebraic codebook containing 2 pulses in a
+ frame of 40 samples.
+
+ The code length is 40, containing 2 nonzero pulses: i0...i1. All pulses can
+ have two possible amplitudes: +1 or -1. Pulse i0 can have 8 possible positions,
+ pulse i1 can have 8 positions. Also coded is which track pair should be used,
+ i.e. first or second pair. Where each pair contains 2 tracks.
+
+ First subframe:
+ first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
+ i1 : 2, 7, 12, 17, 22, 27, 32, 37.
+ second i0 : 1, 6, 11, 16, 21, 26, 31, 36.
+ i1 : 3, 8, 13, 18, 23, 28, 33, 38.
+
+ Second subframe:
+ first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
+ i1 : 3, 8, 13, 18, 23, 28, 33, 38.
+ second i0 : 2, 7, 12, 17, 22, 27, 32, 37.
+ i1 : 4, 9, 14, 19, 24, 29, 34, 39.
+
+ Third subframe:
+ first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
+ i1 : 2, 7, 12, 17, 22, 27, 32, 37.
+ second i0 : 1, 6, 11, 16, 21, 26, 31, 36.
+ i1 : 4, 9, 14, 19, 24, 29, 34, 39.
+
+ Fourth subframe:
+ first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
+ i1 : 3, 8, 13, 18, 23, 28, 33, 38.
+ second i0 : 1, 6, 11, 16, 21, 26, 31, 36.
+ i1 : 4, 9, 14, 19, 24, 29, 34, 39.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 code_2i40_9bits(
+ Word16 subNr, // i : subframe number
+ Word16 x[], // i : target vector
+ Word16 h[], // i : impulse response of weighted synthesis filter
+ // h[-L_subfr..-1] must be set to zero.
+ Word16 T0, // i : Pitch lag
+ Word16 pitch_sharp, // i : Last quantized pitch gain
+ Word16 code[], // o : Innovative codebook
+ Word16 y[], // o : filtered fixed codebook excitation
+ Word16 * sign // o : Signs of 2 pulses
+ )
+ {
+ Word16 codvec[NB_PULSE];
+ Word16 dn[L_CODE], dn2[L_CODE], dn_sign[L_CODE];
+ Word16 rr[L_CODE][L_CODE];
+ Word16 i, index, sharp;
+
+ sharp = shl(pitch_sharp, 1);
+ if (sub(T0, L_CODE) < 0)
+ for (i = T0; i < L_CODE; i++) {
+ h[i] = add(h[i], mult(h[i - T0], sharp));
+ }
+ cor_h_x(h, x, dn, 1);
+ set_sign(dn, dn_sign, dn2, 8); // dn2[] not used in this codebook search
+ cor_h(h, dn_sign, rr);
+ search_2i40(subNr, dn, rr, codvec);
+ index = build_code(subNr, codvec, dn_sign, code, h, y, sign);
+
+ *-----------------------------------------------------------------*
+ * Compute innovation vector gain. *
+ * Include fixed-gain pitch contribution into code[]. *
+ *-----------------------------------------------------------------*
+
+ if (sub(T0, L_CODE) < 0)
+ for (i = T0; i < L_CODE; i++) {
+ code[i] = add(code[i], mult(code[i - T0], sharp));
+ }
+ return index;
+ }
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+
+ Word16 code_2i40_9bits(
+ Word16 subNr, /* i : subframe number */
+ Word16 x[], /* i : target vector */
+ Word16 h[], /* i : impulse response of weighted synthesis */
+ /* filter h[-L_subfr..-1] must be set to 0. */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp, /* i : Last quantized pitch gain */
+ Word16 code[], /* o : Innovative codebook */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 * sign, /* o : Signs of 2 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ Word16 codvec[NB_PULSE];
+ Word16 dn[L_CODE];
+ Word16 dn2[L_CODE];
+ Word16 dn_sign[L_CODE];
+ Word16 rr[L_CODE][L_CODE];
+
+ Word16 i;
+
+ Word16 index;
+ Word16 sharp;
+ Word16 temp;
+ Word32 L_temp;
+
+ L_temp = ((Word32) pitch_sharp) << 1;
+
+ /* Check for overflow condition */
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *(pOverflow) = 1;
+ sharp = (pitch_sharp > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ sharp = (Word16) L_temp;
+ }
+
+ if (T0 < L_CODE)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ temp =
+ mult(
+ *(h + i - T0),
+ sharp,
+ pOverflow);
+
+ *(h + i) =
+ add(
+ *(h + i),
+ temp,
+ pOverflow);
+ }
+ }
+
+ cor_h_x(
+ h,
+ x,
+ dn,
+ 1,
+ pOverflow);
+
+ /* dn2[] not used in this codebook search */
+
+ set_sign(
+ dn,
+ dn_sign,
+ dn2,
+ 8);
+
+ cor_h(
+ h,
+ dn_sign,
+ rr,
+ pOverflow);
+
+ search_2i40(
+ subNr,
+ dn,
+ rr,
+ codvec,
+ pOverflow);
+
+ index =
+ build_code(
+ subNr,
+ codvec,
+ dn_sign,
+ code,
+ h,
+ y,
+ sign,
+ pOverflow);
+
+ /*-----------------------------------------------------------------*
+ * Compute innovation vector gain. *
+ * Include fixed-gain pitch contribution into code[]. *
+ *-----------------------------------------------------------------*/
+
+ if (T0 < L_CODE)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ temp =
+ mult(
+ *(code + i - T0),
+ sharp,
+ pOverflow);
+
+ *(code + i) =
+ add(
+ *(code + i),
+ temp,
+ pOverflow);
+ }
+ }
+
+ return(index);
+ }
+
+ /****************************************************************************/
+
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: search_2i40
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ subNr = subframe number (Word16)
+ dn = vector containing the correlation between target and the impulse
+ response of the weighted synthesis filter (Word16)
+ rr = autocorrelation matrix (Word16)
+ codvec = algebraic codebook vector (Word16)
+
+ Outputs:
+ codvec contains the newly calculated codevectors
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ startPos = table containing the start positions used by fixed codebook
+ routines (const Word16)
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function searches the best codevector and determines the positions of
+ the 2 pulses in the 40-sample frame.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ static void search_2i40(
+ Word16 subNr, // i : subframe number
+ Word16 dn[], // i : correlation between target and h[]
+ Word16 rr[][L_CODE], // i : matrix of autocorrelation
+ Word16 codvec[] // o : algebraic codebook vector
+ )
+ {
+ Word16 i0, i1;
+ Word16 ix = 0; // initialization only needed to keep gcc silent
+ Word16 track1, ipos[NB_PULSE];
+ Word16 psk, ps0, ps1, sq, sq1;
+ Word16 alpk, alp, alp_16;
+ Word32 s, alp0, alp1;
+ Word16 i;
+
+ psk = -1;
+ alpk = 1;
+ for (i = 0; i < NB_PULSE; i++)
+ {
+ codvec[i] = i;
+ }
+
+ for (track1 = 0; track1 < 2; track1++) {
+ // fix starting position
+
+ ipos[0] = startPos[subNr*2+8*track1];
+ ipos[1] = startPos[subNr*2+1+8*track1];
+
+
+ *----------------------------------------------------------------*
+ * i0 loop: try 8 positions. *
+ *----------------------------------------------------------------*
+
+ for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP) {
+
+ ps0 = dn[i0];
+ alp0 = L_mult(rr[i0][i0], _1_4);
+
+ *----------------------------------------------------------------*
+ * i1 loop: 8 positions. *
+ *----------------------------------------------------------------*
+
+ sq = -1;
+ alp = 1;
+ ix = ipos[1];
+
+ *-------------------------------------------------------------------*
+ * These index have low complexity address computation because *
+ * they are, in fact, pointers with fixed increment. For example, *
+ * "rr[i0][i2]" is a pointer initialized to "&rr[i0][ipos[2]]" *
+ * and incremented by "STEP". *
+ *-------------------------------------------------------------------*
+
+ for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP) {
+ ps1 = add(ps0, dn[i1]); // idx increment = STEP
+
+ // alp1 = alp0 + rr[i0][i1] + 1/2*rr[i1][i1];
+
+ alp1 = L_mac(alp0, rr[i1][i1], _1_4); // idx incr = STEP
+ alp1 = L_mac(alp1, rr[i0][i1], _1_2); // idx incr = STEP
+
+ sq1 = mult(ps1, ps1);
+
+ alp_16 = pv_round(alp1);
+
+ s = L_msu(L_mult(alp, sq1), sq, alp_16);
+
+ if (s > 0) {
+ sq = sq1;
+ alp = alp_16;
+ ix = i1;
+ }
+ }
+
+ *----------------------------------------------------------------*
+ * memorise codevector if this one is better than the last one. *
+ *----------------------------------------------------------------*
+
+ s = L_msu(L_mult(alpk, sq), psk, alp);
+
+ if (s > 0) {
+ psk = sq;
+ alpk = alp;
+ codvec[0] = i0;
+ codvec[1] = ix;
+ }
+ }
+ }
+
+ return;
+ }
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+
+ static void search_2i40(
+ Word16 subNr, /* i : subframe number */
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ Word16 i0;
+ Word16 i1;
+ Word16 ix = 0; /* initialization only needed to keep gcc silent */
+ Word16 track1;
+ Word16 ipos[NB_PULSE];
+ Word16 psk;
+ Word16 ps0;
+ Word16 ps1;
+ Word16 sq;
+ Word16 sq1;
+ Word16 alpk;
+ Word16 alp;
+ Word16 alp_16;
+ Word32 s;
+ Word32 alp0;
+ Word32 alp1;
+ Word16 i;
+ Word32 L_temp;
+ Word16 *p_codvec = &codvec[0];
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ psk = -1;
+ alpk = 1;
+
+ /* Unrolled the following FOR loop to save MIPS */
+ /* for (i = 0; i < NB_PULSE; i++) */
+ /* { */
+ /* *(codvec + i) = i; */
+ /* } */
+
+ *(p_codvec++) = 0;
+ *(p_codvec) = 1;
+
+ for (track1 = 0; track1 < 2; track1++)
+ {
+ /* fix starting position */
+
+ i = (subNr << 1) + (track1 << 3);
+ *ipos = *(startPos + i);
+ *(ipos + 1) = *(startPos + i + 1);
+
+
+ /*----------------------------------------------------------*
+ * i0 loop: try 8 positions. *
+ *----------------------------------------------------------*/
+
+ for (i0 = *ipos; i0 < L_CODE; i0 += STEP)
+ {
+ ps0 = *(dn + i0);
+
+ /* Left shift by 1 converts integer product to */
+ /* fractional product. */
+ alp0 = (Word32) rr[i0][i0] << 14;
+
+ /*--------------------------------------------------*
+ * i1 loop: 8 positions. *
+ *--------------------------------------------------*/
+
+ sq = -1;
+ alp = 1;
+ ix = *(ipos + 1);
+
+ /*--------------------------------------------------*
+ * These index have low complexity address *
+ * computation because they are, in fact, pointers *
+ * with fixed increment. For example, "rr[i0][i2]" *
+ * is a pointer initialized to "&rr[i0][ipos[2]]" *
+ * and incremented by "STEP". *
+ *---------------------------------------------------*/
+
+ for (i1 = *(ipos + 1); i1 < L_CODE; i1 += STEP)
+ {
+ /* idx increment = STEP */
+ /* ps1 = add(ps0, *(dn + i1), pOverflow); */
+ ps1 = ps0 + dn[i1];
+
+ /* alp1 = alp0+rr[i0][i1]+1/2*rr[i1][i1]; */
+
+ /* idx incr = STEP */
+ /* Extra left shift by 1 converts integer */
+ /* product to fractional product */
+ /* alp1 = L_add(alp0, s, pOverflow); */
+ alp1 = alp0 + ((Word32) rr[i1][i1] << 14);
+
+ /* idx incr = STEP */
+ /* Extra left shift by 1 converts integer */
+ /* product to fractional product */
+ /* alp1 = L_add(alp1, s, pOverflow); */
+ alp1 += (Word32) rr[i0][i1] << 15;
+
+ /* sq1 = mult(ps1, ps1, pOverflow); */
+ sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);
+
+ /* alp_16 = pv_round(alp1, pOverflow); */
+ alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);
+
+ /* L_temp = L_mult(alp, sq1, pOverflow); */
+ L_temp = ((Word32) alp * sq1) << 1;
+
+ /* s = L_msu(L_temp, sq, alp_16, pOverflow); */
+ s = L_temp - (((Word32) sq * alp_16) << 1);
+
+ if (s > 0)
+ {
+ sq = sq1;
+ alp = alp_16;
+ ix = i1;
+ }
+ }
+
+ /* memorize codevector if this one is better than the last one. */
+
+ /* L_temp = L_mult(alpk, sq, pOverflow); */
+ L_temp = ((Word32) alpk * sq) << 1;
+
+ /* s = L_msu(L_temp, psk, alp, pOverflow); */
+ s = L_temp - (((Word32) psk * alp) << 1);
+
+ if (s > 0)
+ {
+ psk = sq;
+ alpk = alp;
+ p_codvec = &codvec[0];
+ *(p_codvec++) = i0;
+ *(p_codvec) = ix;
+ }
+ }
+ }
+
+ return;
+ }
+
+ /****************************************************************************/
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Test_search_2i40
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ subNr = subframe number (Word16)
+ dn = vector containing the correlation between target and the impulse
+ response of the weighted synthesis filter (Word16)
+ rr = autocorrelation matrix (Word16)
+ codvec = algebraic codebook vector (Word16)
+
+ Outputs:
+ codvec contains the newly calculated codevectors
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ startPos = table containing the start positions used by fixed codebook
+ routines (const Word16)
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function provides external access to the local function search_2i40.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ CALL search_2i40 ( subNr = subNr
+ dn = dn
+ rr = rr
+ codvec = codvec )
+ MODIFYING(nothing)
+ RETURNING(nothing)
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+
+ void Test_search_2i40(
+ Word16 subNr, /* i : subframe number */
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ /*----------------------------------------------------------------------------
+ CALL search_2i40 ( subNr = subNr
+ dn = dn
+ rr = rr
+ codvec = codvec )
+ MODIFYING(nothing)
+ RETURNING(nothing)
+ ----------------------------------------------------------------------------*/
+ search_2i40(
+ subNr,
+ dn,
+ rr,
+ codvec,
+ pOverflow);
+
+ return;
+ }
+
+ /****************************************************************************/
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: build_code
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ subNr = subframe number (Word16)
+ codvec = vector containing the position of pulses (Word16)
+ dn_sign = vector containing the sign of pulses (Word16)
+ cod = innovative code vector (Word16)
+ h = vector containing the impulse response of the weighted
+ synthesis filter (Word16)
+ y = vector containing the filtered innovative code (Word16)
+ sign = vector containing the sign of 2 pulses (Word16)
+
+ Outputs:
+ cod vector contains the new innovative code
+ y vector contains the new filtered innovative code
+ sign vector contains the sign of 2 pulses
+
+ Returns:
+ indx = codebook index (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ trackTable = table used for tracking codewords (Word16)
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function builds the codeword, the filtered codeword and index of the
+ codevector, based on the signs and positions of 2 pulses.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ static Word16 build_code(
+ Word16 subNr, // i : subframe number
+ Word16 codvec[], // i : position of pulses
+ Word16 dn_sign[], // i : sign of pulses
+ Word16 cod[], // o : innovative code vector
+ Word16 h[], // i : impulse response of weighted synthesis filter
+ Word16 y[], // o : filtered innovative code
+ Word16 sign[] // o : sign of 2 pulses
+ )
+ {
+ Word16 i, j, k, track, first, index, _sign[NB_PULSE], indx, rsign;
+ Word16 *p0, *p1, *pt;
+ Word32 s;
+ static Word16 trackTable[4*5] = {
+ 0, 1, 0, 1, -1, // subframe 1; track to code; -1 do not code this position
+ 0, -1, 1, 0, 1, // subframe 2
+ 0, 1, 0, -1, 1, // subframe 3
+ 0, 1, -1, 0, 1};// subframe 4
+
+ pt = &trackTable[add(subNr, shl(subNr, 2))];
+
+ for (i = 0; i < L_CODE; i++) {
+ cod[i] = 0;
+ }
+
+ indx = 0;
+ rsign = 0;
+ for (k = 0; k < NB_PULSE; k++) {
+ i = codvec[k]; // read pulse position
+ j = dn_sign[i]; // read sign
+
+ index = mult(i, 6554); // index = pos/5
+ // track = pos%5
+ track = sub(i, extract_l(L_shr(L_mult(index, 5), 1)));
+
+ first = pt[track];
+
+ if (first == 0) {
+ if (k == 0) {
+ track = 0;
+ } else {
+ track = 1;
+ index = shl(index, 3);
+ }
+ } else {
+ if (k == 0) {
+ track = 0;
+ index = add(index, 64); // table bit is MSB
+ } else {
+ track = 1;
+ index = shl(index, 3);
+ }
+ }
+
+ if (j > 0) {
+ cod[i] = 8191;
+ _sign[k] = 32767;
+ rsign = add(rsign, shl(1, track));
+ } else {
+ cod[i] = -8192;
+ _sign[k] = (Word16) - 32768L;
+ }
+
+ indx = add(indx, index);
+ }
+ *sign = rsign;
+
+ p0 = h - codvec[0];
+ p1 = h - codvec[1];
+
+ for (i = 0; i < L_CODE; i++) {
+ s = 0;
+ s = L_mac(s, *p0++, _sign[0]);
+ s = L_mac(s, *p1++, _sign[1]);
+ y[i] = pv_round(s);
+ }
+
+ return indx;
+ }
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+
+ static Word16 build_code(
+ Word16 subNr, /* i : subframe number */
+ Word16 codvec[], /* i : position of pulses */
+ Word16 dn_sign[], /* i : sign of pulses */
+ Word16 cod[], /* o : innovative code vector */
+ Word16 h[], /* i : impulse response of weighted synthesis */
+ /* filter */
+ Word16 y[], /* o : filtered innovative code */
+ Word16 sign[], /* o : sign of 2 pulses */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ Word16 i;
+ Word16 j;
+ Word16 k;
+ Word16 track;
+ Word16 first;
+ Word16 index;
+ Word16 rsign;
+ Word16 indx;
+ Word16 _sign[NB_PULSE];
+ Word16 *p0;
+ Word16 *p1;
+
+ const Word16 *pt;
+
+ Word32 s;
+
+ pt = trackTable + subNr + (subNr << 2);
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ *(cod + i) = 0;
+ }
+
+ indx = 0;
+ rsign = 0;
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ i = *(codvec + k); /* read pulse position */
+ j = *(dn_sign + i); /* read sign */
+
+ s = ((Word32)(i * 6554)) >> 15;
+ index = (Word16) s; /* index = pos/5 */
+
+ track = i - (5 * index); /* track = pos%5 */
+
+ first = *(pt + track);
+
+
+ if (k == 0)
+ {
+ track = 0;
+
+ if (first != 0)
+ {
+ index += 64; /* table bit is MSB */
+ }
+ }
+ else
+ {
+ track = 1;
+ index <<= 3;
+ }
+
+ if (j > 0)
+ {
+ *(cod + i) = 8191;
+ *(_sign + k) = 32767;
+ rsign += (1 << track);
+ }
+ else
+ {
+ *(cod + i) = ~(8192) + 1;
+ *(_sign + k) = (Word16)(~(32768) + 1);
+ }
+
+ indx += index;
+ }
+
+ *sign = rsign;
+
+ p0 = h - *codvec;
+ p1 = h - *(codvec + 1);
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = 0;
+ s =
+ L_mult(
+ *p0++,
+ *_sign,
+ pOverflow);
+
+ s =
+ L_mac(
+ s,
+ *p1++,
+ *(_sign + 1),
+ pOverflow);
+
+ *(y + i) =
+ pv_round(
+ s,
+ pOverflow);
+ }
+
+ return(indx);
+ }
+
+ /****************************************************************************/
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: Test_build_code
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ subNr = subframe number (Word16)
+ codvec = vector containing the position of pulses (Word16)
+ dn_sign = vector containing the sign of pulses (Word16)
+ cod = innovative code vector (Word16)
+ h = vector containing the impulse response of the weighted
+ synthesis filter (Word16)
+ y = vector containing the filtered innovative code (Word16)
+ sign = vector containing the sign of 2 pulses (Word16)
+
+ Outputs:
+ cod vector contains the new innovative code
+ y vector contains the new filtered innovative code
+ sign vector contains the sign of 2 pulses
+
+ Returns:
+ indx = codebook index (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ trackTable = table used for tracking codewords (Word16)
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function provides external access to the local function build_code.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ CALL build_code ( subNr = subNr
+ codvec = codvec
+ dn_sign = dn_sign
+ cod = cod
+ h = h
+ y = y
+ sign = sign )
+ MODIFYING(nothing)
+ RETURNING(indx)
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+
+ Word16 Test_build_code(
+ Word16 subNr, /* i : subframe number */
+ Word16 codvec[], /* i : position of pulses */
+ Word16 dn_sign[], /* i : sign of pulses */
+ Word16 cod[], /* o : innovative code vector */
+ Word16 h[], /* i : impulse response of weighted synthesis */
+ /* filter */
+ Word16 y[], /* o : filtered innovative code */
+ Word16 sign[], /* o : sign of 2 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ Word16 test_index;
+
+ /*----------------------------------------------------------------------------
+ CALL build_code ( subNr = subNr
+ codvec = codvec
+ dn_sign = dn_sign
+ cod = cod
+ h = h
+ y = y
+ sign = sign )
+ MODIFYING(nothing)
+ RETURNING(indx)
+ ----------------------------------------------------------------------------*/
+ test_index =
+ build_code(
+ subNr,
+ codvec,
+ dn_sign,
+ cod,
+ h,
+ y,
+ sign,
+ pOverflow);
+
+ return(test_index);
+ }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/media/codecs/amrnb/enc/src/c2_9pf.h b/media/codecs/amrnb/enc/src/c2_9pf.h
new file mode 100644
index 0000000..203e1d9
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c2_9pf.h
@@ -0,0 +1,125 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/c2_9pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the c2_9pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef c2_9pf_h
+#define c2_9pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 code_2i40_9bits(
+ Word16 subNr, /* i : subframe number */
+ Word16 x[], /* i : target vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ /* h[-L_subfr..-1] must be set to zero. */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp, /* i : Last quantized pitch gain */
+ Word16 code[], /* o : Innovative codebook */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 * sign, /* o : Signs of 2 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _c2_9PF_H_ */
+
+
+
diff --git a/media/codecs/amrnb/enc/src/c3_14pf.cpp b/media/codecs/amrnb/enc/src/c3_14pf.cpp
new file mode 100644
index 0000000..58ab2fa
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c3_14pf.cpp
@@ -0,0 +1,817 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/c3_14pf.c
+ Functions:
+
+ Date: 05/26/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to pass overflow flag through to basic math function.
+ The flag is passed back to the calling function by pointer reference.
+
+ Description: Optimized file to reduce clock cycle usage. Updated copyright
+ year. Removed unneccesary include files and added only the
+ include files for the math functions used. Removed unused
+ #defines.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "c3_14pf.h"
+#include "typedef.h"
+#include "inv_sqrt.h"
+#include "cnst.h"
+#include "cor_h.h"
+#include "set_sign.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define NB_PULSE 3
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+static void search_3i40(
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 dn2[], /* i : maximum of corr. in each track. */
+ Word16 rr[][L_CODE],/* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+);
+
+static Word16 build_code(
+ Word16 codvec[], /* i : algebraic codebook vector */
+ Word16 dn_sign[], /* i : sign of dn[] */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 sign[], /* o : sign of 3 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+);
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: code_3i40_14bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x[] Array of type Word16 -- target vector
+ h[] Array of type Word16 -- impulse response of weighted synthesis filter
+ h[-L_subfr..-1] must be set to zero.
+
+ T0 Array of type Word16 -- Pitch lag
+ pitch_sharp, Array of type Word16 -- Last quantized pitch gain
+
+ Outputs:
+ code[] Array of type Word16 -- Innovative codebook
+ y[] Array of type Word16 -- filtered fixed codebook excitation
+ * sign Pointer of type Word16 -- Pointer to the signs of 3 pulses
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ index
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Searches a 14 bit algebraic codebook containing 3 pulses
+ in a frame of 40 samples.
+
+ DESCRIPTION:
+ The code length is 40, containing 3 nonzero pulses: i0...i2.
+ All pulses can have two possible amplitudes: +1 or -1.
+ Pulse i0 can have 8 possible positions, pulses i1 and i2 can have
+ 2x8=16 positions.
+
+ i0 : 0, 5, 10, 15, 20, 25, 30, 35.
+ i1 : 1, 6, 11, 16, 21, 26, 31, 36.
+ 3, 8, 13, 18, 23, 28, 33, 38.
+ i2 : 2, 7, 12, 17, 22, 27, 32, 37.
+ 4, 9, 14, 19, 24, 29, 34, 39.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c3_14pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 code_3i40_14bits(
+ Word16 x[], /* i : target vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ /* h[-L_subfr..-1] must be set to zero. */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp, /* i : Last quantized pitch gain */
+ Word16 code[], /* o : Innovative codebook */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 * sign, /* o : Signs of 3 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 codvec[NB_PULSE];
+ Word16 dn[L_CODE];
+ Word16 dn2[L_CODE];
+ Word16 dn_sign[L_CODE];
+ Word16 rr[L_CODE][L_CODE];
+ Word16 i;
+ Word16 index;
+ Word16 sharp;
+ Word16 tempWord;
+
+ /* sharp = shl(pitch_sharp, 1, pOverflow); */
+ sharp = pitch_sharp << 1;
+
+ if (T0 < L_CODE)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ tempWord =
+ mult(
+ h[i - T0],
+ sharp,
+ pOverflow);
+
+ h[i] =
+ add(
+ h[i],
+ tempWord,
+ pOverflow);
+ }
+ }
+
+ cor_h_x(
+ h,
+ x,
+ dn,
+ 1,
+ pOverflow);
+
+ set_sign(
+ dn,
+ dn_sign,
+ dn2,
+ 6);
+
+ cor_h(
+ h,
+ dn_sign,
+ rr,
+ pOverflow);
+
+ search_3i40(
+ dn,
+ dn2,
+ rr,
+ codvec,
+ pOverflow);
+
+ /* function result */
+ index =
+ build_code(
+ codvec,
+ dn_sign,
+ code,
+ h,
+ y,
+ sign,
+ pOverflow);
+
+ /*-----------------------------------------------------------------*
+ * Compute innovation vector gain. *
+ * Include fixed-gain pitch contribution into code[]. *
+ *-----------------------------------------------------------------*/
+
+ if (T0 < L_CODE)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ tempWord =
+ mult(
+ code[i - T0],
+ sharp,
+ pOverflow);
+
+ code[i] =
+ add(
+ code[i],
+ tempWord,
+ pOverflow);
+ }
+ }
+ return index;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: search_3i40
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ dn[] Array of type Word16 -- correlation between target and h[]
+ dn2[] Array of type Word16 -- maximum of corr. in each track.
+ rr[][L_CODE] Double Array of type Word16 -- autocorrelation matrix
+
+ Outputs:
+ codvec[] Array of type Word16 -- algebraic codebook vector
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Search the best codevector; determine positions of the 3 pulses
+ in the 40-sample frame.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c3_14pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+static void search_3i40(
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 dn2[], /* i : maximum of corr. in each track. */
+ Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i0;
+ Word16 i1;
+ Word16 i2;
+
+ Word16 ix = 0; /* initialization only needed to keep gcc silent */
+ Word16 ps = 0; /* initialization only needed to keep gcc silent */
+
+ Word16 i;
+ Word16 pos;
+ Word16 track1;
+ Word16 track2;
+ Word16 ipos[NB_PULSE];
+
+ Word16 psk;
+ Word16 ps0;
+ Word16 ps1;
+ Word16 sq;
+ Word16 sq1;
+ Word16 alpk;
+ Word16 alp;
+ Word16 alp_16;
+
+ Word16 *p_codvec = &codvec[0];
+
+ Word32 s;
+ Word32 alp0;
+ Word32 alp1;
+
+ psk = -1;
+ alpk = 1;
+
+ for (i = 0; i < NB_PULSE; i++)
+ {
+ *(p_codvec++) = i;
+ }
+
+ for (track1 = 1; track1 < 4; track1 += 2)
+ {
+ for (track2 = 2; track2 < 5; track2 += 2)
+ {
+ /* fix starting position */
+
+ ipos[0] = 0;
+ ipos[1] = track1;
+ ipos[2] = track2;
+
+ /*------------------------------------------------------------------*
+ * main loop: try 3 tracks. *
+ *------------------------------------------------------------------*/
+
+ for (i = 0; i < NB_PULSE; i++)
+ {
+ /*----------------------------------------------------------------*
+ * i0 loop: try 8 positions. *
+ *----------------------------------------------------------------*/
+
+ /* account for ptr. init. (rr[io]) */
+ for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP)
+ {
+ if (dn2[i0] >= 0)
+ {
+ ps0 = dn[i0];
+
+ /* alp0 = L_mult(rr[i0][i0],_1_4, pOverflow); */
+ alp0 = (Word32) rr[i0][i0] << 14;
+
+ /*----------------------------------------------------------------*
+ * i1 loop: 8 positions. *
+ *----------------------------------------------------------------*/
+
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ix = ipos[1];
+
+ /* initialize 4 index for next loop. */
+ /*-------------------------------------------------------------------*
+ * These index have low complexity address computation because *
+ * they are, in fact, pointers with fixed increment. For example, *
+ * "rr[i0][i2]" is a pointer initialized to "&rr[i0][ipos[2]]" *
+ * and incremented by "STEP". *
+ *-------------------------------------------------------------------*/
+
+ for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP)
+ {
+ /* idx increment = STEP */
+ /* ps1 = add(ps0, dn[i1], pOverflow); */
+ ps1 = ps0 + dn[i1];
+
+ /* alp1 = alp0 + rr[i0][i1] + 1/2*rr[i1][i1]; */
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp0, rr[i1][i1], _1_4, pOverflow); */
+ alp1 = alp0 + ((Word32) rr[i1][i1] << 14);
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp1, rr[i0][i1], _1_2, pOverflow); */
+ alp1 += (Word32) rr[i0][i1] << 15;
+
+ /* sq1 = mult(ps1, ps1, pOverflow); */
+ sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);
+
+ /* alp_16 = pv_round(alp1, pOverflow); */
+ alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);
+
+ /* s = L_mult(alp, sq1, pOverflow); */
+ s = ((Word32) alp * sq1) << 1;
+
+ /* s = L_msu(s, sq, alp_16, pOverflow); */
+ s -= (((Word32) sq * alp_16) << 1);
+
+ if (s > 0)
+ {
+ sq = sq1;
+ ps = ps1;
+ alp = alp_16;
+ ix = i1;
+ }
+ }
+ i1 = ix;
+
+ /*----------------------------------------------------------------*
+ * i2 loop: 8 positions. *
+ *----------------------------------------------------------------*/
+
+ ps0 = ps;
+
+ /* alp0 = L_mult(alp, _1_4, pOverflow); */
+ alp0 = (Word32) alp << 14;
+
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ix = ipos[2];
+
+ /* initialize 4 index for next loop (see i1 loop) */
+
+ for (i2 = ipos[2]; i2 < L_CODE; i2 += STEP)
+ {
+ /* index increment = STEP */
+ /* ps1 = add(ps0, dn[i2], pOverflow); */
+ ps1 = ps0 + dn[i2];
+
+ /* alp1 = alp0 + rr[i0][i2] + rr[i1][i2] + 1/2*rr[i2][i2]; */
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp0, rr[i2][i2], _1_16, pOverflow); */
+ alp1 = alp0 + ((Word32) rr[i2][i2] << 12);
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp1, rr[i1][i2], _1_8, pOverflow); */
+ alp1 += (Word32) rr[i1][i2] << 13;
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp1,rr[i0][i2], _1_8, pOverflow); */
+ alp1 += (Word32) rr[i0][i2] << 13;
+
+ /* sq1 = mult(ps1, ps1, pOverflow); */
+ sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);
+
+ /* alp_16 = pv_round(alp1, pOverflow); */
+ alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);
+
+ /* s = L_mult(alp, sq1, pOverflow); */
+ s = ((Word32) alp * sq1) << 1;
+
+ /* s = L_msu(s, sq, alp_16, pOverflow); */
+ s -= (((Word32) sq * alp_16) << 1);
+
+ if (s > 0)
+ {
+ sq = sq1;
+ ps = ps1;
+ alp = alp_16;
+ ix = i2;
+ }
+ }
+ i2 = ix;
+
+ /* memorize codevector if this one
+ * is better than the last one.
+ */
+
+ s = L_mult(alpk, sq, pOverflow);
+ //s = ((Word32) alpk * sq) << 1;
+
+ s = L_msu(s, psk, alp, pOverflow);
+ //s -= (((Word32) psk * alp) << 1);
+
+ if (s > 0)
+ {
+ psk = sq;
+ alpk = alp;
+ p_codvec = &codvec[0];
+
+ *(p_codvec++) = i0;
+ *(p_codvec++) = i1;
+ *(p_codvec) = i2;
+ }
+ }
+ }
+ /*----------------------------------------------------------------*
+ * Cyclic permutation of i0, i1 and i2. *
+ *----------------------------------------------------------------*/
+
+ pos = ipos[2];
+ ipos[2] = ipos[1];
+ ipos[1] = ipos[0];
+ ipos[0] = pos;
+ }
+ }
+ }
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: build_code()
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ codvec[] Array of type Word16 -- position of pulses
+ dn_sign[] Array of type Word16 -- sign of pulses
+ h[] Array of type Word16 -- impulse response of
+ weighted synthesis filter
+
+ Outputs:
+ cod[] Array of type Word16 -- innovative code vector
+ y[] Array of type Word16 -- filtered innovative code
+ sign[] Array of type Word16 -- sign of 3 pulses
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ indx
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Builds the codeword, the filtered codeword and index of the
+ codevector, based on the signs and positions of 3 pulses.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c3_14pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16
+build_code(
+ Word16 codvec[], /* i : position of pulses */
+ Word16 dn_sign[], /* i : sign of pulses */
+ Word16 cod[], /* o : innovative code vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ Word16 y[], /* o : filtered innovative code */
+ Word16 sign[], /* o : sign of 3 pulses */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+ Word16 track;
+ Word16 index;
+ Word16 _sign[NB_PULSE];
+ Word16 indx;
+ Word16 rsign;
+
+ Word16 *p0;
+ Word16 *p1;
+ Word16 *p2;
+
+ Word32 s;
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ cod[i] = 0;
+ }
+
+ indx = 0;
+ rsign = 0;
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ i = codvec[k]; /* read pulse position */
+ j = dn_sign[i]; /* read sign */
+
+ /* index = pos/5 */
+ /* index = mult(i, 6554, pOverflow); */
+ index = (Word16)(((Word32) i * 6554) >> 15);
+
+ /* track = pos%5 */
+ /* s = L_mult(index, 5, pOverflow); */
+ s = ((Word32) index * 5) << 1;
+
+ /* s = L_shr(s, 1, pOverflow); */
+ s >>= 1;
+
+ /* track = sub(i, (Word16) s, pOverflow); */
+ track = i - (Word16) s;
+
+ if (track == 1)
+ {
+ /* index = shl(index, 4, pOverflow); */
+ index <<= 4;
+ }
+ else if (track == 2)
+ {
+ track = 2;
+
+ /* index = shl(index, 8, pOverflow); */
+ index <<= 8;
+ }
+ else if (track == 3)
+ {
+ track = 1;
+
+ /* index = shl(index, 4, pOverflow); */
+ index <<= 4;
+
+ /* index = add(index, 8, pOverflow); */
+ index += 8;
+ }
+ else if (track == 4)
+ {
+ track = 2;
+
+ /* index = shl(index, 8, pOverflow); */
+ index <<= 8;
+
+ /* index = add(index, 128, pOverflow); */
+ index += 128;
+ }
+
+ if (j > 0)
+ {
+ cod[i] = 8191;
+ _sign[k] = 32767;
+
+ /* track = shl(1, track, pOverflow); */
+ track = 1 << track;
+
+ /* rsign = add(rsign, track, pOverflow); */
+ rsign += track;
+ }
+ else
+ {
+ cod[i] = -8192;
+ _sign[k] = (Word16) - 32768L;
+ }
+
+ /* indx = add(indx, index, pOverflow); */
+ indx += index;
+ }
+ *sign = rsign;
+
+ p0 = h - codvec[0];
+ p1 = h - codvec[1];
+ p2 = h - codvec[2];
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = 0;
+ s =
+ L_mac(
+ s,
+ *p0++,
+ _sign[0],
+ pOverflow);
+
+ s =
+ L_mac(
+ s,
+ *p1++,
+ _sign[1],
+ pOverflow);
+
+ s =
+ L_mac(
+ s,
+ *p2++,
+ _sign[2],
+ pOverflow);
+
+ y[i] =
+ pv_round(
+ s,
+ pOverflow);
+ }
+
+ return indx;
+}
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/c3_14pf.h b/media/codecs/amrnb/enc/src/c3_14pf.h
new file mode 100644
index 0000000..15e2f1a
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c3_14pf.h
@@ -0,0 +1,123 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/c3_14pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by c3_14pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef c3_14pf_h
+#define c3_14pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word16 code_3i40_14bits(
+ Word16 x[], /* (i) : target vector */
+ Word16 h[], /* (i) : impulse response of weighted synthesis filter */
+ /* h[-L_subfr..-1] must be set to zero. */
+ Word16 T0, /* (i) : Pitch lag */
+ Word16 pitch_sharp, /* (i) : Last quantized pitch gain */
+ Word16 code[], /* (o) : Innovative codebook */
+ Word16 y[], /* (o) : filtered fixed codebook excitation */
+ Word16 * sign, /* (o) : Signs of 3 pulses */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _c3_14PF_H_ */
+
diff --git a/media/codecs/amrnb/enc/src/c4_17pf.cpp b/media/codecs/amrnb/enc/src/c4_17pf.cpp
new file mode 100644
index 0000000..d52b43b
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c4_17pf.cpp
@@ -0,0 +1,891 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/c4_17pf.c
+ Functions:
+
+ Date: 05/26/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to pass overflow flag through to basic math function.
+ The flag is passed back to the calling function by pointer reference.
+
+ Description: Optimized functions to further reduce clock cycle usage.
+ Updated copyright year, removed unnecessary include files,
+ and removed unused #defines.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Purpose : Searches a 17 bit algebraic codebook containing 4 pulses
+ in a frame of 40 samples
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "c4_17pf.h"
+#include "typedef.h"
+#include "inv_sqrt.h"
+#include "cnst.h"
+#include "cor_h.h"
+#include "set_sign.h"
+#include "basic_op.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NB_PULSE 4
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ static void search_4i40(
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 dn2[], /* i : maximum of corr. in each track. */
+ Word16 rr[][L_CODE],/* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ static Word16 build_code(
+ Word16 codvec[], /* i : algebraic codebook vector */
+ Word16 dn_sign[], /* i : sign of dn[] */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 sign[], /* o : index of 4 pulses (position+sign+ampl)*4 */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 gray[];
+ extern const Word16 dgray[];
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: code_4i40_17bits()
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x[] Array of type Word16 -- target vector
+ h[] Array of type Word16 -- impulse response of weighted synthesis filter
+ h[-L_subfr..-1] must be set to zero.
+
+ T0 Array of type Word16 -- Pitch lag
+ pitch_sharp, Array of type Word16 -- Last quantized pitch gain
+
+ Outputs:
+ code[] Array of type Word16 -- Innovative codebook
+ y[] Array of type Word16 -- filtered fixed codebook excitation
+ * sign Pointer of type Word16 -- Pointer to the signs of 4 pulses
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ index
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Searches a 17 bit algebraic codebook containing 4 pulses
+ in a frame of 40 samples.
+
+ DESCRIPTION:
+ The code length is 40, containing 4 nonzero pulses: i0...i3.
+ All pulses can have two possible amplitudes: +1 or -1.
+ Pulse i0 to i2 can have 8 possible positions, pulse i3 can have
+ 2x8=16 positions.
+
+ i0 : 0, 5, 10, 15, 20, 25, 30, 35.
+ i1 : 1, 6, 11, 16, 21, 26, 31, 36.
+ i2 : 2, 7, 12, 17, 22, 27, 32, 37.
+ i3 : 3, 8, 13, 18, 23, 28, 33, 38.
+ 4, 9, 14, 19, 24, 29, 34, 39.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c3_14pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+
+ Word16 code_4i40_17bits(
+ Word16 x[], /* i : target vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ /* h[-L_subfr..-1] must be set to zero. */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp, /* i : Last quantized pitch gain */
+ Word16 code[], /* o : Innovative codebook */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 * sign, /* o : Signs of 4 pulses */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ Word16 codvec[NB_PULSE];
+ Word16 dn[L_CODE];
+ Word16 dn2[L_CODE];
+ Word16 dn_sign[L_CODE];
+
+ Word16 rr[L_CODE][L_CODE];
+ Word16 i;
+ Word16 index;
+ Word16 sharp;
+ Word16 tempWord;
+
+ sharp = pitch_sharp << 1;
+
+ if (T0 < L_CODE)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ tempWord =
+ mult(
+ h[i - T0],
+ sharp,
+ pOverflow);
+
+ h[i] =
+ add(
+ h[i],
+ tempWord,
+ pOverflow);
+ }
+ }
+
+ cor_h_x(
+ h,
+ x,
+ dn,
+ 1,
+ pOverflow);
+
+ set_sign(
+ dn,
+ dn_sign,
+ dn2,
+ 4);
+
+ cor_h(
+ h,
+ dn_sign,
+ rr,
+ pOverflow);
+
+ search_4i40(
+ dn,
+ dn2,
+ rr,
+ codvec,
+ pOverflow);
+
+ /* function result */
+ index =
+ build_code(
+ codvec,
+ dn_sign,
+ code,
+ h,
+ y,
+ sign,
+ pOverflow);
+
+ /*-----------------------------------------------------------------*
+ * Compute innovation vector gain. *
+ * Include fixed-gain pitch contribution into code[]. *
+ *-----------------------------------------------------------------*/
+
+ tempWord = T0 - L_CODE;
+
+ if (tempWord < 0)
+ {
+ for (i = T0; i < L_CODE; i++)
+ {
+ tempWord =
+ mult(
+ code[i - T0],
+ sharp,
+ pOverflow);
+
+ code[i] =
+ add(
+ code[i],
+ tempWord,
+ pOverflow);
+ }
+ }
+
+ return index;
+ }
+ /****************************************************************************/
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: search_4i40()
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ dn[] Array of type Word16 -- correlation between target and h[]
+ dn2[] Array of type Word16 -- maximum of corr. in each track.
+ rr[][L_CODE] Double Array of type Word16 -- autocorrelation matrix
+
+ Outputs:
+ codvec[] Array of type Word16 -- algebraic codebook vector
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Search the best codevector; determine positions of the 4 pulses
+ in the 40-sample frame.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c4_17pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+ static void search_4i40(
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 dn2[], /* i : maximum of corr. in each track. */
+ Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ Word16 i0;
+ Word16 i1;
+ Word16 i2;
+ Word16 i3;
+
+ Word16 ix = 0; /* initialization only needed to keep gcc silent */
+ Word16 ps = 0; /* initialization only needed to keep gcc silent */
+
+ Word16 i;
+ Word16 pos;
+ Word16 track;
+ Word16 ipos[NB_PULSE];
+
+ Word16 psk;
+ Word16 ps0;
+ Word16 ps1;
+ Word16 sq;
+ Word16 sq1;
+
+ Word16 alpk;
+ Word16 alp;
+ Word16 alp_16;
+ Word16 *p_codvec = &codvec[0];
+
+ Word32 s;
+ Word32 alp0;
+ Word32 alp1;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ /* Default value */
+ psk = -1;
+ alpk = 1;
+ for (i = 0; i < NB_PULSE; i++)
+ {
+ *(p_codvec++) = i;
+ }
+
+ for (track = 3; track < 5; track++)
+ {
+ /* fix starting position */
+
+ ipos[0] = 0;
+ ipos[1] = 1;
+ ipos[2] = 2;
+ ipos[3] = track;
+
+ /*------------------------------------------------------------------*
+ * main loop: try 4 tracks. *
+ *------------------------------------------------------------------*/
+
+ for (i = 0; i < NB_PULSE; i++)
+ {
+ /*----------------------------------------------------------------*
+ * i0 loop: try 4 positions (use position with max of corr.). *
+ *----------------------------------------------------------------*/
+
+ for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP)
+ {
+ if (dn2[i0] >= 0)
+ {
+ ps0 = dn[i0];
+
+ alp0 = (Word32) rr[i0][i0] << 14;
+
+ /*----------------------------------------------------------------*
+ * i1 loop: 8 positions. *
+ *----------------------------------------------------------------*/
+
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ix = ipos[1];
+
+ /* initialize 4 index for next loop. */
+ /*-------------------------------------------------------------------*
+ * These index have low complexity address computation because *
+ * they are, in fact, pointers with fixed increment. For example, *
+ * "rr[i0][i3]" is a pointer initialized to "&rr[i0][ipos[3]]" *
+ * and incremented by "STEP". *
+ *-------------------------------------------------------------------*/
+
+ for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP)
+ {
+ /* idx increment = STEP */
+ /* ps1 = add(ps0, dn[i1], pOverflow); */
+ ps1 = ps0 + dn[i1];
+
+ /* alp1 = alp0 + rr[i0][i1] + 1/2*rr[i1][i1]; */
+
+ /* alp1 = L_mac(alp0, rr[i1][i1], _1_4, pOverflow); */
+ alp1 = alp0 + ((Word32) rr[i1][i1] << 14);
+
+ /* alp1 = L_mac(alp1, rr[i0][i1], _1_2, pOverflow); */
+ alp1 += (Word32) rr[i0][i1] << 15;
+
+ /* sq1 = mult(ps1, ps1, pOverflow); */
+ sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);
+
+ /* alp_16 = pv_round(alp1, pOverflow); */
+ alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);
+
+ /* s = L_mult(alp, sq1, pOverflow); */
+ s = ((Word32) alp * sq1) << 1;
+
+ /* s = L_msu(s, sq, alp_16, pOverflow); */
+ s -= (((Word32) sq * alp_16) << 1);
+
+ if (s > 0)
+ {
+ sq = sq1;
+ ps = ps1;
+ alp = alp_16;
+ ix = i1;
+ }
+ }
+ i1 = ix;
+
+ /*----------------------------------------------------------------*
+ * i2 loop: 8 positions. *
+ *----------------------------------------------------------------*/
+
+ ps0 = ps;
+
+ /* alp0 = L_mult(alp, _1_4, pOverflow); */
+ alp0 = (Word32) alp << 14;
+
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ix = ipos[2];
+
+ /* initialize 4 index for next loop (see i1 loop) */
+
+ for (i2 = ipos[2]; i2 < L_CODE; i2 += STEP)
+ {
+ /* index increment = STEP */
+ /* ps1 = add(ps0, dn[i2], pOverflow); */
+ ps1 = ps0 + dn[i2];
+
+ /* alp1 = alp0 + rr[i0][i2] + rr[i1][i2] + 1/2*rr[i2][i2]; */
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp0, rr[i2][i2], _1_16, pOverflow); */
+ alp1 = alp0 + ((Word32) rr[i2][i2] << 12);
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp1, rr[i1][i2], _1_8, pOverflow); */
+ alp1 += (Word32) rr[i1][i2] << 13;
+
+ /* idx incr = STEP */
+ /* alp1 = L_mac(alp1,rr[i0][i2], _1_8, pOverflow); */
+ alp1 += (Word32) rr[i0][i2] << 13;
+
+ /* sq1 = mult(ps1, ps1, pOverflow); */
+ sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);
+
+ /* alp_16 = pv_round(alp1, pOverflow); */
+ alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);
+
+ /* s = L_mult(alp, sq1, pOverflow); */
+ s = ((Word32) alp * sq1) << 1;
+
+ /* s = L_msu(s, sq, alp_16, pOverflow); */
+ s -= (((Word32) sq * alp_16) << 1);
+
+ if (s > 0)
+ {
+ sq = sq1;
+ ps = ps1;
+ alp = alp_16;
+ ix = i2;
+ }
+ }
+ i2 = ix;
+
+ /*----------------------------------------------------------------*
+ * i3 loop: 8 positions. *
+ *----------------------------------------------------------------*/
+
+ ps0 = ps;
+ alp0 = L_deposit_h(alp);
+
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ix = ipos[3];
+
+ /* initialize 5 index for next loop (see i1 loop) */
+
+ for (i3 = ipos[3]; i3 < L_CODE; i3 += STEP)
+ {
+ /* ps1 = add(ps0, dn[i3], pOverflow); */
+ ps1 = ps0 + dn[i3]; /* index increment = STEP */
+
+ /* alp1 = alp0 + rr[i0][i3] + rr[i1][i3] + rr[i2][i3] + 1/2*rr[i3][i3]; */
+
+ /* alp1 = L_mac(alp0, rr[i3][i3], _1_16, pOverflow); */
+ alp1 = alp0 + ((Word32) rr[i3][i3] << 12); /* idx incr = STEP */
+
+ /* alp1 = L_mac(alp1, rr[i2][i3], _1_8, pOverflow); */
+ alp1 += (Word32) rr[i2][i3] << 13; /* idx incr = STEP */
+
+ /* alp1 = L_mac(alp1, rr[i1][i3], _1_8, pOverflow); */
+ alp1 += (Word32) rr[i1][i3] << 13; /* idx incr = STEP */
+
+ /* alp1 = L_mac(alp1, rr[i0][i3], _1_8, pOverflow); */
+ alp1 += (Word32) rr[i0][i3] << 13; /* idx incr = STEP */
+
+ /* sq1 = mult(ps1, ps1, pOverflow); */
+ sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);
+
+ /* alp_16 = pv_round(alp1, pOverflow); */
+ alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);
+
+ /* s = L_mult(alp, sq1, pOverflow); */
+ s = ((Word32) alp * sq1) << 1;
+
+ /* s = L_msu(s, sq, alp_16, pOverflow); */
+ s -= (((Word32) sq * alp_16) << 1);
+
+ if (s > 0)
+ {
+ sq = sq1;
+ ps = ps1;
+ alp = alp_16;
+ ix = i3;
+ }
+ }
+
+
+ /*----------------------------------------------------------------*
+ * memorise codevector if this one is better than the last one. *
+ *----------------------------------------------------------------*/
+
+ /* s = L_mult(alpk, sq, pOverflow); */
+ s = ((Word32) alpk * sq) << 1;
+
+ /* s = L_msu(s, psk, alp, pOverflow); */
+ s -= (((Word32) psk * alp) << 1);
+
+ if (s > 0)
+ {
+ psk = sq;
+ alpk = alp;
+ p_codvec = &codvec[0];
+
+ *(p_codvec++) = i0;
+ *(p_codvec++) = i1;
+ *(p_codvec++) = i2;
+ *(p_codvec) = ix;
+ }
+ }
+ }
+
+ /*----------------------------------------------------------------*
+ * Cyclic permutation of i0,i1,i2 and i3. *
+ *----------------------------------------------------------------*/
+
+ pos = ipos[3];
+ ipos[3] = ipos[2];
+ ipos[2] = ipos[1];
+ ipos[1] = ipos[0];
+ ipos[0] = pos;
+ }
+ }
+
+ return;
+ }
+
+
+
+
+ /****************************************************************************/
+
+ /*
+ ------------------------------------------------------------------------------
+ FUNCTION NAME: build_code()
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ codvec[] Array of type Word16 -- position of pulses
+ dn_sign[] Array of type Word16 -- sign of pulses
+ h[] Array of type Word16 -- impulse response of
+ weighted synthesis filter
+
+ Outputs:
+ cod[] Array of type Word16 -- innovative code vector
+ y[] Array of type Word16 -- filtered innovative code
+ sign[] Array of type Word16 -- index of 4 pulses (sign + position)
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ indx
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+
+ ------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Builds the codeword, the filtered codeword and index of the
+ codevector, based on the signs and positions of 4 pulses.
+
+ ------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+ ------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c4_17pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+ ------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+ ------------------------------------------------------------------------------
+ */
+
+ static Word16
+ build_code(
+ Word16 codvec[], /* i : position of pulses */
+ Word16 dn_sign[], /* i : sign of pulses */
+ Word16 cod[], /* o : innovative code vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter */
+ Word16 y[], /* o : filtered innovative code */
+ Word16 sign[], /* o : index of 4 pulses (sign+position) */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ )
+ {
+ Word16 i;
+ Word16 j;
+ Word16 k;
+ Word16 track;
+ Word16 index;
+ Word16 _sign[NB_PULSE];
+ Word16 indx;
+ Word16 rsign;
+
+ Word16 *p0;
+ Word16 *p1;
+ Word16 *p2;
+ Word16 *p3;
+ Word16 *p_cod = &cod[0];
+
+ Word32 s;
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ *(p_cod++) = 0;
+ }
+
+ indx = 0;
+ rsign = 0;
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ i = codvec[k]; /* read pulse position */
+ j = dn_sign[i]; /* read sign */
+
+ /* index = pos/5 */
+ /* index = mult(i, 6554, pOverflow); */
+ index = (Word16)(((Word32) i * 6554) >> 15);
+
+ /* track = pos%5 */
+ /* s = L_mult(index, 5, pOverflow); */
+ s = ((Word32) index * 5) << 1;
+
+ /* s = L_shr(s, 1, pOverflow); */
+ s >>= 1;
+
+ /* track = sub(i, (Word16) s, pOverflow); */
+ track = i - (Word16) s;
+
+ index = gray[index];
+
+ if (track == 1)
+ {
+ /* index = shl(index, 3, pOverflow); */
+ index <<= 3;
+ }
+ else if (track == 2)
+ {
+ /* index = shl(index, 6, pOverflow); */
+ index <<= 6;
+ }
+ else if (track == 3)
+ {
+ /* index = shl(index, 10, pOverflow); */
+ index <<= 10;
+ }
+ else if (track == 4)
+ {
+ track = 3;
+
+ /* index = shl(index, 10, pOverflow); */
+ index <<= 10;
+
+ /* index = add(index, 512, pOverflow); */
+ index += 512;
+ }
+
+ if (j > 0)
+ {
+ cod[i] = 8191;
+ _sign[k] = 32767;
+
+ /* track = shl(1, track, pOverflow); */
+ track = 1 << track;
+
+ /* rsign = add(rsign, track, pOverflow); */
+ rsign += track;
+ }
+ else
+ {
+ cod[i] = -8192;
+ _sign[k] = (Word16) - 32768L;
+ }
+
+ /* indx = add(indx, index, pOverflow); */
+ indx += index;
+ }
+ *sign = rsign;
+
+ p0 = h - codvec[0];
+ p1 = h - codvec[1];
+ p2 = h - codvec[2];
+ p3 = h - codvec[3];
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = 0;
+ s =
+ L_mac(
+ s,
+ *p0++,
+ _sign[0],
+ pOverflow);
+
+ s =
+ L_mac(
+ s,
+ *p1++,
+ _sign[1],
+ pOverflow);
+
+ s =
+ L_mac(
+ s,
+ *p2++,
+ _sign[2],
+ pOverflow);
+
+ s =
+ L_mac(
+ s,
+ *p3++,
+ _sign[3],
+ pOverflow);
+
+ y[i] =
+ pv_round(
+ s,
+ pOverflow);
+
+ } /* for (i = 0; i < L_CODE; i++) */
+
+ return indx;
+
+ } /* build_code */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/media/codecs/amrnb/enc/src/c4_17pf.h b/media/codecs/amrnb/enc/src/c4_17pf.h
new file mode 100644
index 0000000..4dc66a9
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c4_17pf.h
@@ -0,0 +1,123 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/c4_17pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the c4_17pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef c4_17pf_h
+#define c4_17pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 code_4i40_17bits(
+ Word16 x[], /* (i) : target vector */
+ Word16 h[], /* (i) : impulse response of weighted synthesis filter */
+ /* h[-L_subfr..-1] must be set to zero. */
+ Word16 T0, /* (i) : Pitch lag */
+ Word16 pitch_sharp, /* (i) : Last quantized pitch gain */
+ Word16 code[], /* (o) : Innovative codebook */
+ Word16 y[], /* (o) : filtered fixed codebook excitation */
+ Word16 * sign, /* (o) : Signs of 4 pulses */
+ Flag * pOverflow /* (o) : Flag set when overflow occurs */
+ );
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _c4_17PF_H_ */
+
diff --git a/media/codecs/amrnb/enc/src/c8_31pf.cpp b/media/codecs/amrnb/enc/src/c8_31pf.cpp
new file mode 100644
index 0000000..07c2efd
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c8_31pf.cpp
@@ -0,0 +1,828 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/c8_31pf.c
+ Functions:
+
+ Date: 05/26/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified to pass overflow flag through to basic math function.
+ The flag is passed back to the calling function by pointer reference.
+
+ Description: Optimized file to reduce clock cycle usage. Updated copyright
+ year. Removed unnecessary include files and unused #defines.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Purpose : Searches a 31 bit algebraic codebook containing
+ : 8 pulses in a frame of 40 samples.
+ : in the same manner as GSM-EFR
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "c8_31pf.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "inv_sqrt.h"
+#include "cor_h.h"
+#include "cor_h_x2.h"
+#include "set_sign.h"
+#include "s10_8pf.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NB_PULSE 8
+
+/* define values/representation for output codevector and sign */
+#define POS_CODE 8191
+#define NEG_CODE 8191
+#define POS_SIGN 32767
+#define NEG_SIGN (Word16) (-32768L)
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ codvec[] Array of type Word16 -- position of pulses
+ sign[] Array of type Word16 -- sign of pulses
+ h[] Array of type Word16 -- impulse response of
+ weighted synthesis filter
+ Outputs:
+ cod[] Array of type Word16 -- innovative code vector
+ y[] Array of type Word16 -- filtered innovative code
+ sign_indx[] Array of type Word16 -- signs of 4 pulses (signs only)
+ pos_indx[] Array of type Word16 --
+ position index of 8 pulses(position only)
+
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ indx
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*************************************************************************
+ *
+ * FUNCTION: build_code()
+ *
+ * PURPOSE: Builds the codeword, the filtered codeword and a
+ * linear uncombined version of the index of the
+ * codevector, based on the signs and positions of 8 pulses.
+ *
+ *************************************************************************/
+
+static void build_code(
+ Word16 codvec[], /* i : position of pulses */
+ Word16 sign[], /* i : sign of d[n] */
+ Word16 cod[], /* o : innovative code vector */
+ Word16 h[], /* i : impulse response of weighted synthesis filter*/
+ Word16 y[], /* o : filtered innovative code */
+ Word16 sign_indx[], /* o : signs of 4 pulses (signs only) */
+ Word16 pos_indx[], /* o : position index of 8 pulses(position only) */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+ Word16 track;
+ Word16 sign_index;
+ Word16 pos_index;
+ Word16 _sign[NB_PULSE];
+
+ Word16 *p0;
+ Word16 *p1;
+ Word16 *p2;
+ Word16 *p3;
+ Word16 *p4;
+ Word16 *p5;
+ Word16 *p6;
+ Word16 *p7;
+
+ Word16 *p_cod = &cod[0];
+ Word16 *p_codvec = &codvec[0];
+
+ Word32 s;
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ *(p_cod++) = 0;
+ }
+
+ for (i = 0; i < NB_TRACK_MR102; i++)
+ {
+ pos_indx[i] = -1;
+ sign_indx[i] = -1;
+ }
+
+ for (k = 0; k < NB_PULSE; k++)
+ {
+ /* read pulse position */
+ i = codvec[k];
+ /* read sign */
+ j = sign[i];
+
+ pos_index = i >> 2; /* index = pos/4 */
+
+ track = i & 3; /* track = pos%4 */
+
+ if (j > 0)
+ {
+ cod[i] = (Word16)((Word32) cod[i] + POS_CODE);
+
+ _sign[k] = POS_SIGN;
+ sign_index = 0; /* bit=0 -> positive pulse */
+ }
+ else
+ {
+ cod[i] = (Word16)((Word32) cod[i] - NEG_CODE);
+
+ _sign[k] = NEG_SIGN;
+ sign_index = 1; /* bit=1 => negative pulse */
+ /* index = add (index, 8); 1 = negative old code */
+ }
+
+ if (pos_indx[track] < 0)
+ { /* first set first NB_TRACK pulses */
+ pos_indx[track] = pos_index;
+ sign_indx[track] = sign_index;
+ }
+ else
+ { /* 2nd row of pulses , test if positions needs to be switched */
+ if (((sign_index ^ sign_indx[track]) & 1) == 0)
+ {
+ /* sign of 1st pulse == sign of 2nd pulse */
+
+ if (pos_indx[track] <= pos_index)
+ { /* no swap */
+ pos_indx[track + NB_TRACK_MR102] = pos_index;
+ }
+ else
+ { /* swap*/
+ pos_indx[track + NB_TRACK_MR102] = pos_indx[track];
+
+ pos_indx[track] = pos_index;
+ sign_indx[track] = sign_index;
+ }
+ }
+ else
+ {
+ /* sign of 1st pulse != sign of 2nd pulse */
+
+ if (pos_indx[track] <= pos_index)
+ { /*swap*/
+ pos_indx[track + NB_TRACK_MR102] = pos_indx[track];
+
+ pos_indx[track] = pos_index;
+ sign_indx[track] = sign_index;
+ }
+ else
+ { /*no swap */
+ pos_indx[track + NB_TRACK_MR102] = pos_index;
+ }
+ }
+ }
+ }
+
+ p0 = h - *(p_codvec++);
+ p1 = h - *(p_codvec++);
+ p2 = h - *(p_codvec++);
+ p3 = h - *(p_codvec++);
+ p4 = h - *(p_codvec++);
+ p5 = h - *(p_codvec++);
+ p6 = h - *(p_codvec++);
+ p7 = h - *(p_codvec);
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = 0;
+
+ s =
+ L_mac(
+ s,
+ *p0++,
+ _sign[0],
+ pOverflow);
+ s =
+ L_mac(
+ s,
+ *p1++,
+ _sign[1],
+ pOverflow);
+ s =
+ L_mac(
+ s,
+ *p2++,
+ _sign[2],
+ pOverflow);
+ s =
+ L_mac(
+ s,
+ *p3++,
+ _sign[3],
+ pOverflow);
+ s =
+ L_mac(
+ s,
+ *p4++,
+ _sign[4],
+ pOverflow);
+ s =
+ L_mac(
+ s,
+ *p5++,
+ _sign[5],
+ pOverflow);
+ s =
+ L_mac(
+ s,
+ *p6++,
+ _sign[6],
+ pOverflow);
+ s =
+ L_mac(
+ s,
+ *p7++,
+ _sign[7],
+ pOverflow);
+
+ y[i] =
+ pv_round(
+ s,
+ pOverflow);
+
+ } /* for (i = 0; i < L_CODE; i++) */
+
+} /* build_code */
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: compress_code()
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+
+ Outputs:
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION:
+
+ PURPOSE: compression of three indeces [0..9] to one 10 bit index
+ minimizing the phase shift of a bit error.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 compress10(
+ Word16 pos_indxA, /* i : signs of 4 pulses (signs only) */
+ Word16 pos_indxB, /* i : position index of 8 pulses (pos only) */
+ Word16 pos_indxC, /* i : position and sign of 8 pulses (compressed) */
+ Flag *pOverflow) /* o : Flag set when overflow occurs */
+{
+ Word16 indx;
+ Word16 ia;
+ Word16 ib;
+ Word16 ic;
+
+ Word32 tempWord32;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ ia = pos_indxA >> 1;
+
+ ib = pos_indxB >> 1;
+
+ tempWord32 = ((Word32) ib * 5) << 1;
+
+ tempWord32 = tempWord32 >> 1;
+
+ ib = (Word16) tempWord32;
+
+ ic = pos_indxC >> 1;
+
+ tempWord32 = ((Word32) ic * 25) << 1;
+
+ tempWord32 = tempWord32 >> 1;
+
+ ic = (Word16) tempWord32;
+
+ ib += ic;
+
+ ib += ia;
+
+ indx = ib << 3;
+
+ ia = pos_indxA & 1;
+
+ ib = ((Word16)(pos_indxB & 1)) << 1;
+
+ ic = ((Word16)(pos_indxC & 1)) << 2;
+
+ ib += ic;
+
+ ib += ia;
+
+ indx += ib;
+
+ return indx;
+
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: compress_code()
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ sign_indx Array of type Word16 -- signs of 4 pulses (signs only)
+ pos_indx Array of type Word16 -- position index of 8 pulses
+ (position only)
+
+ Outputs:
+ indx Array of type Word16 -- position and sign of 8 pulses
+ (compressed)
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: compression of the linear codewords to 4+three indeces
+ one bit from each pulse is made robust to errors by
+ minimizing the phase shift of a bit error.
+ 4 signs (one for each track)
+ i0,i4,i1 => one index (7+3) bits, 3 LSBs more robust
+ i2,i6,i5 => one index (7+3) bits, 3 LSBs more robust
+ i3,i7 => one index (5+2) bits, 2-3 LSbs more robust
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c3_14pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void compress_code(
+ Word16 sign_indx[], /* i : signs of 4 pulses (signs only) */
+ Word16 pos_indx[], /* i : position index of 8 pulses (position only) */
+ Word16 indx[], /* o : position and sign of 8 pulses (compressed) */
+ Flag *pOverflow) /* o : Flag set when overflow occurs */
+{
+ Word16 i;
+ Word16 ia;
+ Word16 ib;
+ Word16 ic;
+
+ Word16 *p_indx = &indx[0];
+ Word16 *p_sign_indx = &sign_indx[0];
+
+ Word32 tempWord32;
+
+ for (i = 0; i < NB_TRACK_MR102; i++)
+ {
+ *(p_indx++) = *(p_sign_indx++);
+ }
+
+ /* First index
+ indx[NB_TRACK] = (ia/2+(ib/2)*5 +(ic/2)*25)*8 + ia%2 + (ib%2)*2 + (ic%2)*4; */
+
+ indx[NB_TRACK_MR102] =
+ compress10(
+ pos_indx[0],
+ pos_indx[4],
+ pos_indx[1],
+ pOverflow);
+
+ /* Second index
+ indx[NB_TRACK+1] = (ia/2+(ib/2)*5 +(ic/2)*25)*8 + ia%2 + (ib%2)*2 + (ic%2)*4; */
+
+ indx[NB_TRACK_MR102+1] =
+ compress10(
+ pos_indx[2],
+ pos_indx[6],
+ pos_indx[5],
+ pOverflow);
+
+ /*
+ Third index
+ if ((ib/2)%2 == 1)
+ indx[NB_TRACK+2] = ((((4-ia/2) + (ib/2)*5)*32+12)/25)*4 + ia%2 + (ib%2)*2;
+ else
+ indx[NB_TRACK+2] = ((((ia/2) + (ib/2)*5)*32+12)/25)*4 + ia%2 + (ib%2)*2;
+ */
+
+ ib = pos_indx[7] >> 1;
+
+ ib &= 1;
+
+ ia = pos_indx[3] >> 1;
+
+ if (ib == 1)
+ {
+ ia = 4 - ia;
+ }
+
+ ib = pos_indx[7] >> 1;
+
+ tempWord32 = ((Word32) ib * 5) << 1;
+
+ tempWord32 = tempWord32 >> 1;
+
+ ib = (Word16) tempWord32;
+
+ ib += ia;
+
+ ib <<= 5;
+
+ ib += 12;
+
+ ic = (Word16)(((Word32) ib * 1311) >> 15);
+
+ ic <<= 2;
+
+ ia = pos_indx[3] & 1;
+
+ ib = ((Word16)(pos_indx[7] & 1)) << 1;
+
+ ib += ic;
+
+ ib += ia;
+
+ indx[NB_TRACK_MR102+2] = ib;
+
+} /* compress_code */
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: code_8i40_31bits()
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x Array of type Word16 -- target vector
+ cn Array of type Word16 -- residual after long term prediction
+ h Array of type Word16 -- impulse response of weighted synthesis filter
+
+
+ Outputs:
+ cod Array of type Word16 -- algebraic (fixed) codebook excitation
+ y Array of type Word16 -- filtered fixed codebook excitation
+ indx Array of type Word16 -- index of 8 pulses (signs+positions)
+ pOverflow Pointer to Flag -- set when overflow occurs
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION:
+
+ PURPOSE: Searches a 31 bit algebraic codebook containing 8 pulses
+ in a frame of 40 samples.
+
+ DESCRIPTION:
+ The code contains 8 nonzero pulses: i0...i7.
+ All pulses can have two possible amplitudes: +1 or -1.
+ The 40 positions in a subframe are divided into 4 tracks of
+ interleaved positions. Each track contains two pulses.
+ The pulses can have the following possible positions:
+
+ i0, i4 : 0, 4, 8, 12, 16, 20, 24, 28, 32, 36
+ i1, i5 : 1, 5, 9, 13, 17, 21, 25, 29, 33, 37
+ i2, i6 : 2, 6, 10, 14, 18, 22, 26, 30, 34, 38
+ i3, i7 : 3, 7, 11, 15, 19, 23, 27, 31, 35, 39
+
+ Each pair of pulses require 1 bit for their signs. The positions
+ are encoded together 3,3 and 2 resulting in
+ (7+3) + (7+3) + (5+2) bits for their
+ positions. This results in a 31 (4 sign and 27 pos) bit codebook.
+ The function determines the optimal pulse signs and positions, builds
+ the codevector, and computes the filtered codevector.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] c8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void code_8i40_31bits(
+ Word16 x[], /* i : target vector */
+ Word16 cn[], /* i : residual after long term prediction */
+ Word16 h[], /* i : impulse response of weighted synthesis
+ filter */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 indx[], /* o : 7 Word16, index of 8 pulses (signs+positions) */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+)
+{
+ Word16 ipos[NB_PULSE];
+ Word16 pos_max[NB_TRACK_MR102];
+ Word16 codvec[NB_PULSE];
+
+ Word16 dn[L_CODE];
+ Word16 sign[L_CODE];
+
+ Word16 rr[L_CODE][L_CODE];
+ Word16 linear_signs[NB_TRACK_MR102];
+ Word16 linear_codewords[NB_PULSE];
+
+ cor_h_x2(
+ h,
+ x,
+ dn,
+ 2,
+ NB_TRACK_MR102,
+ STEP_MR102,
+ pOverflow);
+
+ /* 2 = use GSMEFR scaling */
+
+ set_sign12k2(
+ dn,
+ cn,
+ sign,
+ pos_max,
+ NB_TRACK_MR102,
+ ipos,
+ STEP_MR102,
+ pOverflow);
+
+ /* same setsign alg as GSM-EFR new constants though*/
+
+ cor_h(
+ h,
+ sign,
+ rr,
+ pOverflow);
+
+ search_10and8i40(
+ NB_PULSE,
+ STEP_MR102,
+ NB_TRACK_MR102,
+ dn,
+ rr,
+ ipos,
+ pos_max,
+ codvec,
+ pOverflow);
+
+ build_code(
+ codvec,
+ sign,
+ cod,
+ h,
+ y,
+ linear_signs,
+ linear_codewords,
+ pOverflow);
+
+ compress_code(
+ linear_signs,
+ linear_codewords,
+ indx,
+ pOverflow);
+
+} /* code_8i40_31bits */
+
+
+
diff --git a/media/codecs/amrnb/enc/src/c8_31pf.h b/media/codecs/amrnb/enc/src/c8_31pf.h
new file mode 100644
index 0000000..03225ce
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/c8_31pf.h
@@ -0,0 +1,122 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/c8_31pf.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the c8_31pf.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef c8_31pf_h
+#define c8_31pf_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void code_8i40_31bits(
+ Word16 x[], /* i : target vector */
+ Word16 cn[], /* i : residual after long term prediction */
+ Word16 h[], /* i : impulse response of weighted synthesis
+ filter */
+ Word16 cod[], /* o : algebraic (fixed) codebook excitation */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ Word16 indx[], /* o : 7 Word16, index of 8 pulses (signs+positions) */
+ Flag * pOverflow /* o : Flag set when overflow occurs */
+ );
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _c8_31PF_H_ */
diff --git a/media/codecs/amrnb/enc/src/calc_cor.cpp b/media/codecs/amrnb/enc/src/calc_cor.cpp
new file mode 100644
index 0000000..db786a6
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/calc_cor.cpp
@@ -0,0 +1,267 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/calc_cor.c
+
+ Date: 06/12/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Initial Optimization
+
+ Description: Optimize code by calculating two correlation per iteration
+ of the outer loop.
+
+ Description: Delete psedocode
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Defined one local variable per line.
+
+ Description:
+ 1. Eliminated unused include file typedef.h.
+ 2. Replaced array addressing by pointers
+ 3. Unrolled loops to save extra accesses to memory
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Using inline functions from fxp_arithmetic.h for mac operations.
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "calc_cor.h"
+#include "basic_op.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: comp_corr
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ scal_sig = array of input samples. (Word16)
+ L_frame = length of frame used to compute pitch(Word16)
+ lag_max = maximum lag (Word16)
+ lag_min = minimum lag (Word16)
+ corr = pointer to array of correlations corresponding to the selected
+ lags. (Word32)
+
+ Outputs:
+ corr = pointer to array of correlations corresponding to the selected
+ lags. (Word32)
+
+ Returns:
+ none
+
+ Global Variables Used:
+ none
+
+ Local Variables Needed:
+ none
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates all correlations of scal_sig[] in a given delay
+ range.
+
+ The correlation is given by
+
+ cor[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max
+
+ The function outputs all of the correlations
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ none
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] calc_cor.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void comp_corr (
+ Word16 scal_sig[], // i : scaled signal.
+ Word16 L_frame, // i : length of frame to compute pitch
+ Word16 lag_max, // i : maximum lag
+ Word16 lag_min, // i : minimum lag
+ Word32 corr[]) // o : correlation of selected lag
+{
+ Word16 i, j;
+ Word16 *p, *p1;
+ Word32 t0;
+
+ for (i = lag_max; i >= lag_min; i--)
+ {
+ p = scal_sig;
+ p1 = &scal_sig[-i];
+ t0 = 0;
+
+ for (j = 0; j < L_frame; j++, p++, p1++)
+ {
+ t0 = L_mac (t0, *p, *p1);
+ }
+ corr[-i] = t0;
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void comp_corr(
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word32 corr[]) /* o : correlation of selected lag */
+{
+
+
+
+
+ /*---------------------------------------------------
+ ; lag_max and lag_min are typically negative numbers
+ -----------------------------------------------------*/
+
+
+ /* PIT_MIN_MR122 18 Minimum pitch lag (MR122 mode) */
+ /* PIT_MIN 20 Minimum pitch lag (all other modes) */
+ /* PIT_MAX 143 Maximum pitch lag */
+
+
+ Word16 i;
+ Word16 j;
+ Word16 *p;
+ Word16 *p1;
+ Word16 *p2;
+ Word16 *p_scal_sig;
+ Word32 t1;
+ Word32 t2;
+ Word32 t3;
+ Word32 t4;
+
+ corr = corr - lag_max ;
+ p_scal_sig = &scal_sig[-lag_max];
+
+ for (i = ((lag_max - lag_min) >> 2) + 1; i > 0; i--)
+ {
+ t1 = 0;
+ t2 = 0;
+ t3 = 0;
+ t4 = 0;
+ p = &scal_sig[0];
+ p1 = p_scal_sig++;
+ p_scal_sig++;
+ p2 = p_scal_sig++;
+ p_scal_sig++;
+ for (j = (L_frame >> 1); j != 0; j--)
+ {
+ t1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1++), t1);
+ t2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1), t2);
+ t3 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p2++), t3);
+ t4 = amrnb_fxp_mac_16_by_16bb((Word32) * (p++), (Word32) * (p2), t4);
+
+ t1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1++), t1);
+ t2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1), t2);
+ t3 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p2++), t3);
+ t4 = amrnb_fxp_mac_16_by_16bb((Word32) * (p++), (Word32) * (p2), t4);
+ }
+
+ *(corr++) = t1 << 1;
+ *(corr++) = t2 << 1;
+ *(corr++) = t3 << 1;
+ *(corr++) = t4 << 1;
+
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/calc_cor.h b/media/codecs/amrnb/enc/src/calc_cor.h
new file mode 100644
index 0000000..d4a694b
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/calc_cor.h
@@ -0,0 +1,87 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : calc_cor.h
+* Purpose : Calculate all correlations for prior the OL LTP
+*
+********************************************************************************
+*/
+#ifndef calc_cor_h
+#define calc_cor_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ /*************************************************************************
+ *
+ * FUNCTION: comp_corr
+ *
+ * PURPOSE: Calculate all correlations of scal_sig[] in a given delay
+ * range.
+ *
+ * DESCRIPTION:
+ * The correlation is given by
+ * cor[t] = <scal_sig[n], scal_sig[n-t]>, t=lag_min,...,lag_max
+ * The functions outputs all correlations in the given range
+ *
+ *************************************************************************/
+ void comp_corr(Word16 scal_sig[], /* i : scaled signal. */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word32 corr[] /* o : correlation of selected lag */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/enc/src/calc_en.cpp b/media/codecs/amrnb/enc/src/calc_en.cpp
new file mode 100644
index 0000000..6cf6867
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/calc_en.cpp
@@ -0,0 +1,825 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/calc_en.c
+ Funtions: calc_unfilt_energies
+ calc_filt_energies
+ calc_target_energy
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that calculate the energy coefficients
+ for unfiltered and filtered excitation signals, the LTP coding gain, and
+ the target energy.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "calc_en.h"
+#include "typedef.h"
+#include "basicop_malloc.h"
+#include "l_comp.h"
+#include "cnst.h"
+#include "log2.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: calc_unfilt_energies
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ res = LP residual, buffer type Word16
+ exc = LTP excitation (unfiltered), buffer type Word16
+ code = CB innovation (unfiltered), buffer type Word16
+ gain_pit = pitch gain, type Word16
+ L_subfr = Subframe length, type Word16
+ frac_en = energy coefficients (4), fraction part, buffer type Word16
+ exp_en = energy coefficients (4), exponent part, buffer type Word16
+ ltpg = LTP coding gain (log2()), pointer to type Word16
+ pOverflow= pointer to value indicating existence of overflow (Flag)
+
+ Outputs:
+ frac_en buffer containing new fractional parts of energy coefficients
+ exp_en buffer containing new exponential parts of energy coefficients
+ ltpg points to new LTP coding gain
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates several energy coefficients for unfiltered
+ excitation signals and the LTP coding gain
+
+ frac_en[0]*2^exp_en[0] = <res res> LP residual energy
+ frac_en[1]*2^exp_en[1] = <exc exc> LTP residual energy
+ frac_en[2]*2^exp_en[2] = <exc code> LTP/CB innovation dot product
+ frac_en[3]*2^exp_en[3] = <lres lres> LTP residual energy
+ (lres = res - gain_pit*exc)
+ ltpg = log2(LP_res_en / LTP_res_en)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ calc_en.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void
+calc_unfilt_energies(
+ Word16 res[], // i : LP residual, Q0
+ Word16 exc[], // i : LTP excitation (unfiltered), Q0
+ Word16 code[], // i : CB innovation (unfiltered), Q13
+ Word16 gain_pit, // i : pitch gain, Q14
+ Word16 L_subfr, // i : Subframe length
+
+ Word16 frac_en[], // o : energy coefficients (4), fraction part, Q15
+ Word16 exp_en[], // o : energy coefficients (4), exponent part, Q0
+ Word16 *ltpg // o : LTP coding gain (log2()), Q13
+)
+{
+ Word32 s, L_temp;
+ Word16 i, exp, tmp;
+ Word16 ltp_res_en, pred_gain;
+ Word16 ltpg_exp, ltpg_frac;
+
+ // Compute residual energy
+ s = L_mac((Word32) 0, res[0], res[0]);
+ for (i = 1; i < L_subfr; i++)
+ s = L_mac(s, res[i], res[i]);
+
+ // ResEn := 0 if ResEn < 200.0 (= 400 Q1)
+ if (L_sub (s, 400L) < 0)
+ {
+ frac_en[0] = 0;
+ exp_en[0] = -15;
+ }
+ else
+ {
+ exp = norm_l(s);
+ frac_en[0] = extract_h(L_shl(s, exp));
+ exp_en[0] = sub(15, exp);
+ }
+
+ // Compute ltp excitation energy
+ s = L_mac((Word32) 0, exc[0], exc[0]);
+ for (i = 1; i < L_subfr; i++)
+ s = L_mac(s, exc[i], exc[i]);
+
+ exp = norm_l(s);
+ frac_en[1] = extract_h(L_shl(s, exp));
+ exp_en[1] = sub(15, exp);
+
+ // Compute scalar product <exc[],code[]>
+ s = L_mac((Word32) 0, exc[0], code[0]);
+ for (i = 1; i < L_subfr; i++)
+ s = L_mac(s, exc[i], code[i]);
+
+ exp = norm_l(s);
+ frac_en[2] = extract_h(L_shl(s, exp));
+ exp_en[2] = sub(16-14, exp);
+
+ // Compute energy of LTP residual
+ s = 0L;
+ for (i = 0; i < L_subfr; i++)
+ {
+ L_temp = L_mult(exc[i], gain_pit);
+ L_temp = L_shl(L_temp, 1);
+ tmp = sub(res[i], pv_round(L_temp)); // LTP residual, Q0
+ s = L_mac (s, tmp, tmp);
+ }
+
+ exp = norm_l(s);
+ ltp_res_en = extract_h (L_shl (s, exp));
+ exp = sub (15, exp);
+
+ frac_en[3] = ltp_res_en;
+ exp_en[3] = exp;
+
+ // calculate LTP coding gain, i.e. energy reduction LP res -> LTP res
+ if (ltp_res_en > 0 && frac_en[0] != 0)
+ {
+ // gain = ResEn / LTPResEn
+ pred_gain = div_s (shr (frac_en[0], 1), ltp_res_en);
+ exp = sub (exp, exp_en[0]);
+
+ // L_temp = ltpGain * 2^(30 + exp)
+ L_temp = L_deposit_h (pred_gain);
+ // L_temp = ltpGain * 2^27
+ L_temp = L_shr (L_temp, add (exp, 3));
+
+ // Log2 = log2() + 27
+ Log2(L_temp, <pg_exp, <pg_frac);
+
+ // ltpg = log2(LtpGain) * 2^13 --> range: +- 4 = +- 12 dB
+ L_temp = L_Comp (sub (ltpg_exp, 27), ltpg_frac);
+ *ltpg = pv_round (L_shl (L_temp, 13)); // Q13
+ }
+ else
+ {
+ *ltpg = 0;
+ }
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void calc_unfilt_energies(
+ Word16 res[], /* i : LP residual, Q0 */
+ Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
+ Word16 code[], /* i : CB innovation (unfiltered), Q13 */
+ Word16 gain_pit, /* i : pitch gain, Q14 */
+ Word16 L_subfr, /* i : Subframe length */
+
+ Word16 frac_en[], /* o : energy coefficients (4), fraction part, Q15 */
+ Word16 exp_en[], /* o : energy coefficients (4), exponent part, Q0 */
+ Word16 *ltpg, /* o : LTP coding gain (log2()), Q13 */
+ Flag *pOverflow
+)
+{
+ Word32 s1; /* Intermediate energy accumulator */
+ Word32 s2; /* Intermediate energy accumulator */
+ Word32 s3; /* Intermediate energy accumulator */
+ Word32 s4; /* Intermediate energy accumulator */
+ Word32 L_temp; /* temporal 32 bits storage */
+
+ Word16 i; /* index used in all loops */
+ Word16 exp; /* nunmber of '0's or '1's before MSB != 0 */
+ Word16 tmp1; /* temporal storage */
+ Word16 tmp2; /* temporal storage */
+ Word16 ltp_res_en;
+ Word16 pred_gain; /* predictor gain */
+ Word16 ltpg_exp; /* LTP gain (exponent) */
+ Word16 ltpg_frac; /* LTP gain (mantissa or fractional part) */
+
+ s1 = 0;
+ s2 = 0;
+ s3 = 0;
+ s4 = 0;
+
+ /*----------------------------------------------------------------------------
+ NOTE: Overflow is expected as a result of multiply and accumulated without
+ scale down the inputs. This modification is not made at this point
+ to have bit exact results with the pre-optimization code. (JT 6/20/00)
+
+ ----------------------------------------------------------------------------*/
+
+ for (i = 0; i < L_subfr; i++)
+ {
+ tmp1 = res[i]; /* avoid multiple accesses to memory */
+ tmp2 = exc[i];
+
+ s1 = amrnb_fxp_mac_16_by_16bb((Word32) tmp1, (Word32) tmp1, s1); /* Compute residual energy */
+ s2 = amrnb_fxp_mac_16_by_16bb((Word32) tmp2, (Word32) tmp2, s2); /* Compute ltp excitation energy */
+ s3 = amrnb_fxp_mac_16_by_16bb((Word32) tmp2, (Word32) code[i], s3);/* Compute scalar product */
+ /* <exc[],code[]> */
+
+ L_temp = L_mult(tmp2, gain_pit, pOverflow);
+ L_temp = L_shl(L_temp, 1, pOverflow);
+ tmp2 = sub(tmp1, pv_round(L_temp, pOverflow), pOverflow);
+ /* LTP residual, Q0 */
+ s4 = L_mac(s4, tmp2, tmp2, pOverflow);
+ /* Compute energy of LTP residual */
+ }
+ s1 = s1 << 1;
+ s2 = s2 << 1;
+ s3 = s3 << 1;
+
+ if (s1 & MIN_32)
+ {
+ s1 = MAX_32;
+ *pOverflow = 1;
+ }
+
+ /* ResEn := 0 if ResEn < 200.0 (= 400 Q1) */
+ if (s1 < 400L)
+ {
+ frac_en[0] = 0;
+ exp_en[0] = -15;
+ }
+ else
+ {
+ exp = norm_l(s1);
+ frac_en[0] = (Word16)(L_shl(s1, exp, pOverflow) >> 16);
+ exp_en[0] = (15 - exp);
+ }
+
+ if (s2 & MIN_32)
+ {
+ s2 = MAX_32;
+ *pOverflow = 1;
+ }
+
+ exp = norm_l(s2);
+ frac_en[1] = (Word16)(L_shl(s2, exp, pOverflow) >> 16);
+ exp_en[1] = sub(15, exp, pOverflow);
+
+ /* s3 is not always sum of squares */
+ exp = norm_l(s3);
+ frac_en[2] = (Word16)(L_shl(s3, exp, pOverflow) >> 16);
+ exp_en[2] = 2 - exp;
+
+ exp = norm_l(s4);
+ ltp_res_en = (Word16)(L_shl(s4, exp, pOverflow) >> 16);
+ exp = sub(15, exp, pOverflow);
+
+ frac_en[3] = ltp_res_en;
+ exp_en[3] = exp;
+
+ /* calculate LTP coding gain, i.e. energy reduction LP res -> LTP res */
+
+ if (ltp_res_en > 0 && frac_en[0] != 0)
+ {
+ /* gain = ResEn / LTPResEn */
+ pred_gain = div_s(shr(frac_en[0], 1, pOverflow), ltp_res_en);
+ exp = sub(exp, exp_en[0], pOverflow);
+
+ /* L_temp = ltpGain * 2^(30 + exp) */
+ L_temp = (Word32) pred_gain << 16;
+ /* L_temp = ltpGain * 2^27 */
+ L_temp = L_shr(L_temp, (Word16)(exp + 3), pOverflow);
+
+ /* Log2 = log2() + 27 */
+ Log2(L_temp, <pg_exp, <pg_frac, pOverflow);
+
+ /* ltpg = log2(LtpGain) * 2^13 --> range: +- 4 = +- 12 dB */
+ L_temp = L_Comp(sub(ltpg_exp, 27, pOverflow), ltpg_frac, pOverflow);
+ *ltpg = pv_round(L_shl(L_temp, 13, pOverflow), pOverflow); /* Q13 */
+ }
+ else
+ {
+ *ltpg = 0;
+ }
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: calc_filt_energies
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode = coder mode, type Mode
+ xn = LTP target vector, buffer type Word16
+ xn2 = CB target vector, buffer type Word16
+ y1 = Adaptive codebook, buffer type Word16
+ Y2 = Filtered innovative vector, buffer type Word16
+ g_coeff = Correlations <xn y1> <y1 y1>
+ computed in G_pitch() buffer type Word16
+ frac_coeff = energy coefficients (5), fraction part, buffer type Word16
+ exp_coeff = energy coefficients (5), exponent part, buffer type Word16
+ cod_gain_frac = optimum codebook gain (fraction part), pointer type Word16
+ cod_gain_exp = optimum codebook gain (exponent part), pointer type Word16
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ frac_coeff contains new fraction part energy coefficients
+ exp_coeff contains new exponent part energy coefficients
+ cod_gain_frac points to the new optimum codebook gain (fraction part)
+ cod_gain_exp points to the new optimum codebook gain (exponent part)
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates several energy coefficients for filtered
+ excitation signals
+
+ Compute coefficients need for the quantization and the optimum
+ codebook gain gcu (for MR475 only).
+
+ coeff[0] = y1 y1
+ coeff[1] = -2 xn y1
+ coeff[2] = y2 y2
+ coeff[3] = -2 xn y2
+ coeff[4] = 2 y1 y2
+
+ gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
+
+ Product <y1 y1> and <xn y1> have been computed in G_pitch() and
+ are in vector g_coeff[].
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ calc_en.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void
+calc_filt_energies(
+ enum Mode mode, // i : coder mode
+ Word16 xn[], // i : LTP target vector, Q0
+ Word16 xn2[], // i : CB target vector, Q0
+ Word16 y1[], // i : Adaptive codebook, Q0
+ Word16 Y2[], // i : Filtered innovative vector, Q12
+ Word16 g_coeff[], // i : Correlations <xn y1> <y1 y1>
+ // computed in G_pitch()
+
+ Word16 frac_coeff[],// o : energy coefficients (5), fraction part, Q15
+ Word16 exp_coeff[], // o : energy coefficients (5), exponent part, Q0
+ Word16 *cod_gain_frac,// o: optimum codebook gain (fraction part), Q15
+ Word16 *cod_gain_exp // o: optimum codebook gain (exponent part), Q0
+)
+{
+ Word32 s, ener_init;
+ Word16 i, exp, frac;
+ Word16 y2[L_SUBFR];
+
+ if (sub(mode, MR795) == 0 || sub(mode, MR475) == 0)
+ {
+ ener_init = 0L;
+ }
+ else
+ {
+ ener_init = 1L;
+ }
+
+ for (i = 0; i < L_SUBFR; i++) {
+ y2[i] = shr(Y2[i], 3);
+ }
+
+ frac_coeff[0] = g_coeff[0];
+ exp_coeff[0] = g_coeff[1];
+ frac_coeff[1] = negate(g_coeff[2]); // coeff[1] = -2 xn y1
+ exp_coeff[1] = add(g_coeff[3], 1);
+
+
+ // Compute scalar product <y2[],y2[]>
+
+ s = L_mac(ener_init, y2[0], y2[0]);
+ for (i = 1; i < L_SUBFR; i++)
+ s = L_mac(s, y2[i], y2[i]);
+
+ exp = norm_l(s);
+ frac_coeff[2] = extract_h(L_shl(s, exp));
+ exp_coeff[2] = sub(15 - 18, exp);
+
+ // Compute scalar product -2*<xn[],y2[]>
+
+ s = L_mac(ener_init, xn[0], y2[0]);
+ for (i = 1; i < L_SUBFR; i++)
+ s = L_mac(s, xn[i], y2[i]);
+
+ exp = norm_l(s);
+ frac_coeff[3] = negate(extract_h(L_shl(s, exp)));
+ exp_coeff[3] = sub(15 - 9 + 1, exp);
+
+
+ // Compute scalar product 2*<y1[],y2[]>
+
+ s = L_mac(ener_init, y1[0], y2[0]);
+ for (i = 1; i < L_SUBFR; i++)
+ s = L_mac(s, y1[i], y2[i]);
+
+ exp = norm_l(s);
+ frac_coeff[4] = extract_h(L_shl(s, exp));
+ exp_coeff[4] = sub(15 - 9 + 1, exp);
+
+ if (sub(mode, MR475) == 0 || sub(mode, MR795) == 0)
+ {
+ // Compute scalar product <xn2[],y2[]>
+
+ s = L_mac(ener_init, xn2[0], y2[0]);
+ for (i = 1; i < L_SUBFR; i++)
+ s = L_mac(s, xn2[i], y2[i]);
+
+ exp = norm_l(s);
+ frac = extract_h(L_shl(s, exp));
+ exp = sub(15 - 9, exp);
+
+
+ if (frac <= 0)
+ {
+ *cod_gain_frac = 0;
+ *cod_gain_exp = 0;
+ }
+ else
+ {
+ //
+ gcu = <xn2, y2> / c[2]
+ = (frac>>1)/frac[2] * 2^(exp+1-exp[2])
+ = div_s(frac>>1, frac[2])*2^-15 * 2^(exp+1-exp[2])
+ = div_s * 2^(exp-exp[2]-14)
+
+ *cod_gain_frac = div_s (shr (frac,1), frac_coeff[2]);
+ *cod_gain_exp = sub (sub (exp, exp_coeff[2]), 14);
+
+ }
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void calc_filt_energies(
+ enum Mode mode, /* i : coder mode */
+ Word16 xn[], /* i : LTP target vector, Q0 */
+ Word16 xn2[], /* i : CB target vector, Q0 */
+ Word16 y1[], /* i : Adaptive codebook, Q0 */
+ Word16 Y2[], /* i : Filtered innovative vector, Q12 */
+ Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
+ /* computed in G_pitch() */
+ Word16 frac_coeff[], /* o : energy coefficients (5), fraction part, Q15 */
+ Word16 exp_coeff[], /* o : energy coefficients (5), exponent part, Q0 */
+ Word16 *cod_gain_frac, /* o : optimum codebook gain (fraction part),Q15 */
+ Word16 *cod_gain_exp, /* o : optimum codebook gain (exponent part), Q0 */
+ Flag *pOverflow
+)
+{
+ Word32 s1; /* Intermediate energy accumulator */
+ Word32 s2; /* Intermediate energy accumulator */
+ Word32 s3; /* Intermediate energy accumulator */
+
+ Word16 i; /* index used in all loops */
+ Word16 exp; /* number of '0's or '1's before MSB != 0 */
+ Word16 frac; /* fractional part */
+ Word16 tmp; /* temporal storage */
+ Word16 scaled_y2[L_SUBFR];
+
+
+ frac_coeff[0] = g_coeff[0];
+ exp_coeff[0] = g_coeff[1];
+ frac_coeff[1] = negate(g_coeff[2]); /* coeff[1] = -2 xn y1 */
+ exp_coeff[1] = add(g_coeff[3], 1, pOverflow);
+
+ if ((mode == MR795) || (mode == MR475))
+ {
+ s1 = 0L;
+ s2 = 0L;
+ s3 = 0L;
+ }
+ else
+ {
+ s1 = 1L;
+ s2 = 1L;
+ s3 = 1L;
+ }
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ /* avoid multiple accesses to memory */
+ tmp = (Y2[i] >> 3);
+ scaled_y2[i] = tmp;
+
+ /* Compute scalar product <scaled_y2[],scaled_y2[]> */
+ s1 = L_mac(s1, tmp, tmp, pOverflow);
+
+ /* Compute scalar product -2*<xn[],scaled_y2[]> */
+ s2 = L_mac(s2, xn[i], tmp, pOverflow);
+
+ /* Compute scalar product 2*<y1[],scaled_y2[]> */
+ s3 = L_mac(s3, y1[i], tmp, pOverflow);
+ }
+
+ exp = norm_l(s1);
+ frac_coeff[2] = (Word16)(L_shl(s1, exp, pOverflow) >> 16);
+ exp_coeff[2] = (-3 - exp);
+
+ exp = norm_l(s2);
+ frac_coeff[3] = negate((Word16)(L_shl(s2, exp, pOverflow) >> 16));
+ exp_coeff[3] = (7 - exp);
+
+ exp = norm_l(s3);
+ frac_coeff[4] = (Word16)(L_shl(s3, exp, pOverflow) >> 16);
+ exp_coeff[4] = sub(7, exp, pOverflow);
+
+
+ if ((mode == MR795) || (mode == MR475))
+ {
+ /* Compute scalar product <xn2[],scaled_y2[]> */
+ s1 = 0L;
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ s1 = amrnb_fxp_mac_16_by_16bb((Word32) xn2[i], (Word32)scaled_y2[i], s1);
+ }
+
+ s1 = s1 << 1;
+
+ exp = norm_l(s1);
+ frac = (Word16)(L_shl(s1, exp, pOverflow) >> 16);
+ exp = (6 - exp);
+
+ if (frac <= 0)
+ {
+ *cod_gain_frac = 0;
+ *cod_gain_exp = 0;
+ }
+ else
+ {
+ /*
+ gcu = <xn2, scaled_y2> / c[2]
+ = (frac>>1)/frac[2] * 2^(exp+1-exp[2])
+ = div_s(frac>>1, frac[2])*2^-15 * 2^(exp+1-exp[2])
+ = div_s * 2^(exp-exp[2]-14)
+ */
+ *cod_gain_frac = div_s(shr(frac, 1, pOverflow), frac_coeff[2]);
+ *cod_gain_exp = ((exp - exp_coeff[2]) - 14);
+ }
+ }
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: calc_target_energy
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ xn = LTP target vector, buffer to type Word16 Q0
+ en_exp = optimum codebook gain (exponent part) pointer to type Word16
+ en_frac = optimum codebook gain (fraction part) pointer to type Word16
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ en_exp points to new optimum codebook gain (exponent part)
+ en_frac points to new optimum codebook gain (fraction part)
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates the target energy using the formula,
+ en = <xn, xn>
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ calc_en.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void
+calc_target_energy(
+ Word16 xn[], // i: LTP target vector, Q0
+ Word16 *en_exp, // o: optimum codebook gain (exponent part), Q0
+ Word16 *en_frac // o: optimum codebook gain (fraction part), Q15
+)
+{
+ Word32 s;
+ Word16 i, exp;
+
+ // Compute scalar product <xn[], xn[]>
+ s = L_mac(0L, xn[0], xn[0]);
+ for (i = 1; i < L_SUBFR; i++)
+ s = L_mac(s, xn[i], xn[i]);
+
+ // s = SUM 2*xn(i) * xn(i) = <xn xn> * 2
+ exp = norm_l(s);
+ *en_frac = extract_h(L_shl(s, exp));
+ *en_exp = sub(16, exp);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void calc_target_energy(
+ Word16 xn[], /* i: LTP target vector, Q0 */
+ Word16 *en_exp, /* o: optimum codebook gain (exponent part), Q0 */
+ Word16 *en_frac, /* o: optimum codebook gain (fraction part), Q15 */
+ Flag *pOverflow
+)
+{
+ Word32 s; /* Intermediate energy accumulator */
+ Word16 i; /* index used in all loops */
+ Word16 exp;
+
+ /* Compute scalar product <xn[], xn[]> */
+ s = 0;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ s = amrnb_fxp_mac_16_by_16bb((Word32) xn[i], (Word32) xn[i], s);
+ }
+
+ if (s < 0)
+ {
+ *pOverflow = 1;
+ s = MAX_32;
+ }
+
+ /* s = SUM 2*xn(i) * xn(i) = <xn xn> * 2 */
+ exp = norm_l(s);
+ *en_frac = (Word16)(L_shl(s, exp, pOverflow) >> 16);
+ *en_exp = (16 - exp);
+
+ return;
+}
+
+
diff --git a/media/codecs/amrnb/enc/src/calc_en.h b/media/codecs/amrnb/enc/src/calc_en.h
new file mode 100644
index 0000000..052f5b4
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/calc_en.h
@@ -0,0 +1,192 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/c_g_aver.h
+
+ Date: 12/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : calc_en.h
+ Purpose : calculation of energy coefficients for quantizers
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _CALC_EN_H_
+#define _CALC_EN_H_
+#define calc_en_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /*
+ * FUNCTION: calc_unfilt_energies
+ *
+ * PURPOSE: calculation of several energy coefficients for unfiltered
+ * excitation signals and the LTP coding gain
+ *
+ * frac_en[0]*2^exp_en[0] = <res res> // LP residual energy
+ * frac_en[1]*2^exp_en[1] = <exc exc> // LTP residual energy
+ * frac_en[2]*2^exp_en[2] = <exc code> // LTP/CB innovation dot product
+ * frac_en[3]*2^exp_en[3] = <lres lres> // LTP residual energy
+ * // (lres = res - gain_pit*exc)
+ * ltpg = log2(LP_res_en / LTP_res_en)
+ */
+ void
+ calc_unfilt_energies(
+ Word16 res[], /* i : LP residual, Q0 */
+ Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
+ Word16 code[], /* i : CB innovation (unfiltered), Q13 */
+ Word16 gain_pit, /* i : pitch gain, Q14 */
+ Word16 L_subfr, /* i : Subframe length */
+
+ Word16 frac_en[], /* o : energy coefficients (3), fraction part, Q15 */
+ Word16 exp_en[], /* o : energy coefficients (3), exponent part, Q0 */
+ Word16 *ltpg, /* o : LTP coding gain (log2()), Q13 */
+ Flag *pOverflow
+ );
+
+ /*
+ * FUNCTION: calc_filt_energies
+ *
+ * PURPOSE: calculation of several energy coefficients for filtered
+ * excitation signals
+ *
+ * Compute coefficients need for the quantization and the optimum
+ * codebook gain gcu (for MR475 only).
+ *
+ * coeff[0] = y1 y1
+ * coeff[1] = -2 xn y1
+ * coeff[2] = y2 y2
+ * coeff[3] = -2 xn y2
+ * coeff[4] = 2 y1 y2
+ *
+ *
+ * gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
+ *
+ * Product <y1 y1> and <xn y1> have been computed in G_pitch() and
+ * are in vector g_coeff[].
+ */
+ void
+ calc_filt_energies(
+ enum Mode mode, /* i : coder mode */
+ Word16 xn[], /* i : LTP target vector, Q0 */
+ Word16 xn2[], /* i : CB target vector, Q0 */
+ Word16 y1[], /* i : Adaptive codebook, Q0 */
+ Word16 Y2[], /* i : Filtered innovative vector, Q12 */
+ Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
+ /* computed in G_pitch() */
+
+ Word16 frac_coeff[],/* o : energy coefficients (5), fraction part, Q15 */
+ Word16 exp_coeff[], /* o : energy coefficients (5), exponent part, Q0 */
+ Word16 *cod_gain_frac,/* o: optimum codebook gain (fraction part), Q15 */
+ Word16 *cod_gain_exp, /* o: optimum codebook gain (exponent part), Q0 */
+ Flag *pOverflow
+ );
+
+ /*
+ * FUNCTION: calc_target_energy
+ *
+ * PURPOSE: calculation of target energy
+ *
+ * en = <xn, xn>
+ */
+ void
+ calc_target_energy(
+ Word16 xn[], /* i: LTP target vector, Q0 */
+ Word16 *en_exp, /* o: optimum codebook gain (exponent part), Q0 */
+ Word16 *en_frac, /* o: optimum codebook gain (fraction part), Q15 */
+ Flag *pOverflow
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CALC_EN_H_ */
+
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/cbsearch.cpp b/media/codecs/amrnb/enc/src/cbsearch.cpp
new file mode 100644
index 0000000..a02b891
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cbsearch.cpp
@@ -0,0 +1,392 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/cbsearch.c
+ Functions: D_plsf_3
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ (1) Removed "count.h" and "basic_op.h" and replaced with individual include
+ files (add.h, sub.h, etc.)
+ (2) Added pOverflow parameter to code_10i40_35bits()
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+ ------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x[] -- array of type Word16 -- target vector, Q0
+ h[] -- array of type Word16 -- impulse response of weighted synthesis
+ filter h[-L_subfr..-1] must be set to
+ zero. Q12
+ T0 -- Word16 -- Pitch lag
+ pitch_sharp -- Word16 -- Last quantized pitch gain, Q14
+ gain_pit -- Word16 gain_pit -- Pitch gain, Q14
+ res2[] -- array of type Word16 -- Long term prediction residual, Q0
+ mode -- enum Mode -- coder mode
+ subNr -- Word16 -- subframe number
+
+ Outputs:
+ code[] -- array of type Word16 -- Innovative codebook, Q13
+ y[] -- array of type Word16 -- filtered fixed codebook excitation
+ Q12
+
+ anap -- Double pointer to Word16 -- Signs of the pulses
+
+
+ pOverflow -- pointer to Flag -- Flag set when overflow occurs
+
+ Returns:
+ Zero
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose : Inovative codebook search (find index and gain)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cbsearch.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "cbsearch.h"
+
+#include "typedef.h"
+#include "c2_9pf.h"
+#include "c2_11pf.h"
+#include "c3_14pf.h"
+#include "c4_17pf.h"
+#include "c8_31pf.h"
+#include "c1035pf.h"
+#include "mode.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void cbsearch(Word16 x[], /* i : target vector, Q0 */
+ Word16 h[], /* i : impulse response of weighted synthesis*/
+ /* filter h[-L_subfr..-1] must be set to */
+ /* zero. Q12 */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp,/* i : Last quantized pitch gain, Q14 */
+ Word16 gain_pit, /* i : Pitch gain, Q14 */
+ Word16 res2[], /* i : Long term prediction residual, Q0 */
+ Word16 code[], /* o : Innovative codebook, Q13 */
+ Word16 y[], /* o : filtered fixed codebook excitation */
+ /* Q12 */
+ Word16 **anap, /* o : Signs of the pulses */
+ enum Mode mode, /* i : coder mode */
+ Word16 subNr, /* i : subframe number */
+ Flag *pOverflow) /* o : Flag set when overflow occurs */
+{
+ Word16 index;
+ Word16 i;
+ Word16 temp;
+ Word16 pit_sharpTmp;
+
+ /* For MR74, the pre and post CB pitch sharpening is included in the
+ * codebook search routine, while for MR122 is it not.
+ */
+
+ if ((mode == MR475) || (mode == MR515))
+ {
+ /* MR475, MR515 */
+ *(*anap)++ =
+ code_2i40_9bits(
+ subNr,
+ x,
+ h,
+ T0,
+ pitch_sharp,
+ code,
+ y,
+ &index,
+ pOverflow);
+
+ *(*anap)++ = index; /* sign index */
+ }
+ else if (mode == MR59)
+ { /* MR59 */
+ *(*anap)++ =
+ code_2i40_11bits(
+ x,
+ h,
+ T0,
+ pitch_sharp,
+ code,
+ y,
+ &index,
+ pOverflow);
+
+ *(*anap)++ = index; /* sign index */
+ }
+ else if (mode == MR67)
+ { /* MR67 */
+ *(*anap)++ =
+ code_3i40_14bits(
+ x,
+ h,
+ T0,
+ pitch_sharp,
+ code,
+ y,
+ &index,
+ pOverflow);
+
+ *(*anap)++ = index; /* sign index */
+ }
+ else if ((mode == MR74) || (mode == MR795))
+ { /* MR74, MR795 */
+ *(*anap)++ =
+ code_4i40_17bits(
+ x,
+ h,
+ T0,
+ pitch_sharp,
+ code,
+ y,
+ &index,
+ pOverflow);
+
+ *(*anap)++ = index; /* sign index */
+ }
+ else if (mode == MR102)
+ { /* MR102 */
+ /*-------------------------------------------------------------*
+ * - include pitch contribution into impulse resp. h1[] *
+ *-------------------------------------------------------------*/
+ /* pit_sharpTmp = pit_sharp; */
+ /* if (pit_sharpTmp > 1.0) pit_sharpTmp = 1.0; */
+
+ pit_sharpTmp =
+ shl(
+ pitch_sharp,
+ 1,
+ pOverflow);
+
+ for (i = T0; i < L_SUBFR; i++)
+ {
+ temp =
+ mult(
+ h[i - T0],
+ pit_sharpTmp,
+ pOverflow);
+
+ h[i] =
+ add(
+ h[i],
+ temp,
+ pOverflow);
+ }
+
+ /*--------------------------------------------------------------*
+ * - Innovative codebook search (find index and gain) *
+ *--------------------------------------------------------------*/
+ code_8i40_31bits(
+ x,
+ res2,
+ h,
+ code,
+ y,
+ *anap,
+ pOverflow);
+
+ *anap += 7;
+
+ /*-------------------------------------------------------*
+ * - Add the pitch contribution to code[]. *
+ *-------------------------------------------------------*/
+ for (i = T0; i < L_SUBFR; i++)
+ {
+ temp =
+ mult(
+ code[i - T0],
+ pit_sharpTmp,
+ pOverflow);
+
+ code[i] =
+ add(
+ code[i],
+ temp,
+ pOverflow);
+ }
+ }
+ else
+ { /* MR122 */
+ /*-------------------------------------------------------------*
+ * - include pitch contribution into impulse resp. h1[] *
+ *-------------------------------------------------------------*/
+
+ /* pit_sharpTmp = gain_pit; */
+ /* if (pit_sharpTmp > 1.0) pit_sharpTmp = 1.0; */
+
+ pit_sharpTmp = shl(gain_pit, 1, pOverflow);
+
+ for (i = T0; i < L_SUBFR; i++)
+ {
+ temp = ((Word32)h[i - T0] * pit_sharpTmp) >> 15;
+ /*
+ mult(
+ h[i - T0],
+ ,
+ pOverflow);
+ */
+ h[i] =
+ add(
+ h[i],
+ temp,
+ pOverflow);
+ }
+ /*--------------------------------------------------------------*
+ * - Innovative codebook search (find index and gain) *
+ *--------------------------------------------------------------*/
+
+ code_10i40_35bits(
+ x,
+ res2,
+ h,
+ code,
+ y,
+ *anap,
+ pOverflow);
+
+ *anap += 10;
+
+ /*-------------------------------------------------------*
+ * - Add the pitch contribution to code[]. *
+ *-------------------------------------------------------*/
+ for (i = T0; i < L_SUBFR; i++)
+ {
+ temp =
+ mult(
+ code[i - T0],
+ pit_sharpTmp,
+ pOverflow);
+
+ code[i] =
+ add(
+ code[i],
+ temp,
+ pOverflow);
+ }
+ }
+
+}
diff --git a/media/codecs/amrnb/enc/src/cbsearch.h b/media/codecs/amrnb/enc/src/cbsearch.h
new file mode 100644
index 0000000..46d149b
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cbsearch.h
@@ -0,0 +1,136 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/dec_lag3.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the cbsearch.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef cbsearch_h
+#define cbsearch_h "$Id $"
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void cbsearch(Word16 x[], /* i : target vector, Q0 */
+ Word16 h[], /* i : impulse response of weighted synthesis */
+ /* filter h[-L_subfr..-1] must be set to */
+ /* zero. Q12 */
+ Word16 T0, /* i : Pitch lag */
+ Word16 pitch_sharp, /* i : Last quantized pitch gain, Q14 */
+ Word16 gain_pit,/* i : Pitch gain, Q14 */
+ Word16 res2[], /* i : Long term prediction residual, Q0 */
+ Word16 code[], /* o : Innovative codebook, Q13 */
+ Word16 y[], /* o : filtered fixed codebook excitation, Q12 */
+ Word16 **anap, /* o : Signs of the pulses */
+ enum Mode mode, /* i : coder mode */
+ Word16 subNr, /* i : subframe number */
+ Flag *pOverflow /* o : Flag set when overflow occurs */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CBSEARCH_H_ */
+
+
+
diff --git a/media/codecs/amrnb/enc/src/cl_ltp.cpp b/media/codecs/amrnb/enc/src/cl_ltp.cpp
new file mode 100644
index 0000000..525e57d
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cl_ltp.cpp
@@ -0,0 +1,763 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/cl_ltp.c
+ Funtions: cl_ltp_init
+ cl_ltp_reset
+ cl_ltp_exit
+ cl_ltp
+
+ Date: 06/07/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed into PV template and optimized.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Removed basic_op.h and oper_32b.h in the include section, and
+ added basicop_malloc.h.
+
+ Description: Fixed typecasting issue in TI C compiler.
+
+ Description: Added pOverflow parameter -- fixed minor template problem.
+
+ Description:
+ 1. Eliminated unused include file typedef.h.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated if-else checks for saturation
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains functions that perform closed-loop fractional pitch
+ search.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "cl_ltp.h"
+#include "basicop_malloc.h"
+#include "cnst.h"
+#include "convolve.h"
+#include "g_pitch.h"
+#include "pred_lt.h"
+#include "pitch_fr.h"
+#include "enc_lag3.h"
+#include "enc_lag6.h"
+#include "q_gain_p.h"
+#include "ton_stab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cl_ltp_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = Pointer to a pointer to a clLtpState structure
+
+ Outputs:
+ state points to the newly created clLtpState structure.
+
+ Returns:
+ This function returns 0 upon success and -1 upon failure.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Allocates state memory and initializes state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cl_ltp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int cl_ltp_init (clLtpState **state)
+{
+ clLtpState* s;
+
+ if (state == (clLtpState **) NULL){
+ fprintf(stderr, "cl_ltp_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (clLtpState *) malloc(sizeof(clLtpState))) == NULL){
+ fprintf(stderr, "cl_ltp_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ // init the sub state
+ if (Pitch_fr_init(&s->pitchSt)) {
+ cl_ltp_exit(&s);
+ return -1;
+ }
+
+ cl_ltp_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 cl_ltp_init(clLtpState **state)
+{
+ clLtpState* s;
+
+ if (state == (clLtpState **) NULL)
+ {
+ /*fprint(stderr, "cl_ltp_init: invalid parameter\n");*/
+ return(-1);
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (clLtpState *) malloc(sizeof(clLtpState))) == NULL)
+ {
+ /*fprint(stderr, "cl_ltp_init: can not malloc state structure\n");*/
+ return(-1);
+ }
+
+ /* init the sub state */
+ if (Pitch_fr_init(&s->pitchSt))
+ {
+ cl_ltp_exit(&s);
+ return(-1);
+ }
+
+ cl_ltp_reset(s);
+
+ *state = s;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cl_ltp_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to the clLtpState structure to be reset
+
+ Outputs:
+ The state structure pointed to by clLtpState *state is reset.
+
+ Returns:
+ The function returns int 0 if successful, -1 otherwise.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Initializes state memory to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cl_ltp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+ ------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int cl_ltp_reset (clLtpState *state)
+{
+ if (state == (clLtpState *) NULL){
+ fprintf(stderr, "cl_ltp_reset: invalid parameter\n");
+ return -1;
+ }
+
+ // Reset pitch search states
+ Pitch_fr_reset (state->pitchSt);
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 cl_ltp_reset(clLtpState *state)
+{
+ if (state == (clLtpState *) NULL)
+ {
+ /*fprint(stderr, "cl_ltp_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ /* Reset pitch search states */
+ Pitch_fr_reset(state->pitchSt);
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cl_ltp_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ clLtpState **state = Reference to the state object to be freed.
+
+ Outputs:
+ The memory used by the structure which is pointed to by 'state'
+ is freed.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The memory used for state memory is freed
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cl_ltp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void cl_ltp_exit (clLtpState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ // dealloc members
+ Pitch_fr_exit(&(*state)->pitchSt);
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void cl_ltp_exit(clLtpState **state)
+{
+ if (state == NULL || *state == NULL)
+ {
+ return;
+ }
+
+ /* dealloc members */
+ Pitch_fr_exit(&(*state)->pitchSt);
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cl_ltp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ clSt = pointer to the clLtpState struct
+ tonSt = pointer to the tonStabState structure
+ mode = codec mode value, of type enum Mode
+ frameOffset = offset to subframe (Word16)
+ T_op = pointer to buffer of open loop pitch lags (Word16)
+ h1 = pointer to impulse response vector (Word16)
+ exc = pointer to excitation vector (Word16)
+ res2 = pointer to long term prediction residual (Word16)
+ xn = pointer to target vector for pitch search (Word16)
+ lsp_flag = LSP resonance flag (Word16)
+
+ Outputs:
+ clSt = pointer to the clLtpState struct
+ tonSt = pointer to the tonStabState structure
+ exc = pointer to excitation vector (Word16)
+ res2 = pointer to long term prediction residual (Word16)
+ xn2 = pointer to target vector for codebook search (Word16)
+ yl = pointer to buffer of filtered adaptive excitation (Word16)
+ T0 = pointer to pitch delay (integer part) (Word16)
+ T0_frac = pointer to pitch delay (fractional part) (Word16)
+ gain_pit = pointer to pitch gain (Word16)
+ g_coeff = pointer to array of correlations between xn, y1, & y2 (Word16)
+ anap = pointer to pointer to analysis parameters (Word16)
+ gp_limit = pointer to the pitch gain limit (Word16)
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs closed-loop fractional pitch search.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cl_ltp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE FOR cl_ltp
+
+int cl_ltp (
+ clLtpState *clSt, // i/o : State struct
+ tonStabState *tonSt, // i/o : State struct
+ enum Mode mode, // i : coder mode
+ Word16 frameOffset, // i : Offset to subframe
+ Word16 T_op[], // i : Open loop pitch lags
+ Word16 *h1, // i : Impulse response vector Q12
+ Word16 *exc, // i/o : Excitation vector Q0
+ Word16 res2[], // i/o : Long term prediction residual Q0
+ Word16 xn[], // i : Target vector for pitch search Q0
+ Word16 lsp_flag, // i : LSP resonance flag
+ Word16 xn2[], // o : Target vector for codebook search Q0
+ Word16 y1[], // o : Filtered adaptive excitation Q0
+ Word16 *T0, // o : Pitch delay (integer part)
+ Word16 *T0_frac, // o : Pitch delay (fractional part)
+ Word16 *gain_pit, // o : Pitch gain Q14
+ Word16 g_coeff[], // o : Correlations between xn, y1, & y2
+ Word16 **anap, // o : Analysis parameters
+ Word16 *gp_limit // o : pitch gain limit
+)
+{
+ Word16 i;
+ Word16 index;
+ Word32 L_temp; // temporarily variable
+ Word16 resu3; // flag for upsample resolution
+ Word16 gpc_flag;
+
+ *----------------------------------------------------------------------*
+ * Closed-loop fractional pitch search *
+ *----------------------------------------------------------------------*
+ *T0 = Pitch_fr(clSt->pitchSt,
+ mode, T_op, exc, xn, h1,
+ L_SUBFR, frameOffset,
+ T0_frac, &resu3, &index);
+
+ *(*anap)++ = index;
+
+ *-----------------------------------------------------------------*
+ * - find unity gain pitch excitation (adapitve codebook entry) *
+ * with fractional interpolation. *
+ * - find filtered pitch exc. y1[]=exc[] convolve with h1[]) *
+ * - compute pitch gain and limit between 0 and 1.2 *
+ * - update target vector for codebook search *
+ * - find LTP residual. *
+ *-----------------------------------------------------------------*
+
+ Pred_lt_3or6(exc, *T0, *T0_frac, L_SUBFR, resu3);
+
+ Convolve(exc, h1, y1, L_SUBFR);
+
+ // gain_pit is Q14 for all modes
+ *gain_pit = G_pitch(mode, xn, y1, g_coeff, L_SUBFR);
+
+
+ // check if the pitch gain should be limit due to resonance in LPC filter
+ gpc_flag = 0;
+ *gp_limit = MAX_16;
+ if ((lsp_flag != 0) &&
+ (sub(*gain_pit, GP_CLIP) > 0))
+ {
+ gpc_flag = check_gp_clipping(tonSt, *gain_pit);
+ }
+
+ // special for the MR475, MR515 mode; limit the gain to 0.85 to
+ // cope with bit errors in the decoder in a better way.
+ if ((sub (mode, MR475) == 0) || (sub (mode, MR515) == 0)) {
+ if ( sub (*gain_pit, 13926) > 0) {
+ *gain_pit = 13926; // 0.85 in Q14
+ }
+
+ if (gpc_flag != 0) {
+ *gp_limit = GP_CLIP;
+ }
+ }
+ else
+ {
+ if (gpc_flag != 0)
+ {
+ *gp_limit = GP_CLIP;
+ *gain_pit = GP_CLIP;
+ }
+ // For MR122, gain_pit is quantized here and not in gainQuant
+ if (sub(mode, MR122)==0)
+ {
+ *(*anap)++ = q_gain_pitch(MR122, *gp_limit, gain_pit,
+ NULL, NULL);
+ }
+ }
+
+ // update target vector und evaluate LTP residual
+ for (i = 0; i < L_SUBFR; i++) {
+ L_temp = L_mult(y1[i], *gain_pit);
+ L_temp = L_shl(L_temp, 1);
+ xn2[i] = sub(xn[i], extract_h(L_temp));
+
+ L_temp = L_mult(exc[i], *gain_pit);
+ L_temp = L_shl(L_temp, 1);
+ res2[i] = sub(res2[i], extract_h(L_temp));
+ }
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void cl_ltp(
+ clLtpState *clSt, /* i/o : State struct */
+ tonStabState *tonSt, /* i/o : State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 frameOffset, /* i : Offset to subframe */
+ Word16 T_op[], /* i : Open loop pitch lags */
+ Word16 *h1, /* i : Impulse response vector Q12 */
+ Word16 *exc, /* i/o : Excitation vector Q0 */
+ Word16 res2[], /* i/o : Long term prediction residual Q0 */
+ Word16 xn[], /* i : Target vector for pitch search Q0 */
+ Word16 lsp_flag, /* i : LSP resonance flag */
+ Word16 xn2[], /* o : Target vector for codebook search Q0 */
+ Word16 yl[], /* o : Filtered adaptive excitation Q0 */
+ Word16 *T0, /* o : Pitch delay (integer part) */
+ Word16 *T0_frac, /* o : Pitch delay (fractional part) */
+ Word16 *gain_pit, /* o : Pitch gain Q14 */
+ Word16 g_coeff[], /* o : Correlations between xn, y1, & y2 */
+ Word16 **anap, /* o : Analysis parameters */
+ Word16 *gp_limit, /* o : pitch gain limit */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 i;
+ Word16 index;
+ Word32 L_temp; /* temporarily variable */
+ Word16 resu3; /* flag for upsample resolution */
+ Word16 gpc_flag;
+
+ Word16 temp;
+ Word16 *p_exc;
+ Word16 *p_xn;
+ Word16 *p_xn2;
+ Word16 *p_yl;
+
+ /*----------------------------------------------------------------------*
+ * Closed-loop fractional pitch search *
+ *----------------------------------------------------------------------*/
+ *T0 =
+ Pitch_fr(
+ clSt->pitchSt,
+ mode,
+ T_op,
+ exc,
+ xn,
+ h1,
+ L_SUBFR,
+ frameOffset,
+ T0_frac,
+ &resu3,
+ &index,
+ pOverflow);
+
+ *(*anap)++ = index;
+
+ /*-----------------------------------------------------------------*
+ * - find unity gain pitch excitation (adapitve codebook entry) *
+ * with fractional interpolation. *
+ * - find filtered pitch exc. y1[]=exc[] convolve with h1[]) *
+ * - compute pitch gain and limit between 0 and 1.2 *
+ * - update target vector for codebook search *
+ * - find LTP residual. *
+ *-----------------------------------------------------------------*/
+
+ Pred_lt_3or6(
+ exc,
+ *T0,
+ *T0_frac,
+ L_SUBFR,
+ resu3,
+ pOverflow);
+
+ Convolve(exc, h1, yl, L_SUBFR);
+
+ /* gain_pit is Q14 for all modes */
+ *gain_pit =
+ G_pitch(
+ mode,
+ xn,
+ yl,
+ g_coeff,
+ L_SUBFR,
+ pOverflow);
+
+
+ /* check if the pitch gain should be limit due to resonance in LPC filter */
+ gpc_flag = 0;
+ *gp_limit = MAX_16;
+
+ if ((lsp_flag != 0) && ((Word32)(*gain_pit) > GP_CLIP))
+ {
+ gpc_flag = check_gp_clipping(tonSt, *gain_pit, pOverflow);
+ }
+
+ /* special for the MR475, MR515 mode; limit the gain to 0.85 to */
+ /* cope with bit errors in the decoder in a better way. */
+
+ if ((mode == MR475) || (mode == MR515))
+ {
+ *gain_pit = ((Word32) * gain_pit > 13926) ? 13926 : *gain_pit;
+
+ if (gpc_flag != 0)
+ {
+ *gp_limit = GP_CLIP;
+ }
+ }
+ else
+ {
+ if (gpc_flag != 0)
+ {
+ *gp_limit = GP_CLIP;
+ *gain_pit = GP_CLIP;
+ }
+ /* For MR122, gain_pit is quantized here and not in gainQuant */
+ if (mode == MR122)
+ {
+ *(*anap)++ =
+ q_gain_pitch(
+ MR122,
+ *gp_limit,
+ gain_pit,
+ NULL,
+ NULL,
+ pOverflow);
+ }
+ }
+
+
+ p_exc = &exc[0];
+ p_xn = &xn[0];
+ p_xn2 = &xn2[0];
+ p_yl = &yl[0];
+
+ temp = *gain_pit;
+
+ /* update target vector und evaluate LTP residual */
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ L_temp = ((Word32) * (p_yl++) * temp) >> 14;
+ *(p_xn2++) = *(p_xn++) - (Word16)L_temp;
+
+ L_temp = ((Word32) * (p_exc++) * temp) >> 14;
+ res2[i] -= (Word16)L_temp;
+ }
+
+}
diff --git a/media/codecs/amrnb/enc/src/cl_ltp.h b/media/codecs/amrnb/enc/src/cl_ltp.h
new file mode 100644
index 0000000..3e9b587
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cl_ltp.h
@@ -0,0 +1,163 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/cl_ltp.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the cl_ltp.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef cl_ltp_h
+#define cl_ltp_h "$Id $"
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "pitch_fr.h"
+#include "ton_stab.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /* state variable */
+ typedef struct
+ {
+ Pitch_frState *pitchSt;
+ } clLtpState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 cl_ltp_init(clLtpState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to cl_ltp in each call.
+ returns 0 on success
+ */
+
+ Word16 cl_ltp_reset(clLtpState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void cl_ltp_exit(clLtpState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void cl_ltp(
+ clLtpState *clSt, /* i/o : State struct */
+ tonStabState *tonSt, /* i/o : State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 frameOffset, /* i : Offset to subframe */
+ Word16 T_op[], /* i : Open loop pitch lags */
+ Word16 *h1, /* i : Impulse response vector Q12 */
+ Word16 *exc, /* i/o : Excitation vector Q0 */
+ Word16 res2[], /* i/o : Long term prediction residual Q0 */
+ Word16 xn[], /* i : Target vector for pitch search Q0 */
+ Word16 lsp_flag, /* i : LSP resonance flag */
+ Word16 xn2[], /* o : Target vector for codebook search Q0 */
+ Word16 y1[], /* o : Filtered adaptive excitation Q0 */
+ Word16 *T0, /* o : Pitch delay (integer part) */
+ Word16 *T0_frac, /* o : Pitch delay (fractional part) */
+ Word16 *gain_pit, /* o : Pitch gain Q14 */
+ Word16 g_coeff[], /* o : Correlations between xn, y1, & y2 */
+ Word16 **anap, /* o : Analysis parameters */
+ Word16 *gp_limit, /* o : pitch gain limit */
+ Flag *pOverflow /* o : overflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CL_LTP_H_ */
+
diff --git a/media/codecs/amrnb/enc/src/cod_amr.cpp b/media/codecs/amrnb/enc/src/cod_amr.cpp
new file mode 100644
index 0000000..8468131
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cod_amr.cpp
@@ -0,0 +1,1608 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/cod_amr.c
+ Funtions: cod_amr_init
+ cod_amr_reset
+ cod_amr_exit
+ cod_amr_first
+ cod_amr
+
+ Date: 06/09/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Made changes based on comments from the review meeting.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Added initialization of the overflow flag in cod_amr_init()
+ and in cod_amr_reset(). This overflow flag is now part of
+ the cod_amrState structure.
+
+ Description: Cleaned up INCLUDES. removed inclusion of basic_op.h and repeat
+ inclusion of copy.h
+
+ Description: Updated function call to dtx_enc
+
+ Description: For cod_amr_first() and cod_amr()
+ 1. Replaced copy() function with memcpy()
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ These functions comprise the main encoder routine operating on a frame basis.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <string.h>
+
+#include "cod_amr.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "copy.h"
+#include "qua_gain.h"
+#include "lpc.h"
+#include "lsp.h"
+#include "pre_big.h"
+#include "ol_ltp.h"
+#include "p_ol_wgh.h"
+#include "spreproc.h"
+#include "cl_ltp.h"
+#include "pred_lt.h"
+#include "spstproc.h"
+#include "cbsearch.h"
+#include "gain_q.h"
+#include "convolve.h"
+#include "ton_stab.h"
+#include "vad.h"
+#include "dtx_enc.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* Spectral expansion factors */
+
+static const Word16 gamma1[M] =
+{
+ 30802, 28954, 27217, 25584, 24049,
+ 22606, 21250, 19975, 18777, 17650
+};
+
+/* gamma1 differs for the 12k2 coder */
+static const Word16 gamma1_12k2[M] =
+{
+ 29491, 26542, 23888, 21499, 19349,
+ 17414, 15672, 14105, 12694, 11425
+};
+
+static const Word16 gamma2[M] =
+{
+ 19661, 11797, 7078, 4247, 2548,
+ 1529, 917, 550, 330, 198
+};
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cod_amr_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer to a structure of type cod_amrState
+
+ Outputs:
+ Structure pointed to by the pointer pointed to by state is
+ initialized to its reset value
+ state points to the allocated memory
+
+ Returns:
+ Returns 0 if memory was successfully initialized,
+ otherwise returns -1.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function allocates memory and initializes state variables.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int cod_amr_init (cod_amrState **state, Flag dtx)
+{
+ cod_amrState* s;
+
+ if (state == (cod_amrState **) NULL){
+ fprintf(stderr, "cod_amr_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (cod_amrState *) malloc(sizeof(cod_amrState))) == NULL){
+ fprintf(stderr, "cod_amr_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ s->lpcSt = NULL;
+ s->lspSt = NULL;
+ s->clLtpSt = NULL;
+ s->gainQuantSt = NULL;
+ s->pitchOLWghtSt = NULL;
+ s->tonStabSt = NULL;
+ s->vadSt = NULL;
+ s->dtx_encSt = NULL;
+ s->dtx = dtx;
+
+ // Init sub states
+ if (cl_ltp_init(&s->clLtpSt) ||
+ lsp_init(&s->lspSt) ||
+ gainQuant_init(&s->gainQuantSt) ||
+ p_ol_wgh_init(&s->pitchOLWghtSt) ||
+ ton_stab_init(&s->tonStabSt) ||
+#ifndef VAD2
+ vad1_init(&s->vadSt) ||
+#else
+ vad2_init(&s->vadSt) ||
+#endif
+ dtx_enc_init(&s->dtx_encSt) ||
+ lpc_init(&s->lpcSt)) {
+ cod_amr_exit(&s);
+ return -1;
+ }
+
+ cod_amr_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 cod_amr_init(cod_amrState **state, Flag dtx)
+{
+ cod_amrState* s;
+
+ if (state == (cod_amrState **) NULL)
+ {
+ /* fprint(stderr, "cod_amr_init: invalid parameter\n"); */
+ return(-1);
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (cod_amrState *) malloc(sizeof(cod_amrState))) == NULL)
+ {
+ /* fprint(stderr, "cod_amr_init:
+ can not malloc state structure\n"); */
+ return(-1);
+ }
+
+ s->lpcSt = NULL;
+ s->lspSt = NULL;
+ s->clLtpSt = NULL;
+ s->gainQuantSt = NULL;
+ s->pitchOLWghtSt = NULL;
+ s->tonStabSt = NULL;
+ s->vadSt = NULL;
+ s->dtx_encSt = NULL;
+ s->dtx = dtx;
+
+ /* Initialize overflow Flag */
+
+ s->overflow = 0;
+
+
+ /* Init sub states */
+ if (cl_ltp_init(&s->clLtpSt) ||
+ lsp_init(&s->lspSt) ||
+ gainQuant_init(&s->gainQuantSt) ||
+ p_ol_wgh_init(&s->pitchOLWghtSt) ||
+ ton_stab_init(&s->tonStabSt) ||
+#ifndef VAD2
+ vad1_init(&s->vadSt) ||
+#else
+ vad2_init(&s->vadSt) ||
+#endif
+ dtx_enc_init(&s->dtx_encSt) ||
+ lpc_init(&s->lpcSt))
+ {
+ cod_amr_exit(&s);
+ return(-1);
+ }
+
+ cod_amr_reset(s);
+
+ *state = s;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cod_amr_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a structure of type cod_amrState
+
+ Outputs:
+ Structure pointed to by state is initialized to initial values.
+
+ Returns:
+ Returns 0 if memory was successfully initialized,
+ otherwise returns -1.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets the state memory for cod_amr.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int cod_amr_reset (cod_amrState *st)
+{
+ Word16 i;
+
+ if (st == (cod_amrState *) NULL){
+ fprintf(stderr, "cod_amr_reset: invalid parameter\n");
+ return -1;
+ }
+
+ *-----------------------------------------------------------------------*
+ * Initialize pointers to speech vector. *
+ *-----------------------------------------------------------------------*
+
+ st->new_speech = st->old_speech + L_TOTAL - L_FRAME; // New speech
+
+ st->speech = st->new_speech - L_NEXT; // Present frame
+
+ st->p_window = st->old_speech + L_TOTAL - L_WINDOW; // For LPC window
+ st->p_window_12k2 = st->p_window - L_NEXT; // EFR LPC window: no lookahead
+
+ // Initialize static pointers
+
+ st->wsp = st->old_wsp + PIT_MAX;
+ st->exc = st->old_exc + PIT_MAX + L_INTERPOL;
+ st->zero = st->ai_zero + MP1;
+ st->error = st->mem_err + M;
+ st->h1 = &st->hvec[L_SUBFR];
+
+ // Static vectors to zero
+
+ Set_zero(st->old_speech, L_TOTAL);
+ Set_zero(st->old_exc, PIT_MAX + L_INTERPOL);
+ Set_zero(st->old_wsp, PIT_MAX);
+ Set_zero(st->mem_syn, M);
+ Set_zero(st->mem_w, M);
+ Set_zero(st->mem_w0, M);
+ Set_zero(st->mem_err, M);
+ Set_zero(st->zero, L_SUBFR);
+ Set_zero(st->hvec, L_SUBFR); // set to zero "h1[-L_SUBFR..-1]"
+
+ // OL LTP states
+ for (i = 0; i < 5; i++)
+ {
+ st->old_lags[i] = 40;
+ }
+
+ // Reset lpc states
+ lpc_reset(st->lpcSt);
+
+ // Reset lsp states
+ lsp_reset(st->lspSt);
+
+ // Reset clLtp states
+ cl_ltp_reset(st->clLtpSt);
+
+ gainQuant_reset(st->gainQuantSt);
+
+ p_ol_wgh_reset(st->pitchOLWghtSt);
+
+ ton_stab_reset(st->tonStabSt);
+
+#ifndef VAD2
+ vad1_reset(st->vadSt);
+#else
+ vad2_reset(st->vadSt);
+#endif
+
+ dtx_enc_reset(st->dtx_encSt);
+
+ st->sharp = SHARPMIN;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 cod_amr_reset(cod_amrState *st)
+{
+ Word16 i;
+
+ if (st == (cod_amrState *) NULL)
+ {
+ /* fprint(stderr, "cod_amr_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ /*-----------------------------------------------------------------------*
+ * Initialize pointers to speech vector. *
+ *-----------------------------------------------------------------------*/
+
+ st->new_speech = st->old_speech + L_TOTAL - L_FRAME; /* New speech */
+
+ st->speech = st->new_speech - L_NEXT; /* Present frame */
+
+ st->p_window = st->old_speech + L_TOTAL - L_WINDOW; /* For LPC window */
+ st->p_window_12k2 = st->p_window - L_NEXT; /* EFR LPC window: no lookahead */
+
+ /* Initialize static pointers */
+
+ st->wsp = st->old_wsp + PIT_MAX;
+ st->exc = st->old_exc + PIT_MAX + L_INTERPOL;
+ st->zero = st->ai_zero + MP1;
+ st->error = st->mem_err + M;
+ st->h1 = &st->hvec[L_SUBFR];
+
+ /* Initialize overflow Flag */
+
+ st->overflow = 0;
+
+ /* Static vectors to zero */
+ memset(st->old_speech, 0, sizeof(Word16)*L_TOTAL);
+ memset(st->old_exc, 0, sizeof(Word16)*(PIT_MAX + L_INTERPOL));
+ memset(st->old_wsp, 0, sizeof(Word16)*PIT_MAX);
+ memset(st->mem_syn, 0, sizeof(Word16)*M);
+ memset(st->mem_w, 0, sizeof(Word16)*M);
+ memset(st->mem_w0, 0, sizeof(Word16)*M);
+ memset(st->mem_err, 0, sizeof(Word16)*M);
+ memset(st->zero, 0, sizeof(Word16)*L_SUBFR);
+ memset(st->hvec, 0, sizeof(Word16)*L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */
+
+ /* OL LTP states */
+ for (i = 0; i < 5; i++)
+ {
+ st->old_lags[i] = 40;
+ }
+
+ /* Reset lpc states */
+ lpc_reset(st->lpcSt);
+
+ /* Reset lsp states */
+ lsp_reset(st->lspSt);
+
+ /* Reset clLtp states */
+ cl_ltp_reset(st->clLtpSt);
+
+ gainQuant_reset(st->gainQuantSt);
+
+ p_ol_wgh_reset(st->pitchOLWghtSt);
+
+ ton_stab_reset(st->tonStabSt);
+
+#ifndef VAD2
+ vad1_reset(st->vadSt);
+#else
+ vad2_reset(st->vadSt);
+#endif
+
+ dtx_enc_reset(st->dtx_encSt);
+
+ st->sharp = SHARPMIN;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cod_amr_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer to a structure of type cod_amrState
+
+ Outputs:
+ state points to a NULL address
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function frees the memory used for state memory.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void cod_amr_exit (cod_amrState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ // dealloc members
+ lpc_exit(&(*state)->lpcSt);
+ lsp_exit(&(*state)->lspSt);
+ gainQuant_exit(&(*state)->gainQuantSt);
+ cl_ltp_exit(&(*state)->clLtpSt);
+ p_ol_wgh_exit(&(*state)->pitchOLWghtSt);
+ ton_stab_exit(&(*state)->tonStabSt);
+#ifndef VAD2
+ vad1_exit(&(*state)->vadSt);
+#else
+ vad2_exit(&(*state)->vadSt);
+#endif
+ dtx_enc_exit(&(*state)->dtx_encSt);
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void cod_amr_exit(cod_amrState **state)
+{
+ if (state == NULL || *state == NULL)
+ {
+ return;
+ }
+
+ /* dealloc members */
+ lpc_exit(&(*state)->lpcSt);
+ lsp_exit(&(*state)->lspSt);
+ gainQuant_exit(&(*state)->gainQuantSt);
+ cl_ltp_exit(&(*state)->clLtpSt);
+ p_ol_wgh_exit(&(*state)->pitchOLWghtSt);
+ ton_stab_exit(&(*state)->tonStabSt);
+#ifndef VAD2
+ vad1_exit(&(*state)->vadSt);
+#else
+ vad2_exit(&(*state)->vadSt);
+#endif
+ dtx_enc_exit(&(*state)->dtx_encSt);
+
+ /* deallocate memory */
+ free(*state); // BX
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cod_amr_first
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type cod_amrState
+ new_speech = pointer to buffer of length L_FRAME that contains
+ the speech input (Word16)
+
+ Outputs:
+ The structure of type cod_amrState pointed to by st is updated.
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function copes with look-ahead and calls cod_amr.
+ No input argument are passed to this function. However, before
+ calling this function, 40 new speech data should be copied to the
+ vector new_speech[]. This is a global pointer which is declared in
+ this file (it points to the end of speech buffer minus 200).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int cod_amr_first(cod_amrState *st, // i/o : State struct
+ Word16 new_speech[]) // i : speech input (L_FRAME)
+{
+ Copy(new_speech,&st->new_speech[-L_NEXT], L_NEXT);
+ // Copy(new_speech,st->new_speech,L_FRAME);
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 cod_amr_first(cod_amrState *st, /* i/o : State struct */
+ Word16 new_speech[]) /* i : speech input (L_FRAME) */
+{
+
+ memcpy(&st->new_speech[-L_NEXT], new_speech, L_NEXT*sizeof(Word16));
+
+ /* Copy(new_speech,st->new_speech,L_FRAME); */
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cod_amr
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type cod_amrState
+ mode = AMR mode of type enum Mode
+ new_speech = pointer to buffer of length L_FRAME that contains
+ the speech input of type Word16
+ ana = pointer to the analysis parameters of type Word16
+ usedMode = pointer to the used mode of type enum Mode
+ synth = pointer to a buffer containing the local synthesis speech of
+ type Word16
+
+ Outputs:
+ The structure of type cod_amrState pointed to by st is updated.
+ The analysis parameter buffer pointed to by ana is updated.
+ The value pointed to by usedMode is updated.
+ The local synthesis speech buffer pointed to by synth is updated.
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function is the main encoder routine. It is called every 20 ms speech
+ frame, operating on the newly read 160 speech samples. It performs the
+ principle encoding functions to produce the set of encoded parameters
+ which include the LSP, adaptive codebook, and fixed codebook
+ quantization indices (addresses and gains).
+
+ Before calling this function, 160 new speech data should be copied to the
+ vector new_speech[]. This is a global pointer which is declared in
+ this file (it points to the end of speech buffer minus 160).
+
+ The outputs of the function are:
+ ana[]: vector of analysis parameters.
+ synth[]: Local synthesis speech (for debugging purposes)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int cod_amr(
+ cod_amrState *st, // i/o : State struct
+ enum Mode mode, // i : AMR mode
+ Word16 new_speech[], // i : speech input (L_FRAME)
+ Word16 ana[], // o : Analysis parameters
+ enum Mode *usedMode, // o : used mode
+ Word16 synth[] // o : Local synthesis
+)
+{
+ // LPC coefficients
+ Word16 A_t[(MP1) * 4]; // A(z) unquantized for the 4 subframes
+ Word16 Aq_t[(MP1) * 4]; // A(z) quantized for the 4 subframes
+ Word16 *A, *Aq; // Pointer on A_t and Aq_t
+ Word16 lsp_new[M];
+
+ // Other vectors
+ Word16 xn[L_SUBFR]; // Target vector for pitch search
+ Word16 xn2[L_SUBFR]; // Target vector for codebook search
+ Word16 code[L_SUBFR]; // Fixed codebook excitation
+ Word16 y1[L_SUBFR]; // Filtered adaptive excitation
+ Word16 y2[L_SUBFR]; // Filtered fixed codebook excitation
+ Word16 gCoeff[6]; // Correlations between xn, y1, & y2:
+ Word16 res[L_SUBFR]; // Short term (LPC) prediction residual
+ Word16 res2[L_SUBFR]; // Long term (LTP) prediction residual
+
+ // Vector and scalars needed for the MR475
+ Word16 xn_sf0[L_SUBFR]; // Target vector for pitch search
+ Word16 y2_sf0[L_SUBFR]; // Filtered codebook innovation
+ Word16 code_sf0[L_SUBFR]; // Fixed codebook excitation
+ Word16 h1_sf0[L_SUBFR]; // The impulse response of sf0
+ Word16 mem_syn_save[M]; // Filter memory
+ Word16 mem_w0_save[M]; // Filter memory
+ Word16 mem_err_save[M]; // Filter memory
+ Word16 sharp_save; // Sharpening
+ Word16 evenSubfr; // Even subframe indicator
+ Word16 T0_sf0 = 0; // Integer pitch lag of sf0
+ Word16 T0_frac_sf0 = 0; // Fractional pitch lag of sf0
+ Word16 i_subfr_sf0 = 0; // Position in exc[] for sf0
+ Word16 gain_pit_sf0; // Quantized pitch gain for sf0
+ Word16 gain_code_sf0; // Quantized codebook gain for sf0
+
+ // Scalars
+ Word16 i_subfr, subfrNr;
+ Word16 T_op[L_FRAME/L_FRAME_BY2];
+ Word16 T0, T0_frac;
+ Word16 gain_pit, gain_code;
+
+ // Flags
+ Word16 lsp_flag = 0; // indicates resonance in LPC filter
+ Word16 gp_limit; // pitch gain limit value
+ Word16 vad_flag; // VAD decision flag
+ Word16 compute_sid_flag; // SID analysis flag
+
+ Copy(new_speech, st->new_speech, L_FRAME);
+
+ *usedMode = mode;
+
+ // DTX processing
+ if (st->dtx)
+ { // no test() call since this if is only in simulation env
+ // Find VAD decision
+
+#ifdef VAD2
+ vad_flag = vad2 (st->new_speech, st->vadSt);
+ vad_flag = vad2 (st->new_speech+80, st->vadSt) || vad_flag;
+#else
+ vad_flag = vad1(st->vadSt, st->new_speech);
+#endif
+
+ // NB! usedMode may change here
+ compute_sid_flag = tx_dtx_handler(st->dtx_encSt,
+ vad_flag,
+ usedMode);
+ }
+ else
+ {
+ compute_sid_flag = 0;
+ }
+
+ *------------------------------------------------------------------------*
+ * - Perform LPC analysis: *
+ * * autocorrelation + lag windowing *
+ * * Levinson-durbin algorithm to find a[] *
+ * * convert a[] to lsp[] *
+ * * quantize and code the LSPs *
+ * * find the interpolated LSPs and convert to a[] for all *
+ * subframes (both quantized and unquantized) *
+ *------------------------------------------------------------------------*
+
+ // LP analysis
+ lpc(st->lpcSt, mode, st->p_window, st->p_window_12k2, A_t);
+
+
+ // From A(z) to lsp. LSP quantization and interpolation
+ lsp(st->lspSt, mode, *usedMode, A_t, Aq_t, lsp_new, &ana);
+
+
+ // Buffer lsp's and energy
+ dtx_buffer(st->dtx_encSt,
+ lsp_new,
+ st->new_speech);
+
+ // Check if in DTX mode
+ if (sub(*usedMode, MRDTX) == 0)
+ {
+ dtx_enc(st->dtx_encSt,
+ compute_sid_flag,
+ st->lspSt->qSt,
+ st->gainQuantSt->gc_predSt,
+ &ana);
+
+ Set_zero(st->old_exc, PIT_MAX + L_INTERPOL);
+ Set_zero(st->mem_w0, M);
+ Set_zero(st->mem_err, M);
+ Set_zero(st->zero, L_SUBFR);
+ Set_zero(st->hvec, L_SUBFR); // set to zero "h1[-L_SUBFR..-1]"
+ // Reset lsp states
+ lsp_reset(st->lspSt);
+ Copy(lsp_new, st->lspSt->lsp_old, M);
+ Copy(lsp_new, st->lspSt->lsp_old_q, M);
+
+ // Reset clLtp states
+ cl_ltp_reset(st->clLtpSt);
+ st->sharp = SHARPMIN;
+ }
+ else
+ {
+ // check resonance in the filter
+ lsp_flag = check_lsp(st->tonStabSt, st->lspSt->lsp_old);
+ }
+
+ *----------------------------------------------------------------------*
+ * - Find the weighted input speech w_sp[] for the whole speech frame *
+ * - Find the open-loop pitch delay for first 2 subframes *
+ * - Set the range for searching closed-loop pitch in 1st subframe *
+ * - Find the open-loop pitch delay for last 2 subframes *
+ *----------------------------------------------------------------------*
+
+#ifdef VAD2
+ if (st->dtx)
+ { // no test() call since this if is only in simulation env
+ st->vadSt->L_Rmax = 0;
+ st->vadSt->L_R0 = 0;
+ }
+#endif
+ for(subfrNr = 0, i_subfr = 0;
+ subfrNr < L_FRAME/L_FRAME_BY2;
+ subfrNr++, i_subfr += L_FRAME_BY2)
+ {
+ // Pre-processing on 80 samples
+ pre_big(mode, gamma1, gamma1_12k2, gamma2, A_t, i_subfr, st->speech,
+ st->mem_w, st->wsp);
+
+ if ((sub(mode, MR475) != 0) && (sub(mode, MR515) != 0))
+ {
+ // Find open loop pitch lag for two subframes
+ ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[i_subfr],
+ &T_op[subfrNr], st->old_lags, st->ol_gain_flg, subfrNr,
+ st->dtx);
+ }
+ }
+
+ if ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0))
+ {
+ // Find open loop pitch lag for ONE FRAME ONLY
+ // search on 160 samples
+
+ ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[0], &T_op[0],
+ st->old_lags, st->ol_gain_flg, 1, st->dtx);
+ T_op[1] = T_op[0];
+ }
+
+#ifdef VAD2
+ if (st->dtx)
+ { // no test() call since this if is only in simulation env
+ LTP_flag_update(st->vadSt, mode);
+ }
+#endif
+
+#ifndef VAD2
+ // run VAD pitch detection
+ if (st->dtx)
+ { // no test() call since this if is only in simulation env
+ vad_pitch_detection(st->vadSt, T_op);
+ }
+#endif
+
+ if (sub(*usedMode, MRDTX) == 0)
+ {
+ goto the_end;
+ }
+
+ *------------------------------------------------------------------------*
+ * Loop for every subframe in the analysis frame *
+ *------------------------------------------------------------------------*
+ * To find the pitch and innovation parameters. The subframe size is *
+ * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. *
+ * - find the weighted LPC coefficients *
+ * - find the LPC residual signal res[] *
+ * - compute the target signal for pitch search *
+ * - compute impulse response of weighted synthesis filter (h1[]) *
+ * - find the closed-loop pitch parameters *
+ * - encode the pitch dealy *
+ * - update the impulse response h1[] by including fixed-gain pitch *
+ * - find target vector for codebook search *
+ * - codebook search *
+ * - encode codebook address *
+ * - VQ of pitch and codebook gains *
+ * - find synthesis speech *
+ * - update states of weighting filter *
+ *------------------------------------------------------------------------*
+
+ A = A_t; // pointer to interpolated LPC parameters
+ Aq = Aq_t; // pointer to interpolated quantized LPC parameters
+
+ evenSubfr = 0;
+ subfrNr = -1;
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ subfrNr = add(subfrNr, 1);
+ evenSubfr = sub(1, evenSubfr);
+
+ // Save states for the MR475 mode
+ if ((evenSubfr != 0) && (sub(*usedMode, MR475) == 0))
+ {
+ Copy(st->mem_syn, mem_syn_save, M);
+ Copy(st->mem_w0, mem_w0_save, M);
+ Copy(st->mem_err, mem_err_save, M);
+ sharp_save = st->sharp;
+ }
+
+ *-----------------------------------------------------------------*
+ * - Preprocessing of subframe *
+ *-----------------------------------------------------------------*
+ if (sub(*usedMode, MR475) != 0)
+ {
+ subframePreProc(*usedMode, gamma1, gamma1_12k2,
+ gamma2, A, Aq, &st->speech[i_subfr],
+ st->mem_err, st->mem_w0, st->zero,
+ st->ai_zero, &st->exc[i_subfr],
+ st->h1, xn, res, st->error);
+ }
+ else
+ { // MR475
+ subframePreProc(*usedMode, gamma1, gamma1_12k2,
+ gamma2, A, Aq, &st->speech[i_subfr],
+ st->mem_err, mem_w0_save, st->zero,
+ st->ai_zero, &st->exc[i_subfr],
+ st->h1, xn, res, st->error);
+
+ // save impulse response (modified in cbsearch)
+ if (evenSubfr != 0)
+ {
+ Copy (st->h1, h1_sf0, L_SUBFR);
+ }
+ }
+
+ // copy the LP residual (res2 is modified in the CL LTP search)
+ Copy (res, res2, L_SUBFR);
+
+
+ *-----------------------------------------------------------------*
+ * - Closed-loop LTP search *
+ *-----------------------------------------------------------------*
+ cl_ltp(st->clLtpSt, st->tonStabSt, *usedMode, i_subfr, T_op, st->h1,
+ &st->exc[i_subfr], res2, xn, lsp_flag, xn2, y1,
+ &T0, &T0_frac, &gain_pit, gCoeff, &ana,
+ &gp_limit);
+
+ // update LTP lag history
+ if ((subfrNr == 0) && (st->ol_gain_flg[0] > 0))
+ {
+ st->old_lags[1] = T0;
+ }
+
+ if ((sub(subfrNr, 3) == 0) && (st->ol_gain_flg[1] > 0))
+ {
+ st->old_lags[0] = T0;
+ }
+
+
+ *-----------------------------------------------------------------*
+ * - Inovative codebook search (find index and gain) *
+ *-----------------------------------------------------------------*
+ cbsearch(xn2, st->h1, T0, st->sharp, gain_pit, res2,
+ code, y2, &ana, *usedMode, subfrNr);
+
+ *------------------------------------------------------*
+ * - Quantization of gains. *
+ *------------------------------------------------------*
+ gainQuant(st->gainQuantSt, *usedMode, res, &st->exc[i_subfr], code,
+ xn, xn2, y1, y2, gCoeff, evenSubfr, gp_limit,
+ &gain_pit_sf0, &gain_code_sf0,
+ &gain_pit, &gain_code, &ana);
+
+ // update gain history
+ update_gp_clipping(st->tonStabSt, gain_pit);
+
+ if (sub(*usedMode, MR475) != 0)
+ {
+ // Subframe Post Porcessing
+ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
+ gain_code, Aq, synth, xn, code, y1, y2, st->mem_syn,
+ st->mem_err, st->mem_w0, st->exc, &st->sharp);
+ }
+ else
+ {
+ if (evenSubfr != 0)
+ {
+ i_subfr_sf0 = i_subfr;
+ Copy(xn, xn_sf0, L_SUBFR);
+ Copy(y2, y2_sf0, L_SUBFR);
+ Copy(code, code_sf0, L_SUBFR);
+ T0_sf0 = T0;
+ T0_frac_sf0 = T0_frac;
+
+ // Subframe Post Porcessing
+ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
+ gain_code, Aq, synth, xn, code, y1, y2,
+ mem_syn_save, st->mem_err, mem_w0_save,
+ st->exc, &st->sharp);
+ st->sharp = sharp_save;
+ }
+ else
+ {
+ // update both subframes for the MR475
+
+ // Restore states for the MR475 mode
+ Copy(mem_err_save, st->mem_err, M);
+
+ // re-build excitation for sf 0
+ Pred_lt_3or6(&st->exc[i_subfr_sf0], T0_sf0, T0_frac_sf0,
+ L_SUBFR, 1);
+ Convolve(&st->exc[i_subfr_sf0], h1_sf0, y1, L_SUBFR);
+
+ Aq -= MP1;
+ subframePostProc(st->speech, *usedMode, i_subfr_sf0,
+ gain_pit_sf0, gain_code_sf0, Aq,
+ synth, xn_sf0, code_sf0, y1, y2_sf0,
+ st->mem_syn, st->mem_err, st->mem_w0, st->exc,
+ &sharp_save); // overwrites sharp_save
+ Aq += MP1;
+
+ // re-run pre-processing to get xn right (needed by postproc)
+ // (this also reconstructs the unsharpened h1 for sf 1)
+ subframePreProc(*usedMode, gamma1, gamma1_12k2,
+ gamma2, A, Aq, &st->speech[i_subfr],
+ st->mem_err, st->mem_w0, st->zero,
+ st->ai_zero, &st->exc[i_subfr],
+ st->h1, xn, res, st->error);
+
+ // re-build excitation sf 1 (changed if lag < L_SUBFR)
+ Pred_lt_3or6(&st->exc[i_subfr], T0, T0_frac, L_SUBFR, 1);
+ Convolve(&st->exc[i_subfr], st->h1, y1, L_SUBFR);
+
+ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
+ gain_code, Aq, synth, xn, code, y1, y2,
+ st->mem_syn, st->mem_err, st->mem_w0,
+ st->exc, &st->sharp);
+ }
+ }
+
+
+ A += MP1; // interpolated LPC parameters for next subframe
+ Aq += MP1;
+ }
+
+ Copy(&st->old_exc[L_FRAME], &st->old_exc[0], PIT_MAX + L_INTERPOL);
+
+the_end:
+
+ *--------------------------------------------------*
+ * Update signal for next frame. *
+ *--------------------------------------------------*
+ Copy(&st->old_wsp[L_FRAME], &st->old_wsp[0], PIT_MAX);
+
+ Copy(&st->old_speech[L_FRAME], &st->old_speech[0], L_TOTAL - L_FRAME);
+
+ return 0;
+}
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 cod_amr(
+ cod_amrState *st, /* i/o : State struct */
+ enum Mode mode, /* i : AMR mode */
+ Word16 new_speech[], /* i : speech input (L_FRAME) */
+ Word16 ana[], /* o : Analysis parameters */
+ enum Mode *usedMode, /* o : used mode */
+ Word16 synth[] /* o : Local synthesis */
+)
+{
+ /* LPC coefficients */
+ Word16 A_t[(MP1) * 4]; /* A(z) unquantized for the 4 subframes */
+ Word16 Aq_t[(MP1) * 4]; /* A(z) quantized for the 4 subframes */
+ Word16 *A, *Aq; /* Pointer on A_t and Aq_t */
+ Word16 lsp_new[M];
+
+ /* Other vectors */
+ Word16 xn[L_SUBFR]; /* Target vector for pitch search */
+ Word16 xn2[L_SUBFR]; /* Target vector for codebook search */
+ Word16 code[L_SUBFR]; /* Fixed codebook excitation */
+ Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */
+ Word16 y2[L_SUBFR]; /* Filtered fixed codebook excitation */
+ Word16 gCoeff[6]; /* Correlations between xn, y1, & y2: */
+ Word16 res[L_SUBFR]; /* Short term (LPC) prediction residual */
+ Word16 res2[L_SUBFR]; /* Long term (LTP) prediction residual */
+
+ /* Vector and scalars needed for the MR475 */
+ Word16 xn_sf0[L_SUBFR]; /* Target vector for pitch search */
+ Word16 y2_sf0[L_SUBFR]; /* Filtered codebook innovation */
+ Word16 code_sf0[L_SUBFR]; /* Fixed codebook excitation */
+ Word16 h1_sf0[L_SUBFR]; /* The impulse response of sf0 */
+ Word16 mem_syn_save[M]; /* Filter memory */
+ Word16 mem_w0_save[M]; /* Filter memory */
+ Word16 mem_err_save[M]; /* Filter memory */
+ Word16 sharp_save; /* Sharpening */
+ Word16 evenSubfr; /* Even subframe indicator */
+ Word16 T0_sf0 = 0; /* Integer pitch lag of sf0 */
+ Word16 T0_frac_sf0 = 0; /* Fractional pitch lag of sf0 */
+ Word16 i_subfr_sf0 = 0; /* Position in exc[] for sf0 */
+ Word16 gain_pit_sf0; /* Quantized pitch gain for sf0 */
+ Word16 gain_code_sf0; /* Quantized codebook gain for sf0 */
+
+ /* Scalars */
+ Word16 i_subfr, subfrNr;
+ Word16 T_op[L_FRAME/L_FRAME_BY2];
+ Word16 T0, T0_frac;
+ Word16 gain_pit, gain_code;
+
+ /* Flags */
+ Word16 lsp_flag = 0; /* indicates resonance in LPC filter */
+ Word16 gp_limit; /* pitch gain limit value */
+ Word16 vad_flag; /* VAD decision flag */
+ Word16 compute_sid_flag; /* SID analysis flag */
+ Flag *pOverflow = &(st->overflow); /* Overflow flag */
+
+
+ memcpy(st->new_speech, new_speech, L_FRAME*sizeof(Word16));
+
+ *usedMode = mode;
+
+ /* DTX processing */
+ if (st->dtx)
+ {
+ /* Find VAD decision */
+#ifdef VAD2
+ vad_flag = vad2(st->new_speech, st->vadSt, pOverflow);
+ vad_flag = vad2(st->new_speech + 80, st->vadSt, pOverflow) || vad_flag;
+#else
+ vad_flag = vad1(st->vadSt, st->new_speech, pOverflow);
+#endif
+
+ /* NB! usedMode may change here */
+ compute_sid_flag = tx_dtx_handler(st->dtx_encSt,
+ vad_flag,
+ usedMode, pOverflow);
+ }
+ else
+ {
+ compute_sid_flag = 0;
+ }
+
+ /*------------------------------------------------------------------------*
+ * - Perform LPC analysis: *
+ * * autocorrelation + lag windowing *
+ * * Levinson-durbin algorithm to find a[] *
+ * * convert a[] to lsp[] *
+ * * quantize and code the LSPs *
+ * * find the interpolated LSPs and convert to a[] for all *
+ * subframes (both quantized and unquantized) *
+ *------------------------------------------------------------------------*/
+
+ /* LP analysis */
+ lpc(st->lpcSt, mode, st->p_window, st->p_window_12k2, A_t, pOverflow);
+
+ /* From A(z) to lsp. LSP quantization and interpolation */
+ lsp(st->lspSt, mode, *usedMode, A_t, Aq_t, lsp_new, &ana, pOverflow);
+
+ /* Buffer lsp's and energy */
+ dtx_buffer(st->dtx_encSt,
+ lsp_new,
+ st->new_speech, pOverflow);
+
+ /* Check if in DTX mode */
+
+ if (*usedMode == MRDTX)
+ {
+ dtx_enc(st->dtx_encSt,
+ compute_sid_flag,
+ st->lspSt->qSt,
+ &(st->gainQuantSt->gc_predSt),
+ &ana, pOverflow);
+
+ memset(st->old_exc, 0, sizeof(Word16)*(PIT_MAX + L_INTERPOL));
+ memset(st->mem_w0, 0, sizeof(Word16)*M);
+ memset(st->mem_err, 0, sizeof(Word16)*M);
+ memset(st->zero, 0, sizeof(Word16)*L_SUBFR);
+ memset(st->hvec, 0, sizeof(Word16)*L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */
+ /* Reset lsp states */
+ lsp_reset(st->lspSt);
+
+ memcpy(st->lspSt->lsp_old, lsp_new, M*sizeof(Word16));
+ memcpy(st->lspSt->lsp_old_q, lsp_new, M*sizeof(Word16));
+
+ /* Reset clLtp states */
+ cl_ltp_reset(st->clLtpSt);
+ st->sharp = SHARPMIN;
+ }
+ else
+ {
+ /* check resonance in the filter */
+ lsp_flag = check_lsp(st->tonStabSt, st->lspSt->lsp_old, pOverflow);
+ }
+
+ /*----------------------------------------------------------------------*
+ * - Find the weighted input speech w_sp[] for the whole speech frame *
+ * - Find the open-loop pitch delay for first 2 subframes *
+ * - Set the range for searching closed-loop pitch in 1st subframe *
+ * - Find the open-loop pitch delay for last 2 subframes *
+ *----------------------------------------------------------------------*/
+
+#ifdef VAD2
+ if (st->dtx)
+ {
+ st->vadSt->L_Rmax = 0;
+ st->vadSt->L_R0 = 0;
+ }
+#endif
+
+ for (subfrNr = 0, i_subfr = 0;
+ subfrNr < L_FRAME / L_FRAME_BY2;
+ subfrNr++, i_subfr += L_FRAME_BY2)
+ {
+ /* Pre-processing on 80 samples */
+ pre_big(mode, gamma1, gamma1_12k2, gamma2, A_t, i_subfr, st->speech,
+ st->mem_w, st->wsp, pOverflow);
+
+
+ if ((mode != MR475) && (mode != MR515))
+ {
+ /* Find open loop pitch lag for two subframes */
+ ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[i_subfr],
+ &T_op[subfrNr], st->old_lags, st->ol_gain_flg, subfrNr,
+ st->dtx, pOverflow);
+ }
+ }
+
+ if ((mode == MR475) || (mode == MR515))
+ {
+ /* Find open loop pitch lag for ONE FRAME ONLY */
+ /* search on 160 samples */
+
+ ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[0], &T_op[0],
+ st->old_lags, st->ol_gain_flg, 1, st->dtx, pOverflow);
+ T_op[1] = T_op[0];
+ }
+
+#ifdef VAD2
+ if (st->dtx)
+ {
+ LTP_flag_update(st->vadSt, (Word16) mode, pOverflow);
+ }
+#endif
+
+#ifndef VAD2
+ /* run VAD pitch detection */
+ if (st->dtx)
+ {
+ vad_pitch_detection(st->vadSt, T_op, pOverflow);
+ }
+#endif
+
+ if (*usedMode == MRDTX)
+ {
+ goto the_end;
+ }
+
+ /*------------------------------------------------------------------------*
+ * Loop for every subframe in the analysis frame *
+ *------------------------------------------------------------------------*
+ * To find the pitch and innovation parameters. The subframe size is *
+ * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. *
+ * - find the weighted LPC coefficients *
+ * - find the LPC residual signal res[] *
+ * - compute the target signal for pitch search *
+ * - compute impulse response of weighted synthesis filter (h1[]) *
+ * - find the closed-loop pitch parameters *
+ * - encode the pitch dealy *
+ * - update the impulse response h1[] by including fixed-gain pitch *
+ * - find target vector for codebook search *
+ * - codebook search *
+ * - encode codebook address *
+ * - VQ of pitch and codebook gains *
+ * - find synthesis speech *
+ * - update states of weighting filter *
+ *------------------------------------------------------------------------*/
+
+ A = A_t; /* pointer to interpolated LPC parameters */
+ Aq = Aq_t; /* pointer to interpolated quantized LPC parameters */
+
+ evenSubfr = 0;
+ subfrNr = -1;
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ subfrNr++;
+ evenSubfr = 1 - evenSubfr;
+
+ /* Save states for the MR475 mode */
+
+ if ((evenSubfr != 0) && (*usedMode == MR475))
+ {
+ memcpy(mem_syn_save, st->mem_syn, M*sizeof(Word16));
+ memcpy(mem_w0_save, st->mem_w0, M*sizeof(Word16));
+ memcpy(mem_err_save, st->mem_err, M*sizeof(Word16));
+
+ sharp_save = st->sharp;
+ }
+
+ /*-----------------------------------------------------------------*
+ * - Preprocessing of subframe *
+ *-----------------------------------------------------------------*/
+
+ if (*usedMode != MR475)
+ {
+ subframePreProc(*usedMode, gamma1, gamma1_12k2,
+ gamma2, A, Aq, &st->speech[i_subfr],
+ st->mem_err, st->mem_w0, st->zero,
+ st->ai_zero, &st->exc[i_subfr],
+ st->h1, xn, res, st->error);
+ }
+ else
+ { /* MR475 */
+ subframePreProc(*usedMode, gamma1, gamma1_12k2,
+ gamma2, A, Aq, &st->speech[i_subfr],
+ st->mem_err, mem_w0_save, st->zero,
+ st->ai_zero, &st->exc[i_subfr],
+ st->h1, xn, res, st->error);
+
+ /* save impulse response (modified in cbsearch) */
+
+ if (evenSubfr != 0)
+ {
+ memcpy(h1_sf0, st->h1, L_SUBFR*sizeof(Word16));
+
+ }
+ }
+
+ /* copy the LP residual (res2 is modified in the CL LTP search) */
+ memcpy(res2, res, L_SUBFR*sizeof(Word16));
+
+ /*-----------------------------------------------------------------*
+ * - Closed-loop LTP search *
+ *-----------------------------------------------------------------*/
+ cl_ltp(st->clLtpSt, st->tonStabSt, *usedMode, i_subfr, T_op, st->h1,
+ &st->exc[i_subfr], res2, xn, lsp_flag, xn2, y1,
+ &T0, &T0_frac, &gain_pit, gCoeff, &ana,
+ &gp_limit, pOverflow);
+
+ /* update LTP lag history */
+
+ if ((subfrNr == 0) && (st->ol_gain_flg[0] > 0))
+ {
+ st->old_lags[1] = T0;
+ }
+
+
+ if ((subfrNr == 3) && (st->ol_gain_flg[1] > 0))
+ {
+ st->old_lags[0] = T0;
+ }
+
+ /*-----------------------------------------------------------------*
+ * - Inovative codebook search (find index and gain) *
+ *-----------------------------------------------------------------*/
+ cbsearch(xn2, st->h1, T0, st->sharp, gain_pit, res2,
+ code, y2, &ana, *usedMode, subfrNr, pOverflow);
+
+ /*------------------------------------------------------*
+ * - Quantization of gains. *
+ *------------------------------------------------------*/
+ gainQuant(st->gainQuantSt, *usedMode, res, &st->exc[i_subfr], code,
+ xn, xn2, y1, y2, gCoeff, evenSubfr, gp_limit,
+ &gain_pit_sf0, &gain_code_sf0,
+ &gain_pit, &gain_code, &ana, pOverflow);
+
+ /* update gain history */
+ update_gp_clipping(st->tonStabSt, gain_pit, pOverflow);
+
+
+ if (*usedMode != MR475)
+ {
+ /* Subframe Post Porcessing */
+ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
+ gain_code, Aq, synth, xn, code, y1, y2, st->mem_syn,
+ st->mem_err, st->mem_w0, st->exc, &st->sharp, pOverflow);
+ }
+ else
+ {
+
+ if (evenSubfr != 0)
+ {
+ i_subfr_sf0 = i_subfr;
+
+ memcpy(xn_sf0, xn, L_SUBFR*sizeof(Word16));
+ memcpy(y2_sf0, y2, L_SUBFR*sizeof(Word16));
+ memcpy(code_sf0, code, L_SUBFR*sizeof(Word16));
+
+ T0_sf0 = T0;
+ T0_frac_sf0 = T0_frac;
+
+ /* Subframe Post Porcessing */
+ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
+ gain_code, Aq, synth, xn, code, y1, y2,
+ mem_syn_save, st->mem_err, mem_w0_save,
+ st->exc, &st->sharp, pOverflow);
+ st->sharp = sharp_save;
+ }
+ else
+ {
+ /* update both subframes for the MR475 */
+
+ /* Restore states for the MR475 mode */
+ memcpy(st->mem_err, mem_err_save, M*sizeof(Word16));
+
+
+ /* re-build excitation for sf 0 */
+ Pred_lt_3or6(&st->exc[i_subfr_sf0], T0_sf0, T0_frac_sf0,
+ L_SUBFR, 1, pOverflow);
+ Convolve(&st->exc[i_subfr_sf0], h1_sf0, y1, L_SUBFR);
+
+ Aq -= MP1;
+ subframePostProc(st->speech, *usedMode, i_subfr_sf0,
+ gain_pit_sf0, gain_code_sf0, Aq,
+ synth, xn_sf0, code_sf0, y1, y2_sf0,
+ st->mem_syn, st->mem_err, st->mem_w0, st->exc,
+ &sharp_save, pOverflow); /* overwrites sharp_save */
+ Aq += MP1;
+
+ /* re-run pre-processing to get xn right (needed by postproc) */
+ /* (this also reconstructs the unsharpened h1 for sf 1) */
+ subframePreProc(*usedMode, gamma1, gamma1_12k2,
+ gamma2, A, Aq, &st->speech[i_subfr],
+ st->mem_err, st->mem_w0, st->zero,
+ st->ai_zero, &st->exc[i_subfr],
+ st->h1, xn, res, st->error);
+
+ /* re-build excitation sf 1 (changed if lag < L_SUBFR) */
+ Pred_lt_3or6(&st->exc[i_subfr], T0, T0_frac, L_SUBFR, 1, pOverflow);
+ Convolve(&st->exc[i_subfr], st->h1, y1, L_SUBFR);
+
+ subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
+ gain_code, Aq, synth, xn, code, y1, y2,
+ st->mem_syn, st->mem_err, st->mem_w0,
+ st->exc, &st->sharp, pOverflow);
+ }
+ }
+
+ A += MP1; /* interpolated LPC parameters for next subframe */
+ Aq += MP1;
+ }
+
+ memcpy(&st->old_exc[0], &st->old_exc[L_FRAME], (PIT_MAX + L_INTERPOL)*sizeof(Word16));
+
+the_end:
+
+ /*--------------------------------------------------*
+ * Update signal for next frame. *
+ *--------------------------------------------------*/
+
+ memcpy(&st->old_wsp[0], &st->old_wsp[L_FRAME], PIT_MAX*sizeof(Word16));
+ memcpy(&st->old_speech[0], &st->old_speech[L_FRAME], (L_TOTAL - L_FRAME)*sizeof(Word16));
+
+ return(0);
+}
+
+
diff --git a/media/codecs/amrnb/enc/src/cod_amr.h b/media/codecs/amrnb/enc/src/cod_amr.h
new file mode 100644
index 0000000..7360c0a
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cod_amr.h
@@ -0,0 +1,275 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/cod_amr.h
+
+ Date: 02/07/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added overflow flag as an element to the cod_amrState data
+ structure. Corrected the function prototype declaration for
+ cod_amr().
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : cod_amr.h
+ Purpose : Main encoder routine operating on a frame basis.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef cod_amr_h
+#define cod_amr_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "mode.h"
+#include "lpc.h"
+#include "lsp.h"
+#include "cl_ltp.h"
+#include "gain_q.h"
+#include "p_ol_wgh.h"
+#include "ton_stab.h"
+#include "vad.h"
+#include "dtx_enc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ /*-----------------------------------------------------------*
+ * Coder constant parameters (defined in "cnst.h") *
+ *-----------------------------------------------------------*
+ * L_WINDOW : LPC analysis window size. *
+ * L_NEXT : Samples of next frame needed for autocor. *
+ * L_FRAME : Frame size. *
+ * L_FRAME_BY2 : Half the frame size. *
+ * L_SUBFR : Sub-frame size. *
+ * M : LPC order. *
+ * MP1 : LPC order+1 *
+ * L_TOTAL7k4 : Total size of speech buffer. *
+ * PIT_MIN7k4 : Minimum pitch lag. *
+ * PIT_MAX : Maximum pitch lag. *
+ * L_INTERPOL : Length of filter for interpolation *
+ *-----------------------------------------------------------*/
+ typedef struct
+ {
+ /* Speech vector */
+ Word16 old_speech[L_TOTAL];
+ Word16 *speech, *p_window, *p_window_12k2;
+ Word16 *new_speech; /* Global variable */
+
+ /* Weight speech vector */
+ Word16 old_wsp[L_FRAME + PIT_MAX];
+ Word16 *wsp;
+
+ /* OL LTP states */
+ Word16 old_lags[5];
+ Word16 ol_gain_flg[2];
+
+ /* Excitation vector */
+ Word16 old_exc[L_FRAME + PIT_MAX + L_INTERPOL];
+ Word16 *exc;
+
+ /* Zero vector */
+ Word16 ai_zero[L_SUBFR + MP1];
+ Word16 *zero;
+
+ /* Impulse response vector */
+ Word16 *h1;
+ Word16 hvec[L_SUBFR * 2];
+
+ /* Substates */
+ lpcState *lpcSt;
+ lspState *lspSt;
+ clLtpState *clLtpSt;
+ gainQuantState *gainQuantSt;
+ pitchOLWghtState *pitchOLWghtSt;
+ tonStabState *tonStabSt;
+ vadState *vadSt;
+ Flag dtx;
+ dtx_encState *dtx_encSt;
+
+ /* Filter's memory */
+ Word16 mem_syn[M], mem_w0[M], mem_w[M];
+ Word16 mem_err[M + L_SUBFR], *error;
+
+ Word16 sharp;
+
+ /* Overflow flag */
+ Flag overflow;
+
+ } cod_amrState;
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /*
+ **************************************************************************
+ *
+ * Function : cod_amr_init
+ * Purpose : Allocates memory and initializes state variables
+ * Description : Stores pointer to filter status struct in *st. This
+ * pointer has to be passed to cod_amr in each call.
+ * - initilize pointers to speech buffer
+ * - initialize static pointers
+ * - set static vectors to zero
+ * Returns : 0 on success
+ *
+ **************************************************************************
+ */
+ Word16 cod_amr_init(cod_amrState **st, Flag dtx);
+
+ /*
+ **************************************************************************
+ *
+ * Function : cod_amr_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ *
+ **************************************************************************
+ */
+ Word16 cod_amr_reset(cod_amrState *st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : cod_amr_exit
+ * Purpose : The memory used for state memory is freed
+ * Description : Stores NULL in *st
+ *
+ **************************************************************************
+ */
+ void cod_amr_exit(cod_amrState **st);
+
+ /***************************************************************************
+ * FUNCTION: cod_amr_first
+ *
+ * PURPOSE: Copes with look-ahead.
+ *
+ * INPUTS:
+ * No input argument are passed to this function. However, before
+ * calling this function, 40 new speech data should be copied to the
+ * vector new_speech[]. This is a global pointer which is declared in
+ * this file (it points to the end of speech buffer minus 200).
+ *
+ ***************************************************************************/
+
+ Word16 cod_amr_first(cod_amrState *st, /* i/o : State struct */
+ Word16 new_speech[] /* i : speech input (L_FRAME) */
+ );
+
+ /***************************************************************************
+ * FUNCTION: cod_amr
+ *
+ * PURPOSE: Main encoder routine.
+ *
+ * DESCRIPTION: This function is called every 20 ms speech frame,
+ * operating on the newly read 160 speech samples. It performs the
+ * principle encoding functions to produce the set of encoded parameters
+ * which include the LSP, adaptive codebook, and fixed codebook
+ * quantization indices (addresses and gains).
+ *
+ * INPUTS:
+ * No input argument are passed to this function. However, before
+ * calling this function, 160 new speech data should be copied to the
+ * vector new_speech[]. This is a global pointer which is declared in
+ * this file (it points to the end of speech buffer minus 160).
+ *
+ * OUTPUTS:
+ *
+ * ana[]: vector of analysis parameters.
+ * synth[]: Local synthesis speech (for debugging purposes)
+ *
+ ***************************************************************************/
+
+ Word16 cod_amr(cod_amrState *st, /* i/o : State struct */
+ enum Mode mode, /* i : AMR mode */
+ Word16 new_speech[], /* i : speech input (L_FRAME) */
+ Word16 ana[], /* o : Analysis parameters */
+ enum Mode *usedMode, /* o : used mode */
+ Word16 synth[] /* o : Local synthesis */
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _cod_amr_h_ */
+
+
+
diff --git a/media/codecs/amrnb/enc/src/convolve.cpp b/media/codecs/amrnb/enc/src/convolve.cpp
new file mode 100644
index 0000000..5015a4a
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/convolve.cpp
@@ -0,0 +1,245 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/convolve.c
+
+ Date: 06/19/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Optimize for speed. Update to code template.
+
+ Description: Added author name and date, fixed tabs, and added missing
+ sections. Updated Input/Output section.
+
+ Description: Optimized code by calculating two convolution sums per iteration
+ of the outer loop, thereby, decreasing outer loop count by 2.
+ Updated input/output definitions to be the same as the assembly
+ file (convolve.asm). Left Pseudo-code section blank.
+
+ Description: Deleted semi-colon in the Pointers modified section.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Fixed typecasting issue with TI C compiler.
+ 2. Modified FOR loop to count down, wherever applicable.
+
+ Description: Made the following changes
+ 1. Unrolled the correlation loop.
+ 2. Performed 2 correlation per pass per sample to avoid recalling
+ the same data twice.
+ 3. Eliminated math operations that check for saturation.
+
+ Description:
+ 1. Modified loop counter, extra unrolling did speed up code
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Using inlines from fxp_arithmetic.h .
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "convolve.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Convolve
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ x = pointer to input vector of L elements of type Word16
+ h = pointer to the filter's impulse response vector of L elements
+ of type Word16
+ y = pointer to the output vector of L elements of type Word16 used for
+ storing the convolution of x and h;
+ L = Length of the convolution; type definition is Word16
+
+ Outputs:
+ y buffer contains the new convolution output
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Perform the convolution between two vectors x[] and h[] and write the result
+ in the vector y[]. All vectors are of length L and only the first L samples
+ of the convolution are computed.
+
+ The convolution is given by:
+
+ y[n] = sum_{i=0}^{n} x[i] h[n-i], n=0,...,L-1
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ convolve.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Convolve (
+ Word16 x[], // (i) : input vector
+ Word16 h[], // (i) : impulse response
+ Word16 y[], // (o) : output vector
+ Word16 L // (i) : vector size
+)
+{
+ Word16 i, n;
+ Word32 s;
+
+ for (n = 0; n < L; n++)
+ {
+ s = 0; move32 ();
+ for (i = 0; i <= n; i++)
+ {
+ s = L_mac (s, x[i], h[n - i]);
+ }
+ s = L_shl (s, 3);
+ y[n] = extract_h (s); move16 ();
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Convolve(
+ Word16 x[], /* (i) : input vector */
+ Word16 h[], /* (i) : impulse response */
+ Word16 y[], /* (o) : output vector */
+ Word16 L /* (i) : vector size */
+)
+{
+ Word16 i, n;
+ Word32 s1, s2;
+
+
+ for (n = 1; n < L; n = n + 2)
+ {
+
+ h = h + n;
+
+ s2 = ((Word32) * (x)) * *(h--);
+ s1 = ((Word32) * (x++)) * *(h);
+
+ for (i = (n - 1) >> 1; i != 0; i--)
+ {
+ s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (x), (Word32) * (h--), s2);
+ s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (x++), (Word32) * (h), s1);
+ s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (x), (Word32) * (h--), s2);
+ s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (x++), (Word32) * (h), s1);
+ }
+
+ s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (x), (Word32) * (h), s2);
+
+ *(y++) = (Word16)(s1 >> 12);
+ *(y++) = (Word16)(s2 >> 12);
+
+ x = x - n;
+
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/convolve.h b/media/codecs/amrnb/enc/src/convolve.h
new file mode 100644
index 0000000..1f2b503
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/convolve.h
@@ -0,0 +1,83 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : convolve.h
+* Purpose : Perform the convolution between two vectors x[]
+* : and h[] and write the result in the vector y[].
+* : All vectors are of length L and only the first
+* : L samples of the convolution are computed.
+*
+********************************************************************************
+*/
+#ifndef convolve_h
+#define convolve_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ void Convolve(
+ Word16 x[], /* (i) : input vector */
+ Word16 h[], /* (i) : impulse response */
+ Word16 y[], /* (o) : output vector */
+ Word16 L /* (i) : vector size */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/enc/src/cor_h.cpp b/media/codecs/amrnb/enc/src/cor_h.cpp
new file mode 100644
index 0000000..20583c4
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cor_h.cpp
@@ -0,0 +1,429 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/cor_h.c
+
+ Date: 06/12/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Used MAX_16 and MIN_16 when checking the result of Inv_sqrt.
+ Synced up to the new template.
+
+ Description: Added setting of Overflow flag in inlined code.
+
+ Description: Took out cor_h_x function and put it in its own file. Sync'ed
+ up with the single_func_template.c template. Delete version
+ ID variable.
+
+ Description: Synchronized file with UTMS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Fixed portion of the code that builds the rr[] matrix. There
+ was an error in the original inlining of code that caused
+ the code to be not bit-exact with UMTS version 3.2.0.
+
+ Description: Added calls to L_add() and mult() in the code to handle overflow
+ scenario. Moved cor_h.h after cnst.h in the Include section.
+ Doing this allows the unit test to build using the cnst.h in the
+ /test/include directory. Fixed initialization of the accumulator
+ in the first calculation of the sum of squares.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Used #define value instead of hard-coded numbers in the code.
+ 2. Fixed typecasting issue with TI C compiler.
+ 3. Removed typecasting of 0x00008000L in the call to L_add.
+
+ Description: Changed pOverflow from a global variable into a function
+ parameter.
+
+ Description:
+ 1. Added pointer to avoid adding offsets in every pass
+ 2. Eliminate variables defined as registers
+ 3. Removed extra check for overflow by doing scaling right
+ after overflow is detected.
+ 4. Eliminated calls to basic operations (like extract) not
+ needed because of the nature of the number (all bounded)
+ 5. Eliminated duplicate loop accessing same data
+ 6. Simplified matrix addressing by use of pointers
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Access twice the number of points when delaing with matrices
+ and in the process only 3 pointers (instead of 4) are needed
+ 3. Replaced array addressing (array sign[]) by pointers
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Using inlines from fxp_arithmetic.h .
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "cnst.h"
+#include "cor_h.h"
+#include "basicop_malloc.h"
+#include "inv_sqrt.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cor_h
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ h = vector containing the impulse response of the weighted synthesis
+ filter; vector contents are of type Word16; vector length is
+ 2 * L_SUBFR
+ sign = vector containing the sign information for the correlation
+ values; vector contents are of type Word16; vector length is
+ L_CODE
+ rr = autocorrelation matrix; matrix contents are of type Word16;
+ matrix dimension is L_CODE by L_CODE
+
+ Outputs:
+ rr contents are the newly calculated autocorrelation values
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes correlations of the impulse response (h) needed for
+ the codebook search, and includes the sign information into the correlations.
+
+ The correlations are given by:
+ rr[i][j] = sum_{n=i}^{L-1} h[n-i] h[n-j]; i>=j; i,j=0,...,L-1
+
+ The sign information is included by:
+ rr[i][j] = rr[i][j]*sign[i]*sign[j]
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cor_h.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void cor_h (
+ Word16 h[], // (i) : impulse response of weighted synthesis
+ filter
+ Word16 sign[], // (i) : sign of d[n]
+ Word16 rr[][L_CODE] // (o) : matrix of autocorrelation
+)
+{
+ Word16 i, j, k, dec, h2[L_CODE];
+ Word32 s;
+
+ // Scaling for maximum precision
+
+ s = 2;
+ for (i = 0; i < L_CODE; i++)
+ s = L_mac (s, h[i], h[i]);
+
+ j = sub (extract_h (s), 32767);
+ if (j == 0)
+ {
+ for (i = 0; i < L_CODE; i++)
+ {
+ h2[i] = shr (h[i], 1);
+ }
+ }
+ else
+ {
+ s = L_shr (s, 1);
+ k = extract_h (L_shl (Inv_sqrt (s), 7));
+ k = mult (k, 32440); // k = 0.99*k
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ h2[i] = pv_round (L_shl (L_mult (h[i], k), 9));
+ }
+ }
+
+ // build matrix rr[]
+ s = 0;
+ i = L_CODE - 1;
+ for (k = 0; k < L_CODE; k++, i--)
+ {
+ s = L_mac (s, h2[k], h2[k]);
+ rr[i][i] = pv_round (s);
+ }
+
+ for (dec = 1; dec < L_CODE; dec++)
+ {
+ s = 0;
+ j = L_CODE - 1;
+ i = sub (j, dec);
+ for (k = 0; k < (L_CODE - dec); k++, i--, j--)
+ {
+ s = L_mac (s, h2[k], h2[k + dec]);
+ rr[j][i] = mult (pv_round (s), mult (sign[i], sign[j]));
+ rr[i][j] = rr[j][i];
+ }
+ }
+}
+
+---------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void cor_h(
+ Word16 h[], /* (i) : impulse response of weighted synthesis
+ filter */
+ Word16 sign[], /* (i) : sign of d[n] */
+ Word16 rr[][L_CODE], /* (o) : matrix of autocorrelation */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 dec;
+
+ Word16 h2[L_CODE];
+ Word32 s;
+ Word32 s2;
+ Word16 tmp1;
+ Word16 tmp2;
+ Word16 tmp11;
+ Word16 tmp22;
+
+ Word16 *p_h;
+ Word16 *p_h2;
+ Word16 *rr1;
+ Word16 *rr2;
+ Word16 *rr3;
+ Word16 *p_rr_ref1;
+ Word16 *p_sign1;
+ Word16 *p_sign2;
+
+ /* Scaling for maximum precision */
+
+ /* Initialize accumulator to 1 since left shift happens */
+ /* after the accumulation of the sum of squares (original */
+ /* code initialized s to 2) */
+ s = 1;
+ p_h = h;
+
+ for (i = (L_CODE >> 1); i != 0 ; i--)
+ {
+ tmp1 = *(p_h++);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) tmp1, (Word32) tmp1, s);
+ tmp1 = *(p_h++);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) tmp1, (Word32) tmp1, s);
+
+ }
+
+ s <<= 1;
+
+ if (s & MIN_32)
+ {
+ p_h2 = h2;
+ p_h = h;
+
+ for (i = (L_CODE >> 1); i != 0; i--)
+ {
+ *(p_h2++) = *(p_h++) >> 1;
+ *(p_h2++) = *(p_h++) >> 1;
+ }
+ }
+ else
+ {
+
+ s >>= 1;
+
+ s = Inv_sqrt(s, pOverflow);
+
+ if (s < (Word32) 0x00ffffffL)
+ {
+ /* k = 0.99*k */
+ dec = (Word16)(((s >> 9) * 32440) >> 15);
+ }
+ else
+ {
+ dec = 32440; /* 0.99 */
+ }
+
+ p_h = h;
+ p_h2 = h2;
+
+ for (i = (L_CODE >> 1); i != 0; i--)
+ {
+ *(p_h2++) = (Word16)((amrnb_fxp_mac_16_by_16bb((Word32) * (p_h++), (Word32) dec, 0x020L)) >> 6);
+ *(p_h2++) = (Word16)((amrnb_fxp_mac_16_by_16bb((Word32) * (p_h++), (Word32) dec, 0x020L)) >> 6);
+ }
+ }
+ /* build matrix rr[] */
+
+ s = 0;
+
+ p_h2 = h2;
+
+ rr1 = &rr[L_CODE-1][L_CODE-1];
+
+ for (i = L_CODE >> 1; i != 0 ; i--)
+ {
+ tmp1 = *(p_h2++);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) tmp1, (Word32) tmp1, s);
+ *rr1 = (Word16)((s + 0x00004000L) >> 15);
+ rr1 -= (L_CODE + 1);
+ tmp1 = *(p_h2++);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) tmp1, (Word32) tmp1, s);
+ *rr1 = (Word16)((s + 0x00004000L) >> 15);
+ rr1 -= (L_CODE + 1);
+ }
+
+
+ p_rr_ref1 = rr[L_CODE-1];
+
+ for (dec = 1; dec < L_CODE; dec += 2)
+ {
+ rr1 = &p_rr_ref1[L_CODE-1-dec];
+
+ rr2 = &rr[L_CODE-1-dec][L_CODE-1];
+ rr3 = &rr[L_CODE-1-(dec+1)][L_CODE-1];
+
+ s = 0;
+ s2 = 0;
+
+ p_sign1 = &sign[L_CODE - 1];
+ p_sign2 = &sign[L_CODE - 1 - dec];
+
+ p_h2 = h2;
+ p_h = &h2[dec];
+
+ for (i = (L_CODE - dec - 1); i != 0 ; i--)
+ {
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_h2), (Word32) * (p_h++), s);
+ s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p_h2++), (Word32) * (p_h), s2);
+
+ tmp1 = (Word16)((s + 0x00004000L) >> 15);
+ tmp11 = (Word16)((s2 + 0x00004000L) >> 15);
+
+ tmp2 = ((Word32) * (p_sign1) * *(p_sign2--)) >> 15;
+ tmp22 = ((Word32) * (p_sign1--) * *(p_sign2)) >> 15;
+
+ *rr2 = ((Word32) tmp1 * tmp2) >> 15;
+ *(rr1--) = *rr2;
+ *rr1 = ((Word32) tmp11 * tmp22) >> 15;
+ *rr3 = *rr1;
+
+ rr1 -= (L_CODE);
+ rr2 -= (L_CODE + 1);
+ rr3 -= (L_CODE + 1);
+
+ }
+
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_h2), (Word32) * (p_h), s);
+
+ tmp1 = (Word16)((s + 0x00004000L) >> 15);
+
+ tmp2 = ((Word32) * (p_sign1) * *(p_sign2)) >> 15;
+ *rr1 = ((Word32) tmp1 * tmp2) >> 15;
+
+ *rr2 = *rr1;
+
+ rr1 -= (L_CODE + 1);
+ rr2 -= (L_CODE + 1);
+
+ }
+
+ return;
+
+}
+
diff --git a/media/codecs/amrnb/enc/src/cor_h.h b/media/codecs/amrnb/enc/src/cor_h.h
new file mode 100644
index 0000000..59b9d68
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cor_h.h
@@ -0,0 +1,96 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef COR_H_H
+#define COR_H_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+#include "cor_h_x.h" /* Used by legacy files */
+#include "cor_h_x2.h" /* Used by legacy files */
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void cor_h(
+ Word16 h[], /* (i) : impulse response of weighted synthesis
+ filter */
+ Word16 sign[], /* (i) : sign of d[n] */
+ Word16 rr[][L_CODE], /* (o) : matrix of autocorrelation */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/media/codecs/amrnb/enc/src/cor_h_x.cpp b/media/codecs/amrnb/enc/src/cor_h_x.cpp
new file mode 100644
index 0000000..c25c026
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cor_h_x.cpp
@@ -0,0 +1,320 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/cor_h_x.c
+
+ Date: 09/07/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created a separate file for cor_h_x function.
+
+ Description: Synchronized file with UMTS versin 3.2.0. Updated coding
+ template.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Modified FOR loop in the code to count down.
+ 2. Fixed typecasting issue with TI C compiler.
+
+ Description: Added call to round() and L_shl() functions in the last FOR
+ loop to make code bit-exact. Updated copyright year.
+
+ Description: Modified to pass pOverflow in via a pointer, rather than
+ invoking it as a global variable.
+
+ Description: Made the following changes
+ 1. Unrolled the correlation loop and add mechanism control
+ to compute odd or even number of computations.
+ 2. Use pointer to avoid continuos addresses calculation
+ 2. Eliminated math operations that check for saturation.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "cor_h_x.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cor_h_x
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ h = vector containing the impulse response of the weighted synthesis
+ filter; vector contents are of type Word16; vector length is
+ 2 * L_SUBFR
+ x = target signal vector; vector contents are of type Word16; vector
+ length is L_SUBFR
+ dn = vector containing the correlation between the target and the
+ impulse response; vector contents are of type Word16; vector
+ length is L_CODE
+ sf = scaling factor of type Word16 ; 2 when mode is MR122, 1 for all
+ other modes
+
+ Outputs:
+ dn contents are the newly calculated correlation values
+
+ pOverflow = pointer of type Flag * to overflow indicator.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the correlation between the target signal (x) and the
+ impulse response (h).
+
+ The correlation is given by: d[n] = sum_{i=n}^{L-1} x[i] h[i-n],
+ where: n=0,...,L-1
+
+ d[n] is normalized such that the sum of 5 maxima of d[n] corresponding to
+ each position track does not saturate.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cor_h.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void cor_h_x (
+ Word16 h[], // (i): impulse response of weighted synthesis filter
+ Word16 x[], // (i): target
+ Word16 dn[], // (o): correlation between target and h[]
+ Word16 sf // (i): scaling factor: 2 for 12.2, 1 for others
+)
+{
+ cor_h_x2(h, x, dn, sf, NB_TRACK, STEP);
+}
+
+
+void cor_h_x2 (
+ Word16 h[], // (i): impulse response of weighted synthesis filter
+ Word16 x[], // (i): target
+ Word16 dn[], // (o): correlation between target and h[]
+ Word16 sf, // (i): scaling factor: 2 for 12.2, 1 for others
+ Word16 nb_track,// (i): the number of ACB tracks
+ Word16 step // (i): step size from one pulse position to the next
+ in one track
+)
+{
+ Word16 i, j, k;
+ Word32 s, y32[L_CODE], max, tot;
+
+ // first keep the result on 32 bits and find absolute maximum
+
+ tot = 5;
+
+ for (k = 0; k < nb_track; k++)
+ {
+ max = 0;
+ for (i = k; i < L_CODE; i += step)
+ {
+ s = 0;
+ for (j = i; j < L_CODE; j++)
+ s = L_mac (s, x[j], h[j - i]);
+
+ y32[i] = s;
+
+ s = L_abs (s);
+ if (L_sub (s, max) > (Word32) 0L)
+ max = s;
+ }
+ tot = L_add (tot, L_shr (max, 1));
+ }
+
+ j = sub (norm_l (tot), sf);
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ dn[i] = pv_round (L_shl (y32[i], j));
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void cor_h_x(
+ Word16 h[], /* (i): impulse response of weighted synthesis filter */
+ Word16 x[], /* (i): target */
+ Word16 dn[], /* (o): correlation between target and h[] */
+ Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */
+ Flag *pOverflow /* (o): pointer to overflow flag */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+
+ Word32 s;
+ Word32 y32[L_CODE];
+ Word32 max;
+ Word32 tot;
+
+ Word16 *p_x;
+ Word16 *p_ptr;
+ Word32 *p_y32;
+
+
+ tot = 5;
+ for (k = 0; k < NB_TRACK; k++) /* NB_TRACK = 5 */
+ {
+ max = 0;
+ for (i = k; i < L_CODE; i += STEP) /* L_CODE = 40; STEP = 5 */
+ {
+ s = 0;
+ p_x = &x[i];
+ p_ptr = h;
+
+ for (j = (L_CODE - i - 1) >> 1; j != 0; j--)
+ {
+ s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
+ s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
+ }
+
+ s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
+
+ if (!((L_CODE - i) & 1)) /* if even number of iterations */
+ {
+ s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
+ }
+
+ y32[i] = s;
+
+ if (s < 0)
+ {
+ s = -s;
+ }
+
+ if (s > max)
+ {
+ max = s;
+ }
+ }
+
+ tot += (max >> 1);
+ }
+
+
+ j = norm_l(tot) - sf;
+
+ p_ptr = dn;
+ p_y32 = y32;;
+
+ for (i = L_CODE >> 1; i != 0; i--)
+ {
+ s = L_shl(*(p_y32++), j, pOverflow);
+ *(p_ptr++) = (s + 0x00008000) >> 16;
+ s = L_shl(*(p_y32++), j, pOverflow);
+ *(p_ptr++) = (s + 0x00008000) >> 16;
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/cor_h_x.h b/media/codecs/amrnb/enc/src/cor_h_x.h
new file mode 100644
index 0000000..66ada72
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cor_h_x.h
@@ -0,0 +1,103 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains prototype declaration for cor_h_x function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef COR_H_X_H
+#define COR_H_X_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void cor_h_x(
+ Word16 h[], /* (i): impulse response of weighted synthesis filter */
+ Word16 x[], /* (i): target */
+ Word16 dn[], /* (o): correlation between target and h[] */
+ Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */
+ Flag *pOverflow /* (o): pointer to overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/enc/src/cor_h_x2.cpp b/media/codecs/amrnb/enc/src/cor_h_x2.cpp
new file mode 100644
index 0000000..b4fd867
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cor_h_x2.cpp
@@ -0,0 +1,282 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/cor_h_x2.c
+
+ Date: 11/07/2001
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created a separate file for cor_h_x2 function.
+
+ Description: Fixed typecasting issue with TI C compiler and defined one
+ local variable per line. Updated copyright year.
+
+ Description: Added #define for log2(32) = 5.
+
+ Description: Added call to round() and L_shl() functions in the last FOR
+ loop to make code bit-exact.
+
+ Description: Added pOverflow as a variable that's passed in for the EPOC
+ modifications.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Using intrinsics from fxp_arithmetic.h .
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "cor_h_x.h"
+#include "cor_h_x2.h" // BX
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define LOG2_OF_32 5
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cor_h_x2
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ h = vector containing the impulse response of the weighted synthesis
+ filter; vector contents are of type Word16; vector length is
+ 2 * L_SUBFR
+ x = target signal vector; vector contents are of type Word16; vector
+ length is L_SUBFR
+ dn = vector containing the correlation between the target and the
+ impulse response; vector contents are of type Word16; vector
+ length is L_CODE
+ sf = scaling factor of type Word16 ; 2 when mode is MR122, 1 for all
+ other modes
+ nb_track = number of ACB tracks (Word16)
+ step = step size between pulses in one track (Word16)
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ dn contents are the newly calculated correlation values
+ pOverflow = 1 if the math functions called by cor_h_x2 result in overflow
+ else zero.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the correlation between the target signal (x) and the
+ impulse response (h).
+
+ The correlation is given by: d[n] = sum_{i=n}^{L-1} x[i] h[i-n],
+ where: n=0,...,L-1
+
+ d[n] is normalized such that the sum of 5 maxima of d[n] corresponding to
+ each position track does not saturate.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ cor_h.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+The original etsi reference code uses a global flag Overflow. However, in the
+actual implementation a pointer to a the overflow flag is passed in.
+
+void cor_h_x2 (
+ Word16 h[], // (i): impulse response of weighted synthesis filter
+ Word16 x[], // (i): target
+ Word16 dn[], // (o): correlation between target and h[]
+ Word16 sf, // (i): scaling factor: 2 for 12.2, 1 for others
+ Word16 nb_track,// (i): the number of ACB tracks
+ Word16 step // (i): step size from one pulse position to the next
+ in one track
+)
+{
+ Word16 i, j, k;
+ Word32 s, y32[L_CODE], max, tot;
+
+ // first keep the result on 32 bits and find absolute maximum
+
+ tot = 5;
+
+ for (k = 0; k < nb_track; k++)
+ {
+ max = 0;
+ for (i = k; i < L_CODE; i += step)
+ {
+ s = 0;
+ for (j = i; j < L_CODE; j++)
+ s = L_mac (s, x[j], h[j - i]);
+
+ y32[i] = s;
+
+ s = L_abs (s);
+ if (L_sub (s, max) > (Word32) 0L)
+ max = s;
+ }
+ tot = L_add (tot, L_shr (max, 1));
+ }
+
+ j = sub (norm_l (tot), sf);
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ dn[i] = pv_round (L_shl (y32[i], j));
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void cor_h_x2(
+ Word16 h[], /* (i): impulse response of weighted synthesis filter */
+ Word16 x[], /* (i): target */
+ Word16 dn[], /* (o): correlation between target and h[] */
+ Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */
+ Word16 nb_track,/* (i): the number of ACB tracks */
+ Word16 step, /* (i): step size from one pulse position to the next
+ in one track */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+ Word32 s;
+ Word32 y32[L_CODE];
+ Word32 max;
+ Word32 tot;
+
+
+ /* first keep the result on 32 bits and find absolute maximum */
+ tot = LOG2_OF_32;
+ for (k = 0; k < nb_track; k++)
+ {
+ max = 0;
+ for (i = k; i < L_CODE; i += step)
+ {
+ s = 0;
+
+ for (j = i; j < L_CODE; j++)
+ {
+ s = amrnb_fxp_mac_16_by_16bb((Word32)x[j], (Word32)h[j-i], s);
+ }
+
+ s = s << 1;
+ y32[i] = s;
+ s = L_abs(s);
+
+ if (s > max)
+ {
+ max = s;
+ }
+ }
+ tot = (tot + (max >> 1));
+ }
+
+ j = sub(norm_l(tot), sf, pOverflow);
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ dn[i] = pv_round(L_shl(y32[i], j, pOverflow), pOverflow);
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/cor_h_x2.h b/media/codecs/amrnb/enc/src/cor_h_x2.h
new file mode 100644
index 0000000..f2b482c
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/cor_h_x2.h
@@ -0,0 +1,121 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/include/cor_h_x2.h
+
+ Date: 11/07/2001
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Created separate header file for cor_h_x2.
+
+ Description: Added pOverflow for EPOC modifications
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains prototype declaration for cor_h_x2 function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef COR_H_X2_H
+#define COR_H_X2_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void cor_h_x2(
+ Word16 h[], /* (i): impulse response of weighted synthesis filter */
+ Word16 x[], /* (i): target */
+ Word16 dn[], /* (o): correlation between target and h[] */
+ Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */
+ Word16 nb_track,/* (i): the number of ACB tracks */
+ Word16 step, /* (i): step size from one pulse position to the next
+ in one track */
+ Flag *pOverflow
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _COR_H_X2_H_ */
+
diff --git a/media/codecs/amrnb/enc/src/corrwght_tab.cpp b/media/codecs/amrnb/enc/src/corrwght_tab.cpp
new file mode 100644
index 0000000..b3ed02d
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/corrwght_tab.cpp
@@ -0,0 +1,199 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+
+
+
+ Filename: /audio/gsm_amr/c/src/corrwght_tab.c
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the tables for correlation weights
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "p_ol_wgh.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here. Include conditional
+ ; compile variables also.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; [Variable declaration - defined here and used outside this module]
+ ----------------------------------------------------------------------------*/
+ const Word16 corrweight[251] =
+ {
+ 20473, 20506, 20539, 20572, 20605, 20644, 20677,
+ 20716, 20749, 20788, 20821, 20860, 20893, 20932,
+ 20972, 21011, 21050, 21089, 21129, 21168, 21207,
+ 21247, 21286, 21332, 21371, 21417, 21456, 21502,
+ 21542, 21588, 21633, 21679, 21725, 21771, 21817,
+ 21863, 21909, 21961, 22007, 22059, 22105, 22158,
+ 22210, 22263, 22315, 22367, 22420, 22472, 22531,
+ 22584, 22643, 22702, 22761, 22820, 22879, 22938,
+ 23003, 23062, 23128, 23193, 23252, 23324, 23390,
+ 23455, 23527, 23600, 23665, 23744, 23816, 23888,
+ 23967, 24045, 24124, 24202, 24288, 24366, 24451,
+ 24537, 24628, 24714, 24805, 24904, 24995, 25094,
+ 25192, 25297, 25395, 25500, 25611, 25723, 25834,
+ 25952, 26070, 26188, 26313, 26444, 26575, 26706,
+ 26844, 26988, 27132, 27283, 27440, 27597, 27761,
+ 27931, 28108, 28285, 28475, 28665, 28869, 29078,
+ 29295, 29524, 29760, 30002, 30258, 30527, 30808,
+ 31457, 32767, 32767, 32767, 32767, 32767,
+ 32767, 32767, 31457, 30808, 30527, 30258, 30002,
+ 29760, 29524, 29295, 29078, 28869, 28665, 28475,
+ 28285, 28108, 27931, 27761, 27597, 27440, 27283,
+ 27132, 26988, 26844, 26706, 26575, 26444, 26313,
+ 26188, 26070, 25952, 25834, 25723, 25611, 25500,
+ 25395, 25297, 25192, 25094, 24995, 24904, 24805,
+ 24714, 24628, 24537, 24451, 24366, 24288, 24202,
+ 24124, 24045, 23967, 23888, 23816, 23744, 23665,
+ 23600, 23527, 23455, 23390, 23324, 23252, 23193,
+ 23128, 23062, 23003, 22938, 22879, 22820, 22761,
+ 22702, 22643, 22584, 22531, 22472, 22420, 22367,
+ 22315, 22263, 22210, 22158, 22105, 22059, 22007,
+ 21961, 21909, 21863, 21817, 21771, 21725, 21679,
+ 21633, 21588, 21542, 21502, 21456, 21417, 21371,
+ 21332, 21286, 21247, 21207, 21168, 21129, 21089,
+ 21050, 21011, 20972, 20932, 20893, 20860, 20821,
+ 20788, 20749, 20716, 20677, 20644, 20605, 20572,
+ 20539, 20506, 20473, 20434, 20401, 20369, 20336
+ };
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ None
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] corrwght.tab, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/enc/src/dtx_enc.cpp b/media/codecs/amrnb/enc/src/dtx_enc.cpp
new file mode 100644
index 0000000..2ccb777
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/dtx_enc.cpp
@@ -0,0 +1,1163 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/dtx_enc.c
+ Funtions: dtx_enc_init
+ dtx_enc_reset
+ dtx_enc_exit
+ dtx_enc
+ dtx_buffer
+ tx_dtx_handler
+
+ Date: 06/08/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template. First attempt at
+ optimizing C code.
+
+ Description: Updated file per comments gathered from Phase 2/3 review.
+ Synched up with new template (Inputs/Outputs section). Deleted
+ lines leftover from original code prior to the code section of
+ dtx_enc_exit function. Deleted confusing comment in the log_en
+ calculation in dtx_enc function. Restructured IF statement in
+ the calculation of the sum of squares of speech signals in
+ dtx_buffer.
+
+ Description: Added setting of Overflow flag in inlined code.
+
+ Description: Synchronized file with UTMS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Modified FOR loops to count down.
+ 2. Fixed typecasting issue with TI C compiler.
+ 3. Fixed comment in dtx_enc pseudo-code.
+ 4. Added dtx_enc code comment pertaining to possible assembly
+ implementation.
+
+ Description: Added calls to add() in tx_dtx_handler. Updated copyright year.
+
+ Description: Pass in pointer to overflow flag to all functions requiring this
+ flag. This is to make the library EPOC compatible.
+
+ Description: For dtx_enc_reset() only
+ 1. Replaced copy() with memcpy.
+ 2. Eliminated include file copy.h
+ 3. Eliminated printf statement
+ For dtx_buffer()
+ 1. Replaced copy() with memcpy.
+ 2. Eliminated math operations that unnecessary checked for
+ saturation, in some cases this by shifting before adding and
+ in other cases by evaluating the operands
+ 3. Unrolled loop to speed up execution
+
+ Description: For dtx_buffer()
+ 1. Modified scaling and added check for saturation. Previous
+ scaling was correct but altered precision, this cause bit
+ exactness test failure.
+
+ Description: For dtx_buffer()
+ 1. Modified scaling and saturation checks. Previous
+ scaling was correct but altered precision, this cause bit
+ exactness test failure for dtx vad2.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the various functions that perform the computation of the
+ Silence Indicator (SID) parameters when in Discontinuous Transmission (DTX)
+ mode.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <string.h>
+
+#include "dtx_enc.h"
+#include "q_plsf.h"
+#include "typedef.h"
+#include "mode.h"
+#include "basic_op.h"
+#include "log2.h"
+#include "lsp_lsf.h"
+#include "reorder.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+extern Word32 L_add(Word32 L_var1, Word32 L_var2, Flag *pOverflow);
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_enc_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to an array of pointers to structures of type
+ dtx_encState
+
+ Outputs:
+ pointer pointed to by st is set to the address of the allocated
+ memory
+
+ Returns:
+ return_value = 0, if initialization was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function allocates the state memory used by the dtx_enc function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int dtx_enc_init (dtx_encState **st)
+{
+ dtx_encState* s;
+
+ if (st == (dtx_encState **) NULL){
+ fprintf(stderr, "dtx_enc_init: invalid parameter\n");
+ return -1;
+ }
+
+ *st = NULL;
+
+ // allocate memory
+ if ((s= (dtx_encState *) malloc(sizeof(dtx_encState))) == NULL){
+ fprintf(stderr, "dtx_enc_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ dtx_enc_reset(s);
+ *st = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 dtx_enc_init(dtx_encState **st)
+{
+ dtx_encState* s;
+
+ if (st == (dtx_encState **) NULL)
+ {
+ return(-1);
+ }
+
+ *st = NULL;
+
+ /* allocate memory */
+ if ((s = (dtx_encState *) malloc(sizeof(dtx_encState))) == NULL)
+ {
+ return(-1);
+ }
+
+ dtx_enc_reset(s);
+ *st = s;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_enc_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structures of type dtx_encState
+
+ Outputs:
+ structure pointed to by st is initialized to its reset value
+
+ Returns:
+ return_value = 1, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ lsp_init_data = table containing LSP initialization values;
+ table elements are constants of type Word16;
+ table length is M
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes the fields of the state memory used by dtx_enc
+ to their reset values.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int dtx_enc_reset (dtx_encState *st)
+{
+ Word16 i;
+
+ if (st == (dtx_encState *) NULL){
+ fprintf(stderr, "dtx_enc_reset: invalid parameter\n");
+ return -1;
+ }
+
+ st->hist_ptr = 0;
+ st->log_en_index = 0;
+ st->init_lsf_vq_index = 0;
+ st->lsp_index[0] = 0;
+ st->lsp_index[1] = 0;
+ st->lsp_index[2] = 0;
+
+ // Init lsp_hist[]
+ for(i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ Copy(lsp_init_data, &st->lsp_hist[i * M], M);
+ }
+
+ // Reset energy history
+ Set_zero(st->log_en_hist, M);
+
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ st->decAnaElapsedCount = 32767;
+
+ return 1;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 dtx_enc_reset(dtx_encState *st)
+{
+ Word16 i;
+
+ if (st == (dtx_encState *) NULL)
+ {
+ return(-1);
+ }
+
+ st->hist_ptr = 0;
+ st->log_en_index = 0;
+ st->init_lsf_vq_index = 0;
+ st->lsp_index[0] = 0;
+ st->lsp_index[1] = 0;
+ st->lsp_index[2] = 0;
+
+ /* Init lsp_hist[] */
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ memcpy(&st->lsp_hist[i * M], lsp_init_data, M*sizeof(Word16));
+ }
+
+ /* Reset energy history */
+ memset(st->log_en_hist, 0, sizeof(Word16)*M);
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ st->decAnaElapsedCount = 32767;
+
+ return(1);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_enc_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to an array of pointers to structures of type
+ dtx_encState
+
+ Outputs:
+ st points to the NULL address
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function deallocates the state memory used by dtx_enc function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void dtx_enc_exit (dtx_encState **st)
+{
+ if (st == NULL || *st == NULL)
+ return;
+
+ // deallocate memory
+ free(*st);
+ *st = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void dtx_enc_exit(dtx_encState **st)
+{
+ if (st == NULL || *st == NULL)
+ {
+ return;
+ }
+
+ /* deallocate memory */
+ free(*st);
+ *st = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_enc
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structures of type dtx_encState
+ computeSidFlag = compute SID flag of type Word16
+ qSt = pointer to structures of type Q_plsfState
+ predState = pointer to structures of type gc_predState
+ anap = pointer to an array of pointers to analysis parameters of
+ type Word16
+
+ Outputs:
+ structure pointed to by st contains the newly calculated SID
+ parameters
+ structure pointed to by predState contains the new logarithmic frame
+ energy
+ pointer pointed to by anap points to the location of the new
+ logarithmic frame energy and new LSPs
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates the SID parameters when in the DTX mode.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int dtx_enc(dtx_encState *st, // i/o : State struct
+ Word16 computeSidFlag, // i : compute SID
+ Q_plsfState *qSt, // i/o : Qunatizer state struct
+ gc_predState* predState, // i/o : State struct
+ Word16 **anap // o : analysis parameters
+ )
+{
+ Word16 i,j;
+ Word16 log_en;
+ Word16 lsf[M];
+ Word16 lsp[M];
+ Word16 lsp_q[M];
+ Word32 L_lsp[M];
+
+ // VOX mode computation of SID parameters
+ if ((computeSidFlag != 0) ||
+ (st->log_en_index == 0))
+ {
+ // compute new SID frame if safe i.e don't
+ // compute immediately after a talk spurt
+ log_en = 0;
+ for (i = 0; i < M; i++)
+ {
+ L_lsp[i] = 0;
+ }
+
+ // average energy and lsp
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ log_en = add(log_en,
+ shr(st->log_en_hist[i],2));
+
+ for (j = 0; j < M; j++)
+ {
+ L_lsp[j] = L_add(L_lsp[j],
+ L_deposit_l(st->lsp_hist[i * M + j]));
+ }
+ }
+
+ log_en = shr(log_en, 1);
+ for (j = 0; j < M; j++)
+ {
+ lsp[j] = extract_l(L_shr(L_lsp[j], 3)); // divide by 8
+ }
+
+ // quantize logarithmic energy to 6 bits
+ st->log_en_index = add(log_en, 2560); // +2.5 in Q10
+ st->log_en_index = add(st->log_en_index, 128); // add 0.5/4 in Q10
+ st->log_en_index = shr(st->log_en_index, 8);
+
+ if (sub(st->log_en_index, 63) > 0)
+ {
+ st->log_en_index = 63;
+ }
+ if (st->log_en_index < 0)
+ {
+ st->log_en_index = 0;
+ }
+
+ // update gain predictor memory
+ log_en = shl(st->log_en_index, -2+10); // Q11 and divide by 4
+ log_en = sub(log_en, 2560); // add 2.5 in Q11
+
+ log_en = sub(log_en, 9000);
+ if (log_en > 0)
+ {
+ log_en = 0;
+ }
+ if (sub(log_en, -14436) < 0)
+ {
+ log_en = -14436;
+ }
+
+ // past_qua_en for other modes than MR122
+ predState->past_qua_en[0] = log_en;
+ predState->past_qua_en[1] = log_en;
+ predState->past_qua_en[2] = log_en;
+ predState->past_qua_en[3] = log_en;
+
+ // scale down by factor 20*log10(2) in Q15
+ log_en = mult(5443, log_en);
+
+ // past_qua_en for mode MR122
+ predState->past_qua_en_MR122[0] = log_en;
+ predState->past_qua_en_MR122[1] = log_en;
+ predState->past_qua_en_MR122[2] = log_en;
+ predState->past_qua_en_MR122[3] = log_en;
+
+ // make sure that LSP's are ordered
+ Lsp_lsf(lsp, lsf, M);
+ Reorder_lsf(lsf, LSF_GAP, M);
+ Lsf_lsp(lsf, lsp, M);
+
+ // Quantize lsp and put on parameter list
+ Q_plsf_3(qSt, MRDTX, lsp, lsp_q, st->lsp_index,
+ &st->init_lsf_vq_index);
+ }
+
+ *(*anap)++ = st->init_lsf_vq_index; // 3 bits
+
+ *(*anap)++ = st->lsp_index[0]; // 8 bits
+ *(*anap)++ = st->lsp_index[1]; // 9 bits
+ *(*anap)++ = st->lsp_index[2]; // 9 bits
+
+
+ *(*anap)++ = st->log_en_index; // 6 bits
+ // = 35 bits
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void dtx_enc(dtx_encState *st, /* i/o : State struct */
+ Word16 computeSidFlag, /* i : compute SID */
+ Q_plsfState *qSt, /* i/o : Qunatizer state struct */
+ gc_predState* predState, /* i/o : State struct */
+ Word16 **anap, /* o : analysis parameters */
+ Flag *pOverflow /* i/o : overflow indicator */
+ )
+{
+ Word16 i, j;
+ Word16 temp;
+ Word16 log_en;
+ Word16 lsf[M];
+ Word16 lsp[M];
+ Word16 lsp_q[M];
+ Word32 L_lsp[M];
+
+ /* VOX mode computation of SID parameters */
+
+ if ((computeSidFlag != 0) ||
+ (st->log_en_index == 0))
+ {
+ /* compute new SID frame if safe i.e don't
+ * compute immediately after a talk spurt */
+ log_en = 0;
+ for (i = M - 1; i >= 0; i--)
+ {
+ L_lsp[i] = 0;
+ }
+
+ /* average energy and lsp */
+ for (i = DTX_HIST_SIZE - 1; i >= 0; i--)
+ {
+ if (st->log_en_hist[i] < 0)
+ {
+ temp = ~((~(st->log_en_hist[i])) >> 2);
+ }
+ else
+ {
+ temp = st->log_en_hist[i] >> 2;
+ }
+ log_en = add(log_en, temp, pOverflow);
+
+ for (j = M - 1; j >= 0; j--)
+ {
+ L_lsp[j] = L_add(L_lsp[j],
+ (Word32)(st->lsp_hist[i * M + j]),
+ pOverflow);
+ }
+ }
+
+ if (log_en < 0)
+ {
+ log_en = ~((~log_en) >> 1);
+ }
+ else
+ {
+ log_en = log_en >> 1;
+ }
+
+ for (j = M - 1; j >= 0; j--)
+ {
+ /* divide by 8 */
+ if (L_lsp[j] < 0)
+ {
+ lsp[j] = (Word16)(~((~L_lsp[j]) >> 3));
+ }
+ else
+ {
+ lsp[j] = (Word16)(L_lsp[j] >> 3);
+ }
+ }
+
+ /* quantize logarithmic energy to 6 bits */
+ /* +2.5 in Q10 */
+ st->log_en_index = add(log_en, 2560, pOverflow);
+ /* add 0.5/4 in Q10 */
+ st->log_en_index = add(st->log_en_index, 128, pOverflow);
+ if (st->log_en_index < 0)
+ {
+ st->log_en_index = ~((~st->log_en_index) >> 8);
+ }
+ else
+ {
+ st->log_en_index = st->log_en_index >> 8;
+ }
+
+ /*---------------------------------------------*/
+ /* Limit to max and min allowable 6-bit values */
+ /* Note: For assembly implementation, use the */
+ /* following: */
+ /* if(st->long_en_index >> 6 != 0) */
+ /* { */
+ /* if(st->long_en_index < 0) */
+ /* { */
+ /* st->long_en_index = 0 */
+ /* } */
+ /* else */
+ /* { */
+ /* st->long_en_index = 63 */
+ /* } */
+ /* } */
+ /*---------------------------------------------*/
+ if (st->log_en_index > 63)
+ {
+ st->log_en_index = 63;
+ }
+ else if (st->log_en_index < 0)
+ {
+ st->log_en_index = 0;
+ }
+
+ /* update gain predictor memory */
+ /* Q11 and divide by 4 */
+ log_en = (Word16)(((Word32) st->log_en_index) << (-2 + 10));
+
+ log_en = sub(log_en, 11560, pOverflow);
+
+ if (log_en > 0)
+ {
+ log_en = 0;
+ }
+ else if (log_en < -14436)
+ {
+ log_en = -14436;
+ }
+
+ /* past_qua_en for other modes than MR122 */
+ predState->past_qua_en[0] = log_en;
+ predState->past_qua_en[1] = log_en;
+ predState->past_qua_en[2] = log_en;
+ predState->past_qua_en[3] = log_en;
+
+ /* scale down by factor 20*log10(2) in Q15 */
+ log_en = (Word16)(((Word32)(5443 * log_en)) >> 15);
+
+ /* past_qua_en for mode MR122 */
+ predState->past_qua_en_MR122[0] = log_en;
+ predState->past_qua_en_MR122[1] = log_en;
+ predState->past_qua_en_MR122[2] = log_en;
+ predState->past_qua_en_MR122[3] = log_en;
+
+ /* make sure that LSP's are ordered */
+ Lsp_lsf(lsp, lsf, M, pOverflow);
+ Reorder_lsf(lsf, LSF_GAP, M, pOverflow);
+ Lsf_lsp(lsf, lsp, M, pOverflow);
+
+ /* Quantize lsp and put on parameter list */
+ Q_plsf_3(qSt, MRDTX, lsp, lsp_q, st->lsp_index,
+ &st->init_lsf_vq_index, pOverflow);
+ }
+
+ *(*anap)++ = st->init_lsf_vq_index; /* 3 bits */
+ *(*anap)++ = st->lsp_index[0]; /* 8 bits */
+ *(*anap)++ = st->lsp_index[1]; /* 9 bits */
+ *(*anap)++ = st->lsp_index[2]; /* 9 bits */
+ *(*anap)++ = st->log_en_index; /* 6 bits */
+ /* = 35 bits */
+
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: dtx_buffer
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structures of type dtx_encState
+ lsp_new = LSP vector whose elements are of type Word16; vector
+ length is M
+ speech = vector of speech samples of type Word16; vector length is
+ BFR_SIZE_GSM
+
+ Outputs:
+ structure pointed to by st contains the new LSPs and logarithmic
+ frame energy
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function handles the DTX buffer.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int dtx_buffer(dtx_encState *st, // i/o : State struct
+ Word16 lsp_new[], // i : LSP vector
+ Word16 speech[] // i : speech samples
+)
+{
+ Word16 i;
+ Word32 L_frame_en;
+ Word16 log_en_e;
+ Word16 log_en_m;
+ Word16 log_en;
+
+ // update pointer to circular buffer
+ st->hist_ptr = add(st->hist_ptr, 1);
+ if (sub(st->hist_ptr, DTX_HIST_SIZE) == 0)
+ {
+ st->hist_ptr = 0;
+ }
+
+ // copy lsp vector into buffer
+ Copy(lsp_new, &st->lsp_hist[st->hist_ptr * M], M);
+
+ // compute log energy based on frame energy
+ L_frame_en = 0; // Q0
+ for (i=0; i < L_FRAME; i++)
+ {
+ L_frame_en = L_mac(L_frame_en, speech[i], speech[i]);
+ }
+ Log2(L_frame_en, &log_en_e, &log_en_m);
+
+ // convert exponent and mantissa to Word16 Q10
+ log_en = shl(log_en_e, 10); // Q10
+ log_en = add(log_en, shr(log_en_m, 15-10));
+
+ // divide with L_FRAME i.e subtract with log2(L_FRAME) = 7.32193
+ log_en = sub(log_en, 8521);
+
+ // insert into log energy buffer with division by 2
+ log_en = shr(log_en, 1);
+ st->log_en_hist[st->hist_ptr] = log_en; // Q10
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void dtx_buffer(dtx_encState *st, /* i/o : State struct */
+ Word16 lsp_new[], /* i : LSP vector */
+ Word16 speech[], /* i : speech samples */
+ Flag *pOverflow /* i/o : overflow indicator */
+ )
+{
+
+ Word16 i;
+ Word32 L_frame_en;
+ Word32 L_temp;
+ Word16 log_en_e;
+ Word16 log_en_m;
+ Word16 log_en;
+ Word16 *p_speech = &speech[0];
+
+ /* update pointer to circular buffer */
+ st->hist_ptr += 1;
+
+ if (st->hist_ptr == DTX_HIST_SIZE)
+ {
+ st->hist_ptr = 0;
+ }
+
+ /* copy lsp vector into buffer */
+ memcpy(&st->lsp_hist[st->hist_ptr * M], lsp_new, M*sizeof(Word16));
+
+ /* compute log energy based on frame energy */
+ L_frame_en = 0; /* Q0 */
+
+ for (i = L_FRAME; i != 0; i--)
+ {
+ L_frame_en += (((Word32) * p_speech) * *(p_speech)) << 1;
+ p_speech++;
+ if (L_frame_en < 0)
+ {
+ L_frame_en = MAX_32;
+ break;
+ }
+ }
+
+ Log2(L_frame_en, &log_en_e, &log_en_m, pOverflow);
+
+ /* convert exponent and mantissa to Word16 Q10 */
+ /* Q10 */
+ L_temp = ((Word32) log_en_e) << 10;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *pOverflow = 1;
+ log_en = (log_en_e > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ log_en = (Word16) L_temp;
+ }
+
+ log_en += log_en_m >> (15 - 10);
+
+ /* divide with L_FRAME i.e subtract with log2(L_FRAME) = 7.32193 */
+ log_en -= 8521;
+
+ /* insert into log energy buffer with division by 2 */
+
+ st->log_en_hist[st->hist_ptr] = log_en >> 1; /* Q10 */
+
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: tx_dtx_handler
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structures of type dtx_encState
+ vad_flag = VAD decision flag of type Word16
+ usedMode = pointer to the currently used mode of type enum Mode
+
+ Outputs:
+ structure pointed to by st contains the newly calculated speech
+ hangover
+
+ Returns:
+ compute_new_sid_possible = flag to indicate a change in the
+ used mode; store type is Word16
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function adds extra speech hangover to analyze speech on the decoding
+ side.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 tx_dtx_handler(dtx_encState *st, // i/o : State struct
+ Word16 vad_flag, // i : vad decision
+ enum Mode *usedMode // i/o : mode changed or not
+ )
+{
+ Word16 compute_new_sid_possible;
+
+ // this state machine is in synch with the GSMEFR txDtx machine
+ st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1);
+
+ compute_new_sid_possible = 0;
+
+ if (vad_flag != 0)
+ {
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ }
+ else
+ { // non-speech
+ if (st->dtxHangoverCount == 0)
+ { // out of decoder analysis hangover
+ st->decAnaElapsedCount = 0;
+ *usedMode = MRDTX;
+ compute_new_sid_possible = 1;
+ }
+ else
+ { // in possible analysis hangover
+ st->dtxHangoverCount = sub(st->dtxHangoverCount, 1);
+
+ // decAnaElapsedCount + dtxHangoverCount < DTX_ELAPSED_FRAMES_THRESH
+ if (sub(add(st->decAnaElapsedCount, st->dtxHangoverCount),
+ DTX_ELAPSED_FRAMES_THRESH) < 0)
+ {
+ *usedMode = MRDTX;
+ // if short time since decoder update, do not add extra HO
+ }
+ // else
+ // override VAD and stay in
+ // speech mode *usedMode
+ // and add extra hangover
+ }
+ }
+
+ return compute_new_sid_possible;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 tx_dtx_handler(dtx_encState *st, /* i/o : State struct */
+ Word16 vad_flag, /* i : vad decision */
+ enum Mode *usedMode, /* i/o : mode changed or not */
+ Flag *pOverflow /* i/o : overflow indicator */
+ )
+{
+ Word16 compute_new_sid_possible;
+ Word16 count;
+
+ /* this state machine is in synch with the GSMEFR txDtx machine */
+ st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1, pOverflow);
+
+ compute_new_sid_possible = 0;
+
+ if (vad_flag != 0)
+ {
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ }
+ else
+ { /* non-speech */
+ if (st->dtxHangoverCount == 0)
+ { /* out of decoder analysis hangover */
+ st->decAnaElapsedCount = 0;
+ *usedMode = MRDTX;
+ compute_new_sid_possible = 1;
+ }
+ else
+ { /* in possible analysis hangover */
+ st->dtxHangoverCount -= 1;
+
+ /* decAnaElapsedCount + dtxHangoverCount < */
+ /* DTX_ELAPSED_FRAMES_THRESH */
+ count = add(st->decAnaElapsedCount, st->dtxHangoverCount,
+ pOverflow);
+ if (count < DTX_ELAPSED_FRAMES_THRESH)
+ {
+ *usedMode = MRDTX;
+ /* if short time since decoder update, */
+ /* do not add extra HO */
+ }
+ }
+ }
+
+ return(compute_new_sid_possible);
+}
diff --git a/media/codecs/amrnb/enc/src/dtx_enc.h b/media/codecs/amrnb/enc/src/dtx_enc.h
new file mode 100644
index 0000000..5bb168d
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/dtx_enc.h
@@ -0,0 +1,209 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/dtx_enc.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : dtx_enc.h
+ Purpose : DTX mode computation of SID parameters
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef dtx_enc_h
+#define dtx_enc_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "q_plsf.h"
+#include "gc_pred.h"
+#include "mode.h"
+#include "dtx_common_def.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+ extern const Word16 lsp_init_data[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 lsp_hist[M * DTX_HIST_SIZE];
+ Word16 log_en_hist[DTX_HIST_SIZE];
+ Word16 hist_ptr;
+ Word16 log_en_index;
+ Word16 init_lsf_vq_index;
+ Word16 lsp_index[3];
+
+ /* DTX handler stuff */
+ Word16 dtxHangoverCount;
+ Word16 decAnaElapsedCount;
+
+ } dtx_encState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /*
+ **************************************************************************
+ * Function : dtx_enc_init
+ * Purpose : Allocates memory and initializes state variables
+ * Description : Stores pointer to filter status struct in *st. This
+ * pointer has to be passed to dtx_enc in each call.
+ * Returns : 0 on success
+ *
+ **************************************************************************
+ */
+ Word16 dtx_enc_init(dtx_encState **st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : dtx_enc_reset
+ * Purpose : Resets state memory
+ * Returns : 0 on success
+ *
+ **************************************************************************
+ */
+ Word16 dtx_enc_reset(dtx_encState *st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : dtx_enc_exit
+ * Purpose : The memory used for state memory is freed
+ * Description : Stores NULL in *st
+ *
+ **************************************************************************
+ */
+ void dtx_enc_exit(dtx_encState **st);
+
+ /*
+ **************************************************************************
+ *
+ * Function : dtx_enc
+ * Purpose :
+ * Description :
+ *
+ **************************************************************************
+ */
+ void dtx_enc(dtx_encState *st, /* i/o : State struct */
+ Word16 computeSidFlag, /* i : compute SID */
+ Q_plsfState *qSt, /* i/o : Qunatizer state struct */
+ gc_predState* predState, /* i/o : State struct */
+ Word16 **anap, /* o : analysis parameters */
+ Flag *pOverflow /* i/o : overflow indicator */
+ );
+
+ /*
+ **************************************************************************
+ *
+ * Function : dtx_buffer
+ * Purpose : handles the DTX buffer
+ *
+ **************************************************************************
+ */
+ void dtx_buffer(dtx_encState *st, /* i/o : State struct */
+ Word16 lsp_new[], /* i : LSP vector */
+ Word16 speech[], /* i : speech samples */
+ Flag *pOverflow /* i/o : overflow indicator */
+ );
+
+ /*
+ **************************************************************************
+ *
+ * Function : tx_dtx_handler
+ * Purpose : adds extra speech hangover to analyze speech on the decoding side.
+ * Description : returns 1 when a new SID analysis may be made
+ * otherwise it adds the appropriate hangover after a sequence
+ * with out updates of SID parameters .
+ *
+ **************************************************************************
+ */
+ Word16 tx_dtx_handler(dtx_encState *st, /* i/o : State struct */
+ Word16 vad_flag, /* i : vad decision */
+ enum Mode *usedMode, /* i/o : mode changed or not */
+ Flag *pOverflow /* i/o : overflow indicator */
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _dtx_enc_h_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/enc_lag3.cpp b/media/codecs/amrnb/enc/src/enc_lag3.cpp
new file mode 100644
index 0000000..a1fc008
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/enc_lag3.cpp
@@ -0,0 +1,356 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/enc_lag3.c
+ Functions:
+
+ Date: 01/28/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "enc_lag3.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: enc_lag3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ T0 = Pitch delay of type Word16
+ T0_frac = Fractional pitch delay of type Word16
+ T0_prev = Integer pitch delay of last subframe of type Word16
+ T0_min = minimum of search range of type Word16
+ T0_max = maximum of search range of type Word16
+ delta_flag = Flag for 1st (or 3rd) subframe of type Word16
+ flag4 = Flag for encoding with 4 bits of type Word16
+ pOverflow = pointer indicating overflow of type Flag
+
+ Outputs:
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function implements the encoding of fractional pitch lag with
+ 1/3 resolution.
+
+ * FUNCTION: Enc_lag3
+ *
+ * PURPOSE: Encoding of fractional pitch lag with 1/3 resolution.
+ *
+ * DESCRIPTION:
+ * First and third subframes:
+ * --------------------------
+ * The pitch range is divided as follows:
+ * 19 1/3 to 84 2/3 resolution 1/3
+ * 85 to 143 resolution 1
+ *
+ * The period is encoded with 8 bits.
+ * For the range with fractions:
+ * index = (T-19)*3 + frac - 1;
+ * where T=[19..85] and frac=[-1,0,1]
+ * and for the integer only range
+ * index = (T - 85) + 197; where T=[86..143]
+ *
+ * Second and fourth subframes:
+ * ----------------------------
+ * For the 2nd and 4th subframes a resolution of 1/3 is always used,
+ * and the search range is relative to the lag in previous subframe.
+ * If t0 is the lag in the previous subframe then
+ * t_min=t0-5 and t_max=t0+4 and the range is given by
+ * t_min - 2/3 to t_max + 2/3
+ *
+ * The period in the 2nd (and 4th) subframe is encoded with 5 bits:
+ * index = (T-(t_min-1))*3 + frac - 1;
+ * where T=[t_min-1..t_max+1]
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ enc_lag3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 index, i, tmp_ind, uplag;
+ Word16 tmp_lag;
+
+ if (delta_flag == 0)
+ { // if 1st or 3rd subframe
+
+ // encode pitch delay (with fraction)
+
+ if (sub (T0, 85) <= 0)
+ {
+ // index = T0*3 - 58 + T0_frac
+ i = add (add (T0, T0), T0);
+ index = add (sub (i, 58), T0_frac);
+ }
+ else
+ {
+ index = add (T0, 112);
+ }
+ }
+ else
+ { // if second or fourth subframe
+ if (flag4 == 0) {
+
+ // 'normal' encoding: either with 5 or 6 bit resolution
+
+ // index = 3*(T0 - T0_min) + 2 + T0_frac
+ i = sub (T0, T0_min);
+ i = add (add (i, i), i);
+ index = add (add (i, 2), T0_frac);
+ }
+ else {
+
+ // encoding with 4 bit resolution
+
+ tmp_lag = T0_prev;
+
+ if ( sub( sub(tmp_lag, T0_min), 5) > 0)
+ tmp_lag = add (T0_min, 5);
+ if ( sub( sub(T0_max, tmp_lag), 4) > 0)
+ tmp_lag = sub (T0_max, 4);
+
+ uplag = add (add (add (T0, T0), T0), T0_frac);
+
+ i = sub (tmp_lag, 2);
+ tmp_ind = add (add (i, i), i);
+
+ if (sub (tmp_ind, uplag) >= 0) {
+ index = add (sub (T0, tmp_lag), 5);
+ }
+ else {
+
+ i = add (tmp_lag, 1);
+ i = add (add (i, i), i);
+
+ if (sub (i, uplag) > 0) {
+
+ index = add ( sub (uplag, tmp_ind), 3);
+ }
+ else {
+
+ index = add (sub (T0, tmp_lag), 11);
+ }
+ }
+
+ } // end if (encoding with 4 bit resolution)
+ } // end if (second of fourth subframe)
+
+ return index;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+Word16 Enc_lag3( /* o : Return index of encoding */
+ Word16 T0, /* i : Pitch delay */
+ Word16 T0_frac, /* i : Fractional pitch delay */
+ Word16 T0_prev, /* i : Integer pitch delay of last subframe */
+ Word16 T0_min, /* i : minimum of search range */
+ Word16 T0_max, /* i : maximum of search range */
+ Word16 delta_flag, /* i : Flag for 1st (or 3rd) subframe */
+ Word16 flag4, /* i : Flag for encoding with 4 bits */
+ Flag *pOverflow
+)
+{
+ Word16 index, i, tmp_ind, uplag;
+ Word16 tmp_lag;
+ Word16 temp1;
+ Word16 temp2;
+
+
+
+ if (delta_flag == 0)
+ { /* if 1st or 3rd subframe */
+
+ /* encode pitch delay (with fraction) */
+ temp1 = sub(T0, 85, pOverflow);
+ if (temp1 <= 0)
+ {
+ /* index = T0*3 - 58 + T0_frac */
+ temp2 = add(T0, T0, pOverflow);
+ i = add(temp2, T0, pOverflow);
+ temp2 = sub(i, 58, pOverflow);
+ index = add(temp2, T0_frac, pOverflow);
+ }
+ else
+ {
+ index = add(T0, 112, pOverflow);
+ }
+ }
+ else
+ { /* if second or fourth subframe */
+ if (flag4 == 0)
+ {
+
+ /* 'normal' encoding: either with 5 or 6 bit resolution */
+
+ /* index = 3*(T0 - T0_min) + 2 + T0_frac */
+ i = sub(T0, T0_min, pOverflow);
+ temp2 = add(i, i, pOverflow);
+ i = add(temp2, i, pOverflow);
+ temp2 = add(i, 2, pOverflow);
+ index = add(temp2, T0_frac, pOverflow);
+ }
+ else
+ {
+
+ /* encoding with 4 bit resolution */
+
+ tmp_lag = T0_prev;
+ temp1 = sub(tmp_lag, T0_min, pOverflow);
+ temp2 = sub(temp1, 5, pOverflow);
+ if (temp2 > 0)
+ tmp_lag = add(T0_min, 5, pOverflow);
+ temp1 = sub(T0_max, tmp_lag, pOverflow);
+ temp2 = sub(temp1, 4, pOverflow);
+ if (temp2 > 0)
+ tmp_lag = sub(T0_max, 4, pOverflow);
+
+ temp1 = add(T0, T0, pOverflow);
+ temp2 = add(temp1, T0, pOverflow);
+ uplag = add(temp2, T0_frac, pOverflow);
+
+ i = sub(tmp_lag, 2, pOverflow);
+ temp1 = add(i, i, pOverflow);
+ tmp_ind = add(temp1, i, pOverflow);
+
+ temp1 = sub(tmp_ind, uplag, pOverflow);
+ if (temp1 >= 0)
+ {
+ temp1 = sub(T0, tmp_lag, pOverflow);
+ index = add(temp1, 5, pOverflow);
+ }
+ else
+ {
+
+ i = add(tmp_lag, 1, pOverflow);
+ temp1 = add(i, i, pOverflow);
+ i = add(temp1, i, pOverflow);
+
+ if (sub(i, uplag, pOverflow) > 0)
+ {
+ temp1 = sub(uplag, tmp_ind, pOverflow);
+ index = add(temp1, 3, pOverflow);
+ }
+ else
+ {
+ temp1 = sub(T0, tmp_lag, pOverflow);
+ index = add(temp1, 11, pOverflow);
+ }
+ }
+
+ } /* end if (encoding with 4 bit resolution) */
+ } /* end if (second of fourth subframe) */
+
+ return index;
+}
+
+
+
diff --git a/media/codecs/amrnb/enc/src/enc_lag3.h b/media/codecs/amrnb/enc/src/enc_lag3.h
new file mode 100644
index 0000000..949cd97
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/enc_lag3.h
@@ -0,0 +1,125 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/enc_lag3.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : enc_lag3.h
+ Purpose : Encoding of fractional pitch lag with 1/3 resolution.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _ENC_LAG3_H_
+#define _ENC_LAG3_H_
+#define enc_lag3_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 past_gain;
+ } agcState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16
+ Enc_lag3( /* o : Return index of encoding */
+ Word16 T0, /* i : Pitch delay */
+ Word16 T0_frac, /* i : Fractional pitch delay */
+ Word16 T0_prev, /* i : Integer pitch delay of last subframe */
+ Word16 T0_min, /* i : minimum of search range */
+ Word16 T0_max, /* i : maximum of search range */
+ Word16 delta_flag, /* i : Flag for 1st (or 3rd) subframe */
+ Word16 flag4, /* i : Flag for encoding with 4 bits */
+ Flag *pOverflow
+ );
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ENC_LAG3_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/enc_lag6.cpp b/media/codecs/amrnb/enc/src/enc_lag6.cpp
new file mode 100644
index 0000000..2c7863e
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/enc_lag6.cpp
@@ -0,0 +1,230 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/enc_lag6.c
+ Functions:
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description:
+ (1) Removed optimization -- mult(i, 6, pOverflow) is NOT the same as adding
+ i to itself 6 times. The reason is because the mult function does a
+ right shift by 15, which will obliterate smaller numbers.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "enc_lag6.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Enc_lag6
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ T0 -- Word16 -- Pitch delay
+ T0_frac -- Word16 -- Fractional pitch delay
+ T0_min -- Word16 -- minimum of search range
+ delta_flag -- Word16 -- Flag for 1st (or 3rd) subframe
+
+ Outputs:
+ pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ Word16 -- Return index of encoding
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Encoding of fractional pitch lag with 1/6 resolution.
+
+ DESCRIPTION:
+ First and third subframes:
+ --------------------------
+ The pitch range is divided as follows:
+ 17 3/6 to 94 3/6 resolution 1/6
+ 95 to 143 resolution 1
+
+ The period is encoded with 9 bits.
+ For the range with fractions:
+ index = (T-17)*6 + frac - 3;
+ where T=[17..94] and frac=[-2,-1,0,1,2,3]
+ and for the integer only range
+ index = (T - 95) + 463; where T=[95..143]
+
+ Second and fourth subframes:
+ ----------------------------
+ For the 2nd and 4th subframes a resolution of 1/6 is always used,
+ and the search range is relative to the lag in previous subframe.
+ If t0 is the lag in the previous subframe then
+ t_min=t0-5 and t_max=t0+4 and the range is given by
+ (t_min-1) 3/6 to (t_max) 3/6
+
+ The period in the 2nd (and 4th) subframe is encoded with 6 bits:
+ index = (T-(t_min-1))*6 + frac - 3;
+ where T=[t_min-1..t_max] and frac=[-2,-1,0,1,2,3]
+
+ Note that only 61 values are used. If the decoder receives 61, 62,
+ or 63 as the relative pitch index, it means that a transmission
+ error occurred and the pitch from previous subframe should be used.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ enc_lag6.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Enc_lag6( /* o : Return index of encoding */
+ Word16 T0, /* i : Pitch delay */
+ Word16 T0_frac, /* i : Fractional pitch delay */
+ Word16 T0_min, /* i : minimum of search range */
+ Word16 delta_flag, /* i : Flag for 1st (or 3rd) subframe */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 index;
+ Word16 i;
+ Word16 temp;
+
+ if (delta_flag == 0) /* if 1st or 3rd subframe */
+ {
+ /* encode pitch delay (with fraction) */
+ if (T0 <= 94)
+ {
+ /* index = T0*6 - 105 + T0_frac */
+ i = 6 * T0 - 105;
+
+ index = add(i, T0_frac, pOverflow);
+ }
+ else
+ {
+ index = add(T0, 368, pOverflow);
+ }
+
+ }
+ else
+ /* if second or fourth subframe */
+ {
+ /* index = 6*(T0-T0_min) + 3 + T0_frac */
+ temp = sub(T0, T0_min, pOverflow);
+
+ i = add(temp, temp, pOverflow);
+ i = add(temp, i, pOverflow);
+ i = add(i, i, pOverflow);
+
+ i = add(i, 3, pOverflow);
+
+ index = add(i, T0_frac, pOverflow);
+ }
+
+ return index;
+}
diff --git a/media/codecs/amrnb/enc/src/enc_lag6.h b/media/codecs/amrnb/enc/src/enc_lag6.h
new file mode 100644
index 0000000..0438321
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/enc_lag6.h
@@ -0,0 +1,122 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/enc_lag6.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, enc_lag6.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef enc_lag6_h
+#define enc_lag6_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 Enc_lag6( /* o : Return index of encoding */
+ Word16 T0, /* i : Pitch delay */
+ Word16 T0_frac, /* i : Fractional pitch delay */
+ Word16 T0_min, /* i : minimum of search range */
+ Word16 delta_flag, /* i : Flag for 1st (or 3rd) subframe */
+ Flag *pOverflow /* o : Overflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* enc_lag6_h */
+
+
diff --git a/media/codecs/amrnb/enc/src/enc_output_format_tab.cpp b/media/codecs/amrnb/enc/src/enc_output_format_tab.cpp
new file mode 100644
index 0000000..4551fd7
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/enc_output_format_tab.cpp
@@ -0,0 +1,232 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+ Pathname: .audio/gsm-amr/c/src/enc_output_format_tab.c
+
+ Date: 03/08/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved WMFBytesUsed and IF2BytesUsed tables from gsmamr_enc.h.
+ Changed their type definition to 'const int'. Renamed tables to
+ WmfEncBytesPerFrame and If2EncBytesPerFrame.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition.
+
+ Description: Put "extern" back.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This file contains the tables of the number of data bytes per codec mode in
+ both WMF and IF2 output formats.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] AMR Speech Codec Frame Structure, 3GPP TS 26.101 version 4.1.0 Release 4,
+ June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "amrencode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ /* Number of data bytes in an encoder frame for each codec mode */
+ /* for WMF output format. */
+ /* Each entry is the sum of the 3GPP frame type byte and the */
+ /* number of packed core AMR data bytes */
+ const Word16 WmfEncBytesPerFrame[16] =
+ {
+ 13, /* 4.75 */
+ 14, /* 5.15 */
+ 16, /* 5.90 */
+ 18, /* 6.70 */
+ 20, /* 7.40 */
+ 21, /* 7.95 */
+ 27, /* 10.2 */
+ 32, /* 12.2 */
+ 6, /* GsmAmr comfort noise */
+ 7, /* Gsm-Efr comfort noise */
+ 6, /* IS-641 comfort noise */
+ 6, /* Pdc-Efr comfort noise */
+ 0, /* future use */
+ 0, /* future use */
+ 0, /* future use */
+ 1 /* No transmission */
+ };
+
+
+ /* Number of data bytes in an encoder frame for each codec mode */
+ /* for IF2 output format */
+ const Word16 If2EncBytesPerFrame[16] =
+ {
+ 13, /* 4.75 */
+ 14, /* 5.15 */
+ 16, /* 5.90 */
+ 18, /* 6.70 */
+ 19, /* 7.40 */
+ 21, /* 7.95 */
+ 26, /* 10.2 */
+ 31, /* 12.2 */
+ 6, /* GsmAmr comfort noise */
+ 6, /* Gsm-Efr comfort noise */
+ 6, /* IS-641 comfort noise */
+ 6, /* Pdc-Efr comfort noise */
+ 0, /* future use */
+ 0, /* future use */
+ 0, /* future use */
+ 1 /* No transmission */
+ };
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
diff --git a/media/codecs/amrnb/enc/src/ets_to_if2.cpp b/media/codecs/amrnb/enc/src/ets_to_if2.cpp
new file mode 100644
index 0000000..01b8627
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ets_to_if2.cpp
@@ -0,0 +1,242 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: ./audio/gsm-amr/c/src/ets_to_if2.c
+ Funtions: ets_to_if2
+
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "frame_type_3gpp.h"
+#include "ets_to_if2.h"
+#include "typedef.h"
+#include "bitreorder_tab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ets_to_if2
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
+ ets_input_ptr = pointer to input encoded speech bits in ETS format (Word16)
+ if2_output_ptr = pointer to output encoded speech bits in IF2 format (UWord8)
+
+ Outputs:
+ if2_output_ptr = pointer to encoded speech bits in the IF2 format (UWord8)
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs a transformation on the data buffers. It converts the
+ data format from ETS (European Telecommunication Standard) to IF2. ETS format
+ has the encoded speech bits each separate with only one bit stored in each
+ word. IF2 is the storage format where the frame type is in the first four bits
+ of the first byte. The upper four bits of that byte contain the first four
+ encoded speech bits for the frame. The following bytes contain the rest of
+ the encoded speech bits. The final byte has padded zeros to make the frame
+ byte aligned.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void ets_to_if2(
+ enum Frame_Type_3GPP frame_type_3gpp,
+ Word16 *ets_input_ptr,
+ UWord8 *if2_output_ptr)
+{
+ Word16 i;
+ Word16 k;
+ Word16 j = 0;
+ Word16 *ptr_temp;
+ Word16 bits_left;
+ UWord8 accum;
+
+ if (frame_type_3gpp < AMR_SID)
+ {
+ if2_output_ptr[j++] = (UWord8)(frame_type_3gpp) |
+ (ets_input_ptr[reorderBits[frame_type_3gpp][0]] << 4) |
+ (ets_input_ptr[reorderBits[frame_type_3gpp][1]] << 5) |
+ (ets_input_ptr[reorderBits[frame_type_3gpp][2]] << 6) |
+ (ets_input_ptr[reorderBits[frame_type_3gpp][3]] << 7);
+
+ for (i = 4; i < numOfBits[frame_type_3gpp] - 7;)
+ {
+ if2_output_ptr[j] =
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]];
+ if2_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 1;
+ if2_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 2;
+ if2_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 3;
+ if2_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 4;
+ if2_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 5;
+ if2_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 6;
+ if2_output_ptr[j++] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 7;
+ }
+
+ bits_left = 4 + numOfBits[frame_type_3gpp] -
+ ((4 + numOfBits[frame_type_3gpp]) & 0xFFF8);
+
+ if (bits_left != 0)
+ {
+ if2_output_ptr[j] = 0;
+
+ for (k = 0; k < bits_left; k++)
+ {
+ if2_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << k;
+ }
+ }
+ }
+ else
+ {
+ if (frame_type_3gpp != AMR_NO_DATA)
+ {
+ /* First octet contains 3GPP frame type and */
+ /* first 4 bits of encoded parameters */
+ if2_output_ptr[j++] = (UWord8)(frame_type_3gpp) |
+ (ets_input_ptr[0] << 4) | (ets_input_ptr[1] << 5) |
+ (ets_input_ptr[2] << 6) | (ets_input_ptr[3] << 7);
+ ptr_temp = &ets_input_ptr[4];
+
+ bits_left = ((4 + numOfBits[frame_type_3gpp]) & 0xFFF8);
+
+ for (i = (bits_left - 7) >> 3; i > 0; i--)
+ {
+ accum = (UWord8) * (ptr_temp++);
+ accum |= (UWord8) * (ptr_temp++) << 1;
+ accum |= (UWord8) * (ptr_temp++) << 2;
+ accum |= (UWord8) * (ptr_temp++) << 3;
+ accum |= (UWord8) * (ptr_temp++) << 4;
+ accum |= (UWord8) * (ptr_temp++) << 5;
+ accum |= (UWord8) * (ptr_temp++) << 6;
+ accum |= (UWord8) * (ptr_temp++) << 7;
+
+ if2_output_ptr[j++] = accum;
+ }
+
+ bits_left = 4 + numOfBits[frame_type_3gpp] - bits_left;
+
+ if (bits_left != 0)
+ {
+ if2_output_ptr[j] = 0;
+
+ for (i = 0; i < bits_left; i++)
+ {
+ if2_output_ptr[j] |= (ptr_temp[i] << i);
+ }
+ }
+ }
+ else
+ {
+ /* When there is no data, LSnibble of first octet */
+ /* is the 3GPP frame type, MSnibble is zeroed out */
+ if2_output_ptr[j++] = (UWord8)(frame_type_3gpp);
+ }
+
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/ets_to_if2.h b/media/codecs/amrnb/enc/src/ets_to_if2.h
new file mode 100644
index 0000000..d85bcc9
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ets_to_if2.h
@@ -0,0 +1,121 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/include/src/ets_to_if2.h
+
+ Date: 01/23/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the ets_to_if2 function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef ETS_TO_IF2_H
+#define ETS_TO_IF2_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mode.h"
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void ets_to_if2(enum Frame_Type_3GPP mode,
+ Word16 *ets_input_ptr,
+ UWord8 *if2_output_ptr);
+
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/enc/src/ets_to_wmf.cpp b/media/codecs/amrnb/enc/src/ets_to_wmf.cpp
new file mode 100644
index 0000000..9da3fb8
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ets_to_wmf.cpp
@@ -0,0 +1,244 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/ets_to_wmf.c
+ Funtions: ets_to_wmf
+
+ Date: 01/23/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Modified code as per review comments regarding things such as
+ adding the tables in bitreorder_tab.c to the Global section of
+ the input/output section of the template and removing the #define
+ of 244 since it wasn't needed in this function.
+
+ Description: Fixed the loop that packs the last octet of the WMF output.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "ets_to_wmf.h"
+#include "typedef.h"
+#include "bitreorder_tab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ets_to_wmf
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
+ ets_input_ptr = pointer to input encoded speech bits in ETS format (Word16)
+ wmf_output_ptr = pointer to output encoded speech bits in WMF format(UWord8)
+
+ Outputs:
+ wmf_output_ptr = pointer to encoded speech bits in the WMF format (UWord8)
+
+ Returns:
+ None
+
+ Global Variables Used:
+ numOfBits = table of values that describe the number of bits per frame for
+ each 3GPP frame type mode. The table is type const Word16 and has
+ NUM_MODES elements. This table is located in bitreorder_tab.c.
+ reorderBits = table of pointers that point to tables used to reorder the
+ encoded speech bits when converting from ETS to WMF or IF2
+ format. The table is of type const Word16 * and contains
+ NUM_MODES-1 elements. This table is located in bitreorder_tab.c.
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs a transformation on the data buffers. It converts the
+ data format from ETS (European Telecommunication Standard) to WMF (wireless
+ multimedia forum). ETS format has the encoded speech bits each separate with
+ only one bit stored in each word. WMF is the storage format where the frame
+ type is in the first four bits of the first byte. This first byte has the
+ upper four bits as padded zeroes. The following bytes contain the rest of the
+ encoded speech bits. The final byte has padded zeros to make the frame byte
+ aligned.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void ets_to_wmf(
+ enum Frame_Type_3GPP frame_type_3gpp,
+ Word16 *ets_input_ptr,
+ UWord8 *wmf_output_ptr)
+{
+ Word16 i;
+ Word16 k = 0;
+ Word16 j = 0;
+ Word16 *ptr_temp;
+ Word16 bits_left;
+ UWord8 accum;
+
+ if (frame_type_3gpp < AMR_SID)
+ {
+ wmf_output_ptr[j++] = (UWord8)(frame_type_3gpp) & 0x0f;
+
+ for (i = 0; i < numOfBits[frame_type_3gpp] - 7;)
+ {
+ wmf_output_ptr[j] =
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 7;
+ wmf_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 6;
+ wmf_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 5;
+ wmf_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 4;
+ wmf_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 3;
+ wmf_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 2;
+ wmf_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 1;
+ wmf_output_ptr[j++] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]];
+ }
+
+ bits_left = numOfBits[frame_type_3gpp] -
+ (numOfBits[frame_type_3gpp] & 0xFFF8);
+
+ wmf_output_ptr[j] = 0;
+
+ for (k = 0; k < bits_left; k++)
+ {
+ wmf_output_ptr[j] |=
+ (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << (7 - k);
+
+ }
+ }
+ else
+ {
+ wmf_output_ptr[j++] = (UWord8)(frame_type_3gpp) & 0x0f;
+
+ ptr_temp = &ets_input_ptr[0];
+
+ for (i = numOfBits[frame_type_3gpp] - 7; i > 0; i -= 8)
+ {
+ accum = (UWord8) * (ptr_temp++) << 7;
+ accum |= (UWord8) * (ptr_temp++) << 6;
+ accum |= (UWord8) * (ptr_temp++) << 5;
+ accum |= (UWord8) * (ptr_temp++) << 4;
+ accum |= (UWord8) * (ptr_temp++) << 3;
+ accum |= (UWord8) * (ptr_temp++) << 2;
+ accum |= (UWord8) * (ptr_temp++) << 1;
+ accum |= (UWord8) * (ptr_temp++);
+
+ wmf_output_ptr[j++] = accum;
+ }
+
+ bits_left = numOfBits[frame_type_3gpp] -
+ (numOfBits[frame_type_3gpp] & 0xFFF8);
+
+ wmf_output_ptr[j] = 0;
+
+ for (i = 0; i < bits_left; i++)
+ {
+ wmf_output_ptr[j] |= *(ptr_temp++) << (7 - i);
+ }
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/ets_to_wmf.h b/media/codecs/amrnb/enc/src/ets_to_wmf.h
new file mode 100644
index 0000000..a018fcf
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ets_to_wmf.h
@@ -0,0 +1,123 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/include/src/ets_to_wmf.h
+
+ Date: 02/22/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Corrected the copyright year.
+
+ Description: Updated template to make it build in Symbian. Updated copyright
+ year.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the ets_to_wmf function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef ETS_TO_WMF_H
+#define ETS_TO_WMF_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "frame_type_3gpp.h"
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void ets_to_wmf(enum Frame_Type_3GPP frame_type_3gpp,
+ Word16 *ets_input_ptr,
+ UWord8 *wmf_output_ptr);
+
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/enc/src/g_adapt.cpp b/media/codecs/amrnb/enc/src/g_adapt.cpp
new file mode 100644
index 0000000..712a7fd
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/g_adapt.cpp
@@ -0,0 +1,522 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/g_adapt.c
+ Functions:
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "g_adapt.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "cnst.h"
+#include "gmed_n.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define LTP_GAIN_THR1 2721 /* 2721 Q13 = 0.3322 ~= 1.0 / (10*log10(2)) */
+#define LTP_GAIN_THR2 5443 /* 5443 Q13 = 0.6644 ~= 2.0 / (10*log10(2)) */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gain_adapt_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to GainAdaptState
+
+ Outputs:
+ st -- double ponter to GainAdaptState
+
+ Returns:
+ -1 if an error occurs during memory initialization
+ 0 if OK
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Allocates state memory and initializes state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ g_adapt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 gain_adapt_init(GainAdaptState **st)
+{
+ GainAdaptState* s;
+
+ if (st == (GainAdaptState **) NULL)
+ {
+ /* fprintf(stderr, "gain_adapt_init: invalid parameter\n"); */
+ return -1;
+ }
+ *st = NULL;
+
+ /* allocate memory */
+ if ((s = (GainAdaptState *) malloc(sizeof(GainAdaptState))) == NULL)
+ {
+ /* fprintf(stderr, "gain_adapt_init: can't malloc state structure\n"); */
+ return -1;
+ }
+ gain_adapt_reset(s);
+ *st = s;
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gain_adapt_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to GainAdaptState
+
+ Outputs:
+ st -- double ponter to GainAdaptState
+
+ Returns:
+ -1 if an error occurs
+ 0 if OK
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Initializes state memory to zero
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ g_adapt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 gain_adapt_reset(GainAdaptState *st)
+{
+ Word16 i;
+
+ if (st == (GainAdaptState *) NULL)
+ {
+ /* fprintf(stderr, "gain_adapt_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ st->onset = 0;
+ st->prev_alpha = 0;
+ st->prev_gc = 0;
+
+ for (i = 0; i < LTPG_MEM_SIZE; i++)
+ {
+ st->ltpg_mem[i] = 0;
+ }
+
+ return 0;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gain_adapt_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to GainAdaptState
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The memory used for state memory is freed
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ g_adapt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void gain_adapt_exit(GainAdaptState **st)
+{
+ if (st == NULL || *st == NULL)
+ return;
+
+ /* deallocate memory */
+ free(*st);
+ *st = NULL;
+
+ return;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gain_adapt
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to GainAdaptState
+ ltpg -- Word16 -- ltp coding gain (log2()), Q13
+ gain_cod -- Word16 -- code gain, Q1
+
+ Outputs:
+ alpha -- Pointer to Word16 -- gain adaptation factor, Q15
+ pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Purpose: calculate pitch/codebook gain adaptation factor alpha
+ (and update the adaptor state)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ g_adapt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void gain_adapt(
+ GainAdaptState *st, /* i : state struct */
+ Word16 ltpg, /* i : ltp coding gain (log2()), Q13 */
+ Word16 gain_cod, /* i : code gain, Q1 */
+ Word16 *alpha, /* o : gain adaptation factor, Q15 */
+ Flag *pOverflow
+)
+{
+ Word16 adapt; /* adaptdation status; 0, 1, or 2 */
+ Word16 result; /* alpha factor, Q13 */
+ Word16 filt; /* median-filtered LTP coding gain, Q13 */
+ Word16 tmp;
+ Word16 i;
+
+ /* basic adaptation */
+ if (ltpg <= LTP_GAIN_THR1)
+ {
+ adapt = 0;
+ }
+ else
+ {
+ if (ltpg <= LTP_GAIN_THR2)
+ {
+ adapt = 1;
+ }
+ else
+ {
+ adapt = 2;
+ }
+ }
+
+ /*
+ * // onset indicator
+ * if ((cbGain > onFact * cbGainMem[0]) && (cbGain > 100.0))
+ * onset = 8;
+ * else
+ * if (onset)
+ * onset--;
+ */
+ /* tmp = cbGain / onFact; onFact = 2.0; 200 Q1 = 100.0 */
+ tmp = shr_r(gain_cod, 1, pOverflow);
+
+ if ((tmp > st->prev_gc) && (gain_cod > 200))
+ {
+ st->onset = 8;
+ }
+ else
+ {
+ if (st->onset != 0)
+ {
+ st->onset = sub(st->onset, 1, pOverflow);
+ }
+ }
+
+ /*
+ * // if onset, increase adaptor state
+ * if (onset && (gainAdapt < 2)) gainAdapt++;
+ */
+ if ((st->onset != 0) && (adapt < 2))
+ {
+ adapt = add(adapt, 1, pOverflow);
+ }
+
+ st->ltpg_mem[0] = ltpg;
+ filt = gmed_n(st->ltpg_mem, 5); /* function result */
+
+ if (adapt == 0)
+ {
+ if (filt > 5443) /* 5443 Q13 = 0.66443... */
+ {
+ result = 0;
+ }
+ else
+ {
+ if (filt < 0)
+ {
+ result = 16384; /* 16384 Q15 = 0.5 */
+ }
+ else
+ { /* result = 0.5 - 0.75257499*filt */
+ /* result (Q15) = 16384 - 24660 * (filt << 2) */
+ filt = shl(filt, 2, pOverflow); /* Q15 */
+ result = mult(24660, filt, pOverflow);
+ result = sub(16384, result, pOverflow);
+ }
+ }
+ }
+ else
+ {
+ result = 0;
+ }
+ /*
+ * if (prevAlpha == 0.0) result = 0.5 * (result + prevAlpha);
+ */
+ if (st->prev_alpha == 0)
+ {
+ result = shr(result, 1, pOverflow);
+ }
+
+ /* store the result */
+ *alpha = result;
+
+ /* update adapter state memory */
+ st->prev_alpha = result;
+ st->prev_gc = gain_cod;
+
+ for (i = LTPG_MEM_SIZE - 1; i > 0; i--)
+ {
+ st->ltpg_mem[i] = st->ltpg_mem[i-1];
+ }
+ /* mem[0] is just present for convenience in calling the gmed_n[5]
+ * function above. The memory depth is really LTPG_MEM_SIZE-1.
+ */
+}
diff --git a/media/codecs/amrnb/enc/src/g_adapt.h b/media/codecs/amrnb/enc/src/g_adapt.h
new file mode 100644
index 0000000..2ea508b
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/g_adapt.h
@@ -0,0 +1,159 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/g_adapt.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, g_adapt.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef g_adapt_h
+#define g_adapt_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+#define LTPG_MEM_SIZE 5 /* number of stored past LTP coding gains + 1 */
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 onset; /* onset state, Q0 */
+ Word16 prev_alpha; /* previous adaptor output, Q15 */
+ Word16 prev_gc; /* previous code gain, Q1 */
+
+ Word16 ltpg_mem[LTPG_MEM_SIZE]; /* LTP coding gain history, Q13 */
+ /* (ltpg_mem[0] not used for history) */
+ } GainAdaptState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 gain_adapt_init(GainAdaptState **st);
+ /* initialize one instance of the gain adaptor
+ Stores pointer to state struct in *st. This pointer has to
+ be passed to gain_adapt and gain_adapt_update in each call.
+ returns 0 on success
+ */
+
+ Word16 gain_adapt_reset(GainAdaptState *st);
+ /* reset of gain adaptor state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void gain_adapt_exit(GainAdaptState **st);
+ /* de-initialize gain adaptor state (i.e. free state struct)
+ stores NULL in *st
+ */
+
+ /*************************************************************************
+ *
+ * Function: gain_adapt()
+ * Purpose: calculate pitch/codebook gain adaptation factor alpha
+ * (and update the adaptor state)
+ *
+ **************************************************************************
+ */
+ void gain_adapt(
+ GainAdaptState *st, /* i : state struct */
+ Word16 ltpg, /* i : ltp coding gain (log2()), Q */
+ Word16 gain_cod, /* i : code gain, Q13 */
+ Word16 *alpha, /* o : gain adaptation factor, Q15 */
+ Flag *pOverflow /* o : overflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/g_code.cpp b/media/codecs/amrnb/enc/src/g_code.cpp
new file mode 100644
index 0000000..f937cb7
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/g_code.cpp
@@ -0,0 +1,322 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/g_code.c
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: The return of L_mult was being stored in a Word16 before it was
+ being operated on (extract_h). Data loss happened here.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation, in some cases this by shifting before adding and
+ in other cases by evaluating the operands
+ 4. Unrolled loops to speed up processing
+ 5. Eliminated calls to shifts left and right functions by adding
+ if-else statements that do the same faster.
+
+ Description: Added casting to eliminate warnings
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: 1. Using inlines from fxp_arithmetic.h
+ 2. Removing a compiler warning.
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "g_code.h"
+#include "cnst.h"
+#include "basic_op.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: G_code
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ xn2[] = target vector (Word16)
+ y2[] = filtered innovation vector
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the innovative gain calculation resulted in overflow
+
+ Returns:
+ gain = Gain of Innovation code (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the innovative codebook gain.
+
+ The innovative codebook gain is given by
+ g = <x[], y[]> / <y[], y[]>
+
+ where x[] is the target vector, y[] is the filtered innovative codevector,
+ and <> denotes dot product.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] g_code.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 G_code ( // out : Gain of innovation code
+ Word16 xn2[], // in : target vector
+ Word16 y2[] // in : filtered innovation vector
+)
+{
+ Word16 i;
+ Word16 xy, yy, exp_xy, exp_yy, gain;
+ Word16 scal_y2[L_SUBFR];
+ Word32 s;
+
+// The original ETSI implementation uses a global overflow flag. However in
+// actual implementation a pointer to Overflow flag is passed into the
+// function for access by the low level math functions.
+
+ // Scale down Y[] by 2 to avoid overflow
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ scal_y2[i] = shr (y2[i], 1);
+ }
+
+ // Compute scalar product <X[],Y[]>
+
+ s = 1L; // Avoid case of all zeros
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ s = L_mac (s, xn2[i], scal_y2[i]);
+ }
+ exp_xy = norm_l (s);
+ xy = extract_h (L_shl (s, exp_xy));
+
+ // If (xy < 0) gain = 0
+
+ if (xy <= 0)
+ return ((Word16) 0);
+
+ // Compute scalar product <Y[],Y[]>
+
+ s = 0L;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ s = L_mac (s, scal_y2[i], scal_y2[i]);
+ }
+ exp_yy = norm_l (s);
+ yy = extract_h (L_shl (s, exp_yy));
+
+ // compute gain = xy/yy
+
+ xy = shr (xy, 1); // Be sure xy < yy
+ gain = div_s (xy, yy);
+
+ // Denormalization of division
+ i = add (exp_xy, 5); // 15-1+9-18 = 5
+ i = sub (i, exp_yy);
+
+ gain = shl (shr (gain, i), 1); // Q0 -> Q1/
+
+ return (gain);
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 G_code( /* o : Gain of innovation code */
+ Word16 xn2[], /* i : target vector */
+ Word16 y2[], /* i : filtered innovation vector */
+ Flag *pOverflow /* i/o : overflow flag */
+)
+{
+ Word16 i;
+ Word16 xy, yy, exp_xy, exp_yy, gain;
+ Word32 s;
+
+ Word16 *p_xn2 = xn2;
+ Word16 *p_y2 = y2;
+ Word16 temp;
+ Word32 temp2;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ /* Compute scalar product <X[],Y[]> */
+ s = 0;
+
+ for (i = (L_SUBFR >> 2); i != 0 ; i--)
+ {
+ temp2 = (Word32)(*(p_y2++) >> 1);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn2++), temp2, s);
+ temp2 = (Word32)(*(p_y2++) >> 1);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn2++), temp2, s);
+ temp2 = (Word32)(*(p_y2++) >> 1);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn2++), temp2, s);
+ temp2 = (Word32)(*(p_y2++) >> 1);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn2++), temp2, s);
+ }
+ s <<= 1;
+ exp_xy = norm_l(s + 1); /* Avoid case of all zeros, add 1 */
+
+ if (exp_xy < 17) /* extra right shift to be sure xy < yy */
+ {
+ xy = (Word16)(s >> (17 - exp_xy));
+ }
+ else
+ {
+ xy = (Word16)(s << (exp_xy - 17));
+ }
+
+ /* If (xy < 0) gain = 0 */
+
+ if (xy <= 0)
+ {
+ return ((Word16) 0);
+ }
+
+ /* Compute scalar product <Y[],Y[]> */
+
+ s = 0L;
+ p_y2 = y2;
+
+ for (i = (L_SUBFR >> 1); i != 0 ; i--)
+ {
+ temp = *(p_y2++) >> 1;
+ s += ((Word32) temp * temp) >> 2;
+ temp = *(p_y2++) >> 1;
+ s += ((Word32) temp * temp) >> 2;
+ }
+ s <<= 3;
+ exp_yy = norm_l(s);
+
+ if (exp_yy < 16)
+ {
+ yy = (Word16)(s >> (16 - exp_yy));
+ }
+ else
+ {
+ yy = (Word16)(s << (exp_yy - 16));
+ }
+
+ gain = div_s(xy, yy);
+
+ /* Denormalization of division */
+ i = exp_xy + 5; /* 15-1+9-18 = 5 */
+ i -= exp_yy;
+
+ // gain = shl (shr (gain, i), 1); /* Q0 -> Q1 */
+
+ if (i > 1)
+ {
+ gain >>= i - 1;
+ }
+ else
+ {
+ gain <<= 1 - i;
+ }
+
+
+ return (gain);
+}
diff --git a/media/codecs/amrnb/enc/src/g_code.h b/media/codecs/amrnb/enc/src/g_code.h
new file mode 100644
index 0000000..c62cba6
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/g_code.h
@@ -0,0 +1,116 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/g_code.h
+
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the G_code() function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef G_CODE_H
+#define G_CODE_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 G_code( /* o : Gain of innovation code */
+ Word16 xn2[], /* i : target vector */
+ Word16 y2[], /* i : filtered innovation vector */
+ Flag *pOverflow /* i/o : overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _G_CODE_H */
+
diff --git a/media/codecs/amrnb/enc/src/g_pitch.cpp b/media/codecs/amrnb/enc/src/g_pitch.cpp
new file mode 100644
index 0000000..5b80e2a
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/g_pitch.cpp
@@ -0,0 +1,465 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/g_pitch.c
+
+ Date: 06/12/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed into template and began to optimize.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h and oper_32b.h with the header files of the
+ math functions used in the file. Fixed typecasting issue with
+ TI compiler.
+
+ Description: Passing in pointer to overflow flag for EPOC compatibility. .
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation, in some cases this by shifting before adding and
+ in other cases by evaluating the operands
+ 4. Unrolled loops to speed up processing
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Using inlines from fxp_arithmetic.h .
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "g_pitch.h"
+#include "mode.h"
+#include "cnst.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: G_pitch
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode = AMR mode (enum Mode)
+ xn = pointer to pitch target buffer (Word16)
+ y1 = pointer to filtered adaptive codebook buffer (Word16)
+ g_coeff = pointer to buffer of correlations needed for gain quantization
+ (Word16)
+ L_subfr = length of subframe (Word16)
+ pOverflow = pointer to overflow flag (Flag)
+
+ Outputs:
+ g_coeff contains the mantissa and exponent of the two dot products.
+ pOverflow -> 1 if an overflow occurs
+
+ Returns:
+ gain = ratio of dot products.(Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the pitch (adaptive codebook) gain. The adaptive
+ codebook gain is given by
+
+ g = <x[], y[]> / <y[], y[]>
+
+ where: x[] is the target vector
+ y[] is the filtered adaptive codevector
+ <> denotes dot product.
+
+ The gain is limited to the range [0,1.2] (=0..19661 Q14)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ g_pitch.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 G_pitch ( // o : Gain of pitch lag saturated to 1.2
+ enum Mode mode, // i : AMR mode
+ Word16 xn[], // i : Pitch target.
+ Word16 y1[], // i : Filtered adaptive codebook.
+ Word16 g_coeff[], // i : Correlations need for gain quantization
+ Word16 L_subfr // i : Length of subframe.
+)
+{
+ Word16 i;
+ Word16 xy, yy, exp_xy, exp_yy, gain;
+ Word32 s;
+
+ Word16 scaled_y1[L_SUBFR]; // Usually dynamic allocation of (L_subfr)
+
+ // divide "y1[]" by 4 to avoid overflow
+
+// The reference ETSI code uses a global overflow Flag. However in the actual
+// implementation a pointer to the overflow flag is passed into the function.
+
+ for (i = 0; i < L_subfr; i++)
+ {
+ scaled_y1[i] = shr (y1[i], 2);
+ }
+
+ // Compute scalar product <y1[],y1[]>
+
+ // Q12 scaling / MR122
+ Overflow = 0;
+ s = 1L; // Avoid case of all zeros
+ for (i = 0; i < L_subfr; i++)
+ {
+ s = L_mac (s, y1[i], y1[i]);
+ }
+ if (Overflow == 0) // Test for overflow
+ {
+ exp_yy = norm_l (s);
+ yy = pv_round (L_shl (s, exp_yy));
+ }
+ else
+ {
+ s = 1L; // Avoid case of all zeros
+ for (i = 0; i < L_subfr; i++)
+ {
+ s = L_mac (s, scaled_y1[i], scaled_y1[i]);
+ }
+ exp_yy = norm_l (s);
+ yy = pv_round (L_shl (s, exp_yy));
+ exp_yy = sub (exp_yy, 4);
+ }
+
+ // Compute scalar product <xn[],y1[]>
+
+ Overflow = 0;
+ s = 1L; // Avoid case of all zeros
+
+ for (i = 0; i < L_subfr; i++)
+ {
+ s = L_mac(s, xn[i], y1[i]);
+ }
+ if (Overflow == 0)
+ {
+ exp_xy = norm_l (s);
+ xy = pv_round (L_shl (s, exp_xy));
+ }
+ else
+ {
+ s = 1L; // Avoid case of all zeros
+ for (i = 0; i < L_subfr; i++)
+ {
+ s = L_mac (s, xn[i], scaled_y1[i]);
+ }
+ exp_xy = norm_l (s);
+ xy = pv_round (L_shl (s, exp_xy));
+ exp_xy = sub (exp_xy, 2);
+ }
+
+ g_coeff[0] = yy;
+ g_coeff[1] = sub (15, exp_yy);
+ g_coeff[2] = xy;
+ g_coeff[3] = sub (15, exp_xy);
+
+ // If (xy < 4) gain = 0
+
+ i = sub (xy, 4);
+
+ if (i < 0)
+ return ((Word16) 0);
+
+ // compute gain = xy/yy
+
+ xy = shr (xy, 1); // Be sure xy < yy
+ gain = div_s (xy, yy);
+
+ i = sub (exp_xy, exp_yy); // Denormalization of division
+ gain = shr (gain, i);
+
+ // if(gain >1.2) gain = 1.2
+
+ if (sub (gain, 19661) > 0)
+ {
+ gain = 19661;
+ }
+
+ if (sub(mode, MR122) == 0)
+ {
+ // clear 2 LSBits
+ gain = gain & 0xfffC;
+ }
+
+ return (gain);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 G_pitch( /* o : Gain of pitch lag saturated to 1.2 */
+ enum Mode mode, /* i : AMR mode */
+ Word16 xn[], /* i : Pitch target. Q0 */
+ Word16 y1[], /* i : Filtered adaptive codebook. Q12 */
+ Word16 g_coeff[], /* i : Correlations need for gain quantization */
+ Word16 L_subfr, /* i : Length of subframe. */
+ Flag *pOverflow /* i/o : Overflow flag */
+)
+{
+
+ Word16 i;
+ Word16 xy;
+ Word16 yy;
+ Word16 exp_xy;
+ Word16 exp_yy;
+ Word16 gain;
+ Word16 tmp;
+ Word32 s;
+ Word32 s1;
+ Word32 L_temp; /* Use this as an intermediate value */
+ Word16 *p_xn = &xn[0];
+ Word16 *p_y1 = &y1[0];
+
+ /* Compute scalar product <y1[],y1[]> */
+
+ /* Q12 scaling / MR122 */
+ *pOverflow = 0;
+ s = 0;
+
+ for (i = L_subfr >> 2; i != 0; i--)
+ {
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y1), (Word32) * (p_y1), s);
+ p_y1++;
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y1), (Word32) * (p_y1), s);
+ p_y1++;
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y1), (Word32) * (p_y1), s);
+ p_y1++;
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_y1), (Word32) * (p_y1), s);
+ p_y1++;
+ }
+ if ((s >= 0) & (s < 0x40000000))
+ {
+ s <<= 1;
+ s += 1; /* Avoid case of all zeros */
+
+ exp_yy = norm_l(s); /* Note 0<=exp_yy <= 31 */
+ L_temp = s << exp_yy;
+ yy = pv_round(L_temp, pOverflow);
+ }
+ else
+ {
+ s = 0; /* Avoid case of all zeros */
+ p_y1 = &y1[0];
+ for (i = (L_subfr >> 1); i != 0; i--)
+ {
+ tmp = *(p_y1++) >> 2;
+ s = amrnb_fxp_mac_16_by_16bb((Word32) tmp, (Word32) tmp, s);
+ tmp = *(p_y1++) >> 2;
+ s = amrnb_fxp_mac_16_by_16bb((Word32) tmp, (Word32) tmp, s);
+ }
+
+ s <<= 1;
+ s += 1; /* Avoid case of all zeros */
+
+ exp_yy = norm_l(s);
+ L_temp = s << exp_yy;
+ yy = pv_round(L_temp, pOverflow);
+ exp_yy = exp_yy - 4;
+
+ }
+
+ /* Compute scalar product <xn[],y1[]> */
+
+ s = 0;
+ p_y1 = &y1[0];
+ *pOverflow = 0;
+
+ for (i = L_subfr; i != 0; i--)
+ {
+ L_temp = ((Word32) * (p_xn++) * *(p_y1++));
+ s1 = s;
+ s = s1 + L_temp;
+
+ if ((s1 ^ L_temp) > 0)
+ {
+ if ((s1 ^ s) < 0)
+ {
+ *pOverflow = 1;
+ break;
+ }
+ }
+ }
+
+ if (!(*pOverflow))
+ {
+
+ s <<= 1;
+ s += 1; /* Avoid case of all zeros */
+
+ exp_xy = norm_l(s); /* Note 0<=exp_yy <= 31 */
+ L_temp = s << exp_xy;
+ xy = pv_round(L_temp, pOverflow);
+ }
+ else
+ {
+ s = 0; /* re-initialize calculations */
+ p_y1 = &y1[0];
+ p_xn = &xn[0];
+ for (i = (L_subfr >> 2); i != 0; i--)
+ {
+ L_temp = (Word32)(*(p_y1++) >> 2);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn++), L_temp, s);
+ L_temp = (Word32)(*(p_y1++) >> 2);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn++), L_temp, s);
+ L_temp = (Word32)(*(p_y1++) >> 2);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn++), L_temp, s);
+ L_temp = (Word32)(*(p_y1++) >> 2);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (p_xn++), L_temp, s);
+ }
+
+ s <<= 1;
+ s += 1; /* Avoid case of all zeros */
+
+ exp_xy = norm_l(s);
+ L_temp = s << exp_xy;
+ xy = pv_round(L_temp, pOverflow);
+ exp_xy = exp_xy - 4;
+
+ }
+
+ g_coeff[0] = yy;
+ g_coeff[1] = 15 - exp_yy;
+ g_coeff[2] = xy;
+ g_coeff[3] = 15 - exp_xy;
+
+ /* If (xy < 4) gain = 0 */
+ if (xy < 4)
+ {
+ return ((Word16) 0);
+ }
+
+ /* compute gain = xy/yy */
+ /* Be sure xy < yy */
+
+ xy = xy >> 1;
+
+ gain = div_s(xy, yy);
+
+ i = exp_xy - exp_yy; /* Denormalization of division */
+
+ gain = shr(gain, i, pOverflow);
+
+
+ /* if(gain >1.2) gain = 1.2 */
+ if (gain > 19661)
+ {
+ gain = 19661;
+ }
+
+ if (mode == MR122)
+ {
+ /* clear 2 LSBits */
+ gain = gain & 0xfffC;
+ }
+
+ return(gain);
+
+}
diff --git a/media/codecs/amrnb/enc/src/g_pitch.h b/media/codecs/amrnb/enc/src/g_pitch.h
new file mode 100644
index 0000000..6ea06ea
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/g_pitch.h
@@ -0,0 +1,119 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/g_pitch.h
+
+
+ Date: 02/01/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the G_pitch() function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef G_PITCH_H
+#define G_PITCH_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mode.h"
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 G_pitch( /* o : Gain of pitch lag saturated to 1.2 */
+ enum Mode mode, /* i : AMR mode */
+ Word16 xn[], /* i : Pitch target. */
+ Word16 y1[], /* i : Filtered adaptive codebook. */
+ Word16 g_coeff[], /* i : Correlations need for gain quantization */
+ Word16 L_subfr, /* i : Length of subframe. */
+ Flag *pOverflow /* i/o : Overflow flag */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _G_PITCH_H_ */
+
diff --git a/media/codecs/amrnb/enc/src/gain_q.cpp b/media/codecs/amrnb/enc/src/gain_q.cpp
new file mode 100644
index 0000000..e44e4bc
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/gain_q.cpp
@@ -0,0 +1,747 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/gain_q.c
+ Functions:
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Removed everything associated with gc_pred_init
+ and gc_pred_exit. gc_pred_exit was simply removed -- gc_pred_init
+ was replaced with calls to gc_pred_reset. This is because the gc_pred
+ related structures are no longer dynamically allocated via malloc.
+
+ Description: For gainQuant()
+ 1. Replaced gc_pred_copy() with memcpy.
+ 2. Eliminated unused include file gc_pred.h.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Quantazation of gains
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <string.h>
+
+#include "gain_q.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "qua_gain.h"
+#include "cnst.h"
+#include "mode.h"
+#include "g_code.h"
+#include "q_gain_c.h"
+#include "calc_en.h"
+#include "qgain795.h"
+#include "qgain475.h"
+#include "set_zero.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NPRED 4 /* number of prediction taps */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gainQuant_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to gainQuantState
+
+ Outputs:
+ st -- double ponter to gainQuantState
+
+ Returns:
+ -1 if an error occurs during memory initialization
+ 0 if OK
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Allocates state memory and initializes state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gain_q.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 gainQuant_init(gainQuantState **state)
+{
+ gainQuantState* s;
+
+ if (state == (gainQuantState **) NULL)
+ {
+ /* fprintf(stderr, "gainQuant_init: invalid parameter\n"); */
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (gainQuantState *) malloc(sizeof(gainQuantState))) == NULL)
+ {
+ /* fprintf(stderr, "gainQuant_init: can not malloc state structure\n"); */
+ return -1;
+ }
+
+ s->gain_idx_ptr = NULL;
+
+ s->adaptSt = NULL;
+
+ /* Init sub states */
+ if (gc_pred_reset(&s->gc_predSt)
+ || gc_pred_reset(&s->gc_predUnqSt)
+ || gain_adapt_init(&s->adaptSt))
+ {
+ gainQuant_exit(&s);
+ return -1;
+ }
+
+ gainQuant_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gainQuant_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to gainQuantState
+
+ Outputs:
+ st -- double ponter to gainQuantState
+
+ Returns:
+ -1 if an error occurs
+ 0 if OK
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Initializes state memory to zero
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gain_q.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 gainQuant_reset(gainQuantState *state)
+{
+
+ if (state == (gainQuantState *) NULL)
+ {
+ /* fprintf(stderr, "gainQuant_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ state->sf0_exp_gcode0 = 0;
+ state->sf0_frac_gcode0 = 0;
+ state->sf0_exp_target_en = 0;
+ state->sf0_frac_target_en = 0;
+
+ Set_zero(state->sf0_exp_coeff, 5);
+ Set_zero(state->sf0_frac_coeff, 5);
+ state->gain_idx_ptr = NULL;
+
+ gc_pred_reset(&(state->gc_predSt));
+ gc_pred_reset(&(state->gc_predUnqSt));
+ gain_adapt_reset(state->adaptSt);
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gainQuant_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- double pointer to gainQuantState
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The memory used for state memory is freed
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gain_q.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void gainQuant_exit(gainQuantState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ gain_adapt_exit(&(*state)->adaptSt);
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: gainQuant
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st -- pointer to gainQuantState
+ mode -- enum Mode -- coder mode
+ res -- Word16 array -- LP residual, Q0
+ exc -- Word16 array -- LTP excitation (unfiltered), Q0
+ code -- Word16 array -- CB innovation (unfiltered), Q13
+ (unsharpened for MR475)
+ xn -- Word16 array -- Target vector.
+ xn2 -- Word16 array -- Target vector.
+ y1 -- Word16 array -- Adaptive codebook.
+ Y2 -- Word16 array -- Filtered innovative vector.
+ g_coeff -- Word16 array -- Correlations <xn y1> <y1 y1>
+ Compute in G_pitch().
+
+ even_subframe -- Word16 -- even subframe indicator flag
+ gp_limit -- Word16 -- pitch gain limit
+ gain_pit -- Word16 Pointer -- Pitch gain.
+
+ Outputs:
+ st -- pointer to gainQuantState
+ sf0_gain_pit -- Word16 Pointer -- Pitch gain sf 0. MR475
+ sf0_gain_cod -- Word16 Pointer -- Code gain sf 0. MR475
+ gain_pit -- Word16 Pointer -- Pitch gain.
+ gain_cod -- Word16 Pointer -- Code gain.
+ MR475: gain_* unquantized in even
+ subframes, quantized otherwise
+
+ anap -- Word16 Double Pointer -- Index of quantization
+
+ pOverflow -- Flag Pointer -- overflow indicator
+
+ Returns:
+ Zero
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Quantazation of gains
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ gain_q.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+
+void gainQuant(
+ gainQuantState *st, /* i/o : State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 res[], /* i : LP residual, Q0 */
+ Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
+ Word16 code[], /* i : CB innovation (unfiltered), Q13 */
+ /* (unsharpened for MR475) */
+ Word16 xn[], /* i : Target vector. */
+ Word16 xn2[], /* i : Target vector. */
+ Word16 y1[], /* i : Adaptive codebook. */
+ Word16 Y2[], /* i : Filtered innovative vector. */
+ Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
+ /* Compute in G_pitch(). */
+ Word16 even_subframe, /* i : even subframe indicator flag */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *sf0_gain_pit, /* o : Pitch gain sf 0. MR475 */
+ Word16 *sf0_gain_cod, /* o : Code gain sf 0. MR475 */
+ Word16 *gain_pit, /* i/o : Pitch gain. */
+ Word16 *gain_cod, /* o : Code gain. */
+ /* MR475: gain_* unquantized in even */
+ /* subframes, quantized otherwise */
+ Word16 **anap, /* o : Index of quantization */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 exp_gcode0;
+ Word16 frac_gcode0;
+ Word16 qua_ener_MR122;
+ Word16 qua_ener;
+ Word16 frac_coeff[5];
+ Word16 exp_coeff[5];
+ Word16 exp_en;
+ Word16 frac_en;
+ Word16 cod_gain_exp;
+ Word16 cod_gain_frac;
+ Word16 temp;
+
+ if (mode == MR475)
+ {
+ if (even_subframe != 0)
+ {
+ /* save position in output parameter stream and current
+ state of codebook gain predictor */
+ st->gain_idx_ptr = (*anap)++;
+
+// gc_pred_copy(&(st->gc_predSt), &(st->gc_predUnqSt));
+
+ memcpy(st->gc_predUnqSt.past_qua_en,
+ st->gc_predSt.past_qua_en,
+ NPRED*sizeof(Word16));
+ memcpy(st->gc_predUnqSt.past_qua_en_MR122,
+ st->gc_predSt.past_qua_en_MR122,
+ NPRED*sizeof(Word16));
+
+
+ /* predict codebook gain (using "unquantized" predictor)*/
+ /* (note that code[] is unsharpened in MR475) */
+ gc_pred(
+ &(st->gc_predUnqSt),
+ mode,
+ code,
+ &st->sf0_exp_gcode0,
+ &st->sf0_frac_gcode0,
+ &exp_en,
+ &frac_en,
+ pOverflow);
+
+ /* calculate energy coefficients for quantization
+ and store them in state structure (will be used
+ in next subframe when real quantizer is run) */
+ calc_filt_energies(
+ mode,
+ xn,
+ xn2,
+ y1,
+ Y2,
+ g_coeff,
+ st->sf0_frac_coeff,
+ st->sf0_exp_coeff,
+ &cod_gain_frac,
+ &cod_gain_exp,
+ pOverflow);
+
+ /* store optimum codebook gain (Q1) */
+ temp =
+ add(
+ cod_gain_exp,
+ 1,
+ pOverflow);
+
+ *gain_cod =
+ shl(
+ cod_gain_frac,
+ temp,
+ pOverflow);
+
+ calc_target_energy(
+ xn,
+ &st->sf0_exp_target_en,
+ &st->sf0_frac_target_en,
+ pOverflow);
+
+ /* calculate optimum codebook gain and update
+ "unquantized" predictor */
+ MR475_update_unq_pred(
+ &(st->gc_predUnqSt),
+ st->sf0_exp_gcode0,
+ st->sf0_frac_gcode0,
+ cod_gain_exp,
+ cod_gain_frac,
+ pOverflow);
+
+ /* the real quantizer is not run here... */
+ }
+ else
+ {
+ /* predict codebook gain (using "unquantized" predictor) */
+ /* (note that code[] is unsharpened in MR475) */
+ gc_pred(
+ &(st->gc_predUnqSt),
+ mode,
+ code,
+ &exp_gcode0,
+ &frac_gcode0,
+ &exp_en,
+ &frac_en,
+ pOverflow);
+
+ /* calculate energy coefficients for quantization */
+ calc_filt_energies(
+ mode,
+ xn,
+ xn2,
+ y1,
+ Y2,
+ g_coeff,
+ frac_coeff,
+ exp_coeff,
+ &cod_gain_frac,
+ &cod_gain_exp,
+ pOverflow);
+
+ calc_target_energy(
+ xn,
+ &exp_en,
+ &frac_en,
+ pOverflow);
+
+ /* run real (4-dim) quantizer and update real gain predictor */
+ *st->gain_idx_ptr =
+ MR475_gain_quant(
+ &(st->gc_predSt),
+ st->sf0_exp_gcode0,
+ st->sf0_frac_gcode0,
+ st->sf0_exp_coeff,
+ st->sf0_frac_coeff,
+ st->sf0_exp_target_en,
+ st->sf0_frac_target_en,
+ code,
+ exp_gcode0,
+ frac_gcode0,
+ exp_coeff,
+ frac_coeff,
+ exp_en,
+ frac_en,
+ gp_limit,
+ sf0_gain_pit,
+ sf0_gain_cod,
+ gain_pit,
+ gain_cod,
+ pOverflow);
+ }
+ }
+ else
+ {
+ /*-------------------------------------------------------------------*
+ * predict codebook gain and quantize *
+ * (also compute normalized CB innovation energy for MR795) *
+ *-------------------------------------------------------------------*/
+ gc_pred(
+ &(st->gc_predSt),
+ mode,
+ code,
+ &exp_gcode0,
+ &frac_gcode0,
+ &exp_en,
+ &frac_en,
+ pOverflow);
+
+ if (mode == MR122)
+ {
+ *gain_cod =
+ G_code(
+ xn2,
+ Y2,
+ pOverflow);
+
+ *(*anap)++ =
+ q_gain_code(
+ mode,
+ exp_gcode0,
+ frac_gcode0,
+ gain_cod,
+ &qua_ener_MR122,
+ &qua_ener,
+ pOverflow);
+ }
+ else
+ {
+ /* calculate energy coefficients for quantization */
+ calc_filt_energies(
+ mode,
+ xn,
+ xn2,
+ y1,
+ Y2,
+ g_coeff,
+ frac_coeff,
+ exp_coeff,
+ &cod_gain_frac,
+ &cod_gain_exp,
+ pOverflow);
+
+ if (mode == MR795)
+ {
+ MR795_gain_quant(
+ st->adaptSt,
+ res,
+ exc,
+ code,
+ frac_coeff,
+ exp_coeff,
+ exp_en,
+ frac_en,
+ exp_gcode0,
+ frac_gcode0,
+ L_SUBFR,
+ cod_gain_frac,
+ cod_gain_exp,
+ gp_limit,
+ gain_pit,
+ gain_cod,
+ &qua_ener_MR122,
+ &qua_ener,
+ anap,
+ pOverflow);
+ }
+ else
+ {
+ *(*anap)++ =
+ Qua_gain(
+ mode,
+ exp_gcode0,
+ frac_gcode0,
+ frac_coeff,
+ exp_coeff,
+ gp_limit,
+ gain_pit,
+ gain_cod,
+ &qua_ener_MR122,
+ &qua_ener,
+ pOverflow);
+ }
+ }
+
+ /*------------------------------------------------------------------*
+ * update table of past quantized energies *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * st->past_qua_en(Q10) = 20 * Log10(qua_gain_code) / constant *
+ * = Log2(qua_gain_code) *
+ * = qua_ener *
+ * constant = 20*Log10(2) *
+ *------------------------------------------------------------------*/
+ gc_pred_update(
+ &(st->gc_predSt),
+ qua_ener_MR122,
+ qua_ener);
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/gain_q.h b/media/codecs/amrnb/enc/src/gain_q.h
new file mode 100644
index 0000000..a5c7f4e
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/gain_q.h
@@ -0,0 +1,182 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/gain_q.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow.
+
+ Description: Changed definition of...
+
+ gc_predState gc_predSt;
+ gc_predState gc_predUnqSt;
+
+ in the structure typedef. These are no longer pointers, which avoids
+ the need to malloc memory for the pointers. They are, rather, the actual
+ structure declared within the gainQuantState structure.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, gain_q.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef gain_q_h
+#define gain_q_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "gc_pred.h"
+#include "g_adapt.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 sf0_exp_gcode0;
+ Word16 sf0_frac_gcode0;
+ Word16 sf0_exp_target_en;
+ Word16 sf0_frac_target_en;
+ Word16 sf0_exp_coeff[5];
+ Word16 sf0_frac_coeff[5];
+ Word16 *gain_idx_ptr;
+
+ gc_predState gc_predSt;
+ gc_predState gc_predUnqSt;
+ GainAdaptState *adaptSt;
+ } gainQuantState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 gainQuant_init(gainQuantState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to gainQuant in each call.
+ returns 0 on success
+ */
+ Word16 gainQuant_reset(gainQuantState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void gainQuant_exit(gainQuantState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void gainQuant(
+ gainQuantState *st, /* i/o : State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 res[], /* i : LP residual, Q0 */
+ Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
+ Word16 code[], /* i : CB innovation (unfiltered), Q13 */
+ /* (unsharpened for MR475) */
+ Word16 xn[], /* i : Target vector. */
+ Word16 xn2[], /* i : Target vector. */
+ Word16 y1[], /* i : Adaptive codebook. */
+ Word16 Y2[], /* i : Filtered innovative vector. */
+ Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
+ /* Compute in G_pitch(). */
+ Word16 even_subframe, /* i : even subframe indicator flag */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *sf0_gain_pit, /* o : Pitch gain sf 0. MR475 */
+ Word16 *sf0_gain_cod, /* o : Code gain sf 0. MR475 */
+ Word16 *gain_pit, /* i/o : Pitch gain. */
+ Word16 *gain_cod, /* o : Code gain. */
+ /* MR475: gain_* unquantized in even */
+ /* subframes, quantized otherwise */
+ Word16 **anap, /* o : Index of quantization */
+ Flag *pOverflow /* o : overflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* gain_q_h */
+
+
diff --git a/media/codecs/amrnb/enc/src/gsmamr_enc.h b/media/codecs/amrnb/enc/src/gsmamr_enc.h
new file mode 100644
index 0000000..67c7aa3
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/gsmamr_enc.h
@@ -0,0 +1,193 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/include/gsmamr_enc.h
+
+ Date: 09/26/2001
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changing code as per review comments. These changes include
+ removing unnecessary tables and changing function descriptions.
+ The comments were changed to "slash-star" rather than double
+ slash, and some wordings of comments were corrected.
+
+ Description: Replaced GSMEncodeFrame function prototype with that of
+ AMREncode. Updated copyright year.
+
+ Description: Added #define for WMF and IF2, and updated function prototype
+ of AMREncode.
+
+ Description: Renamed WMF and IF2 to AMR_WMF and AMR_IF2, respectively. Added
+ AMR_ETS, and changed output_type to output_format in the
+ function prototype of AMREncode(). Removed function prototypes
+ for frame_header_move() and reverse_bits() since they are not
+ needed anymore.
+
+ Description: Moved WMFBytesUsed and IF2BytesUsed tables to
+ enc_output_format_tab.c.
+
+ Description: Added function prototypes for init, reset, and exit functions
+ in amrencode.c. Renamed output format #defines so that it it
+ unique to the encoder.
+
+ Description: Added comment to describe L_FRAME.
+
+ Description: Added Frame_Type_3GPP type definition.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This header contains all the necessary information needed to use the
+ GSM AMR encoder library.
+
+------------------------------------------------------------------------------
+*/
+#ifndef _GSMAMR_ENC_H_
+#define _GSMAMR_ENC_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "gsm_amr_typedefs.h"
+#include "frame_type_3gpp.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ----------------------------------------------------------------------------*/
+ /* Number of 13-bit linear PCM samples per 20 ms frame */
+ /* L_FRAME = (8 kHz) * (20 msec) = 160 samples */
+#define L_FRAME 160
+
+ /* Output format types */
+#define AMR_TX_WMF 0
+#define AMR_TX_IF2 1
+#define AMR_TX_ETS 2
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ enum Mode
+ {
+ MR475 = 0,/* 4.75 kbps */
+ MR515, /* 5.15 kbps */
+ MR59, /* 5.90 kbps */
+ MR67, /* 6.70 kbps */
+ MR74, /* 7.40 kbps */
+ MR795, /* 7.95 kbps */
+ MR102, /* 10.2 kbps */
+ MR122, /* 12.2 kbps */
+ MRDTX, /* DTX */
+ N_MODES /* Not Used */
+ };
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ----------------------------------------------------------------------------*/
+ /* AMREncodeInit initializes the GSM AMR Encoder library by calling
+ * GSMInitEncode and sid_sync_init. If initialization was successful,
+ * init_status is set to zero, otherwise, it is set to -1.
+ */
+ int AMREncodeInit(
+ void **pEncStructure,
+ void **pSidSyncStructure,
+ Flag dtx_enable);
+
+ /* AMREncodeReset resets the state memory used by the Encoder and SID sync
+ * function. If reset was successful, reset_status is set to zero, otherwise,
+ * it is set to -1.
+ */
+ int AMREncodeReset(
+ void *pEncStructure,
+ void *pSidSyncStructure);
+
+ /* AMREncodeExit frees up the state memory used by the Encoder and SID
+ * synchronization function.
+ */
+ void AMREncodeExit(
+ void **pEncStructure,
+ void **pSidSyncStructure);
+
+ /*
+ * AMREncode is the entry point to the ETS Encoder library that encodes the raw
+ * data speech bits and converts the encoded bitstream into either an IF2-
+ * formatted bitstream, WMF-formatted bitstream, or ETS-formatted bitstream,
+ * depending on the the value of output_format. A zero is returned on success.
+ */
+ int AMREncode(
+ void *pEncState,
+ void *pSidSyncState,
+ enum Mode mode,
+ Word16 *pEncInput,
+ unsigned char *pEncOutput,
+ enum Frame_Type_3GPP *p3gpp_frame_type,
+ Word16 output_format
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _GSMAMR_DEC_H_ */
+
diff --git a/media/codecs/amrnb/enc/src/hp_max.cpp b/media/codecs/amrnb/enc/src/hp_max.cpp
new file mode 100644
index 0000000..d086594
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/hp_max.cpp
@@ -0,0 +1,332 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/hp_max.c
+
+ Date: 02/01/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "hp_max.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: hp_max
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ corr[] = correlation vector (Word16)
+ scal_sig[] = scaled signal vector (Word16)
+ L_frame = length of frame to compute pitch (Word16
+ lag_max = maximum lag (Word16)
+ lag_min = minimum lag (Word16)
+ cor_hp_max = pointer to max high-pass filtered norm. correlation (Word16)
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ cor_hp_max contains max high-pass filtered norm. correlation (Word16)
+ pOverflow -> 1 if the maximum correlation computation resulted in overflow
+
+ Returns:
+ 0 (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function finds the maximum high-pass filtered correlation of scal_sig[]
+ in a given delay range.
+
+ The correlation is given by
+ corr[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max
+ The functions outputs the maximum high-pass filtered correlation after
+ normalization.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] hp_max.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 hp_max (
+ Word32 corr[], // i : correlation vector
+ Word16 scal_sig[], // i : scaled signal
+ Word16 L_frame, // i : length of frame to compute pitch
+ Word16 lag_max, // i : maximum lag
+ Word16 lag_min, // i : minimum lag
+ Word16 *cor_hp_max) // o : max high-pass filtered norm. correlation
+{
+ Word16 i;
+ Word16 *p, *p1;
+ Word32 max, t0, t1;
+ Word16 max16, t016, cor_max;
+ Word16 shift, shift1, shift2;
+
+ max = MIN_32;
+ t0 = 0L;
+* The reference ETSI code uses a global flag for Overflow inside the math functions
+* saturate(). In the actual implementation a pointer to Overflow flag is passed in
+* as a parameter to the function
+
+ for (i = lag_max-1; i > lag_min; i--)
+ {
+ // high-pass filtering
+ t0 = L_sub (L_sub(L_shl(corr[-i], 1), corr[-i-1]), corr[-i+1]);
+ t0 = L_abs (t0);
+
+ if (L_sub (t0, max) >= 0)
+ {
+ max = t0;
+ }
+ }
+
+ // compute energy
+ p = scal_sig;
+ p1 = &scal_sig[0];
+ t0 = 0L;
+ for (i = 0; i < L_frame; i++, p++, p1++)
+ {
+ t0 = L_mac (t0, *p, *p1);
+ }
+
+ p = scal_sig;
+ p1 = &scal_sig[-1];
+ t1 = 0L;
+ for (i = 0; i < L_frame; i++, p++, p1++)
+ {
+ t1 = L_mac (t1, *p, *p1);
+ }
+
+ // high-pass filtering
+ t0 = L_sub(L_shl(t0, 1), L_shl(t1, 1));
+ t0 = L_abs (t0);
+
+ // max/t0
+ shift1 = sub(norm_l(max), 1);
+ max16 = extract_h(L_shl(max, shift1));
+ shift2 = norm_l(t0);
+ t016 = extract_h(L_shl(t0, shift2));
+
+ if (t016 != 0)
+ {
+ cor_max = div_s(max16, t016);
+ }
+ else
+ {
+ cor_max = 0;
+ }
+
+ shift = sub(shift1, shift2);
+
+ if (shift >= 0)
+ {
+ *cor_hp_max = shr(cor_max, shift); // Q15
+ }
+ else
+ {
+ *cor_hp_max = shl(cor_max, negate(shift)); // Q15
+ }
+
+ return 0;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word16 hp_max(
+ Word32 corr[], /* i : correlation vector. */
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word16 *cor_hp_max, /* o : max high-pass filtered norm. correlation */
+ Flag *pOverflow /* i/o : overflow Flag */
+)
+{
+ Word16 i;
+ Word16 *p, *p1;
+ Word32 max, t0, t1;
+ Word16 max16, t016, cor_max;
+ Word16 shift, shift1, shift2;
+ Word32 L_temp;
+
+ max = MIN_32;
+ t0 = 0L;
+
+ for (i = lag_max - 1; i > lag_min; i--)
+ {
+ /* high-pass filtering */
+ t0 = L_shl(corr[-i], 1, pOverflow);
+ L_temp = L_sub(t0, corr[-i-1], pOverflow);
+ t0 = L_sub(L_temp, corr[-i+1], pOverflow);
+ t0 = L_abs(t0);
+
+ if (t0 >= max)
+ {
+ max = t0;
+ }
+ }
+
+ /* compute energy */
+ p = scal_sig;
+ p1 = &scal_sig[0];
+ t0 = 0L;
+ for (i = 0; i < L_frame; i++, p++, p1++)
+ {
+ t0 = L_mac(t0, *p, *p1, pOverflow);
+ }
+
+ p = scal_sig;
+ p1 = &scal_sig[-1];
+ t1 = 0L;
+ for (i = 0; i < L_frame; i++, p++, p1++)
+ {
+ t1 = L_mac(t1, *p, *p1, pOverflow);
+ }
+
+ /* high-pass filtering */
+ L_temp = L_shl(t0, 1, pOverflow);
+ t1 = L_shl(t1, 1, pOverflow);
+ t0 = L_sub(L_temp, t1, pOverflow);
+ t0 = L_abs(t0);
+
+ /* max/t0 */
+ /* shift1 = sub(norm_l(max), 1);
+ max16 = extract_h(L_shl(max, shift1));
+ shift2 = norm_l(t0);
+ t016 = extract_h(L_shl(t0, shift2)); */
+
+ t016 = norm_l(max);
+ shift1 = sub(t016, 1, pOverflow);
+
+ L_temp = L_shl(max, shift1, pOverflow);
+ max16 = (Word16)(L_temp >> 16);
+
+ shift2 = norm_l(t0);
+ L_temp = L_shl(t0, shift2, pOverflow);
+ t016 = (Word16)(L_temp >> 16);
+
+ if (t016 != 0)
+ {
+ cor_max = div_s(max16, t016);
+ }
+ else
+ {
+ cor_max = 0;
+ }
+
+ shift = sub(shift1, shift2, pOverflow);
+
+ if (shift >= 0)
+ {
+ *cor_hp_max = shr(cor_max, shift, pOverflow); /* Q15 */
+ }
+ else
+ {
+ *cor_hp_max = shl(cor_max, negate(shift), pOverflow); /* Q15 */
+ }
+
+ return 0;
+}
+
diff --git a/media/codecs/amrnb/enc/src/hp_max.h b/media/codecs/amrnb/enc/src/hp_max.h
new file mode 100644
index 0000000..b668924
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/hp_max.h
@@ -0,0 +1,116 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/hp_max.h
+
+ Date: 02/01/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : hp_max.h
+ Purpose : Find the maximum correlation of scal_sig[] in a given
+ delay range.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef HP_MAX_H
+#define HP_MAX_H "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 hp_max(
+ Word32 corr[], /* i : correlation vector. */
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word16 *cor_hp_max, /* o : max high-pass filtered norm. correlation */
+ Flag *pOverflow /* i/o : overflow Flag */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _HP_MAX_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/inter_36.cpp b/media/codecs/amrnb/enc/src/inter_36.cpp
new file mode 100644
index 0000000..87766a9
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/inter_36.cpp
@@ -0,0 +1,250 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/inter_36.c
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation
+ 4. Unrolled loops to speed up processing, use decrement loops
+ 5. Eliminated call to round by proper initialization
+
+ Description: Added casting to eliminate warnings
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Using intrinsics from fxp_arithmetic.h .
+
+ Description: Replacing fxp_arithmetic.h with basic_op.h.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "inter_36.h"
+#include "cnst.h"
+#include "inter_36_tab.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define UP_SAMP_MAX 6
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: inter_36
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pX = pointer to input vector of type Word16
+ frac = fraction (-2..2 for 3*, -3..3 for 6*) of type Word16
+ flag3 = if set, upsampling rate = 3 (6 otherwise) of type Word16
+ pOverflow = pointer to overflow flag
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : inter_36.c
+ Purpose : Interpolating the normalized correlation
+ : with 1/3 or 1/6 resolution.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ inter_36.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 i, k;
+ Word16 *x1, *x2;
+ const Word16 *c1, *c2;
+ Word32 s;
+
+ if (flag3 != 0)
+ {
+ frac = shl (frac, 1); // inter_3[k] = inter_6[2*k] -> k' = 2*k
+ }
+
+ if (frac < 0)
+ {
+ frac = add (frac, UP_SAMP_MAX);
+ x--;
+ }
+
+ x1 = &x[0];
+ x2 = &x[1];
+ c1 = &inter_6[frac];
+ c2 = &inter_6[sub (UP_SAMP_MAX, frac)];
+
+ s = 0;
+ for (i = 0, k = 0; i < L_INTER_SRCH; i++, k += UP_SAMP_MAX)
+ {
+ s = L_mac (s, x1[-i], c1[k]);
+ s = L_mac (s, x2[i], c2[k]);
+ }
+
+ return pv_round (s);
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 Interpol_3or6( /* o : interpolated value */
+ Word16 *pX, /* i : input vector */
+ Word16 frac, /* i : fraction (-2..2 for 3*, -3..3 for 6*) */
+ Word16 flag3, /* i : if set, upsampling rate = 3 (6 otherwise) */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 k;
+ Word16 *pX1;
+ Word16 *pX2;
+ const Word16 *pC1;
+ const Word16 *pC2;
+ Word32 s;
+ Word16 temp1;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ if (flag3 != 0)
+ {
+ frac <<= 1;
+ /* inter_3[k] = inter_6[2*k] -> k' = 2*k */
+ }
+
+ if (frac < 0)
+ {
+ frac += UP_SAMP_MAX;
+ pX--;
+ }
+
+ pX1 = &pX[0];
+ pX2 = &pX[1];
+ pC1 = &inter_6[frac];
+ temp1 = UP_SAMP_MAX - frac;
+ pC2 = &inter_6[temp1];
+
+ s = 0x04000;
+ k = 0;
+
+ for (i = (L_INTER_SRCH >> 1); i != 0; i--)
+ {
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX1--), (Word32) pC1[k], s);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX2++), (Word32) pC2[k], s);
+ k += UP_SAMP_MAX;
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX1--), (Word32) pC1[k], s);
+ s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX2++), (Word32) pC2[k], s);
+ k <<= 1;
+ }
+
+ return((Word16)(s >> 15));
+}
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/inter_36.h b/media/codecs/amrnb/enc/src/inter_36.h
new file mode 100644
index 0000000..f35a5c5
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/inter_36.h
@@ -0,0 +1,117 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/inter_36.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : inter_36.h
+ Purpose : Interpolating the normalized correlation
+ : with 1/3 or 1/6 resolution.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _INTER_36_H_
+#define _INTER_36_H_
+#define inter_36_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 Interpol_3or6( /* (o) : interpolated value */
+ Word16 *x, /* (i) : input vector */
+ Word16 frac, /* (i) : fraction (-2..2 for 3*, -3..3 for 6*) */
+ Word16 flag3, /* (i) : if set, upsampling rate = 3 (6 otherwise) */
+ Flag *pOverflow
+ );
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _INTER_36_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/inter_36_tab.cpp b/media/codecs/amrnb/enc/src/inter_36_tab.cpp
new file mode 100644
index 0000000..c8d7b13
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/inter_36_tab.cpp
@@ -0,0 +1,213 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: .audio/gsm-amr/c/src/inter_36_tab.c
+
+ Date: 02/01/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed tables from static const to just const.
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition. Removed corresponding header file from Include
+ section.
+
+ Description: Put "extern" back.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : inter_36.tab
+ Purpose : Tables for interpolating the normalized correlation
+ with 1/3 or 1/6 resolution.
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "inter_36_tab.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define UP_SAMP_MAX 6
+#define FIR_SIZE (UP_SAMP_MAX*L_INTER_SRCH+1)
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ /* 1/6 resolution interpolation filter (-3 dB at 3600 Hz) */
+ /* Note: The IS641 (7.4) 1/3 resolution filter is simply a subsampled
+ version of the 1/6 resolution filter, i.e. it uses
+ every second coefficient:
+
+ inter_3[k] = inter_6[2*k], 0 <= k <= 3*L_INTER_SRCH
+ */
+
+ const Word16 inter_6[FIR_SIZE] =
+ {
+ 29519,
+ 28316, 24906, 19838, 13896, 7945, 2755,
+ -1127, -3459, -4304, -3969, -2899, -1561,
+ -336, 534, 970, 1023, 823, 516,
+ 220, 0, -131, -194, -215, 0
+ };
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/inter_36_tab.h b/media/codecs/amrnb/enc/src/inter_36_tab.h
new file mode 100644
index 0000000..21ade69
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/inter_36_tab.h
@@ -0,0 +1,113 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: .audio/gsm-amr/c/include/inter_36_tab.h
+
+ Date: 02/01/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares a table BytesUsed.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef INTER_36_TAB_H
+#define INTER_36_TAB_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 inter_6[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/enc/src/l_comp.cpp b/media/codecs/amrnb/enc/src/l_comp.cpp
new file mode 100644
index 0000000..64be4dd
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/l_comp.cpp
@@ -0,0 +1,162 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ hi = 16 bit signed integer (Word16) whose value falls in
+ the range : 0x8000 <= hi <= 0x7fff.
+ lo = 16 bit signed integer (Word16) whose value falls in
+ the range : 0x8000 <= lo <= 0x7fff.
+
+ Outputs:
+ pOverflow = 1 if overflow happens in a math function called by this function.
+ L_out = 32-bit result of (hi<<16 + lo<<1).
+
+ Returns:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function composes a 32 bit integer from two 16 bit double precision
+ format (DPF) numbers hi and lo by the following operation:
+ 1. Deposit hi into the 16 MS bits of the 32 bit output L_out.
+ 2. Shift lo left by 1.
+ 3. Add results from 1 and 2 with saturation to return the 32 bit result
+ L_out.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] oper_32b.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "l_comp.h"
+#include "basic_op.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+Word32 L_Comp(Word16 hi, Word16 lo, Flag *pOverflow)
+{
+
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ Word32 L_32;
+ Word32 temp32;
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+
+ L_32 = L_deposit_h(hi);
+
+ temp32 = L_mac(L_32, lo, 1, pOverflow);
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+
+ return (temp32); /* = hi<<16 + lo<<1 */
+}
diff --git a/media/codecs/amrnb/enc/src/l_extract.cpp b/media/codecs/amrnb/enc/src/l_extract.cpp
new file mode 100644
index 0000000..6add299
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/l_extract.cpp
@@ -0,0 +1,174 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+
+
+
+ Filename: /audio/gsm_amr/c/src/l_extract.c
+
+ Date: 09/07/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Changed function interface to pass in a
+ pointer to overflow flag into the function instead of using a
+ global flag. Changed names of function parameters for clarity.
+ Removed inclusion of unwanted header files.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: L_extract
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var = 32 bit signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_32 <= 0x7fff ffff.
+
+ pL_var_hi = pointer to the most significant word of L_var (Word16).
+
+ pL_var_lo = pointer to the least significant word of L_var shifted
+ to the left by 1 (Word16).
+
+ pOverflow = pointer to overflow (Flag)
+
+ Outputs:
+ pOverflow -> 1 if the 32 bit add operation resulted in overflow
+ pL_var_hi -> MS word of L_32.
+ pL_var_lo -> LS word of L_32 shifted left by 1.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function extracts two 16-bit double precision format (DPF) numbers
+ from a 32-bit integer. The MS word of L_var will be stored in the location
+ pointed to by pL_var_hi and the shifted LS word of L_var will be stored in
+ the location pointed to by pL_var_lo.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] L_extract() function in oper_32b.c, UMTS GSM AMR speech codec, R99 -
+ Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void L_Extract(Word32 L_var,
+ Word16 *pL_var_hi,
+ Word16 *pL_var_lo,
+ Flag *pOverflow)
+{
+
+ Word32 temp;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ temp = (L_var >> 16);
+
+ *(pL_var_hi) = (Word16) temp;
+ *(pL_var_lo) = (Word16)((L_var >> 1) - (temp << 15));
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/l_negate.cpp b/media/codecs/amrnb/enc/src/l_negate.cpp
new file mode 100644
index 0000000..523e482
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/l_negate.cpp
@@ -0,0 +1,166 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ L_var1 = 32 bit long signed integer (Word32) whose value falls
+ in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ L_var1 = 32-bit negation of input
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function negates the 32 bit variable, L_var1, with saturation; saturate
+ in the case where input is -2147483648 (0x8000 0000).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] basicop2.c, ETS Version 2.0.0, February 8, 1999
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word32 L_negate (Word32 L_var1)
+{
+ Word32 L_var_out;
+
+ L_var_out = (L_var1 == MIN_32) ? MAX_32 : -L_var1;
+#if (WMOPS)
+ multiCounter[currCounter].L_negate++;
+#endif
+ return (L_var_out);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+Word32 L_negate(Word32 L_var1)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ L_var1 = (L_var1 == MIN_32) ? MAX_32 : -L_var1;
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return (L_var1);
+}
+
diff --git a/media/codecs/amrnb/enc/src/lag_wind.cpp b/media/codecs/amrnb/enc/src/lag_wind.cpp
new file mode 100644
index 0000000..0b2d2a1
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/lag_wind.cpp
@@ -0,0 +1,195 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/lag_wind.c
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated l_extract() function call
+
+ Description: Added casting to eliminate warnings
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "lag_wind.h"
+#include "lag_wind_tab.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lag_wind
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ m = LPC order of type Word16
+ r_h[] = pointer to autocorrelations (msb) of type Word16
+ r_l[] = pointer to autocorrelations (lsb) of type Word16
+ pOverflow = pointer to overflow flag
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : lag_wind.c
+ Purpose : Lag windowing of autocorrelations.
+
+ FUNCTION: Lag_window()
+
+ PURPOSE: Lag windowing of autocorrelations.
+
+ DESCRIPTION:
+ r[i] = r[i]*lag_wind[i], i=1,...,10
+
+ r[i] and lag_wind[i] are in special double precision format.
+ See "oper_32b.c" for the format.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lag_wind.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 i;
+ Word32 x;
+
+ for (i = 1; i <= m; i++)
+ {
+ x = Mpy_32 (r_h[i], r_l[i], lag_h[i - 1], lag_l[i - 1], pOverflow);
+ L_Extract (x, &r_h[i], &r_l[i], pOverflow);
+ }
+ return;
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void Lag_window(
+ Word16 m, /* (i) : LPC order */
+ Word16 r_h[], /* (i/o) : Autocorrelations (msb) */
+ Word16 r_l[], /* (i/o) : Autocorrelations (lsb) */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word32 x;
+ const Word16 *p_lag_h = &lag_h[0];
+ const Word16 *p_lag_l = &lag_l[0];
+ Word16 *p_r_h = &r_h[1];
+ Word16 *p_r_l = &r_l[1];
+
+ for (i = m; i != 0 ; i--)
+ {
+ x = Mpy_32(*(p_r_h), *(p_r_l), *(p_lag_h++), *(p_lag_l++), pOverflow);
+ *(p_r_h) = (Word16)(x >> 16);
+ *(p_r_l++) = (x >> 1) - (*(p_r_h++) << 15);
+ }
+
+ return;
+}
+
diff --git a/media/codecs/amrnb/enc/src/lag_wind.h b/media/codecs/amrnb/enc/src/lag_wind.h
new file mode 100644
index 0000000..4928ac4
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/lag_wind.h
@@ -0,0 +1,117 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/lag_wind.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : lag_wind.h
+ Purpose : Lag windowing of autocorrelations.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _LAG_WIND_H_
+#define _LAG_WIND_H_
+#define lag_wind_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ void Lag_window(
+ Word16 m, /* (i) : LPC order */
+ Word16 r_h[], /* (i/o) : Autocorrelations (msb) */
+ Word16 r_l[], /* (i/o) : Autocorrelations (lsb) */
+ Flag *pOverflow
+ );
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LAG_WIND_H_ */
+
+
+
diff --git a/media/codecs/amrnb/enc/src/lag_wind_tab.cpp b/media/codecs/amrnb/enc/src/lag_wind_tab.cpp
new file mode 100644
index 0000000..b0f5b3a
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/lag_wind_tab.cpp
@@ -0,0 +1,233 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: .audio/gsm-amr/c/src/lag_wind_tab.c
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus and removed "extern" from table
+ definition. Removed corresponding header file from Include
+ section.
+
+ Description: Put "extern" back.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ None
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ None
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ File : lag_wind.tab
+ Purpose : Table of lag_window for autocorrelation.
+
+ *-----------------------------------------------------*
+ | Table of lag_window for autocorrelation. |
+ | |
+ | noise floor = 1.0001 = (0.9999 on r[1] ..r[10]) |
+ | Bandwitdh expansion = 60 Hz |
+ | |
+ | |
+ | lag_wind[0] = 1.00000000 (not stored) |
+ | lag_wind[1] = 0.99879038 |
+ | lag_wind[2] = 0.99546897 |
+ | lag_wind[3] = 0.98995781 |
+ | lag_wind[4] = 0.98229337 |
+ | lag_wind[5] = 0.97252619 |
+ | lag_wind[6] = 0.96072036 |
+ | lag_wind[7] = 0.94695264 |
+ | lag_wind[8] = 0.93131179 |
+ | lag_wind[9] = 0.91389757 |
+ | lag_wind[10]= 0.89481968 |
+ -------------------------------------------------------
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ None
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "lag_wind_tab.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+ const Word16 lag_h[10] =
+ {
+ 32728,
+ 32619,
+ 32438,
+ 32187,
+ 31867,
+ 31480,
+ 31029,
+ 30517,
+ 29946,
+ 29321
+ };
+
+ const Word16 lag_l[10] =
+ {
+ 11904,
+ 17280,
+ 30720,
+ 25856,
+ 24192,
+ 28992,
+ 24384,
+ 7360,
+ 19520,
+ 14784
+ };
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL FUNCTION REFERENCES
+ ; Declare functions defined elsewhere and referenced in this module
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/amrnb/enc/src/lag_wind_tab.h b/media/codecs/amrnb/enc/src/lag_wind_tab.h
new file mode 100644
index 0000000..c210932
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/lag_wind_tab.h
@@ -0,0 +1,112 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Pathname: .audio/gsm-amr/c/include/lag_wind_tab.h
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added #ifdef __cplusplus after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file declares tables used by lag_wind.c.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef LAG_WIND_TAB_H
+#define LAG_WIND_TAB_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 lag_h[];
+ extern const Word16 lag_l[];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/media/codecs/amrnb/enc/src/levinson.cpp b/media/codecs/amrnb/enc/src/levinson.cpp
new file mode 100644
index 0000000..29cdac6
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/levinson.cpp
@@ -0,0 +1,824 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/levinson.c
+ Funtions: Levinson_init
+ Levinson_reset
+ Levinson_exit
+ Levinson
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the function the implements the Levinson-Durbin algorithm
+ using double-precision arithmetic. This file also includes functions to
+ initialize, allocate, and deallocate memory used by the Levinson function.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <string.h>
+
+#include "levinson.h"
+#include "basicop_malloc.h"
+#include "basic_op.h"
+#include "div_32.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Levinson_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to an array of pointers to structures of type
+ LevinsonState
+
+ Outputs:
+ pointer pointed to by state points to the newly allocated memory to
+ be used by Levinson function
+
+ Returns:
+ return_value = 0, if initialization was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function allocates and initializes the state memory used by the
+ Levinson function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ levinson.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Levinson_init (LevinsonState **state)
+{
+ LevinsonState* s;
+
+ if (state == (LevinsonState **) NULL){
+ //fprint(stderr, "Levinson_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (LevinsonState *) malloc(sizeof(LevinsonState))) == NULL){
+ //fprint(stderr, "Levinson_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ Levinson_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Levinson_init(LevinsonState **state)
+{
+ LevinsonState* s;
+
+ if (state == (LevinsonState **) NULL)
+ {
+ /* fprint(stderr, "Levinson_init: invalid parameter\n"); */
+ return(-1);
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (LevinsonState *) malloc(sizeof(LevinsonState))) == NULL)
+ {
+ /* fprint(stderr, "Levinson_init:
+ can not malloc state structure\n"); */
+ return(-1);
+ }
+
+ Levinson_reset(s);
+ *state = s;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Levinson_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to structures of type LevinsonState
+
+ Outputs:
+ old_A field of structure pointed to by state is initialized to 4096
+ (first location) and the rest to zeros
+
+ Returns:
+ return_value = 0, if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes the state memory used by the Levinson function to
+ zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ levinson.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Levinson_reset (LevinsonState *state)
+{
+ Word16 i;
+
+ if (state == (LevinsonState *) NULL){
+ fprint(stderr, "Levinson_reset: invalid parameter\n");
+ return -1;
+ }
+
+ state->old_A[0] = 4096;
+ for(i = 1; i < M + 1; i++)
+ state->old_A[i] = 0;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Levinson_reset(LevinsonState *state)
+{
+ Word16 i;
+
+ if (state == (LevinsonState *) NULL)
+ {
+ /* fprint(stderr, "Levinson_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ state->old_A[0] = 4096;
+ for (i = 1; i < M + 1; i++)
+ {
+ state->old_A[i] = 0;
+ }
+
+ return(0);
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Levinson_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to an array of pointers to structures of type
+ LevinsonState
+
+ Outputs:
+ pointer pointed to by state is set to the NULL address
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function deallocates the state memory used by the Levinson function.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ levinson.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Levinson_exit (LevinsonState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Levinson_exit(LevinsonState **state)
+{
+ if (state == NULL || *state == NULL)
+ {
+ return;
+ }
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Levinson
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to structures of type LevinsonState
+ Rh = vector containing most significant byte of
+ autocorrelation values (Word16)
+ Rl = vector containing least significant byte of
+ autocorrelation values (Word16)
+ A = vector of LPC coefficients (10th order) (Word16)
+ rc = vector containing first four reflection coefficients (Word16)
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ A contains the newly calculated LPC coefficients
+ rc contains the newly calculated reflection coefficients
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function implements the Levinson-Durbin algorithm using double-
+ precision arithmetic. This is used to compute the Linear Predictive (LP)
+ filter parameters from the speech autocorrelation values.
+
+ The algorithm implemented is as follows:
+ A[0] = 1
+ K = -R[1]/R[0]
+ A[1] = K
+ Alpha = R[0] * (1-K**2]
+
+ FOR i = 2 to M
+
+ S = SUM ( R[j]*A[i-j] ,j=1,i-1 ) + R[i]
+ K = -S / Alpha
+
+ FOR j = 1 to i-1
+ An[j] = A[j] + K*A[i-j] where An[i] = new A[i]
+ ENDFOR
+
+ An[i]=K
+ Alpha=Alpha * (1-K**2)
+
+ END
+
+ where:
+ R[i] = autocorrelations
+ A[i] = filter coefficients
+ K = reflection coefficient
+ Alpha = prediction gain
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ levinson.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Levinson (
+ LevinsonState *st,
+ Word16 Rh[], // i : Rh[m+1] Vector of autocorrelations (msb)
+ Word16 Rl[], // i : Rl[m+1] Vector of autocorrelations (lsb)
+ Word16 A[], // o : A[m] LPC coefficients (m = 10)
+ Word16 rc[] // o : rc[4] First 4 reflection coefficients
+)
+{
+ Word16 i, j;
+ Word16 hi, lo;
+ Word16 Kh, Kl; // reflexion coefficient; hi and lo
+ Word16 alp_h, alp_l, alp_exp; // Prediction gain; hi lo and exponent
+ Word16 Ah[M + 1], Al[M + 1]; // LPC coef. in double prec.
+ Word16 Anh[M + 1], Anl[M + 1];// LPC coef.for next iteration in double
+ prec.
+ Word32 t0, t1, t2; // temporary variable
+
+ // K = A[1] = -R[1] / R[0]
+
+ t1 = L_Comp (Rh[1], Rl[1]);
+ t2 = L_abs (t1); // abs R[1]
+ t0 = Div_32 (t2, Rh[0], Rl[0]); // R[1]/R[0]
+ if (t1 > 0)
+ t0 = L_negate (t0); // -R[1]/R[0]
+ L_Extract (t0, &Kh, &Kl); // K in DPF
+
+ rc[0] = pv_round (t0);
+
+ t0 = L_shr (t0, 4); // A[1] in
+ L_Extract (t0, &Ah[1], &Al[1]); // A[1] in DPF
+
+ // Alpha = R[0] * (1-K**2)
+
+ t0 = Mpy_32 (Kh, Kl, Kh, Kl); // K*K
+ t0 = L_abs (t0); // Some case <0 !!
+ t0 = L_sub ((Word32) 0x7fffffffL, t0); // 1 - K*K
+ L_Extract (t0, &hi, &lo); // DPF format
+ t0 = Mpy_32 (Rh[0], Rl[0], hi, lo); // Alpha in
+
+ // Normalize Alpha
+
+ alp_exp = norm_l (t0);
+ t0 = L_shl (t0, alp_exp);
+ L_Extract (t0, &alp_h, &alp_l); // DPF format
+
+ *--------------------------------------*
+ * ITERATIONS I=2 to M *
+ *--------------------------------------*
+
+ for (i = 2; i <= M; i++)
+ {
+ // t0 = SUM ( R[j]*A[i-j] ,j=1,i-1 ) + R[i]
+
+ t0 = 0;
+ for (j = 1; j < i; j++)
+ {
+ t0 = L_add (t0, Mpy_32 (Rh[j], Rl[j], Ah[i - j], Al[i - j]));
+ }
+ t0 = L_shl (t0, 4);
+
+ t1 = L_Comp (Rh[i], Rl[i]);
+ t0 = L_add (t0, t1); // add R[i]
+
+ // K = -t0 / Alpha
+
+ t1 = L_abs (t0);
+ t2 = Div_32 (t1, alp_h, alp_l); // abs(t0)/Alpha
+ if (t0 > 0)
+ t2 = L_negate (t2); // K =-t0/Alpha
+ t2 = L_shl (t2, alp_exp); // denormalize; compare to Alpha
+ L_Extract (t2, &Kh, &Kl); // K in DPF
+
+ if (sub (i, 5) < 0)
+ {
+ rc[i - 1] = pv_round (t2);
+ }
+ // Test for unstable filter. If unstable keep old A(z)
+
+ if (sub (abs_s (Kh), 32750) > 0)
+ {
+ for (j = 0; j <= M; j++)
+ {
+ A[j] = st->old_A[j];
+ }
+
+ for (j = 0; j < 4; j++)
+ {
+ rc[j] = 0;
+ }
+
+ return 0;
+ }
+ *------------------------------------------*
+ * Compute new LPC coeff. -> An[i] *
+ * An[j]= A[j] + K*A[i-j] , j=1 to i-1 *
+ * An[i]= K *
+ *------------------------------------------*
+
+ for (j = 1; j < i; j++)
+ {
+ t0 = Mpy_32 (Kh, Kl, Ah[i - j], Al[i - j]);
+ t0 = L_add(t0, L_Comp(Ah[j], Al[j]));
+ L_Extract (t0, &Anh[j], &Anl[j]);
+ }
+ t2 = L_shr (t2, 4);
+ L_Extract (t2, &Anh[i], &Anl[i]);
+
+ // Alpha = Alpha * (1-K**2)
+
+ t0 = Mpy_32 (Kh, Kl, Kh, Kl); // K*K
+ t0 = L_abs (t0); // Some case <0 !!
+ t0 = L_sub ((Word32) 0x7fffffffL, t0); // 1 - K*K
+ L_Extract (t0, &hi, &lo); // DPF format
+ t0 = Mpy_32 (alp_h, alp_l, hi, lo);
+
+ // Normalize Alpha
+
+ j = norm_l (t0);
+ t0 = L_shl (t0, j);
+ L_Extract (t0, &alp_h, &alp_l); // DPF format
+ alp_exp = add (alp_exp, j); // Add normalization to
+ alp_exp
+
+ // A[j] = An[j]
+
+ for (j = 1; j <= i; j++)
+ {
+ Ah[j] = Anh[j];
+ Al[j] = Anl[j];
+ }
+ }
+
+ A[0] = 4096;
+ for (i = 1; i <= M; i++)
+ {
+ t0 = L_Comp (Ah[i], Al[i]);
+ st->old_A[i] = A[i] = pv_round (L_shl (t0, 1));
+ }
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Levinson(
+ LevinsonState *st,
+ Word16 Rh[], /* i : Rh[m+1] Vector of autocorrelations (msb) */
+ Word16 Rl[], /* i : Rl[m+1] Vector of autocorrelations (lsb) */
+ Word16 A[], /* o : A[m] LPC coefficients (m = 10) */
+ Word16 rc[], /* o : rc[4] First 4 reflection coefficients */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 hi;
+ Word16 lo;
+ Word16 Kh; /* reflexion coefficient; hi and lo */
+ Word16 Kl;
+ Word16 alp_h; /* Prediction gain; hi lo and exponent*/
+ Word16 alp_l;
+ Word16 alp_exp;
+ Word16 Ah[M + 1]; /* LPC coef. in double prec. */
+ Word16 Al[M + 1];
+ Word16 Anh[M + 1]; /* LPC coef.for next iteration in */
+ Word16 Anl[M + 1]; /* double prec. */
+ Word32 t0; /* temporary variable */
+ Word32 t1; /* temporary variable */
+ Word32 t2; /* temporary variable */
+
+ Word16 *p_Rh;
+ Word16 *p_Rl;
+ Word16 *p_Ah;
+ Word16 *p_Al;
+ Word16 *p_Anh;
+ Word16 *p_Anl;
+ Word16 *p_A;
+
+ /* K = A[1] = -R[1] / R[0] */
+ t1 = ((Word32) * (Rh + 1)) << 16;
+ t1 += *(Rl + 1) << 1;
+
+ t2 = L_abs(t1); /* abs R[1] - required by Div_32 */
+ t0 = Div_32(t2, *Rh, *Rl, pOverflow); /* R[1]/R[0] */
+
+ if (t1 > 0)
+ {
+ t0 = L_negate(t0); /* -R[1]/R[0] */
+ }
+
+ /* K in DPF */
+ Kh = (Word16)(t0 >> 16);
+ Kl = (Word16)((t0 >> 1) - ((Word32)(Kh) << 15));
+
+ *rc = pv_round(t0, pOverflow);
+
+ t0 = t0 >> 4;
+
+ /* A[1] in DPF */
+ *(Ah + 1) = (Word16)(t0 >> 16);
+
+ *(Al + 1) = (Word16)((t0 >> 1) - ((Word32)(*(Ah + 1)) << 15));
+
+ /* Alpha = R[0] * (1-K**2) */
+ t0 = Mpy_32(Kh, Kl, Kh, Kl, pOverflow); /* K*K */
+ t0 = L_abs(t0); /* Some case <0 !! */
+ t0 = 0x7fffffffL - t0; /* 1 - K*K */
+
+ /* DPF format */
+ hi = (Word16)(t0 >> 16);
+ lo = (Word16)((t0 >> 1) - ((Word32)(hi) << 15));
+
+ t0 = Mpy_32(*Rh, *Rl, hi, lo, pOverflow); /* Alpha in */
+
+ /* Normalize Alpha */
+
+ alp_exp = norm_l(t0);
+ t0 = t0 << alp_exp;
+
+ /* DPF format */
+ alp_h = (Word16)(t0 >> 16);
+ alp_l = (Word16)((t0 >> 1) - ((Word32)(alp_h) << 15));
+
+ /*--------------------------------------*
+ * ITERATIONS I=2 to M *
+ *--------------------------------------*/
+
+ for (i = 2; i <= M; i++)
+ {
+ /* t0 = SUM ( R[j]*A[i-j] ,j=1,i-1 ) + R[i] */
+
+ t0 = 0;
+ p_Rh = &Rh[1];
+ p_Rl = &Rl[1];
+ p_Ah = &Ah[i-1];
+ p_Al = &Al[i-1];
+ for (j = 1; j < i; j++)
+ {
+ t0 += (((Word32) * (p_Rh)* *(p_Al--)) >> 15);
+ t0 += (((Word32) * (p_Rl++)* *(p_Ah)) >> 15);
+ t0 += ((Word32) * (p_Rh++)* *(p_Ah--));
+ }
+
+ t0 = t0 << 5;
+
+ t1 = ((Word32) * (Rh + i) << 16) + ((Word32)(*(Rl + i)) << 1);
+ t0 += t1;
+
+ /* K = -t0 / Alpha */
+
+ t1 = L_abs(t0);
+ t2 = Div_32(t1, alp_h, alp_l, pOverflow); /* abs(t0)/Alpha */
+
+ if (t0 > 0)
+ {
+ t2 = L_negate(t2); /* K =-t0/Alpha */
+ }
+
+ t2 = L_shl(t2, alp_exp, pOverflow); /* denormalize; compare to Alpha */
+ Kh = (Word16)(t2 >> 16);
+ Kl = (Word16)((t2 >> 1) - ((Word32)(Kh) << 15));
+
+ if (i < 5)
+ {
+ *(rc + i - 1) = (Word16)((t2 + 0x00008000L) >> 16);
+ }
+ /* Test for unstable filter. If unstable keep old A(z) */
+ if ((abs_s(Kh)) > 32750)
+ {
+ memcpy(A, &(st->old_A[0]), sizeof(Word16)*(M + 1));
+ memset(rc, 0, sizeof(Word16)*4);
+ return(0);
+ }
+ /*------------------------------------------*
+ * Compute new LPC coeff. -> An[i] *
+ * An[j]= A[j] + K*A[i-j] , j=1 to i-1 *
+ * An[i]= K *
+ *------------------------------------------*/
+ p_Ah = &Ah[i-1];
+ p_Al = &Al[i-1];
+ p_Anh = &Anh[1];
+ p_Anl = &Anl[1];
+ for (j = 1; j < i; j++)
+ {
+ t0 = (((Word32)Kh* *(p_Al--)) >> 15);
+ t0 += (((Word32)Kl* *(p_Ah)) >> 15);
+ t0 += ((Word32)Kh* *(p_Ah--));
+
+ t0 += (Ah[j] << 15) + Al[j];
+
+ *(p_Anh) = (Word16)(t0 >> 15);
+ *(p_Anl++) = (Word16)(t0 - ((Word32)(*(p_Anh++)) << 15));
+ }
+
+ *(p_Anh) = (Word16)(t2 >> 20);
+ *(p_Anl) = (Word16)((t2 >> 5) - ((Word32)(*(Anh + i)) << 15));
+
+ /* Alpha = Alpha * (1-K**2) */
+
+ t0 = Mpy_32(Kh, Kl, Kh, Kl, pOverflow); /* K*K */
+ t0 = L_abs(t0); /* Some case <0 !! */
+ t0 = 0x7fffffffL - t0; /* 1 - K*K */
+
+ hi = (Word16)(t0 >> 16);
+ lo = (Word16)((t0 >> 1) - ((Word32)(hi) << 15));
+
+ t0 = (((Word32)alp_h * lo) >> 15);
+ t0 += (((Word32)alp_l * hi) >> 15);
+ t0 += ((Word32)alp_h * hi);
+
+ t0 <<= 1;
+ /* Normalize Alpha */
+
+ j = norm_l(t0);
+ t0 <<= j;
+ alp_h = (Word16)(t0 >> 16);
+ alp_l = (Word16)((t0 >> 1) - ((Word32)(alp_h) << 15));
+ alp_exp += j; /* Add normalization to alp_exp */
+
+ /* A[j] = An[j] */
+ memcpy(&Ah[1], &Anh[1], sizeof(Word16)*i);
+ memcpy(&Al[1], &Anl[1], sizeof(Word16)*i);
+ }
+
+ p_A = &A[0];
+ *(p_A++) = 4096;
+ p_Ah = &Ah[1];
+ p_Al = &Al[1];
+
+ for (i = 1; i <= M; i++)
+ {
+ t0 = ((Word32) * (p_Ah++) << 15) + *(p_Al++);
+ st->old_A[i] = *(p_A++) = (Word16)((t0 + 0x00002000) >> 14);
+ }
+
+ return(0);
+}
diff --git a/media/codecs/amrnb/enc/src/levinson.h b/media/codecs/amrnb/enc/src/levinson.h
new file mode 100644
index 0000000..65ba481
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/levinson.h
@@ -0,0 +1,143 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/levinson.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+ Description: 1. Modified "int" definition by Word16
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : lag_wind.h
+ Purpose : Lag windowing of autocorrelations.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _LEVINSON_H_
+#define _LEVINSON_H_
+#define levinson_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 old_A[M + 1]; /* Last A(z) for case of unstable filter */
+ } LevinsonState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 Levinson_init(LevinsonState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to Levinson in each call.
+ returns 0 on success
+ */
+
+ Word16 Levinson_reset(LevinsonState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void Levinson_exit(LevinsonState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ Word16 Levinson(
+ LevinsonState *st,
+ Word16 Rh[], /* i : Rh[m+1] Vector of autocorrelations (msb) */
+ Word16 Rl[], /* i : Rl[m+1] Vector of autocorrelations (lsb) */
+ Word16 A[], /* o : A[m] LPC coefficients (m = 10) */
+ Word16 rc[], /* o : rc[4] First 4 reflection coefficients */
+ Flag *pOverflow
+ );
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LEVINSON_H_ */
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/lpc.cpp b/media/codecs/amrnb/enc/src/lpc.cpp
new file mode 100644
index 0000000..3c1a4bc
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/lpc.cpp
@@ -0,0 +1,542 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/lpc.c
+
+ Date: 01/31/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updating includes and making code more simple as per comments.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "lpc.h"
+#include "typedef.h"
+#include "oper_32b.h"
+#include "autocorr.h"
+#include "lag_wind.h"
+#include "levinson.h"
+#include "cnst.h"
+#include "mode.h"
+#include "window_tab.h"
+#include "sub.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lpc_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer of state data of type lpcState
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes the state data for the LPC module.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+ lpcState* s;
+
+ if (state == (lpcState **) NULL){
+ // fprintf(stderr, "lpc_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (lpcState *) malloc(sizeof(lpcState))) == NULL){
+ // fprintf(stderr, "lpc_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ s->levinsonSt = NULL;
+
+ // Init sub states
+ if (Levinson_init(&s->levinsonSt)) {
+ lpc_exit(&s);
+ return -1;
+ }
+
+
+ lpc_reset(s);
+ *state = s;
+
+ return 0;
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 lpc_init(lpcState **state)
+{
+ lpcState* s;
+
+ if (state == (lpcState **) NULL)
+ {
+ /* fprintf(stderr, "lpc_init: invalid parameter\n"); */
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (lpcState *) malloc(sizeof(lpcState))) == NULL)
+ {
+ /* fprintf(stderr, "lpc_init: can not malloc state structure\n"); */
+ return -1;
+ }
+
+ s->levinsonSt = NULL;
+
+ /* Init sub states */
+ if (Levinson_init(&s->levinsonSt))
+ {
+ lpc_exit(&s);
+ return -1;
+ }
+
+ lpc_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lpc_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer of state data of type lpcState
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets the state data for the LPC module.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ if (state == (lpcState *) NULL){
+ // fprintf(stderr, "lpc_reset: invalid parameter\n");
+ return -1;
+ }
+
+ Levinson_reset(state->levinsonSt);
+
+ return 0;
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 lpc_reset(lpcState *state)
+{
+
+ if (state == (lpcState *) NULL)
+ {
+ /* fprintf(stderr, "lpc_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ Levinson_reset(state->levinsonSt);
+
+ return 0;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lpc_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer of state data of type lpcState
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function frees the state data for the LPC module.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+ if (state == NULL || *state == NULL)
+ return;
+
+ Levinson_exit(&(*state)->levinsonSt);
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void lpc_exit(lpcState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ Levinson_exit(&(*state)->levinsonSt);
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: lpc
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to state data of type lpcState
+ mode = coder mode of type enum Mode
+ x[] = pointer to input signal (Q15) of type Word16
+ x_12k2[] = pointer to input signal (EFR) (Q15) of type Word16
+ pOverflow = pointer to overflow indicator of type Flag
+
+ Outputs:
+ a[] = pointer to predictor coefficients (Q12) of type Word16
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function executes the LPC functionality for GSM AMR.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Word16 rc[4]; // First 4 reflection coefficients Q15
+ Word16 rLow[MP1], rHigh[MP1]; // Autocorrelations low and hi
+ // No fixed Q value but normalized
+ // so that overflow is avoided
+
+ if ( sub ((Word16)mode, (Word16)MR122) == 0)
+ {
+ // Autocorrelations
+ Autocorr(x_12k2, M, rHigh, rLow, window_160_80);
+ // Lag windowing
+ Lag_window(M, rHigh, rLow);
+ // Levinson Durbin
+ Levinson(st->levinsonSt, rHigh, rLow, &a[MP1], rc);
+
+ // Autocorrelations
+ Autocorr(x_12k2, M, rHigh, rLow, window_232_8);
+ // Lag windowing
+ Lag_window(M, rHigh, rLow);
+ // Levinson Durbin
+ Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
+ }
+ else
+ {
+ // Autocorrelations
+ Autocorr(x, M, rHigh, rLow, window_200_40);
+ // Lag windowing
+ Lag_window(M, rHigh, rLow);
+ // Levinson Durbin
+ Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
+ }
+
+ return 0;
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void lpc(
+ lpcState *st, /* i/o: State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 x[], /* i : Input signal Q15 */
+ Word16 x_12k2[], /* i : Input signal (EFR) Q15 */
+ Word16 a[], /* o : predictor coefficients Q12 */
+ Flag *pOverflow
+)
+{
+ Word16 rc[4]; /* First 4 reflection coefficients Q15 */
+ Word16 rLow[MP1], rHigh[MP1]; /* Autocorrelations low and hi */
+ /* No fixed Q value but normalized */
+ /* so that overflow is avoided */
+
+ if (mode == MR122)
+ {
+ /* Autocorrelations */
+ Autocorr(x_12k2, M, rHigh, rLow, window_160_80, pOverflow);
+ /* Lag windowing */
+ Lag_window(M, rHigh, rLow, pOverflow);
+ /* Levinson Durbin */
+ Levinson(st->levinsonSt, rHigh, rLow, &a[MP1], rc, pOverflow);
+
+ /* Autocorrelations */
+ Autocorr(x_12k2, M, rHigh, rLow, window_232_8, pOverflow);
+ /* Lag windowing */
+ Lag_window(M, rHigh, rLow, pOverflow);
+ /* Levinson Durbin */
+ Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc, pOverflow);
+ }
+ else
+ {
+ /* Autocorrelations */
+ Autocorr(x, M, rHigh, rLow, window_200_40, pOverflow);
+ /* Lag windowing */
+ Lag_window(M, rHigh, rLow, pOverflow);
+ /* Levinson Durbin */
+ Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc, pOverflow);
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/lpc.h b/media/codecs/amrnb/enc/src/lpc.h
new file mode 100644
index 0000000..705a1d4
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/lpc.h
@@ -0,0 +1,147 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/lpc.h
+
+ Date: 01/29/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : lpc.h
+ Purpose : 2 LP analyses centered at 2nd and 4th subframe
+ for mode 12.2. For all other modes a
+ LP analysis centered at 4th subframe is
+ performed.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _LPC_H_
+#define _LPC_H_
+#define lpc_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "levinson.h"
+#include "mode.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ LevinsonState *levinsonSt;
+ } lpcState;
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 lpc_init(lpcState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to lpc in each call.
+ returns 0 on success
+ */
+
+ Word16 lpc_reset(lpcState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void lpc_exit(lpcState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void lpc(
+ lpcState *st, /* i/o: State struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 x[], /* i : Input signal Q15 */
+ Word16 x_12k2[], /* i : Input signal (EFR) Q15 */
+ Word16 a[], /* o : predictor coefficients Q12 */
+ Flag *pOverflow
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LPC_H_ */
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/ol_ltp.cpp b/media/codecs/amrnb/enc/src/ol_ltp.cpp
new file mode 100644
index 0000000..7d034e0
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ol_ltp.cpp
@@ -0,0 +1,246 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/ol_ltp.c
+ Funtions: ol_ltp
+
+ Date: 04/18/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Adding pOverflow to the functions to remove global variables.
+ These changes are needed for the EPOC releases. Cleaned up code.
+ Updated template.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "ol_ltp.h"
+#include "cnst.h"
+#include "pitch_ol.h"
+#include "p_ol_wgh.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ol_ltp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to pitchOLWghtState structure
+ vadSt = pointer to a vadState structure
+ mode = coder mode (Mode)
+ wsp = pointer to buffer of signal used to compute the Open loop pitch
+ T_op = pointer to open loop pitch lag
+ old_lags = pointer to history with old stored Cl lags (Word16)
+ ol_gain_flg = pointer to OL gain flag (Word16)
+ idx = 16 bit value specifies the frame index
+ dtx = Data of type 'Flag' used for dtx. Use dtx=1, do not use dtx=0
+ pOverflow = pointer to Overflow indicator (Flag)
+
+ Outputs:
+ pOverflow -> 1 if processing this funvction results in satuaration
+
+ Returns:
+ Zero
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the open loop pitch lag.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ol_ltp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int ol_ltp(
+ pitchOLWghtState *st, // i/o : State struct
+ vadState *vadSt, // i/o : VAD state struct
+ enum Mode mode, // i : coder mode
+ Word16 wsp[], // i : signal used to compute the OL pitch, Q0
+ // uses signal[-pit_max] to signal[-1]
+ Word16 *T_op, // o : open loop pitch lag, Q0
+ Word16 old_lags[], // i : history with old stored Cl lags
+ Word16 ol_gain_flg[], // i : OL gain flag
+ Word16 idx, // i : index
+ Flag dtx // i : dtx flag; use dtx=1, do not use dtx=0
+ )
+{
+ if (sub ((Word16)mode, (Word16)MR102) != 0 )
+ {
+ ol_gain_flg[0] = 0;
+ ol_gain_flg[1] = 0;
+ }
+
+ if (sub ((Word16)mode, (Word16)MR475) == 0 || sub ((Word16)mode, (Word16)MR515) == 0 )
+ {
+ *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME, idx, dtx);
+ }
+ else
+ {
+ if ( sub ((Word16)mode, (Word16)MR795) <= 0 )
+ {
+ *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
+ idx, dtx);
+ }
+ else if ( sub ((Word16)mode, (Word16)MR102) == 0 )
+ {
+ *T_op = Pitch_ol_wgh(st, vadSt, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
+ old_lags, ol_gain_flg, idx, dtx);
+ }
+ else
+ {
+ *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN_MR122, PIT_MAX,
+ L_FRAME_BY2, idx, dtx);
+ }
+ }
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void ol_ltp(
+ pitchOLWghtState *st, /* i/o : State struct */
+ vadState *vadSt, /* i/o : VAD state struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 wsp[], /* i : signal used to compute the OL pitch, Q0 */
+ /* uses signal[-pit_max] to signal[-1] */
+ Word16 *T_op, /* o : open loop pitch lag, Q0 */
+ Word16 old_lags[], /* i : history with old stored Cl lags */
+ Word16 ol_gain_flg[], /* i : OL gain flag */
+ Word16 idx, /* i : index */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow indicator */
+)
+{
+ if ((mode != MR102))
+ {
+ ol_gain_flg[0] = 0;
+ ol_gain_flg[1] = 0;
+ }
+
+ if ((mode == MR475) || (mode == MR515))
+ {
+ *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME, idx, dtx,
+ pOverflow);
+ }
+ else
+ {
+ if (mode <= MR795)
+ {
+ *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
+ idx, dtx, pOverflow);
+ }
+ else if (mode == MR102)
+ {
+ *T_op = Pitch_ol_wgh(st, vadSt, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
+ old_lags, ol_gain_flg, idx, dtx, pOverflow);
+ }
+ else
+ {
+ *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN_MR122, PIT_MAX,
+ L_FRAME_BY2, idx, dtx, pOverflow);
+ }
+ }
+
+}
+
diff --git a/media/codecs/amrnb/enc/src/ol_ltp.h b/media/codecs/amrnb/enc/src/ol_ltp.h
new file mode 100644
index 0000000..f8c1481
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ol_ltp.h
@@ -0,0 +1,125 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/ol_ltp.h
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : ol_ltp.h
+ Purpose : Compute the open loop pitch lag.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef OL_LTP_H
+#define OL_LTP_H "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "p_ol_wgh.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ void ol_ltp(
+ pitchOLWghtState *st, /* i/o : State struct */
+ vadState *vadSt, /* i/o : VAD state struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 wsp[], /* i : signal used to compute the OL pitch, Q0 */
+ /* uses signal[-pit_max] to signal[-1] */
+ Word16 *T_op, /* o : open loop pitch lag, Q0 */
+ Word16 old_lags[], /* i : history with old stored Cl lags */
+ Word16 ol_gain_flg[], /* i : OL gain flag */
+ Word16 idx, /* i : index */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow Flag */
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _OL_LTP_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/p_ol_wgh.cpp b/media/codecs/amrnb/enc/src/p_ol_wgh.cpp
new file mode 100644
index 0000000..68d7345
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/p_ol_wgh.cpp
@@ -0,0 +1,989 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/p_ol_wgh.c
+ Funtions: p_ol_wgh_init
+ p_ol_wgh_reset
+ p_ol_wgh_exit
+ Lag_max
+ Pitch_ol_wgh
+
+ Date: 02/05/2002
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: t0 was not being declared as Word32.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ The modules in this file compute the open loop pitch lag with weighting.
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "p_ol_wgh.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "basic_op.h"
+#include "gmed_n.h"
+#include "inv_sqrt.h"
+#include "vad1.h"
+#include "calc_cor.h"
+#include "hp_max.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: p_ol_wgh_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs
+ state = pointer to a pointer of structure type pitchOLWghtState
+
+ Outputs:
+ None
+
+ Returns:
+ 0 if the memory allocation is a success
+ -1 if the memory allocation fails
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function allocates state memory and initializes state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int p_ol_wgh_init (pitchOLWghtState **state)
+{
+ pitchOLWghtState* s;
+
+ if (state == (pitchOLWghtState **) NULL){
+ // fprintf(stderr, "p_ol_wgh_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (pitchOLWghtState *) malloc(sizeof(pitchOLWghtState))) == NULL){
+ // fprintf(stderr, "p_ol_wgh_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ p_ol_wgh_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 p_ol_wgh_init(pitchOLWghtState **state)
+{
+ pitchOLWghtState* s;
+
+ if (state == (pitchOLWghtState **) NULL)
+ {
+ /* fprintf(stderr, "p_ol_wgh_init: invalid parameter\n"); */
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (pitchOLWghtState *) malloc(sizeof(pitchOLWghtState))) == NULL)
+ {
+ /* fprintf(stderr, "p_ol_wgh_init: can not malloc state structure\n"); */
+ return -1;
+ }
+
+ p_ol_wgh_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+/*----------------------------------------------------------------------------
+; End Function: p_ol_wgh_init
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: p_ol_wgh_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs
+ st = pointer to structure type pitchOLWghtState
+
+ Outputs:
+ None
+
+ Returns:
+ 0 if the memory initialization is a success
+ -1 if the memory initialization fails
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initializes state memory to zero
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int p_ol_wgh_reset (pitchOLWghtState *st)
+{
+ if (st == (pitchOLWghtState *) NULL){
+ // fprintf(stderr, "p_ol_wgh_reset: invalid parameter\n");
+ return -1;
+ }
+
+ // Reset pitch search states
+ st->old_T0_med = 40;
+ st->ada_w = 0;
+ st->wght_flg = 0;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 p_ol_wgh_reset(pitchOLWghtState *st)
+{
+ if (st == (pitchOLWghtState *) NULL)
+ {
+ /* fprintf(stderr, "p_ol_wgh_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ /* Reset pitch search states */
+ st->old_T0_med = 40;
+ st->ada_w = 0;
+ st->wght_flg = 0;
+
+ return 0;
+}
+
+/*----------------------------------------------------------------------------
+; End Function: p_ol_wgh_reset
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: p_ol_wgh_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs
+ st = pointer to a pointer of structure type pitchOLWghtState
+
+ Outputs:
+ None
+
+ Returns:
+ 0 if the memory initialization is a success
+ -1 if the memory initialization fails
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function frees the memory used for state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void p_ol_wgh_exit (pitchOLWghtState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void p_ol_wgh_exit(pitchOLWghtState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+; End Function: p_ol_wgh_exit
+----------------------------------------------------------------------------*/
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Lag_max
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ corr = pointer to buffer of correlation values (Word32)
+ scal_sig = pointer to buffer of scaled signal values (Word16)
+ scal_fac = scaled signal factor (Word16)
+ scal_flag = EFR compatible scaling flag (Word16)
+ L_frame = length of frame to compute pitch (Word16)
+ lag_max = maximum lag (Word16)
+ lag_min = minimum lag (Word16)
+ cor_max = pointer to the normalized correlation of selected lag (Word16)
+ rmax = pointer to max(<s[i]*s[j]>), (Word32)
+ r0 = pointer to the residual energy (Word32)
+ dtx = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag)
+ pOverflow = Pointer to overflow (Flag)
+
+ Outputs:
+ cor_max contains the newly calculated normalized correlation of the
+ selected lag
+ rmax contains the newly calculated max(<s[i]*s[j]>)
+ r0 contains the newly calculated residual energy
+ pOverflow -> 1 if the math functions called by this routine saturate.
+
+ Returns:
+ p_max = lag of the max correlation found (Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function finds the lag that has maximum correlation of scal_sig[] in a
+ given delay range.
+ The correlation is given by
+ cor[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max
+ The functions outputs the maximum correlation after normalization and the
+ corresponding lag.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static Word16 Lag_max ( // o : lag found
+ vadState *vadSt, // i/o : VAD state struct
+ Word32 corr[], // i : correlation vector.
+ Word16 scal_sig[], // i : scaled signal.
+ Word16 L_frame, // i : length of frame to compute pitch
+ Word16 lag_max, // i : maximum lag
+ Word16 lag_min, // i : minimum lag
+ Word16 old_lag, // i : old open-loop lag
+ Word16 *cor_max, // o : normalized correlation of selected lag
+ Word16 wght_flg, // i : is weighting function used
+ Word16 *gain_flg, // o : open-loop flag
+ Flag dtx // i : dtx flag; use dtx=1, do not use dtx=0
+ )
+{
+ Word16 i, j;
+ Word16 *p, *p1;
+ Word32 max, t0;
+ Word16 t0_h, t0_l;
+ Word16 p_max;
+ const Word16 *ww, *we;
+ Word32 t1;
+
+ ww = &corrweight[250];
+ we = &corrweight[123 + lag_max - old_lag];
+
+ max = MIN_32;
+ p_max = lag_max;
+
+ for (i = lag_max; i >= lag_min; i--)
+ {
+ t0 = corr[-i];
+
+ // Weighting of the correlation function.
+ L_Extract (corr[-i], &t0_h, &t0_l);
+ t0 = Mpy_32_16 (t0_h, t0_l, *ww);
+ ww--;
+ if (wght_flg > 0) {
+ // Weight the neighbourhood of the old lag
+ L_Extract (t0, &t0_h, &t0_l);
+ t0 = Mpy_32_16 (t0_h, t0_l, *we);
+ we--;
+ }
+
+ if (L_sub (t0, max) >= 0)
+ {
+ max = t0;
+ p_max = i;
+ }
+ }
+
+ p = &scal_sig[0];
+ p1 = &scal_sig[-p_max];
+ t0 = 0;
+ t1 = 0;
+
+ for (j = 0; j < L_frame; j++, p++, p1++)
+ {
+ t0 = L_mac (t0, *p, *p1);
+ t1 = L_mac (t1, *p1, *p1);
+ }
+
+ if (dtx)
+ { // no test() call since this if is only in simulation env
+#ifdef VAD2
+ vadSt->L_Rmax = L_add(vadSt->L_Rmax, t0); // Save max correlation
+ vadSt->L_R0 = L_add(vadSt->L_R0, t1); // Save max energy
+#else
+ // update and detect tone
+ vad_tone_detection_update (vadSt, 0);
+ vad_tone_detection (vadSt, t0, t1);
+#endif
+ }
+
+ // gain flag is set according to the open_loop gain
+ // is t2/t1 > 0.4 ?
+ *gain_flg = pv_round(L_msu(t0, pv_round(t1), 13107));
+
+ *cor_max = 0;
+
+ return (p_max);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16 Lag_max( /* o : lag found */
+ vadState *vadSt, /* i/o : VAD state struct */
+ Word32 corr[], /* i : correlation vector. */
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word16 old_lag, /* i : old open-loop lag */
+ Word16 *cor_max, /* o : normalized correlation of selected lag */
+ Word16 wght_flg, /* i : is weighting function used */
+ Word16 *gain_flg, /* o : open-loop flag */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* o : overflow flag */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 *p;
+ Word16 *p1;
+ Word32 max;
+ Word32 t0;
+ Word16 t0_h;
+ Word16 t0_l;
+ Word16 p_max;
+ const Word16 *ww;
+ const Word16 *we;
+ Word32 t1;
+ Word16 temp;
+
+ ww = &corrweight[250];
+ we = &corrweight[123 + lag_max - old_lag];
+
+ max = MIN_32;
+ p_max = lag_max;
+
+ for (i = lag_max; i >= lag_min; i--)
+ {
+ t0 = corr[-i];
+
+ /* Weighting of the correlation function. */
+ L_Extract(corr[-i], &t0_h, &t0_l, pOverflow);
+ t0 = Mpy_32_16(t0_h, t0_l, *ww, pOverflow);
+ ww--;
+ if (wght_flg > 0)
+ {
+ /* Weight the neighbourhood of the old lag. */
+ L_Extract(t0, &t0_h, &t0_l, pOverflow);
+ t0 = Mpy_32_16(t0_h, t0_l, *we, pOverflow);
+ we--;
+ }
+
+ /* if (L_sub (t0, max) >= 0) */
+ if (t0 >= max)
+ {
+ max = t0;
+ p_max = i;
+ }
+ }
+ p = &scal_sig[0];
+ p1 = &scal_sig[-p_max];
+ t0 = 0;
+ t1 = 0;
+
+ for (j = 0; j < L_frame; j++, p++, p1++)
+ {
+ t0 = L_mac(t0, *p, *p1, pOverflow);
+ t1 = L_mac(t1, *p1, *p1, pOverflow);
+ }
+
+ if (dtx)
+ { /* no test() call since this if is only in simulation env */
+#ifdef VAD2
+ /* Save max correlation */
+ vadSt->L_Rmax = L_add(vadSt->L_Rmax, t0, pOverflow);
+ /* Save max energy */
+ vadSt->L_R0 = L_add(vadSt->L_R0, t1, pOverflow);
+#else
+ /* update and detect tone */
+ vad_tone_detection_update(vadSt, 0, pOverflow);
+ vad_tone_detection(vadSt, t0, t1, pOverflow);
+#endif
+ }
+
+ /* gain flag is set according to the open_loop gain */
+ /* is t2/t1 > 0.4 ? */
+ temp = pv_round(t1, pOverflow);
+ t1 = L_msu(t0, temp, 13107, pOverflow);
+ *gain_flg = pv_round(t1, pOverflow);
+
+ *cor_max = 0;
+
+ return (p_max);
+}
+/*----------------------------------------------------------------------------
+; End Function: Lag_max
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pitch_ol_wgh
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to pitchOLWghtState structure
+ vadSt = pointer to a vadState structure
+ signal = pointer to buffer of signal used to compute the open loop
+ pitch where signal[-pit_max] to signal[-1] should be known
+ pit_min = 16 bit value specifies the minimum pitch lag
+ pit_max = 16 bit value specifies the maximum pitch lag
+ L_frame = 16 bit value specifies the length of frame to compute pitch
+ old_lags = pointer to history with old stored Cl lags (Word16)
+ ol_gain_flg = pointer to OL gain flag (Word16)
+ idx = 16 bit value specifies the frame index
+ dtx = Data of type 'Flag' used for dtx. Use dtx=1, do not use dtx=0
+ pOverflow = pointer to Overflow indicator (Flag)
+ Outputs
+ st = The pitchOLWghtState may be modified
+ vadSt = The vadSt state structure may be modified.
+ pOverflow -> 1 if the math functions invoked by this routine saturate.
+
+ Returns:
+ p_max1 = 16 bit value representing the open loop pitch lag.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs an open-loop pitch search with weighting
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_ol.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Pitch_ol_wgh ( // o : open loop pitch lag
+ pitchOLWghtState *st, // i/o : State struct
+ vadState *vadSt, // i/o : VAD state struct/
+ Word16 signal[], // i : signal used to compute the open loop pitch
+ // signal[-pit_max] to signal[-1] should be known
+ Word16 pit_min, // i : minimum pitch lag
+ Word16 pit_max, // i : maximum pitch lag
+ Word16 L_frame, // i : length of frame to compute pitch
+ Word16 old_lags[], // i : history with old stored Cl lags
+ Word16 ol_gain_flg[], // i : OL gain flag
+ Word16 idx, // i : index
+ Flag dtx // i : dtx flag; use dtx=1, do not use dtx=0
+ )
+{
+ Word16 i;
+ Word16 max1;
+ Word16 p_max1;
+ Word32 t0;
+#ifndef VAD2
+ Word16 corr_hp_max;
+#endif
+ Word32 corr[PIT_MAX+1], *corr_ptr;
+
+ // Scaled signal
+ Word16 scaled_signal[PIT_MAX + L_FRAME];
+ Word16 *scal_sig;
+
+ scal_sig = &scaled_signal[pit_max];
+
+ t0 = 0L;
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ t0 = L_mac (t0, signal[i], signal[i]);
+ }
+ //
+ // Scaling of input signal
+ //
+ // if Overflow -> scal_sig[i] = signal[i]>>2
+ // else if t0 < 1^22 -> scal_sig[i] = signal[i]<<2
+ // else -> scal_sig[i] = signal[i]
+
+ //
+ // Verification for risk of overflow.
+ //
+
+ // Test for overflow
+ if (L_sub (t0, MAX_32) == 0L)
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = shr (signal[i], 3);
+ }
+ }
+ else if (L_sub (t0, (Word32) 1048576L) < (Word32) 0)
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = shl (signal[i], 3);
+ }
+ }
+ else
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = signal[i];
+ }
+ }
+
+ // calculate all coreelations of scal_sig, from pit_min to pit_max
+ corr_ptr = &corr[pit_max];
+ comp_corr (scal_sig, L_frame, pit_max, pit_min, corr_ptr);
+
+ p_max1 = Lag_max (vadSt, corr_ptr, scal_sig, L_frame, pit_max, pit_min,
+ st->old_T0_med, &max1, st->wght_flg, &ol_gain_flg[idx],
+ dtx);
+
+ if (ol_gain_flg[idx] > 0)
+ {
+ // Calculate 5-point median of previous lag
+ for (i = 4; i > 0; i--) // Shift buffer
+ {
+ old_lags[i] = old_lags[i-1];
+ }
+ old_lags[0] = p_max1;
+ st->old_T0_med = gmed_n (old_lags, 5);
+ st->ada_w = 32767; // Q15 = 1.0
+ }
+ else
+ {
+ st->old_T0_med = p_max1;
+ st->ada_w = mult(st->ada_w, 29491); // = ada_w = ada_w * 0.9
+ }
+
+ if (sub(st->ada_w, 9830) < 0) // ada_w - 0.3
+ {
+ st->wght_flg = 0;
+ }
+ else
+ {
+ st->wght_flg = 1;
+ }
+
+#ifndef VAD2
+ if (dtx)
+ { // no test() call since this if is only in simulation env
+ if (sub(idx, 1) == 0)
+ {
+ // calculate max high-passed filtered correlation of all lags
+ hp_max (corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max);
+
+ // update complex background detector
+ vad_complex_detection_update(vadSt, corr_hp_max);
+ }
+ }
+#endif
+
+ return (p_max1);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Pitch_ol_wgh( /* o : open loop pitch lag */
+ pitchOLWghtState *st, /* i/o : State struct */
+ vadState *vadSt, /* i/o : VAD state struct */
+ Word16 signal[], /* i : signal used to compute the open loop pitch */
+ /* signal[-pit_max] to signal[-1] should be known */
+ Word16 pit_min, /* i : minimum pitch lag */
+ Word16 pit_max, /* i : maximum pitch lag */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 old_lags[], /* i : history with old stored Cl lags */
+ Word16 ol_gain_flg[], /* i : OL gain flag */
+ Word16 idx, /* i : index */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* o : overflow flag */
+)
+{
+ Word16 i;
+ Word16 max1;
+ Word16 p_max1;
+ Word32 t0;
+#ifndef VAD2
+ Word16 corr_hp_max;
+#endif
+ Word32 corr[PIT_MAX+1], *corr_ptr;
+
+ /* Scaled signal */
+ Word16 scaled_signal[PIT_MAX + L_FRAME];
+ Word16 *scal_sig;
+
+ scal_sig = &scaled_signal[pit_max];
+
+ t0 = 0L;
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ t0 = L_mac(t0, signal[i], signal[i], pOverflow);
+ }
+ /*--------------------------------------------------------*
+ * Scaling of input signal. *
+ * *
+ * if Overflow -> scal_sig[i] = signal[i]>>2 *
+ * else if t0 < 1^22 -> scal_sig[i] = signal[i]<<2 *
+ * else -> scal_sig[i] = signal[i] *
+ *--------------------------------------------------------*/
+
+ /*--------------------------------------------------------*
+ * Verification for risk of overflow. *
+ *--------------------------------------------------------*/
+
+ /* Test for overflow */
+ if (L_sub(t0, MAX_32, pOverflow) == 0L)
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = shr(signal[i], 3, pOverflow);
+ }
+ }
+ else if (L_sub(t0, (Word32) 1048576L, pOverflow) < (Word32) 0)
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = shl(signal[i], 3, pOverflow);
+ }
+ }
+ else
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = signal[i];
+ }
+ }
+
+ /* calculate all coreelations of scal_sig, from pit_min to pit_max */
+ corr_ptr = &corr[pit_max];
+ comp_corr(scal_sig, L_frame, pit_max, pit_min, corr_ptr);
+
+ p_max1 = Lag_max(vadSt, corr_ptr, scal_sig, L_frame, pit_max, pit_min,
+ st->old_T0_med, &max1, st->wght_flg, &ol_gain_flg[idx],
+ dtx, pOverflow);
+
+ if (ol_gain_flg[idx] > 0)
+ {
+ /* Calculate 5-point median of previous lags */
+ for (i = 4; i > 0; i--) /* Shift buffer */
+ {
+ old_lags[i] = old_lags[i-1];
+ }
+ old_lags[0] = p_max1;
+ st->old_T0_med = gmed_n(old_lags, 5);
+ st->ada_w = 32767; /* Q15 = 1.0 */
+ }
+ else
+ {
+ st->old_T0_med = p_max1;
+ /* = ada_w = ada_w * 0.9 */
+ st->ada_w = mult(st->ada_w, 29491, pOverflow);
+ }
+
+ if (sub(st->ada_w, 9830, pOverflow) < 0) /* ada_w - 0.3 */
+ {
+ st->wght_flg = 0;
+ }
+ else
+ {
+ st->wght_flg = 1;
+ }
+
+#ifndef VAD2
+ if (dtx)
+ { /* no test() call since this if is only in simulation env */
+ if (sub(idx, 1, pOverflow) == 0)
+ {
+ /* calculate max high-passed filtered correlation of all lags */
+ hp_max(corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max, pOverflow);
+
+ /* update complex background detector */
+ vad_complex_detection_update(vadSt, corr_hp_max);
+ }
+ }
+#endif
+
+ return (p_max1);
+}
+
+/*----------------------------------------------------------------------------
+; End Function: Pitch_ol_wgh
+----------------------------------------------------------------------------*/
+
+
+
+
+
diff --git a/media/codecs/amrnb/enc/src/pitch_fr.cpp b/media/codecs/amrnb/enc/src/pitch_fr.cpp
new file mode 100644
index 0000000..5a846fa
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pitch_fr.cpp
@@ -0,0 +1,1609 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/pitch_fr.c
+ Functions:
+
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added pOverflow as a passed in value to searchFrac and made
+ other fixes to the code regarding simple syntax fixes. Removed
+ the include of stio.h.
+
+ Description: *lag-- decrements the pointer. (*lag)-- decrements what is
+ pointed to. The latter is what the coder intended, but the former is
+ the coding instruction that was used.
+
+ Description: A common problem -- a comparison != 0 was inadvertantly replaced
+ by a comparison == 0.
+
+
+ Description: For Norm_Corr() and getRange()
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation, in some cases this by shifting before adding and
+ in other cases by evaluating the operands
+ 4. Unrolled loops to speed up processing, use decrement loops
+ 5. Replaced extract_l() call with equivalent code
+ 6. Modified scaling threshold and group all shifts (avoiding
+ successive shifts)
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Removed compiler warnings.
+
+ Description:
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ File : pitch_fr.c
+ Purpose : Find the pitch period with 1/3 or 1/6 subsample
+ : resolution (closed loop).
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "pitch_fr.h"
+#include "oper_32b.h"
+#include "cnst.h"
+#include "enc_lag3.h"
+#include "enc_lag6.h"
+#include "inter_36.h"
+#include "inv_sqrt.h"
+#include "convolve.h"
+
+#include "basic_op.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+ * mode dependent parameters used in Pitch_fr()
+ * Note: order of MRxx in 'enum Mode' is important!
+ */
+static const struct
+{
+ Word16 max_frac_lag; /* lag up to which fractional lags are used */
+ Word16 flag3; /* enable 1/3 instead of 1/6 fract. resolution */
+ Word16 first_frac; /* first fractional to check */
+ Word16 last_frac; /* last fractional to check */
+ Word16 delta_int_low; /* integer lag below TO to start search from */
+ Word16 delta_int_range; /* integer range around T0 */
+ Word16 delta_frc_low; /* fractional below T0 */
+ Word16 delta_frc_range; /* fractional range around T0 */
+ Word16 pit_min; /* minimum pitch */
+} mode_dep_parm[N_MODES] =
+{
+ /* MR475 */ { 84, 1, -2, 2, 5, 10, 5, 9, PIT_MIN },
+ /* MR515 */ { 84, 1, -2, 2, 5, 10, 5, 9, PIT_MIN },
+ /* MR59 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN },
+ /* MR67 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN },
+ /* MR74 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN },
+ /* MR795 */ { 84, 1, -2, 2, 3, 6, 10, 19, PIT_MIN },
+ /* MR102 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN },
+ /* MR122 */ { 94, 0, -3, 3, 3, 6, 5, 9, PIT_MIN_MR122 }
+};
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Norm_Corr
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ exc[] = pointer to buffer of type Word16
+ xn[] = pointer to buffer of type Word16
+ h[] = pointer to buffer of type Word16
+ L_subfr = length of sub frame (Word16)
+ t_min = the minimum table value of type Word16
+ t_max = the maximum table value of type Word16
+ corr_norm[] = pointer to buffer of type Word16
+
+ Outputs:
+ pOverflow = 1 if the math functions called result in overflow else zero.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION: Norm_Corr()
+
+ PURPOSE: Find the normalized correlation between the target vector
+ and the filtered past excitation.
+
+ DESCRIPTION:
+ The normalized correlation is given by the correlation between the
+ target and filtered past excitation divided by the square root of
+ the energy of filtered excitation.
+ corr[k] = <x[], y_k[]>/sqrt(y_k[],y_k[])
+ where x[] is the target vector and y_k[] is the filtered past
+ excitation at delay k.
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static void Norm_Corr (Word16 exc[], Word16 xn[], Word16 h[], Word16 L_subfr,
+ Word16 t_min, Word16 t_max, Word16 corr_norm[])
+{
+ Word16 i, j, k;
+ Word16 corr_h, corr_l, norm_h, norm_l;
+ Word32 s;
+
+ // Usally dynamic allocation of (L_subfr)
+ Word16 excf[L_SUBFR];
+ Word16 scaling, h_fac, *s_excf, scaled_excf[L_SUBFR];
+
+ k = -t_min;
+
+ // compute the filtered excitation for the first delay t_min
+
+ Convolve (&exc[k], h, excf, L_subfr);
+
+ // scale "excf[]" to avoid overflow
+
+ for (j = 0; j < L_subfr; j++) {
+ scaled_excf[j] = shr (excf[j], 2);
+ }
+
+ // Compute 1/sqrt(energy of excf[])
+
+ s = 0;
+ for (j = 0; j < L_subfr; j++) {
+ s = L_mac (s, excf[j], excf[j]);
+ }
+ if (L_sub (s, 67108864L) <= 0) { // if (s <= 2^26)
+ s_excf = excf;
+ h_fac = 15 - 12;
+ scaling = 0;
+ }
+ else {
+ // "excf[]" is divided by 2
+ s_excf = scaled_excf;
+ h_fac = 15 - 12 - 2;
+ scaling = 2;
+ }
+
+ // loop for every possible period
+
+ for (i = t_min; i <= t_max; i++) {
+ // Compute 1/sqrt(energy of excf[])
+
+ s = 0;
+ for (j = 0; j < L_subfr; j++) {
+ s = L_mac (s, s_excf[j], s_excf[j]);
+ }
+
+ s = Inv_sqrt (s);
+ L_Extract (s, &norm_h, &norm_l);
+
+ // Compute correlation between xn[] and excf[]
+
+ s = 0;
+ for (j = 0; j < L_subfr; j++) {
+ s = L_mac (s, xn[j], s_excf[j]);
+ }
+ L_Extract (s, &corr_h, &corr_l);
+
+ // Normalize correlation = correlation * (1/sqrt(energy))
+
+ s = Mpy_32 (corr_h, corr_l, norm_h, norm_l);
+
+ corr_norm[i] = extract_h (L_shl (s, 16));
+
+ // modify the filtered excitation excf[] for the next iteration
+
+ if (sub (i, t_max) != 0) {
+ k--;
+ for (j = L_subfr - 1; j > 0; j--) {
+ s = L_mult (exc[k], h[j]);
+ s = L_shl (s, h_fac);
+ s_excf[j] = add (extract_h (s), s_excf[j - 1]);
+ }
+ s_excf[0] = shr (exc[k], scaling);
+ }
+ }
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void Norm_Corr(Word16 exc[],
+ Word16 xn[],
+ Word16 h[],
+ Word16 L_subfr,
+ Word16 t_min,
+ Word16 t_max,
+ Word16 corr_norm[],
+ Flag *pOverflow)
+{
+ Word16 i;
+ Word16 j;
+ Word16 k;
+ Word16 corr_h;
+ Word16 corr_l;
+ Word16 norm_h;
+ Word16 norm_l;
+ Word32 s;
+ Word32 s2;
+ Word16 excf[L_SUBFR];
+ Word16 scaling;
+ Word16 h_fac;
+ Word16 *s_excf;
+ Word16 scaled_excf[L_SUBFR];
+ Word16 *p_s_excf;
+ Word16 *p_excf;
+ Word16 temp;
+ Word16 *p_x;
+ Word16 *p_h;
+
+ k = -t_min;
+
+ /* compute the filtered excitation for the first delay t_min */
+
+ Convolve(&exc[k], h, excf, L_subfr);
+
+ /* scale "excf[]" to avoid overflow */
+ s = 0;
+ p_s_excf = scaled_excf;
+ p_excf = excf;
+
+ for (j = (L_subfr >> 1); j != 0; j--)
+ {
+ temp = *(p_excf++);
+ *(p_s_excf++) = temp >> 2;
+ s += (Word32) temp * temp;
+ temp = *(p_excf++);
+ *(p_s_excf++) = temp >> 2;
+ s += (Word32) temp * temp;
+ }
+
+
+ if (s <= (67108864L >> 1))
+ {
+ s_excf = excf;
+ h_fac = 12;
+ scaling = 0;
+ }
+ else
+ {
+ /* "excf[]" is divided by 2 */
+ s_excf = scaled_excf;
+ h_fac = 14;
+ scaling = 2;
+ }
+
+ /* loop for every possible period */
+
+ for (i = t_min; i <= t_max; i++)
+ {
+ /* Compute 1/sqrt(energy of excf[]) */
+
+ s = s2 = 0;
+ p_x = xn;
+ p_s_excf = s_excf;
+ j = L_subfr >> 1;
+
+ while (j--)
+ {
+ s += (Word32) * (p_x++) * *(p_s_excf);
+ s2 += ((Word32)(*(p_s_excf)) * (*(p_s_excf)));
+ p_s_excf++;
+ s += (Word32) * (p_x++) * *(p_s_excf);
+ s2 += ((Word32)(*(p_s_excf)) * (*(p_s_excf)));
+ p_s_excf++;
+ }
+
+ s2 = s2 << 1;
+ s2 = Inv_sqrt(s2, pOverflow);
+ norm_h = (Word16)(s2 >> 16);
+ norm_l = (Word16)((s2 >> 1) - (norm_h << 15));
+ corr_h = (Word16)(s >> 15);
+ corr_l = (Word16)((s) - (corr_h << 15));
+
+ /* Normalize correlation = correlation * (1/sqrt(energy)) */
+
+ s = Mpy_32(corr_h, corr_l, norm_h, norm_l, pOverflow);
+
+ corr_norm[i] = (Word16) s ;
+
+ /* modify the filtered excitation excf[] for the next iteration */
+ if (i != t_max)
+ {
+ k--;
+ temp = exc[k];
+ p_s_excf = &s_excf[L_subfr - 1];
+ p_h = &h[L_subfr - 1];
+
+ p_excf = &s_excf[L_subfr - 2];
+ for (j = (L_subfr - 1) >> 1; j != 0; j--)
+ {
+ s = ((Word32) temp * *(p_h--)) >> h_fac;
+ *(p_s_excf--) = (Word16) s + *(p_excf--);
+ s = ((Word32) temp * *(p_h--)) >> h_fac;
+ *(p_s_excf--) = (Word16) s + *(p_excf--);
+ }
+
+ s = ((Word32) temp * *(p_h)) >> h_fac;
+ *(p_s_excf--) = (Word16) s + *(p_excf);
+
+ *(p_s_excf) = temp >> scaling;
+ }
+
+ }
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: searchFrac
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ lag = pointer to integer pitch of type Word16
+ frac = pointer to starting point of search fractional pitch of type Word16
+ last_frac = endpoint of search of type Word16
+ corr[] = pointer to normalized correlation of type Word16
+ flag3 = subsample resolution (3: =1 / 6: =0) of type Word16
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION: searchFrac()
+
+ PURPOSE: Find fractional pitch
+
+ DESCRIPTION:
+ The function interpolates the normalized correlation at the
+ fractional positions around lag T0. The position at which the
+ interpolation function reaches its maximum is the fractional pitch.
+ Starting point of the search is frac, end point is last_frac.
+ frac is overwritten with the fractional pitch.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static void searchFrac (
+ Word16 *lag, // i/o : integer pitch
+ Word16 *frac, // i/o : start point of search -
+ fractional pitch
+ Word16 last_frac, // i : endpoint of search
+ Word16 corr[], // i : normalized correlation
+ Word16 flag3 // i : subsample resolution
+ (3: =1 / 6: =0)
+)
+{
+ Word16 i;
+ Word16 max;
+ Word16 corr_int;
+
+ // Test the fractions around T0 and choose the one which maximizes
+ // the interpolated normalized correlation.
+
+ max = Interpol_3or6 (&corr[*lag], *frac, flag3); // function result
+
+ for (i = add (*frac, 1); i <= last_frac; i++) {
+ corr_int = Interpol_3or6 (&corr[*lag], i, flag3);
+ if (sub (corr_int, max) > 0) {
+ max = corr_int;
+ *frac = i;
+ }
+ }
+
+ if (flag3 == 0) {
+ // Limit the fraction value in the interval [-2,-1,0,1,2,3]
+
+ if (sub (*frac, -3) == 0) {
+ *frac = 3;
+ *lag = sub (*lag, 1);
+ }
+ }
+ else {
+ // limit the fraction value between -1 and 1
+
+ if (sub (*frac, -2) == 0) {
+ *frac = 1;
+ *lag = sub (*lag, 1);
+ }
+ if (sub (*frac, 2) == 0) {
+ *frac = -1;
+ *lag = add (*lag, 1);
+ }
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void searchFrac(
+ Word16 *lag, /* i/o : integer pitch */
+ Word16 *frac, /* i/o : start point of search -
+ fractional pitch */
+ Word16 last_frac, /* i : endpoint of search */
+ Word16 corr[], /* i : normalized correlation */
+ Word16 flag3, /* i : subsample resolution
+ (3: =1 / 6: =0) */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 max;
+ Word16 corr_int;
+
+ /* Test the fractions around T0 and choose the one which maximizes */
+ /* the interpolated normalized correlation. */
+
+ max = Interpol_3or6(&corr[*lag], *frac, flag3, pOverflow);
+ /* function result */
+
+ for (i = *frac + 1; i <= last_frac; i++)
+ {
+ corr_int = Interpol_3or6(&corr[*lag], i, flag3, pOverflow);
+ if (corr_int > max)
+ {
+ max = corr_int;
+ *frac = i;
+ }
+ }
+
+ if (flag3 == 0)
+ {
+ /* Limit the fraction value in the interval [-2,-1,0,1,2,3] */
+
+ if (*frac == -3)
+ {
+ *frac = 3;
+ (*lag)--;
+ }
+ }
+ else
+ {
+ /* limit the fraction value between -1 and 1 */
+
+ if (*frac == -2)
+ {
+ *frac = 1;
+ (*lag)--;
+ }
+ if (*frac == 2)
+ {
+ *frac = -1;
+ (*lag)++;
+ }
+ }
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: getRange
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ T0 = integer pitch of type Word16
+ delta_low = search start offset of type Word16
+ delta_range = search range of type Word16
+ pitmin = minimum pitch of type Word16
+ pitmax = maximum pitch of type Word16
+ t0_min = search range minimum of type Word16
+ t0_max = search range maximum of type Word16
+
+ Outputs:
+ pOverflow = 1 if the math functions called result in overflow else zero.
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION: getRange()
+
+ PURPOSE: Sets range around open-loop pitch or integer pitch of last subframe
+
+ DESCRIPTION:
+ Takes integer pitch T0 and calculates a range around it with
+ t0_min = T0-delta_low and t0_max = (T0-delta_low) + delta_range
+ t0_min and t0_max are bounded by pitmin and pitmax
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static void getRange (
+ Word16 T0, // i : integer pitch
+ Word16 delta_low, // i : search start offset
+ Word16 delta_range, // i : search range
+ Word16 pitmin, // i : minimum pitch
+ Word16 pitmax, // i : maximum pitch
+ Word16 *t0_min, // o : search range minimum
+ Word16 *t0_max) // o : search range maximum
+{
+ *t0_min = sub(T0, delta_low);
+ if (sub(*t0_min, pitmin) < 0) {
+ *t0_min = pitmin;
+ }
+ *t0_max = add(*t0_min, delta_range);
+ if (sub(*t0_max, pitmax) > 0) {
+ *t0_max = pitmax;
+ *t0_min = sub(*t0_max, delta_range);
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+static void getRange(
+ Word16 T0, /* i : integer pitch */
+ Word16 delta_low, /* i : search start offset */
+ Word16 delta_range, /* i : search range */
+ Word16 pitmin, /* i : minimum pitch */
+ Word16 pitmax, /* i : maximum pitch */
+ Word16 *t0_min, /* o : search range minimum */
+ Word16 *t0_max, /* o : search range maximum */
+ Flag *pOverflow)
+{
+
+ Word16 temp;
+ OSCL_UNUSED_ARG(pOverflow);
+
+ temp = *t0_min;
+ temp = T0 - delta_low;
+ if (temp < pitmin)
+ {
+ temp = pitmin;
+ }
+ *t0_min = temp;
+
+ temp += delta_range;
+ if (temp > pitmax)
+ {
+ temp = pitmax;
+ *t0_min = pitmax - delta_range;
+ }
+ *t0_max = temp;
+
+}
+
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pitch_fr_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer of structure type Pitch_fr_State.
+
+ Outputs:
+ None
+
+ Returns:
+ Returns a zero if successful and -1 if not successful.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: Pitch_fr_init
+ Purpose: Allocates state memory and initializes state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Pitch_fr_init (Pitch_frState **state)
+{
+ Pitch_frState* s;
+
+ if (state == (Pitch_frState **) NULL){
+ // fprintf(stderr, "Pitch_fr_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (Pitch_frState *) malloc(sizeof(Pitch_frState))) == NULL){
+ // fprintf(stderr, "Pitch_fr_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ Pitch_fr_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 Pitch_fr_init(Pitch_frState **state)
+{
+ Pitch_frState* s;
+
+ if (state == (Pitch_frState **) NULL)
+ {
+ /* fprintf(stderr, "Pitch_fr_init: invalid parameter\n"); */
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (Pitch_frState *) malloc(sizeof(Pitch_frState))) == NULL)
+ {
+ /* fprintf(stderr, "Pitch_fr_init: can not malloc state structure\n"); */
+ return -1;
+ }
+
+ Pitch_fr_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pitch_fr_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer of structure type Pitch_fr_State.
+
+ Outputs:
+ None
+
+ Returns:
+ Returns a zero if successful and -1 if not successful.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: Pitch_fr_reset
+ Purpose: Initializes state memory to zero
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Pitch_fr_reset (Pitch_frState *state)
+{
+
+ if (state == (Pitch_frState *) NULL){
+ // fprintf(stderr, "Pitch_fr_reset: invalid parameter\n");
+ return -1;
+ }
+
+ state->T0_prev_subframe = 0;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 Pitch_fr_reset(Pitch_frState *state)
+{
+
+ if (state == (Pitch_frState *) NULL)
+ {
+ /* fprintf(stderr, "Pitch_fr_reset: invalid parameter\n"); */
+ return -1;
+ }
+
+ state->T0_prev_subframe = 0;
+
+ return 0;
+}
+
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pitch_fr_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer of structure type Pitch_fr_State.
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: Pitch_fr_exit
+ Purpose: The memory for state is freed.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Pitch_fr_exit (Pitch_frState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void Pitch_fr_exit(Pitch_frState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pitch_fr
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to stat structure of type Pitch_frState
+ mode = codec mode of type enum Mode
+ T_op[] = pointer to open loop pitch lags of type Word16
+ exc[] = pointer to excitation buffer of type Word16
+ xn[] = pointer to target vector of type Word16
+ h[] = pointer to impulse response of synthesis and weighting filters
+ of type Word16
+ L_subfr = length of subframe of type Word16
+ i_subfr = subframe offset of type Word16
+
+ Outputs:
+ pit_frac = pointer to pitch period (fractional) of type Word16
+ resu3 = pointer to subsample resolution of type Word16
+ ana_index = pointer to index of encoding of type Word16
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION: Pitch_fr()
+
+ PURPOSE: Find the pitch period with 1/3 or 1/6 subsample resolution
+ (closed loop).
+
+ DESCRIPTION:
+ - find the normalized correlation between the target and filtered
+ past excitation in the search range.
+ - select the delay with maximum normalized correlation.
+ - interpolate the normalized correlation at fractions -3/6 to 3/6
+ with step 1/6 around the chosen delay.
+ - The fraction which gives the maximum interpolated value is chosen.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Pitch_fr ( // o : pitch period (integer)
+ Pitch_frState *st, // i/o : State struct
+ enum Mode mode, // i : codec mode
+ Word16 T_op[], // i : open loop pitch lags
+ Word16 exc[], // i : excitation buffer Q0
+ Word16 xn[], // i : target vector Q0
+ Word16 h[], // i : impulse response of synthesis and
+ weighting filters Q12
+ Word16 L_subfr, // i : Length of subframe
+ Word16 i_subfr, // i : subframe offset
+ Word16 *pit_frac, // o : pitch period (fractional)
+ Word16 *resu3, // o : subsample resolution 1/3 (=1) or 1/6 (=0)
+ Word16 *ana_index // o : index of encoding
+)
+{
+ Word16 i;
+ Word16 t_min, t_max;
+ Word16 t0_min, t0_max;
+ Word16 max, lag, frac;
+ Word16 tmp_lag;
+ Word16 *corr;
+ Word16 corr_v[40]; // Total length = t0_max-t0_min+1+2*L_INTER_SRCH
+
+ Word16 max_frac_lag;
+ Word16 flag3, flag4;
+ Word16 last_frac;
+ Word16 delta_int_low, delta_int_range;
+ Word16 delta_frc_low, delta_frc_range;
+ Word16 pit_min;
+ Word16 frame_offset;
+ Word16 delta_search;
+
+ //-----------------------------------------------------------------------
+ // set mode specific variables
+ //----------------------------------------------------------------------
+
+ max_frac_lag = mode_dep_parm[mode].max_frac_lag;
+ flag3 = mode_dep_parm[mode].flag3;
+ frac = mode_dep_parm[mode].first_frac;
+ last_frac = mode_dep_parm[mode].last_frac;
+ delta_int_low = mode_dep_parm[mode].delta_int_low;
+ delta_int_range = mode_dep_parm[mode].delta_int_range;
+
+ delta_frc_low = mode_dep_parm[mode].delta_frc_low;
+ delta_frc_range = mode_dep_parm[mode].delta_frc_range;
+ pit_min = mode_dep_parm[mode].pit_min;
+
+ //-----------------------------------------------------------------------
+ // decide upon full or differential search
+ //-----------------------------------------------------------------------
+
+ delta_search = 1;
+
+ if ((i_subfr == 0) || (sub(i_subfr,L_FRAME_BY2) == 0)) {
+
+ // Subframe 1 and 3
+
+ if (((sub((Word16)mode, (Word16)MR475) != 0) && (sub((Word16)mode,
+ (Word16)MR515) != 0)) ||
+ (sub(i_subfr,L_FRAME_BY2) != 0)) {
+
+ // set t0_min, t0_max for full search
+ // this is *not* done for mode MR475, MR515 in subframe 3
+
+ delta_search = 0; // no differential search
+
+ // calculate index into T_op which contains the open-loop
+ // pitch estimations for the 2 big subframes
+
+ frame_offset = 1;
+ if (i_subfr == 0)
+ frame_offset = 0;
+
+ // get T_op from the corresponding half frame and
+ // set t0_min, t0_max
+
+ getRange (T_op[frame_offset], delta_int_low, delta_int_range,
+ pit_min, PIT_MAX, &t0_min, &t0_max);
+ }
+ else {
+
+ // mode MR475, MR515 and 3. Subframe: delta search as well
+ getRange (st->T0_prev_subframe, delta_frc_low, delta_frc_range,
+ pit_min, PIT_MAX, &t0_min, &t0_max);
+ }
+ }
+ else {
+
+ // for Subframe 2 and 4
+ // get range around T0 of previous subframe for delta search
+
+ getRange (st->T0_prev_subframe, delta_frc_low, delta_frc_range,
+ pit_min, PIT_MAX, &t0_min, &t0_max);
+ }
+
+ //-----------------------------------------------------------------------
+ Find interval to compute normalized correlation
+ -----------------------------------------------------------------------
+
+ t_min = sub (t0_min, L_INTER_SRCH);
+ t_max = add (t0_max, L_INTER_SRCH);
+
+ corr = &corr_v[-t_min];
+
+ //-----------------------------------------------------------------------
+ Compute normalized correlation between target and filtered excitation
+ -----------------------------------------------------------------------
+
+ Norm_Corr (exc, xn, h, L_subfr, t_min, t_max, corr);
+
+ //-----------------------------------------------------------------------
+ Find integer pitch
+ -----------------------------------------------------------------------
+
+ max = corr[t0_min];
+ lag = t0_min;
+
+ for (i = t0_min + 1; i <= t0_max; i++) {
+ if (sub (corr[i], max) >= 0) {
+ max = corr[i];
+ lag = i;
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ Find fractional pitch
+ -----------------------------------------------------------------------
+ if ((delta_search == 0) && (sub (lag, max_frac_lag) > 0)) {
+
+ // full search and integer pitch greater than max_frac_lag
+ // fractional search is not needed, set fractional to zero
+
+ frac = 0;
+ }
+ else {
+
+ // if differential search AND mode MR475 OR MR515 OR MR59 OR MR67
+ // then search fractional with 4 bits resolution
+
+ if ((delta_search != 0) &&
+ ((sub ((Word16)mode, (Word16)MR475) == 0) ||
+ (sub ((Word16)mode, (Word16)MR515) == 0) ||
+ (sub ((Word16)mode, (Word16)MR59) == 0) ||
+ (sub ((Word16)mode, (Word16)MR67) == 0))) {
+
+ // modify frac or last_frac according to position of last
+ // integer pitch: either search around integer pitch,
+ // or only on left or right side
+
+ tmp_lag = st->T0_prev_subframe;
+ if ( sub( sub(tmp_lag, t0_min), 5) > 0)
+ tmp_lag = add (t0_min, 5);
+ if ( sub( sub(t0_max, tmp_lag), 4) > 0)
+ tmp_lag = sub (t0_max, 4);
+
+ if ((sub (lag, tmp_lag) == 0) ||
+ (sub (lag, sub(tmp_lag, 1)) == 0)) {
+
+ // normal search in fractions around T0
+
+ searchFrac (&lag, &frac, last_frac, corr, flag3);
+
+ }
+ else if (sub (lag, sub (tmp_lag, 2)) == 0) {
+ // limit search around T0 to the right side
+ frac = 0;
+ searchFrac (&lag, &frac, last_frac, corr, flag3);
+ }
+ else if (sub (lag, add(tmp_lag, 1)) == 0) {
+ // limit search around T0 to the left side
+ last_frac = 0;
+ searchFrac (&lag, &frac, last_frac, corr, flag3);
+ }
+ else {
+ // no fractional search
+ frac = 0;
+ }
+ }
+ else
+ // test the fractions around T0
+ searchFrac (&lag, &frac, last_frac, corr, flag3);
+ }
+
+ //-----------------------------------------------------------------------
+ // encode pitch
+ //-----------------------------------------------------------------------
+
+ if (flag3 != 0) {
+ // flag4 indicates encoding with 4 bit resolution;
+ // this is needed for mode MR475, MR515 and MR59
+
+ flag4 = 0;
+ if ( (sub ((Word16)mode, (Word16)MR475) == 0) ||
+ (sub ((Word16)mode, (Word16)MR515) == 0) ||
+ (sub ((Word16)mode, (Word16)MR59) == 0) ||
+ (sub ((Word16)mode, (Word16)MR67) == 0) ) {
+ flag4 = 1;
+ }
+
+ // encode with 1/3 subsample resolution
+
+ *ana_index = Enc_lag3(lag, frac, st->T0_prev_subframe,
+ t0_min, t0_max, delta_search, flag4);
+ // function result
+
+ }
+ else
+ {
+ // encode with 1/6 subsample resolution
+
+ *ana_index = Enc_lag6(lag, frac, t0_min, delta_search);
+ // function result
+ }
+
+ //-----------------------------------------------------------------------
+ // update state variables
+ //-----------------------------------------------------------------------
+
+ st->T0_prev_subframe = lag;
+
+ //-----------------------------------------------------------------------
+ // update output variables
+ //-----------------------------------------------------------------------
+
+ *resu3 = flag3;
+
+ *pit_frac = frac;
+
+ return (lag);
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 Pitch_fr( /* o : pitch period (integer) */
+ Pitch_frState *st, /* i/o : State struct */
+ enum Mode mode, /* i : codec mode */
+ Word16 T_op[], /* i : open loop pitch lags */
+ Word16 exc[], /* i : excitation buffer Q0 */
+ Word16 xn[], /* i : target vector Q0 */
+ Word16 h[], /* i : impulse response of synthesis and
+ weighting filters Q12 */
+ Word16 L_subfr, /* i : Length of subframe */
+ Word16 i_subfr, /* i : subframe offset */
+ Word16 *pit_frac, /* o : pitch period (fractional) */
+ Word16 *resu3, /* o : subsample resolution 1/3 (=1) or 1/6 (=0) */
+ Word16 *ana_index, /* o : index of encoding */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 t_min;
+ Word16 t_max;
+ Word16 t0_min = 0;
+ Word16 t0_max;
+ Word16 max;
+ Word16 lag;
+ Word16 frac;
+ Word16 tmp_lag;
+ Word16 *corr;
+ Word16 corr_v[40]; /* Total length = t0_max-t0_min+1+2*L_INTER_SRCH */
+
+ Word16 max_frac_lag;
+ Word16 flag3;
+ Word16 flag4;
+ Word16 last_frac;
+ Word16 delta_int_low;
+ Word16 delta_int_range;
+ Word16 delta_frc_low;
+ Word16 delta_frc_range;
+ Word16 pit_min;
+ Word16 frame_offset;
+ Word16 delta_search;
+
+ /*-----------------------------------------------------------------------*
+ * set mode specific variables *
+ *-----------------------------------------------------------------------*/
+
+ max_frac_lag = mode_dep_parm[mode].max_frac_lag;
+ flag3 = mode_dep_parm[mode].flag3;
+ frac = mode_dep_parm[mode].first_frac;
+ last_frac = mode_dep_parm[mode].last_frac;
+ delta_int_low = mode_dep_parm[mode].delta_int_low;
+ delta_int_range = mode_dep_parm[mode].delta_int_range;
+
+ delta_frc_low = mode_dep_parm[mode].delta_frc_low;
+ delta_frc_range = mode_dep_parm[mode].delta_frc_range;
+ pit_min = mode_dep_parm[mode].pit_min;
+
+ /*-----------------------------------------------------------------------*
+ * decide upon full or differential search *
+ *-----------------------------------------------------------------------*/
+
+ delta_search = 1;
+
+ if ((i_subfr == 0) || (i_subfr == L_FRAME_BY2))
+ {
+
+ /* Subframe 1 and 3 */
+
+ if (((mode != MR475) && (mode != MR515)) || (i_subfr != L_FRAME_BY2))
+ {
+
+ /* set t0_min, t0_max for full search */
+ /* this is *not* done for mode MR475, MR515 in subframe 3 */
+
+ delta_search = 0; /* no differential search */
+
+ /* calculate index into T_op which contains the open-loop */
+ /* pitch estimations for the 2 big subframes */
+
+ frame_offset = 1;
+ if (i_subfr == 0)
+ frame_offset = 0;
+
+ /* get T_op from the corresponding half frame and */
+ /* set t0_min, t0_max */
+
+ getRange(T_op[frame_offset], delta_int_low, delta_int_range,
+ pit_min, PIT_MAX, &t0_min, &t0_max, pOverflow);
+ }
+ else
+ {
+
+ /* mode MR475, MR515 and 3. Subframe: delta search as well */
+ getRange(st->T0_prev_subframe, delta_frc_low, delta_frc_range,
+ pit_min, PIT_MAX, &t0_min, &t0_max, pOverflow);
+ }
+ }
+ else
+ {
+
+ /* for Subframe 2 and 4 */
+ /* get range around T0 of previous subframe for delta search */
+
+ getRange(st->T0_prev_subframe, delta_frc_low, delta_frc_range,
+ pit_min, PIT_MAX, &t0_min, &t0_max, pOverflow);
+ }
+
+ /*-----------------------------------------------------------------------*
+ * Find interval to compute normalized correlation *
+ *-----------------------------------------------------------------------*/
+
+ t_min = sub(t0_min, L_INTER_SRCH, pOverflow);
+ t_max = add(t0_max, L_INTER_SRCH, pOverflow);
+
+ corr = &corr_v[-t_min];
+
+ /*-----------------------------------------------------------------------*
+ * Compute normalized correlation between target and filtered excitation *
+ *-----------------------------------------------------------------------*/
+
+ Norm_Corr(exc, xn, h, L_subfr, t_min, t_max, corr, pOverflow);
+
+ /*-----------------------------------------------------------------------*
+ * Find integer pitch *
+ *-----------------------------------------------------------------------*/
+
+ max = corr[t0_min];
+ lag = t0_min;
+
+ for (i = t0_min + 1; i <= t0_max; i++)
+ {
+ if (corr[i] >= max)
+ {
+ max = corr[i];
+ lag = i;
+ }
+ }
+
+ /*-----------------------------------------------------------------------*
+ * Find fractional pitch *
+ *-----------------------------------------------------------------------*/
+ if ((delta_search == 0) && (lag > max_frac_lag))
+ {
+
+ /* full search and integer pitch greater than max_frac_lag */
+ /* fractional search is not needed, set fractional to zero */
+
+ frac = 0;
+ }
+ else
+ {
+
+ /* if differential search AND mode MR475 OR MR515 OR MR59 OR MR67 */
+ /* then search fractional with 4 bits resolution */
+
+ if ((delta_search != 0) &&
+ ((mode == MR475) || (mode == MR515) ||
+ (mode == MR59) || (mode == MR67)))
+ {
+
+ /* modify frac or last_frac according to position of last */
+ /* integer pitch: either search around integer pitch, */
+ /* or only on left or right side */
+
+ tmp_lag = st->T0_prev_subframe;
+ if (sub(sub(tmp_lag, t0_min, pOverflow), 5, pOverflow) > 0)
+ tmp_lag = add(t0_min, 5, pOverflow);
+ if (sub(sub(t0_max, tmp_lag, pOverflow), 4, pOverflow) > 0)
+ tmp_lag = sub(t0_max, 4, pOverflow);
+
+ if ((lag == tmp_lag) || (lag == (tmp_lag - 1)))
+ {
+
+ /* normal search in fractions around T0 */
+
+ searchFrac(&lag, &frac, last_frac, corr, flag3, pOverflow);
+
+ }
+ else if (lag == (tmp_lag - 2))
+ {
+ /* limit search around T0 to the right side */
+ frac = 0;
+ searchFrac(&lag, &frac, last_frac, corr, flag3, pOverflow);
+ }
+ else if (lag == (tmp_lag + 1))
+ {
+ /* limit search around T0 to the left side */
+ last_frac = 0;
+ searchFrac(&lag, &frac, last_frac, corr, flag3, pOverflow);
+ }
+ else
+ {
+ /* no fractional search */
+ frac = 0;
+ }
+ }
+ else
+ /* test the fractions around T0 */
+ searchFrac(&lag, &frac, last_frac, corr, flag3, pOverflow);
+ }
+
+ /*-----------------------------------------------------------------------*
+ * encode pitch *
+ *-----------------------------------------------------------------------*/
+
+ if (flag3 != 0)
+ {
+ /* flag4 indicates encoding with 4 bit resolution; */
+ /* this is needed for mode MR475, MR515 and MR59 */
+
+ flag4 = 0;
+ if ((mode == MR475) || (mode == MR515) ||
+ (mode == MR59) || (mode == MR67))
+ {
+ flag4 = 1;
+ }
+
+ /* encode with 1/3 subsample resolution */
+
+ *ana_index = Enc_lag3(lag, frac, st->T0_prev_subframe,
+ t0_min, t0_max, delta_search, flag4, pOverflow);
+ /* function result */
+
+ }
+ else
+ {
+ /* encode with 1/6 subsample resolution */
+
+ *ana_index = Enc_lag6(lag, frac, t0_min, delta_search, pOverflow);
+ /* function result */
+ }
+
+ /*-----------------------------------------------------------------------*
+ * update state variables *
+ *-----------------------------------------------------------------------*/
+
+ st->T0_prev_subframe = lag;
+
+ /*-----------------------------------------------------------------------*
+ * update output variables *
+ *-----------------------------------------------------------------------*/
+
+ *resu3 = flag3;
+
+ *pit_frac = frac;
+
+ return (lag);
+}
+
diff --git a/media/codecs/amrnb/enc/src/pitch_fr.h b/media/codecs/amrnb/enc/src/pitch_fr.h
new file mode 100644
index 0000000..5e87cc9
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pitch_fr.h
@@ -0,0 +1,148 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/pitch_fr.h
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : pitch_fr.h
+ Purpose : Find the pitch period with 1/3 or 1/6 subsample
+ : resolution (closed loop).
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _PITCH_FR_H_
+#define _PITCH_FR_H_
+#define pitch_fr_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 T0_prev_subframe; /* integer pitch lag of previous sub-frame */
+ } Pitch_frState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ Word16 Pitch_fr_init(Pitch_frState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to Pitch_fr in each call.
+ returns 0 on success
+ */
+
+ Word16 Pitch_fr_reset(Pitch_frState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void Pitch_fr_exit(Pitch_frState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ Word16 Pitch_fr( /* o : pitch period (integer) */
+ Pitch_frState *st, /* i/o : State struct */
+ enum Mode mode, /* i : codec mode */
+ Word16 T_op[], /* i : open loop pitch lags */
+ Word16 exc[], /* i : excitation buffer */
+ Word16 xn[], /* i : target vector */
+ Word16 h[], /* i : impulse response of synthesis and
+ weighting filters */
+ Word16 L_subfr, /* i : Length of subframe */
+ Word16 i_subfr, /* i : subframe offset */
+ Word16 *pit_frac, /* o : pitch period (fractional) */
+ Word16 *resu3, /* o : subsample resolution 1/3 (=1) or 1/6 (=0) */
+ Word16 *ana_index, /* o : index of encoding */
+ Flag *pOverflow
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PITCH_FR_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/pitch_ol.cpp b/media/codecs/amrnb/enc/src/pitch_ol.cpp
new file mode 100644
index 0000000..c039bb0
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pitch_ol.cpp
@@ -0,0 +1,1213 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/pitch_ol.c
+ Funtions: Pitch_ol
+ Lag_max
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ The modules in this file compute the open loop pitch lag.
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "pitch_ol.h"
+#include "typedef.h"
+#include "basicop_malloc.h"
+#include "cnst.h"
+#include "inv_sqrt.h"
+#include "vad.h"
+#include "calc_cor.h"
+#include "hp_max.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define THRESHOLD 27853
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Lag_max
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS (If VAD2 is defined)
+
+ Inputs
+ corr = pointer to buffer of correlation values (Word32)
+ scal_sig = pointer to buffer of scaled signal values (Word16)
+ scal_fac = scaled signal factor (Word16)
+ scal_flag = EFR compatible scaling flag (Word16)
+ L_frame = length of frame to compute pitch (Word16)
+ lag_max = maximum lag (Word16)
+ lag_min = minimum lag (Word16)
+ cor_max = pointer to the normalized correlation of selected lag (Word16)
+ rmax = pointer to max(<s[i]*s[j]>), (Word32)
+ r0 = pointer to the residual energy (Word32)
+ dtx = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag)
+
+ Outputs:
+ cor_max contains the newly calculated normalized correlation of the
+ selected lag
+ rmax contains the newly calculated max(<s[i]*s[j]>)
+ r0 contains the newly calculated residual energy
+
+ Returns:
+ p_max = lag of the max correlation found (Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS (If VAD2 is not defined)
+
+ Inputs
+ vadSt = pointer to a vadState structure
+ corr = pointer to buffer of correlation values (Word32)
+ scal_sig = pointer to buffer of scaled signal values (Word16)
+ scal_fac = scaled signal factor (Word16)
+ scal_flag = EFR compatible scaling flag (Word16)
+ L_frame = length of frame to compute pitch (Word16)
+ lag_max = maximum lag (Word16)
+ lag_min = minimum lag (Word16)
+ cor_max = pointer to the normalized correlation of selected lag (Word16)
+ dtx = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag)
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ cor_max contains the newly calculated normalized correlation of the
+ selected lag
+ vadSt contains the updated VAD state parameters
+ pOverflow -> 1 if the math operations called by this routine saturate
+
+ Returns:
+ p_max = lag of the max correlation found (Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Find the lag that has maximum correlation of scal_sig in a given delay range.
+ The correlation is given by:
+
+ cor[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max
+
+ The function returns the maximum correlation after normalization and the
+ corresponding lag.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_ol.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+#ifdef VAD2
+static Word16 Lag_max ( // o : lag found
+ Word32 corr[], // i : correlation vector.
+ Word16 scal_sig[], // i : scaled signal.
+ Word16 scal_fac, // i : scaled signal factor.
+ Word16 scal_flag, // i : if 1 use EFR compatible scaling
+ Word16 L_frame, // i : length of frame to compute pitch
+ Word16 lag_max, // i : maximum lag
+ Word16 lag_min, // i : minimum lag
+ Word16 *cor_max, // o : normalized correlation of selected lag
+ Word32 *rmax, // o : max(<s[i]*s[j]>)
+ Word32 *r0, // o : residual energy
+ Flag dtx // i : dtx flag; use dtx=1, do not use dtx=0
+ )
+#else
+static Word16 Lag_max ( // o : lag found
+ vadState *vadSt, // i/o : VAD state struct
+ Word32 corr[], // i : correlation vector.
+ Word16 scal_sig[], // i : scaled signal.
+ Word16 scal_fac, // i : scaled signal factor.
+ Word16 scal_flag, // i : if 1 use EFR compatible scaling
+ Word16 L_frame, // i : length of frame to compute pitch
+ Word16 lag_max, // i : maximum lag
+ Word16 lag_min, // i : minimum lag
+ Word16 *cor_max, // o : normalized correlation of selected lag
+ Flag dtx // i : dtx flag; use dtx=1, do not use dtx=0
+ )
+#endif
+{
+ Word16 i, j;
+ Word16 *p;
+ Word32 max, t0;
+ Word16 max_h, max_l, ener_h, ener_l;
+ Word16 p_max = 0; // initialization only needed to keep gcc silent
+
+ max = MIN_32;
+ p_max = lag_max;
+
+ for (i = lag_max, j = (PIT_MAX-lag_max-1); i >= lag_min; i--, j--)
+ {
+ if (L_sub (corr[-i], max) >= 0)
+ {
+ max = corr[-i];
+ p_max = i;
+ }
+ }
+
+ // compute energy
+
+ t0 = 0;
+ p = &scal_sig[-p_max];
+ for (i = 0; i < L_frame; i++, p++)
+ {
+ t0 = L_mac (t0, *p, *p);
+ }
+ // 1/sqrt(energy)
+
+ if (dtx)
+ { // no test() call since this if is only in simulation env
+#ifdef VAD2
+ *rmax = max;
+ *r0 = t0;
+#else
+ // check tone
+ vad_tone_detection (vadSt, max, t0);
+#endif
+ }
+
+ t0 = Inv_sqrt (t0);
+
+ if (scal_flag)
+ {
+ t0 = L_shl (t0, 1);
+ }
+
+ // max = max/sqrt(energy)
+
+ L_Extract (max, &max_h, &max_l);
+ L_Extract (t0, &ener_h, &ener_l);
+
+ t0 = Mpy_32 (max_h, max_l, ener_h, ener_l);
+
+ if (scal_flag)
+ {
+ t0 = L_shr (t0, scal_fac);
+ *cor_max = extract_h (L_shl (t0, 15)); // divide by 2
+ }
+ else
+ {
+ *cor_max = extract_l(t0);
+ }
+
+ return (p_max);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+#ifdef VAD2
+static Word16 Lag_max( /* o : lag found */
+ Word32 corr[], /* i : correlation vector. */
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 scal_fac, /* i : scaled signal factor. */
+ Word16 scal_flag, /* i : if 1 use EFR compatible scaling */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word16 *cor_max, /* o : normalized correlation of selected lag */
+ Word32 *rmax, /* o : max(<s[i]*s[j]>) */
+ Word32 *r0, /* o : residual energy */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow Flag */
+)
+#else
+static Word16 Lag_max( /* o : lag found */
+ vadState *vadSt, /* i/o : VAD state struct */
+ Word32 corr[], /* i : correlation vector. */
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 scal_fac, /* i : scaled signal factor. */
+ Word16 scal_flag, /* i : if 1 use EFR compatible scaling */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word16 *cor_max, /* o : normalized correlation of selected lag */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow Flag */
+)
+#endif
+{
+ Word16 i;
+ Word16 *p;
+ Word32 max;
+ Word32 t0;
+ Word16 max_h;
+ Word16 max_l;
+ Word16 ener_h;
+ Word16 ener_l;
+ Word16 p_max = 0; /* initialization only needed to keep gcc silent */
+ Word32 L_temp;
+ Word32 L_temp_2;
+ Word32 L_temp_3;
+ Word32 *p_corr = &corr[-lag_max];
+
+ max = MIN_32;
+ p_max = lag_max;
+
+ for (i = lag_max; i >= lag_min; i--)
+ {
+ /* The negative array index is equivalent to a negative */
+ /* address offset, i.e., corr[-i] == *(corr - i) */
+ if (*(p_corr++) >= max)
+ {
+ p_corr--;
+ max = *(p_corr++);
+ p_max = i;
+ }
+ }
+
+ /* compute energy */
+
+ t0 = 0;
+
+ /* The negative array index is equivalent to a negative */
+ /* address offset, i.e., scal_sig[-p_max] == *(scal_sig - p_max) */
+ p = &scal_sig[-p_max];
+ for (i = (L_frame >> 2); i != 0; i--)
+ {
+ t0 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p), t0);
+ p++;
+ t0 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p), t0);
+ p++;
+ t0 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p), t0);
+ p++;
+ t0 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p), t0);
+ p++;
+ }
+
+ t0 <<= 1;
+ /* 1/sqrt(energy) */
+
+ if (dtx)
+ { /* no test() call since this if is only in simulation env */
+ /* check tone */
+#ifdef VAD2
+ *rmax = max;
+ *r0 = t0;
+#else
+ /* check tone */
+ vad_tone_detection(vadSt, max, t0, pOverflow);
+#endif
+ }
+
+ t0 = Inv_sqrt(t0, pOverflow);
+
+ if (scal_flag)
+ {
+ if (t0 > (Word32) 0x3fffffffL)
+ {
+ t0 = MAX_32;
+ }
+ else
+ {
+ t0 = t0 << 1;
+ }
+ }
+
+ /* max = max/sqrt(energy) */
+ /* The following code is an inlined version of */
+ /* L_Extract (max, &max_h, &max_l), i.e. */
+ /* */
+ /* *max_h = extract_h (max); */
+ max_h = (Word16)(max >> 16);
+
+ /* L_temp_2 = L_shr(max,1), which is used in */
+ /* the calculation of *max_l (see next operation) */
+ L_temp_2 = max >> 1;
+
+ /* *max_l = extract_l (L_msu (L_shr (max, 1), *max_h, 16384)); */
+ L_temp_3 = (Word32)(max_h << 15);
+
+ L_temp = L_temp_2 - L_temp_3;
+
+ max_l = (Word16)L_temp;
+
+ /* The following code is an inlined version of */
+ /* L_Extract (t0, &ener_h, &ener_l), i.e. */
+ /* */
+ /* *ener_h = extract_h (t0); */
+ ener_h = (Word16)(t0 >> 16);
+
+ /* L_temp_2 = L_shr(t0,1), which is used in */
+ /* the calculation of *ener_l (see next operation) */
+
+ L_temp_2 = t0 >> 1;
+
+ L_temp_3 = (Word32)(ener_h << 15);
+
+ L_temp = L_temp_2 - L_temp_3;
+
+ ener_l = (Word16)L_temp;
+
+ t0 = Mpy_32(max_h, max_l, ener_h, ener_l, pOverflow);
+
+ if (scal_flag)
+ {
+ t0 = L_shr(t0, scal_fac, pOverflow);
+
+ if (t0 > (Word32) 0X0000FFFFL)
+ {
+ *cor_max = MAX_16;
+ }
+ else if (t0 < (Word32) 0xFFFF0000L)
+ {
+ *cor_max = MIN_16;
+ }
+ else
+ {
+ *cor_max = (Word16)(t0 >> 1);
+ }
+ }
+ else
+ {
+ *cor_max = (Word16)t0;
+ }
+
+ return (p_max);
+}
+
+/*----------------------------------------------------------------------------
+; End Function: Lag_max
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Lag_max_wrapper
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs
+ corr = pointer to buffer of correlation values (Word32)
+ scal_sig = pointer to buffer of scaled signal values (Word16)
+ scal_fac = scaled signal factor (Word16)
+ scal_flag = EFR compatible scaling flag (Word16)
+ L_frame = length of frame to compute pitch (Word16)
+ lag_max = maximum lag (Word16)
+ lag_min = minimum lag (Word16)
+ cor_max = pointer to the normalized correlation of selected lag (Word16)
+ rmax = pointer to max(<s[i]*s[j]>), (Word32)
+ r0 = pointer to the residual energy (Word32)
+ dtx = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag)
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ cor_max contains the newly calculated normalized correlation of the
+ selected lag
+ rmax contains the newly calculated max(<s[i]*s[j]>)
+ r0 contains the newly calculated residual energy
+ pOverflow -> 1 if the math operations called by this routine saturate
+
+ Returns:
+ p_max = lag of the max correlation found (Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS (If VAD2 is not defined)
+
+ Inputs
+ vadSt = pointer to a vadState structure
+ corr = pointer to buffer of correlation values (Word32)
+ scal_sig = pointer to buffer of scaled signal values (Word16)
+ scal_fac = scaled signal factor (Word16)
+ scal_flag = EFR compatible scaling flag (Word16)
+ L_frame = length of frame to compute pitch (Word16)
+ lag_max = maximum lag (Word16)
+ lag_min = minimum lag (Word16)
+ cor_max = pointer to the normalized correlation of selected lag (Word16)
+ dtx = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag)
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs:
+ cor_max contains the newly calculated normalized correlation of the
+ selected lag
+ vadSt contains the updated VAD state parameters
+ pOverflow -> 1 if the math operations called by this routine saturate
+
+ Returns:
+ p_max = lag of the max correlation found (Word16)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function provides external access to the local function Lag_max.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_ol.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+#ifdef VAD2
+ CALL Lag_max(corr = corr
+ scal_sig = scal_sig
+ scal_fac = scal_fac
+ scal_flag = scal_flag
+ L_frame = L_frame
+ lag_max = lag_max
+ lag_min = lag_min
+ cor_max = cor_max
+ rmax = rmax
+ r0 = r0
+ dtx = dtx
+ pOverflow = pOverflow)
+ MODIFYING(nothing)
+ RETURNING(temp)
+
+#else
+ CALL Lag_max(vadSt = vadSt
+ corr = corr
+ scal_sig = scal_sig
+ scal_fac = scal_fac
+ scal_flag = scal_flag
+ L_frame = L_frame
+ lag_max = lag_max
+ lag_min = lag_min
+ cor_max = cor_max
+ dtx = dtx
+ pOverflow = pOverflow)
+ MODIFYING(nothing)
+ RETURNING(temp)
+
+#endif
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+#ifdef VAD2
+Word16 Lag_max_wrapper( /* o : lag found */
+ Word32 corr[], /* i : correlation vector. */
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 scal_fac, /* i : scaled signal factor. */
+ Word16 scal_flag, /* i : if 1 use EFR compatible scaling */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word16 *cor_max, /* o : normalized correlation of selected lag */
+ Word32 *rmax, /* o : max(<s[i]*s[j]>) */
+ Word32 *r0, /* o : residual energy */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow Flag */
+)
+{
+ Word16 temp;
+
+ temp = Lag_max(corr, scal_sig, scal_fac, scal_flag, L_frame, lag_max,
+ lag_min, cor_max, rmax, r0, dtx, pOverflow);
+
+ return(temp);
+}
+
+#else
+Word16 Lag_max_wrapper( /* o : lag found */
+ vadState *vadSt, /* i/o : VAD state struct */
+ Word32 corr[], /* i : correlation vector. */
+ Word16 scal_sig[], /* i : scaled signal. */
+ Word16 scal_fac, /* i : scaled signal factor. */
+ Word16 scal_flag, /* i : if 1 use EFR compatible scaling */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 lag_max, /* i : maximum lag */
+ Word16 lag_min, /* i : minimum lag */
+ Word16 *cor_max, /* o : normalized correlation of selected lag */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow Flag */
+)
+{
+ Word16 temp;
+
+ temp = Lag_max(vadSt, corr, scal_sig, scal_fac, scal_flag, L_frame,
+ lag_max, lag_min, cor_max, dtx, pOverflow);
+
+ return(temp);
+}
+
+#endif
+
+/*----------------------------------------------------------------------------
+; End Function: Lag_max_wrapper
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pitch_ol
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ vadSt = pointer to a vadState structure
+ mode = data of type enum Mode specifies the mode.
+ signal = pointer to buffer of signal used to compute the open loop
+ pitch
+ where signal[-pit_max] to signal[-1] should be known
+ pit_min = 16 bit value specifies the minimum pitch lag
+ pit_max = 16 bit value specifies the maximum pitch lag
+ L_frame = 16 bit value specifies the length of frame to compute pitch
+ idx = 16 bit value specifies the frame index
+ dtx = Data of type 'Flag' used for dtx. Use dtx=1, do not use dtx=0
+ pOverflow = pointer to overflow indicator (Flag)
+
+ Outputs
+ vadSt = The vadSt state structure may be modified.
+ pOverflow -> 1 if the math operations called by this routine saturate
+
+ Returns:
+ p_max1 = 16 bit value representing the open loop pitch lag.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function computes the open loop pitch lag based on the perceptually
+ weighted speech signal. This is done in the following steps:
+ - find three maxima of the correlation <sw[n],sw[n-T]>,
+ dividing the search range into three parts:
+ pit_min ... 2*pit_min-1
+ 2*pit_min ... 4*pit_min-1
+ 4*pit_min ... pit_max
+ - divide each maximum by <sw[n-t], sw[n-t]> where t is the delay at
+ that maximum correlation.
+ - select the delay of maximum normalized correlation (among the
+ three candidates) while favoring the lower delay ranges.
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pitch_ol.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 Pitch_ol ( // o : open loop pitch lag
+ vadState *vadSt, // i/o : VAD state struct
+ enum Mode mode, // i : coder mode
+ Word16 signal[], // i : signal used to compute the open loop pitch
+ // signal[-pit_max] to signal[-1] should be known
+ Word16 pit_min, // i : minimum pitch lag
+ Word16 pit_max, // i : maximum pitch lag
+ Word16 L_frame, // i : length of frame to compute pitch
+ Word16 idx, // i : frame index
+ Flag dtx // i : dtx flag; use dtx=1, do not use dtx=0
+ )
+{
+ Word16 i, j;
+ Word16 max1, max2, max3;
+ Word16 p_max1, p_max2, p_max3;
+ Word16 scal_flag = 0;
+ Word32 t0;
+#ifdef VAD2
+ Word32 r01, r02, r03;
+ Word32 rmax1, rmax2, rmax3;
+#else
+ Word16 corr_hp_max;
+#endif
+ Word32 corr[PIT_MAX+1], *corr_ptr;
+
+ // Scaled signal
+
+ Word16 scaled_signal[L_FRAME + PIT_MAX];
+ Word16 *scal_sig, scal_fac;
+
+#ifndef VAD2
+ if (dtx)
+ { // no test() call since this if is only in simulation env
+ // update tone detection
+ if ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0))
+ {
+ vad_tone_detection_update (vadSt, 1);
+ }
+ else
+ {
+ vad_tone_detection_update (vadSt, 0);
+ }
+ }
+#endif
+
+ scal_sig = &scaled_signal[pit_max];
+
+ t0 = 0L;
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ t0 = L_mac (t0, signal[i], signal[i]);
+ }
+
+ *--------------------------------------------------------*
+ * Scaling of input signal. *
+ * *
+ * if Overflow -> scal_sig[i] = signal[i]>>3 *
+ * else if t0 < 1^20 -> scal_sig[i] = signal[i]<<3 *
+ * else -> scal_sig[i] = signal[i] *
+ *--------------------------------------------------------*
+
+ *--------------------------------------------------------*
+ * Verification for risk of overflow. *
+ *--------------------------------------------------------*
+
+ if (L_sub (t0, MAX_32) == 0L) // Test for overflow
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = shr (signal[i], 3);
+ }
+ scal_fac = 3;
+ }
+ else if (L_sub (t0, (Word32) 1048576L) < (Word32) 0)
+ // if (t0 < 2^20)
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = shl (signal[i], 3);
+ }
+ scal_fac = -3;
+ }
+ else
+ {
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ scal_sig[i] = signal[i];
+ }
+ scal_fac = 0;
+ }
+
+ // calculate all coreelations of scal_sig, from pit_min to pit_max
+ corr_ptr = &corr[pit_max];
+ comp_corr (scal_sig, L_frame, pit_max, pit_min, corr_ptr);
+
+ *--------------------------------------------------------------------*
+ * The pitch lag search is divided in three sections. *
+ * Each section cannot have a pitch multiple. *
+ * We find a maximum for each section. *
+ * We compare the maximum of each section by favoring small lags. *
+ * *
+ * First section: lag delay = pit_max downto 4*pit_min *
+ * Second section: lag delay = 4*pit_min-1 downto 2*pit_min *
+ * Third section: lag delay = 2*pit_min-1 downto pit_min *
+ *--------------------------------------------------------------------*
+
+ // mode dependent scaling in Lag_max
+ if (sub(mode, MR122) == 0)
+ {
+ scal_flag = 1;
+ }
+ else
+ {
+ scal_flag = 0;
+ }
+
+#ifdef VAD2
+ j = shl (pit_min, 2);
+ p_max1 = Lag_max (corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ pit_max, j, &max1, &rmax1, &r01, dtx);
+
+ i = sub (j, 1);
+ j = shl (pit_min, 1);
+ p_max2 = Lag_max (corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, j, &max2, &rmax2, &r02, dtx);
+
+ i = sub (j, 1);
+ p_max3 = Lag_max (corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, pit_min, &max3, &rmax3, &r03, dtx);
+#else
+ j = shl (pit_min, 2);
+ p_max1 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ pit_max, j, &max1, dtx);
+
+ i = sub (j, 1);
+ j = shl (pit_min, 1);
+ p_max2 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, j, &max2, dtx);
+
+ i = sub (j, 1);
+ p_max3 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, pit_min, &max3, dtx);
+
+ if (dtx)
+ { // no test() call since this if is only in simulation env
+ if (sub(idx, 1) == 0)
+ {
+ // calculate max high-passed filtered correlation of all lags
+ hp_max (corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max);
+
+ // update complex background detector
+ vad_complex_detection_update(vadSt, corr_hp_max);
+ }
+ }
+#endif
+
+ *--------------------------------------------------------------------*
+ * Compare the 3 sections maximum, and favor small lag. *
+ *--------------------------------------------------------------------*
+
+ if (sub (mult (max1, THRESHOLD), max2) < 0)
+ {
+ max1 = max2;
+ p_max1 = p_max2;
+#ifdef VAD2
+ if (dtx)
+ {
+ rmax1 = rmax2;
+ r01 = r02;
+#endif
+ }
+ if (sub (mult (max1, THRESHOLD), max3) < 0)
+ {
+ p_max1 = p_max3;
+#ifdef VAD2
+ if (dtx)
+ {
+ rmax1 = rmax3;
+ r01 = r03;
+ }
+#endif
+ }
+
+#ifdef VAD2
+ if (dtx)
+ {
+ vadSt->L_Rmax = L_add(vadSt->L_Rmax, rmax1); // Save max correlation
+ vadSt->L_R0 = L_add(vadSt->L_R0, r01); // Save max energy
+ }
+#endif
+
+ return (p_max1);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Pitch_ol( /* o : open loop pitch lag */
+ vadState *vadSt, /* i/o : VAD state struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 signal[], /* i : signal used to compute the open loop pitch */
+ /* signal[-pit_max] to signal[-1] should be known */
+ Word16 pit_min, /* i : minimum pitch lag */
+ Word16 pit_max, /* i : maximum pitch lag */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 idx, /* i : frame index */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow Flag */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 max1;
+ Word16 max2;
+ Word16 max3;
+ Word16 p_max1;
+ Word16 p_max2;
+ Word16 p_max3;
+ Word16 scal_flag = 0;
+ Word32 t0;
+
+#ifdef VAD2
+ Word32 r01;
+ Word32 r02;
+ Word32 r03;
+ Word32 rmax1;
+ Word32 rmax2;
+ Word32 rmax3;
+#else
+ Word16 corr_hp_max;
+#endif
+ Word32 corr[PIT_MAX+1];
+ Word32 *corr_ptr;
+
+ /* Scaled signal */
+
+ Word16 scaled_signal[L_FRAME + PIT_MAX];
+ Word16 *scal_sig;
+ Word16 *p_signal;
+ Word16 scal_fac;
+ Word32 L_temp;
+
+#ifndef VAD2
+ if (dtx)
+ { /* no test() call since this if is only in simulation env */
+ /* update tone detection */
+ if ((mode == MR475) || (mode == MR515))
+ {
+ vad_tone_detection_update(vadSt, 1, pOverflow);
+ }
+ else
+ {
+ vad_tone_detection_update(vadSt, 0, pOverflow);
+ }
+ }
+#endif
+
+
+ t0 = 0L;
+ p_signal = &signal[-pit_max];
+
+ for (i = -pit_max; i < L_frame; i++)
+ {
+ t0 += (((Word32) * (p_signal)) * *(p_signal)) << 1;
+ p_signal++;
+ if (t0 < 0)
+ {
+ t0 = MAX_32;
+ break;
+ }
+
+ }
+
+ /*--------------------------------------------------------*
+ * Scaling of input signal. *
+ * *
+ * if Overflow -> scal_sig[i] = signal[i]>>3 *
+ * else if t0 < 1^20 -> scal_sig[i] = signal[i]<<3 *
+ * else -> scal_sig[i] = signal[i] *
+ *--------------------------------------------------------*/
+
+ /*--------------------------------------------------------*
+ * Verification for risk of overflow. *
+ *--------------------------------------------------------*/
+
+ scal_sig = &scaled_signal[0];
+ p_signal = &signal[-pit_max];
+
+ if (t0 == MAX_32) /* Test for overflow */
+ {
+
+ for (i = (pit_max + L_frame) >> 1; i != 0; i--)
+ {
+ *(scal_sig++) = (Word16)(((Word32) * (p_signal++) >> 3));
+ *(scal_sig++) = (Word16)(((Word32) * (p_signal++) >> 3));
+ }
+
+ if ((pit_max + L_frame) & 1)
+ {
+ *(scal_sig) = (Word16)(((Word32) * (p_signal) >> 3));
+ }
+
+ scal_fac = 3;
+ }
+ else if (t0 < (Word32)1048576L)
+ /* if (t0 < 2^20) */
+ {
+ for (i = (pit_max + L_frame) >> 1; i != 0; i--)
+ {
+ *(scal_sig++) = (Word16)(((Word32) * (p_signal++) << 3));
+ *(scal_sig++) = (Word16)(((Word32) * (p_signal++) << 3));
+ }
+
+ if ((pit_max + L_frame) & 1)
+ {
+ *(scal_sig) = (Word16)(((Word32) * (p_signal) << 3));
+ }
+ scal_fac = -3;
+ }
+ else
+ {
+
+ memcpy(scal_sig, p_signal, (L_frame + pit_max)*sizeof(*signal));
+ scal_fac = 0;
+ }
+
+ /* calculate all coreelations of scal_sig, from pit_min to pit_max */
+ corr_ptr = &corr[pit_max];
+
+ scal_sig = &scaled_signal[pit_max];
+
+ comp_corr(scal_sig, L_frame, pit_max, pit_min, corr_ptr);
+
+ /*--------------------------------------------------------------------*
+ * The pitch lag search is divided in three sections. *
+ * Each section cannot have a pitch multiple. *
+ * We find a maximum for each section. *
+ * We compare the maximum of each section by favoring small lags. *
+ * *
+ * First section: lag delay = pit_max downto 4*pit_min *
+ * Second section: lag delay = 4*pit_min-1 downto 2*pit_min *
+ * Third section: lag delay = 2*pit_min-1 downto pit_min *
+ *--------------------------------------------------------------------*/
+
+ /* mode dependent scaling in Lag_max */
+
+ if (mode == MR122)
+ {
+ scal_flag = 1;
+ }
+ else
+ {
+ scal_flag = 0;
+ }
+
+#ifdef VAD2
+ L_temp = ((Word32)pit_min) << 2;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *pOverflow = 1;
+ j = (pit_min > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ j = (Word16)L_temp;
+ }
+
+ p_max1 = Lag_max(corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ pit_max, j, &max1, &rmax1, &r01, dtx, pOverflow);
+
+ i = j - 1;
+
+ j = pit_min << 1;
+
+ p_max2 = Lag_max(corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, j, &max2, &rmax2, &r02, dtx, pOverflow);
+
+ i = j - 1;
+
+ p_max3 = Lag_max(corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, pit_min, &max3, &rmax3, &r03, dtx, pOverflow);
+
+#else
+ L_temp = ((Word32)pit_min) << 2;
+ if (L_temp != (Word32)((Word16) L_temp))
+ {
+ *pOverflow = 1;
+ j = (pit_min > 0) ? MAX_16 : MIN_16;
+ }
+ else
+ {
+ j = (Word16)L_temp;
+ }
+
+ p_max1 = Lag_max(vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ pit_max, j, &max1, dtx, pOverflow);
+
+ i = j - 1;
+
+
+ j = pit_min << 1;
+
+
+ p_max2 = Lag_max(vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, j, &max2, dtx, pOverflow);
+
+ i = j - 1;
+ p_max3 = Lag_max(vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
+ i, pit_min, &max3, dtx, pOverflow);
+
+ if (dtx)
+ { /* no test() call since this if is only in simulation env */
+
+ if (idx == 1)
+ {
+ /* calculate max high-passed filtered correlation of all lags */
+ hp_max(corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max,
+ pOverflow);
+
+ /* update complex background detector */
+ vad_complex_detection_update(vadSt, corr_hp_max);
+ }
+ }
+#endif
+
+ /*--------------------------------------------------------------------*
+ * Compare the 3 sections maximum, and favor small lag. *
+ *--------------------------------------------------------------------*/
+
+ i = mult(max1, THRESHOLD, pOverflow);
+
+ if (i < max2)
+ {
+ max1 = max2;
+ p_max1 = p_max2;
+
+#ifdef VAD2
+ if (dtx)
+ {
+ rmax1 = rmax2;
+ r01 = r02;
+ }
+#endif
+ }
+
+ i = mult(max1, THRESHOLD, pOverflow);
+
+ if (i < max3)
+ {
+ p_max1 = p_max3;
+
+#ifdef VAD2
+ if (dtx)
+ {
+ rmax1 = rmax3;
+ r01 = r03;
+ }
+#endif
+ }
+
+#ifdef VAD2
+ if (dtx)
+ {
+ /* Save max correlation */
+ vadSt->L_Rmax = L_add(vadSt->L_Rmax, rmax1, pOverflow);
+ /* Save max energy */
+ vadSt->L_R0 = L_add(vadSt->L_R0, r01, pOverflow);
+ }
+#endif
+
+ return (p_max1);
+}
diff --git a/media/codecs/amrnb/enc/src/pitch_ol.h b/media/codecs/amrnb/enc/src/pitch_ol.h
new file mode 100644
index 0000000..df7f307
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pitch_ol.h
@@ -0,0 +1,122 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/pitch_ol.h
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : pitch_ol.h
+ Purpose : Compute the open loop pitch lag.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PITCH_OL_H
+#define PITCH_OL_H "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "vad.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ Word16 Pitch_ol( /* o : open loop pitch lag */
+ vadState *vadSt, /* i/o : VAD state struct */
+ enum Mode mode, /* i : coder mode */
+ Word16 signal[], /* i : signal used to compute the open loop pitch */
+ /* signal[-pit_max] to signal[-1] should be known */
+ Word16 pit_min, /* i : minimum pitch lag */
+ Word16 pit_max, /* i : maximum pitch lag */
+ Word16 L_frame, /* i : length of frame to compute pitch */
+ Word16 idx, /* i : frame index */
+ Flag dtx, /* i : dtx flag; use dtx=1, do not use dtx=0 */
+ Flag *pOverflow /* i/o : overflow Flag */
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PITCH_OL_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/pre_big.cpp b/media/codecs/amrnb/enc/src/pre_big.cpp
new file mode 100644
index 0000000..02544cf
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pre_big.cpp
@@ -0,0 +1,210 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/pre_big.c
+ Functions:
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Big subframe (2 subframes) preprocessing
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pre_big.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "syn_filt.h"
+#include "weight_a.h"
+#include "residu.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: pre_big
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode = enum Mode -- coder mode
+ gamma1 = array of type const Word16 -- spectral exp. factor 1
+ gamma1_12k2 = array of type const Word16 -- spectral exp. factor 1 for EFR
+ gamma2 = array of type const Word16 -- spectral exp. factor 2
+ A_t = array of type Word16 -- A(z) unquantized, for 4 subframes, Q12
+ frameOffset = Word16 -- Start position in speech vector, Q0
+ speech[] = array of type Word16 -- speech, Q0
+
+ Outputs:
+ mem_w = array of type Word16 -- synthesis filter memory state, Q0
+ wsp = array of type Word16 -- weighted speech Q0
+ pOverflow = pointer of type Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pre_big.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void pre_big(
+ enum Mode mode, /* i : coder mode */
+ const Word16 gamma1[], /* i : spectral exp. factor 1 */
+ const Word16 gamma1_12k2[],/* i : spectral exp. factor 1 for EFR */
+ const Word16 gamma2[], /* i : spectral exp. factor 2 */
+ Word16 A_t[], /* i : A(z) unquantized, for 4 subframes, Q12 */
+ Word16 frameOffset, /* i : Start position in speech vector, Q0 */
+ Word16 speech[], /* i : speech, Q0 */
+ Word16 mem_w[], /* i/o: synthesis filter memory state, Q0 */
+ Word16 wsp[], /* o : weighted speech Q0 */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 Ap1[MP1]; /* A(z) with spectral expansion */
+ Word16 Ap2[MP1]; /* A(z) with spectral expansion */
+ const Word16 *g1; /* Pointer to correct gammma1 vector */
+ Word16 aOffset;
+ Word16 i;
+
+ if (mode <= MR795)
+ {
+ g1 = gamma1;
+ }
+ else
+ {
+ g1 = gamma1_12k2;
+ }
+
+ if (frameOffset > 0)
+ {
+ aOffset = 2 * MP1;
+ }
+ else
+ {
+ aOffset = 0;
+ }
+
+ /* process two subframes (which form the "big" subframe) */
+ for (i = 0; i < 2; i++)
+ {
+ Weight_Ai(&A_t[aOffset], g1, Ap1);
+ Weight_Ai(&A_t[aOffset], gamma2, Ap2);
+ Residu(Ap1, &speech[frameOffset], &wsp[frameOffset], L_SUBFR);
+
+ Syn_filt(Ap2, &wsp[frameOffset], &wsp[frameOffset], L_SUBFR, mem_w, 1);
+
+ aOffset = add(aOffset, MP1, pOverflow);
+
+ frameOffset = add(frameOffset, L_SUBFR, pOverflow);
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/pre_big.h b/media/codecs/amrnb/enc/src/pre_big.h
new file mode 100644
index 0000000..6b47bfe
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pre_big.h
@@ -0,0 +1,131 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/pre_big.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, pre_big.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef pre_big_h
+#define pre_big_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void pre_big(
+ enum Mode mode, /* i : coder mode */
+ const Word16 gamma1[], /* i : spectral exp. factor 1 */
+ const Word16 gamma1_12k2[],/* i : spectral exp. factor 1 for EFR */
+ const Word16 gamma2[], /* i : spectral exp. factor 2 */
+ Word16 A_t[], /* i : A(z) unquantized, for 4 subframes, Q12 */
+ Word16 frameOffset, /* i : Start position in speech vector, Q0 */
+ Word16 speech[], /* i : speech, Q0 */
+ Word16 mem_w[], /* i/o: synthesis filter memory state, Q0 */
+ Word16 wsp[], /* o : weighted speech Q0 */
+ Flag *pOverflow /* o : overflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _H_ */
+
diff --git a/media/codecs/amrnb/enc/src/pre_proc.cpp b/media/codecs/amrnb/enc/src/pre_proc.cpp
new file mode 100644
index 0000000..042920e
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pre_proc.cpp
@@ -0,0 +1,589 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/pre_proc.c
+ Funtions: Pre_Process_init
+ Pre_Process_reset
+ Pre_Process_exit
+ Pre_Process
+
+ Date: 05/17/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Put the file into our template structure.
+
+ Description: First pass optimization.
+
+ Description: Made changes based on comments from review meeting.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Removed basic_op.h from the Include section. It is not used.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Fixed typecasting issue with TI C compiler.
+ 2. Modified FOR loop to count down.
+ 3. Cosmetic changes to the code to make address post-increment
+ clearer.
+ 4. Removed unnecessary typecasting in the multiply-accumulate
+ portion of FOR loop body.
+ 5. Removed "static" in table definitions.
+ 6. Updated copyright year.
+
+ Description: For Pre_Process()
+ 1. Replaced variables (containing filter coefficients) with
+ constants, to avoid extra register swaping.
+ 2. Changed to decrement loop
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ These modules handle the preprocessing of input speech.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "pre_proc.h"
+#include "typedef.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pre_Process_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to an array of pointer to structures of type
+ Pre_ProcessState
+
+ Outputs:
+ Structure pointed to by the pointer pointed to by state is
+ initialized to its reset value
+ state points to the allocated memory
+
+ Returns:
+ return_value = 0 if memory was successfully initialized,
+ otherwise returns -1.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Allocates state memory and initializes state memory.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pre_proc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Pre_Process_init (Pre_ProcessState **state)
+{
+ Pre_ProcessState* s;
+
+ if (state == (Pre_ProcessState **) NULL){
+ fprintf(stderr, "Pre_Process_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (Pre_ProcessState *) malloc(sizeof(Pre_ProcessState))) == NULL){
+ fprintf(stderr, "Pre_Process_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ Pre_Process_reset(s);
+ *state = s;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Pre_Process_init(Pre_ProcessState **state)
+{
+ Pre_ProcessState* s;
+
+ if (state == (Pre_ProcessState **) NULL)
+ {
+ /* fprintf(stderr, "Pre_Process_init: invalid parameter\n"); */
+ return(-1);
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (Pre_ProcessState *) malloc(sizeof(Pre_ProcessState))) == NULL)
+ {
+ /* fprintf(stderr, "Pre_Process_init:
+ can not malloc state structure\n"); */
+ return(-1);
+ }
+
+ Pre_Process_reset(s);
+ *state = s;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pre_Process_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to structure of type Pre_ProcessState
+
+ Outputs:
+ Structure pointed to by state is initialized to zero.
+
+ Returns:
+ return_value = 0 if memory was successfully reset,
+ otherwise returns -1.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Initializes state memory to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pre_proc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Pre_Process_reset (Pre_ProcessState *state)
+{
+ if (state == (Pre_ProcessState *) NULL){
+ fprintf(stderr, "Pre_Process_reset: invalid parameter\n");
+ return -1;
+ }
+
+ state->y2_hi = 0;
+ state->y2_lo = 0;
+ state->y1_hi = 0;
+ state->y1_lo = 0;
+ state->x0 = 0;
+ state->x1 = 0;
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Pre_Process_reset(Pre_ProcessState *state)
+{
+ if (state == (Pre_ProcessState *) NULL)
+ {
+ /* fprintf(stderr, "Pre_Process_reset: invalid parameter\n"); */
+ return(-1);
+ }
+
+ state->y2_hi = 0;
+ state->y2_lo = 0;
+ state->y1_hi = 0;
+ state->y1_lo = 0;
+ state->x0 = 0;
+ state->x1 = 0;
+
+ return(0);
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pre_Process_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = a pointer to an array of pointers to structures of
+ type Pre_ProcessState
+
+ Outputs:
+ state points to a NULL address
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The memory used for state memory is freed.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pre_proc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Pre_Process_exit (Pre_ProcessState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Pre_Process_exit(Pre_ProcessState **state)
+{
+ if (state == NULL || *state == NULL)
+ {
+ return;
+ }
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Pre_Process
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = a pointer to a structure of type Pre_ProcessState
+ signal = input/output signal (Word16)
+ lg = length of signal (Word16)
+
+ Outputs:
+ st points to the updated structure
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ a = points to a buffer of filter coefficients
+ b = points to a buffer of filter coefficients
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This module performs the preprocessing of the input speech.
+ The signal is passed through a 2nd order high pass filtering with cut off
+ frequency at 80 Hz. The input is divided by two in the filtering process.
+
+ y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b[2]*x[i-2]/2
+ + a[1]*y[i-1] + a[2]*y[i-2];
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ pre_proc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Pre_Process (
+ Pre_ProcessState *st,
+ Word16 signal[], // input/output signal
+ Word16 lg) // lenght of signal
+{
+ Word16 i, x2;
+ Word32 L_tmp;
+
+ for (i = 0; i < lg; i++)
+ {
+ x2 = st->x1;
+ st->x1 = st->x0;
+ st->x0 = signal[i];
+
+ // y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b140[2]*x[i-2]/2
+ // + a[1]*y[i-1] + a[2] * y[i-2];
+
+ L_tmp = Mpy_32_16 (st->y1_hi, st->y1_lo, a[1]);
+ L_tmp = L_add (L_tmp, Mpy_32_16 (st->y2_hi, st->y2_lo, a[2]));
+ L_tmp = L_mac (L_tmp, st->x0, b[0]);
+ L_tmp = L_mac (L_tmp, st->x1, b[1]);
+ L_tmp = L_mac (L_tmp, x2, b[2]);
+ L_tmp = L_shl (L_tmp, 3);
+ signal[i] = pv_round (L_tmp);
+
+ st->y2_hi = st->y1_hi;
+ st->y2_lo = st->y1_lo;
+ L_Extract (L_tmp, &st->y1_hi, &st->y1_lo);
+ }
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+/*
+ filter coefficients (fc = 80 Hz, coeff. b[] is divided by 2)
+ const Word16 b[3] = {1899, -3798, 1899};
+ const Word16 a[3] = {4096, 7807, -3733};
+
+*/
+
+void Pre_Process(
+ Pre_ProcessState *st,
+ Word16 signal[], /* input/output signal */
+ Word16 lg) /* length of signal */
+{
+ Word16 i;
+ Word16 x_n_2;
+ Word16 x_n_1;
+ Word32 L_tmp;
+ Word16 *p_signal = signal;
+
+ x_n_2 = st->x1;
+ x_n_1 = st->x0;
+
+ for (i = lg; i != 0; i--)
+ {
+
+
+ /* y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b140[2]*x[i-2]/2 */
+ /* + a[1]*y[i-1] + a[2] * y[i-2]; */
+
+ L_tmp = ((Word32) st->y1_hi) * 7807;
+ L_tmp += (Word32)(((Word32) st->y1_lo * 7807) >> 15);
+
+ L_tmp += ((Word32) st->y2_hi) * (-3733);
+ st->y2_hi = st->y1_hi;
+ L_tmp += (Word32)(((Word32) st->y2_lo * (-3733)) >> 15);
+ st->y2_lo = st->y1_lo;
+
+ L_tmp += ((Word32) x_n_2) * 1899;
+ x_n_2 = x_n_1;
+ L_tmp += ((Word32) x_n_1) * (-3798);
+ x_n_1 = *(p_signal);
+ L_tmp += ((Word32) x_n_1) * 1899;
+
+
+ *(p_signal++) = (Word16)((L_tmp + 0x0000800L) >> 12);
+
+ st->y1_hi = (Word16)(L_tmp >> 12);
+ st->y1_lo = (Word16)((L_tmp << 3) - ((Word32)(st->y1_hi) << 15));
+
+ }
+
+ st->x1 = x_n_2;
+ st->x0 = x_n_1;
+
+ return;
+}
+
+
diff --git a/media/codecs/amrnb/enc/src/pre_proc.h b/media/codecs/amrnb/enc/src/pre_proc.h
new file mode 100644
index 0000000..abe676f
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/pre_proc.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : pre_proc.h
+* Purpose : Preprocessing of input speech.
+*
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+********************************************************************************
+*/
+#ifndef pre_proc_h
+#define pre_proc_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * LOCAL VARIABLES AND TABLES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+ typedef struct
+ {
+ Word16 y2_hi;
+ Word16 y2_lo;
+ Word16 y1_hi;
+ Word16 y1_lo;
+ Word16 x0;
+ Word16 x1;
+ } Pre_ProcessState;
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+
+ Word16 Pre_Process_init(Pre_ProcessState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to Pre_Process in each call.
+ returns 0 on success
+ */
+
+ Word16 Pre_Process_reset(Pre_ProcessState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ void Pre_Process_exit(Pre_ProcessState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ void Pre_Process(
+ Pre_ProcessState *st,
+ Word16 signal[], /* Input/output signal */
+ Word16 lg /* Lenght of signal */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/enc/src/prm2bits.cpp b/media/codecs/amrnb/enc/src/prm2bits.cpp
new file mode 100644
index 0000000..9088f7d
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/prm2bits.cpp
@@ -0,0 +1,310 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+
+
+
+ Filename: /audio/gsm_amr/c/src/prm2bits.c
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Improved the code as per review comments.
+
+ Description: For Int2bin() and Prm2bits()
+ 1. Eliminated unused include file typedef.h.
+ 2. Replaced array addressing by pointers
+ 3. Changed to decrement loops
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "prm2bits.h"
+#include "mode.h"
+#include "bitno_tab.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+#define MASK 0x0001
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Int2bin
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ value = value to be converted to binary of type Word16
+ no_of_bits = number of bits associated with value of type Word16
+
+ Outputs:
+ bitstream = pointer to address where bits are written of type Word16
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION: Int2bin
+
+ PURPOSE: convert integer to binary and write the bits to the array
+ bitstream[]. The most significant bits are written first.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ prm2bits.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static void Int2bin (
+ Word16 value, // input : value to be converted to binary
+ Word16 no_of_bits, // input : number of bits associated with value
+ Word16 *bitstream // output: address where bits are written
+)
+{
+ Word16 *pt_bitstream, i, bit;
+
+ pt_bitstream = &bitstream[no_of_bits];
+
+ for (i = 0; i < no_of_bits; i++)
+ {
+ bit = value & MASK;
+ if (bit == 0)
+ {
+ *--pt_bitstream = BIT_0;
+ }
+ else
+ {
+ *--pt_bitstream = BIT_1;
+ }
+ value = shr (value, 1);
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+static void Int2bin(
+ Word16 value, /* input : value to be converted to binary */
+ Word16 no_of_bits, /* input : number of bits associated with value */
+ Word16 *bitstream /* output: address where bits are written */
+)
+{
+ Word16 *pt_bitstream;
+ Word16 i;
+
+ pt_bitstream = &bitstream[no_of_bits-1];
+
+ for (i = no_of_bits; i != 0; i--)
+ {
+ *(pt_bitstream--) = value & MASK;
+ value >>= 1;
+ }
+
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: prm2bits
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode = AMR mode of type enum Mode
+ prm[] = pointer to analysis parameters of type Word16
+
+ Outputs:
+ bits[] = pointer to serial bits of type Word16
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ FUNCTION: Prm2bits
+
+ PURPOSE: converts the encoder parameter vector into a vector of serial
+ bits.
+
+ DESCRIPTION: depending on the mode, different numbers of parameters
+ (with differing numbers of bits) are processed. Details
+ are found in bitno.tab
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ prm2bits.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void Prm2bits (
+ enum Mode mode, // i : AMR mode
+ Word16 prm[], // i : analysis parameters (size <= MAX_PRM_SIZE)
+ Word16 bits[] // o : serial bits (size <= MAX_SERIAL_SIZE)
+)
+{
+ Word16 i;
+
+ for (i = 0; i < prmno[mode]; i++)
+ {
+ Int2bin (prm[i], bitno[mode][i], bits);
+ bits += bitno[mode][i];
+ add(0,0); // account for above pointer update
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void Prm2bits(
+ enum Mode mode, /* i : AMR mode */
+ Word16 prm[], /* i : analysis parameters (size <= MAX_PRM_SIZE) */
+ Word16 bits[] /* o : serial bits (size <= MAX_SERIAL_SIZE) */
+)
+{
+ Word16 i;
+ const Word16 *p_mode;
+ Word16 *p_prm;
+
+ p_mode = &bitno[mode][0];
+ p_prm = &prm[0];
+
+ for (i = prmno[mode]; i != 0; i--)
+ {
+ Int2bin(*(p_prm++), *(p_mode), bits);
+ bits += *(p_mode++);
+ }
+
+ return;
+}
+
diff --git a/media/codecs/amrnb/enc/src/prm2bits.h b/media/codecs/amrnb/enc/src/prm2bits.h
new file mode 100644
index 0000000..8ad11a8
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/prm2bits.h
@@ -0,0 +1,81 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+********************************************************************************
+*
+* GSM AMR-NB speech codec R98 Version 7.5.0 March 2, 2001
+* R99 Version 3.2.0
+* REL-4 Version 4.0.0
+*
+********************************************************************************
+*
+* File : prm2bits.h
+* Purpose : Converts the encoder parameter vector into a
+* : vector of serial bits.
+*
+********************************************************************************
+*/
+#ifndef prm2bits_h
+#define prm2bits_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "mode.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ ********************************************************************************
+ * DEFINITION OF DATA TYPES
+ ********************************************************************************
+ */
+
+ /*
+ ********************************************************************************
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************
+ */
+ void Prm2bits(
+ enum Mode mode, /* i : AMR mode */
+ Word16 prm[], /* input : analysis parameters */
+ Word16 bits[] /* output: serial bits */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrnb/enc/src/q_gain_c.cpp b/media/codecs/amrnb/enc/src/q_gain_c.cpp
new file mode 100644
index 0000000..c58b687
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/q_gain_c.cpp
@@ -0,0 +1,293 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/q_gain_c.c
+ Functions: q_gain_code
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description:
+ (1) Removed optimization -- mult(i, 3, pOverflow) is NOT the same as adding
+ i to itself 3 times. The reason is because the mult function does a
+ right shift by 15, which will obliterate smaller numbers.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Eliminated math operations that unnecessary checked for
+ saturation by evaluating the operands
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Scalar quantization of the innovative codebook gain.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "q_gain_c.h"
+#include "mode.h"
+#include "oper_32b.h"
+#include "basic_op.h"
+#include "log2.h"
+#include "pow2.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NB_QUA_CODE 32
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 qua_gain_code[NB_QUA_CODE*3];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: q_gain_code
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode -- enum Mode -- AMR mode
+ exp_gcode0 -- Word16 -- predicted CB gain (exponent), Q0
+ frac_gcode0 -- Word16 -- predicted CB gain (fraction), Q15
+ gain -- Pointer to Word16 -- quantized fixed codebook gain, Q1
+
+ Outputs:
+ gain -- Pointer to Word16 -- quantized fixed codebook gain, Q1
+
+ qua_ener_MR122 -- Pointer to Word16 -- quantized energy error, Q10
+ (for MR122 MA predictor update)
+
+ qua_ener -- Pointer to Word16 -- quantized energy error, Q10
+ (for other MA predictor update)
+
+ pOverflow -- Pointer to Flag -- overflow indicator
+ Returns:
+ quantization index -- Word16 -- Q0
+
+ Global Variables Used:
+ qua_gain_code[]
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Scalar quantization of the innovative codebook gain.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_gain_c.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 q_gain_code( /* o : quantization index, Q0 */
+ enum Mode mode, /* i : AMR mode */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 *gain, /* i/o: quantized fixed codebook gain, Q1 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Flag *pOverflow
+)
+{
+ const Word16 *p;
+ Word16 i;
+ Word16 index;
+ Word16 gcode0;
+ Word16 err;
+ Word16 err_min;
+ Word16 g_q0;
+ Word16 temp;
+
+ if (mode == MR122)
+ {
+ g_q0 = *gain >> 1; /* Q1 -> Q0 */
+ }
+ else
+ {
+ g_q0 = *gain;
+ }
+
+ /*-------------------------------------------------------------------*
+ * predicted codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = Pow2(int(d)+frac(d)) *
+ * = 2^exp + 2^frac *
+ * *
+ *-------------------------------------------------------------------*/
+
+ gcode0 = (Word16) Pow2(exp_gcode0, frac_gcode0, pOverflow); /* predicted gain */
+
+ if (mode == MR122)
+ {
+ gcode0 = shl(gcode0, 4, pOverflow);
+ }
+ else
+ {
+ gcode0 = shl(gcode0, 5, pOverflow);
+ }
+
+ /*-------------------------------------------------------------------*
+ * Search for best quantizer *
+ *-------------------------------------------------------------------*/
+
+ p = &qua_gain_code[0];
+ err_min = ((Word32)gcode0 * *(p++)) >> 15;
+ err_min = g_q0 - err_min;
+ if (err_min < 0)
+ {
+ err_min = -err_min;
+ }
+
+ p += 2; /* skip quantized energy errors */
+ index = 0;
+
+ for (i = 1; i < NB_QUA_CODE; i++)
+ {
+ err = ((Word32)gcode0 * *(p++)) >> 15;
+ err = g_q0 - err;
+
+ if (err < 0)
+ {
+ err = -err;
+ }
+
+ p += 2; /* skip quantized energy error */
+
+ if (err < err_min)
+ {
+ err_min = err;
+ index = i;
+ }
+ }
+
+ temp = index + (index << 1);
+
+ p = &qua_gain_code[temp];
+
+ temp = (gcode0 * *(p++)) >> 15;
+ if (mode == MR122)
+ {
+ *gain = temp << 1;
+ }
+ else
+ {
+ *gain = temp;
+ }
+
+ /* quantized error energies (for MA predictor update) */
+ *qua_ener_MR122 = *p++;
+ *qua_ener = *p;
+
+ return index;
+}
diff --git a/media/codecs/amrnb/enc/src/q_gain_c.h b/media/codecs/amrnb/enc/src/q_gain_c.h
new file mode 100644
index 0000000..621143d
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/q_gain_c.h
@@ -0,0 +1,136 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/q_gain.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, q_gain.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef q_gain_c_h
+#define q_gain_c_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "gc_pred.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*--------------------------------------------------------------------------*
+ * Function q_gain_code() *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * Scalar quantization of the innovative codebook gain. *
+ * *
+ * gc_pred() is used for MA prediction of the innovation energy *
+ *--------------------------------------------------------------------------*/
+ Word16 q_gain_code( /* o : quantization index, Q0 */
+ enum Mode mode, /* i : AMR mode */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 *gain, /* i/o: quantized fixed codebook gain, Q1 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* q_gain_c_h */
+
+
diff --git a/media/codecs/amrnb/enc/src/q_gain_p.cpp b/media/codecs/amrnb/enc/src/q_gain_p.cpp
new file mode 100644
index 0000000..c1aff6b
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/q_gain_p.cpp
@@ -0,0 +1,267 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/q_gain_p.c
+ Functions: q_gain_pitch
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "q_gain_p.h"
+#include "typedef.h"
+#include "oper_32b.h"
+#include "cnst.h"
+#include "basic_op.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NB_QUA_PITCH 16
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 qua_gain_pitch[NB_QUA_PITCH];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: q_gain_pitch
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode -- enum Mode -- AMR mode
+ gp_limit -- Word16 -- pitch gain limit
+ gain -- Pointer to Word16 -- Pitch gain (unquant/quant), Q14
+
+ Outputs:
+ gain -- Pointer to Word16 -- Pitch gain (unquant/quant), Q14
+
+ gain_cand -- Array of type Word16 -- pitch gain candidates (3),
+ MR795 only, Q14
+
+ gain_cind -- Array of type Word16 -- pitch gain cand. indices (3),
+ MR795 only, Q0
+
+ pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ Word16 -- index of quantization
+
+ Global Variables Used:
+ qua_gain_pitch
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ q_gain_p.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 q_gain_pitch( /* Return index of quantization */
+ enum Mode mode, /* i : AMR mode */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *gain, /* i/o: Pitch gain (unquant/quant), Q14 */
+ Word16 gain_cand[], /* o : pitch gain candidates (3), MR795 only, Q14 */
+ Word16 gain_cind[], /* o : pitch gain cand. indices (3),MR795 only, Q0 */
+ Flag *pOverflow
+)
+{
+ Word16 i;
+ Word16 index;
+ Word16 err;
+ Word16 err_min;
+
+ err_min = sub(*gain, qua_gain_pitch[0], pOverflow);
+ err_min = abs_s(err_min);
+
+ index = 0;
+
+ for (i = 1; i < NB_QUA_PITCH; i++)
+ {
+ if (qua_gain_pitch[i] <= gp_limit)
+ {
+ err = sub(*gain, qua_gain_pitch[i], pOverflow);
+ err = abs_s(err);
+
+ if (err < err_min)
+ {
+ err_min = err;
+ index = i;
+ }
+ }
+ }
+
+ if (mode == MR795)
+ {
+ /* in MR795 mode, compute three gain_pit candidates around the index
+ * found in the quantization loop: the index found and the two direct
+ * neighbours, except for the extreme cases (i=0 or i=NB_QUA_PITCH-1),
+ * where the direct neighbour and the neighbour to that is used.
+ */
+ Word16 ii;
+
+ if (index == 0)
+ {
+ ii = index;
+ }
+ else
+ {
+ if (index == (NB_QUA_PITCH - 1) ||
+ (qua_gain_pitch[index+1] > gp_limit))
+ {
+ ii = index - 2;
+ }
+ else
+ {
+ ii = index - 1;
+ }
+ }
+
+ /* store candidate indices and values */
+ for (i = 0; i < 3; i++)
+ {
+ gain_cind[i] = ii;
+ gain_cand[i] = qua_gain_pitch[ii];
+
+ ii = add(ii, 1, pOverflow);
+ }
+
+ *gain = qua_gain_pitch[index];
+ }
+ else
+ {
+ /* in MR122 mode, just return the index and gain pitch found.
+ * If bitexactness is required, mask away the two LSBs (because
+ * in the original EFR, gain_pit was scaled Q12)
+ */
+ if (mode == MR122)
+ {
+ /* clear 2 LSBits */
+ *gain = qua_gain_pitch[index] & 0xFFFC;
+ }
+ else
+ {
+ *gain = qua_gain_pitch[index];
+ }
+ }
+ return index;
+}
diff --git a/media/codecs/amrnb/enc/src/q_gain_p.h b/media/codecs/amrnb/enc/src/q_gain_p.h
new file mode 100644
index 0000000..233ccb0
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/q_gain_p.h
@@ -0,0 +1,124 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/q_gain_p.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, q_gain_p.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef q_gain_p_h
+#define q_gain_p_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ Word16 q_gain_pitch( /* Return index of quantization */
+ enum Mode mode, /* i : AMR mode */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *gain, /* i/o: Pitch gain (unquant/quant), Q14 */
+ Word16 gain_cand[], /* o : pitch gain candidates (3), MR795 only, Q14 */
+ Word16 gain_cind[], /* o : pitch gain cand. indices (3),MR795 only, Q0 */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* q_gain_p_h */
+
diff --git a/media/codecs/amrnb/enc/src/qgain475.cpp b/media/codecs/amrnb/enc/src/qgain475.cpp
new file mode 100644
index 0000000..08a5c15
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/qgain475.cpp
@@ -0,0 +1,1445 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/qgain475.c
+ Funtions: MR475_quant_store_results
+ MR475_update_unq_pred
+ MR475_gain_quant
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ These modules handle the quantization of pitch and codebook gains for MR475.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "qgain475.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "mode.h"
+#include "cnst.h"
+#include "pow2.h"
+#include "log2.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define MR475_VQ_SIZE 256
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* The table contains the following data:
+ *
+ * g_pitch(0) (Q14) // for sub-
+ * g_fac(0) (Q12) // frame 0 and 2
+ * g_pitch(1) (Q14) // for sub-
+ * g_fac(2) (Q12) // frame 1 and 3
+ *
+ */
+static const Word16 table_gain_MR475[MR475_VQ_SIZE*4] =
+{
+ /*g_pit(0), g_fac(0), g_pit(1), g_fac(1) */
+ 812, 128, 542, 140,
+ 2873, 1135, 2266, 3402,
+ 2067, 563, 12677, 647,
+ 4132, 1798, 5601, 5285,
+ 7689, 374, 3735, 441,
+ 10912, 2638, 11807, 2494,
+ 20490, 797, 5218, 675,
+ 6724, 8354, 5282, 1696,
+ 1488, 428, 5882, 452,
+ 5332, 4072, 3583, 1268,
+ 2469, 901, 15894, 1005,
+ 14982, 3271, 10331, 4858,
+ 3635, 2021, 2596, 835,
+ 12360, 4892, 12206, 1704,
+ 13432, 1604, 9118, 2341,
+ 3968, 1538, 5479, 9936,
+ 3795, 417, 1359, 414,
+ 3640, 1569, 7995, 3541,
+ 11405, 645, 8552, 635,
+ 4056, 1377, 16608, 6124,
+ 11420, 700, 2007, 607,
+ 12415, 1578, 11119, 4654,
+ 13680, 1708, 11990, 1229,
+ 7996, 7297, 13231, 5715,
+ 2428, 1159, 2073, 1941,
+ 6218, 6121, 3546, 1804,
+ 8925, 1802, 8679, 1580,
+ 13935, 3576, 13313, 6237,
+ 6142, 1130, 5994, 1734,
+ 14141, 4662, 11271, 3321,
+ 12226, 1551, 13931, 3015,
+ 5081, 10464, 9444, 6706,
+ 1689, 683, 1436, 1306,
+ 7212, 3933, 4082, 2713,
+ 7793, 704, 15070, 802,
+ 6299, 5212, 4337, 5357,
+ 6676, 541, 6062, 626,
+ 13651, 3700, 11498, 2408,
+ 16156, 716, 12177, 751,
+ 8065, 11489, 6314, 2256,
+ 4466, 496, 7293, 523,
+ 10213, 3833, 8394, 3037,
+ 8403, 966, 14228, 1880,
+ 8703, 5409, 16395, 4863,
+ 7420, 1979, 6089, 1230,
+ 9371, 4398, 14558, 3363,
+ 13559, 2873, 13163, 1465,
+ 5534, 1678, 13138, 14771,
+ 7338, 600, 1318, 548,
+ 4252, 3539, 10044, 2364,
+ 10587, 622, 13088, 669,
+ 14126, 3526, 5039, 9784,
+ 15338, 619, 3115, 590,
+ 16442, 3013, 15542, 4168,
+ 15537, 1611, 15405, 1228,
+ 16023, 9299, 7534, 4976,
+ 1990, 1213, 11447, 1157,
+ 12512, 5519, 9475, 2644,
+ 7716, 2034, 13280, 2239,
+ 16011, 5093, 8066, 6761,
+ 10083, 1413, 5002, 2347,
+ 12523, 5975, 15126, 2899,
+ 18264, 2289, 15827, 2527,
+ 16265, 10254, 14651, 11319,
+ 1797, 337, 3115, 397,
+ 3510, 2928, 4592, 2670,
+ 7519, 628, 11415, 656,
+ 5946, 2435, 6544, 7367,
+ 8238, 829, 4000, 863,
+ 10032, 2492, 16057, 3551,
+ 18204, 1054, 6103, 1454,
+ 5884, 7900, 18752, 3468,
+ 1864, 544, 9198, 683,
+ 11623, 4160, 4594, 1644,
+ 3158, 1157, 15953, 2560,
+ 12349, 3733, 17420, 5260,
+ 6106, 2004, 2917, 1742,
+ 16467, 5257, 16787, 1680,
+ 17205, 1759, 4773, 3231,
+ 7386, 6035, 14342, 10012,
+ 4035, 442, 4194, 458,
+ 9214, 2242, 7427, 4217,
+ 12860, 801, 11186, 825,
+ 12648, 2084, 12956, 6554,
+ 9505, 996, 6629, 985,
+ 10537, 2502, 15289, 5006,
+ 12602, 2055, 15484, 1653,
+ 16194, 6921, 14231, 5790,
+ 2626, 828, 5615, 1686,
+ 13663, 5778, 3668, 1554,
+ 11313, 2633, 9770, 1459,
+ 14003, 4733, 15897, 6291,
+ 6278, 1870, 7910, 2285,
+ 16978, 4571, 16576, 3849,
+ 15248, 2311, 16023, 3244,
+ 14459, 17808, 11847, 2763,
+ 1981, 1407, 1400, 876,
+ 4335, 3547, 4391, 4210,
+ 5405, 680, 17461, 781,
+ 6501, 5118, 8091, 7677,
+ 7355, 794, 8333, 1182,
+ 15041, 3160, 14928, 3039,
+ 20421, 880, 14545, 852,
+ 12337, 14708, 6904, 1920,
+ 4225, 933, 8218, 1087,
+ 10659, 4084, 10082, 4533,
+ 2735, 840, 20657, 1081,
+ 16711, 5966, 15873, 4578,
+ 10871, 2574, 3773, 1166,
+ 14519, 4044, 20699, 2627,
+ 15219, 2734, 15274, 2186,
+ 6257, 3226, 13125, 19480,
+ 7196, 930, 2462, 1618,
+ 4515, 3092, 13852, 4277,
+ 10460, 833, 17339, 810,
+ 16891, 2289, 15546, 8217,
+ 13603, 1684, 3197, 1834,
+ 15948, 2820, 15812, 5327,
+ 17006, 2438, 16788, 1326,
+ 15671, 8156, 11726, 8556,
+ 3762, 2053, 9563, 1317,
+ 13561, 6790, 12227, 1936,
+ 8180, 3550, 13287, 1778,
+ 16299, 6599, 16291, 7758,
+ 8521, 2551, 7225, 2645,
+ 18269, 7489, 16885, 2248,
+ 17882, 2884, 17265, 3328,
+ 9417, 20162, 11042, 8320,
+ 1286, 620, 1431, 583,
+ 5993, 2289, 3978, 3626,
+ 5144, 752, 13409, 830,
+ 5553, 2860, 11764, 5908,
+ 10737, 560, 5446, 564,
+ 13321, 3008, 11946, 3683,
+ 19887, 798, 9825, 728,
+ 13663, 8748, 7391, 3053,
+ 2515, 778, 6050, 833,
+ 6469, 5074, 8305, 2463,
+ 6141, 1865, 15308, 1262,
+ 14408, 4547, 13663, 4515,
+ 3137, 2983, 2479, 1259,
+ 15088, 4647, 15382, 2607,
+ 14492, 2392, 12462, 2537,
+ 7539, 2949, 12909, 12060,
+ 5468, 684, 3141, 722,
+ 5081, 1274, 12732, 4200,
+ 15302, 681, 7819, 592,
+ 6534, 2021, 16478, 8737,
+ 13364, 882, 5397, 899,
+ 14656, 2178, 14741, 4227,
+ 14270, 1298, 13929, 2029,
+ 15477, 7482, 15815, 4572,
+ 2521, 2013, 5062, 1804,
+ 5159, 6582, 7130, 3597,
+ 10920, 1611, 11729, 1708,
+ 16903, 3455, 16268, 6640,
+ 9306, 1007, 9369, 2106,
+ 19182, 5037, 12441, 4269,
+ 15919, 1332, 15357, 3512,
+ 11898, 14141, 16101, 6854,
+ 2010, 737, 3779, 861,
+ 11454, 2880, 3564, 3540,
+ 9057, 1241, 12391, 896,
+ 8546, 4629, 11561, 5776,
+ 8129, 589, 8218, 588,
+ 18728, 3755, 12973, 3149,
+ 15729, 758, 16634, 754,
+ 15222, 11138, 15871, 2208,
+ 4673, 610, 10218, 678,
+ 15257, 4146, 5729, 3327,
+ 8377, 1670, 19862, 2321,
+ 15450, 5511, 14054, 5481,
+ 5728, 2888, 7580, 1346,
+ 14384, 5325, 16236, 3950,
+ 15118, 3744, 15306, 1435,
+ 14597, 4070, 12301, 15696,
+ 7617, 1699, 2170, 884,
+ 4459, 4567, 18094, 3306,
+ 12742, 815, 14926, 907,
+ 15016, 4281, 15518, 8368,
+ 17994, 1087, 2358, 865,
+ 16281, 3787, 15679, 4596,
+ 16356, 1534, 16584, 2210,
+ 16833, 9697, 15929, 4513,
+ 3277, 1085, 9643, 2187,
+ 11973, 6068, 9199, 4462,
+ 8955, 1629, 10289, 3062,
+ 16481, 5155, 15466, 7066,
+ 13678, 2543, 5273, 2277,
+ 16746, 6213, 16655, 3408,
+ 20304, 3363, 18688, 1985,
+ 14172, 12867, 15154, 15703,
+ 4473, 1020, 1681, 886,
+ 4311, 4301, 8952, 3657,
+ 5893, 1147, 11647, 1452,
+ 15886, 2227, 4582, 6644,
+ 6929, 1205, 6220, 799,
+ 12415, 3409, 15968, 3877,
+ 19859, 2109, 9689, 2141,
+ 14742, 8830, 14480, 2599,
+ 1817, 1238, 7771, 813,
+ 19079, 4410, 5554, 2064,
+ 3687, 2844, 17435, 2256,
+ 16697, 4486, 16199, 5388,
+ 8028, 2763, 3405, 2119,
+ 17426, 5477, 13698, 2786,
+ 19879, 2720, 9098, 3880,
+ 18172, 4833, 17336, 12207,
+ 5116, 996, 4935, 988,
+ 9888, 3081, 6014, 5371,
+ 15881, 1667, 8405, 1183,
+ 15087, 2366, 19777, 7002,
+ 11963, 1562, 7279, 1128,
+ 16859, 1532, 15762, 5381,
+ 14708, 2065, 20105, 2155,
+ 17158, 8245, 17911, 6318,
+ 5467, 1504, 4100, 2574,
+ 17421, 6810, 5673, 2888,
+ 16636, 3382, 8975, 1831,
+ 20159, 4737, 19550, 7294,
+ 6658, 2781, 11472, 3321,
+ 19397, 5054, 18878, 4722,
+ 16439, 2373, 20430, 4386,
+ 11353, 26526, 11593, 3068,
+ 2866, 1566, 5108, 1070,
+ 9614, 4915, 4939, 3536,
+ 7541, 878, 20717, 851,
+ 6938, 4395, 16799, 7733,
+ 10137, 1019, 9845, 964,
+ 15494, 3955, 15459, 3430,
+ 18863, 982, 20120, 963,
+ 16876, 12887, 14334, 4200,
+ 6599, 1220, 9222, 814,
+ 16942, 5134, 5661, 4898,
+ 5488, 1798, 20258, 3962,
+ 17005, 6178, 17929, 5929,
+ 9365, 3420, 7474, 1971,
+ 19537, 5177, 19003, 3006,
+ 16454, 3788, 16070, 2367,
+ 8664, 2743, 9445, 26358,
+ 10856, 1287, 3555, 1009,
+ 5606, 3622, 19453, 5512,
+ 12453, 797, 20634, 911,
+ 15427, 3066, 17037, 10275,
+ 18883, 2633, 3913, 1268,
+ 19519, 3371, 18052, 5230,
+ 19291, 1678, 19508, 3172,
+ 18072, 10754, 16625, 6845,
+ 3134, 2298, 10869, 2437,
+ 15580, 6913, 12597, 3381,
+ 11116, 3297, 16762, 2424,
+ 18853, 6715, 17171, 9887,
+ 12743, 2605, 8937, 3140,
+ 19033, 7764, 18347, 3880,
+ 20475, 3682, 19602, 3380,
+ 13044, 19373, 10526, 23124
+};
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: MR475_quant_store_results
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pred_st = pointer to structure of type gc_predState
+ p = pointer to selected quantizer table entry (const Word16)
+ gcode0 = predicted CB gain (Word16)
+ exp_gcode0 = exponent of predicted CB gain (Word16)
+ gain_pit = pointer to Pitch gain (Word16)
+ gain_cod = pointer to Code gain (Word16)
+
+ Outputs:
+ pred_st points to the updated structure of type gc_predState
+ gain_pit points to Pitch gain
+ gain_cod points to Code gain
+ pOverflow points to overflow indicator (Flag)
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function calculates the final fixed codebook gain and the predictor
+ update values, and updates the gain predictor.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ qgain475.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+static void MR475_quant_store_results(
+
+ gc_predState *pred_st, // i/o: gain predictor state struct
+ const Word16 *p, // i : pointer to selected quantizer table entry
+ Word16 gcode0, // i : predicted CB gain, Q(14 - exp_gcode0)
+ Word16 exp_gcode0, // i : exponent of predicted CB gain, Q0
+ Word16 *gain_pit, // o : Pitch gain, Q14
+ Word16 *gain_cod // o : Code gain, Q1
+)
+{
+
+ Word16 g_code, exp, frac, tmp;
+ Word32 L_tmp;
+
+ Word16 qua_ener_MR122; // o : quantized energy error, MR122 version Q10
+ Word16 qua_ener; // o : quantized energy error, Q10
+
+ // Read the quantized gains
+ *gain_pit = *p++;
+ g_code = *p++;
+
+ //------------------------------------------------------------------*
+ * calculate final fixed codebook gain: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * gc = gc0 * g *
+ *------------------------------------------------------------------
+
+ L_tmp = L_mult(g_code, gcode0);
+ L_tmp = L_shr(L_tmp, sub(10, exp_gcode0));
+ *gain_cod = extract_h(L_tmp);
+
+ //------------------------------------------------------------------*
+ * calculate predictor update values and update gain predictor: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * qua_ener = log2(g) *
+ * qua_ener_MR122 = 20*log10(g) *
+ *------------------------------------------------------------------
+
+ Log2 (L_deposit_l (g_code), &exp, &frac); // Log2(x Q12) = log2(x) + 12
+ exp = sub(exp, 12);
+
+ tmp = shr_r (frac, 5);
+ qua_ener_MR122 = add (tmp, shl (exp, 10));
+
+ L_tmp = Mpy_32_16(exp, frac, 24660); // 24660 Q12 ~= 6.0206 = 20*log10(2)
+ qua_ener = pv_round (L_shl (L_tmp, 13)); // Q12 * Q0 = Q13 -> Q10
+
+ gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void MR475_quant_store_results(
+ gc_predState *pred_st, /* i/o: gain predictor state struct */
+ const Word16 *p, /* i : pointer to selected quantizer table entry */
+ Word16 gcode0, /* i : predicted CB gain, Q(14 - exp_gcode0) */
+ Word16 exp_gcode0, /* i : exponent of predicted CB gain, Q0 */
+ Word16 *gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *gain_cod, /* o : Code gain, Q1 */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 g_code;
+ Word16 exp;
+ Word16 frac;
+ Word16 tmp;
+ Word32 L_tmp;
+
+ Word16 qua_ener_MR122; /* o : quantized energy error, MR122 version Q10 */
+ Word16 qua_ener; /* o : quantized energy error, Q10 */
+
+
+ /* Read the quantized gains */
+ *gain_pit = *p++;
+ g_code = *p++;
+
+ /*------------------------------------------------------------------*
+ * calculate final fixed codebook gain: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * gc = gc0 * g *
+ *------------------------------------------------------------------*/
+
+ L_tmp = ((Word32) g_code * gcode0) << 1;
+ tmp = 10 - exp_gcode0;
+ L_tmp = L_shr(L_tmp, tmp, pOverflow);
+ *gain_cod = (Word16)(L_tmp >> 16);
+
+ /*------------------------------------------------------------------*
+ * calculate predictor update values and update gain predictor: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * qua_ener = log2(g) *
+ * qua_ener_MR122 = 20*log10(g) *
+ *------------------------------------------------------------------*/
+
+ /* Log2(x Q12) = log2(x) + 12 */
+ Log2((Word32) g_code, &exp, &frac, pOverflow);
+ exp -= 12;
+
+ tmp = shr_r(frac, 5, pOverflow);
+ qua_ener_MR122 = exp << 10;
+ qua_ener_MR122 = tmp + qua_ener_MR122;
+
+ /* 24660 Q12 ~= 6.0206 = 20*log10(2) */
+ L_tmp = Mpy_32_16(exp, frac, 24660, pOverflow);
+ L_tmp = L_tmp << 13;
+
+ /* Q12 * Q0 = Q13 -> Q10 */
+ qua_ener = (Word16)((L_tmp + (Word32) 0x00008000L) >> 16);
+
+ gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: MR475_update_unq_pred
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pred_st = pointer to structure of type gc_predState
+ exp_gcode0 = predicted CB gain (exponent MSW) (Word16)
+ frac_gcode0 = predicted CB gain (exponent LSW) (Word16)
+ cod_gain_exp = optimum codebook gain (exponent)(Word16)
+ cod_gain_frac = optimum codebook gain (fraction) (Word16)
+
+ Outputs:
+ pred_st points to the updated structure of type gc_predState
+ pOverflow points to overflow indicator (Flag)
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This module uses the optimum codebook gain and updates the "unquantized"
+ gain predictor with the (bounded) prediction error.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ qgain475.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void
+MR475_update_unq_pred(
+ gc_predState *pred_st, // i/o: gain predictor state struct
+ Word16 exp_gcode0, // i : predicted CB gain (exponent MSW), Q0
+ Word16 frac_gcode0, // i : predicted CB gain (exponent LSW), Q15
+ Word16 cod_gain_exp, // i : optimum codebook gain (exponent), Q0
+ Word16 cod_gain_frac // i : optimum codebook gain (fraction), Q15
+)
+{
+ Word16 tmp, exp, frac;
+ Word16 qua_ener, qua_ener_MR122;
+ Word32 L_tmp;
+
+ // calculate prediction error factor (given optimum CB gain gcu):
+ // predErrFact = gcu / gcode0
+ // (limit to MIN_PRED_ERR_FACT <= predErrFact <= MAX_PRED_ERR_FACT
+ // -> limit qua_ener*)
+ //
+ // calculate prediction error (log):
+ //
+ // qua_ener_MR122 = log2(predErrFact)
+ // qua_ener = 20*log10(predErrFact)
+
+ if (cod_gain_frac <= 0)
+ {
+ // if gcu <= 0 -> predErrFact = 0 < MIN_PRED_ERR_FACT
+ // -> set qua_ener(_MR122) directly
+ qua_ener = MIN_QUA_ENER;
+ qua_ener_MR122 = MIN_QUA_ENER_MR122;
+ }
+ else
+ {
+ // convert gcode0 from DPF to standard fraction/exponent format
+ // with normalized frac, i.e. 16384 <= frac <= 32767
+ // Note: exponent correction (exp=exp-14) is done after div_s
+ frac_gcode0 = extract_l (Pow2 (14, frac_gcode0));
+
+ // make sure cod_gain_frac < frac_gcode0 for div_s
+ if (sub(cod_gain_frac, frac_gcode0) >= 0)
+ {
+ cod_gain_frac = shr (cod_gain_frac, 1);
+ cod_gain_exp = add (cod_gain_exp, 1);
+ }
+
+ // predErrFact
+ // = gcu / gcode0
+ // = cod_gain_frac/frac_gcode0 * 2^(cod_gain_exp-(exp_gcode0-14))
+ // = div_s (c_g_f, frac_gcode0)*2^-15 * 2^(c_g_e-exp_gcode0+14)
+ // = div_s * 2^(cod_gain_exp-exp_gcode0 - 1)
+
+ frac = div_s (cod_gain_frac, frac_gcode0);
+ tmp = sub (sub (cod_gain_exp, exp_gcode0), 1);
+
+ Log2 (L_deposit_l (frac), &exp, &frac);
+ exp = add (exp, tmp);
+
+ // calculate prediction error (log2, Q10)
+ qua_ener_MR122 = shr_r (frac, 5);
+ qua_ener_MR122 = add (qua_ener_MR122, shl (exp, 10));
+
+ if (sub(qua_ener_MR122, MIN_QUA_ENER_MR122) < 0)
+ {
+ qua_ener = MIN_QUA_ENER;
+ qua_ener_MR122 = MIN_QUA_ENER_MR122;
+ }
+ else if (sub(qua_ener_MR122, MAX_QUA_ENER_MR122) > 0)
+ {
+ qua_ener = MAX_QUA_ENER;
+ qua_ener_MR122 = MAX_QUA_ENER_MR122;
+ }
+ else
+ {
+ // calculate prediction error (20*log10, Q10)
+ L_tmp = Mpy_32_16(exp, frac, 24660);
+ // 24660 Q12 ~= 6.0206 = 20*log10(2)
+ qua_ener = pv_round (L_shl (L_tmp, 13));
+ // Q12 * Q0 = Q13 -> Q26 -> Q10
+ }
+ }
+
+ // update MA predictor memory
+ gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void MR475_update_unq_pred(
+ gc_predState *pred_st, /* i/o: gain predictor state struct */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent MSW), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (exponent LSW), Q15 */
+ Word16 cod_gain_exp, /* i : optimum codebook gain (exponent), Q0 */
+ Word16 cod_gain_frac, /* i : optimum codebook gain (fraction), Q15 */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 tmp;
+ Word16 exp;
+ Word16 frac;
+ Word16 qua_ener;
+ Word16 qua_ener_MR122;
+ Word32 L_tmp;
+
+ /* calculate prediction error factor (given optimum CB gain gcu):
+ *
+ * predErrFact = gcu / gcode0
+ * (limit to MIN_PRED_ERR_FACT <= predErrFact <= MAX_PRED_ERR_FACT
+ * -> limit qua_ener*)
+ *
+ * calculate prediction error (log):
+ *
+ * qua_ener_MR122 = log2(predErrFact)
+ * qua_ener = 20*log10(predErrFact)
+ *
+ */
+
+ if (cod_gain_frac <= 0)
+ {
+ /* if gcu <= 0 -> predErrFact = 0 < MIN_PRED_ERR_FACT */
+ /* -> set qua_ener(_MR122) directly */
+ qua_ener = MIN_QUA_ENER;
+ qua_ener_MR122 = MIN_QUA_ENER_MR122;
+ }
+ else
+ {
+ /* convert gcode0 from DPF to standard fraction/exponent format */
+ /* with normalized frac, i.e. 16384 <= frac <= 32767 */
+ /* Note: exponent correction (exp=exp-14) is done after div_s */
+ frac_gcode0 = (Word16)(Pow2(14, frac_gcode0, pOverflow));
+
+ /* make sure cod_gain_frac < frac_gcode0 for div_s */
+ if (cod_gain_frac >= frac_gcode0)
+ {
+ cod_gain_frac >>= 1;
+ cod_gain_exp += 1;
+ }
+
+ /*
+ predErrFact
+ = gcu / gcode0
+ = cod_gain_frac/frac_gcode0 * 2^(cod_gain_exp-(exp_gcode0-14))
+ = div_s (c_g_f, frac_gcode0)*2^-15 * 2^(c_g_e-exp_gcode0+14)
+ = div_s * 2^(cod_gain_exp-exp_gcode0 - 1)
+ */
+ frac = div_s(cod_gain_frac, frac_gcode0);
+ tmp = cod_gain_exp - exp_gcode0;
+ tmp -= 1;
+
+ Log2((Word32) frac, &exp, &frac, pOverflow);
+ exp += tmp;
+
+ /* calculate prediction error (log2, Q10) */
+ qua_ener_MR122 = shr_r(frac, 5, pOverflow);
+ tmp = exp << 10;
+ qua_ener_MR122 += tmp;
+
+ if (qua_ener_MR122 > MAX_QUA_ENER_MR122)
+ {
+ qua_ener = MAX_QUA_ENER;
+ qua_ener_MR122 = MAX_QUA_ENER_MR122;
+ }
+ else
+ {
+ /* calculate prediction error (20*log10, Q10) */
+ L_tmp = Mpy_32_16(exp, frac, 24660, pOverflow);
+ /* 24660 Q12 ~= 6.0206 = 20*log10(2) */
+ L_tmp = L_shl(L_tmp, 13, pOverflow);
+ qua_ener = pv_round(L_tmp, pOverflow);
+
+ /* Q12 * Q0 = Q13 -> Q26 -> Q10 */
+ }
+ }
+
+ /* update MA predictor memory */
+ gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
+
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: MR475_gain_quant
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ pred_st = pointer to structure of type gc_predState
+ sf0_exp_gcode0 = predicted CB gain (exponent) (Word16)
+ f0_frac_gcode0 = predicted CB gain (fraction) (Word16)
+ sf0_exp_coeff = energy coeff. (exponent part) (Word16)
+ sf0_frac_coeff = energy coeff. ((fraction part) (Word16)
+ sf0_exp_target_en = exponent of target energy (Word16)
+ sf0_frac_target_en = fraction of target energy (Word16)
+ sf1_code_nosharp = innovative codebook vector (Word16)
+ sf1_exp_gcode0 = predicted CB gain (exponent) (Word16)
+ sf1_frac_gcode0 = predicted CB gain (fraction) (Word16)
+ sf1_exp_coeff = energy coeff. (exponent part) (Word16)
+ sf1_frac_coeff = energy coeff. (fraction part) (Word16)
+ sf1_exp_target_en = exponent of target energy (Word16)
+ sf1_frac_target_en = fraction of target energy (Word16)
+ gp_limit = pitch gain limit (Word16)
+ sf0_gain_pit = pointer to Pitch gain (Word16)
+ sf0_gain_cod = pointer to Code gain (Word16)
+ sf1_gain_pit = pointer to Pitch gain (Word16)
+ sf1_gain_cod = pointer to Code gain (Word16)
+
+ Outputs:
+ pred_st points to the updated structure of type gc_predState
+ sf0_gain_pit points to Pitch gain
+ sf0_gain_cod points to Code gain
+ sf1_gain_pit points to Pitch gain
+ sf1_gain_cod points to Code gain
+
+ Returns:
+ index = index of quantization
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This module provides quantization of pitch and codebook gains for two
+ subframes using the predicted codebook gain.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ qgain475.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16
+MR475_gain_quant( // o : index of quantization.
+ gc_predState *pred_st, // i/o: gain predictor state struct
+
+ // data from subframe 0 (or 2)
+ Word16 sf0_exp_gcode0, // i : predicted CB gain (exponent), Q0
+ Word16 sf0_frac_gcode0, // i : predicted CB gain (fraction), Q15
+ Word16 sf0_exp_coeff[], // i : energy coeff. (5), exponent part, Q0
+ Word16 sf0_frac_coeff[], // i : energy coeff. (5), fraction part, Q15
+ // (frac_coeff and exp_coeff computed in
+ // calc_filt_energies())
+ Word16 sf0_exp_target_en, // i : exponent of target energy, Q0
+ Word16 sf0_frac_target_en, // i : fraction of target energy, Q15
+
+ // data from subframe 1 (or 3)
+ Word16 sf1_code_nosharp[], // i : innovative codebook vector (L_SUBFR)
+ // (whithout pitch sharpening)
+ Word16 sf1_exp_gcode0, // i : predicted CB gain (exponent), Q0
+ Word16 sf1_frac_gcode0, // i : predicted CB gain (fraction), Q15
+ Word16 sf1_exp_coeff[], // i : energy coeff. (5), exponent part, Q0
+ Word16 sf1_frac_coeff[], // i : energy coeff. (5), fraction part, Q15
+ // (frac_coeff and exp_coeff computed in
+ // calc_filt_energies())
+ Word16 sf1_exp_target_en, // i : exponent of target energy, Q0
+ Word16 sf1_frac_target_en, // i : fraction of target energy, Q15
+
+ Word16 gp_limit, // i : pitch gain limit
+
+ Word16 *sf0_gain_pit, // o : Pitch gain, Q14
+ Word16 *sf0_gain_cod, // o : Code gain, Q1
+
+ Word16 *sf1_gain_pit, // o : Pitch gain, Q14
+ Word16 *sf1_gain_cod // o : Code gain, Q1
+)
+{
+ const Word16 *p;
+ Word16 i, index = 0;
+ Word16 tmp;
+ Word16 exp;
+ Word16 sf0_gcode0, sf1_gcode0;
+ Word16 g_pitch, g2_pitch, g_code, g2_code, g_pit_cod;
+ Word16 coeff[10], coeff_lo[10], exp_max[10]; // 0..4: sf0; 5..9: sf1
+ Word32 L_tmp, dist_min;
+
+ *-------------------------------------------------------------------*
+ * predicted codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = 2^exp_gcode0 + 2^frac_gcode0 *
+ * *
+ * gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0) *
+ *-------------------------------------------------------------------*
+
+ sf0_gcode0 = extract_l(Pow2(14, sf0_frac_gcode0));
+ sf1_gcode0 = extract_l(Pow2(14, sf1_frac_gcode0));
+
+ * For each subframe, the error energy (sum) to be minimized consists
+ * of five terms, t[0..4].
+ *
+ * t[0] = gp^2 * <y1 y1>
+ * t[1] = -2*gp * <xn y1>
+ * t[2] = gc^2 * <y2 y2>
+ * t[3] = -2*gc * <xn y2>
+ * t[4] = 2*gp*gc * <y1 y2>
+ *
+
+ // sf 0
+ // determine the scaling exponent for g_code: ec = ec0 - 11
+ exp = sub(sf0_exp_gcode0, 11);
+
+ // calculate exp_max[i] = s[i]-1
+ exp_max[0] = sub(sf0_exp_coeff[0], 13);
+ exp_max[1] = sub(sf0_exp_coeff[1], 14);
+ exp_max[2] = add(sf0_exp_coeff[2], add(15, shl(exp, 1)));
+ exp_max[3] = add(sf0_exp_coeff[3], exp);
+ exp_max[4] = add(sf0_exp_coeff[4], add(1, exp));
+
+ // sf 1
+ // determine the scaling exponent for g_code: ec = ec0 - 11
+ exp = sub(sf1_exp_gcode0, 11);
+
+ // calculate exp_max[i] = s[i]-1
+ exp_max[5] = sub(sf1_exp_coeff[0], 13);
+ exp_max[6] = sub(sf1_exp_coeff[1], 14);
+ exp_max[7] = add(sf1_exp_coeff[2], add(15, shl(exp, 1)));
+ exp_max[8] = add(sf1_exp_coeff[3], exp);
+ exp_max[9] = add(sf1_exp_coeff[4], add(1, exp));
+
+ *-------------------------------------------------------------------*
+ * Gain search equalisation: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * The MSE for the two subframes is weighted differently if there *
+ * is a big difference in the corresponding target energies *
+ *-------------------------------------------------------------------*
+
+ // make the target energy exponents the same by de-normalizing the
+ // fraction of the smaller one. This is necessary to be able to compare
+ // them
+
+ exp = sf0_exp_target_en - sf1_exp_target_en;
+ if (exp > 0)
+ {
+ sf1_frac_target_en = shr (sf1_frac_target_en, exp);
+ }
+ else
+ {
+ sf0_frac_target_en = shl (sf0_frac_target_en, exp);
+ }
+
+ // assume no change of exponents
+ exp = 0;
+
+ // test for target energy difference; set exp to +1 or -1 to scale
+ // up/down coefficients for sf 1
+
+ tmp = shr_r (sf1_frac_target_en, 1); // tmp = ceil(0.5*en(sf1))
+ if (sub (tmp, sf0_frac_target_en) > 0) // tmp > en(sf0)?
+ {
+ // target_energy(sf1) > 2*target_energy(sf0)
+ // -> scale up MSE(sf0) by 2 by adding 1 to exponents 0..4
+ exp = 1;
+ }
+ else
+ {
+ tmp = shr (add (sf0_frac_target_en, 3), 2); // tmp=ceil(0.25*en(sf0))
+ if (sub (tmp, sf1_frac_target_en) > 0) // tmp > en(sf1)?
+ {
+ // target_energy(sf1) < 0.25*target_energy(sf0)
+ // -> scale down MSE(sf0) by 0.5 by subtracting 1 from
+ // coefficients 0..4
+ exp = -1;
+ }
+ }
+
+ for (i = 0; i < 5; i++)
+ {
+ exp_max[i] = add (exp_max[i], exp);
+ }
+
+ *-------------------------------------------------------------------*
+ * Find maximum exponent: *
+ * ~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * For the sum operation, all terms must have the same scaling; *
+ * that scaling should be low enough to prevent overflow. There- *
+ * fore, the maximum scale is determined and all coefficients are *
+ * re-scaled: *
+ * *
+ * exp = max(exp_max[i]) + 1; *
+ * e = exp_max[i]-exp; e <= 0! *
+ * c[i] = c[i]*2^e *
+ *-------------------------------------------------------------------*
+
+ exp = exp_max[0];
+ for (i = 1; i < 10; i++)
+ {
+ if (sub(exp_max[i], exp) > 0)
+ {
+ exp = exp_max[i];
+ }
+ }
+ exp = add(exp, 1); // To avoid overflow
+
+ p = &sf0_frac_coeff[0];
+ for (i = 0; i < 5; i++) {
+ tmp = sub(exp, exp_max[i]);
+ L_tmp = L_deposit_h(*p++);
+ L_tmp = L_shr(L_tmp, tmp);
+ L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);
+ }
+ p = &sf1_frac_coeff[0];
+ for (; i < 10; i++) {
+ tmp = sub(exp, exp_max[i]);
+ L_tmp = L_deposit_h(*p++);
+ L_tmp = L_shr(L_tmp, tmp);
+ L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);
+ }
+
+ //-------------------------------------------------------------------*
+ * Codebook search: *
+ * ~~~~~~~~~~~~~~~~ *
+ * *
+ * For each pair (g_pitch, g_fac) in the table calculate the *
+ * terms t[0..4] and sum them up; the result is the mean squared *
+ * error for the quantized gains from the table. The index for the *
+ * minimum MSE is stored and finally used to retrieve the quantized *
+ * gains *
+ *-------------------------------------------------------------------
+
+ // start with "infinite" MSE
+ dist_min = MAX_32;
+
+ p = &table_gain_MR475[0];
+
+ for (i = 0; i < MR475_VQ_SIZE; i++)
+ {
+ // subframe 0 (and 2) calculations
+ g_pitch = *p++;
+ g_code = *p++;
+
+ g_code = mult(g_code, sf0_gcode0);
+ g2_pitch = mult(g_pitch, g_pitch);
+ g2_code = mult(g_code, g_code);
+ g_pit_cod = mult(g_code, g_pitch);
+
+ L_tmp = Mpy_32_16( coeff[0], coeff_lo[0], g2_pitch);
+ L_tmp = Mac_32_16(L_tmp, coeff[1], coeff_lo[1], g_pitch);
+ L_tmp = Mac_32_16(L_tmp, coeff[2], coeff_lo[2], g2_code);
+ L_tmp = Mac_32_16(L_tmp, coeff[3], coeff_lo[3], g_code);
+ L_tmp = Mac_32_16(L_tmp, coeff[4], coeff_lo[4], g_pit_cod);
+
+ tmp = sub (g_pitch, gp_limit);
+
+ // subframe 1 (and 3) calculations
+ g_pitch = *p++;
+ g_code = *p++;
+
+ if (tmp <= 0 && sub(g_pitch, gp_limit) <= 0)
+ {
+ g_code = mult(g_code, sf1_gcode0);
+ g2_pitch = mult(g_pitch, g_pitch);
+ g2_code = mult(g_code, g_code);
+ g_pit_cod = mult(g_code, g_pitch);
+
+ L_tmp = Mac_32_16(L_tmp, coeff[5], coeff_lo[5], g2_pitch);
+ L_tmp = Mac_32_16(L_tmp, coeff[6], coeff_lo[6], g_pitch);
+ L_tmp = Mac_32_16(L_tmp, coeff[7], coeff_lo[7], g2_code);
+ L_tmp = Mac_32_16(L_tmp, coeff[8], coeff_lo[8], g_code);
+ L_tmp = Mac_32_16(L_tmp, coeff[9], coeff_lo[9], g_pit_cod);
+
+ // store table index if MSE for this index is lower
+ than the minimum MSE seen so far
+ if (L_sub(L_tmp, dist_min) < (Word32) 0)
+ {
+ dist_min = L_tmp;
+ index = i;
+ }
+ }
+ }
+
+ *------------------------------------------------------------------*
+ * read quantized gains and update MA predictor memories *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ *------------------------------------------------------------------*
+
+ // for subframe 0, the pre-calculated gcode0/exp_gcode0 are the same
+ // as those calculated from the "real" predictor using quantized gains
+ tmp = shl(index, 2);
+ MR475_quant_store_results(pred_st,
+ &table_gain_MR475[tmp],
+ sf0_gcode0,
+ sf0_exp_gcode0,
+ sf0_gain_pit,
+ sf0_gain_cod);
+
+ // calculate new predicted gain for subframe 1 (this time using
+ // the real, quantized gains)
+ gc_pred(pred_st, MR475, sf1_code_nosharp,
+ &sf1_exp_gcode0, &sf1_frac_gcode0,
+ &sf0_exp_gcode0, &sf0_gcode0); // last two args are unused
+ sf1_gcode0 = extract_l(Pow2(14, sf1_frac_gcode0));
+
+ tmp = add (tmp, 2);
+ MR475_quant_store_results(pred_st,
+ &table_gain_MR475[tmp],
+ sf1_gcode0,
+ sf1_exp_gcode0,
+ sf1_gain_pit,
+ sf1_gain_cod);
+
+ return index;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 MR475_gain_quant( /* o : index of quantization. */
+ gc_predState *pred_st, /* i/o: gain predictor state struct */
+
+ /* data from subframe 0 (or 2) */
+ Word16 sf0_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 sf0_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 sf0_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
+ Word16 sf0_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
+ /* (frac_coeff and exp_coeff computed in */
+ /* calc_filt_energies()) */
+ Word16 sf0_exp_target_en, /* i : exponent of target energy, Q0 */
+ Word16 sf0_frac_target_en, /* i : fraction of target energy, Q15 */
+
+ /* data from subframe 1 (or 3) */
+ Word16 sf1_code_nosharp[], /* i : innovative codebook vector (L_SUBFR) */
+ /* (whithout pitch sharpening) */
+ Word16 sf1_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 sf1_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 sf1_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
+ Word16 sf1_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
+ /* (frac_coeff and exp_coeff computed in */
+ /* calc_filt_energies()) */
+ Word16 sf1_exp_target_en, /* i : exponent of target energy, Q0 */
+ Word16 sf1_frac_target_en, /* i : fraction of target energy, Q15 */
+
+ Word16 gp_limit, /* i : pitch gain limit */
+
+ Word16 *sf0_gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *sf0_gain_cod, /* o : Code gain, Q1 */
+
+ Word16 *sf1_gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *sf1_gain_cod, /* o : Code gain, Q1 */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ const Word16 *p;
+ Word16 i;
+ Word16 index = 0;
+ Word16 tmp;
+ Word16 exp;
+ Word16 sf0_gcode0;
+ Word16 sf1_gcode0;
+ Word16 g_pitch;
+ Word16 g2_pitch;
+ Word16 g_code;
+ Word16 g2_code;
+ Word16 g_pit_cod;
+ Word16 coeff[10];
+ Word16 coeff_lo[10];
+ Word16 exp_max[10]; /* 0..4: sf0; 5..9: sf1 */
+ Word32 L_tmp;
+ Word32 dist_min;
+
+ /*-------------------------------------------------------------------*
+ * predicted codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = 2^exp_gcode0 + 2^frac_gcode0 *
+ * *
+ * gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0) *
+ *-------------------------------------------------------------------*/
+
+ sf0_gcode0 = (Word16)(Pow2(14, sf0_frac_gcode0, pOverflow));
+ sf1_gcode0 = (Word16)(Pow2(14, sf1_frac_gcode0, pOverflow));
+
+ /*
+ * For each subframe, the error energy (sum) to be minimized consists
+ * of five terms, t[0..4].
+ *
+ * t[0] = gp^2 * <y1 y1>
+ * t[1] = -2*gp * <xn y1>
+ * t[2] = gc^2 * <y2 y2>
+ * t[3] = -2*gc * <xn y2>
+ * t[4] = 2*gp*gc * <y1 y2>
+ *
+ */
+
+ /* sf 0 */
+ /* determine the scaling exponent for g_code: ec = ec0 - 11 */
+ exp = sf0_exp_gcode0 - 11;
+
+ /* calculate exp_max[i] = s[i]-1 */
+ exp_max[0] = (sf0_exp_coeff[0] - 13);
+ exp_max[1] = (sf0_exp_coeff[1] - 14);
+ exp_max[2] = (sf0_exp_coeff[2] + (15 + (exp << 1)));
+ exp_max[3] = (sf0_exp_coeff[3] + exp);
+ exp_max[4] = (sf0_exp_coeff[4] + (1 + exp));
+
+ /* sf 1 */
+ /* determine the scaling exponent for g_code: ec = ec0 - 11 */
+ exp = sf1_exp_gcode0 - 11;
+
+ /* calculate exp_max[i] = s[i]-1 */
+ exp_max[5] = (sf1_exp_coeff[0] - 13);
+ exp_max[6] = (sf1_exp_coeff[1] - 14);
+ exp_max[7] = (sf1_exp_coeff[2] + (15 + (exp << 1)));
+ exp_max[8] = (sf1_exp_coeff[3] + exp);
+ exp_max[9] = (sf1_exp_coeff[4] + (1 + exp));
+
+ /*-------------------------------------------------------------------*
+ * Gain search equalisation: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * The MSE for the two subframes is weighted differently if there *
+ * is a big difference in the corresponding target energies *
+ *-------------------------------------------------------------------*/
+
+ /* make the target energy exponents the same by de-normalizing the
+ fraction of the smaller one. This is necessary to be able to compare
+ them
+ */
+ exp = sf0_exp_target_en - sf1_exp_target_en;
+ if (exp > 0)
+ {
+ sf1_frac_target_en >>= exp;
+ }
+ else
+ {
+ sf0_frac_target_en >>= (-exp);
+ }
+
+ /* assume no change of exponents */
+ exp = 0;
+
+ /* test for target energy difference; set exp to +1 or -1 to scale
+ * up/down coefficients for sf 1
+ */
+ tmp = shr_r(sf1_frac_target_en, 1, pOverflow); /* tmp = ceil(0.5*en(sf1)) */
+
+ if (tmp > sf0_frac_target_en) /* tmp > en(sf0)? */
+ {
+ /*
+ * target_energy(sf1) > 2*target_energy(sf0)
+ * -> scale up MSE(sf0) by 2 by adding 1 to exponents 0..4
+ */
+ exp = 1;
+ }
+ else
+ {
+ tmp = ((sf0_frac_target_en + 3) >> 2); /* tmp=ceil(0.25*en(sf0)) */
+
+ if (tmp > sf1_frac_target_en) /* tmp > en(sf1)? */
+ {
+ /*
+ * target_energy(sf1) < 0.25*target_energy(sf0)
+ * -> scale down MSE(sf0) by 0.5 by subtracting 1 from
+ * coefficients 0..4
+ */
+ exp = -1;
+ }
+ }
+
+ for (i = 0; i < 5; i++)
+ {
+ exp_max[i] += exp;
+ }
+
+ /*-------------------------------------------------------------------*
+ * Find maximum exponent: *
+ * ~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * For the sum operation, all terms must have the same scaling; *
+ * that scaling should be low enough to prevent overflow. There- *
+ * fore, the maximum scale is determined and all coefficients are *
+ * re-scaled: *
+ * *
+ * exp = max(exp_max[i]) + 1; *
+ * e = exp_max[i]-exp; e <= 0! *
+ * c[i] = c[i]*2^e *
+ *-------------------------------------------------------------------*/
+
+ exp = exp_max[0];
+ for (i = 9; i > 0; i--)
+ {
+ if (exp_max[i] > exp)
+ {
+ exp = exp_max[i];
+ }
+ }
+ exp++; /* To avoid overflow */
+
+ p = &sf0_frac_coeff[0];
+ for (i = 0; i < 5; i++)
+ {
+ tmp = (exp - exp_max[i]);
+ L_tmp = ((Word32)(*p++) << 16);
+ L_tmp = L_shr(L_tmp, tmp, pOverflow);
+ coeff[i] = (Word16)(L_tmp >> 16);
+ coeff_lo[i] = (Word16)((L_tmp >> 1) - ((L_tmp >> 16) << 15));
+ }
+ p = &sf1_frac_coeff[0];
+ for (; i < 10; i++)
+ {
+ tmp = exp - exp_max[i];
+ L_tmp = ((Word32)(*p++) << 16);
+ L_tmp = L_shr(L_tmp, tmp, pOverflow);
+ coeff[i] = (Word16)(L_tmp >> 16);
+ coeff_lo[i] = (Word16)((L_tmp >> 1) - ((L_tmp >> 16) << 15));
+ }
+
+
+ /*-------------------------------------------------------------------*
+ * Codebook search: *
+ * ~~~~~~~~~~~~~~~~ *
+ * *
+ * For each pair (g_pitch, g_fac) in the table calculate the *
+ * terms t[0..4] and sum them up; the result is the mean squared *
+ * error for the quantized gains from the table. The index for the *
+ * minimum MSE is stored and finally used to retrieve the quantized *
+ * gains *
+ *-------------------------------------------------------------------*/
+
+ /* start with "infinite" MSE */
+ dist_min = MAX_32;
+
+ p = &table_gain_MR475[0];
+
+ for (i = 0; i < MR475_VQ_SIZE; i++)
+ {
+ /* subframe 0 (and 2) calculations */
+ g_pitch = *p++;
+ g_code = *p++;
+
+ /* Need to be there OKA */
+ g_code = (Word16)(((Word32) g_code * sf0_gcode0) >> 15);
+ g2_pitch = (Word16)(((Word32) g_pitch * g_pitch) >> 15);
+ g2_code = (Word16)(((Word32) g_code * g_code) >> 15);
+ g_pit_cod = (Word16)(((Word32) g_code * g_pitch) >> 15);
+
+
+ L_tmp = Mpy_32_16(coeff[0], coeff_lo[0], g2_pitch, pOverflow) +
+ Mpy_32_16(coeff[1], coeff_lo[1], g_pitch, pOverflow) +
+ Mpy_32_16(coeff[2], coeff_lo[2], g2_code, pOverflow) +
+ Mpy_32_16(coeff[3], coeff_lo[3], g_code, pOverflow) +
+ Mpy_32_16(coeff[4], coeff_lo[4], g_pit_cod, pOverflow);
+
+ tmp = (g_pitch - gp_limit);
+
+ /* subframe 1 (and 3) calculations */
+ g_pitch = *p++;
+ g_code = *p++;
+
+ if ((tmp <= 0) && (g_pitch <= gp_limit))
+ {
+ g_code = (Word16)(((Word32) g_code * sf1_gcode0) >> 15);
+ g2_pitch = (Word16)(((Word32) g_pitch * g_pitch) >> 15);
+ g2_code = (Word16)(((Word32) g_code * g_code) >> 15);
+ g_pit_cod = (Word16)(((Word32) g_code * g_pitch) >> 15);
+
+ L_tmp += (Mpy_32_16(coeff[5], coeff_lo[5], g2_pitch, pOverflow) +
+ Mpy_32_16(coeff[6], coeff_lo[6], g_pitch, pOverflow) +
+ Mpy_32_16(coeff[7], coeff_lo[7], g2_code, pOverflow) +
+ Mpy_32_16(coeff[8], coeff_lo[8], g_code, pOverflow) +
+ Mpy_32_16(coeff[9], coeff_lo[9], g_pit_cod, pOverflow));
+
+ /* store table index if MSE for this index is lower
+ than the minimum MSE seen so far */
+ if (L_tmp < dist_min)
+ {
+ dist_min = L_tmp;
+ index = i;
+ }
+ }
+ }
+
+ /*------------------------------------------------------------------*
+ * read quantized gains and update MA predictor memories *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ *------------------------------------------------------------------*/
+
+ /* for subframe 0, the pre-calculated gcode0/exp_gcode0 are the same
+ as those calculated from the "real" predictor using quantized gains */
+ tmp = index << 2;
+ MR475_quant_store_results(pred_st,
+ &table_gain_MR475[tmp],
+ sf0_gcode0,
+ sf0_exp_gcode0,
+ sf0_gain_pit,
+ sf0_gain_cod,
+ pOverflow);
+
+ /* calculate new predicted gain for subframe 1 (this time using
+ the real, quantized gains) */
+ gc_pred(pred_st, MR475, sf1_code_nosharp,
+ &sf1_exp_gcode0, &sf1_frac_gcode0,
+ &sf0_exp_gcode0, &sf0_gcode0, /* unused args */
+ pOverflow);
+
+ sf1_gcode0 = (Word16)(Pow2(14, sf1_frac_gcode0, pOverflow));
+
+ tmp += 2;
+ MR475_quant_store_results(
+ pred_st,
+ &table_gain_MR475[tmp],
+ sf1_gcode0,
+ sf1_exp_gcode0,
+ sf1_gain_pit,
+ sf1_gain_cod,
+ pOverflow);
+
+ return(index);
+}
diff --git a/media/codecs/amrnb/enc/src/qgain475.h b/media/codecs/amrnb/enc/src/qgain475.h
new file mode 100644
index 0000000..3f1f03f
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/qgain475.h
@@ -0,0 +1,180 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/include/qgain475.h
+
+ Date: 01/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template and copied #defines from qgain475.c file.
+
+ Description: Changed to include pOverflow as a function parameter for all
+ functions in qgain475.c
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the defines and function prototypes used in the
+ quantization of pitch and codebook gains for MR475.
+
+------------------------------------------------------------------------------
+*/
+#ifndef _QGAIN475_H_
+#define _QGAIN475_H_
+#define qgain475_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "gc_pred.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+ /* minimum allowed gain code prediction error: 102.887/4096 = 0.0251189 */
+#define MIN_QUA_ENER ( -5443) /* Q10 <-> log2 (0.0251189) */
+#define MIN_QUA_ENER_MR122 (-32768) /* Q10 <-> 20*log10(0.0251189) */
+
+ /* minimum allowed gain code prediction error: 32000/4096 = 7.8125 */
+#define MAX_QUA_ENER ( 3037) /* Q10 <-> log2 (7.8125) */
+#define MAX_QUA_ENER_MR122 ( 18284) /* Q10 <-> 20*log10(7.8125) */
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+
+ /*************************************************************************
+ *
+ * FUNCTION: MR475_update_unq_pred()
+ *
+ * PURPOSE: use optimum codebook gain and update "unquantized"
+ * gain predictor with the (bounded) prediction error
+ *
+ *************************************************************************/
+ void
+ MR475_update_unq_pred(
+ gc_predState *pred_st, /* i/o: gain predictor state struct */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 cod_gain_exp, /* i : optimum codebook gain (exponent), Q0 */
+ Word16 cod_gain_frac, /* i : optimum codebook gain (fraction), Q15 */
+ Flag *pOverflow /* o : overflow indicator */
+ );
+
+ /*************************************************************************
+ *
+ * FUNCTION: MR475_gain_quant()
+ *
+ * PURPOSE: Quantization of pitch and codebook gains for two subframes
+ * (using predicted codebook gain)
+ *
+ *************************************************************************/
+
+ Word16
+ MR475_gain_quant( /* o : index of quantization. */
+ gc_predState *pred_st, /* i/o: gain predictor state struct */
+
+ /* data from subframe 0 (or 2) */
+ Word16 sf0_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 sf0_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 sf0_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
+ Word16 sf0_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
+ /* (frac_coeff and exp_coeff computed in */
+ /* calc_filt_energies()) */
+ Word16 sf0_exp_target_en, /* i : exponent of target energy, Q0 */
+ Word16 sf0_frac_target_en, /* i : fraction of target energy, Q15 */
+
+ /* data from subframe 1 (or 3) */
+ Word16 sf1_code_nosharp[], /* i : innovative codebook vector (L_SUBFR) */
+ /* (whithout pitch sharpening) */
+ Word16 sf1_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 sf1_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 sf1_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
+ Word16 sf1_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
+ /* (frac_coeff and exp_coeff computed in */
+ /* calc_filt_energies()) */
+ Word16 sf1_exp_target_en, /* i : exponent of target energy, Q0 */
+ Word16 sf1_frac_target_en, /* i : fraction of target energy, Q15 */
+
+ Word16 gp_limit, /* i : pitch gain limit */
+
+ Word16 *sf0_gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *sf0_gain_cod, /* o : Code gain, Q1 */
+
+ Word16 *sf1_gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *sf1_gain_cod, /* o : Code gain, Q1 */
+ Flag *pOverflow /* o : overflow indicator */
+ );
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _QGAIN475_H_ */
diff --git a/media/codecs/amrnb/enc/src/qgain795.cpp b/media/codecs/amrnb/enc/src/qgain795.cpp
new file mode 100644
index 0000000..d09fbe3
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/qgain795.cpp
@@ -0,0 +1,904 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/qgain795.c
+ Functions: MR795_gain_code_quant3
+ MR795_gain_code_quant_mod
+ MR795_gain_quant
+
+ Date: 02/04/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description:
+ (1) Removed optimization -- mult(i, 3, pOverflow) is NOT the same as adding
+ i to itself 3 times. The reason is because the mult function does a
+ right shift by 15, which will obliterate smaller numbers.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "qgain795.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "log2.h"
+#include "pow2.h"
+#include "sqrt_l.h"
+#include "g_adapt.h"
+#include "calc_en.h"
+#include "q_gain_p.h"
+
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+#define NB_QUA_CODE 32
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 qua_gain_code[NB_QUA_CODE*3];
+
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: MR795_gain_code_quant3
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ exp_gcode0 -- Word16 -- predicted CB gain (exponent), Q0
+ gcode0 -- Word16 -- predicted CB gain (norm.)
+ g_pitch_cand[] -- Word16 array -- Pitch gain candidates (3), Q14
+ g_pitch_cind[] -- Word16 array -- Pitch gain cand. indices (3), Q0
+ frac_coeff[] -- Word16 array -- coefficients (5), Q15
+ exp_coeff[] -- Word16 array -- energy coefficients (5), Q0
+ coefficients from calc_filt_ener()
+
+ Outputs:
+ gain_pit -- Pointer to Word16 -- Pitch gain, Q14
+ gain_pit_ind -- Pointer to Word16 -- Pitch gain index, Q0
+ gain_cod -- Pointer to Word16 -- Code gain, Q1
+ gain_cod_ind -- Pointer to Word16 -- Code gain index, Q0
+ qua_ener_MR122 -- Pointer to Word16 -- quantized energy error, Q10
+ (for MR122 MA predictor update)
+
+ qua_ener -- Pointer to Word16 -- quantized energy error, Q10
+ (for other MA predictor update)
+
+ pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Pre-quantization of codebook gains, given three possible
+ LTP gains (using predicted codebook gain)
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ qgain795.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static void
+MR795_gain_code_quant3(
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 gcode0, /* i : predicted CB gain (norm.), Q14 */
+ Word16 g_pitch_cand[], /* i : Pitch gain candidates (3), Q14 */
+ Word16 g_pitch_cind[], /* i : Pitch gain cand. indices (3), Q0 */
+ Word16 frac_coeff[], /* i : coefficients (5), Q15 */
+ Word16 exp_coeff[], /* i : energy coefficients (5), Q0 */
+ /* coefficients from calc_filt_ener()*/
+ Word16 *gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *gain_pit_ind, /* o : Pitch gain index, Q0 */
+ Word16 *gain_cod, /* o : Code gain, Q1 */
+ Word16 *gain_cod_ind, /* o : Code gain index, Q0 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ const Word16 *p;
+ Word16 i;
+ Word16 j;
+ Word16 cod_ind;
+ Word16 pit_ind;
+ Word16 e_max;
+ Word16 exp_code;
+ Word16 g_pitch;
+ Word16 g2_pitch;
+ Word16 g_code;
+ Word16 g2_code_h;
+ Word16 g2_code_l;
+ Word16 g_pit_cod_h;
+ Word16 g_pit_cod_l;
+ Word16 coeff[5];
+ Word16 coeff_lo[5];
+ Word16 exp_max[5];
+ Word32 L_tmp;
+ Word32 L_tmp0;
+ Word32 dist_min;
+
+ /*
+ * The error energy (sum) to be minimized consists of five terms, t[0..4].
+ *
+ * t[0] = gp^2 * <y1 y1>
+ * t[1] = -2*gp * <xn y1>
+ * t[2] = gc^2 * <y2 y2>
+ * t[3] = -2*gc * <xn y2>
+ * t[4] = 2*gp*gc * <y1 y2>
+ *
+ */
+
+ /* determine the scaling exponent for g_code: ec = ec0 - 10 */
+ exp_code = sub(exp_gcode0, 10, pOverflow);
+
+ /* calculate exp_max[i] = s[i]-1 */
+ exp_max[0] = sub(exp_coeff[0], 13, pOverflow);
+ exp_max[1] = sub(exp_coeff[1], 14, pOverflow);
+ exp_max[2] = add(exp_coeff[2], add(15, shl(exp_code, 1, pOverflow), pOverflow), pOverflow);
+ exp_max[3] = add(exp_coeff[3], exp_code, pOverflow);
+ exp_max[4] = add(exp_coeff[4], add(exp_code, 1, pOverflow), pOverflow);
+
+
+ /*-------------------------------------------------------------------*
+ * Find maximum exponent: *
+ * ~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * For the sum operation, all terms must have the same scaling; *
+ * that scaling should be low enough to prevent overflow. There- *
+ * fore, the maximum scale is determined and all coefficients are *
+ * re-scaled: *
+ * *
+ * e_max = max(exp_max[i]) + 1; *
+ * e = exp_max[i]-e_max; e <= 0! *
+ * c[i] = c[i]*2^e *
+ *-------------------------------------------------------------------*/
+
+ e_max = exp_max[0];
+ for (i = 1; i < 5; i++) /* implemented flattened */
+ {
+ if (exp_max[i] > e_max)
+ {
+ e_max = exp_max[i];
+ }
+ }
+
+ e_max = add(e_max, 1, pOverflow); /* To avoid overflow */
+
+ for (i = 0; i < 5; i++)
+ {
+ j = sub(e_max, exp_max[i], pOverflow);
+ L_tmp = L_deposit_h(frac_coeff[i]);
+ L_tmp = L_shr(L_tmp, j, pOverflow);
+ L_Extract(L_tmp, &coeff[i], &coeff_lo[i], pOverflow);
+ }
+
+
+ /*-------------------------------------------------------------------*
+ * Codebook search: *
+ * ~~~~~~~~~~~~~~~~ *
+ * *
+ * For each of the candiates LTP gains in g_pitch_cand[], the terms *
+ * t[0..4] are calculated from the values in the table (and the *
+ * pitch gain candidate) and summed up; the result is the mean *
+ * squared error for the LPT/CB gain pair. The index for the mini- *
+ * mum MSE is stored and finally used to retrieve the quantized CB *
+ * gain *
+ *-------------------------------------------------------------------*/
+
+ /* start with "infinite" MSE */
+ dist_min = MAX_32;
+ cod_ind = 0;
+ pit_ind = 0;
+
+ /* loop through LTP gain candidates */
+ for (j = 0; j < 3; j++)
+ {
+ /* pre-calculate terms only dependent on pitch gain */
+ g_pitch = g_pitch_cand[j];
+ g2_pitch = mult(g_pitch, g_pitch, pOverflow);
+ L_tmp0 = Mpy_32_16(coeff[0], coeff_lo[0], g2_pitch, pOverflow);
+ L_tmp0 = Mac_32_16(L_tmp0, coeff[1], coeff_lo[1], g_pitch, pOverflow);
+
+ p = &qua_gain_code[0];
+ for (i = 0; i < NB_QUA_CODE; i++)
+ {
+ g_code = *p++; /* this is g_fac Q11 */
+ p++; /* skip log2(g_fac) */
+ p++; /* skip 20*log10(g_fac) */
+
+ g_code = mult(g_code, gcode0, pOverflow);
+
+ L_tmp = L_mult(g_code, g_code, pOverflow);
+ L_Extract(L_tmp, &g2_code_h, &g2_code_l, pOverflow);
+
+ L_tmp = L_mult(g_code, g_pitch, pOverflow);
+ L_Extract(L_tmp, &g_pit_cod_h, &g_pit_cod_l, pOverflow);
+
+ L_tmp = Mac_32(L_tmp0, coeff[2], coeff_lo[2],
+ g2_code_h, g2_code_l, pOverflow);
+ L_tmp = Mac_32_16(L_tmp, coeff[3], coeff_lo[3],
+ g_code, pOverflow);
+ L_tmp = Mac_32(L_tmp, coeff[4], coeff_lo[4],
+ g_pit_cod_h, g_pit_cod_l, pOverflow);
+
+ /* store table index if MSE for this index is lower
+ than the minimum MSE seen so far; also store the
+ pitch gain for this (so far) lowest MSE */
+ if (L_tmp < dist_min)
+ {
+ dist_min = L_tmp;
+ cod_ind = i;
+ pit_ind = j;
+ }
+ }
+ }
+
+ /*------------------------------------------------------------------*
+ * read quantized gains and new values for MA predictor memories *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ *------------------------------------------------------------------*/
+
+ /* Read the quantized gains */
+ p = &qua_gain_code[
+ add(add(cod_ind, cod_ind, pOverflow), cod_ind, pOverflow)];
+
+ g_code = *p++;
+ *qua_ener_MR122 = *p++;
+ *qua_ener = *p;
+
+ /*------------------------------------------------------------------*
+ * calculate final fixed codebook gain: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * gc = gc0 * g *
+ *------------------------------------------------------------------*/
+
+ L_tmp = L_mult(g_code, gcode0, pOverflow);
+ L_tmp = L_shr(L_tmp, sub(9, exp_gcode0, pOverflow), pOverflow);
+ *gain_cod = extract_h(L_tmp);
+ *gain_cod_ind = cod_ind;
+ *gain_pit = g_pitch_cand[pit_ind];
+ *gain_pit_ind = g_pitch_cind[pit_ind];
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: MR795_gain_code_quant_mod
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ gain_pit -- Word16 -- pitch gain, Q14
+ exp_gcode0 -- Word16 -- predicted CB gain (exponent), Q0
+ gcode0 -- Word16 -- predicted CB gain (norm.), Q14
+ frac_en[] -- Word16 array -- energy coefficients (4), fraction part, Q15
+ exp_en[] -- Word16 array -- energy coefficients (4), exponent part, Q0
+ alpha -- Word16 -- gain adaptor factor (>0), Q15
+
+ gain_cod_unq -- Word16 -- Code gain (unquantized)
+ (scaling: Q10 - exp_gcode0)
+
+ gain_cod -- Pointer to Word16 -- Code gain (pre-/quantized), Q1
+
+ Outputs:
+ qua_ener_MR122 -- Pointer to Word16 -- quantized energy error, Q10
+ (for MR122 MA predictor update)
+ qua_ener -- Pointer to Word16 -- quantized energy error, Q10
+ (for other MA predictor update)
+ pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ index of quantization (Word16)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ PURPOSE: Modified quantization of the MR795 codebook gain
+
+ Uses pre-computed energy coefficients in frac_en[]/exp_en[]
+
+ frac_en[0]*2^exp_en[0] = <res res> // LP residual energy
+ frac_en[1]*2^exp_en[1] = <exc exc> // LTP residual energy
+ frac_en[2]*2^exp_en[2] = <exc code> // LTP/CB innovation dot product
+ frac_en[3]*2^exp_en[3] = <code code> // CB innovation energy
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ qgain795.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+static Word16
+MR795_gain_code_quant_mod( /* o : index of quantization. */
+ Word16 gain_pit, /* i : pitch gain, Q14 */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 gcode0, /* i : predicted CB gain (norm.), Q14 */
+ Word16 frac_en[], /* i : energy coefficients (4),
+ fraction part, Q15 */
+ Word16 exp_en[], /* i : energy coefficients (4),
+ eponent part, Q0 */
+ Word16 alpha, /* i : gain adaptor factor (>0), Q15 */
+ Word16 gain_cod_unq, /* i : Code gain (unquantized) */
+ /* (scaling: Q10 - exp_gcode0) */
+ Word16 *gain_cod, /* i/o: Code gain (pre-/quantized), Q1 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ const Word16 *p;
+ Word16 i;
+ Word16 index;
+ Word16 tmp;
+ Word16 one_alpha;
+ Word16 exp;
+ Word16 e_max;
+
+ Word16 g2_pitch;
+ Word16 g_code;
+ Word16 g2_code_h;
+ Word16 g2_code_l;
+ Word16 d2_code_h;
+ Word16 d2_code_l;
+ Word16 coeff[5];
+ Word16 coeff_lo[5];
+ Word16 exp_coeff[5];
+ Word32 L_tmp;
+ Word32 L_t0;
+ Word32 L_t1;
+ Word32 dist_min;
+ Word16 gain_code;
+
+ /*
+ Steps in calculation of the error criterion (dist):
+ ---------------------------------------------------
+
+ underlined = constant; alp = FLP value of alpha, alpha = FIP
+ ----------
+
+
+ ExEn = gp^2 * LtpEn + 2.0*gp*gc[i] * XC + gc[i]^2 * InnEn;
+ ------------ ------ -- -----
+
+ aExEn= alp * ExEn
+ = alp*gp^2*LtpEn + 2.0*alp*gp*XC* gc[i] + alp*InnEn* gc[i]^2
+ -------------- ------------- ---------
+
+ = t[1] + t[2] + t[3]
+
+ dist = d1 + d2;
+
+ d1 = (1.0 - alp) * InnEn * (gcu - gc[i])^2 = t[4]
+ ------------------- ---
+
+ d2 = alp * (ResEn - 2.0 * sqrt(ResEn*ExEn) + ExEn);
+ --- ----- --- -----
+
+ = alp * (sqrt(ExEn) - sqrt(ResEn))^2
+ --- -----------
+
+ = (sqrt(aExEn) - sqrt(alp*ResEn))^2
+ ---------------
+
+ = (sqrt(aExEn) - t[0] )^2
+ ----
+
+ */
+
+ /*
+ * calculate scalings of the constant terms
+ */
+ gain_code = shl(*gain_cod, sub(10, exp_gcode0, pOverflow), pOverflow); /* Q1 -> Q11 (-ec0) */
+ g2_pitch = mult(gain_pit, gain_pit, pOverflow); /* Q14 -> Q13 */
+ /* 0 < alpha <= 0.5 => 0.5 <= 1-alpha < 1, i.e one_alpha is normalized */
+ one_alpha = add(sub(32767, alpha, pOverflow), 1, pOverflow); /* 32768 - alpha */
+
+
+ /* alpha <= 0.5 -> mult. by 2 to keep precision; compensate in exponent */
+ L_t1 = L_mult(alpha, frac_en[1], pOverflow);
+ L_t1 = L_shl(L_t1, 1, pOverflow);
+ tmp = extract_h(L_t1);
+
+ /* directly store in 32 bit variable because no further mult. required */
+ L_t1 = L_mult(tmp, g2_pitch, pOverflow);
+ exp_coeff[1] = sub(exp_en[1], 15, pOverflow);
+
+
+ tmp = extract_h(L_shl(L_mult(alpha, frac_en[2], pOverflow), 1, pOverflow));
+ coeff[2] = mult(tmp, gain_pit, pOverflow);
+ exp = sub(exp_gcode0, 10, pOverflow);
+ exp_coeff[2] = add(exp_en[2], exp, pOverflow);
+
+
+ /* alpha <= 0.5 -> mult. by 2 to keep precision; compensate in exponent */
+ coeff[3] = extract_h(L_shl(L_mult(alpha, frac_en[3], pOverflow), 1, pOverflow));
+ exp = sub(shl(exp_gcode0, 1, pOverflow), 7, pOverflow);
+ exp_coeff[3] = add(exp_en[3], exp, pOverflow);
+
+
+ coeff[4] = mult(one_alpha, frac_en[3], pOverflow);
+ exp_coeff[4] = add(exp_coeff[3], 1, pOverflow);
+
+
+ L_tmp = L_mult(alpha, frac_en[0], pOverflow);
+ /* sqrt_l returns normalized value and 2*exponent
+ -> result = val >> (exp/2)
+ exp_coeff holds 2*exponent for c[0] */
+ /* directly store in 32 bit variable because no further mult. required */
+ L_t0 = sqrt_l_exp(L_tmp, &exp, pOverflow); /* normalization included in sqrt_l_exp */
+ exp = add(exp, 47, pOverflow);
+ exp_coeff[0] = sub(exp_en[0], exp, pOverflow);
+
+ /*
+ * Determine the maximum exponent occuring in the distance calculation
+ * and adjust all fractions accordingly (including a safety margin)
+ *
+ */
+
+ /* find max(e[1..4],e[0]+31) */
+ e_max = add(exp_coeff[0], 31, pOverflow);
+ for (i = 1; i <= 4; i++)
+ {
+ if (exp_coeff[i] > e_max)
+ {
+ e_max = exp_coeff[i];
+ }
+ }
+
+ /* scale c[1] (requires no further multiplication) */
+ tmp = sub(e_max, exp_coeff[1], pOverflow);
+ L_t1 = L_shr(L_t1, tmp, pOverflow);
+
+ /* scale c[2..4] (used in Mpy_32_16 in the quantizer loop) */
+ for (i = 2; i <= 4; i++)
+ {
+ tmp = sub(e_max, exp_coeff[i], pOverflow);
+ L_tmp = L_deposit_h(coeff[i]);
+ L_tmp = L_shr(L_tmp, tmp, pOverflow);
+ L_Extract(L_tmp, &coeff[i], &coeff_lo[i], pOverflow);
+ }
+
+ /* scale c[0] (requires no further multiplication) */
+ exp = sub(e_max, 31, pOverflow); /* new exponent */
+ tmp = sub(exp, exp_coeff[0], pOverflow);
+ L_t0 = L_shr(L_t0, shr(tmp, 1, pOverflow), pOverflow);
+ /* perform correction by 1/sqrt(2) if exponent difference is odd */
+ if ((tmp & 0x1) != 0)
+ {
+ L_Extract(L_t0, &coeff[0], &coeff_lo[0], pOverflow);
+ L_t0 = Mpy_32_16(coeff[0], coeff_lo[0],
+ 23170, pOverflow); /* 23170 Q15 = 1/sqrt(2)*/
+ }
+
+ /* search the quantizer table for the lowest value
+ of the search criterion */
+ dist_min = MAX_32;
+ index = 0;
+ p = &qua_gain_code[0];
+
+ for (i = 0; i < NB_QUA_CODE; i++)
+ {
+ g_code = *p++; /* this is g_fac (Q11) */
+ p++; /* skip log2(g_fac) */
+ p++; /* skip 20*log10(g_fac) */
+ g_code = mult(g_code, gcode0, pOverflow);
+
+ /* only continue if gc[i] < 2.0*gc
+ which is equiv. to g_code (Q10-ec0) < gain_code (Q11-ec0) */
+
+ if (g_code >= gain_code)
+ {
+ break;
+ }
+
+ L_tmp = L_mult(g_code, g_code, pOverflow);
+ L_Extract(L_tmp, &g2_code_h, &g2_code_l, pOverflow);
+
+ tmp = sub(g_code, gain_cod_unq, pOverflow);
+ L_tmp = L_mult(tmp, tmp, pOverflow);
+ L_Extract(L_tmp, &d2_code_h, &d2_code_l, pOverflow);
+
+ /* t2, t3, t4 */
+ L_tmp = Mac_32_16(L_t1, coeff[2], coeff_lo[2], g_code, pOverflow);
+ L_tmp = Mac_32(L_tmp, coeff[3], coeff_lo[3], g2_code_h, g2_code_l, pOverflow);
+
+ L_tmp = sqrt_l_exp(L_tmp, &exp, pOverflow);
+ L_tmp = L_shr(L_tmp, shr(exp, 1, pOverflow), pOverflow);
+
+ /* d2 */
+ tmp = pv_round(L_sub(L_tmp, L_t0, pOverflow), pOverflow);
+ L_tmp = L_mult(tmp, tmp, pOverflow);
+
+ /* dist */
+ L_tmp = Mac_32(L_tmp, coeff[4], coeff_lo[4], d2_code_h, d2_code_l, pOverflow);
+
+ /* store table index if distance measure for this
+ index is lower than the minimum seen so far */
+ if (L_tmp < dist_min)
+ {
+ dist_min = L_tmp;
+ index = i;
+ }
+ }
+
+ /*------------------------------------------------------------------*
+ * read quantized gains and new values for MA predictor memories *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ *------------------------------------------------------------------*/
+
+ /* Read the quantized gains */
+ p = &qua_gain_code[add(add(index, index, pOverflow), index, pOverflow)];
+ g_code = *p++;
+ *qua_ener_MR122 = *p++;
+ *qua_ener = *p;
+
+ /*------------------------------------------------------------------*
+ * calculate final fixed codebook gain: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * gc = gc0 * g *
+ *------------------------------------------------------------------*/
+
+ L_tmp = L_mult(g_code, gcode0, pOverflow);
+ L_tmp = L_shr(L_tmp, sub(9, exp_gcode0, pOverflow), pOverflow);
+ *gain_cod = extract_h(L_tmp);
+
+ return index;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: MR795_gain_quant
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+MR795_gain_quant(
+
+
+ Inputs:
+ adapt_st -- Pointer to GainAdaptState -- gain adapter state structure
+ res -- Word16 array -- LP residual, Q0
+ exc -- Word16 array -- LTP excitation (unfiltered), Q0
+ code -- Word16 array -- CB innovation (unfiltered), Q13
+ frac_coeff -- Word16 array -- coefficients (5), Q15
+ exp_coeff -- Word16 array -- energy coefficients (5), Q0
+ coefficients from calc_filt_ener()
+ exp_code_en -- Word16 -- innovation energy (exponent), Q0
+ frac_code_en -- Word16 -- innovation energy (fraction), Q15
+ exp_gcode0 -- Word16 -- predicted CB gain (exponent), Q0
+ frac_gcode0 -- Word16 -- predicted CB gain (fraction), Q15
+ L_subfr -- Word16 -- Subframe length
+ cod_gain_frac -- Word16 -- opt. codebook gain (fraction),Q15
+ cod_gain_exp -- Word16 -- opt. codebook gain (exponent), Q0
+ gp_limit -- Word16 -- pitch gain limit
+ gain_pit -- Pointer to Word16 -- Pitch gain, Q14
+
+ Output
+ adapt_st -- Pointer to GainAdaptState -- gain adapter state structure
+ gain_pit -- Pointer to Word16 -- Pitch gain, Q14
+
+ gain_pit -- Pointer to Word16 -- Pitch gain, Q14
+ gain_cod -- Pointer to Word16 -- Code gain, Q1
+ qua_ener_MR122 -- Pointer to Word16 -- quantized energy error, Q10
+ (for MR122 MA predictor update)
+
+ qua_ener -- Pointer to Word16 -- quantized energy error, Q10
+ (for other MA predictor update)
+
+ anap -- Double Pointer to Word16 -- Index of quantization
+ (first gain pitch, then code pitch)
+
+ pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ pitch and codebook quantization for MR795
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ qgain795.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void
+MR795_gain_quant(
+ GainAdaptState *adapt_st, /* i/o: gain adapter state structure */
+ Word16 res[], /* i : LP residual, Q0 */
+ Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
+ Word16 code[], /* i : CB innovation (unfiltered), Q13 */
+ Word16 frac_coeff[], /* i : coefficients (5), Q15 */
+ Word16 exp_coeff[], /* i : energy coefficients (5), Q0 */
+ /* coefficients from calc_filt_ener() */
+ Word16 exp_code_en, /* i : innovation energy (exponent), Q0 */
+ Word16 frac_code_en, /* i : innovation energy (fraction), Q15 */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 L_subfr, /* i : Subframe length */
+ Word16 cod_gain_frac, /* i : opt. codebook gain (fraction),Q15 */
+ Word16 cod_gain_exp, /* i : opt. codebook gain (exponent), Q0 */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *gain_pit, /* i/o: Pitch gain, Q14 */
+ Word16 *gain_cod, /* o : Code gain, Q1 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Word16 **anap, /* o : Index of quantization */
+ /* (first gain pitch, then code pitch)*/
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 frac_en[4];
+ Word16 exp_en[4];
+ Word16 ltpg, alpha, gcode0;
+ Word16 g_pitch_cand[3]; /* pitch gain candidates Q14 */
+ Word16 g_pitch_cind[3]; /* pitch gain indices Q0 */
+ Word16 gain_pit_index;
+ Word16 gain_cod_index;
+ Word16 exp;
+ Word16 gain_cod_unq; /* code gain (unq.) Q(10-exp_gcode0) */
+
+
+ /* get list of candidate quantized pitch gain values
+ * and corresponding quantization indices
+ */
+ gain_pit_index = q_gain_pitch(MR795, gp_limit, gain_pit,
+ g_pitch_cand, g_pitch_cind, pOverflow);
+
+ /*-------------------------------------------------------------------*
+ * predicted codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = 2^exp_gcode0 + 2^frac_gcode0 *
+ * *
+ * gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0) *
+ *-------------------------------------------------------------------*/
+ gcode0 = (Word16)(Pow2(14, frac_gcode0, pOverflow)); /* Q14 */
+
+ /* pre-quantization of codebook gain
+ * (using three pitch gain candidates);
+ * result: best guess of pitch gain and code gain
+ */
+ MR795_gain_code_quant3(
+ exp_gcode0, gcode0, g_pitch_cand, g_pitch_cind,
+ frac_coeff, exp_coeff,
+ gain_pit, &gain_pit_index, gain_cod, &gain_cod_index,
+ qua_ener_MR122, qua_ener, pOverflow);
+
+ /* calculation of energy coefficients and LTP coding gain */
+ calc_unfilt_energies(res, exc, code, *gain_pit, L_subfr,
+ frac_en, exp_en, <pg, pOverflow);
+
+ /* run gain adaptor, calculate alpha factor to balance LTP/CB gain
+ * (this includes the gain adaptor update)
+ * Note: ltpg = 0 if frac_en[0] == 0, so the update is OK in that case
+ */
+ gain_adapt(adapt_st, ltpg, *gain_cod, &alpha, pOverflow);
+
+ /* if this is a very low energy signal (threshold: see
+ * calc_unfilt_energies) or alpha <= 0 then don't run the modified quantizer
+ */
+ if (frac_en[0] != 0 && alpha > 0)
+ {
+ /* innovation energy <cod cod> was already computed in gc_pred() */
+ /* (this overwrites the LtpResEn which is no longer needed) */
+ frac_en[3] = frac_code_en;
+ exp_en[3] = exp_code_en;
+
+ /* store optimum codebook gain in Q(10-exp_gcode0) */
+ exp = add(sub(cod_gain_exp, exp_gcode0, pOverflow), 10, pOverflow);
+ gain_cod_unq = shl(cod_gain_frac, exp, pOverflow);
+
+ /* run quantization with modified criterion */
+ gain_cod_index = MR795_gain_code_quant_mod(
+ *gain_pit, exp_gcode0, gcode0,
+ frac_en, exp_en, alpha, gain_cod_unq,
+ gain_cod, qua_ener_MR122, qua_ener, pOverflow); /* function result */
+ }
+
+ *(*anap)++ = gain_pit_index;
+ *(*anap)++ = gain_cod_index;
+}
diff --git a/media/codecs/amrnb/enc/src/qgain795.h b/media/codecs/amrnb/enc/src/qgain795.h
new file mode 100644
index 0000000..b739dad
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/qgain795.h
@@ -0,0 +1,143 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/qgain795.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, qgain795.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef qgain795_h
+#define qgain795_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "g_adapt.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void
+ MR795_gain_quant(
+ GainAdaptState *adapt_st, /* i/o: gain adapter state structure */
+ Word16 res[], /* i : LP residual, Q0 */
+ Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
+ Word16 code[], /* i : CB innovation (unfiltered), Q13 */
+ Word16 frac_coeff[], /* i : coefficients (5), Q15 */
+ Word16 exp_coeff[], /* i : energy coefficients (5), Q0 */
+ /* coefficients from calc_filt_ener() */
+ Word16 exp_code_en, /* i : innovation energy (exponent), Q0 */
+ Word16 frac_code_en, /* i : innovation energy (fraction), Q15 */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 L_subfr, /* i : Subframe length */
+ Word16 cod_gain_frac, /* i : opt. codebook gain (fraction),Q15 */
+ Word16 cod_gain_exp, /* i : opt. codebook gain (exponent), Q0 */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *gain_pit, /* i/o: Pitch gain (unquant/quant), Q14 */
+ Word16 *gain_cod, /* o : Code gain, Q1 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Word16 **anap, /* o : Index of quantization */
+ /* (first gain pitch, then code pitch)*/
+ Flag *pOverflow /* o : overflow indicator */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* qgain795_H_ */
+
+
diff --git a/media/codecs/amrnb/enc/src/qua_gain.cpp b/media/codecs/amrnb/enc/src/qua_gain.cpp
new file mode 100644
index 0000000..740abcb
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/qua_gain.cpp
@@ -0,0 +1,400 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/qua_gain.c
+ Functions:
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description: Changed include files to lowercase.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Added #ifdef __cplusplus around extern'ed table.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Quantization of pitch and codebook gains.
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "qua_gain.h"
+#include "typedef.h"
+#include "basic_op.h"
+
+#include "mode.h"
+#include "cnst.h"
+#include "pow2.h"
+#include "gc_pred.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here. Include conditional
+ ; compile variables also.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; LOCAL VARIABLE DEFINITIONS
+ ; Variable declaration - defined here and used outside this module
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+ extern const Word16 table_gain_lowrates[];
+ extern const Word16 table_gain_highrates[];
+
+ /*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME:
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+ Inputs:
+ mode -- enum Mode -- AMR mode
+ Word16 exp_gcode0 -- Word16 -- predicted CB gain (exponent), Q0
+ Word16 frac_gcode0 -- Word16 -- predicted CB gain (fraction), Q15
+ Word16 frac_coeff -- Word16 Array -- energy coeff. (5), fraction part, Q15
+ Word16 exp_coeff -- Word16 Array -- energy coeff. (5), exponent part, Q0
+ (frac_coeff and exp_coeff computed in
+ calc_filt_energies())
+
+ Word16 gp_limit -- Word16 -- pitch gain limit
+
+ Outputs:
+ Word16 *gain_pit -- Pointer to Word16 -- Pitch gain, Q14
+ Word16 *gain_cod -- Pointer to Word16 -- Code gain, Q1
+ Word16 *qua_ener_MR122 -- Pointer to Word16 -- quantized energy error, Q10
+ (for MR122 MA predictor update)
+ Word16 *qua_ener -- Pointer to Word16 -- quantized energy error, Q10
+ (for other MA predictor update)
+ Flag *pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ Word16 -- index of quantization.
+
+ Global Variables Used:
+
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Quantization of pitch and codebook gains.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ qua_gain.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+Word16
+Qua_gain( /* o : index of quantization. */
+ enum Mode mode, /* i : AMR mode */
+ Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
+ Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
+ Word16 frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
+ Word16 exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
+ /* (frac_coeff and exp_coeff computed in */
+ /* calc_filt_energies()) */
+ Word16 gp_limit, /* i : pitch gain limit */
+ Word16 *gain_pit, /* o : Pitch gain, Q14 */
+ Word16 *gain_cod, /* o : Code gain, Q1 */
+ Word16 *qua_ener_MR122, /* o : quantized energy error, Q10 */
+ /* (for MR122 MA predictor update) */
+ Word16 *qua_ener, /* o : quantized energy error, Q10 */
+ /* (for other MA predictor update) */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ const Word16 *p;
+ Word16 i;
+ Word16 j;
+ Word16 index = 0;
+ Word16 gcode0;
+ Word16 e_max;
+ Word16 temp;
+ Word16 exp_code;
+ Word16 g_pitch;
+ Word16 g2_pitch;
+ Word16 g_code;
+ Word16 g2_code;
+ Word16 g_pit_cod;
+ Word16 coeff[5];
+ Word16 coeff_lo[5];
+ Word16 exp_max[5];
+ Word32 L_tmp;
+ Word32 L_tmp2;
+ Word32 dist_min;
+ const Word16 *table_gain;
+ Word16 table_len;
+
+ if (mode == MR102 || mode == MR74 || mode == MR67)
+ {
+ table_len = VQ_SIZE_HIGHRATES;
+ table_gain = table_gain_highrates;
+ }
+ else
+ {
+ table_len = VQ_SIZE_LOWRATES;
+ table_gain = table_gain_lowrates;
+ }
+
+ /*-------------------------------------------------------------------*
+ * predicted codebook gain *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * gc0 = 2^exp_gcode0 + 2^frac_gcode0 *
+ * *
+ * gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0) *
+ *-------------------------------------------------------------------*/
+
+ gcode0 = (Word16)(Pow2(14, frac_gcode0, pOverflow));
+
+ /*-------------------------------------------------------------------*
+ * Scaling considerations: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ *-------------------------------------------------------------------*/
+
+ /*
+ * The error energy (sum) to be minimized consists of five terms, t[0..4].
+ *
+ * t[0] = gp^2 * <y1 y1>
+ * t[1] = -2*gp * <xn y1>
+ * t[2] = gc^2 * <y2 y2>
+ * t[3] = -2*gc * <xn y2>
+ * t[4] = 2*gp*gc * <y1 y2>
+ *
+ */
+
+ /* determine the scaling exponent for g_code: ec = ec0 - 11 */
+ exp_code = sub(exp_gcode0, 11, pOverflow);
+
+ /* calculate exp_max[i] = s[i]-1 */
+ exp_max[0] = sub(exp_coeff[0], 13, pOverflow);
+ exp_max[1] = sub(exp_coeff[1], 14, pOverflow);
+
+ temp = shl(exp_code, 1, pOverflow);
+ temp = add(15, temp, pOverflow);
+ exp_max[2] = add(exp_coeff[2], temp, pOverflow);
+
+ exp_max[3] = add(exp_coeff[3], exp_code, pOverflow);
+
+ temp = add(1, exp_code, pOverflow);
+ exp_max[4] = add(exp_coeff[4], temp, pOverflow);
+
+
+ /*-------------------------------------------------------------------*
+ * Find maximum exponent: *
+ * ~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * For the sum operation, all terms must have the same scaling; *
+ * that scaling should be low enough to prevent overflow. There- *
+ * fore, the maximum scale is determined and all coefficients are *
+ * re-scaled: *
+ * *
+ * e_max = max(exp_max[i]) + 1; *
+ * e = exp_max[i]-e_max; e <= 0! *
+ * c[i] = c[i]*2^e *
+ *-------------------------------------------------------------------*/
+
+ e_max = exp_max[0];
+ for (i = 1; i < 5; i++)
+ {
+ if (exp_max[i] > e_max)
+ {
+ e_max = exp_max[i];
+ }
+ }
+
+ e_max = add(e_max, 1, pOverflow); /* To avoid overflow */
+
+ for (i = 0; i < 5; i++)
+ {
+ j = sub(e_max, exp_max[i], pOverflow);
+ L_tmp = L_deposit_h(frac_coeff[i]);
+ L_tmp = L_shr(L_tmp, j, pOverflow);
+ L_Extract(L_tmp, &coeff[i], &coeff_lo[i], pOverflow);
+ }
+
+
+ /*-------------------------------------------------------------------*
+ * Codebook search: *
+ * ~~~~~~~~~~~~~~~~ *
+ * *
+ * For each pair (g_pitch, g_fac) in the table calculate the *
+ * terms t[0..4] and sum them up; the result is the mean squared *
+ * error for the quantized gains from the table. The index for the *
+ * minimum MSE is stored and finally used to retrieve the quantized *
+ * gains *
+ *-------------------------------------------------------------------*/
+
+ /* start with "infinite" MSE */
+ dist_min = MAX_32;
+
+ p = &table_gain[0];
+
+ for (i = 0; i < table_len; i++)
+ {
+ g_pitch = *p++;
+ g_code = *p++; /* this is g_fac */
+ p++; /* skip log2(g_fac) */
+ p++; /* skip 20*log10(g_fac) */
+
+ if (g_pitch <= gp_limit)
+ {
+ g_code = mult(g_code, gcode0, pOverflow);
+ g2_pitch = mult(g_pitch, g_pitch, pOverflow);
+ g2_code = mult(g_code, g_code, pOverflow);
+ g_pit_cod = mult(g_code, g_pitch, pOverflow);
+
+ L_tmp = Mpy_32_16(coeff[0], coeff_lo[0], g2_pitch, pOverflow);
+ L_tmp2 = Mpy_32_16(coeff[1], coeff_lo[1], g_pitch, pOverflow);
+ L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
+
+ L_tmp2 = Mpy_32_16(coeff[2], coeff_lo[2], g2_code, pOverflow);
+ L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
+
+ L_tmp2 = Mpy_32_16(coeff[3], coeff_lo[3], g_code, pOverflow);
+ L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
+
+ L_tmp2 = Mpy_32_16(coeff[4], coeff_lo[4], g_pit_cod, pOverflow);
+ L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
+
+ /* store table index if MSE for this index is lower
+ than the minimum MSE seen so far */
+ if (L_tmp < dist_min)
+ {
+ dist_min = L_tmp;
+ index = i;
+ }
+ }
+ }
+
+ /*------------------------------------------------------------------*
+ * read quantized gains and new values for MA predictor memories *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ *------------------------------------------------------------------*/
+
+ /* Read the quantized gains */
+ p = &table_gain[shl(index, 2, pOverflow)];
+ *gain_pit = *p++;
+ g_code = *p++;
+ *qua_ener_MR122 = *p++;
+ *qua_ener = *p;
+
+ /*------------------------------------------------------------------*
+ * calculate final fixed codebook gain: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * gc = gc0 * g *
+ *------------------------------------------------------------------*/
+
+ L_tmp = L_mult(g_code, gcode0, pOverflow);
+ temp = sub(10, exp_gcode0, pOverflow);
+ L_tmp = L_shr(L_tmp, temp, pOverflow);
+
+ *gain_cod = extract_h(L_tmp);
+
+ return index;
+}
diff --git a/media/codecs/amrnb/enc/src/s10_8pf.cpp b/media/codecs/amrnb/enc/src/s10_8pf.cpp
new file mode 100644
index 0000000..352b611
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/s10_8pf.cpp
@@ -0,0 +1,990 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/s10_8pf.c
+ Funtions: search_10and8i40
+
+ Date: 04/18/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Adding pOverflow to the functions to remove global variables.
+ These changes are needed for the EPOC releases. Cleaned up code.
+ Updated template.
+
+ Description: Changed temp to temp32. When temp was only 16 bits it was not
+ holding the 32 bit value returned from the functions. Some
+ variables were also being declared as Word16 rather than Word32
+ as they were suposed to be.
+
+ Description: Changed copyright year. Removed all calls to math functions by
+ inlining them, and removed all unnecessary files in the Include
+ section.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Removed all #defines.
+ 2. Used a pointer to &codvec[0] instead of array indexing.
+ 3. Removed multiple data casting in the code.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers, this by taking
+ advantage of the fact that the autocrrelation matrix is
+ a toeplitz matrix, so r[i][j] = r[j][i], then a single
+ pointer can be used to address a matrix. The use of this
+ is not uniform along the function (due to compiler limitations:
+ handling so many variables in this file) so the use
+ of this is pointer optimizations is limited to places
+ where the ARM compiler provides the lesses numer of cycles
+ 3. Eliminated use of intermediate variables to accelerate
+ comparisons (like in the nested loops)
+ 4. Introduced array temp1[], to pre-calculate the elements
+ used in the nested loops, in this way the calculation is
+ not repeated in every loop iteration. This is done for
+ loops i3-i5-i7 and i9
+ 5. Use array Index[] to store indexes i1:i9, and then use memcpy
+ to update indexes.
+ 6. Eliminated shifts by modifying the way number are rounded,
+ this does not have any effect in ARM processors but may help
+ other compilers
+
+ Description:
+ 1. When storing indexes, added memcpy() to support the rates
+ that use this function: 12.2 (already done) and 10.2 (missing).
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "s10_8pf.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: search_10and8i40
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ nbPulse = nbPulses to find (Word16)
+ step = step size (Word16)
+ nbTracks = nbTracks (Word16)
+ dn[] = correlation between target and h[] (Word16)
+ rr[][] = matrix of autocorrelation (Word16)
+ ipos[] = starting position of each pulse (Word16)
+ pos_max[] = Position of maximum dn[] (Word16)
+ codvec[] = Algebraic codebook vector (Word16)
+ pOverflow = pointer to Overflow flag (Flag)
+
+ Outputs:
+ codvec[] = Algebraic codebook vector (Word16)
+ pOverflow -> 1 if processing this funvction results in satuaration
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function searches for the best codevector; It determines the positions
+ of the 10/8 pulses in the 40-sample frame.
+
+ search_10and8i40 (10,5,5,dn, rr, ipos, pos_max, codvec); for GSMEFR
+ search_10and8i40 (8, 4,4,dn, rr, ipos, pos_max, codvec); for 10.2
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ s10_8pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void search_10and8i40 (
+ Word16 nbPulse, // i : nbpulses to find
+ Word16 step, // i : stepsize
+ Word16 nbTracks, // i : nbTracks
+ Word16 dn[], // i : correlation between target and h[]
+ Word16 rr[][L_CODE], // i : matrix of autocorrelation
+ Word16 ipos[], // i : starting position for each pulse
+ Word16 pos_max[], // i : position of maximum of dn[]
+ Word16 codvec[] // o : algebraic codebook vector
+)
+{
+ Word16 i0, i1, i2, i3, i4, i5, i6, i7, i8, i9;
+ Word16 i, j, k, pos, ia, ib;
+ Word16 psk, ps, ps0, ps1, ps2, sq, sq2;
+ Word16 alpk, alp, alp_16;
+ Word16 rrv[L_CODE];
+ Word32 s, alp0, alp1, alp2;
+ Word16 gsmefrFlag;
+
+
+ if (sub(nbPulse, 10) == 0)
+ {
+ gsmefrFlag=1;
+ }
+ else
+ {
+ gsmefrFlag=0;
+ }
+
+ // fix i0 on maximum of correlation position
+ i0 = pos_max[ipos[0]];
+
+ //
+ // i1 loop: *
+ //
+
+ // Default value
+
+ psk = -1;
+ alpk = 1;
+ for (i = 0; i < nbPulse; i++)
+ {
+ codvec[i] = i;
+ }
+
+ for (i = 1; i < nbTracks; i++)
+ {
+ i1 = pos_max[ipos[1]];
+ ps0 = add (dn[i0], dn[i1]);
+ alp0 = L_mult (rr[i0][i0], _1_16);
+ alp0 = L_mac (alp0, rr[i1][i1], _1_16);
+ alp0 = L_mac (alp0, rr[i0][i1], _1_8);
+
+ //
+ // i2 and i3 loop
+ //
+
+ for (i3 = ipos[3]; i3 < L_CODE; i3 += step)
+ {
+ s = L_mult (rr[i3][i3], _1_8); // index incr= step+L_CODE
+ s = L_mac (s, rr[i0][i3], _1_4); // index increment = step
+ s = L_mac (s, rr[i1][i3], _1_4); // index increment = step
+ rrv[i3] = pv_round (s);
+ }
+
+ // Default value
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[2];
+ ib = ipos[3];
+
+ for (i2 = ipos[2]; i2 < L_CODE; i2 += step)
+ {
+ // index increment = step
+ ps1 = add (ps0, dn[i2]);
+
+ // index incr= step+L_CODE
+ alp1 = L_mac (alp0, rr[i2][i2], _1_16);
+
+ // index increment = step
+ alp1 = L_mac (alp1, rr[i0][i2], _1_8);
+
+ // index increment = step
+ alp1 = L_mac (alp1, rr[i1][i2], _1_8);
+
+ for (i3 = ipos[3]; i3 < L_CODE; i3 += step)
+ {
+ // index increment = step
+ ps2 = add (ps1, dn[i3]);
+
+ // index increment = step
+ alp2 = L_mac (alp1, rrv[i3], _1_2);
+
+ // index increment = step
+ alp2 = L_mac (alp2, rr[i2][i3], _1_8);
+
+ sq2 = mult (ps2, ps2);
+
+ alp_16 = pv_round (alp2);
+
+ s = L_msu (L_mult (alp, sq2), sq, alp_16);
+
+ if (s > 0)
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = alp_16;
+ ia = i2;
+ ib = i3;
+ }
+ }
+ }
+ i2 = ia;
+ i3 = ib;
+
+ //
+ // i4 and i5 loop:
+ //
+
+ ps0 = ps;
+ alp0 = L_mult (alp, _1_2);
+
+ for (i5 = ipos[5]; i5 < L_CODE; i5 += step)
+ {
+ s = L_mult (rr[i5][i5], _1_8);
+ s = L_mac (s, rr[i0][i5], _1_4);
+ s = L_mac (s, rr[i1][i5], _1_4);
+ s = L_mac (s, rr[i2][i5], _1_4);
+ s = L_mac (s, rr[i3][i5], _1_4);
+ rrv[i5] = pv_round (s);
+ }
+
+ // Default value
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[4];
+ ib = ipos[5];
+
+ for (i4 = ipos[4]; i4 < L_CODE; i4 += step)
+ {
+ ps1 = add (ps0, dn[i4]);
+
+ alp1 = L_mac (alp0, rr[i4][i4], _1_32);
+ alp1 = L_mac (alp1, rr[i0][i4], _1_16);
+ alp1 = L_mac (alp1, rr[i1][i4], _1_16);
+ alp1 = L_mac (alp1, rr[i2][i4], _1_16);
+ alp1 = L_mac (alp1, rr[i3][i4], _1_16);
+
+ for (i5 = ipos[5]; i5 < L_CODE; i5 += step)
+ {
+ ps2 = add (ps1, dn[i5]);
+
+ alp2 = L_mac (alp1, rrv[i5], _1_4);
+ alp2 = L_mac (alp2, rr[i4][i5], _1_16);
+
+ sq2 = mult (ps2, ps2);
+
+ alp_16 = pv_round (alp2);
+
+ s = L_msu (L_mult (alp, sq2), sq, alp_16);
+
+ if (s > 0)
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = alp_16;
+ ia = i4;
+ ib = i5;
+ }
+ }
+ }
+ i4 = ia;
+ i5 = ib;
+
+ //
+ // i6 and i7 loop:
+ //
+
+ ps0 = ps;
+ alp0 = L_mult (alp, _1_2);
+
+ for (i7 = ipos[7]; i7 < L_CODE; i7 += step)
+ {
+ s = L_mult (rr[i7][i7], _1_16);
+ s = L_mac (s, rr[i0][i7], _1_8);
+ s = L_mac (s, rr[i1][i7], _1_8);
+ s = L_mac (s, rr[i2][i7], _1_8);
+ s = L_mac (s, rr[i3][i7], _1_8);
+ s = L_mac (s, rr[i4][i7], _1_8);
+ s = L_mac (s, rr[i5][i7], _1_8);
+ rrv[i7] = pv_round (s);
+ }
+
+ // Default value
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[6];
+ ib = ipos[7];
+
+ for (i6 = ipos[6]; i6 < L_CODE; i6 += step)
+ {
+ ps1 = add (ps0, dn[i6]);
+
+ alp1 = L_mac (alp0, rr[i6][i6], _1_64);
+ alp1 = L_mac (alp1, rr[i0][i6], _1_32);
+ alp1 = L_mac (alp1, rr[i1][i6], _1_32);
+ alp1 = L_mac (alp1, rr[i2][i6], _1_32);
+ alp1 = L_mac (alp1, rr[i3][i6], _1_32);
+ alp1 = L_mac (alp1, rr[i4][i6], _1_32);
+ alp1 = L_mac (alp1, rr[i5][i6], _1_32);
+
+ for (i7 = ipos[7]; i7 < L_CODE; i7 += step)
+ {
+ ps2 = add (ps1, dn[i7]);
+
+ alp2 = L_mac (alp1, rrv[i7], _1_4);
+ alp2 = L_mac (alp2, rr[i6][i7], _1_32);
+
+ sq2 = mult (ps2, ps2);
+
+ alp_16 = pv_round (alp2);
+
+ s = L_msu (L_mult (alp, sq2), sq, alp_16);
+
+ if (s > 0)
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = alp_16;
+ ia = i6;
+ ib = i7;
+ }
+ }
+ }
+ i6 = ia;
+ i7 = ib;
+
+ // now finished searching a set of 8 pulses
+
+ if(gsmefrFlag != 0){
+ // go on with the two last pulses for GSMEFR
+ //
+ // i8 and i9 loop:
+ //
+
+ ps0 = ps;
+ alp0 = L_mult (alp, _1_2);
+
+ for (i9 = ipos[9]; i9 < L_CODE; i9 += step)
+ {
+ s = L_mult (rr[i9][i9], _1_16);
+ s = L_mac (s, rr[i0][i9], _1_8);
+ s = L_mac (s, rr[i1][i9], _1_8);
+ s = L_mac (s, rr[i2][i9], _1_8);
+ s = L_mac (s, rr[i3][i9], _1_8);
+ s = L_mac (s, rr[i4][i9], _1_8);
+ s = L_mac (s, rr[i5][i9], _1_8);
+ s = L_mac (s, rr[i6][i9], _1_8);
+ s = L_mac (s, rr[i7][i9], _1_8);
+ rrv[i9] = pv_round (s);
+ }
+
+ // Default value
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[8];
+ ib = ipos[9];
+
+ for (i8 = ipos[8]; i8 < L_CODE; i8 += step)
+ {
+ ps1 = add (ps0, dn[i8]);
+
+ alp1 = L_mac (alp0, rr[i8][i8], _1_128);
+ alp1 = L_mac (alp1, rr[i0][i8], _1_64);
+ alp1 = L_mac (alp1, rr[i1][i8], _1_64);
+ alp1 = L_mac (alp1, rr[i2][i8], _1_64);
+ alp1 = L_mac (alp1, rr[i3][i8], _1_64);
+ alp1 = L_mac (alp1, rr[i4][i8], _1_64);
+ alp1 = L_mac (alp1, rr[i5][i8], _1_64);
+ alp1 = L_mac (alp1, rr[i6][i8], _1_64);
+ alp1 = L_mac (alp1, rr[i7][i8], _1_64);
+
+ for (i9 = ipos[9]; i9 < L_CODE; i9 += step)
+ {
+ ps2 = add (ps1, dn[i9]);
+
+ alp2 = L_mac (alp1, rrv[i9], _1_8);
+ alp2 = L_mac (alp2, rr[i8][i9], _1_64);
+
+ sq2 = mult (ps2, ps2);
+
+ alp_16 = pv_round (alp2);
+
+ s = L_msu (L_mult (alp, sq2), sq, alp_16);
+
+ if (s > 0)
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = alp_16;
+ ia = i8;
+ ib = i9;
+ }
+ }
+ }
+ } // end gsmefrFlag
+
+ //
+ // test and memorise if this combination is better than the last one/
+ //
+
+ s = L_msu (L_mult (alpk, sq), psk, alp);
+
+ if (s > 0)
+ {
+ psk = sq;
+ alpk = alp;
+ codvec[0] = i0;
+ codvec[1] = i1;
+ codvec[2] = i2;
+ codvec[3] = i3;
+ codvec[4] = i4;
+ codvec[5] = i5;
+ codvec[6] = i6;
+ codvec[7] = i7;
+
+ if (gsmefrFlag != 0)
+ {
+ codvec[8] = ia;
+ codvec[9] = ib;
+ }
+ }
+
+ //
+ // Cyclic permutation of i1,i2,i3,i4,i5,i6,i7,(i8 and i9)/
+ //
+
+ pos = ipos[1];
+ for (j = 1, k = 2; k < nbPulse; j++, k++)
+ {
+ ipos[j] = ipos[k];
+ }
+ ipos[sub(nbPulse,1)] = pos;
+ } // end 1..nbTracks loop
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void search_10and8i40(
+ Word16 nbPulse, /* i : nbpulses to find */
+ Word16 step, /* i : stepsize */
+ Word16 nbTracks, /* i : nbTracks */
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
+ Word16 ipos[], /* i : starting position for each pulse */
+ Word16 pos_max[], /* i : position of maximum of dn[] */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag *pOverflow /* i/o : overflow flag */
+)
+{
+ Word16 i0, i1, i2, i3, i4, i5, i6, i7, i9;
+ Word16 i, j, k/*, m*/;
+ Word16 pos, ia, ib;
+ Word16 psk;
+ Word16 sq, sq2;
+ Word16 alpk, alp, alp_16;
+ Word32 s;
+ Word32 alp0, alp1, alp2;
+ Word16 gsmefrFlag;
+ Word16 *p_codvec = codvec;
+ Word16 *p_temp2;
+
+ Word16 temp1[2*L_CODE];
+ Word16 *p_temp1;
+ Word16 ps2;
+ Word16 ps1;
+ Word16 ps;
+ Word16 ps0;
+
+ Word16 index[10];
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ if (nbPulse == 10)
+ {
+ gsmefrFlag = 1;
+ }
+ else
+ {
+ gsmefrFlag = 0;
+ }
+
+ /* fix i0 on maximum of correlation position */
+ i0 = pos_max[ipos[0]];
+ index[0] = i0;
+ /*------------------------------------------------------------------*
+ * i1 loop: *
+ *------------------------------------------------------------------*/
+
+ /* Default value */
+ psk = -1;
+ alpk = 1;
+ for (i = 0; i < nbPulse; i++)
+ {
+ *(p_codvec++) = i;
+ }
+
+ for (i = 1; i < nbTracks; i++)
+ {
+ i1 = pos_max[ipos[1]];
+ index[1] = i1;
+
+ /* ps0 = add (dn[i0], dn[i1], pOverflow);*/
+ ps0 = (Word16)((Word32) dn[i0] + dn[i1]);
+
+ /* alp0 = L_mult (rr[i0][i0], _1_16, pOverflow); */
+ alp0 = (Word32) rr[i0][i0] << 12;
+
+ /* alp0 = L_mac (alp0, rr[i1][i1], _1_16, pOverflow); */
+ alp0 += (Word32) rr[i1][i1] << 12;
+
+ /* alp0 = L_mac (alp0, rr[i0][i1], _1_8, pOverflow); */
+ alp0 += (Word32) rr[i0][i1] << 13;
+ alp0 += 0x00008000L;
+
+ /*----------------------------------------------------------------*
+ * i2 and i3 loop: *
+ *----------------------------------------------------------------*/
+
+ p_temp1 = temp1;
+ for (i3 = ipos[3]; i3 < L_CODE; i3 += step)
+ {
+ p_temp2 = &rr[i3][0];
+ s = (Word32) * (p_temp2 + i3) >> 1;
+ s += (Word32) * (p_temp2 + i0);
+ s += (Word32) * (p_temp2 + i1);
+ *(p_temp1++) = ps0 + dn[i3];
+ *(p_temp1++) = (Word16)((s + 2) >> 2);
+ }
+
+ /* Default value */
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[2];
+ ib = ipos[3];
+
+ s = (alp0 >> 12);
+
+ for (j = ipos[2]; j < L_CODE; j += step)
+ {
+ /* index increment = step */
+ p_temp2 = &rr[j][0];
+
+ alp1 = (s + (Word32) * (p_temp2 + j)) >> 1;
+
+ alp1 += (Word32) * (p_temp2 + i0);
+
+ alp1 += (Word32) * (p_temp2 + i1);
+
+ p_temp1 = temp1;
+ ps1 = dn[j];
+
+
+ for (i3 = ipos[3]; i3 < L_CODE; i3 += step)
+ {
+ /* index increment = step */
+ ps2 = ps1 + *(p_temp1++);
+
+ sq2 = (Word16)(((Word32) ps2 * ps2) >> 15);
+
+ alp2 = (alp1 + p_temp2[i3]) >> 2;
+ alp2 = (alp2 + *(p_temp1++)) >> 1; /* alp2 is always > 0 */
+ if (((Word32) sq2 * alp) > ((Word32) sq * alp2))
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = (Word16)alp2;
+ ia = j;
+ ib = i3;
+ }
+ }
+
+ }
+ i2 = ia;
+ i3 = ib;
+ index[2] = ia;
+ index[3] = ib;
+
+ /*----------------------------------------------------------------*
+ * i4 and i5 loop: *
+ *----------------------------------------------------------------*/
+
+ alp0 = ((Word32) alp << 15) + 0x00008000L;
+ p_temp1 = temp1;
+
+ for (i5 = ipos[5]; i5 < L_CODE; i5 += step)
+ {
+ p_temp2 = &rr[i5][0];
+ s = (Word32) * (p_temp2 + i5) >> 1;
+ s += (Word32) * (p_temp2 + i0);
+ s += (Word32) * (p_temp2 + i1);
+ s += (Word32) * (p_temp2 + i2);
+ s += (Word32) * (p_temp2 + i3);
+
+ *(p_temp1++) = ps + dn[i5];
+ *(p_temp1++) = (Word16)((s + 2) >> 2);
+ }
+
+ /* Default value */
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[4];
+ ib = ipos[5];
+
+ for (j = ipos[4]; j < L_CODE; j += step)
+ {
+ /* ps1 = add (ps0, dn[i4], pOverflow); */
+ p_temp2 = &rr[j][0];
+
+ /* alp1 = L_mac (alp0, rr[i4][i4], _1_32, pOverflow); */
+ alp1 = alp0 + ((Word32) * (p_temp2 + j) << 11);
+
+ /* alp1 = L_mac (alp1, rr[i0][i4], _1_16, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i0) << 12;
+
+ /* alp1 = L_mac (alp1, rr[i1][i4], _1_16, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i1) << 12;
+
+ /* alp1 = L_mac (alp1, rr[i2][i4], _1_16, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i2) << 12;
+
+ /* alp1 = L_mac (alp1, rr[i3][i4], _1_16, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i3) << 12;
+
+ p_temp1 = temp1;
+ ps1 = dn[j];
+
+ for (i5 = ipos[5]; i5 < L_CODE; i5 += step)
+ {
+ ps2 = ps1 + *(p_temp1++);
+
+ alp2 = alp1 + ((Word32) * (p_temp2 + i5) << 12);
+
+ alp_16 = (Word16)((alp2 + ((Word32) * (p_temp1++) << 14)) >> 16);
+ sq2 = (Word16)(((Word32) ps2 * ps2) >> 15);
+
+ if (((Word32) sq2 * alp) > ((Word32) sq * alp_16))
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = alp_16;
+ ia = j;
+ ib = i5;
+ }
+
+ }
+ }
+ i4 = ia;
+ i5 = ib;
+ index[4] = ia;
+ index[5] = ib;
+
+ /*----------------------------------------------------------------*
+ * i6 and i7 loop: *
+ *----------------------------------------------------------------*/
+
+ alp0 = ((Word32) alp << 15) + 0x00008000L;
+
+ p_temp1 = temp1;
+
+ for (i7 = ipos[7]; i7 < L_CODE; i7 += step)
+ {
+ s = (Word32) rr[i7][i7] >> 1;
+ s += (Word32) rr[i0][i7];
+ s += (Word32) rr[i1][i7];
+ s += (Word32) rr[i2][i7];
+ s += (Word32) rr[i3][i7];
+ s += (Word32) rr[i4][i7];
+ s += (Word32) rr[i5][i7];
+ *(p_temp1++) = ps + dn[i7];
+ *(p_temp1++) = (Word16)((s + 4) >> 3);
+ }
+
+
+ /* Default value */
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[6];
+ ib = ipos[7];
+
+ for (j = ipos[6]; j < L_CODE; j += step)
+ {
+ /* ps1 = add (ps0, dn[i6], pOverflow); */
+
+ p_temp2 = (Word16 *) & rr[j];
+
+ /* alp1 = L_mac (alp0, rr[i6][i6], _1_64, pOverflow); */
+ alp1 = alp0 + ((Word32) * (p_temp2 + j) << 10);
+
+ /* alp1 = L_mac (alp1, rr[i0][i6], _1_32, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i0) << 11;
+
+
+ /* alp1 = L_mac (alp1, rr[i1][i6], _1_32, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i1) << 11;
+
+ /* alp1 = L_mac (alp1, rr[i2][i6], _1_32, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i2) << 11;
+
+ /* alp1 = L_mac (alp1, rr[i3][i6], _1_32, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i3) << 11;
+
+ /* alp1 = L_mac (alp1, rr[i4][i6], _1_32, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i4) << 11;
+
+ /* alp1 = L_mac (alp1, rr[i5][i6], _1_32, pOverflow); */
+ alp1 += (Word32) * (p_temp2 + i5) << 11;
+
+ p_temp1 = temp1;
+ ps1 = dn[j];
+
+ for (i7 = ipos[7]; i7 < L_CODE; i7 += step)
+ {
+ ps2 = ps1 + *(p_temp1++);
+
+ alp2 = alp1 + ((Word32) * (p_temp2 + i7) << 11);
+
+ alp_16 = (Word16)((alp2 + ((Word32) * (p_temp1++) << 14)) >> 16);
+
+ sq2 = (Word16)(((Word32) ps2 * ps2) >> 15);
+
+ if (((Word32) sq2 * alp) > ((Word32) sq * alp_16))
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = alp_16;
+ ia = j;
+ ib = i7;
+ }
+ }
+ }
+
+ i6 = ia;
+ i7 = ib;
+ index[6] = ia;
+ index[7] = ib;
+
+ /* now finished searching a set of 8 pulses */
+
+ if (gsmefrFlag != 0)
+ {
+ /* go on with the two last pulses for GSMEFR */
+ /*----------------------------------------------------------------*
+ * i8 and i9 loop: *
+ *----------------------------------------------------------------*/
+
+ alp0 = ((Word32) alp << 15) + 0x00008000L;
+
+ p_temp1 = temp1;
+
+ for (i9 = ipos[9]; i9 < L_CODE; i9 += step)
+ {
+ s = (Word32) rr[i9][i9] >> 1;
+ s += (Word32) rr[i0][i9];
+ s += (Word32) rr[i1][i9];
+ s += (Word32) rr[i2][i9];
+ s += (Word32) rr[i3][i9];
+ s += (Word32) rr[i4][i9];
+ s += (Word32) rr[i5][i9];
+ s += (Word32) rr[i6][i9];
+ s += (Word32) rr[i7][i9];
+
+ *(p_temp1++) = ps + dn[i9];
+ *(p_temp1++) = (Word16)((s + 4) >> 3);
+ }
+
+ /* Default value */
+ sq = -1;
+ alp = 1;
+ ps = 0;
+ ia = ipos[8];
+ ib = ipos[9];
+
+ for (j = ipos[8]; j < L_CODE; j += step)
+ {
+ /* ps1 = add (ps0, dn[i8], pOverflow); */
+ p_temp2 = &rr[j][0];
+
+ /* alp1 = L_mac (alp0, rr[i8][i8], _1_128, pOverflow); */
+ alp1 = alp0 + ((Word32) * (p_temp2 + j) << 9);
+
+ /* alp1 = L_mac (alp1, rr[i0][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i0][j] << 10;
+
+ /* alp1 = L_mac (alp1, rr[i1][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i1][j] << 10;
+
+ /* alp1 = L_mac (alp1, rr[i2][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i2][j] << 10;
+
+ /* alp1 = L_mac (alp1, rr[i3][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i3][j] << 10;
+
+ /* alp1 = L_mac (alp1, rr[i4][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i4][j] << 10;
+
+ /* alp1 = L_mac (alp1, rr[i5][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i5][j] << 10;
+
+ /* alp1 = L_mac (alp1, rr[i6][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i6][j] << 10;
+
+ /* alp1 = L_mac (alp1, rr[i7][i8], _1_64, pOverflow); */
+ alp1 += (Word32) rr[i7][j] << 10;
+
+ p_temp1 = temp1;
+ ps1 = dn[j];
+
+ for (i9 = ipos[9]; i9 < L_CODE; i9 += step)
+ {
+ /* ps2 = add (ps1, dn[i9], pOverflow); */
+ ps2 = ps1 + *(p_temp1++);
+
+ /* sq2 = mult (ps2, ps2, pOverflow); */
+ sq2 = (Word16)(((Word32) ps2 * ps2) >> 15);
+
+ /* alp2 = L_mac (alp1, rrv[i9], _1_8, pOverflow); */
+ alp2 = alp1 + ((Word32) * (p_temp2 + i9) << 10) ;
+
+ /* alp2 = L_mac (alp2, rr[i8][i9], _1_64, pOverflow); */
+ alp_16 = (Word16)((alp2 + ((Word32) * (p_temp1++) << 13)) >> 16);
+
+ if (((Word32) sq2 * alp) > ((Word32) sq * alp_16))
+ {
+ sq = sq2;
+ ps = ps2;
+ alp = alp_16;
+ ia = j;
+ ib = i9;
+ }
+ }
+ }
+
+ index[8] = ia;
+ index[9] = ib;
+
+ }/* end gsmefrFlag */
+
+ /*---------------------------------------------------------------- *
+ * test and memorise if this combination is better than the last one.*
+ *----------------------------------------------------------------*/
+
+ if (((Word32) alpk * sq) > ((Word32) psk * alp))
+ {
+ psk = sq;
+ alpk = alp;
+
+ if (gsmefrFlag != 0)
+ {
+ memcpy(codvec, index, (2*NB_TRACK)*sizeof(*index));
+ }
+ else
+ {
+ memcpy(codvec, index, (2*NB_TRACK_MR102)*sizeof(*index));
+ }
+
+ }
+ /*----------------------------------------------------------------*
+ * Cyclic permutation of i1,i2,i3,i4,i5,i6,i7,(i8 and i9). *
+ *----------------------------------------------------------------*/
+
+ pos = ipos[1];
+ for (j = 1, k = 2; k < nbPulse; j++, k++)
+ {
+ ipos[j] = ipos[k];
+ }
+ ipos[nbPulse-1] = pos;
+ } /* end 1..nbTracks loop*/
+}
+
diff --git a/media/codecs/amrnb/enc/src/s10_8pf.h b/media/codecs/amrnb/enc/src/s10_8pf.h
new file mode 100644
index 0000000..7591f5f
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/s10_8pf.h
@@ -0,0 +1,128 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/s10_8pf.h
+
+
+
+
+ Date: 08/11/2000
+
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Changed function prototype; pointer to overflow flag is passed
+ in as a parameter. Updated template
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the s10_8pf module.
+------------------------------------------------------------------------------
+*/
+
+#ifndef S10_8PF_H
+#define S10_8PF_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void search_10and8i40(
+ Word16 nbPulse, /* i : nbpulses to find */
+ Word16 step, /* i : stepsize */
+ Word16 nbTracks, /* i : nbTracks */
+ Word16 dn[], /* i : correlation between target and h[] */
+ Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
+ Word16 ipos[], /* i : starting position for each pulse */
+ Word16 pos_max[], /* i : position of maximum of dn[] */
+ Word16 codvec[], /* o : algebraic codebook vector */
+ Flag *pOverflow /* i/o : Overflow flag */
+ );
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _S10_8PF_H_ */
diff --git a/media/codecs/amrnb/enc/src/set_sign.cpp b/media/codecs/amrnb/enc/src/set_sign.cpp
new file mode 100644
index 0000000..fa43f78
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/set_sign.cpp
@@ -0,0 +1,609 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/set_sign.c
+ Funtions: set_sign
+ set_sign12k2
+
+ Date: 05/26/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed into PV template and optimized.
+
+ Description: Synchronized file with UMTS version 3.2.0. Updated coding
+ template. Removed unnecessary include files.
+
+ Description: Replaced basic_op.h with the header files of the math functions
+ used in the file.
+
+ Description: Made the following changes per comments from Phase 2/3 review:
+ 1. Modified certain FOR loops to count down.
+ 2. Modified code for further optimization.
+
+ Description: Modified FOR loops in set_sign12k2 to count up. The FOR loops
+ affected are the loop that calculates the starting position of
+ each incoming pulse, and the loop that calculates the position
+ of the max correlation. Updated copyright year.
+
+ Description: Passing in pointer to overflow flag for EPOC compatibility.
+
+ Description: For set_sign12k2()
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation, this by evaluating the operands
+ 4. Replaced loop counter with decrement loops
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Changed round function name to pv_round to avoid conflict with
+ round function in C standard library.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This module contains the functions set_sign and set_sign12k2.
+ These functions are used to build a sign vector according
+ to the values in the input arrays. These functions also
+ find the position in the input codes of the maximum correlation
+ and the starting position for each pulse.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "set_sign.h"
+#include "basic_op.h"
+#include "inv_sqrt.h"
+#include "cnst.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: set_sign
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ dn = buffer of correlation values (Word16)
+ sign = buffer containing sign of dn elements (Word16)
+ dn2 = buffer containing the maximum of correlation in each track.(Word16)
+ n = number of maximum correlations in dn2 (Word16)
+
+ Returns:
+ None
+
+ Outputs:
+ dn buffer is modified to contain the absolute value of its input
+ sign buffer is modified to contain the sign information for the
+ values in dn buffer
+ dn2 buffer is modified to denote the location of the maximum
+ correlation for each track.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+ This function builds sign vector according to dn buffer It also finds
+ the position of maximum of correlation in each track and the starting
+ position for each pulse.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ set_sign.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void set_sign(Word16 dn[], i/o : correlation between target and h[]
+ Word16 sign[], o : sign of dn[]
+ Word16 dn2[], o : maximum of correlation in each track.
+ Word16 n i : # of maximum correlations in dn2[]
+)
+{
+ Word16 i, j, k;
+ Word16 val, min;
+ Word16 pos = 0; //initialization only needed to keep gcc silent
+
+ // set sign according to dn[]
+
+ for (i = 0; i < L_CODE; i++) {
+ val = dn[i];
+
+ if (val >= 0) {
+ sign[i] = 32767;
+ } else {
+ sign[i] = -32767;
+ val = negate(val);
+ }
+ dn[i] = val; // modify dn[] according to the fixed sign
+ dn2[i] = val;
+ }
+
+ // keep 8-n maximum positions/8 of each track and store it in dn2[]
+
+ for (i = 0; i < NB_TRACK; i++)
+ {
+ for (k = 0; k < (8-n); k++)
+ {
+ min = 0x7fff;
+ for (j = i; j < L_CODE; j += STEP)
+ {
+ if (dn2[j] >= 0)
+ {
+ val = sub(dn2[j], min);
+
+ if (val < 0)
+ {
+ min = dn2[j];
+ pos = j;
+ }
+ }
+ }
+ dn2[pos] = -1;
+ }
+ }
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void set_sign(Word16 dn[], /* i/o : correlation between target and h[] */
+ Word16 sign[], /* o : sign of dn[] */
+ Word16 dn2[], /* o : maximum of correlation in each track. */
+ Word16 n /* i : # of maximum correlations in dn2[] */
+ )
+{
+ Word16 i, j, k;
+ Word16 val, min;
+ Word16 pos = 0; /* initialization only needed to keep gcc silent */
+
+ /* set sign according to dn[] */
+ for (i = L_CODE - 1; i >= 0; i--)
+ {
+ val = dn[i];
+
+ if (val >= 0)
+ {
+ sign[i] = 32767;
+ }
+ else
+ {
+ sign[i] = -32767;
+ val = negate(val);
+ dn[i] = val; /* modify dn[] according to the fixed sign */
+ }
+
+ dn2[i] = val;
+ }
+
+ /* keep 8-n maximum positions/8 of each track and store it in dn2[] */
+
+ for (i = 0; i < NB_TRACK; i++)
+ {
+ for (k = 0; k < (8 - n); k++)
+ {
+ min = 0x7fff;
+ for (j = i; j < L_CODE; j += STEP)
+ {
+ if (dn2[j] >= 0)
+ {
+ if (dn2[j] < min)
+ {
+ min = dn2[j];
+ pos = j;
+ }
+ }
+ }
+ dn2[pos] = -1;
+ }
+ }
+
+ return;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: set_sign12k2()
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ dn = buffer of correlation values (Word16)
+ cn = buffer of residual after long term prediction (Word16)
+ sign = sign of correlation buffer elements (Word16)
+ pos_max = buffer containing position of maximum correlation (Word16)
+ nb_track = number of tracks (Word16)
+ ipos = buffer containing the starting position for each pulse (Word16)
+ step = step size in the tracks (Word16)
+ pOverflow = pointer to Overflow flag (Flag)
+
+ Outputs:
+ sign buffer contains the sign of correlation values
+ dn buffer contains the sign-adjusted correlation values
+ pos_max buffer contains the maximum correlation position
+ ipos buffer contains the starting position of each pulse
+ pOverflow -> 1 if the math operations called by this function result in
+ saturation
+
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function builds the sign vector according to dn and cn, and modifies
+ dn to include the sign information (dn[i]=sign[i]*dn[i]). It also finds
+ the position of maximum of correlation in each track and the starting
+ position for each pulse.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ set_sign.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void set_sign12k2 (
+ Word16 dn[], //i/o : correlation between target and h[]
+ Word16 cn[], //i : residual after long term prediction
+ Word16 sign[], //o : sign of d[n]
+ Word16 pos_max[], //o : position of maximum correlation
+ Word16 nb_track, //i : number of tracks tracks
+ Word16 ipos[], //o : starting position for each pulse
+ Word16 step //i : the step size in the tracks
+)
+{
+ Word16 i, j;
+ Word16 val, cor, k_cn, k_dn, max, max_of_all;
+ Word16 pos = 0; // initialization only needed to keep gcc silent
+ Word16 en[L_CODE]; // correlation vector
+ Word32 s;
+
+ // The reference ETSI code uses a global flag for Overflow. However in the
+ // actual implementation a pointer to the overflow flag is passed in. This
+ // pointer is passed into the basic math functions called by this routine.
+
+ // calculate energy for normalization of cn[] and dn[]
+
+ s = 256;
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = L_mac (s, cn[i], cn[i]);
+ }
+ s = Inv_sqrt (s);
+ k_cn = extract_h (L_shl (s, 5));
+
+ s = 256;
+ for (i = 0; i < L_CODE; i++)
+ {
+ s = L_mac (s, dn[i], dn[i]);
+ }
+ s = Inv_sqrt (s);
+ k_dn = extract_h (L_shl (s, 5));
+
+ for (i = 0; i < L_CODE; i++)
+ {
+ val = dn[i];
+ cor = pv_round (L_shl (L_mac (L_mult (k_cn, cn[i]), k_dn, val), 10));
+
+ if (cor >= 0)
+ {
+ sign[i] = 32767; // sign = +1
+ }
+ else
+ {
+ sign[i] = -32767; // sign = -1
+ cor = negate (cor);
+ val = negate (val);
+ }
+ // modify dn[] according to the fixed sign
+ dn[i] = val;
+ en[i] = cor;
+ }
+
+ max_of_all = -1;
+ for (i = 0; i < nb_track; i++)
+ {
+ max = -1;
+
+ for (j = i; j < L_CODE; j += step)
+ {
+ cor = en[j];
+ val = sub (cor, max);
+
+ if (val > 0)
+ {
+ max = cor;
+ pos = j;
+ }
+ }
+ // store maximum correlation position
+ pos_max[i] = pos;
+ val = sub (max, max_of_all);
+
+ if (val > 0)
+ {
+ max_of_all = max;
+ // starting position for i0
+ ipos[0] = i;
+ }
+ }
+
+ //
+ // Set starting position of each pulse.
+ //
+
+ pos = ipos[0];
+ ipos[nb_track] = pos;
+
+ for (i = 1; i < nb_track; i++)
+ {
+ pos = add (pos, 1);
+
+ if (sub (pos, nb_track) >= 0)
+ {
+ pos = 0;
+ }
+ ipos[i] = pos;
+ ipos[add(i, nb_track)] = pos;
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void set_sign12k2(
+ Word16 dn[], /* i/o : correlation between target and h[] */
+ Word16 cn[], /* i : residual after long term prediction */
+ Word16 sign[], /* o : sign of d[n] */
+ Word16 pos_max[], /* o : position of maximum correlation */
+ Word16 nb_track, /* i : number of tracks tracks */
+ Word16 ipos[], /* o : starting position for each pulse */
+ Word16 step, /* i : the step size in the tracks */
+ Flag *pOverflow /* i/o: overflow flag */
+)
+{
+ Word16 i, j;
+ Word16 val;
+ Word16 cor;
+ Word16 k_cn;
+ Word16 k_dn;
+ Word16 max;
+ Word16 max_of_all;
+ Word16 pos = 0; /* initialization only needed to keep gcc silent */
+ Word16 en[L_CODE]; /* correlation vector */
+ Word32 s;
+ Word32 t;
+ Word32 L_temp;
+ Word16 *p_cn;
+ Word16 *p_dn;
+ Word16 *p_sign;
+ Word16 *p_en;
+
+ /* calculate energy for normalization of cn[] and dn[] */
+
+ s = 256;
+ t = 256;
+ p_cn = cn;
+ p_dn = dn; /* crosscorrelation values do not have strong peaks, so
+ scaling applied in cor_h_x (sf=2) guaranteed that the
+ mac of the energy for this vector will not overflow */
+
+ for (i = L_CODE; i != 0; i--)
+ {
+ val = *(p_cn++);
+ s = L_mac(s, val, val, pOverflow);
+ val = *(p_dn++);
+ t += ((Word32) val * val) << 1;
+ }
+ s = Inv_sqrt(s, pOverflow);
+ k_cn = (Word16)((L_shl(s, 5, pOverflow)) >> 16);
+
+ t = Inv_sqrt(t, pOverflow);
+ k_dn = (Word16)(t >> 11);
+
+ p_cn = &cn[L_CODE-1];
+ p_sign = &sign[L_CODE-1];
+ p_en = &en[L_CODE-1];
+
+ for (i = L_CODE - 1; i >= 0; i--)
+ {
+ L_temp = ((Word32)k_cn * *(p_cn--)) << 1;
+ val = dn[i];
+ s = L_mac(L_temp, k_dn, val, pOverflow);
+ L_temp = L_shl(s, 10, pOverflow);
+ cor = pv_round(L_temp, pOverflow);
+
+ if (cor >= 0)
+ {
+ *(p_sign--) = 32767; /* sign = +1 */
+ }
+ else
+ {
+ *(p_sign--) = -32767; /* sign = -1 */
+ cor = negate(cor);
+
+ /* modify dn[] according to the fixed sign */
+ dn[i] = negate(val);
+ }
+
+ *(p_en--) = cor;
+ }
+
+ max_of_all = -1;
+ for (i = 0; i < nb_track; i++)
+ {
+ max = -1;
+
+ for (j = i; j < L_CODE; j += step)
+ {
+ cor = en[j];
+ if (cor > max)
+ {
+ max = cor;
+ pos = j;
+ }
+ }
+ /* store maximum correlation position */
+ pos_max[i] = pos;
+ if (max > max_of_all)
+ {
+ max_of_all = max;
+ /* starting position for i0 */
+ ipos[0] = i;
+ }
+ }
+
+ /*----------------------------------------------------------------*
+ * Set starting position of each pulse. *
+ *----------------------------------------------------------------*/
+
+ pos = ipos[0];
+ ipos[nb_track] = pos;
+
+ for (i = 1; i < nb_track; i++)
+ {
+ pos++;
+
+ if (pos >= nb_track)
+ {
+ pos = 0;
+ }
+ ipos[ i] = pos;
+ ipos[ i + nb_track] = pos;
+ }
+
+ return;
+}
+
diff --git a/media/codecs/amrnb/enc/src/set_sign.h b/media/codecs/amrnb/enc/src/set_sign.h
new file mode 100644
index 0000000..7b0185a
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/set_sign.h
@@ -0,0 +1,127 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/set_sign.h
+
+ Date: 08/11/2000
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description: Changed function prototype for set_sign12k2(); pointer to
+ overflow flag is passed in as a parameter.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the set_sign() and set_sign12k2() function.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef SET_SIGN_H
+#define SET_SIGN_H "@(#)$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "basicop_malloc.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void set_sign(Word16 dn[], /* i/o : correlation between target and h[] */
+ Word16 sign[], /* o : sign of dn[] */
+ Word16 dn2[], /* o : maximum of correlation in each track. */
+ Word16 n /* i : # of maximum correlations in dn2[] */
+ );
+
+ void set_sign12k2(
+ Word16 dn[], /* i/o : correlation between target and h[] */
+ Word16 cn[], /* i : residual after long term prediction */
+ Word16 sign[], /* o : sign of d[n] */
+ Word16 pos_max[], /* o : position of maximum correlation */
+ Word16 nb_track, /* i : number of tracks tracks */
+ Word16 ipos[], /* o : starting position for each pulse */
+ Word16 step, /* i : the step size in the tracks */
+ Flag *pOverflow /* i/o : overflow flag */
+ );
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SET_SIGN_H_ */
diff --git a/media/codecs/amrnb/enc/src/sid_sync.cpp b/media/codecs/amrnb/enc/src/sid_sync.cpp
new file mode 100644
index 0000000..3e744f6
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/sid_sync.cpp
@@ -0,0 +1,544 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/src/sid_sync.c
+ Functions: sid_sync_init
+ sid_sync_reset
+ sid_sync_exit
+ sid_sync_set_handover_debt
+ sid_sync
+
+ Date: 03/13/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Changed type definition of state pointer to 'void' for
+ sid_sync_init, sid_sync_reset, sid_sync_exit, and sid_sync.
+ Updated to PV coding template.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that initialize, reset, exit, and perform
+ SID synchronization.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "mode.h"
+#include "sid_sync.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; [Define module specific macros here]
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; [Include all pre-processor statements here. Include conditional
+; compile variables also.]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; [List function prototypes here]
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; [Variable declaration - defined here and used outside this module]
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: sid_sync_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer containing a pointer to the state structure used for
+ SID synchronization (void)
+
+ Outputs:
+ None
+
+ Returns:
+ return_value = status of sid_sync_reset function; -1, if state is pointing
+ to a NULL address (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function initialize one instance of the sid_sync module. It stores
+ the pointer to state struct in *st. This pointer has to be passed to sid_sync
+ in each call. This function returns 0 on success, otherwise, -1.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sid_sync.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 sid_sync_init(void **state)
+{
+ sid_syncState* s;
+
+ if (state == NULL)
+ {
+ /* fprintf(stderr, "sid_sync_init:invalid state parameter\n"); */
+ return -1;
+ }
+
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (sid_syncState *)
+ malloc(sizeof(sid_syncState))) == NULL)
+ {
+ /* fprintf(stderr,
+ "sid_sync_init: "
+ "can not malloc state structure\n"); */
+ return -1;
+ }
+ s->sid_update_rate = 8;
+
+ *state = (void *)s;
+
+ return(sid_sync_reset(s));
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: sid_sync_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to the state structure used for SID synchronization (void)
+
+ Outputs:
+ None
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs a reset of the sid_sync module by setting the state
+ memory to zero.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sid_sync.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+Word16 sid_sync_reset(void *st)
+{
+ sid_syncState *state = (sid_syncState *) st;
+
+ state->sid_update_counter = 3;
+ state->sid_handover_debt = 0;
+ state->prev_ft = TX_SPEECH_GOOD;
+
+ return 0;
+}
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: sid_sync_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer containing a pointer to the state structure used for
+ SID synchronization (void)
+
+ Outputs:
+ None
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function frees up the state structure used by sid_sync function. It
+ stores NULL in *state.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sid_sync.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void sid_sync_exit(void **state)
+{
+ sid_syncState **st = (sid_syncState **) state;
+
+ if (st == NULL || *st == NULL)
+ {
+ return;
+ }
+
+ /* deallocate memory */
+ free(*st);
+ *st = NULL;
+
+ return;
+
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: sid_sync_set_handover_debt
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to the state structure used for SID synchronization
+ (sid_syncState)
+ debtFrames = number of handover debt frames (Word16)
+
+ Outputs:
+ st->sid_handover_debt is set to debtFrames
+
+ Returns:
+ return_value = 0
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function updates the handover debt to debtFrames. Extra SID_UPD are
+ scheduled to update remote decoder CNI states, right after an handover.
+ This is primarily for use on MS UL side.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sid_sync.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void sid_sync_set_handover_debt(sid_syncState *st,
+ Word16 debtFrames)
+{
+ /* debtFrames >= 0 */
+ st->sid_handover_debt = debtFrames;
+ return;
+}
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: sid_sync
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to the state structure used for SID synchronization
+ (sid_syncState)
+ mode = codec mode (enum Mode)
+ tx_frame_type = pointer to TX frame type store (enum TXFrameType)
+
+ Outputs:
+ tx_frame_type contains the new TX frame type
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs SID frame synchronization to ensure that the mode
+ only switches to a neighbouring mode.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sid_sync.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+void sid_sync(void *state,
+ enum Mode mode,
+ enum TXFrameType *tx_frame_type)
+{
+
+ sid_syncState *st = (sid_syncState *) state;
+
+ if (mode == MRDTX)
+ {
+
+ st->sid_update_counter--;
+
+ if (st->prev_ft == TX_SPEECH_GOOD)
+ {
+ *tx_frame_type = TX_SID_FIRST;
+ st->sid_update_counter = 3;
+ }
+ else
+ {
+ /* TX_SID_UPDATE or TX_NO_DATA */
+ if ((st->sid_handover_debt > 0) &&
+ (st->sid_update_counter > 2))
+ {
+ /* ensure extra updates are properly delayed after
+ a possible SID_FIRST */
+ *tx_frame_type = TX_SID_UPDATE;
+ st->sid_handover_debt--;
+ }
+ else
+ {
+ if (st->sid_update_counter == 0)
+ {
+ *tx_frame_type = TX_SID_UPDATE;
+ st->sid_update_counter = st->sid_update_rate;
+ }
+ else
+ {
+ *tx_frame_type = TX_NO_DATA;
+ }
+ }
+ }
+ }
+ else
+ {
+ st->sid_update_counter = st->sid_update_rate ;
+ *tx_frame_type = TX_SPEECH_GOOD;
+ }
+ st->prev_ft = *tx_frame_type;
+}
+
diff --git a/media/codecs/amrnb/enc/src/sid_sync.h b/media/codecs/amrnb/enc/src/sid_sync.h
new file mode 100644
index 0000000..c3cb1cf
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/sid_sync.h
@@ -0,0 +1,147 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm-amr/c/include/sid_sync.h
+
+ Date: 03/13/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Added PV coding template sections to 3GPP version 3.2.0.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains the type definition and function prototypes used by the
+ SID synchronization functions.
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef _SID_SYNC_H_
+#define _SID_SYNC_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "frame.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+#define sid_sync_h "$Id $"
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Word16 sid_update_rate; /* Send SID Update every sid_update_rate frame */
+ Word16 sid_update_counter; /* Number of frames since last SID */
+ Word16 sid_handover_debt; /* Number of extra SID_UPD frames to schedule*/
+ enum TXFrameType prev_ft;
+ } sid_syncState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /* initialize one instance of the sid_sync module
+ Stores pointer to state struct in *st. This pointer has to
+ be passed to sid_sync in each call.
+ returns 0 on success
+ */
+ Word16 sid_sync_init(void **st);
+
+ /* reset of sid_sync module (i.e. set state memory to zero)
+ returns 0 on success
+ */
+ Word16 sid_sync_reset(void *st);
+
+ /* de-initialize sid_sync module (i.e. free status struct)
+ stores NULL in *st
+ */
+ void sid_sync_exit(void **st);
+
+ /* update handover debt
+ debtFrames extra SID_UPD are scheduled .
+ to update remote decoder CNI states, right after an handover.
+ (primarily for use on MS UL side )
+ */
+ void sid_sync_set_handover_debt(sid_syncState *st, /* i/o: sid_sync state */
+ Word16 debtFrames);
+
+ /* To ensure that the mode only switches to a neighbouring mode */
+ void sid_sync(void *st ,
+ enum Mode mode,
+ enum TXFrameType *tx_frame_type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SID_SYNC_H_ */
diff --git a/media/codecs/amrnb/enc/src/sp_enc.cpp b/media/codecs/amrnb/enc/src/sp_enc.cpp
new file mode 100644
index 0000000..77ae9de
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/sp_enc.cpp
@@ -0,0 +1,754 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/sp_enc.c
+ Funtions: GSMInitEncode
+ Speech_Encode_Frame_reset
+ GSMEncodeFrameExit
+ Speech_Encode_Frame_First
+ GSMEncodeFrame
+
+ Date: 02/07/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Cleaned up INCLUDES. removed inclusion of basic_op.h and count.h.
+
+
+ Description: Revert back to Speech_Encode_Frame_reset() and
+ Speech_Encode_Frame_First
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ These functions comprise the pre filtering and encoding of one speech frame.
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "sp_enc.h"
+#include "typedef.h"
+#include "cnst.h"
+#include "set_zero.h"
+#include "pre_proc.h"
+#include "prm2bits.h"
+#include "mode.h"
+#include "cod_amr.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: GSMInitEncode
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+ Inputs:
+ state = pointer to an array of pointers to structures of type
+ Speech_Decode_FrameState
+ dtx = flag to turn off or turn on DTX (Flag)
+ id = pointer to an array whose contents are of type char
+
+ Outputs:
+ pre_state field of the structure pointed to by the pointer pointed to
+ by state is set to NULL
+ cod_amr_state field of the structure pointed to by the pointer pointed to
+ by state is set to NULL
+ dtx field of the structure pointed to by the pointer pointed to by state
+ is set to the input dtx
+
+ Returns:
+ return_value = set to zero, if initialization was successful; -1,
+ otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function allocates memory for filter structure and initializes state
+ memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+ Note: Original function name of Speech_Encode_Frame_init was changed to
+ GSMInitEncode in the Code section.
+
+int Speech_Encode_Frame_init (void **state_data,
+ Flag dtx,
+ char *id)
+{
+ Speech_Encode_FrameState* s;
+
+ if (state_data == NULL){
+ fprintf(stderr, "Speech_Encode_Frame_init: invalid parameter\n");
+ return -1;
+ }
+ *state_data = NULL;
+
+ // allocate memory
+ if ((s= (Speech_Encode_FrameState *) malloc(sizeof(Speech_Encode_FrameState))) == NULL){
+ fprintf(stderr, "Speech_Encode_Frame_init: can not malloc state "
+ "structure\n");
+ return -1;
+ }
+
+ s->complexityCounter = getCounterId(id);
+
+ s->pre_state = NULL;
+ s->cod_amr_state = NULL;
+ s->dtx = dtx;
+
+ if (Pre_Process_init(&s->pre_state) ||
+ cod_amr_init(&s->cod_amr_state, s->dtx)) {
+ GSMEncodeFrameExit(&s);
+ return -1;
+ }
+
+ Speech_Encode_Frame_reset(s);
+ *state_data = (void *)s;
+
+ return 0;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 GSMInitEncode(void **state_data,
+ Flag dtx,
+ Word8 *id)
+{
+ Speech_Encode_FrameState* s;
+
+ OSCL_UNUSED_ARG(id);
+
+ if (state_data == NULL)
+ {
+ /* fprintf(stderr, "Speech_Encode_Frame_init: invalid parameter\n"); */
+ return -1;
+ }
+ *state_data = NULL;
+
+ /* allocate memory */
+ if ((s = (Speech_Encode_FrameState *) malloc(sizeof(Speech_Encode_FrameState))) == NULL)
+ {
+ /* fprintf(stderr, "Speech_Encode_Frame_init: can not malloc state "
+ "structure\n"); */
+ return -1;
+ }
+
+ s->pre_state = NULL;
+ s->cod_amr_state = NULL;
+ s->dtx = dtx;
+
+ if (Pre_Process_init(&s->pre_state) ||
+ cod_amr_init(&s->cod_amr_state, s->dtx))
+ {
+ Speech_Encode_FrameState** temp = &s;
+ GSMEncodeFrameExit((void**)temp);
+ return -1;
+ }
+
+ Speech_Encode_Frame_reset(s);
+ *state_data = (void *)s;
+
+ return 0;
+}
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Speech_Encode_Frame_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to structures of type Speech_Decode_FrameState
+
+ Outputs:
+ None
+
+ Returns:
+ return_value = set to zero if reset was successful; -1, otherwise (int)
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function resets state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Speech_Encode_Frame_reset (void *state_data)
+{
+
+ Speech_Encode_FrameState *state =
+ (Speech_Encode_FrameState *) state_data;
+
+ if (state_data == NULL){
+ fprintf(stderr, "Speech_Encode_Frame_reset
+ : invalid parameter\n");
+ return -1;
+ }
+
+ Pre_Process_reset(state->pre_state);
+ cod_amr_reset(state->cod_amr_state);
+
+ setCounter(state->complexityCounter);
+ Init_WMOPS_counter();
+ setCounter(0); // set counter to global counter
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 Speech_Encode_Frame_reset(void *state_data)
+{
+
+ Speech_Encode_FrameState *state =
+ (Speech_Encode_FrameState *) state_data;
+
+ if (state_data == NULL)
+ {
+ /* fprintf(stderr, "Speech_Encode_Frame_reset
+ : invalid parameter\n"); */
+ return -1;
+ }
+
+ Pre_Process_reset(state->pre_state);
+ cod_amr_reset(state->cod_amr_state);
+
+ return 0;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: GSMEncodeFrameExit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to a pointer to a structure of type cod_amrState
+
+ Outputs:
+ state points to a NULL address
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function frees the memory used for state memory.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Note: Original function name of Speech_Encode_Frame_exit was changed to
+ GSMEncodeFrameExit in the Code section.
+
+void Speech_Encode_Frame_exit (void **state_data)
+{
+
+ Speech_Encode_FrameState **state =
+ (Speech_Encode_FrameState **) state_data;
+
+ if (state == NULL || *state == NULL)
+ return;
+
+ Pre_Process_exit(&(*state)->pre_state);
+ cod_amr_exit(&(*state)->cod_amr_state);
+
+ setCounter((*state)->complexityCounter);
+ WMOPS_output(0);
+ setCounter(0); // set counter to global counter
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void GSMEncodeFrameExit(void **state_data)
+{
+
+ Speech_Encode_FrameState **state =
+ (Speech_Encode_FrameState **) state_data;
+
+ if (state == NULL || *state == NULL)
+ return;
+
+ Pre_Process_exit(&(*state)->pre_state);
+ cod_amr_exit(&(*state)->cod_amr_state);
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: Speech_Encode_Frame_First
+------------------------------------------------------------------------------
+
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to a structure of type Speech_Encode_FrameState that contains
+ the post filter states
+ new_speech = pointer to buffer of length L_FRAME that contains
+ the speech input (Word16)
+
+ Outputs:
+ The structure of type Speech_Encode_FrameState pointed to by st is updated.
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function encodes the first frame of speech. It calls the pre-processing
+ filter and the first frame encoder.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int Speech_Encode_Frame_First (
+ Speech_Encode_FrameState *st, // i/o : post filter states
+ Word16 *new_speech) // i : speech input
+{
+#if !defined(NO13BIT)
+ Word16 i;
+#endif
+
+ setCounter(st->complexityCounter);
+
+#if !defined(NO13BIT)
+ // Delete the 3 LSBs (13-bit input)
+ for (i = 0; i < L_NEXT; i++)
+ {
+ new_speech[i] = new_speech[i] & 0xfff8;
+ }
+#endif
+
+ // filter + downscaling
+ Pre_Process (st->pre_state, new_speech, L_NEXT);
+
+ cod_amr_first(st->cod_amr_state, new_speech);
+
+ Init_WMOPS_counter (); // reset WMOPS counter for the new frame
+
+ return 0;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void Speech_Encode_Frame_First(
+ Speech_Encode_FrameState *st, /* i/o : post filter states */
+ Word16 *new_speech) /* i : speech input */
+{
+#if !defined(NO13BIT)
+ Word16 i;
+#endif
+
+#if !defined(NO13BIT)
+ /* Delete the 3 LSBs (13-bit input) */
+ for (i = 0; i < L_NEXT; i++)
+ {
+ new_speech[i] = new_speech[i] & 0xfff8;
+ }
+#endif
+
+ /* filter + downscaling */
+ Pre_Process(st->pre_state, new_speech, L_NEXT);
+
+ cod_amr_first(st->cod_amr_state, new_speech);
+
+ return;
+}
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: cod_amr
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state_data = a void pointer to the post filter states
+ mode = AMR mode of type enum Mode
+ new_speech = pointer to buffer of length L_FRAME that contains
+ the speech input of type Word16
+ serial = pointer to the serial bit stream of type Word16
+ usedMode = pointer to the used mode of type enum Mode
+
+ Outputs:
+ serial -> encoded serial bit stream
+ The value pointed to by usedMode is updated.
+
+ Returns:
+ return_value = 0 (int)
+
+ Global Variables Used:
+ None.
+
+ Local Variables Needed:
+ None.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function is the entry point to the GSM AMR encoder. The following
+ operations are performed to generate one encoded frame: First, the incoming
+ audio samples are passed through the pre-processing filter where they are
+ filtered and downscaled. A call is then made to the main encoder cod_amr().
+ This generates the set of encoded parameters which include the LSP, adaptive
+ codebook, and fixed codebook quantization indices (addresses and gains). The
+ generated parameters are then converted to serial bits.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ sp_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+ Note: Original function name of Speech_Encode_Frame was changed to
+ GSMEncodeFrame in the Code section.
+
+int Speech_Encode_Frame (
+ void *state_data, // i/o : post filter states
+ enum Mode mode, // i : speech coder mode
+ Word16 *new_speech, // i : speech input
+ Word16 *serial, // o : serial bit stream
+ enum Mode *usedMode // o : used speech coder mode
+ )
+{
+
+ Speech_Encode_FrameState *st =
+ (Speech_Encode_FrameState *) state_data;
+
+ Word16 prm[MAX_PRM_SIZE]; // Analysis parameters
+ Word16 syn[L_FRAME]; // Buffer for synthesis speech
+ Word16 i;
+
+ setCounter(st->complexityCounter);
+ Reset_WMOPS_counter (); // reset WMOPS counter for the new frame
+ // initialize the serial output frame to zero
+ for (i = 0; i < MAX_SERIAL_SIZE; i++)
+ {
+ serial[i] = 0;
+ }
+#if !defined(NO13BIT)
+ // Delete the 3 LSBs (13-bit input)
+ for (i = 0; i < L_FRAME; i++)
+ {
+ new_speech[i] = new_speech[i] & 0xfff8;
+
+
+ }
+#endif
+
+ // filter + downscaling
+ Pre_Process (st->pre_state, new_speech, L_FRAME);
+
+ // Call the speech encoder
+ cod_amr(st->cod_amr_state, mode, new_speech, prm, usedMode, syn);
+
+ // Parameters to serial bits
+ Prm2bits (*usedMode, prm, &serial[0]);
+
+ fwc();
+ setCounter(0); // set counter to global counter
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void GSMEncodeFrame(
+ void *state_data, /* i/o : post filter states */
+ enum Mode mode, /* i : speech coder mode */
+ Word16 *new_speech, /* i : speech input */
+ Word16 *serial, /* o : serial bit stream */
+ enum Mode *usedMode /* o : used speech coder mode */
+)
+{
+
+ Speech_Encode_FrameState *st =
+ (Speech_Encode_FrameState *) state_data;
+
+ Word16 prm[MAX_PRM_SIZE]; /* Analysis parameters. */
+ Word16 syn[L_FRAME]; /* Buffer for synthesis speech */
+ Word16 i;
+
+ /* initialize the serial output frame to zero */
+ for (i = 0; i < MAX_SERIAL_SIZE; i++)
+ {
+ serial[i] = 0;
+ }
+#if !defined(NO13BIT)
+ /* Delete the 3 LSBs (13-bit input) */
+ for (i = 0; i < L_FRAME; i++)
+ {
+ new_speech[i] = new_speech[i] & 0xfff8;
+ }
+#endif
+
+ /* filter + downscaling */
+ Pre_Process(st->pre_state, new_speech, L_FRAME);
+
+ /* Call the speech encoder */
+ cod_amr(st->cod_amr_state, mode, new_speech, prm, usedMode, syn);
+
+ /* Parameters to serial bits */
+ Prm2bits(*usedMode, prm, &serial[0]);
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/sp_enc.h b/media/codecs/amrnb/enc/src/sp_enc.h
new file mode 100644
index 0000000..8eb2a9b
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/sp_enc.h
@@ -0,0 +1,154 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/src/include/sp_enc.h
+
+ Date: 02/07/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template. Changed the function names of
+ Speech_Encode_Frame_reset and Speech_Encode_Frame_first to
+ GSMEncodeFrameReset and GSMEncodeFrameFirst respectively for
+ consistency.
+
+ Description: Reverted back to old function names Speech_Encode_Frame_reset()
+ and Speech_Encode_Frame_First()
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : sp_enc.h
+ Purpose : Encoding of one speech frame
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef sp_enc_h
+#define sp_enc_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "cnst.h"
+#include "pre_proc.h"
+#include "mode.h"
+#include "cod_amr.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; [Define module specific macros here]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; [Include all pre-processor statements here.]
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; [Declare variables used in this module but defined elsewhere]
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef struct
+ {
+ Pre_ProcessState *pre_state;
+ cod_amrState *cod_amr_state;
+ Flag dtx;
+ } Speech_Encode_FrameState;
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; [List function prototypes here]
+ ----------------------------------------------------------------------------*/
+ /* initialize one instance of the speech encoder
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to Speech_Encode_Frame in each call.
+ returns 0 on success */
+ Word16 GSMInitEncode(void **state_data,
+ Flag dtx,
+ Word8 *id);
+
+
+ /* reset speech encoder (i.e. set state memory to zero)
+ returns 0 on success */
+ Word16 Speech_Encode_Frame_reset(void *state_data);
+
+ /* de-initialize speech encoder (i.e. free status struct)
+ stores NULL in *s */
+ void GSMEncodeFrameExit(void **state_data);
+
+ void Speech_Encode_Frame_First(
+ Speech_Encode_FrameState *st, /* i/o : post filter states */
+ Word16 *new_speech); /* i : speech input */
+
+ void GSMEncodeFrame(
+ void *state_data, /* i/o : encoder states */
+ enum Mode mode, /* i : speech coder mode */
+ Word16 *new_speech, /* i : input speech */
+ Word16 *serial, /* o : serial bit stream */
+ enum Mode *usedMode /* o : used speech coder mode */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _sp_enc_h_ */
+
diff --git a/media/codecs/amrnb/enc/src/spreproc.cpp b/media/codecs/amrnb/enc/src/spreproc.cpp
new file mode 100644
index 0000000..71d645a
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/spreproc.cpp
@@ -0,0 +1,234 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/spreproc.c
+ Functions: subframePreProc
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Eliminated unnecessary use of the sub() function.
+
+ Description:
+ 1. Replaced copy() and for-loop with more efficient memcpy().
+ 2. Eliminated unused include file copy.h.
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "spreproc.h"
+#include "typedef.h"
+#include "weight_a.h"
+#include "syn_filt.h"
+#include "residu.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: subframePreProc
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ mode -- enum Mode -- coder mode
+ gamma1 -- const Word16 array -- spectral exp. factor 1
+ gamma1_12k2 -- const Word16 array -- spectral exp. factor 1 for EFR
+ gamma2 -- const Word16 array -- spectral exp. factor 2
+ A -- Pointer to Word16 -- A(z) unquantized for the 4 subframes
+ Aq -- Pointer to Word16 -- A(z) quantized for the 4 subframes
+ speech -- Pointer to Word16 -- speech segment
+ mem_err -- Pointer to Word16 -- pointer to error signal
+ mem_w0 -- Pointer to Word16 -- memory of weighting filter
+ zero -- Pointer to Word16 -- pointer to zero vector
+
+ Outputs:
+ ai_zero -- Word16 array -- history of weighted synth. filter
+ exc -- Word16 array -- long term prediction residual
+ h1 -- Word16 array -- impulse response
+ xn -- Word16 array -- target vector for pitch search
+ res2 -- Word16 array -- long term prediction residual
+ error -- Word16 array -- error of LPC synthesis filter
+
+ Returns:
+ Zero
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ spreproc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void subframePreProc(
+ enum Mode mode, /* i : coder mode */
+ const Word16 gamma1[], /* i : spectral exp. factor 1 */
+ const Word16 gamma1_12k2[],/* i : spectral exp. factor 1 for EFR */
+ const Word16 gamma2[], /* i : spectral exp. factor 2 */
+ Word16 *A, /* i : A(z) unquantized for the 4 subframes */
+ Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
+ Word16 *speech, /* i : speech segment */
+ Word16 *mem_err, /* i : pointer to error signal */
+ Word16 *mem_w0, /* i : memory of weighting filter */
+ Word16 *zero, /* i : pointer to zero vector */
+ Word16 ai_zero[], /* o : history of weighted synth. filter */
+ Word16 exc[], /* o : long term prediction residual */
+ Word16 h1[], /* o : impulse response */
+ Word16 xn[], /* o : target vector for pitch search */
+ Word16 res2[], /* o : long term prediction residual */
+ Word16 error[] /* o : error of LPC synthesis filter */
+)
+{
+ Word16 Ap1[MP1]; /* A(z) with spectral expansion */
+ Word16 Ap2[MP1]; /* A(z) with spectral expansion */
+ const Word16 *g1; /* Pointer to correct gammma1 vector */
+
+ /* mode specific pointer to gamma1 values */
+ if (mode == MR122 || mode == MR102)
+ {
+ g1 = gamma1_12k2;
+ }
+ else
+ {
+ g1 = gamma1;
+ }
+
+ /* Find the weighted LPC coefficients for the weighting filter. */
+ Weight_Ai(A, g1, Ap1);
+ Weight_Ai(A, gamma2, Ap2);
+
+ memcpy(ai_zero, Ap1, (M + 1)*sizeof(Word16));
+
+
+ Syn_filt(Aq, ai_zero, h1, L_SUBFR, zero, 0);
+ Syn_filt(Ap2, h1, h1, L_SUBFR, zero, 0);
+
+ /*
+ *
+ * Find the target vector for pitch search:
+ *
+ */
+
+ /* LPC residual */
+ Residu(Aq, speech, res2, L_SUBFR);
+
+ memcpy(exc, res2, L_SUBFR*sizeof(Word16));
+
+ Syn_filt(Aq, exc, error, L_SUBFR, mem_err, 0);
+
+ Residu(Ap1, error, xn, L_SUBFR);
+
+ /* target signal xn[]*/
+ Syn_filt(Ap2, xn, xn, L_SUBFR, mem_w0, 0);
+
+ return;
+
+}
diff --git a/media/codecs/amrnb/enc/src/spreproc.h b/media/codecs/amrnb/enc/src/spreproc.h
new file mode 100644
index 0000000..77d35fc
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/spreproc.h
@@ -0,0 +1,135 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/spreproc.h
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, spreproc.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef spreproc_h
+#define spreproc_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "cnst.h"
+#include "mode.h"
+#include "typedef.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ void subframePreProc(
+ enum Mode mode, /* i : coder mode */
+ const Word16 gamma1[], /* i : spectral exp. factor 1 */
+ const Word16 gamma1_12k2[],/* i : spectral exp. factor 1 for EFR */
+ const Word16 gamma2[], /* i : spectral exp. factor 2 */
+ Word16 *A, /* i : A(z) unquantized for the 4 subframes */
+ Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
+ Word16 *speech, /* i : speech segment */
+ Word16 *mem_err, /* i : pointer to error signal */
+ Word16 *mem_w0, /* i : memory of weighting filter */
+ Word16 *zero, /* i : pointer to zero vector */
+ Word16 ai_zero[], /* o : history of weighted synth. filter */
+ Word16 exc[], /* o : long term prediction residual */
+ Word16 h1[], /* o : impulse response */
+ Word16 xn[], /* o : target vector for pitch search */
+ Word16 res2[], /* o : long term prediction residual */
+ Word16 error[] /* o : error of LPC synthesis filter */
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* spreproc_h */
+
diff --git a/media/codecs/amrnb/enc/src/spstproc.cpp b/media/codecs/amrnb/enc/src/spstproc.cpp
new file mode 100644
index 0000000..b9574aa
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/spstproc.cpp
@@ -0,0 +1,314 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/spstproc.c
+ Functions: subframePostProc
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Updated template used to PV coding template.
+ Changed to accept the pOverflow flag for EPOC compatibility.
+
+ Description:
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation
+ 4. Replaced loop counter with decrement loops
+
+ Description: Added casting to eliminate warnings
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ Subframe post processing
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "spstproc.h"
+#include "syn_filt.h"
+#include "cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: subframePostProc
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+ Inputs:
+ speech -- Pointer to Word16 -- speech segment
+ mode -- enum Mode -- coder mode
+ i_subfr -- Word16 -- Subframe nr
+ gain_pit -- Word16 -- Pitch gain Q14
+ gain_code -- Word16 -- Decoded innovation gain
+ Aq -- Pointer to Word16 -- A(z) quantized for the 4 subframes
+ synth -- Word16 Array -- Local synthesis
+ xn -- Word16 Array -- Target vector for pitch search
+ code -- Word16 Array -- Fixed codebook exitation
+ y1 -- Word16 Array -- Filtered adaptive exitation
+ y2 -- Word16 Array -- Filtered fixed codebook excitation
+ mem_syn -- Pointer to Word16 -- memory of synthesis filter
+
+ Outputs:
+ mem_syn -- Pointer to Word16 -- memory of synthesis filter
+ mem_err -- Pointer to Word16 -- pointer to error signal
+ mem_w0 -- Pointer to Word16 -- memory of weighting filter
+ exc -- Pointer to Word16 -- long term prediction residual
+ sharp -- Pointer to Word16 -- pitch sharpening value
+ pOverflow -- Pointer to Flag -- overflow indicator
+
+ Returns:
+ None
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ spstproc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void subframePostProc(
+ Word16 *speech, /* i : speech segment */
+ enum Mode mode, /* i : coder mode */
+ Word16 i_subfr, /* i : Subframe nr */
+ Word16 gain_pit, /* i : Pitch gain Q14 */
+ Word16 gain_code, /* i : Decoded innovation gain */
+ Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
+ Word16 synth[], /* i : Local snthesis */
+ Word16 xn[], /* i : Target vector for pitch search */
+ Word16 code[], /* i : Fixed codebook exitation */
+ Word16 y1[], /* i : Filtered adaptive exitation */
+ Word16 y2[], /* i : Filtered fixed codebook excitation */
+ Word16 *mem_syn, /* i/o : memory of synthesis filter */
+ Word16 *mem_err, /* o : pointer to error signal */
+ Word16 *mem_w0, /* o : memory of weighting filter */
+ Word16 *exc, /* o : long term prediction residual */
+ Word16 *sharp, /* o : pitch sharpening value */
+ Flag *pOverflow /* o : overflow indicator */
+)
+{
+ Word16 i;
+ Word16 j;
+ Word16 temp;
+ Word32 L_temp;
+ Word32 L_temp2;
+ Word16 tempShift;
+ Word16 kShift;
+ Word16 pitch_fac;
+ Word16 *p_exc;
+ Word16 *p_code;
+
+ OSCL_UNUSED_ARG(pOverflow);
+
+ if (mode != MR122)
+ {
+ tempShift = 1;
+ kShift = 16 - 2 - 1;
+ pitch_fac = gain_pit;
+ }
+ else
+ {
+ tempShift = 2;
+ kShift = 16 - 4 - 1;
+ pitch_fac = gain_pit >> 1;
+ }
+
+ /*------------------------------------------------------------*
+ * - Update pitch sharpening "sharp" with quantized gain_pit *
+ *------------------------------------------------------------*/
+
+ if (gain_pit < SHARPMAX)
+ {
+ *sharp = gain_pit;
+ }
+ else
+ {
+ *sharp = SHARPMAX;
+ }
+
+ /*------------------------------------------------------*
+ * - Find the total excitation *
+ * - find synthesis speech corresponding to exc[] *
+ * - update filters memories for finding the target *
+ * vector in the next subframe *
+ * (update error[-m..-1] and mem_w_err[]) *
+ *------------------------------------------------------*/
+
+ p_exc = &exc[ i_subfr];
+ p_code = &code[0];
+
+ for (i = L_SUBFR >> 1; i != 0 ; i--)
+ {
+ /* exc[i] = gain_pit*exc[i] + gain_code*code[i]; */
+
+ /*
+ * 12k2 others
+ * ---------------------------------
+ * exc Q0 Q0
+ * gain_pit Q14 Q14
+ * pitch_fac Q13 Q14
+ * product: Q14 Q15
+ *
+ * code Q12 Q13
+ * gain_code Q1 Q1
+ * product Q14 Q15
+ * sum Q14 Q15
+ *
+ * tempShift 2 1
+ * sum<<tempShift Q16 Q16
+ * result -> exc Q0 Q0
+ */
+ L_temp = ((Word32) * (p_exc++) * pitch_fac) << 1;
+ L_temp2 = ((Word32) * (p_exc--) * pitch_fac) << 1;
+ L_temp += ((Word32) * (p_code++) * gain_code) << 1;
+ L_temp2 += ((Word32) * (p_code++) * gain_code) << 1;
+ L_temp <<= tempShift;
+ L_temp2 <<= tempShift;
+ *(p_exc++) = (Word16)((L_temp + 0x08000L) >> 16);
+ *(p_exc++) = (Word16)((L_temp2 + 0x08000L) >> 16);
+
+ }
+
+ Syn_filt(
+ Aq,
+ &exc[i_subfr],
+ &synth[i_subfr],
+ L_SUBFR,
+ mem_syn,
+ 1);
+
+ for (i = L_SUBFR - M, j = 0; i < L_SUBFR; i++, j++)
+ {
+ mem_err[j] = speech[i_subfr + i] - synth[i_subfr + i];
+
+ /*
+ * 12k2 others
+ * ---------------------------------
+ * y1 Q0 Q0
+ * gain_pit Q14 Q14
+ * product Q15 Q15
+ * shifted prod. Q16 Q16
+ * temp Q0 Q0
+ *
+ * y2 Q10 Q12
+ * gain_code Q1 Q1
+ * product Q12 Q14
+ * kshift 4 2
+ * shifted prod. Q16 Q16
+ * k Q0 Q0
+ * mem_w0,xn,sum Q0 Q0
+ */
+
+ L_temp = ((Word32)y1[i] * gain_pit);
+ temp = (Word16)(L_temp >> 14);
+
+ L_temp = ((Word32)y2[i] * gain_code);
+ temp += (Word16)(L_temp >> kShift);
+
+ mem_w0[j] = xn[i] - temp;
+ }
+
+ return;
+}
diff --git a/media/codecs/amrnb/enc/src/spstproc.h b/media/codecs/amrnb/enc/src/spstproc.h
new file mode 100644
index 0000000..edc43e4
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/spstproc.h
@@ -0,0 +1,136 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/spstproc.h
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Placed header file in the proper template format. Added
+ parameter pOverflow for the basic math ops.
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file contains all the constant definitions and prototype definitions
+ needed by the file, spstproc.c
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef spstproc_h
+#define spstproc_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void subframePostProc(
+ Word16 *speech, /* i : speech segment */
+ enum Mode mode, /* i : coder mode */
+ Word16 i_subfr, /* i : Subframe nr */
+ Word16 gain_pit, /* i : Pitch gain Q14 */
+ Word16 gain_code, /* i : Decoded innovation gain */
+ Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
+ Word16 synth[], /* i : Local snthesis */
+ Word16 xn[], /* i : Target vector for pitch search */
+ Word16 code[], /* i : Fixed codebook exitation */
+ Word16 y1[], /* i : Filtered adaptive exitation */
+ Word16 y2[], /* i : Filtered fixed codebook excitation */
+ Word16 *mem_syn, /* i/o : memory of synthesis filter */
+ Word16 *mem_err, /* o : pointer to error signal */
+ Word16 *mem_w0, /* o : memory of weighting filter */
+ Word16 *exc, /* o : long term prediction residual */
+ Word16 *sharp, /* o : pitch sharpening value */
+ Flag *pOverflow
+ );
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* spstproc_h */
+
diff --git a/media/codecs/amrnb/enc/src/ton_stab.cpp b/media/codecs/amrnb/enc/src/ton_stab.cpp
new file mode 100644
index 0000000..455a510
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ton_stab.cpp
@@ -0,0 +1,801 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./audio/gsm-amr/c/src/ton_stab.c
+ Funtions:
+
+ Date: 02/06/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: For check_lsp()
+ 1. Eliminated unused include files.
+ 2. Replaced array addressing by pointers
+ 3. Eliminated math operations that unnecessary checked for
+ saturation this by evaluating the operands
+ For update_gp_clipping()
+ 1. Replaced copy() with more efficient memcpy()
+ 2. Replaced right shift function with right shift
+
+ Description: Replaced OSCL mem type functions and eliminated include
+ files that now are chosen by OSCL definitions
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description:
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include <stdlib.h>
+
+#include "ton_stab.h"
+#include "oper_32b.h"
+#include "cnst.h"
+#include "set_zero.h"
+#include "basic_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL VARIABLE DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ton_stab_init
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer to structure type tonStabState.
+
+ Outputs:
+ None
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: ton_stab_init
+ Purpose: Allocates state memory and initializes state memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ton_stab.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int ton_stab_init (tonStabState **state)
+{
+ tonStabState* s;
+
+ if (state == (tonStabState **) NULL){
+ // fprintf(stderr, "ton_stab_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ // allocate memory
+ if ((s= (tonStabState *) malloc(sizeof(tonStabState))) == NULL){
+ // fprintf(stderr, "ton_stab_init: can not malloc state structure\n");
+ return -1;
+ }
+
+ ton_stab_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 ton_stab_init(tonStabState **state)
+{
+ tonStabState* s;
+
+ if (state == (tonStabState **) NULL)
+ {
+ /* fprintf(stderr, "ton_stab_init: invalid parameter\n"); */
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (tonStabState *) malloc(sizeof(tonStabState))) == NULL)
+ {
+ /* fprintf(stderr, "ton_stab_init: can not malloc state structure\n"); */
+ return -1;
+ }
+
+ ton_stab_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+/****************************************************************************/
+
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ton_stab_reset
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ st = pointer to pointer to structure type tonStabState.
+
+ Outputs:
+ None
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: ton_stab_reset
+ Purpose: Initializes state memory to zero
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ton_stab.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+int ton_stab_reset (tonStabState *st)
+{
+ if (st == (tonStabState *) NULL){
+ // fprintf(stderr, "ton_stab_init: invalid parameter\n");
+ return -1;
+ }
+
+ // initialize tone stabilizer state
+ st->count = 0;
+ Set_zero(st->gp, N_FRAME); // Init Gp_Clipping
+
+ return 0;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 ton_stab_reset(tonStabState *st)
+{
+ if (st == (tonStabState *) NULL)
+ {
+ /* fprintf(stderr, "ton_stab_init: invalid parameter\n"); */
+ return -1;
+ }
+
+ /* initialize tone stabilizer state */
+ st->count = 0;
+ Set_zero(st->gp, N_FRAME); /* Init Gp_Clipping */
+
+ return 0;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: ton_stab_exit
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer to structure type tonStabState.
+
+ Outputs:
+ None
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: ton_stab_exit
+ Purpose: The memory used for state memory is freed
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ton_stab.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void ton_stab_exit (tonStabState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ // deallocate memory
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void ton_stab_exit(tonStabState **state)
+{
+ if (state == NULL || *state == NULL)
+ return;
+
+ /* deallocate memory */
+ free(*state);
+ *state = NULL;
+
+ return;
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: check_lsp
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer to structure type tonStabState.
+ lsp = pointer to unquantized LSPs of type Word16
+
+ Outputs:
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: check_lsp()
+ Purpose: Check the LSP's to detect resonances
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ton_stab.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 check_lsp(tonStabState *st, // i/o : State struct
+ Word16 *lsp // i : unquantized LSP's
+)
+{
+ Word16 i, dist, dist_min1, dist_min2, dist_th;
+
+ // Check for a resonance:
+ // Find minimum distance between lsp[i] and lsp[i+1]
+
+ dist_min1 = MAX_16;
+ for (i = 3; i < M-2; i++)
+ {
+ dist = sub(lsp[i], lsp[i+1]);
+
+ if (sub(dist, dist_min1) < 0)
+ {
+ dist_min1 = dist;
+ }
+ }
+
+ dist_min2 = MAX_16;
+ for (i = 1; i < 3; i++)
+ {
+ dist = sub(lsp[i], lsp[i+1]);
+
+ if (sub(dist, dist_min2) < 0)
+ {
+ dist_min2 = dist;
+ }
+ }
+
+ if (sub(lsp[1], 32000) > 0)
+ {
+ dist_th = 600;
+ }
+ else if (sub(lsp[1], 30500) > 0)
+ {
+ dist_th = 800;
+ }
+ else
+ {
+ dist_th = 1100;
+ }
+
+ if (sub(dist_min1, 1500) < 0 ||
+ sub(dist_min2, dist_th) < 0)
+ {
+ st->count = add(st->count, 1);
+ }
+ else
+ {
+ st->count = 0;
+ }
+
+ // Need 12 consecutive frames to set the flag
+ if (sub(st->count, 12) >= 0)
+ {
+ st->count = 12;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 check_lsp(tonStabState *st, /* i/o : State struct */
+ Word16 *lsp, /* i : unquantized LSP's */
+ Flag *pOverflow
+ )
+{
+ Word16 i;
+ Word16 dist;
+ Word16 dist_min1;
+ Word16 dist_min2;
+ Word16 dist_th;
+ Word16 *p_lsp = &lsp[3];
+ Word16 *p_lsp_1 = &lsp[4];
+
+ OSCL_UNUSED_ARG(pOverflow);
+ /* Check for a resonance: */
+ /* Find minimum distance between lsp[i] and lsp[i+1] */
+
+ dist_min1 = MAX_16;
+ for (i = 3; i < M - 2; i++)
+ {
+ dist = *(p_lsp++) - *(p_lsp_1++);
+
+ if (dist < dist_min1)
+ {
+ dist_min1 = dist;
+ }
+ }
+
+ dist_min2 = MAX_16;
+ p_lsp = &lsp[1];
+ p_lsp_1 = &lsp[2];
+
+ for (i = 1; i < 3; i++)
+ {
+ dist = *(p_lsp++) - *(p_lsp_1++);
+
+ if (dist < dist_min2)
+ {
+ dist_min2 = dist;
+ }
+ }
+
+ if (lsp[1] > 32000)
+ {
+ dist_th = 600;
+ }
+ else if (lsp[1] > 30500)
+ {
+ dist_th = 800;
+ }
+ else
+ {
+ dist_th = 1100;
+ }
+
+ if ((dist_min1 < 1500) || (dist_min2 < dist_th))
+ {
+ st->count++;
+ }
+ else
+ {
+ st->count = 0;
+ }
+
+ /* Need 12 consecutive frames to set the flag */
+ if (st->count >= 12)
+ {
+ st->count = 12;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: check_gp_clipping
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer to structure type tonStabState.
+ g_pitch = pitch gain of type Word16
+
+ Outputs:
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: Check_Gp_Clipping()
+ Purpose: Verify that the sum of the last (N_FRAME+1) pitch
+ gains is under a certain threshold.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ton_stab.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+Word16 check_gp_clipping(tonStabState *st, // i/o : State struct
+ Word16 g_pitch // i : pitch gain
+)
+{
+ Word16 i, sum;
+
+ sum = shr(g_pitch, 3); // Division by 8
+ for (i = 0; i < N_FRAME; i++)
+ {
+ sum = add(sum, st->gp[i]);
+ }
+
+ if (sub(sum, GP_CLIP) > 0)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+Word16 check_gp_clipping(tonStabState *st, /* i/o : State struct */
+ Word16 g_pitch, /* i : pitch gain */
+ Flag *pOverflow
+ )
+{
+ Word16 i;
+ Word16 sum;
+
+ sum = shr(g_pitch, 3, pOverflow); /* Division by 8 */
+ for (i = 0; i < N_FRAME; i++)
+ {
+ sum = add(sum, st->gp[i], pOverflow);
+ }
+
+ if (sum > GP_CLIP)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: update_gp_clipping
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ state = pointer to pointer to structure type tonStabState.
+ g_pitch = pitch gain of type Word16
+
+ Outputs:
+ pOverflow = 1 if there is an overflow else it is zero.
+
+ Returns:
+ None.
+
+ Global Variables Used:
+ None
+
+ Local Variables Needed:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Function: Update_Gp_Clipping()
+ Purpose: Update past pitch gain memory
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ None.
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ ton_stab.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+void update_gp_clipping(tonStabState *st, // i/o : State struct
+ Word16 g_pitch // i : pitch gain
+)
+{
+ Copy(&st->gp[1], &st->gp[0], N_FRAME-1);
+ st->gp[N_FRAME-1] = shr(g_pitch, 3);
+}
+
+------------------------------------------------------------------------------
+ RESOURCES USED [optional]
+
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ HEAP MEMORY USED: x bytes
+
+ STACK MEMORY USED: x bytes
+
+ CLOCK CYCLES: (cycle count equation for this function) + (variable
+ used to represent cycle count for each subroutine
+ called)
+ where: (cycle count variable) = cycle count for [subroutine
+ name]
+
+------------------------------------------------------------------------------
+ CAUTION [optional]
+ [State any special notes, constraints or cautions for users of this function]
+
+------------------------------------------------------------------------------
+*/
+
+void update_gp_clipping(tonStabState *st, /* i/o : State struct */
+ Word16 g_pitch, /* i : pitch gain */
+ Flag *pOverflow
+ )
+{
+ OSCL_UNUSED_ARG(pOverflow);
+ int i;
+ for (i = 0; i < N_FRAME - 1; i++)
+ {
+ st->gp[i] = st->gp[i+1];
+ }
+ st->gp[N_FRAME-1] = g_pitch >> 3;
+}
+
diff --git a/media/codecs/amrnb/enc/src/ton_stab.h b/media/codecs/amrnb/enc/src/ton_stab.h
new file mode 100644
index 0000000..fb06e64
--- /dev/null
+++ b/media/codecs/amrnb/enc/src/ton_stab.h
@@ -0,0 +1,155 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.073
+ ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: /audio/gsm_amr/c/include/ton_stab.h
+
+ Date: 02/05/2002
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description: Replaced "int" and/or "char" with OSCL defined types.
+
+ Description: Moved _cplusplus #ifdef after Include section.
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ File : ton_stab.h
+ Purpose : Tone stabilization routines
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef TON_STAB_H
+#define TON_STAB_H
+#define ton_stab_h "$Id $"
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "typedef.h"
+#include "mode.h"
+#include "cnst.h"
+
+/*--------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ /* state variable */
+ typedef struct
+ {
+ /* counters */
+ Word16 count;
+ /* gain history Q11 */
+ Word16 gp[N_FRAME];
+ } tonStabState;
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+ Word16 ton_stab_init(tonStabState **st);
+ /* initialize one instance of the pre processing state.
+ Stores pointer to filter status struct in *st. This pointer has to
+ be passed to ton_stab in each call.
+ returns 0 on success
+ */
+
+ Word16 ton_stab_reset(tonStabState *st);
+ /* reset of pre processing state (i.e. set state memory to zero)
+ returns 0 on success
+ */
+
+ void ton_stab_exit(tonStabState **st);
+ /* de-initialize pre processing state (i.e. free status struct)
+ stores NULL in *st
+ */
+
+ Word16 check_lsp(tonStabState *st, /* i/o : State struct */
+ Word16 *lsp, /* i : unquantized LSP's */
+ Flag *pOverflow
+ );
+
+ Word16 check_gp_clipping(tonStabState *st, /* i/o : State struct */
+ Word16 g_pitch, /* i : pitch gain */
+ Flag *pOverflow
+ );
+
+ void update_gp_clipping(tonStabState *st, /* i/o : State struct */
+ Word16 g_pitch, /* i : pitch gain */
+ Flag *pOverflow
+ );
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _TON_STAB_H_ */
+
+
+
+
diff --git a/media/codecs/amrnb/enc/test/AmrnbEncTestEnvironment.h b/media/codecs/amrnb/enc/test/AmrnbEncTestEnvironment.h
new file mode 100644
index 0000000..5a2fcd1
--- /dev/null
+++ b/media/codecs/amrnb/enc/test/AmrnbEncTestEnvironment.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AMRNBENC_TEST_ENVIRONMENT_H__
+#define __AMRNBENC_TEST_ENVIRONMENT_H__
+
+#include <gtest/gtest.h>
+
+#include <getopt.h>
+
+using namespace std;
+
+class AmrnbEncTestEnvironment : public ::testing::Environment {
+ public:
+ AmrnbEncTestEnvironment() : res("/data/local/tmp/") {}
+
+ // Parses the command line arguments
+ int initFromOptions(int argc, char **argv);
+
+ void setRes(const char *_res) { res = _res; }
+
+ const string getRes() const { return res; }
+
+ private:
+ string res;
+};
+
+int AmrnbEncTestEnvironment::initFromOptions(int argc, char **argv) {
+ static struct option options[] = {{"res", required_argument, 0, 'P'}, {0, 0, 0, 0}};
+
+ while (true) {
+ int index = 0;
+ int c = getopt_long(argc, argv, "P:", options, &index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'P':
+ setRes(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr,
+ "unrecognized option: %s\n\n"
+ "usage: %s <gtest options> <test options>\n\n"
+ "test options are:\n\n"
+ "-P, --path: Resource files directory location\n",
+ argv[optind ?: 1], argv[0]);
+ return 2;
+ }
+ return 0;
+}
+
+#endif // __AMRNBENC_TEST_ENVIRONMENT_H__
diff --git a/media/codecs/amrnb/enc/test/AmrnbEncoderTest.cpp b/media/codecs/amrnb/enc/test/AmrnbEncoderTest.cpp
new file mode 100644
index 0000000..fb72998
--- /dev/null
+++ b/media/codecs/amrnb/enc/test/AmrnbEncoderTest.cpp
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "AmrnbEncoderTest"
+
+#include <utils/Log.h>
+
+#include <audio_utils/sndfile.h>
+#include <stdio.h>
+
+#include "gsmamr_enc.h"
+
+#include "AmrnbEncTestEnvironment.h"
+
+#define OUTPUT_FILE "/data/local/tmp/amrnbEncode.out"
+
+constexpr int32_t kInputBufferSize = L_FRAME * 2; // 160 samples * 16-bit per sample.
+constexpr int32_t kOutputBufferSize = 1024;
+constexpr int32_t kNumFrameReset = 200;
+constexpr int32_t kMaxCount = 10;
+struct AmrNbEncState {
+ void *encCtx;
+ void *pidSyncCtx;
+};
+
+static AmrnbEncTestEnvironment *gEnv = nullptr;
+
+class AmrnbEncoderTest : public ::testing::TestWithParam<pair<string, int32_t>> {
+ public:
+ AmrnbEncoderTest() : mAmrEncHandle(nullptr) {}
+
+ ~AmrnbEncoderTest() {
+ if (mAmrEncHandle) {
+ free(mAmrEncHandle);
+ mAmrEncHandle = nullptr;
+ }
+ }
+
+ AmrNbEncState *mAmrEncHandle;
+ int32_t EncodeFrames(int32_t mode, FILE *fpInput, FILE *mFpOutput,
+ int32_t frameCount = INT32_MAX);
+};
+
+int32_t AmrnbEncoderTest::EncodeFrames(int32_t mode, FILE *fpInput, FILE *mFpOutput,
+ int32_t frameCount) {
+ int32_t frameNum = 0;
+ uint16_t inputBuf[kInputBufferSize];
+ uint8_t outputBuf[kOutputBufferSize];
+ while (frameNum < frameCount) {
+ int32_t bytesRead = fread(inputBuf, 1, kInputBufferSize, fpInput);
+ if (bytesRead != kInputBufferSize && !feof(fpInput)) {
+ ALOGE("Unable to read data from input file");
+ return -1;
+ } else if (feof(fpInput) && bytesRead == 0) {
+ break;
+ }
+ Frame_Type_3GPP frame_type = (Frame_Type_3GPP)mode;
+ int32_t bytesGenerated =
+ AMREncode(mAmrEncHandle->encCtx, mAmrEncHandle->pidSyncCtx, (Mode)mode,
+ (Word16 *)inputBuf, outputBuf, &frame_type, AMR_TX_WMF);
+ frameNum++;
+ if (bytesGenerated < 0) {
+ ALOGE("Error in encoging the file: Invalid output format");
+ return -1;
+ }
+
+ // Convert from WMF to RFC 3267 format.
+ if (bytesGenerated > 0) {
+ outputBuf[0] = ((outputBuf[0] << 3) | 4) & 0x7c;
+ }
+ fwrite(outputBuf, 1, bytesGenerated, mFpOutput);
+ }
+ return 0;
+}
+
+TEST_F(AmrnbEncoderTest, CreateAmrnbEncoderTest) {
+ mAmrEncHandle = (AmrNbEncState *)malloc(sizeof(AmrNbEncState));
+ ASSERT_NE(mAmrEncHandle, nullptr) << "Error in allocating memory to Codec handle";
+ for (int count = 0; count < kMaxCount; count++) {
+ int32_t status = AMREncodeInit(&mAmrEncHandle->encCtx, &mAmrEncHandle->pidSyncCtx, 0);
+ ASSERT_EQ(status, 0) << "Error creating AMR-NB encoder";
+ ALOGV("Successfully created encoder");
+ }
+ if (mAmrEncHandle) {
+ AMREncodeExit(&mAmrEncHandle->encCtx, &mAmrEncHandle->pidSyncCtx);
+ ASSERT_EQ(mAmrEncHandle->encCtx, nullptr) << "Error deleting AMR-NB encoder";
+ ASSERT_EQ(mAmrEncHandle->pidSyncCtx, nullptr) << "Error deleting AMR-NB encoder";
+ free(mAmrEncHandle);
+ mAmrEncHandle = nullptr;
+ ALOGV("Successfully deleted encoder");
+ }
+}
+
+TEST_P(AmrnbEncoderTest, EncodeTest) {
+ mAmrEncHandle = (AmrNbEncState *)malloc(sizeof(AmrNbEncState));
+ ASSERT_NE(mAmrEncHandle, nullptr) << "Error in allocating memory to Codec handle";
+ int32_t status = AMREncodeInit(&mAmrEncHandle->encCtx, &mAmrEncHandle->pidSyncCtx, 0);
+ ASSERT_EQ(status, 0) << "Error creating AMR-NB encoder";
+
+ string inputFile = gEnv->getRes() + GetParam().first;
+ FILE *fpInput = fopen(inputFile.c_str(), "rb");
+ ASSERT_NE(fpInput, nullptr) << "Error opening input file " << inputFile;
+
+ FILE *fpOutput = fopen(OUTPUT_FILE, "wb");
+ ASSERT_NE(fpOutput, nullptr) << "Error opening output file " << OUTPUT_FILE;
+
+ // Write file header.
+ fwrite("#!AMR\n", 1, 6, fpOutput);
+
+ int32_t mode = GetParam().second;
+ int32_t encodeErr = EncodeFrames(mode, fpInput, fpOutput);
+ ASSERT_EQ(encodeErr, 0) << "EncodeFrames returned error for Codec mode: " << mode;
+
+ fclose(fpOutput);
+ fclose(fpInput);
+
+ AMREncodeExit(&mAmrEncHandle->encCtx, &mAmrEncHandle->pidSyncCtx);
+ ASSERT_EQ(mAmrEncHandle->encCtx, nullptr) << "Error deleting AMR-NB encoder";
+ ASSERT_EQ(mAmrEncHandle->pidSyncCtx, nullptr) << "Error deleting AMR-NB encoder";
+ free(mAmrEncHandle);
+ mAmrEncHandle = nullptr;
+ ALOGV("Successfully deleted encoder");
+}
+
+TEST_P(AmrnbEncoderTest, ResetEncoderTest) {
+ mAmrEncHandle = (AmrNbEncState *)malloc(sizeof(AmrNbEncState));
+ ASSERT_NE(mAmrEncHandle, nullptr) << "Error in allocating memory to Codec handle";
+ int32_t status = AMREncodeInit(&mAmrEncHandle->encCtx, &mAmrEncHandle->pidSyncCtx, 0);
+ ASSERT_EQ(status, 0) << "Error creating AMR-NB encoder";
+
+ string inputFile = gEnv->getRes() + GetParam().first;
+ FILE *fpInput = fopen(inputFile.c_str(), "rb");
+ ASSERT_NE(fpInput, nullptr) << "Error opening input file " << inputFile;
+
+ FILE *fpOutput = fopen(OUTPUT_FILE, "wb");
+ ASSERT_NE(fpOutput, nullptr) << "Error opening output file " << OUTPUT_FILE;
+
+ // Write file header.
+ fwrite("#!AMR\n", 1, 6, fpOutput);
+
+ int32_t mode = GetParam().second;
+ // Encode kNumFrameReset first
+ int32_t encodeErr = EncodeFrames(mode, fpInput, fpOutput, kNumFrameReset);
+ ASSERT_EQ(encodeErr, 0) << "EncodeFrames returned error for Codec mode: " << mode;
+
+ status = AMREncodeReset(mAmrEncHandle->encCtx, mAmrEncHandle->pidSyncCtx);
+ ASSERT_EQ(status, 0) << "Error resting AMR-NB encoder";
+
+ // Start encoding again
+ encodeErr = EncodeFrames(mode, fpInput, fpOutput);
+ ASSERT_EQ(encodeErr, 0) << "EncodeFrames returned error for Codec mode: " << mode;
+
+ fclose(fpOutput);
+ fclose(fpInput);
+
+ AMREncodeExit(&mAmrEncHandle->encCtx, &mAmrEncHandle->pidSyncCtx);
+ ASSERT_EQ(mAmrEncHandle->encCtx, nullptr) << "Error deleting AMR-NB encoder";
+ ASSERT_EQ(mAmrEncHandle->pidSyncCtx, nullptr) << "Error deleting AMR-NB encoder";
+ free(mAmrEncHandle);
+ mAmrEncHandle = nullptr;
+ ALOGV("Successfully deleted encoder");
+}
+
+// TODO: Add more test vectors
+INSTANTIATE_TEST_SUITE_P(AmrnbEncoderTestAll, AmrnbEncoderTest,
+ ::testing::Values(make_pair("bbb_raw_1ch_8khz_s16le.raw", MR475),
+ make_pair("bbb_raw_1ch_8khz_s16le.raw", MR515),
+ make_pair("bbb_raw_1ch_8khz_s16le.raw", MR59),
+ make_pair("bbb_raw_1ch_8khz_s16le.raw", MR67),
+ make_pair("bbb_raw_1ch_8khz_s16le.raw", MR74),
+ make_pair("bbb_raw_1ch_8khz_s16le.raw", MR795),
+ make_pair("bbb_raw_1ch_8khz_s16le.raw", MR102),
+ make_pair("bbb_raw_1ch_8khz_s16le.raw", MR122),
+ make_pair("sinesweepraw.raw", MR475),
+ make_pair("sinesweepraw.raw", MR515),
+ make_pair("sinesweepraw.raw", MR59),
+ make_pair("sinesweepraw.raw", MR67),
+ make_pair("sinesweepraw.raw", MR74),
+ make_pair("sinesweepraw.raw", MR795),
+ make_pair("sinesweepraw.raw", MR102),
+ make_pair("sinesweepraw.raw", MR122)));
+
+int main(int argc, char **argv) {
+ gEnv = new AmrnbEncTestEnvironment();
+ ::testing::AddGlobalTestEnvironment(gEnv);
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = gEnv->initFromOptions(argc, argv);
+ if (status == 0) {
+ status = RUN_ALL_TESTS();
+ ALOGV("Test result = %d\n", status);
+ }
+ return status;
+}
diff --git a/media/codecs/amrnb/enc/test/Android.bp b/media/codecs/amrnb/enc/test/Android.bp
new file mode 100644
index 0000000..e8982fe
--- /dev/null
+++ b/media/codecs/amrnb/enc/test/Android.bp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_test {
+ name: "AmrnbEncoderTest",
+ gtest: true,
+
+ srcs: [
+ "AmrnbEncoderTest.cpp",
+ ],
+
+ static_libs: [
+ "libstagefright_amrnb_common",
+ "libstagefright_amrnbenc",
+ "libaudioutils",
+ "libsndfile",
+ ],
+
+ shared_libs: [
+ "liblog",
+ ],
+
+ cflags: [
+ "-Werror",
+ "-Wall",
+ ],
+
+ sanitize: {
+ cfi: true,
+ misc_undefined: [
+ "unsigned-integer-overflow",
+ "signed-integer-overflow",
+ ],
+ },
+}
diff --git a/media/codecs/amrnb/enc/test/AndroidTest.xml b/media/codecs/amrnb/enc/test/AndroidTest.xml
new file mode 100644
index 0000000..9fe61b1
--- /dev/null
+++ b/media/codecs/amrnb/enc/test/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for Amr-nb Encoder unit test">
+ <option name="test-suite-tag" value="AmrnbEncoderTest" />
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="AmrnbEncoderTest->/data/local/tmp/AmrnbEncoderTest" />
+ <option name="push-file"
+ key="https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrnb/enc/test/AmrnbEncoderTest.zip?unzip=true"
+ value="/data/local/tmp/AmrnbEncoderTestRes/" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="AmrnbEncoderTest" />
+ <option name="native-test-flag" value="-P /data/local/tmp/AmrnbEncoderTestRes/" />
+ </test>
+</configuration>
diff --git a/media/codecs/amrnb/enc/test/README.md b/media/codecs/amrnb/enc/test/README.md
new file mode 100644
index 0000000..e9d2c95
--- /dev/null
+++ b/media/codecs/amrnb/enc/test/README.md
@@ -0,0 +1,39 @@
+## Media Testing ##
+---
+#### AMR-NB Encoder :
+The Amr-Nb Encoder Test Suite validates the amrnb encoder available in libstagefright.
+
+Run the following steps to build the test suite:
+```
+m AmrnbEncoderTest
+```
+
+The 32-bit binaries will be created in the following path : ${OUT}/data/nativetest/
+
+The 64-bit binaries will be created in the following path : ${OUT}/data/nativetest64/
+
+To test 64-bit binary push binaries from nativetest64.
+```
+adb push ${OUT}/data/nativetest64/AmrnbEncoderTest/AmrnbEncoderTest /data/local/tmp/
+```
+
+To test 32-bit binary push binaries from nativetest.
+```
+adb push ${OUT}/data/nativetest/AmrnbEncoderTest/AmrnbEncoderTest /data/local/tmp/
+```
+
+The resource file for the tests is taken from [here](https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrnb/enc/test/AmrnbEncoderTest.zip). Download, unzip and push these files into device for testing.
+
+```
+adb push AmrnbEncoderTestRes/. /data/local/tmp/
+```
+
+usage: AmrnbEncoderTest -P \<path_to_folder\>
+```
+adb shell /data/local/tmp/AmrnbEncoderTest -P /data/local/tmp/AmrnbEncoderTestRes/
+```
+Alternatively, the test can also be run using atest command.
+
+```
+atest AmrnbEncoderTest -- --enable-module-dynamic-download=true
+```
diff --git a/media/codecs/amrnb/enc/test/amrnb_enc_test.cpp b/media/codecs/amrnb/enc/test/amrnb_enc_test.cpp
new file mode 100644
index 0000000..e2d198e
--- /dev/null
+++ b/media/codecs/amrnb/enc/test/amrnb_enc_test.cpp
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <stdint.h>
+#include <assert.h>
+#include "gsmamr_enc.h"
+
+enum {
+ kInputSize = 320, // 160 samples * 16-bit per sample.
+ kOutputSize = 1024
+};
+
+struct AmrNbEncState {
+ void *encCtx;
+ void *pidSyncCtx;
+};
+
+void usage(void) {
+ printf("Usage:\n");
+ printf("AMRNBEnc [options] <input file> <output file>\n");
+ printf("\n");
+ printf("Options +M* for setting compression bitrate mode, default is 4.75 kbps\n");
+ printf(" +M0 = 4.75 kbps\n");
+ printf(" +M1 = 5.15 kbps\n");
+ printf(" +M2 = 5.90 kbps\n");
+ printf(" +M3 = 6.70 kbps\n");
+ printf(" +M4 = 7.40 kbps\n");
+ printf(" +M5 = 7.95 kbps\n");
+ printf(" +M6 = 10.2 kbps\n");
+ printf(" +M7 = 12.2 kbps\n");
+ printf("\n");
+}
+
+int encode(int mode, const char *srcFile, const char *dstFile) {
+ int retVal = EXIT_SUCCESS;
+ FILE *fSrc = NULL;
+ FILE *fDst = NULL;
+ int frameNum = 0;
+ bool eofReached = false;
+ uint16_t *inputBuf = NULL;
+ uint8_t *outputBuf = NULL;
+ AmrNbEncState *amr = NULL;
+
+ clock_t start, finish;
+ double duration = 0.0;
+
+ // Open input file.
+ fSrc = fopen(srcFile, "rb");
+ if (fSrc == NULL) {
+ fprintf(stderr, "Error opening input file\n");
+ retVal = EXIT_FAILURE;
+ goto safe_exit;
+ }
+
+ // Open output file.
+ fDst = fopen(dstFile, "wb");
+ if (fDst == NULL) {
+ fprintf(stderr, "Error opening output file\n");
+ retVal = EXIT_FAILURE;
+ goto safe_exit;
+ }
+
+ // Allocate input buffer.
+ inputBuf = (uint16_t*) malloc(kInputSize);
+ assert(inputBuf != NULL);
+
+ // Allocate output buffer.
+ outputBuf = (uint8_t*) malloc(kOutputSize);
+ assert(outputBuf != NULL);
+
+ // Initialize encoder.
+ amr = (AmrNbEncState*) malloc(sizeof(AmrNbEncState));
+ AMREncodeInit(&amr->encCtx, &amr->pidSyncCtx, 0);
+
+ // Write file header.
+ fwrite("#!AMR\n", 1, 6, fDst);
+
+ while (1) {
+ // Read next input frame.
+ int bytesRead;
+ bytesRead = fread(inputBuf, 1, kInputSize, fSrc);
+ if (bytesRead != kInputSize && !feof(fSrc)) {
+ retVal = EXIT_FAILURE; // Invalid magic number.
+ fprintf(stderr, "Error reading input file\n");
+ goto safe_exit;
+ } else if (feof(fSrc) && bytesRead == 0) {
+ eofReached = true;
+ break;
+ }
+
+ start = clock();
+
+ // Encode the frame.
+ Frame_Type_3GPP frame_type = (Frame_Type_3GPP) mode;
+ int bytesGenerated;
+ bytesGenerated = AMREncode(amr->encCtx, amr->pidSyncCtx, (Mode)mode,
+ (Word16*)inputBuf, outputBuf, &frame_type,
+ AMR_TX_WMF);
+
+ // Convert from WMF to RFC 3267 format.
+ if (bytesGenerated > 0) {
+ outputBuf[0] = ((outputBuf[0] << 3) | 4) & 0x7c;
+ }
+
+ finish = clock();
+ duration += finish - start;
+
+ if (bytesGenerated < 0) {
+ retVal = EXIT_FAILURE;
+ fprintf(stderr, "Encoding error\n");
+ goto safe_exit;
+ }
+
+ frameNum++;
+ printf(" Frames processed: %d\n", frameNum);
+
+ // Write the output.
+ fwrite(outputBuf, 1, bytesGenerated, fDst);
+ }
+
+ // Dump the time taken by encode.
+ printf("\n%2.5lf seconds\n", (double)duration/CLOCKS_PER_SEC);
+
+safe_exit:
+
+ // Free the encoder instance.
+ if (amr) {
+ AMREncodeExit(&amr->encCtx, &amr->pidSyncCtx);
+ free(amr);
+ }
+
+ // Free input and output buffer.
+ free(inputBuf);
+ free(outputBuf);
+
+ // Close the input and output files.
+ if (fSrc) {
+ fclose(fSrc);
+ }
+ if (fDst) {
+ fclose(fDst);
+ }
+
+ return retVal;
+}
+
+int main(int argc, char *argv[]) {
+ Mode mode = MR475;
+ int retVal;
+ char *inFileName = NULL;
+ char *outFileName = NULL;
+ int arg, filename = 0;
+
+ if (argc < 3) {
+ usage();
+ return EXIT_FAILURE;
+ } else {
+ for (arg = 1; arg < argc; arg++) {
+ if (argv[arg][0] == '+') {
+ if (argv[arg][1] == 'M') {
+ switch (argv[arg][2]) {
+ case '0': mode = MR475;
+ break;
+ case '1': mode = MR515;
+ break;
+ case '2': mode = MR59;
+ break;
+ case '3': mode = MR67;
+ break;
+ case '4': mode = MR74;
+ break;
+ case '5': mode = MR795;
+ break;
+ case '6': mode = MR102;
+ break;
+ case '7': mode = MR122;
+ break;
+ default:
+ usage();
+ fprintf(stderr, "Invalid parameter '%s'.\n", argv[arg]);
+ return EXIT_FAILURE;
+ break;
+ }
+ } else {
+ usage();
+ fprintf(stderr, "Invalid parameter '%s'.\n", argv[arg]);
+ return EXIT_FAILURE;
+ }
+ } else {
+ switch (filename) {
+ case 0:
+ inFileName = argv[arg];
+ break;
+ case 1:
+ outFileName = argv[arg];
+ break;
+ default:
+ usage();
+ fprintf(stderr, "Invalid parameter '%s'.\n", argv[arg]);
+ return EXIT_FAILURE;
+ }
+ filename++;
+ }
+ }
+ }
+
+ retVal = encode(mode, inFileName, outFileName);
+ return retVal;
+}
+
diff --git a/media/codecs/amrnb/fuzzer/Android.bp b/media/codecs/amrnb/fuzzer/Android.bp
new file mode 100644
index 0000000..c1eaa53
--- /dev/null
+++ b/media/codecs/amrnb/fuzzer/Android.bp
@@ -0,0 +1,43 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+
+cc_fuzz {
+ name: "amrnb_dec_fuzzer",
+ host_supported: true,
+ srcs: [
+ "amrnb_dec_fuzzer.cpp",
+ ],
+ static_libs: [
+ "libstagefright_amrnbdec",
+ "libstagefright_amrnb_common",
+ "liblog",
+ ],
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
diff --git a/media/codecs/amrnb/fuzzer/README.md b/media/codecs/amrnb/fuzzer/README.md
new file mode 100644
index 0000000..7791b83
--- /dev/null
+++ b/media/codecs/amrnb/fuzzer/README.md
@@ -0,0 +1,62 @@
+# Fuzzer for libstagefright_amrnbdec decoder
+
+## Plugin Design Considerations
+The fuzzer plugin for AMR-NB is designed based on the understanding of the
+codec and tries to achieve the following:
+
+##### Maximize code coverage
+The configuration parameters are not hardcoded, but instead selected based on
+incoming data. This ensures more code paths are reached by the fuzzer.
+
+AMR-NB supports the following parameters:
+1. Stream format (parameter name: `input_format`)
+2. 3GPP frame type (parameter name: `frame_type`)
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `input_format` | 0. `MIME_IETF` 1. `IF2` | Bit 0 (LSB) of 1st byte of data. |
+| `frame_type` | 0. `AMR_475` 1. `AMR_515` 2. `AMR_59` 3. `AMR_67` 4. `AMR_74` 5. `AMR_795` 6. `AMR_102` 7. `AMR_122` | Bits 3, 4 and 5 of 1st byte of data. |
+
+
+This also ensures that the plugin is always deterministic for any given input.
+
+##### Maximize utilization of input data
+The plugin feeds the entire input data to the codec using a loop.
+If the decode operation was successful, the input is advanced by the frame size
+which is based on `input_format` and `frame_type` selected.
+If the decode operation was un-successful, the input is still advanced by frame size so
+that the fuzzer can proceed to feed the next frame.
+
+This ensures that the plugin tolerates any kind of input (empty, huge,
+malformed, etc) and doesnt `exit()` on any input and thereby increasing the
+chance of identifying vulnerabilities.
+
+## Build
+
+This describes steps to build amrnb_dec_fuzzer binary.
+
+### Android
+
+#### Steps to build
+Build the fuzzer
+```
+ $ mm -j$(nproc) amrnb_dec_fuzzer
+```
+
+#### Steps to run
+Create a directory CORPUS_DIR and copy some amrnb files to that folder
+Push this directory to device.
+
+To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/amrnb_dec_fuzzer/amrnb_dec_fuzzer CORPUS_DIR
+```
+To run on host
+```
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/amrnb_dec_fuzzer/amrnb_dec_fuzzer CORPUS_DIR
+```
+
+## References:
+ * http://llvm.org/docs/LibFuzzer.html
+ * https://github.com/google/oss-fuzz
diff --git a/media/codecs/amrnb/fuzzer/amrnb_dec_fuzzer.cpp b/media/codecs/amrnb/fuzzer/amrnb_dec_fuzzer.cpp
new file mode 100644
index 0000000..c7a7378
--- /dev/null
+++ b/media/codecs/amrnb/fuzzer/amrnb_dec_fuzzer.cpp
@@ -0,0 +1,96 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+#include <string.h>
+#include <algorithm>
+#include "gsmamr_dec.h"
+
+// Constants for AMR-NB
+constexpr int32_t kSamplesPerFrame = L_FRAME;
+constexpr int32_t kBitsPerSample = 16;
+constexpr int32_t kOutputBufferSize = kSamplesPerFrame * kBitsPerSample / 8;
+const bitstream_format kBitStreamFormats[2] = {MIME_IETF, IF2};
+const int32_t kLocalWmfDecBytesPerFrame[16] = {12, 13, 15, 17, 19, 20, 26, 31,
+ 5, 6, 5, 5, 0, 0, 0, 0};
+const int32_t kLocalIf2DecBytesPerFrame[16] = {13, 14, 16, 18, 19, 21, 26, 31,
+ 13, 14, 16, 18, 19, 21, 26, 31};
+
+class Codec {
+ public:
+ Codec() = default;
+ ~Codec() { deInitDecoder(); }
+ int16_t initDecoder();
+ void deInitDecoder();
+ void decodeFrames(const uint8_t *data, size_t size);
+
+ private:
+ void *mAmrHandle = nullptr;
+};
+
+int16_t Codec::initDecoder() { return GSMInitDecode(&mAmrHandle, (Word8 *)"AMRNBDecoder"); }
+
+void Codec::deInitDecoder() { GSMDecodeFrameExit(&mAmrHandle); }
+
+void Codec::decodeFrames(const uint8_t *data, size_t size) {
+ while (size > 0) {
+ uint8_t mode = *data;
+ bool bit = mode & 0x01;
+ bitstream_format bitsreamFormat = kBitStreamFormats[bit];
+ int32_t frameSize = 0;
+ /* Find frame type */
+ Frame_Type_3GPP frameType = static_cast<Frame_Type_3GPP>((mode >> 3) & 0x0f);
+ ++data;
+ --size;
+ if (bit) {
+ frameSize = kLocalIf2DecBytesPerFrame[frameType];
+ } else {
+ frameSize = kLocalWmfDecBytesPerFrame[frameType];
+ }
+ int16_t outputBuf[kOutputBufferSize];
+ uint8_t *inputBuf = new uint8_t[frameSize];
+ if (!inputBuf) {
+ return;
+ }
+ int32_t minSize = std::min((int32_t)size, frameSize);
+ memcpy(inputBuf, data, minSize);
+ AMRDecode(mAmrHandle, frameType, inputBuf, outputBuf, bitsreamFormat);
+ /* AMRDecode() decodes minSize number of bytes if decode is successful.
+ * AMRDecode() returns -1 if decode fails.
+ * Even if no bytes are decoded, increment by minSize to ensure fuzzer proceeds
+ * to feed next data */
+ data += minSize;
+ size -= minSize;
+ delete[] inputBuf;
+ }
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size < 2) {
+ return 0;
+ }
+ Codec *codec = new Codec();
+ if (!codec) {
+ return 0;
+ }
+ if (codec->initDecoder() == 0) {
+ codec->decodeFrames(data, size);
+ }
+ delete codec;
+ return 0;
+}
diff --git a/media/codecs/amrnb/patent_disclaimer.txt b/media/codecs/amrnb/patent_disclaimer.txt
new file mode 100644
index 0000000..b4bf11d
--- /dev/null
+++ b/media/codecs/amrnb/patent_disclaimer.txt
@@ -0,0 +1,9 @@
+
+THIS IS NOT A GRANT OF PATENT RIGHTS.
+
+Google makes no representation or warranty that the codecs for which
+source code is made available hereunder are unencumbered by
+third-party patents. Those intending to use this source code in
+hardware or software products are advised that implementations of
+these codecs, including in open source software or shareware, may
+require patent licenses from the relevant patent holders.
diff --git a/media/codecs/amrwb/dec/Android.bp b/media/codecs/amrwb/dec/Android.bp
new file mode 100644
index 0000000..204cbe3
--- /dev/null
+++ b/media/codecs/amrwb/dec/Android.bp
@@ -0,0 +1,104 @@
+cc_library_static {
+ name: "libstagefright_amrwbdec",
+ vendor_available: true,
+ host_supported: true,
+ min_sdk_version: "29",
+
+ srcs: [
+ "src/agc2_amr_wb.cpp",
+ "src/band_pass_6k_7k.cpp",
+ "src/dec_acelp_2p_in_64.cpp",
+ "src/dec_acelp_4p_in_64.cpp",
+ "src/dec_alg_codebook.cpp",
+ "src/dec_gain2_amr_wb.cpp",
+ "src/deemphasis_32.cpp",
+ "src/dtx_decoder_amr_wb.cpp",
+ "src/get_amr_wb_bits.cpp",
+ "src/highpass_400hz_at_12k8.cpp",
+ "src/highpass_50hz_at_12k8.cpp",
+ "src/homing_amr_wb_dec.cpp",
+ "src/interpolate_isp.cpp",
+ "src/isf_extrapolation.cpp",
+ "src/isp_az.cpp",
+ "src/isp_isf.cpp",
+ "src/lagconceal.cpp",
+ "src/low_pass_filt_7k.cpp",
+ "src/median5.cpp",
+ "src/mime_io.cpp",
+ "src/noise_gen_amrwb.cpp",
+ "src/normalize_amr_wb.cpp",
+ "src/oversamp_12k8_to_16k.cpp",
+ "src/phase_dispersion.cpp",
+ "src/pit_shrp.cpp",
+ "src/pred_lt4.cpp",
+ "src/preemph_amrwb_dec.cpp",
+ "src/pvamrwb_math_op.cpp",
+ "src/pvamrwbdecoder.cpp",
+ "src/q_gain2_tab.cpp",
+ "src/qisf_ns.cpp",
+ "src/qisf_ns_tab.cpp",
+ "src/qpisf_2s.cpp",
+ "src/qpisf_2s_tab.cpp",
+ "src/scale_signal.cpp",
+ "src/synthesis_amr_wb.cpp",
+ "src/voice_factor.cpp",
+ "src/wb_syn_filt.cpp",
+ "src/weight_amrwb_lpc.cpp",
+ ],
+
+ export_include_dirs: [
+ "src",
+ "include",
+ ],
+
+ cflags: [
+ "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+ "-DOSCL_IMPORT_REF=",
+
+ "-Werror",
+ ],
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ ],
+ },
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+//###############################################################################
+cc_test {
+ name: "libstagefright_amrwbdec_test",
+ gtest: false,
+ host_supported: true,
+
+ srcs: ["test/amrwbdec_test.cpp"],
+
+ cflags: ["-Wall", "-Werror"],
+
+ static_libs: [
+ "libstagefright_amrwbdec",
+ "libsndfile",
+ ],
+
+ local_include_dirs: ["src"],
+
+ shared_libs: ["libaudioutils"],
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ ],
+ },
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
diff --git a/media/codecs/amrwb/dec/MODULE_LICENSE_APACHE2 b/media/codecs/amrwb/dec/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/amrwb/dec/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/amrwb/dec/NOTICE b/media/codecs/amrwb/dec/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/amrwb/dec/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/amrwb/dec/TEST_MAPPING b/media/codecs/amrwb/dec/TEST_MAPPING
new file mode 100644
index 0000000..0278d26
--- /dev/null
+++ b/media/codecs/amrwb/dec/TEST_MAPPING
@@ -0,0 +1,10 @@
+// mappings for frameworks/av/media/libstagefright/codecs/amrwb
+{
+ // tests which require dynamic content
+ // invoke with: atest -- --enable-module-dynamic-download=true
+ // TODO(b/148094059): unit tests not allowed to download content
+ "dynamic-presubmit": [
+ { "name": "AmrwbDecoderTest"}
+
+ ]
+}
diff --git a/media/codecs/amrwb/dec/fuzzer/Android.bp b/media/codecs/amrwb/dec/fuzzer/Android.bp
new file mode 100644
index 0000000..7106a30
--- /dev/null
+++ b/media/codecs/amrwb/dec/fuzzer/Android.bp
@@ -0,0 +1,41 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+
+cc_fuzz {
+ name: "amrwb_dec_fuzzer",
+ host_supported: true,
+ srcs: [
+ "amrwb_dec_fuzzer.cpp",
+ ],
+ static_libs: [
+ "libstagefright_amrwbdec",
+ ],
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
diff --git a/media/codecs/amrwb/dec/fuzzer/README.md b/media/codecs/amrwb/dec/fuzzer/README.md
new file mode 100644
index 0000000..de45784
--- /dev/null
+++ b/media/codecs/amrwb/dec/fuzzer/README.md
@@ -0,0 +1,61 @@
+# Fuzzer for libstagefright_amrwbdec decoder
+
+## Plugin Design Considerations
+The fuzzer plugin for AMR-WB is designed based on the understanding of the
+codec and tries to achieve the following:
+
+##### Maximize code coverage
+The configuration parameters are not hardcoded, but instead selected based on
+incoming data. This ensures more code paths are reached by the fuzzer.
+
+AMR-WB supports the following parameters:
+1. Quality (parameter name: `quality`)
+2. Mode (parameter name: `mode`)
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `quality` | 0. `Bad Quality` 1. `Good quality` | Bit 0 (LSB) of 1st byte of data. |
+| `mode` | 0. `MODE_7k` 1. `MODE_9k` 2. `MODE_12k` 3. `MODE_14k` 4. `MODE_16k ` 5. `MODE_18k` 6. `MODE_20k` 7. `MODE_23k` 8. `MODE_24k` 9. `MRDTX` | Bits 3, 4, 5 and 6 of 1st byte of data. |
+
+This also ensures that the plugin is always deterministic for any given input.
+
+##### Maximize utilization of input data
+The plugin feeds the entire input data to the codec using a loop.
+If the decode operation was successful, the input is advanced by the frame size
+which is based on `mode` and `quality` selected.
+If the decode operation was un-successful, the input is still advanced by frame size so
+that the fuzzer can proceed to feed the next frame.
+
+This ensures that the plugin tolerates any kind of input (empty, huge,
+malformed, etc) and doesnt `exit()` on any input and thereby increasing the
+chance of identifying vulnerabilities.
+
+## Build
+
+This describes steps to build amrwb_dec_fuzzer binary.
+
+### Android
+
+#### Steps to build
+Build the fuzzer
+```
+ $ mm -j$(nproc) amrwb_dec_fuzzer
+```
+
+#### Steps to run
+Create a directory CORPUS_DIR and copy some amrwb files to that folder
+Push this directory to device.
+
+To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/amrwb_dec_fuzzer/amrwb_dec_fuzzer CORPUS_DIR
+```
+To run on host
+```
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/amrwb_dec_fuzzer/amrwb_dec_fuzzer CORPUS_DIR
+```
+
+## References:
+ * http://llvm.org/docs/LibFuzzer.html
+ * https://github.com/google/oss-fuzz
diff --git a/media/codecs/amrwb/dec/fuzzer/amrwb_dec_fuzzer.cpp b/media/codecs/amrwb/dec/fuzzer/amrwb_dec_fuzzer.cpp
new file mode 100644
index 0000000..592a6ec
--- /dev/null
+++ b/media/codecs/amrwb/dec/fuzzer/amrwb_dec_fuzzer.cpp
@@ -0,0 +1,110 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+#include <malloc.h>
+#include <string.h>
+#include <algorithm>
+#include "pvamrwbdecoder.h"
+#include "pvamrwbdecoder_api.h"
+
+// Constants for AMR-WB.
+constexpr int32_t kSamplesPerFrame = 320;
+constexpr int32_t kBitsPerSample = 16;
+constexpr int32_t kMaxSourceDataUnitSize = KAMRWB_NB_BITS_MAX * sizeof(int16_t);
+constexpr int32_t kOutputBufferSize = kSamplesPerFrame * kBitsPerSample / 8;
+constexpr int32_t kFrameSizes[16] = {17, 23, 32, 36, 40, 46, 50, 58,
+ 60, 17, 23, 32, 36, 40, 46, 50};
+
+class Codec {
+ public:
+ Codec() = default;
+ ~Codec() { deInitDecoder(); }
+ bool initDecoder();
+ void decodeFrames(const uint8_t *data, size_t size);
+ void deInitDecoder();
+
+ private:
+ void *mAmrHandle = nullptr;
+ int16_t *mDecoderCookie = nullptr;
+ void *mDecoderBuffer = nullptr;
+};
+
+bool Codec::initDecoder() {
+ mDecoderBuffer = malloc(pvDecoder_AmrWbMemRequirements());
+ if (mDecoderBuffer) {
+ pvDecoder_AmrWb_Init(&mAmrHandle, mDecoderBuffer, &mDecoderCookie);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void Codec::deInitDecoder() {
+ if (mDecoderBuffer) {
+ free(mDecoderBuffer);
+ mDecoderBuffer = nullptr;
+ }
+ mAmrHandle = nullptr;
+ mDecoderCookie = nullptr;
+}
+
+void Codec::decodeFrames(const uint8_t *data, size_t size) {
+ RX_State_wb rx_state{};
+ while (size > 0) {
+ uint8_t modeByte = *data;
+ bool quality = modeByte & 0x01;
+ int16 mode = ((modeByte >> 3) & 0x0f);
+ ++data;
+ --size;
+ int32_t frameSize = kFrameSizes[mode];
+ int16_t inputSampleBuf[kMaxSourceDataUnitSize];
+ uint8_t *inputBuf = new uint8_t[frameSize];
+ if (!inputBuf) {
+ return;
+ }
+ int32_t minSize = std::min((int32_t)size, frameSize);
+ memcpy(inputBuf, data, minSize);
+ int16 frameMode = mode;
+ int16 frameType;
+ mime_unsorting(inputBuf, inputSampleBuf, &frameType, &frameMode, quality, &rx_state);
+
+ int16_t numSamplesOutput;
+ int16_t outputBuf[kOutputBufferSize];
+ pvDecoder_AmrWb(frameMode, inputSampleBuf, outputBuf, &numSamplesOutput, mDecoderBuffer,
+ frameType, mDecoderCookie);
+ data += minSize;
+ size -= minSize;
+ delete[] inputBuf;
+ }
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size < 2) {
+ return 0;
+ }
+ Codec *codec = new Codec();
+ if (!codec) {
+ return 0;
+ }
+ if (codec->initDecoder()) {
+ codec->decodeFrames(data, size);
+ }
+ delete codec;
+ return 0;
+}
diff --git a/media/codecs/amrwb/dec/include/pvamrwbdecoder_api.h b/media/codecs/amrwb/dec/include/pvamrwbdecoder_api.h
new file mode 100644
index 0000000..eca5ae0
--- /dev/null
+++ b/media/codecs/amrwb/dec/include/pvamrwbdecoder_api.h
@@ -0,0 +1,154 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Name: pvamrwbdecoder_api.h
+
+ Date: 05/02/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ Main header file for the Packet Video AMR Wide Band decoder library. The
+ constants, structures, and functions defined within this file, along with
+ a basic data types header file, is all that is needed to use and communicate
+ with the library. The internal data structures within the library are
+ purposely hidden.
+
+ ---* Need description of the input buffering. *-------
+
+ ---* Need an example of calling the library here *----
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ (Normally header files do not have a reference section)
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef _PVAMRWBDECODER_API_H
+#define _PVAMRWBDECODER_API_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+#define AMR_WB_PCM_FRAME 320 /* Frame size at 16kHz */
+
+
+#define NBBITS_7k 132 /* 6.60k */
+#define NBBITS_9k 177 /* 8.85k */
+#define NBBITS_12k 253 /* 12.65k */
+#define NBBITS_14k 285 /* 14.25k */
+#define NBBITS_16k 317 /* 15.85k */
+#define NBBITS_18k 365 /* 18.25k */
+#define NBBITS_20k 397 /* 19.85k */
+#define NBBITS_23k 461 /* 23.05k */
+#define NBBITS_24k 477 /* 23.85k */
+
+#define NBBITS_SID 35
+
+#define KAMRWB_NB_BITS_MAX NBBITS_24k
+#define KAMRWB_NB_BYTES_MAX ((KAMRWB_NB_BITS_MAX>>3)+1)
+
+#define NUM_OF_MODES 10
+
+
+ static const int16 AMR_WB_COMPRESSED[NUM_OF_MODES] =
+ {
+ NBBITS_7k,
+ NBBITS_9k,
+ NBBITS_12k,
+ NBBITS_14k,
+ NBBITS_16k,
+ NBBITS_18k,
+ NBBITS_20k,
+ NBBITS_23k,
+ NBBITS_24k,
+ NBBITS_SID
+ };
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* PVMP4AUDIODECODER_API_H */
+
+
diff --git a/media/codecs/amrwb/dec/patent_disclaimer.txt b/media/codecs/amrwb/dec/patent_disclaimer.txt
new file mode 100644
index 0000000..b4bf11d
--- /dev/null
+++ b/media/codecs/amrwb/dec/patent_disclaimer.txt
@@ -0,0 +1,9 @@
+
+THIS IS NOT A GRANT OF PATENT RIGHTS.
+
+Google makes no representation or warranty that the codecs for which
+source code is made available hereunder are unencumbered by
+third-party patents. Those intending to use this source code in
+hardware or software products are advised that implementations of
+these codecs, including in open source software or shareware, may
+require patent licenses from the relevant patent holders.
diff --git a/media/codecs/amrwb/dec/src/agc2_amr_wb.cpp b/media/codecs/amrwb/dec/src/agc2_amr_wb.cpp
new file mode 100644
index 0000000..2e53d13
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/agc2_amr_wb.cpp
@@ -0,0 +1,190 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: agc2_amr_wb.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 * sig_in, (i) : postfilter input signal
+ int16 * sig_out, (i/o) : postfilter output signal
+ int16 l_trm (i) : subframe size
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Performs adaptive gain control
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void agc2_amr_wb(
+ int16 * sig_in, /* (i) : postfilter input signal */
+ int16 * sig_out, /* (i/o) : postfilter output signal */
+ int16 l_trm /* (i) : subframe size */
+)
+{
+
+ int16 i, exp;
+ int16 gain_in, gain_out, g0;
+ int32 s;
+
+ int16 temp;
+
+ /* calculate gain_out with exponent */
+
+ temp = sig_out[0] >> 2;
+ s = fxp_mul_16by16(temp, temp) << 1;
+ for (i = 1; i < l_trm; i++)
+ {
+ temp = sig_out[i] >> 2;
+ s = mac_16by16_to_int32(s, temp, temp);
+ }
+
+
+ if (s == 0)
+ {
+ return;
+ }
+ exp = normalize_amr_wb(s) - 1;
+ gain_out = amr_wb_round(s << exp);
+
+ /* calculate gain_in with exponent */
+
+ temp = sig_in[0] >> 2;
+ s = mul_16by16_to_int32(temp, temp);
+ for (i = 1; i < l_trm; i++)
+ {
+ temp = sig_in[i] >> 2;
+ s = mac_16by16_to_int32(s, temp, temp);
+ }
+
+
+ if (s == 0)
+ {
+ g0 = 0;
+ }
+ else
+ {
+ i = normalize_amr_wb(s);
+ gain_in = amr_wb_round(s << i);
+ exp -= i;
+
+ /*
+ * g0 = sqrt(gain_in/gain_out)
+ */
+
+ s = div_16by16(gain_out, gain_in);
+ s = shl_int32(s, 7); /* s = gain_out / gain_in */
+ s = shr_int32(s, exp); /* add exponent */
+
+ s = one_ov_sqrt(s);
+ g0 = amr_wb_round(shl_int32(s, 9));
+ }
+ /* sig_out(n) = gain(n) sig_out(n) */
+
+ for (i = 0; i < l_trm; i++)
+ {
+ sig_out[i] = extract_h(shl_int32(fxp_mul_16by16(sig_out[i], g0), 3));
+
+ }
+
+ return;
+}
+
diff --git a/media/codecs/amrwb/dec/src/band_pass_6k_7k.cpp b/media/codecs/amrwb/dec/src/band_pass_6k_7k.cpp
new file mode 100644
index 0000000..97c7402
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/band_pass_6k_7k.cpp
@@ -0,0 +1,240 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: band_pass_6k_7k.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 signal[], input signal / output is divided by 16
+ int16 lg, lenght of signal
+ int16 mem[] in/out: memory (size=30)
+ int16 x[] scratch mem ( size= 60)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ 15th order band pass 6kHz to 7kHz FIR filter.
+
+ frequency: 4kHz 5kHz 5.5kHz 6kHz 6.5kHz 7kHz 7.5kHz 8kHz
+ dB loss: -60dB -45dB -13dB -3dB 0dB -3dB -13dB -45dB
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "pvamrwbdecoder_cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define L_FIR 30
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* filter coefficients (gain=4.0) */
+
+const int16 fir_6k_7k[L_FIR] =
+{
+ -32, 47, 32, -27,
+ -369, 1122, -1421, 0,
+ 3798, -8880, 12349, -10984,
+ 3548, 7766, -18001,
+ 22118,
+ -18001, 7766, 3548, -10984,
+ 12349, -8880, 3798, 0,
+ -1421, 1122, -369, -27,
+ 32, 47
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void band_pass_6k_7k_init(int16 mem[]) /* mem[30] */
+{
+ pv_memset((void *)mem, 0, L_FIR*sizeof(*mem));
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void band_pass_6k_7k(
+ int16 signal[], /* input: signal */
+ int16 lg, /* input: length of input */
+ int16 mem[], /* in/out: memory (size=30) */
+ int16 x[]
+)
+{
+ int16 i, j;
+ int32 L_tmp1;
+ int32 L_tmp2;
+ int32 L_tmp3;
+ int32 L_tmp4;
+
+ int16 *pt_sign = signal;
+
+ pv_memcpy((void *)x, (void *)mem, L_FIR*sizeof(*x));
+
+
+ for (i = 0; i < lg >> 2; i++)
+ {
+
+ x[(i<<2) + L_FIR ] = *(pt_sign) >> 2; /* gain of filter = 4 */
+ x[(i<<2) + L_FIR + 1] = *(pt_sign + 1) >> 2; /* gain of filter = 4 */
+ x[(i<<2) + L_FIR + 2] = *(pt_sign + 2) >> 2; /* gain of filter = 4 */
+ x[(i<<2) + L_FIR + 3] = *(pt_sign + 3) >> 2; /* gain of filter = 4 */
+
+ L_tmp1 = 0x00004000;
+ L_tmp2 = 0x00004000;
+ L_tmp3 = 0x00004000;
+ L_tmp4 = 0x00004000;
+
+ L_tmp1 -= ((int32)x[(i<<2)+L_FIR ] << 5);
+ L_tmp2 -= ((int32)x[(i<<2)+L_FIR+1] << 5);
+ L_tmp3 -= ((int32)x[(i<<2)+L_FIR+2] << 5);
+ L_tmp4 -= ((int32)x[(i<<2)+L_FIR+3] << 5);
+
+ L_tmp1 -= ((int32)x[(i<<2)] << 5);
+ L_tmp2 -= ((int32)x[(i<<2)+1] << 5);
+ L_tmp3 -= ((int32)x[(i<<2)+2] << 5);
+ L_tmp4 -= ((int32)x[(i<<2)+3] << 5);
+
+
+ for (j = 1; j < L_FIR - 1; j += 4)
+ {
+ int16 tmp1 = x[(i<<2)+j ];
+ int16 tmp2 = x[(i<<2)+j+1];
+ int16 tmp3 = x[(i<<2)+j+2];
+
+ L_tmp1 = fxp_mac_16by16(tmp1, fir_6k_7k[j ], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(tmp2, fir_6k_7k[j ], L_tmp2);
+ L_tmp1 = fxp_mac_16by16(tmp2, fir_6k_7k[j+1], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(tmp3, fir_6k_7k[j+1], L_tmp2);
+ L_tmp3 = fxp_mac_16by16(tmp3, fir_6k_7k[j ], L_tmp3);
+ L_tmp1 = fxp_mac_16by16(tmp3, fir_6k_7k[j+2], L_tmp1);
+
+ tmp1 = x[(i<<2)+j+3];
+ tmp2 = x[(i<<2)+j+4];
+
+ L_tmp2 = fxp_mac_16by16(tmp1, fir_6k_7k[j+2], L_tmp2);
+ L_tmp4 = fxp_mac_16by16(tmp1, fir_6k_7k[j ], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(tmp1, fir_6k_7k[j+1], L_tmp3);
+ L_tmp1 = fxp_mac_16by16(tmp1, fir_6k_7k[j+3], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(tmp2, fir_6k_7k[j+3], L_tmp2);
+ L_tmp4 = fxp_mac_16by16(tmp2, fir_6k_7k[j+1], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(tmp2, fir_6k_7k[j+2], L_tmp3);
+
+ tmp1 = x[(i<<2)+j+5];
+ tmp2 = x[(i<<2)+j+6];
+
+ L_tmp4 = fxp_mac_16by16(tmp1, fir_6k_7k[j+2], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(tmp1, fir_6k_7k[j+3], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(tmp2, fir_6k_7k[j+3], L_tmp4);
+
+ }
+
+ L_tmp1 = fxp_mac_16by16(x[(i<<2)+j ], fir_6k_7k[L_FIR-1 ], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(x[(i<<2)+j+1], fir_6k_7k[L_FIR-1 ], L_tmp2);
+ L_tmp3 = fxp_mac_16by16(x[(i<<2)+j+2], fir_6k_7k[L_FIR-1 ], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(x[(i<<2)+j+3], fir_6k_7k[L_FIR-1 ], L_tmp4);
+
+
+ *(pt_sign++) = (int16)(L_tmp1 >> 15);
+ *(pt_sign++) = (int16)(L_tmp2 >> 15);
+ *(pt_sign++) = (int16)(L_tmp3 >> 15);
+ *(pt_sign++) = (int16)(L_tmp4 >> 15);
+
+ }
+
+ pv_memcpy((void *)mem, (void *)(x + lg), L_FIR*sizeof(*mem));
+
+}
+
diff --git a/media/codecs/amrwb/dec/src/dec_acelp_2p_in_64.cpp b/media/codecs/amrwb/dec/src/dec_acelp_2p_in_64.cpp
new file mode 100644
index 0000000..740bc16
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/dec_acelp_2p_in_64.cpp
@@ -0,0 +1,157 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: dec_acelp_2p_in_64.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 index, (i): 12 bits index
+ int16 code[] (o): Q9 algebraic (fixed) codebook excitation
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ 12 bits algebraic codebook decoder.
+ 2 tracks x 32 positions per track = 64 samples.
+
+ 12 bits --> 2 pulses in a frame of 64 samples.
+
+ All pulses can have two (2) possible amplitudes: +1 or -1.
+ Each pulse can have 32 possible positions.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define L_CODE 64 /* codevector length */
+#define NB_TRACK 2 /* number of track */
+#define NB_POS 32 /* number of position */
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_acelp_2p_in_64(
+ int16 index, /* (i): 12 bits index */
+ int16 code[] /* (o): Q9 algebraic (fixed) codebook excitation */
+)
+{
+ int16 i;
+
+ pv_memset(code, 0, L_CODE*sizeof(*code));
+
+ /* decode the positions and signs of pulses and build the codeword */
+
+ i = (index >> 5) & 0x003E;
+
+ if (((index >> 6) & NB_POS) == 0)
+ {
+ code[i] = 512;
+ }
+ else
+ {
+ code[i] = -512;
+ }
+
+ i = ((index & 0x001F) << 1) + 1;
+
+ if ((index & NB_POS) == 0)
+ {
+ code[i] = 512;
+ }
+ else
+ {
+ code[i] = -512;
+ }
+
+}
diff --git a/media/codecs/amrwb/dec/src/dec_acelp_4p_in_64.cpp b/media/codecs/amrwb/dec/src/dec_acelp_4p_in_64.cpp
new file mode 100644
index 0000000..36a7393
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/dec_acelp_4p_in_64.cpp
@@ -0,0 +1,266 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: dec_acelp_4p_in_64.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 index[], (i) : index (20): 5+5+5+5 = 20 bits.
+ (i) : index (36): 9+9+9+9 = 36 bits.
+ (i) : index (44): 13+9+13+9 = 44 bits.
+ (i) : index (52): 13+13+13+13 = 52 bits.
+ (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits.
+ (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits.
+ (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits.
+ int16 nbbits, (i) : 20, 36, 44, 52, 64, 72 or 88 bits
+ int16 code[] (o) Q9: algebraic (fixed) codebook excitation
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook decoder.
+ 4 tracks x 16 positions per track = 64 samples.
+
+ 20 bits --> 4 pulses in a frame of 64 samples.
+ 36 bits --> 8 pulses in a frame of 64 samples.
+ 44 bits --> 10 pulses in a frame of 64 samples.
+ 52 bits --> 12 pulses in a frame of 64 samples.
+ 64 bits --> 16 pulses in a frame of 64 samples.
+ 72 bits --> 18 pulses in a frame of 64 samples.
+ 88 bits --> 24 pulses in a frame of 64 samples.
+
+ All pulses can have two (2) possible amplitudes: +1 or -1.
+ Each pulse can have sixteen (16) possible positions.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+#include "q_pulse.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define L_CODE 64 /* codevector length */
+#define NB_TRACK 4 /* number of track */
+#define NB_POS 16 /* number of position */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void add_pulses(int16 pos[], int16 nb_pulse, int16 track, int16 code[]);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_acelp_4p_in_64(
+ int16 index[], /* (i) : index (20): 5+5+5+5 = 20 bits. */
+ /* (i) : index (36): 9+9+9+9 = 36 bits. */
+ /* (i) : index (44): 13+9+13+9 = 44 bits. */
+ /* (i) : index (52): 13+13+13+13 = 52 bits. */
+ /* (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits. */
+ /* (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits. */
+ /* (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
+ int16 nbbits, /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits */
+ int16 code[] /* (o) Q9: algebraic (fixed) codebook excitation */
+)
+{
+ int16 k, pos[6];
+ int32 L_index;
+ pv_memset(code, 0, L_CODE*sizeof(*code));
+
+ /* decode the positions and signs of pulses and build the codeword */
+
+
+ switch (nbbits)
+ {
+ case 20:
+ for (k = 0; k < NB_TRACK; k++)
+ {
+ L_index = index[k];
+ dec_1p_N1(L_index, 4, 0, pos);
+ add_pulses(pos, 1, k, code);
+ }
+ break;
+
+ case 36:
+ for (k = 0; k < NB_TRACK; k++)
+ {
+ L_index = index[k];
+ dec_2p_2N1(L_index, 4, 0, pos);
+ add_pulses(pos, 2, k, code);
+ }
+ break;
+ case 44:
+ for (k = 0; k < NB_TRACK - 2; k++)
+ {
+ L_index = index[k];
+ dec_3p_3N1(L_index, 4, 0, pos);
+ add_pulses(pos, 3, k, code);
+ }
+ for (k = 2; k < NB_TRACK; k++)
+ {
+ L_index = index[k];
+ dec_2p_2N1(L_index, 4, 0, pos);
+ add_pulses(pos, 2, k, code);
+ }
+ break;
+ case 52:
+ for (k = 0; k < NB_TRACK; k++)
+ {
+ L_index = index[k];
+ dec_3p_3N1(L_index, 4, 0, pos);
+ add_pulses(pos, 3, k, code);
+ }
+ break;
+ case 64:
+ for (k = 0; k < NB_TRACK; k++)
+ {
+ L_index = ((int32)index[k] << 14) + index[k + NB_TRACK];
+ dec_4p_4N(L_index, 4, 0, pos);
+ add_pulses(pos, 4, k, code);
+ }
+ break;
+ case 72:
+ for (k = 0; k < NB_TRACK - 2; k++)
+ {
+ L_index = ((int32)index[k] << 10) + index[k + NB_TRACK];
+ dec_5p_5N(L_index, 4, 0, pos);
+ add_pulses(pos, 5, k, code);
+ }
+ for (k = 2; k < NB_TRACK; k++)
+ {
+ L_index = ((int32)index[k] << 14) + index[k + NB_TRACK];
+ dec_4p_4N(L_index, 4, 0, pos);
+ add_pulses(pos, 4, k, code);
+ }
+ break;
+ case 88:
+ for (k = 0; k < NB_TRACK; k++)
+ {
+ L_index = ((int32)index[k] << 11) + index[k + NB_TRACK];
+ dec_6p_6N_2(L_index, 4, 0, pos);
+ add_pulses(pos, 6, k, code);
+ }
+ break;
+ default:
+ break;
+ }
+
+
+}
+
+
+
+void add_pulses(int16 pos[], int16 nb_pulse, int16 track, int16 code[])
+{
+ int16 i, k;
+
+ for (k = 0; k < nb_pulse; k++)
+ {
+ /* i = ((pos[k] & (NB_POS-1))*NB_TRACK) + track; */
+ i = ((pos[k] & (NB_POS - 1)) << 2) + track;
+
+ if ((pos[k] & NB_POS) == 0)
+ {
+ code[i] += 512;
+ }
+ else
+ {
+ code[i] -= 512;
+ }
+ }
+
+}
diff --git a/media/codecs/amrwb/dec/src/dec_alg_codebook.cpp b/media/codecs/amrwb/dec/src/dec_alg_codebook.cpp
new file mode 100644
index 0000000..44fdc09
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/dec_alg_codebook.cpp
@@ -0,0 +1,392 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: dec_alg_codebook.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ decoding of algebraic codebook
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "q_pulse.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define NB_POS 16 /* pos in track, mask for sign bit */
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void dec_1p_N1(int32 index, int16 N, int16 offset, int16 pos[])
+{
+ int16 pos1;
+ int32 mask, i;
+
+ mask = ((1 << N) - 1);
+ /*-------------------------------------------------------*
+ * Decode 1 pulse with N+1 bits: *
+ *-------------------------------------------------------*/
+ pos1 = ((index & mask) + offset);
+
+ i = ((index >> N) & 1L); /* i = ((index >> N) & 1); */
+
+ if (i == 1)
+ {
+ pos1 += NB_POS;
+ }
+ pos[0] = pos1;
+
+}
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_2p_2N1(int32 index, int16 N, int16 offset, int16 pos[])
+{
+ int16 pos1, pos2, tmp;
+ int32 mask, i;
+
+ mask = (int32)(sub_int16(shl_int16(1, N), 1)); /* mask = ((1<<N)-1); */
+ /*-------------------------------------------------------*
+ * Decode 2 pulses with 2*N+1 bits: *
+ *-------------------------------------------------------*/
+ /* pos1 = (((index >> N) & mask) + offset); */
+ pos1 = (int16)(add_int32((shr_int32(index, N) & mask), (int32)(offset)));
+ tmp = shl_int16(N, 1);
+ i = (index >> tmp) & 1L; /* i = (index >> (2*N)) & 1; */
+ pos2 = add_int16((int16)(index & mask), offset); /* pos2 = ((index & mask) + offset); */
+
+ if (pos2 < pos1) /* ((pos2 - pos1) < 0) */
+ {
+ if (i == 1)
+ { /* (i == 1) */
+ pos1 += NB_POS; /* pos1 += NB_POS; */
+ }
+ else
+ {
+ pos2 += NB_POS; /* pos2 += NB_POS; */
+ }
+ }
+ else
+ {
+ if (i == 1)
+ { /* (i == 1) */
+ pos1 += NB_POS; /* pos1 += NB_POS; */
+ pos2 += NB_POS; /* pos2 += NB_POS; */
+ }
+ }
+
+ pos[0] = pos1;
+ pos[1] = pos2;
+
+ return;
+}
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_3p_3N1(int32 index, int16 N, int16 offset, int16 pos[])
+{
+ int16 j, tmp;
+ int32 mask, idx;
+
+ /*-------------------------------------------------------*
+ * Decode 3 pulses with 3*N+1 bits: *
+ *-------------------------------------------------------*/
+ tmp = sub_int16(shl_int16(N, 1), 1); /* mask = ((1<<((2*N)-1))-1); */
+
+ mask = ((1 << ((2 * N) - 1)) - 1);
+
+ idx = index & mask;
+ j = offset;
+ tmp = (N << 1) - 1;
+
+
+ if (((index >> tmp) & 1L) != 0L)
+ { /* if (((index >> ((2*N)-1)) & 1) == 1){ */
+ j += (1 << (N - 1)); /* j += (1<<(N-1)); */
+ }
+ dec_2p_2N1(idx, (int16)(N - 1), j, pos);
+
+ mask = ((1 << (N + 1)) - 1);
+ tmp = N << 1; /* idx = (index >> (2*N)) & mask; */
+ idx = (index >> tmp) & mask;
+
+ dec_1p_N1(idx, N, offset, pos + 2);
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_4p_4N1(int32 index, int16 N, int16 offset, int16 pos[])
+{
+ int16 j, tmp;
+ int32 mask, idx;
+
+ /*-------------------------------------------------------*
+ * Decode 4 pulses with 4*N+1 bits: *
+ *-------------------------------------------------------*/
+ tmp = (N << 1) - 1;
+ mask = (1L << tmp) - 1L;
+ idx = index & mask;
+ j = offset;
+ tmp = (N << 1) - 1;
+
+
+ if (((index >> tmp) & 1L) != 0L)
+ { /* (((index >> ((2*N)-1)) & 1) == 1) */
+ j += (1 << (N - 1)); /* j += (1<<(N-1)); */
+ }
+ dec_2p_2N1(idx, (int16)(N - 1), j, pos);
+
+
+ tmp = (N << 1) + 1; /* mask = ((1<<((2*N)+1))-1); */
+ mask = (1L << tmp) - 1L;
+ idx = (index >> (N << 1)) & mask; /* idx = (index >> (2*N)) & mask; */
+ dec_2p_2N1(idx, N, offset, pos + 2); /* dec_2p_2N1(idx, N, offset, pos+2); */
+
+ return;
+}
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_4p_4N(int32 index, int16 N, int16 offset, int16 pos[])
+{
+ int16 j, n_1, tmp;
+
+ /*-------------------------------------------------------*
+ * Decode 4 pulses with 4*N bits: *
+ *-------------------------------------------------------*/
+
+ n_1 = N - 1;
+ j = offset + (1 << n_1); /* j = offset + (1 << n_1); */
+
+ tmp = (N << 2) - 2;
+
+ switch ((index >> tmp) & 3)
+ { /* ((index >> ((4*N)-2)) & 3) */
+ case 0:
+ tmp = (n_1 << 2) + 1;
+
+ if ((index >> tmp) & 1)
+ { /* (((index >> ((4*n_1)+1)) & 1) == 0) */
+ dec_4p_4N1(index, n_1, j, pos);
+ }
+ else
+ {
+ dec_4p_4N1(index, n_1, offset, pos);
+ }
+ break;
+ case 1:
+ tmp = (3 * n_1) + 1; /* dec_1p_N1((index>>((3*n_1)+1)), n_1, offset, pos) */
+ dec_1p_N1(index >> tmp, n_1, offset, pos);
+ dec_3p_3N1(index, n_1, j, pos + 1);
+ break;
+ case 2:
+ tmp = (n_1 << 1) + 1; /* dec_2p_2N1((index>>((2*n_1)+1)), n_1, offset, pos); */
+ dec_2p_2N1(index >> tmp, n_1, offset, pos);
+ dec_2p_2N1(index, n_1, j, pos + 2);
+ break;
+ case 3:
+ tmp = n_1 + 1; /* dec_3p_3N1((index>>(n_1+1)), n_1, offset, pos); */
+ dec_3p_3N1(index >> tmp, n_1, offset, pos);
+ dec_1p_N1(index, n_1, j, pos + 3);
+ break;
+ }
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_5p_5N(int32 index, int16 N, int16 offset, int16 pos[])
+{
+ int16 j, n_1, tmp;
+ int32 idx;
+
+ /*-------------------------------------------------------*
+ * Decode 5 pulses with 5*N bits: *
+ *-------------------------------------------------------*/
+
+ n_1 = (int16)(N - 1);
+ j = add_int16(offset, shl_int16(1, n_1)); /* j = offset + (1 << n_1); */
+ tmp = (N << 1) + 1; /* idx = (index >> ((2*N)+1)); */
+ idx = index >> tmp;
+ tmp = (5 * N) - 1; /* ((5*N)-1)) */
+
+
+ if ((index >> tmp) & 1) /* ((index >> ((5*N)-1)) & 1) */
+ {
+ dec_3p_3N1(idx, n_1, j, pos);
+ dec_2p_2N1(index, N, offset, pos + 3);
+ }
+ else
+ {
+ dec_3p_3N1(idx, n_1, offset, pos);
+ dec_2p_2N1(index, N, offset, pos + 3);
+ }
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_6p_6N_2(int32 index, int16 N, int16 offset, int16 pos[])
+{
+ int16 j, n_1, offsetA, offsetB;
+
+ n_1 = N - 1;
+ j = offset + (1 << n_1); /* j = offset + (1 << n_1); */
+
+
+ /* !! N and n_1 are constants -> it doesn't need to be operated by Basic Operators */
+
+ offsetA = offsetB = j;
+
+ if (((index >> (6*N - 5)) & 1L) == 0)
+ { /* if (((index >> ((6*N)-5)) & 1) == 0) */
+ offsetA = offset;
+ }
+ else
+ {
+ offsetB = offset;
+ }
+
+
+ switch ((index >> (6*N - 4)) & 3)
+ { /* (index >> ((6*N)-4)) & 3 */
+ case 0:
+ dec_5p_5N(index >> N, n_1, offsetA, pos); /* dec_5p_5N(index>>N, n_1, offsetA, pos); */
+ dec_1p_N1(index, n_1, offsetA, pos + 5);
+ break;
+ case 1:
+ dec_5p_5N(index >> N, n_1, offsetA, pos); /* dec_5p_5N(index>>N, n_1, offsetA, pos); */
+ dec_1p_N1(index, n_1, offsetB, pos + 5);
+ break;
+ case 2:
+ dec_4p_4N(index >> (2*n_1 + 1), n_1, offsetA, pos); /* dec_4p_4N(index>>((2*n_1)+1 ), n_1, offsetA, pos); */
+ dec_2p_2N1(index, n_1, offsetB, pos + 4);
+ break;
+ case 3:
+ dec_3p_3N1(index >> (3*n_1 + 1), n_1, offset, pos); /* dec_3p_3N1(index>>((3*n_1)+ 1), n_1, offset, pos); */
+ dec_3p_3N1(index, n_1, j, pos + 3);
+ break;
+ }
+ return;
+}
diff --git a/media/codecs/amrwb/dec/src/dec_gain2_amr_wb.cpp b/media/codecs/amrwb/dec/src/dec_gain2_amr_wb.cpp
new file mode 100644
index 0000000..8cae559
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/dec_gain2_amr_wb.cpp
@@ -0,0 +1,404 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: dec_gain2_amr_wb.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 index, (i) : index of quantization.
+ int16 nbits, (i) : number of bits (6 or 7)
+ int16 code[], (i) Q9 : Innovative vector.
+ int16 L_subfr, (i) : Subframe lenght.
+ int16 * gain_pit, (o) Q14 : Pitch gain.
+ int32 * gain_cod, (o) Q16 : Code gain.
+ int16 bfi, (i) : bad frame indicator
+ int16 prev_bfi, (i) : Previous BF indicator
+ int16 state, (i) : State of BFH
+ int16 unusable_frame, (i) : UF indicator
+ int16 vad_hist, (i) : number of non-speech frames
+ int16 * mem (i/o) : static memory (4 words)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Decode the pitch and codebook gains
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+#include "qisf_ns.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define MEAN_ENER 30
+#define PRED_ORDER 4
+
+#define L_LTPHIST 5
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+const int16 pdown_unusable[7] = {32767, 31130, 29491, 24576, 7537, 1638, 328};
+const int16 cdown_unusable[7] = {32767, 16384, 8192, 8192, 8192, 4915, 3277};
+
+const int16 pdown_usable[7] = {32767, 32113, 31457, 24576, 7537, 1638, 328};
+const int16 cdown_usable[7] = {32767, 32113, 32113, 32113, 32113, 32113, 22938};
+
+
+/* MA prediction coeff ={0.5, 0.4, 0.3, 0.2} in Q13 */
+const int16 pred[PRED_ORDER] = {4096, 3277, 2458, 1638};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+/* output :static memory (4 words) */
+void dec_gain2_amr_wb_init(int16 * mem)
+{
+
+ /* 4nd order quantizer energy predictor (init to -14.0 in Q10) */
+ mem[0] = -14336; /* past_qua_en[0] */
+ mem[1] = -14336; /* past_qua_en[1] */
+ mem[2] = -14336; /* past_qua_en[2] */
+ mem[3] = -14336; /* past_qua_en[3] */
+ /* 4 *past_gain_pit */
+ /* 5 *past_gain_code */
+ /* 6 *prev_gc */
+ /* next 5 pbuf[] */
+ /* next 5 gbuf[] */
+ /* next 5 pbuf2[] */
+ pv_memset((void *)&mem[4], 0, 18*sizeof(*mem));
+
+ mem[22] = 21845;
+
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dec_gain2_amr_wb(
+ int16 index, /* (i) : index of quantization. */
+ int16 nbits, /* (i) : number of bits (6 or 7) */
+ int16 code[], /* (i) Q9 : Innovative vector. */
+ int16 L_subfr, /* (i) : Subframe lenght. */
+ int16 * gain_pit, /* (o) Q14 : Pitch gain. */
+ int32 * gain_cod, /* (o) Q16 : Code gain. */
+ int16 bfi, /* (i) : bad frame indicator */
+ int16 prev_bfi, /* (i) : Previous BF indicator */
+ int16 state, /* (i) : State of BFH */
+ int16 unusable_frame, /* (i) : UF indicator */
+ int16 vad_hist, /* (i) : number of non-speech frames */
+ int16 * mem /* (i/o) : static memory (4 words) */
+)
+{
+ const int16 *p;
+ int16 *past_gain_pit, *past_gain_code, *past_qua_en, *gbuf, *pbuf, *prev_gc;
+ int16 *pbuf2;
+ int16 i, tmp, exp, frac, gcode0, exp_gcode0, qua_ener, gcode_inov;
+ int16 tmp1, g_code;
+ int16 tmp2;
+ int32 L_tmp;
+
+ past_qua_en = mem;
+ past_gain_pit = mem + 4;
+ past_gain_code = mem + 5;
+ prev_gc = mem + 6;
+ pbuf = mem + 7;
+ gbuf = mem + 12;
+ pbuf2 = mem + 17;
+
+ /*
+ * Find energy of code and compute:
+ *
+ * L_tmp = 1.0 / sqrt(energy of code/ L_subfr)
+ */
+
+ L_tmp = Dot_product12(code, code, L_subfr, &exp);
+ exp -= 24; /* exp: -18 (code in Q9), -6 (/L_subfr) */
+
+ one_ov_sqrt_norm(&L_tmp, &exp);
+
+ gcode_inov = extract_h(shl_int32(L_tmp, exp - 3)); /* g_code_inov in Q12 */
+
+ /*
+ * Case of erasure.
+ */
+
+ if (bfi != 0)
+ {
+ tmp = median5(&pbuf[2]);
+ *past_gain_pit = tmp;
+
+ if (*past_gain_pit > 15565)
+ {
+ *past_gain_pit = 15565; /* 0.95 in Q14 */
+
+ }
+
+ if (unusable_frame != 0)
+ {
+ *gain_pit = mult_int16(pdown_unusable[state], *past_gain_pit);
+ }
+ else
+ {
+ *gain_pit = mult_int16(pdown_usable[state], *past_gain_pit);
+ }
+ tmp = median5(&gbuf[2]);
+
+ if (vad_hist > 2)
+ {
+ *past_gain_code = tmp;
+ }
+ else
+ {
+
+ if (unusable_frame != 0)
+ {
+ *past_gain_code = mult_int16(cdown_unusable[state], tmp);
+ }
+ else
+ {
+ *past_gain_code = mult_int16(cdown_usable[state], tmp);
+ }
+ }
+
+ /* update table of past quantized energies */
+
+ tmp = past_qua_en[3];
+ tmp1 = past_qua_en[2];
+ L_tmp = tmp;
+ L_tmp += tmp1;
+ past_qua_en[3] = tmp;
+ tmp = past_qua_en[1];
+ tmp1 = past_qua_en[0];
+ L_tmp += tmp;
+ L_tmp += tmp1;
+ past_qua_en[2] = tmp;
+ qua_ener = (int16)(L_tmp >> 3);
+ past_qua_en[1] = tmp1;
+
+
+ qua_ener -= 3072; /* -3 in Q10 */
+
+ if (qua_ener < -14336)
+ {
+ qua_ener = -14336; /* -14 in Q10 */
+ }
+
+ past_qua_en[0] = qua_ener;
+
+
+ for (i = 1; i < 5; i++)
+ {
+ gbuf[i - 1] = gbuf[i];
+ pbuf[i - 1] = pbuf[i];
+ }
+ gbuf[4] = *past_gain_code;
+ pbuf[4] = *past_gain_pit;
+
+
+ /* adjust gain according to energy of code */
+ /* past_gain_code(Q3) * gcode_inov(Q12) => Q16 */
+ *gain_cod = mul_16by16_to_int32(*past_gain_code, gcode_inov);
+
+ return;
+ }
+ /*
+ * Compute gcode0
+ * = Sum(i=0,1) pred[i]*past_qua_en[i] + mean_ener - ener_code
+ */
+
+ L_tmp = L_deposit_h(MEAN_ENER); /* MEAN_ENER in Q16 */
+ L_tmp = shl_int32(L_tmp, 8); /* From Q16 to Q24 */
+ L_tmp = mac_16by16_to_int32(L_tmp, pred[0], past_qua_en[0]); /* Q13*Q10 -> Q24 */
+ L_tmp = mac_16by16_to_int32(L_tmp, pred[1], past_qua_en[1]); /* Q13*Q10 -> Q24 */
+ L_tmp = mac_16by16_to_int32(L_tmp, pred[2], past_qua_en[2]); /* Q13*Q10 -> Q24 */
+ L_tmp = mac_16by16_to_int32(L_tmp, pred[3], past_qua_en[3]); /* Q13*Q10 -> Q24 */
+
+ gcode0 = extract_h(L_tmp); /* From Q24 to Q8 */
+
+ /*
+ * gcode0 = pow(10.0, gcode0/20)
+ * = pow(2, 3.321928*gcode0/20)
+ * = pow(2, 0.166096*gcode0)
+ */
+
+ L_tmp = ((int32)gcode0 * 5443) >> 7; /* *0.166096 in Q15 -> Q24 */
+
+ int32_to_dpf(L_tmp, &exp_gcode0, &frac); /* Extract exponant of gcode0 */
+
+ gcode0 = (int16)(power_of_2(14, frac)); /* Put 14 as exponant so that */
+ /* output of Pow2() will be: */
+ /* 16384 < Pow2() <= 32767 */
+ exp_gcode0 -= 14;
+
+ /* Read the quantized gains */
+
+ if (nbits == 6)
+ {
+ p = &t_qua_gain6b[index<<1];
+ }
+ else
+ {
+ p = &t_qua_gain7b[index<<1];
+ }
+ *gain_pit = *p++; /* selected pitch gain in Q14 */
+ g_code = *p++; /* selected code gain in Q11 */
+
+ L_tmp = mul_16by16_to_int32(g_code, gcode0); /* Q11*Q0 -> Q12 */
+ L_tmp = shl_int32(L_tmp, exp_gcode0 + 4); /* Q12 -> Q16 */
+
+ *gain_cod = L_tmp; /* gain of code in Q16 */
+
+ if (prev_bfi == 1)
+ {
+ L_tmp = mul_16by16_to_int32(*prev_gc, 5120); /* prev_gc(Q3) * 1.25(Q12) = Q16 */
+ /* if((*gain_cod > ((*prev_gc) * 1.25)) && (*gain_cod > 100.0)) */
+
+ if ((*gain_cod > L_tmp) && (*gain_cod > 6553600))
+ {
+ *gain_cod = L_tmp;
+ }
+ }
+ /* keep past gain code in Q3 for frame erasure (can saturate) */
+ *past_gain_code = amr_wb_round(shl_int32(*gain_cod, 3));
+ *past_gain_pit = *gain_pit;
+
+
+ *prev_gc = *past_gain_code;
+ tmp = gbuf[1];
+ tmp1 = pbuf[1];
+ tmp2 = pbuf2[1];
+ for (i = 1; i < 5; i++)
+ {
+ gbuf[i - 1] = tmp;
+ pbuf[i - 1] = tmp1;
+ pbuf2[i - 1] = tmp2;
+ tmp = gbuf[i];
+ tmp1 = pbuf[i];
+ tmp2 = pbuf2[i];
+ }
+ gbuf[4] = *past_gain_code;
+ pbuf[4] = *past_gain_pit;
+ pbuf2[4] = *past_gain_pit;
+
+
+ /* adjust gain according to energy of code */
+ int32_to_dpf(*gain_cod, &exp, &frac);
+ L_tmp = mul_32by16(exp, frac, gcode_inov);
+
+ *gain_cod = shl_int32(L_tmp, 3); /* gcode_inov in Q12 */
+
+
+ past_qua_en[3] = past_qua_en[2];
+ past_qua_en[2] = past_qua_en[1];
+ past_qua_en[1] = past_qua_en[0];
+
+ /*
+ * qua_ener = 20*log10(g_code)
+ * = 6.0206*log2(g_code)
+ * = 6.0206*(log2(g_codeQ11) - 11)
+ */
+ L_tmp = (int32)g_code;
+ amrwb_log_2(L_tmp, &exp, &frac);
+ exp -= 11;
+ L_tmp = mul_32by16(exp, frac, 24660); /* x 6.0206 in Q12 */
+
+ /* update table of past quantized energies */
+
+ past_qua_en[0] = (int16)(L_tmp >> 3); /* result in Q10 */
+
+ return;
+}
+
+
diff --git a/media/codecs/amrwb/dec/src/deemphasis_32.cpp b/media/codecs/amrwb/dec/src/deemphasis_32.cpp
new file mode 100644
index 0000000..c0e4c51
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/deemphasis_32.cpp
@@ -0,0 +1,166 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: deemphasis_32.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 x_hi[], (i) : input signal (bit31..16)
+ int16 x_lo[], (i) : input signal (bit15..4)
+ int16 y[], (o) : output signal (x16)
+ int16 mu, (i) Q15 : deemphasis factor
+ int16 L, (i) : vector size
+ int16 * mem (i/o) : memory (y[-1])
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ 32-bits filtering through 1/(1-mu z^-1)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ Deemphasis H(z) = 1/(1 - 0.68z^(-1)) where mu = 0.67999 in Q15
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void deemphasis_32(
+ int16 x_hi[], /* (i) : input signal (bit31..16) */
+ int16 x_lo[], /* (i) : input signal (bit15..4) */
+ int16 y[], /* (o) : output signal (x16) */
+ int16 mu, /* (i) Q15 : deemphasis factor */
+ int16 L, /* (i) : vector size */
+ int16 * mem /* (i/o) : memory (y[-1]) */
+)
+{
+ int16 i;
+ int32 L_tmp;
+ int16 lo, hi;
+
+ L_tmp = ((int32)x_hi[0]) << 16;
+ L_tmp += (((int32)x_lo[0]) << 4) & 0xFFFF;
+ L_tmp = shl_int32(L_tmp, 3);
+
+ L_tmp = fxp_mac_16by16(*mem, mu, L_tmp),
+
+ L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */
+ y[0] = amr_wb_round(L_tmp);
+
+ lo = x_lo[1];
+ hi = x_hi[1];
+ for (i = 1; i < L - 1; i++)
+ {
+ L_tmp = ((int32)hi) << 16;
+ L_tmp += (((int32)lo) << 4) & 0xFFFF;
+ L_tmp = shl_int32(L_tmp, 3);
+ L_tmp = fxp_mac_16by16(y[i - 1], mu, L_tmp),
+ L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */
+ y[i] = amr_wb_round(L_tmp);
+ lo = x_lo[i+1];
+ hi = x_hi[i+1];
+ }
+ L_tmp = ((int32)hi) << 16;
+ L_tmp += (((int32)lo) << 4) & 0xFFFF;
+ L_tmp = shl_int32(L_tmp, 3);
+ L_tmp = fxp_mac_16by16(y[i - 1], mu, L_tmp),
+ L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */
+ y[i] = amr_wb_round(L_tmp);
+
+ *mem = y[L - 1];
+
+ return;
+}
+
diff --git a/media/codecs/amrwb/dec/src/dtx.h b/media/codecs/amrwb/dec/src/dtx.h
new file mode 100644
index 0000000..cf686a0
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/dtx.h
@@ -0,0 +1,242 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/dtx.h
+
+ Date: 01/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+ Static memory, constants and frametypes for the DTX
+------------------------------------------------------------------------------
+*/
+#ifndef DTX_H
+#define DTX_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES AND SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+#define DTX_MAX_EMPTY_THRESH 50
+#define DTX_HIST_SIZE 8
+#define DTX_HIST_SIZE_MIN_ONE 7
+#define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1)
+#define DTX_HANG_CONST 7 /* yields eight frames of SP HANGOVER */
+#define INV_MED_THRESH 14564
+#define ISF_GAP 128 /* 50 */
+#define ONE_MINUS_ISF_GAP (16384 - ISF_GAP)
+
+#define ISF_GAP 128
+#define ISF_DITH_GAP 448
+#define ISF_FACTOR_LOW 256
+#define ISF_FACTOR_STEP 2
+
+#define GAIN_THR 180
+#define GAIN_FACTOR 75
+
+ typedef struct
+ {
+ int16 isf_hist[M * DTX_HIST_SIZE];
+ int16 log_en_hist[DTX_HIST_SIZE];
+ int16 hist_ptr;
+ int16 log_en_index;
+ int16 cng_seed;
+
+ /* DTX handler stuff */
+ int16 dtxHangoverCount;
+ int16 decAnaElapsedCount;
+ int32 D[28];
+ int32 sumD[DTX_HIST_SIZE];
+ } dtx_encState;
+
+#define SPEECH 0
+#define DTX 1
+#define DTX_MUTE 2
+
+#define TX_SPEECH 0
+#define TX_SID_FIRST 1
+#define TX_SID_UPDATE 2
+#define TX_NO_DATA 3
+
+#define RX_SPEECH_GOOD 0
+#define RX_SPEECH_PROBABLY_DEGRADED 1
+#define RX_SPEECH_LOST 2
+#define RX_SPEECH_BAD 3
+#define RX_SID_FIRST 4
+#define RX_SID_UPDATE 5
+#define RX_SID_BAD 6
+#define RX_NO_DATA 7
+
+ /*****************************************************************************
+ *
+ * DEFINITION OF DATA TYPES
+ *****************************************************************************/
+
+ typedef struct
+ {
+ int16 since_last_sid;
+ int16 true_sid_period_inv;
+ int16 log_en;
+ int16 old_log_en;
+ int16 level;
+ int16 isf[M];
+ int16 isf_old[M];
+ int16 cng_seed;
+
+ int16 isf_hist[M * DTX_HIST_SIZE];
+ int16 log_en_hist[DTX_HIST_SIZE];
+ int16 hist_ptr;
+
+ int16 dtxHangoverCount;
+ int16 decAnaElapsedCount;
+
+ int16 sid_frame;
+ int16 valid_data;
+ int16 dtxHangoverAdded;
+
+ int16 dtxGlobalState; /* contains previous state */
+ /* updated in main decoder */
+
+ int16 data_updated; /* marker to know if CNI data is ever renewed */
+
+ int16 dither_seed;
+ int16 CN_dith;
+
+ } dtx_decState;
+
+ int16 dtx_enc_init(dtx_encState ** st, int16 isf_init[]);
+ int16 dtx_enc_reset(dtx_encState * st, int16 isf_init[]);
+ void dtx_enc_exit(dtx_encState ** st);
+
+ int16 dtx_enc(
+ dtx_encState * st, /* i/o : State struct */
+ int16 isf[M], /* o : CN ISF vector */
+ int16 * exc2, /* o : CN excitation */
+ int16 ** prms
+ );
+
+ int16 dtx_buffer(
+ dtx_encState * st, /* i/o : State struct */
+ int16 isf_new[], /* i : isf vector */
+ int32 enr, /* i : residual energy (in L_FRAME) */
+ int16 codec_mode
+ );
+
+ void tx_dtx_handler(dtx_encState * st, /* i/o : State struct */
+ int16 vad_flag, /* i : vad decision */
+ int16 * usedMode /* i/o : mode changed or not */
+ );
+
+ void Qisf_ns(
+ int16 * isf1, /* input : ISF in the frequency domain (0..0.5) */
+ int16 * isf_q, /* output: quantized ISF */
+ int16 * indice /* output: quantization indices */
+ );
+
+
+ int16 dtx_dec_amr_wb_reset(dtx_decState * st, const int16 isf_init[]);
+
+ int16 dtx_dec_amr_wb(
+ dtx_decState * st, /* i/o : State struct */
+ int16 * exc2, /* o : CN excitation */
+ int16 new_state, /* i : New DTX state */
+ int16 isf[], /* o : CN ISF vector */
+ int16 ** prms
+ );
+
+ void dtx_dec_amr_wb_activity_update(
+ dtx_decState * st,
+ int16 isf[],
+ int16 exc[]);
+
+
+ int16 rx_amr_wb_dtx_handler(
+ dtx_decState * st, /* i/o : State struct */
+ int16 frame_type /* i : Frame type */
+ );
+
+ void Disf_ns(
+ int16 * indice, /* input: quantization indices */
+ int16 * isf_q /* input : ISF in the frequency domain (0..0.5) */
+ );
+
+ void aver_isf_history(
+ int16 isf_old[],
+ int16 indices[],
+ int32 isf_aver[]
+ );
+ void find_frame_indices(
+ int16 isf_old_tx[],
+ int16 indices[],
+ dtx_encState * st
+ );
+
+ int16 dithering_control(
+ dtx_encState * st
+ );
+ void CN_dithering(
+ int16 isf[M],
+ int32 * L_log_en_int,
+ int16 * dither_seed
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DTX_H */
+
+
diff --git a/media/codecs/amrwb/dec/src/dtx_decoder_amr_wb.cpp b/media/codecs/amrwb/dec/src/dtx_decoder_amr_wb.cpp
new file mode 100644
index 0000000..7c798cc
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/dtx_decoder_amr_wb.cpp
@@ -0,0 +1,984 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: dtx_decoder_amr_wb.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ DTX functions
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h" /* prototype of functions */
+#include "get_amr_wb_bits.h"
+#include "dtx.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+/*
+ * Function : dtx_dec_amr_wb_reset
+ */
+int16 dtx_dec_amr_wb_reset(dtx_decState * st, const int16 isf_init[])
+{
+ int16 i;
+
+
+ if (st == (dtx_decState *) NULL)
+ {
+ /* dtx_dec_amr_wb_reset invalid parameter */
+ return (-1);
+ }
+ st->since_last_sid = 0;
+ st->true_sid_period_inv = (1 << 13); /* 0.25 in Q15 */
+
+ st->log_en = 3500;
+ st->old_log_en = 3500;
+ /* low level noise for better performance in DTX handover cases */
+
+ st->cng_seed = RANDOM_INITSEED;
+
+ st->hist_ptr = 0;
+
+ /* Init isf_hist[] and decoder log frame energy */
+ pv_memcpy((void *)st->isf, (void *)isf_init, M*sizeof(*isf_init));
+
+ pv_memcpy((void *)st->isf_old, (void *)isf_init, M*sizeof(*isf_init));
+
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ pv_memcpy((void *)&st->isf_hist[i * M], (void *)isf_init, M*sizeof(*isf_init));
+ st->log_en_hist[i] = st->log_en;
+ }
+
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ st->decAnaElapsedCount = 32767;
+
+ st->sid_frame = 0;
+ st->valid_data = 0;
+ st->dtxHangoverAdded = 0;
+
+ st->dtxGlobalState = SPEECH;
+ st->data_updated = 0;
+
+ st->dither_seed = RANDOM_INITSEED;
+ st->CN_dith = 0;
+
+ return 0;
+}
+
+
+/*
+ Table of new SPD synthesis states
+
+ | previous SPD_synthesis_state
+ Incoming |
+ frame_type | SPEECH | DTX | DTX_MUTE
+ ---------------------------------------------------------------
+ RX_SPEECH_GOOD , | | |
+ RX_SPEECH_PR_DEGRADED | SPEECH | SPEECH | SPEECH
+ ----------------------------------------------------------------
+ RX_SPEECH_BAD, | SPEECH | DTX | DTX_MUTE
+ ----------------------------------------------------------------
+ RX_SID_FIRST, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
+ ----------------------------------------------------------------
+ RX_SID_UPDATE, | DTX | DTX | DTX
+ ----------------------------------------------------------------
+ RX_SID_BAD, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
+ ----------------------------------------------------------------
+ RX_NO_DATA, | SPEECH | DTX/(DTX_MUTE)| DTX_MUTE
+ RX_SPARE |(class2 garb.)| |
+ ----------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*
+ * Function : dtx_dec_amr_wb
+ */
+int16 dtx_dec_amr_wb(
+ dtx_decState * st, /* i/o : State struct */
+ int16 * exc2, /* o : CN excitation */
+ int16 new_state, /* i : New DTX state */
+ int16 isf[], /* o : CN ISF vector */
+ int16 ** prms
+)
+{
+ int16 log_en_index;
+ int16 ind[7];
+ int16 i, j;
+ int16 int_fac;
+ int16 gain;
+
+ int32 L_isf[M], L_log_en_int, level32, ener32;
+ int16 ptr;
+ int16 tmp_int_length;
+ int16 tmp, exp, exp0, log_en_int_e, log_en_int_m, level;
+
+ /* This function is called if synthesis state is not SPEECH the globally passed inputs to this function
+ * are st->sid_frame st->valid_data st->dtxHangoverAdded new_state (SPEECH, DTX, DTX_MUTE) */
+
+ if ((st->dtxHangoverAdded != 0) &&
+ (st->sid_frame != 0))
+ {
+ /* sid_first after dtx hangover period */
+ /* or sid_upd after dtxhangover */
+
+ /* consider twice the last frame */
+ ptr = st->hist_ptr + 1;
+
+ if (ptr == DTX_HIST_SIZE)
+ ptr = 0;
+
+ pv_memcpy((void *)&st->isf_hist[ptr * M], (void *)&st->isf_hist[st->hist_ptr * M], M*sizeof(*st->isf_hist));
+
+ st->log_en_hist[ptr] = st->log_en_hist[st->hist_ptr];
+
+ /* compute mean log energy and isf from decoded signal (SID_FIRST) */
+ st->log_en = 0;
+ for (i = 0; i < M; i++)
+ {
+ L_isf[i] = 0;
+ }
+
+ /* average energy and isf */
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ /* Division by DTX_HIST_SIZE = 8 has been done in dtx_buffer log_en is in Q10 */
+ st->log_en = add_int16(st->log_en, st->log_en_hist[i]);
+
+ for (j = 0; j < M; j++)
+ {
+ L_isf[j] = add_int32(L_isf[j], (int32)(st->isf_hist[i * M + j]));
+ }
+ }
+
+ /* st->log_en in Q9 */
+ st->log_en >>= 1;
+
+ /* Add 2 in Q9, in order to have only positive values for Pow2 */
+ /* this value is subtracted back after Pow2 function */
+ st->log_en += 1024;
+
+ if (st->log_en < 0)
+ st->log_en = 0;
+
+ for (j = 0; j < M; j++)
+ {
+ st->isf[j] = (int16)(L_isf[j] >> 3); /* divide by 8 */
+ }
+
+ }
+
+ if (st->sid_frame != 0)
+ {
+ /* Set old SID parameters, always shift */
+ /* even if there is no new valid_data */
+
+ pv_memcpy((void *)st->isf_old, (void *)st->isf, M*sizeof(*st->isf));
+
+ st->old_log_en = st->log_en;
+
+ if (st->valid_data != 0) /* new data available (no CRC) */
+ {
+ /* st->true_sid_period_inv = 1.0f/st->since_last_sid; */
+ /* Compute interpolation factor, since the division only works * for values of since_last_sid <
+ * 32 we have to limit the * interpolation to 32 frames */
+ tmp_int_length = st->since_last_sid;
+
+
+ if (tmp_int_length > 32)
+ {
+ tmp_int_length = 32;
+ }
+
+ if (tmp_int_length >= 2)
+ {
+ st->true_sid_period_inv = div_16by16(1 << 10, shl_int16(tmp_int_length, 10));
+ }
+ else
+ {
+ st->true_sid_period_inv = 1 << 14; /* 0.5 it Q15 */
+ }
+
+ ind[0] = Serial_parm(6, prms);
+ ind[1] = Serial_parm(6, prms);
+ ind[2] = Serial_parm(6, prms);
+ ind[3] = Serial_parm(5, prms);
+ ind[4] = Serial_parm(5, prms);
+
+ Disf_ns(ind, st->isf);
+
+ log_en_index = Serial_parm(6, prms);
+
+ /* read background noise stationarity information */
+ st->CN_dith = Serial_parm_1bit(prms);
+
+ /* st->log_en = (float)log_en_index / 2.625 - 2.0; */
+ /* log2(E) in Q9 (log2(E) lies in between -2:22) */
+ st->log_en = shl_int16(log_en_index, 15 - 6);
+
+ /* Divide by 2.625 */
+ st->log_en = mult_int16(st->log_en, 12483);
+ /* Subtract 2 in Q9 is done later, after Pow2 function */
+
+ /* no interpolation at startup after coder reset */
+ /* or when SID_UPD has been received right after SPEECH */
+
+ if ((st->data_updated == 0) || (st->dtxGlobalState == SPEECH))
+ {
+ pv_memcpy((void *)st->isf_old, (void *)st->isf, M*sizeof(*st->isf));
+
+ st->old_log_en = st->log_en;
+ }
+ } /* endif valid_data */
+ } /* endif sid_frame */
+
+
+ if ((st->sid_frame != 0) && (st->valid_data != 0))
+ {
+ st->since_last_sid = 0;
+ }
+ /* Interpolate SID info */
+ int_fac = shl_int16(st->since_last_sid, 10); /* Q10 */
+ int_fac = mult_int16(int_fac, st->true_sid_period_inv); /* Q10 * Q15 -> Q10 */
+
+ /* Maximize to 1.0 in Q10 */
+
+ if (int_fac > 1024)
+ {
+ int_fac = 1024;
+ }
+ int_fac = shl_int16(int_fac, 4); /* Q10 -> Q14 */
+
+ L_log_en_int = mul_16by16_to_int32(int_fac, st->log_en); /* Q14 * Q9 -> Q24 */
+
+ for (i = 0; i < M; i++)
+ {
+ isf[i] = mult_int16(int_fac, st->isf[i]);/* Q14 * Q15 -> Q14 */
+ }
+
+ int_fac = 16384 - int_fac; /* 1-k in Q14 */
+
+ /* ( Q14 * Q9 -> Q24 ) + Q24 -> Q24 */
+ L_log_en_int = mac_16by16_to_int32(L_log_en_int, int_fac, st->old_log_en);
+
+ for (i = 0; i < M; i++)
+ {
+ /* Q14 + (Q14 * Q15 -> Q14) -> Q14 */
+ isf[i] = add_int16(isf[i], mult_int16(int_fac, st->isf_old[i]));
+ isf[i] = shl_int16(isf[i], 1); /* Q14 -> Q15 */
+ }
+
+ /* If background noise is non-stationary, insert comfort noise dithering */
+ if (st->CN_dith != 0)
+ {
+ CN_dithering(isf, &L_log_en_int, &st->dither_seed);
+ }
+ /* L_log_en_int corresponds to log2(E)+2 in Q24, i.e log2(gain)+1 in Q25 */
+ /* Q25 -> Q16 */
+ L_log_en_int >>= 9;
+
+ /* Find integer part */
+ log_en_int_e = extract_h(L_log_en_int);
+
+ /* Find fractional part */
+ log_en_int_m = (int16)(sub_int32(L_log_en_int, L_deposit_h(log_en_int_e)) >> 1);
+
+ /* Subtract 2 from L_log_en_int in Q9, i.e divide the gain by 2 (energy by 4) */
+ /* Add 16 in order to have the result of pow2 in Q16 */
+ log_en_int_e += 15;
+
+ /* level = (float)( pow( 2.0f, log_en ) ); */
+ level32 = power_of_2(log_en_int_e, log_en_int_m); /* Q16 */
+
+ exp0 = normalize_amr_wb(level32);
+ level32 <<= exp0; /* level in Q31 */
+ exp0 = 15 - exp0;
+ level = (int16)(level32 >> 16); /* level in Q15 */
+
+ /* generate white noise vector */
+ for (i = 0; i < L_FRAME; i++)
+ {
+ exc2[i] = noise_gen_amrwb(&(st->cng_seed)) >> 4;
+ }
+
+ /* gain = level / sqrt(ener) * sqrt(L_FRAME) */
+
+ /* energy of generated excitation */
+ ener32 = Dot_product12(exc2, exc2, L_FRAME, &exp);
+
+ one_ov_sqrt_norm(&ener32, &exp);
+
+ gain = extract_h(ener32);
+
+ gain = mult_int16(level, gain); /* gain in Q15 */
+
+ exp += exp0;
+
+ /* Multiply by sqrt(L_FRAME)=16, i.e. shift left by 4 */
+ exp += 4;
+
+ for (i = 0; i < L_FRAME; i++)
+ {
+ tmp = mult_int16(exc2[i], gain); /* Q0 * Q15 */
+ exc2[i] = shl_int16(tmp, exp);
+ }
+
+
+ if (new_state == DTX_MUTE)
+ {
+ /* mute comfort noise as it has been quite a long time since last SID update was performed */
+
+ tmp_int_length = st->since_last_sid;
+
+ if (tmp_int_length > 32)
+ {
+ tmp_int_length = 32;
+ }
+
+ st->true_sid_period_inv = div_16by16(1 << 10, shl_int16(tmp_int_length, 10));
+
+ st->since_last_sid = 0;
+ st->old_log_en = st->log_en;
+ /* subtract 1/8 in Q9 (energy), i.e -3/8 dB */
+ st->log_en -= 64;
+ }
+ /* reset interpolation length timer if data has been updated. */
+
+ if ((st->sid_frame != 0) &&
+ ((st->valid_data != 0) ||
+ ((st->valid_data == 0) && (st->dtxHangoverAdded) != 0)))
+ {
+ st->since_last_sid = 0;
+ st->data_updated = 1;
+ }
+ return 0;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void dtx_dec_amr_wb_activity_update(
+ dtx_decState * st,
+ int16 isf[],
+ int16 exc[])
+{
+ int16 i;
+
+ int32 L_frame_en;
+ int16 log_en_e, log_en_m, log_en;
+
+
+ st->hist_ptr++;
+
+ if (st->hist_ptr == DTX_HIST_SIZE)
+ {
+ st->hist_ptr = 0;
+ }
+ pv_memcpy((void *)&st->isf_hist[st->hist_ptr * M], (void *)isf, M*sizeof(*isf));
+
+
+ /* compute log energy based on excitation frame energy in Q0 */
+ L_frame_en = 0;
+ for (i = 0; i < L_FRAME; i++)
+ {
+ L_frame_en = mac_16by16_to_int32(L_frame_en, exc[i], exc[i]);
+ }
+ L_frame_en >>= 1;
+
+ /* log_en = (float)log10(L_frame_en/(float)L_FRAME)/(float)log10(2.0f); */
+ amrwb_log_2(L_frame_en, &log_en_e, &log_en_m);
+
+ /* convert exponent and mantissa to int16 Q7. Q7 is used to simplify averaging in dtx_enc */
+ log_en = shl_int16(log_en_e, 7); /* Q7 */
+ log_en += log_en_m >> 8;
+
+ /* Divide by L_FRAME = 256, i.e subtract 8 in Q7 = 1024 */
+ log_en -= 1024;
+
+ /* insert into log energy buffer */
+ st->log_en_hist[st->hist_ptr] = log_en;
+
+ return;
+}
+
+
+/*
+ Table of new SPD synthesis states
+
+ | previous SPD_synthesis_state
+ Incoming |
+ frame_type | SPEECH | DTX | DTX_MUTE
+ ---------------------------------------------------------------
+ RX_SPEECH_GOOD , | | |
+ RX_SPEECH_PR_DEGRADED | SPEECH | SPEECH | SPEECH
+ ----------------------------------------------------------------
+ RX_SPEECH_BAD, | SPEECH | DTX | DTX_MUTE
+ ----------------------------------------------------------------
+ RX_SID_FIRST, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
+ ----------------------------------------------------------------
+ RX_SID_UPDATE, | DTX | DTX | DTX
+ ----------------------------------------------------------------
+ RX_SID_BAD, | DTX | DTX/(DTX_MUTE)| DTX_MUTE
+ ----------------------------------------------------------------
+ RX_NO_DATA, | SPEECH | DTX/(DTX_MUTE)| DTX_MUTE
+ RX_SPARE |(class2 garb.)| |
+ ----------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int16 rx_amr_wb_dtx_handler(
+ dtx_decState * st, /* i/o : State struct */
+ int16 frame_type /* i : Frame type */
+)
+{
+ int16 newState;
+ int16 encState;
+
+ /* DTX if SID frame or previously in DTX{_MUTE} and (NO_RX OR BAD_SPEECH) */
+
+
+
+ if ((frame_type == RX_SID_FIRST) ||
+ (frame_type == RX_SID_UPDATE) ||
+ (frame_type == RX_SID_BAD) ||
+ (((st->dtxGlobalState == DTX) ||
+ (st->dtxGlobalState == DTX_MUTE)) &&
+ ((frame_type == RX_NO_DATA) ||
+ (frame_type == RX_SPEECH_BAD) ||
+ (frame_type == RX_SPEECH_LOST))))
+ {
+ newState = DTX;
+
+ /* stay in mute for these input types */
+
+ if ((st->dtxGlobalState == DTX_MUTE) &&
+ ((frame_type == RX_SID_BAD) ||
+ (frame_type == RX_SID_FIRST) ||
+ (frame_type == RX_SPEECH_LOST) ||
+ (frame_type == RX_NO_DATA)))
+ {
+ newState = DTX_MUTE;
+ }
+ /* evaluate if noise parameters are too old */
+ /* since_last_sid is reset when CN parameters have been updated */
+ st->since_last_sid = add_int16(st->since_last_sid, 1);
+
+ /* no update of sid parameters in DTX for a long while */
+
+ if (st->since_last_sid > DTX_MAX_EMPTY_THRESH)
+ {
+ newState = DTX_MUTE;
+ }
+ }
+ else
+ {
+ newState = SPEECH;
+ st->since_last_sid = 0;
+ }
+
+ /* reset the decAnaElapsed Counter when receiving CNI data the first time, to robustify counter missmatch
+ * after handover this might delay the bwd CNI analysis in the new decoder slightly. */
+
+ if ((st->data_updated == 0) &&
+ (frame_type == RX_SID_UPDATE))
+ {
+ st->decAnaElapsedCount = 0;
+ }
+ /* update the SPE-SPD DTX hangover synchronization */
+ /* to know when SPE has added dtx hangover */
+ st->decAnaElapsedCount = add_int16(st->decAnaElapsedCount, 1);
+ st->dtxHangoverAdded = 0;
+
+
+ if ((frame_type == RX_SID_FIRST) ||
+ (frame_type == RX_SID_UPDATE) ||
+ (frame_type == RX_SID_BAD) ||
+ (frame_type == RX_NO_DATA))
+ {
+ encState = DTX;
+ }
+ else
+ {
+ encState = SPEECH;
+ }
+
+
+ if (encState == SPEECH)
+ {
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ }
+ else
+ {
+
+ if (st->decAnaElapsedCount > DTX_ELAPSED_FRAMES_THRESH)
+ {
+ st->dtxHangoverAdded = 1;
+ st->decAnaElapsedCount = 0;
+ st->dtxHangoverCount = 0;
+ }
+ else if (st->dtxHangoverCount == 0)
+ {
+ st->decAnaElapsedCount = 0;
+ }
+ else
+ {
+ st->dtxHangoverCount--;
+ }
+ }
+
+ if (newState != SPEECH)
+ {
+ /* DTX or DTX_MUTE CN data is not in a first SID, first SIDs are marked as SID_BAD but will do
+ * backwards analysis if a hangover period has been added according to the state machine above */
+
+ st->sid_frame = 0;
+ st->valid_data = 0;
+
+
+ if (frame_type == RX_SID_FIRST)
+ {
+ st->sid_frame = 1;
+ }
+ else if (frame_type == RX_SID_UPDATE)
+ {
+ st->sid_frame = 1;
+ st->valid_data = 1;
+ }
+ else if (frame_type == RX_SID_BAD)
+ {
+ st->sid_frame = 1;
+ st->dtxHangoverAdded = 0; /* use old data */
+ }
+ }
+ return newState;
+ /* newState is used by both SPEECH AND DTX synthesis routines */
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void aver_isf_history(
+ int16 isf_old[],
+ int16 indices[],
+ int32 isf_aver[]
+)
+{
+ int16 i, j, k;
+ int16 isf_tmp[2 * M];
+ int32 L_tmp;
+
+ /* Memorize in isf_tmp[][] the ISF vectors to be replaced by */
+ /* the median ISF vector prior to the averaging */
+ for (k = 0; k < 2; k++)
+ {
+
+ if (indices[k] + 1 != 0)
+ {
+ for (i = 0; i < M; i++)
+ {
+ isf_tmp[k * M + i] = isf_old[indices[k] * M + i];
+ isf_old[indices[k] * M + i] = isf_old[indices[2] * M + i];
+ }
+ }
+ }
+
+ /* Perform the ISF averaging */
+ for (j = 0; j < M; j++)
+ {
+ L_tmp = 0;
+
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ L_tmp = add_int32(L_tmp, (int32)(isf_old[i * M + j]));
+ }
+ isf_aver[j] = L_tmp;
+ }
+
+ /* Retrieve from isf_tmp[][] the ISF vectors saved prior to averaging */
+ for (k = 0; k < 2; k++)
+ {
+
+ if (indices[k] + 1 != 0)
+ {
+ for (i = 0; i < M; i++)
+ {
+ isf_old[indices[k] * M + i] = isf_tmp[k * M + i];
+ }
+ }
+ }
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void find_frame_indices(
+ int16 isf_old_tx[],
+ int16 indices[],
+ dtx_encState * st
+)
+{
+ int32 L_tmp, summin, summax, summax2nd;
+ int16 i, j, tmp;
+ int16 ptr;
+
+ /* Remove the effect of the oldest frame from the column */
+ /* sum sumD[0..DTX_HIST_SIZE-1]. sumD[DTX_HIST_SIZE] is */
+ /* not updated since it will be removed later. */
+
+ tmp = DTX_HIST_SIZE_MIN_ONE;
+ j = -1;
+ for (i = 0; i < DTX_HIST_SIZE_MIN_ONE; i++)
+ {
+ j += tmp;
+ st->sumD[i] = sub_int32(st->sumD[i], st->D[j]);
+ tmp--;
+ }
+
+ /* Shift the column sum sumD. The element sumD[DTX_HIST_SIZE-1] */
+ /* corresponding to the oldest frame is removed. The sum of */
+ /* the distances between the latest isf and other isfs, */
+ /* i.e. the element sumD[0], will be computed during this call. */
+ /* Hence this element is initialized to zero. */
+
+ for (i = DTX_HIST_SIZE_MIN_ONE; i > 0; i--)
+ {
+ st->sumD[i] = st->sumD[i - 1];
+ }
+ st->sumD[0] = 0;
+
+ /* Remove the oldest frame from the distance matrix. */
+ /* Note that the distance matrix is replaced by a one- */
+ /* dimensional array to save static memory. */
+
+ tmp = 0;
+ for (i = 27; i >= 12; i -= tmp)
+ {
+ tmp++;
+ for (j = tmp; j > 0; j--)
+ {
+ st->D[i - j + 1] = st->D[i - j - tmp];
+ }
+ }
+
+ /* Compute the first column of the distance matrix D */
+ /* (squared Euclidean distances from isf1[] to isf_old_tx[][]). */
+
+ ptr = st->hist_ptr;
+ for (i = 1; i < DTX_HIST_SIZE; i++)
+ {
+ /* Compute the distance between the latest isf and the other isfs. */
+ ptr--;
+
+ if (ptr < 0)
+ {
+ ptr = DTX_HIST_SIZE_MIN_ONE;
+ }
+ L_tmp = 0;
+ for (j = 0; j < M; j++)
+ {
+ tmp = sub_int16(isf_old_tx[st->hist_ptr * M + j], isf_old_tx[ptr * M + j]);
+ L_tmp = mac_16by16_to_int32(L_tmp, tmp, tmp);
+ }
+ st->D[i - 1] = L_tmp;
+
+ /* Update also the column sums. */
+ st->sumD[0] = add_int32(st->sumD[0], st->D[i - 1]);
+ st->sumD[i] = add_int32(st->sumD[i], st->D[i - 1]);
+ }
+
+ /* Find the minimum and maximum distances */
+ summax = st->sumD[0];
+ summin = st->sumD[0];
+ indices[0] = 0;
+ indices[2] = 0;
+ for (i = 1; i < DTX_HIST_SIZE; i++)
+ {
+
+ if (st->sumD[i] > summax)
+ {
+ indices[0] = i;
+ summax = st->sumD[i];
+ }
+
+ if (st->sumD[i] < summin)
+ {
+ indices[2] = i;
+ summin = st->sumD[i];
+ }
+ }
+
+ /* Find the second largest distance */
+ summax2nd = -2147483647L;
+ indices[1] = -1;
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+
+ if ((st->sumD[i] > summax2nd) && (i != indices[0]))
+ {
+ indices[1] = i;
+ summax2nd = st->sumD[i];
+ }
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ indices[i] = sub_int16(st->hist_ptr, indices[i]);
+
+ if (indices[i] < 0)
+ {
+ indices[i] = add_int16(indices[i], DTX_HIST_SIZE);
+ }
+ }
+
+ /* If maximum distance/MED_THRESH is smaller than minimum distance */
+ /* then the median ISF vector replacement is not performed */
+ tmp = normalize_amr_wb(summax);
+ summax <<= tmp;
+ summin <<= tmp;
+ L_tmp = mul_16by16_to_int32(amr_wb_round(summax), INV_MED_THRESH);
+
+ if (L_tmp <= summin)
+ {
+ indices[0] = -1;
+ }
+ /* If second largest distance/MED_THRESH is smaller than */
+ /* minimum distance then the median ISF vector replacement is */
+ /* not performed */
+ summax2nd = shl_int32(summax2nd, tmp);
+ L_tmp = mul_16by16_to_int32(amr_wb_round(summax2nd), INV_MED_THRESH);
+
+ if (L_tmp <= summin)
+ {
+ indices[1] = -1;
+ }
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int16 dithering_control(dtx_encState * st)
+{
+ int16 i, tmp, mean, CN_dith, gain_diff;
+ int32 ISF_diff;
+
+ /* determine how stationary the spectrum of background noise is */
+ ISF_diff = 0;
+ for (i = 0; i < 8; i++)
+ {
+ ISF_diff = add_int32(ISF_diff, st->sumD[i]);
+ }
+ if ((ISF_diff >> 26) > 0)
+ {
+ CN_dith = 1;
+ }
+ else
+ {
+ CN_dith = 0;
+ }
+
+ /* determine how stationary the energy of background noise is */
+ mean = 0;
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ mean = add_int16(mean, st->log_en_hist[i]);
+ }
+ mean >>= 3;
+ gain_diff = 0;
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ tmp = sub_int16(st->log_en_hist[i], mean);
+ tmp = tmp - (tmp < 0);
+
+ gain_diff += tmp ^(tmp >> 15); /* tmp ^sign(tmp) */;
+ }
+ if (gain_diff > GAIN_THR)
+ {
+ CN_dith = 1;
+ }
+ return CN_dith;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void CN_dithering(
+ int16 isf[M],
+ int32 * L_log_en_int,
+ int16 * dither_seed
+)
+{
+ int16 temp, temp1, i, dither_fac, rand_dith;
+ int16 rand_dith2;
+
+ /* Insert comfort noise dithering for energy parameter */
+ rand_dith = noise_gen_amrwb(dither_seed) >> 1;
+ rand_dith2 = noise_gen_amrwb(dither_seed) >> 1;
+ rand_dith += rand_dith2;
+ *L_log_en_int = add_int32(*L_log_en_int, mul_16by16_to_int32(rand_dith, GAIN_FACTOR));
+
+ if (*L_log_en_int < 0)
+ {
+ *L_log_en_int = 0;
+ }
+ /* Insert comfort noise dithering for spectral parameters (ISF-vector) */
+ dither_fac = ISF_FACTOR_LOW;
+
+ rand_dith = noise_gen_amrwb(dither_seed) >> 1;
+ rand_dith2 = noise_gen_amrwb(dither_seed) >> 1;
+ rand_dith += rand_dith2;
+ temp = add_int16(isf[0], mult_int16_r(rand_dith, dither_fac));
+
+ /* Make sure that isf[0] will not get negative values */
+ if (temp < ISF_GAP)
+ {
+ isf[0] = ISF_GAP;
+ }
+ else
+ {
+ isf[0] = temp;
+ }
+
+ for (i = 1; i < M - 1; i++)
+ {
+ dither_fac = add_int16(dither_fac, ISF_FACTOR_STEP);
+
+ rand_dith = noise_gen_amrwb(dither_seed) >> 1;
+ rand_dith2 = noise_gen_amrwb(dither_seed) >> 1;
+ rand_dith += rand_dith2;
+ temp = add_int16(isf[i], mult_int16_r(rand_dith, dither_fac));
+ temp1 = sub_int16(temp, isf[i - 1]);
+
+ /* Make sure that isf spacing remains at least ISF_DITH_GAP Hz */
+ if (temp1 < ISF_DITH_GAP)
+ {
+ isf[i] = isf[i - 1] + ISF_DITH_GAP;
+ }
+ else
+ {
+ isf[i] = temp;
+ }
+ }
+
+ /* Make sure that isf[M-2] will not get values above 16384 */
+ if (isf[M - 2] > 16384)
+ {
+ isf[M - 2] = 16384;
+ }
+ return;
+}
diff --git a/media/codecs/amrwb/dec/src/e_pv_amrwbdec.h b/media/codecs/amrwb/dec/src/e_pv_amrwbdec.h
new file mode 100644
index 0000000..251a3ce
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/e_pv_amrwbdec.h
@@ -0,0 +1,136 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+
+ Filename: e_pv_amrwbdec.h
+ Funtions:
+
+
+ Date: 05/03/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef E_PV_AMRWBDEC_H
+#define E_PV_AMRWBDEC_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvamrwbdecoder_cnst.h" /* coder constant parameters */
+#include "dtx.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+
+typedef struct
+{
+ int16 old_exc[PIT_MAX + L_INTERPOL]; /* old excitation vector */
+ int16 ispold[M]; /* old isp (immittance spectral pairs)*/
+ int16 isfold[M]; /* old isf (frequency domain) */
+ int16 isf_buf[L_MEANBUF * M]; /* isf buffer(frequency domain) */
+ int16 past_isfq[M]; /* past isf quantizer */
+ int16 tilt_code; /* tilt of code */
+ int16 Q_old; /* old scaling factor */
+ int16 Qsubfr[4]; /* old maximum scaling factor */
+ int32 L_gc_thres; /* threshold for noise enhancer */
+ int16 mem_syn_hi[M]; /* modified synthesis memory (MSB) */
+ int16 mem_syn_lo[M]; /* modified synthesis memory (LSB) */
+ int16 mem_deemph; /* speech deemph filter memory */
+ int16 mem_sig_out[6]; /* hp50 filter memory for synthesis */
+ int16 mem_oversamp[2 * L_FILT]; /* synthesis oversampled filter memory */
+ int16 mem_syn_hf[M16k]; /* HF synthesis memory */
+ int16 mem_hf[2 * L_FILT16k]; /* HF band-pass filter memory */
+ int16 mem_hf2[2 * L_FILT16k]; /* HF band-pass filter memory */
+ int16 mem_hf3[2 * L_FILT16k]; /* HF band-pass filter memory */
+ int16 seed; /* random memory for frame erasure */
+ int16 seed2; /* random memory for HF generation */
+ int16 old_T0; /* old pitch lag */
+ int16 old_T0_frac; /* old pitch fraction lag */
+ int16 lag_hist[5];
+ int16 dec_gain[23]; /* gain decoder memory */
+ int16 seed3; /* random memory for lag concealment */
+ int16 disp_mem[8]; /* phase dispersion memory */
+ int16 mem_hp400[6]; /* hp400 filter memory for synthesis */
+
+ int16 prev_bfi;
+ int16 state;
+ int16 first_frame;
+ dtx_decState dtx_decSt;
+ int16 vad_hist;
+
+} Decoder_State;
+
+typedef struct
+{
+ Decoder_State state;
+ int16 ScratchMem[L_SUBFR + L_SUBFR16k + ((L_SUBFR + M + M16k +1)<<1) + \
+ (2*L_FRAME + 1) + PIT_MAX + L_INTERPOL + NB_SUBFR*(M+1) \
+ + 3*(M+L_SUBFR) + M16k];
+} PV_AmrWbDec;
+
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
diff --git a/media/codecs/amrwb/dec/src/get_amr_wb_bits.cpp b/media/codecs/amrwb/dec/src/get_amr_wb_bits.cpp
new file mode 100644
index 0000000..b325e8f
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/get_amr_wb_bits.cpp
@@ -0,0 +1,164 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: get_amr_wb_bits.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 no_of_bits, input : number of bits
+ int16 ** prms bitstream pointer
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns no_of_bits from serial bit stream
+ Serial_parm -> convert serial stream to parameters
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "get_amr_wb_bits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+int16 Serial_parm( /* Return the parameter */
+ int16 no_of_bits, /* input : number of bits */
+ int16 ** prms
+)
+{
+ int16 value = 0;
+ int16 i;
+
+ for (i = no_of_bits >> 1; i != 0; i--)
+ {
+ value <<= 2;
+
+ if (*((*prms)++) == BIT_1)
+ {
+ value |= 2;
+ }
+
+ if (*((*prms)++) == BIT_1)
+ {
+ value |= 1;
+ }
+
+ }
+
+ if (no_of_bits&1)
+ {
+ value <<= 1;
+
+ if (*((*prms)++) == BIT_1)
+ {
+ value |= 1;
+ }
+
+ }
+
+ return (value);
+}
+
+
+int16 Serial_parm_1bit(int16 ** prms) /* Return the parameter */
+{
+ int16 value = 0;
+
+ if (*((*prms)++) == BIT_1)
+ {
+ value = 1;
+ }
+ return (value);
+}
diff --git a/media/codecs/amrwb/dec/src/get_amr_wb_bits.h b/media/codecs/amrwb/dec/src/get_amr_wb_bits.h
new file mode 100644
index 0000000..48e43db
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/get_amr_wb_bits.h
@@ -0,0 +1,60 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*--------------------------------------------------------------------------*
+ * get_amr_wb_bits.h *
+ *--------------------------------------------------------------------------*
+ * Number of bits for different modes *
+ *--------------------------------------------------------------------------*/
+
+#ifndef GET_AMR_WB_BITS_H
+#define GET_AMR_WB_BITS_H
+
+
+#include "pv_amr_wb_type_defs.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ int16 Serial_parm( /* Return the parameter */
+ int16 no_of_bits, /* input : number of bits */
+ int16 ** prms
+ );
+
+ int16 Serial_parm_1bit( /* Return the parameter */
+ int16 ** prms
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/media/codecs/amrwb/dec/src/highpass_400hz_at_12k8.cpp b/media/codecs/amrwb/dec/src/highpass_400hz_at_12k8.cpp
new file mode 100644
index 0000000..6503454
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/highpass_400hz_at_12k8.cpp
@@ -0,0 +1,201 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: highpass_400Hz_at_12k8.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 signal[], input signal / output is divided by 16
+ int16 lg, lenght of signal
+ int16 mem[] filter memory [6]
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ 2nd order high pass filter with cut off frequency at 400 Hz.
+ Designed with cheby2 function in MATLAB.
+ Optimized for fixed-point to get the following frequency response:
+
+ frequency: 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz
+ dB loss: -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB
+
+ Algorithm:
+
+ y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2]
+ + a[1]*y[i-1] + a[2]*y[i-2];
+
+ int16 b[3] = {3660, -7320, 3660}; in Q12
+ int16 a[3] = {4096, 7320, -3540}; in Q12
+
+ float --> b[3] = {0.893554687, -1.787109375, 0.893554687};
+ a[3] = {1.000000000, 1.787109375, -0.864257812};
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+/* Initialization of static values */
+
+void highpass_400Hz_at_12k8_init(int16 mem[])
+{
+ pv_memset((void *)mem, 0, 6*sizeof(*mem));
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void highpass_400Hz_at_12k8(
+ int16 signal[], /* input signal / output is divided by 16 */
+ int16 lg, /* lenght of signal */
+ int16 mem[] /* filter memory [6] */
+)
+{
+ int16 i, x2;
+ int16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1;
+ int32 L_tmp1;
+ int32 L_tmp2;
+
+ y2_hi = mem[0];
+ y2_lo = mem[1];
+ y1_hi = mem[2];
+ y1_lo = mem[3];
+ x0 = mem[4];
+ x1 = mem[5];
+
+ for (i = 0; i < lg; i++)
+ {
+
+ /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[0]*x[i-2] */
+ /* + a[0]*y[i-1] + a[1] * y[i-2]; */
+
+ L_tmp1 = fxp_mac_16by16(y1_lo, 29280, 8192L);
+ L_tmp2 = fxp_mul_16by16(y1_hi, 29280);
+ L_tmp1 = fxp_mac_16by16(y2_lo, -14160, L_tmp1);
+ L_tmp2 = fxp_mac_16by16(y2_hi, -14160, L_tmp2);
+ x2 = x1;
+ x1 = x0;
+ x0 = signal[i];
+ L_tmp2 = fxp_mac_16by16(x2, 915, L_tmp2);
+ L_tmp2 = fxp_mac_16by16(x1, -1830, L_tmp2);
+ L_tmp2 = fxp_mac_16by16(x0, 915, L_tmp2);
+
+ L_tmp1 = (L_tmp1 >> 13) + (L_tmp2 << 2); /* coeff Q12 --> Q13 */
+
+ y2_hi = y1_hi;
+ y2_lo = y1_lo;
+ /* signal is divided by 16 to avoid overflow in energy computation */
+ signal[i] = (int16)((L_tmp1 + 0x00008000) >> 16);
+
+ y1_hi = (int16)(L_tmp1 >> 16);
+ y1_lo = (int16)((L_tmp1 - (y1_hi << 16)) >> 1);
+
+
+ }
+
+
+ mem[0] = y2_hi;
+ mem[1] = y2_lo;
+ mem[2] = y1_hi;
+ mem[3] = y1_lo;
+ mem[4] = x0;
+ mem[5] = x1;
+
+}
+
+
diff --git a/media/codecs/amrwb/dec/src/highpass_50hz_at_12k8.cpp b/media/codecs/amrwb/dec/src/highpass_50hz_at_12k8.cpp
new file mode 100644
index 0000000..c70c163
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/highpass_50hz_at_12k8.cpp
@@ -0,0 +1,205 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: highpass_50Hz_at_12k8.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 signal[], input signal / output is divided by 16
+ int16 lg, lenght of signal
+ int16 mem[] filter memory [6]
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ 2nd order high pass filter with cut off frequency at 31 Hz.
+ Designed with cheby2 function in MATLAB.
+ Optimized for fixed-point to get the following frequency response:
+
+ frequency: 0Hz 14Hz 24Hz 31Hz 37Hz 41Hz 47Hz
+ dB loss: -infdB -15dB -6dB -3dB -1.5dB -1dB -0.5dB
+
+ Algorithm:
+
+ y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2]
+ + a[1]*y[i-1] + a[2]*y[i-2];
+
+ int16 b[3] = {4053, -8106, 4053}; in Q12
+ int16 a[3] = {8192, 16211, -8021}; in Q12
+
+ float --> b[3] = {0.989501953, -1.979003906, 0.989501953};
+ a[3] = {1.000000000, 1.978881836, -0.979125977};
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void highpass_50Hz_at_12k8_init(int16 mem[])
+{
+ pv_memset((void *)mem, 0, 6*sizeof(*mem));
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void highpass_50Hz_at_12k8(
+ int16 signal[], /* input/output signal */
+ int16 lg, /* lenght of signal */
+ int16 mem[] /* filter memory [6] */
+)
+{
+ int16 i, x2;
+ int16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1;
+ int32 L_tmp1;
+ int32 L_tmp2;
+ int16 *pt_sign = signal;
+
+ y2_hi = mem[0];
+ y2_lo = mem[1];
+ y1_hi = mem[2];
+ y1_lo = mem[3];
+ x0 = mem[4];
+ x1 = mem[5];
+
+
+ for (i = lg; i != 0; i--)
+ {
+
+ /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[0]*x[i-2] */
+ /* + a[0]*y[i-1] + a[1] * y[i-2]; */
+
+ L_tmp1 = fxp_mac_16by16(y1_lo, 16211, 8192L);
+ L_tmp1 = fxp_mac_16by16(y2_lo, -8021, L_tmp1);
+ L_tmp2 = fxp_mul_16by16(y1_hi, 32422);
+ L_tmp2 = fxp_mac_16by16(y2_hi, -16042, L_tmp2);
+
+ x2 = x1;
+ x1 = x0;
+ x0 = *pt_sign;
+ L_tmp2 = fxp_mac_16by16(x2, 8106, L_tmp2);
+ L_tmp2 = fxp_mac_16by16(x1, -16212, L_tmp2);
+ L_tmp2 = fxp_mac_16by16(x0, 8106, L_tmp2);
+
+
+ L_tmp1 = ((L_tmp1 >> 14) + L_tmp2) << 2;
+
+ y2_hi = y1_hi;
+ y2_lo = y1_lo;
+ y1_hi = (int16)(L_tmp1 >> 16);
+ y1_lo = (int16)((L_tmp1 - (y1_hi << 16)) >> 1);
+
+ /* coeff Q14 --> Q15 with saturation */
+ *(pt_sign++) = amr_wb_shl1_round(L_tmp1);
+
+ }
+
+
+ mem[0] = y2_hi;
+ mem[1] = y2_lo;
+ mem[2] = y1_hi;
+ mem[3] = y1_lo;
+ mem[4] = x0;
+ mem[5] = x1;
+
+}
+
diff --git a/media/codecs/amrwb/dec/src/homing_amr_wb_dec.cpp b/media/codecs/amrwb/dec/src/homing_amr_wb_dec.cpp
new file mode 100644
index 0000000..dde3e43
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/homing_amr_wb_dec.cpp
@@ -0,0 +1,370 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: homing_amr_wb_dec.cpp
+
+ Date: 4/25/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+
+
+
+INPUT AND OUTPUT DEFINITIONS
+
+Input
+ int16 input_frame[], 16-bit input frame
+ int16 mode 16-bit mode
+ int16 nparms 16-bit number of parameters
+Returns
+ Int16 i number of leading zeros on x
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Performs the homing routines
+
+ int16 dhf_test(int16 input_frame[], int16 mode, int16 nparms)
+ int16 decoder_homing_frame_test(int16 input_frame[], int16 mode)
+ int16 decoder_homing_frame_test_first(int16 input_frame[], int16 mode)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "get_amr_wb_bits.h"
+#include "pvamrwbdecoder_api.h"
+#include "pvamrwbdecoder.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define DHF_PARMS_MAX 32 /* homing frame pattern */
+#define NUM_OF_SPMODES 9
+
+#define PRML 15
+#define PRMN_7k (NBBITS_7k/PRML + 1)
+#define PRMN_9k (NBBITS_9k/PRML + 1)
+#define PRMN_12k (NBBITS_12k/PRML + 1)
+#define PRMN_14k (NBBITS_14k/PRML + 1)
+#define PRMN_16k (NBBITS_16k/PRML + 1)
+#define PRMN_18k (NBBITS_18k/PRML + 1)
+#define PRMN_20k (NBBITS_20k/PRML + 1)
+#define PRMN_23k (NBBITS_23k/PRML + 1)
+#define PRMN_24k (NBBITS_24k/PRML + 1)
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int16 dhf_test(int16 input_frame[], int32 mode, int16 nparms);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+static const int16 prmnofsf[NUM_OF_SPMODES] =
+{
+ 63, 81, 100,
+ 108, 116, 128,
+ 136, 152, 156
+};
+
+
+static const int16 dfh_M7k[PRMN_7k] =
+{
+ 3168, 29954, 29213, 16121,
+ 64, 13440, 30624, 16430,
+ 19008
+};
+
+static const int16 dfh_M9k[PRMN_9k] =
+{
+ 3168, 31665, 9943, 9123,
+ 15599, 4358, 20248, 2048,
+ 17040, 27787, 16816, 13888
+};
+
+static const int16 dfh_M12k[PRMN_12k] =
+{
+ 3168, 31665, 9943, 9128,
+ 3647, 8129, 30930, 27926,
+ 18880, 12319, 496, 1042,
+ 4061, 20446, 25629, 28069,
+ 13948
+};
+
+static const int16 dfh_M14k[PRMN_14k] =
+{
+ 3168, 31665, 9943, 9131,
+ 24815, 655, 26616, 26764,
+ 7238, 19136, 6144, 88,
+ 4158, 25733, 30567, 30494,
+ 221, 20321, 17823
+};
+
+static const int16 dfh_M16k[PRMN_16k] =
+{
+ 3168, 31665, 9943, 9131,
+ 24815, 700, 3824, 7271,
+ 26400, 9528, 6594, 26112,
+ 108, 2068, 12867, 16317,
+ 23035, 24632, 7528, 1752,
+ 6759, 24576
+};
+
+static const int16 dfh_M18k[PRMN_18k] =
+{
+ 3168, 31665, 9943, 9135,
+ 14787, 14423, 30477, 24927,
+ 25345, 30154, 916, 5728,
+ 18978, 2048, 528, 16449,
+ 2436, 3581, 23527, 29479,
+ 8237, 16810, 27091, 19052,
+ 0
+};
+
+static const int16 dfh_M20k[PRMN_20k] =
+{
+ 3168, 31665, 9943, 9129,
+ 8637, 31807, 24646, 736,
+ 28643, 2977, 2566, 25564,
+ 12930, 13960, 2048, 834,
+ 3270, 4100, 26920, 16237,
+ 31227, 17667, 15059, 20589,
+ 30249, 29123, 0
+};
+
+static const int16 dfh_M23k[PRMN_23k] =
+{
+ 3168, 31665, 9943, 9132,
+ 16748, 3202, 28179, 16317,
+ 30590, 15857, 19960, 8818,
+ 21711, 21538, 4260, 16690,
+ 20224, 3666, 4194, 9497,
+ 16320, 15388, 5755, 31551,
+ 14080, 3574, 15932, 50,
+ 23392, 26053, 31216
+};
+
+static const int16 dfh_M24k[PRMN_24k] =
+{
+ 3168, 31665, 9943, 9134,
+ 24776, 5857, 18475, 28535,
+ 29662, 14321, 16725, 4396,
+ 29353, 10003, 17068, 20504,
+ 720, 0, 8465, 12581,
+ 28863, 24774, 9709, 26043,
+ 7941, 27649, 13965, 15236,
+ 18026, 22047, 16681, 3968
+};
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int16 dhf_test(int16 input_frame[], int32 mode, int16 nparms)
+{
+ int16 i, j, tmp, shift;
+ int16 param[DHF_PARMS_MAX];
+ int16 *prms;
+
+ /* overall table with the parameters of the
+ decoder homing frames for all modes */
+
+ const int16 *dhf[] =
+ {
+ dfh_M7k,
+ dfh_M9k,
+ dfh_M12k,
+ dfh_M14k,
+ dfh_M16k,
+ dfh_M18k,
+ dfh_M20k,
+ dfh_M23k,
+ dfh_M24k,
+ dfh_M24k
+ };
+
+ prms = input_frame;
+ j = 0;
+ i = 0;
+
+ if (mode != MRDTX)
+ {
+ if (mode != MODE_24k)
+ {
+ /* convert the received serial bits */
+ tmp = nparms - 15;
+ while (tmp > j)
+ {
+ param[i] = Serial_parm(15, &prms);
+ j += 15;
+ i++;
+ }
+ tmp = nparms - j;
+ param[i] = Serial_parm(tmp, &prms);
+ shift = 15 - tmp;
+ param[i] = shl_int16(param[i], shift);
+ }
+ else
+ {
+ /*If mode is 23.85Kbit/s, remove high band energy bits */
+ for (i = 0; i < 10; i++)
+ {
+ param[i] = Serial_parm(15, &prms);
+ }
+ param[10] = Serial_parm(15, &prms) & 0x61FF;
+
+ for (i = 11; i < 17; i++)
+ {
+ param[i] = Serial_parm(15, &prms);
+ }
+ param[17] = Serial_parm(15, &prms) & 0xE0FF;
+
+ for (i = 18; i < 24; i++)
+ {
+ param[i] = Serial_parm(15, &prms);
+ }
+ param[24] = Serial_parm(15, &prms) & 0x7F0F;
+
+ for (i = 25; i < 31; i++)
+ {
+ param[i] = Serial_parm(15, &prms);
+ }
+
+ tmp = Serial_parm(8, &prms);
+ param[31] = shl_int16(tmp, 7);
+ shift = 0;
+ }
+
+ /* check if the parameters matches the parameters of the corresponding decoder homing frame */
+ tmp = i;
+ j = 0;
+ for (i = 0; i < tmp; i++)
+ {
+ j = (param[i] ^ dhf[mode][i]);
+ if (j)
+ {
+ break;
+ }
+ }
+ tmp = 0x7fff;
+ tmp >>= shift;
+ tmp = shl_int16(tmp, shift);
+ tmp = (dhf[mode][i] & tmp);
+ tmp = (param[i] ^ tmp);
+ j = (int16)(j | tmp);
+
+ }
+ else
+ {
+ j = 1;
+ }
+
+ return (!j);
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+int16 pvDecoder_AmrWb_homing_frame_test(int16 input_frame[], int16 mode)
+{
+ /* perform test for COMPLETE parameter frame */
+ return dhf_test(input_frame, mode, AMR_WB_COMPRESSED[mode]);
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+int16 pvDecoder_AmrWb_homing_frame_test_first(int16 input_frame[], int16 mode)
+{
+ /* perform test for FIRST SUBFRAME of parameter frame ONLY */
+ return dhf_test(input_frame, mode, prmnofsf[mode]);
+}
diff --git a/media/codecs/amrwb/dec/src/interpolate_isp.cpp b/media/codecs/amrwb/dec/src/interpolate_isp.cpp
new file mode 100644
index 0000000..3ccebdb
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/interpolate_isp.cpp
@@ -0,0 +1,146 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: interpolate_isp.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 isp_old[], input : isps from past frame
+ int16 isp_new[], input : isps from present frame
+ const int16 frac[], input : fraction for 3 first subfr (Q15)
+ int16 Az[] output: LP coefficients in 4 subframes
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Interpolation of the LP parameters in 4 subframes
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define MP1 (M+1)
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void interpolate_isp(
+ int16 isp_old[], /* input : isps from past frame */
+ int16 isp_new[], /* input : isps from present frame */
+ const int16 frac[], /* input : fraction for 3 first subfr (Q15) */
+ int16 Az[] /* output: LP coefficients in 4 subframes */
+)
+{
+ int16 i, k, fac_old, fac_new;
+ int16 isp[M];
+ int32 L_tmp;
+
+ for (k = 0; k < 3; k++)
+ {
+ fac_new = frac[k];
+ fac_old = add_int16(sub_int16(32767, fac_new), 1); /* 1.0 - fac_new */
+
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = mul_16by16_to_int32(isp_old[i], fac_old);
+ L_tmp = mac_16by16_to_int32(L_tmp, isp_new[i], fac_new);
+ isp[i] = amr_wb_round(L_tmp);
+ }
+ Isp_Az(isp, Az, M, 0);
+ Az += MP1;
+ }
+
+ /* 4th subframe: isp_new (frac=1.0) */
+
+ Isp_Az(isp_new, Az, M, 0);
+
+ return;
+}
diff --git a/media/codecs/amrwb/dec/src/isf_extrapolation.cpp b/media/codecs/amrwb/dec/src/isf_extrapolation.cpp
new file mode 100644
index 0000000..72d353a
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/isf_extrapolation.cpp
@@ -0,0 +1,274 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: isf_extrapolation.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 HfIsf[] (i/o) isf vector
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Conversion of 16th-order 12.8kHz ISF vector
+ into 20th-order 16kHz ISF vector
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "pvamrwb_math_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define INV_LENGTH 2731 /* 1/12 */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void isf_extrapolation(int16 HfIsf[])
+{
+ int16 IsfDiff[M - 2];
+ int32 IsfCorr[3];
+ int32 L_tmp;
+ int16 coeff, mean, tmp, tmp2, tmp3;
+ int16 exp, exp2, hi, lo;
+ int16 i, MaxCorr;
+
+ HfIsf[M16k - 1] = HfIsf[M - 1];
+
+ /* Difference vector */
+ for (i = 1; i < (M - 1); i++)
+ {
+ IsfDiff[i - 1] = sub_int16(HfIsf[i], HfIsf[i - 1]);
+ }
+ L_tmp = 0;
+
+ /* Mean of difference vector */
+ for (i = 3; i < (M - 1); i++)
+ {
+ L_tmp = mac_16by16_to_int32(L_tmp, IsfDiff[i - 1], INV_LENGTH);
+
+ }
+ mean = amr_wb_round(L_tmp);
+
+ IsfCorr[0] = 0;
+
+ tmp = 0;
+ for (i = 0; i < (M - 2); i++)
+ {
+ if (IsfDiff[i] > tmp)
+ {
+ tmp = IsfDiff[i];
+ }
+ }
+ exp = norm_s(tmp);
+ for (i = 0; i < (M - 2); i++)
+ {
+ IsfDiff[i] = shl_int16(IsfDiff[i], exp);
+ }
+ mean = shl_int16(mean, exp);
+ for (i = 7; i < (M - 2); i++)
+ {
+ tmp2 = sub_int16(IsfDiff[i], mean);
+ tmp3 = sub_int16(IsfDiff[i - 2], mean);
+ L_tmp = mul_16by16_to_int32(tmp2, tmp3);
+ int32_to_dpf(L_tmp, &hi, &lo);
+ L_tmp = mpy_dpf_32(hi, lo, hi, lo);
+ IsfCorr[0] = add_int32(IsfCorr[0], L_tmp);
+ }
+ IsfCorr[1] = 0;
+ for (i = 7; i < (M - 2); i++)
+ {
+ tmp2 = sub_int16(IsfDiff[i], mean);
+ tmp3 = sub_int16(IsfDiff[i - 3], mean);
+ L_tmp = mul_16by16_to_int32(tmp2, tmp3);
+ int32_to_dpf(L_tmp, &hi, &lo);
+ L_tmp = mpy_dpf_32(hi, lo, hi, lo);
+ IsfCorr[1] = add_int32(IsfCorr[1], L_tmp);
+ }
+ IsfCorr[2] = 0;
+ for (i = 7; i < (M - 2); i++)
+ {
+ tmp2 = sub_int16(IsfDiff[i], mean);
+ tmp3 = sub_int16(IsfDiff[i - 4], mean);
+ L_tmp = mul_16by16_to_int32(tmp2, tmp3);
+ int32_to_dpf(L_tmp, &hi, &lo);
+ L_tmp = mpy_dpf_32(hi, lo, hi, lo);
+ IsfCorr[2] = add_int32(IsfCorr[2], L_tmp);
+ }
+
+ if (IsfCorr[0] > IsfCorr[1])
+ {
+ MaxCorr = 0;
+ }
+ else
+ {
+ MaxCorr = 1;
+ }
+
+
+ if (IsfCorr[2] > IsfCorr[MaxCorr])
+ {
+ MaxCorr = 2;
+ }
+
+ MaxCorr++; /* Maximum correlation of difference vector */
+
+ for (i = M - 1; i < (M16k - 1); i++)
+ {
+ tmp = sub_int16(HfIsf[i - 1 - MaxCorr], HfIsf[i - 2 - MaxCorr]);
+ HfIsf[i] = add_int16(HfIsf[i - 1], tmp);
+ }
+
+ /* tmp=7965+(HfIsf[2]-HfIsf[3]-HfIsf[4])/6; */
+ tmp = add_int16(HfIsf[4], HfIsf[3]);
+ tmp = sub_int16(HfIsf[2], tmp);
+ tmp = mult_int16(tmp, 5461);
+ tmp += 20390;
+
+
+ if (tmp > 19456)
+ { /* Maximum value of ISF should be at most 7600 Hz */
+ tmp = 19456;
+ }
+ tmp = sub_int16(tmp, HfIsf[M - 2]);
+ tmp2 = sub_int16(HfIsf[M16k - 2], HfIsf[M - 2]);
+
+ exp2 = norm_s(tmp2);
+ exp = norm_s(tmp);
+ exp--;
+ tmp <<= exp;
+ tmp2 <<= exp2;
+ coeff = div_16by16(tmp, tmp2); /* Coefficient for stretching the ISF vector */
+ exp = exp2 - exp;
+
+ for (i = M - 1; i < (M16k - 1); i++)
+ {
+ tmp = mult_int16(sub_int16(HfIsf[i], HfIsf[i - 1]), coeff);
+ IsfDiff[i - (M - 1)] = shl_int16(tmp, exp);
+ }
+
+ for (i = M; i < (M16k - 1); i++)
+ {
+ /* The difference between ISF(n) and ISF(n-2) should be at least 500 Hz */
+ tmp = IsfDiff[i - (M - 1)] + IsfDiff[i - M] - 1280;
+
+ if (tmp < 0)
+ {
+
+ if (IsfDiff[i - (M - 1)] > IsfDiff[i - M])
+ {
+ IsfDiff[i - M] = 1280 - IsfDiff[i - (M - 1)];
+ }
+ else
+ {
+ IsfDiff[i - (M - 1)] = 1280 - IsfDiff[i - M];
+ }
+ }
+ }
+
+ for (i = M - 1; i < (M16k - 1); i++)
+ {
+ HfIsf[i] = add_int16(HfIsf[i - 1], IsfDiff[i - (M - 1)]);
+ }
+
+ for (i = 0; i < (M16k - 1); i++)
+ {
+ HfIsf[i] = mult_int16(HfIsf[i], 26214); /* Scale the ISF vector correctly for 16000 kHz */
+ }
+
+ Isf_isp(HfIsf, HfIsf, M16k);
+
+ return;
+}
+
+
diff --git a/media/codecs/amrwb/dec/src/isp_az.cpp b/media/codecs/amrwb/dec/src/isp_az.cpp
new file mode 100644
index 0000000..40093f5
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/isp_az.cpp
@@ -0,0 +1,403 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: isp_az.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 isp[], (i) Q15 : Immittance spectral pairs
+ int16 a[], (o) Q12 : predictor coefficients (order=M)
+ int16 m, (i) : order
+ int16 adaptive_scaling (i) 0 : adaptive scaling disabled
+ 1 : adaptive scaling enabled
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Compute the LPC coefficients from isp (order=M)
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "pvamrwb_math_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NC (M/2)
+#define NC16k (M16k/2)
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void Get_isp_pol(int16 * isp, int32 * f, int16 n);
+ void Get_isp_pol_16kHz(int16 * isp, int32 * f, int16 n);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Isp_Az(
+ int16 isp[], /* (i) Q15 : Immittance spectral pairs */
+ int16 a[], /* (o) Q12 : predictor coefficients (order=M) */
+ int16 m, /* (i) : order */
+ int16 adaptive_scaling /* (i) 0 : adaptive scaling disabled */
+ /* 1 : adaptive scaling enabled */
+)
+{
+ int16 i, j;
+ int32 f1[NC16k + 1], f2[NC16k];
+ int16 nc;
+ int32 t0;
+ int32 t1;
+ int16 q, q_sug;
+ int32 tmax;
+
+ nc = m >> 1;
+
+
+ if (nc > 8)
+ {
+ Get_isp_pol_16kHz(&isp[0], f1, nc);
+ for (i = 0; i <= nc; i++)
+ {
+ f1[i] = shl_int32(f1[i], 2);
+ }
+ Get_isp_pol_16kHz(&isp[1], f2, nc - 1);
+ for (i = 0; i <= nc - 1; i++)
+ {
+ f2[i] = shl_int32(f2[i], 2);
+ }
+ }
+ else
+ {
+ Get_isp_pol(&isp[0], f1, nc);
+ Get_isp_pol(&isp[1], f2, nc - 1);
+ }
+
+ /*
+ * Multiply F2(z) by (1 - z^-2)
+ */
+
+ for (i = nc - 1; i > 1; i--)
+ {
+ f2[i] -= f2[i - 2]; /* f2[i] -= f2[i-2]; */
+ }
+
+ /*
+ * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1])
+ */
+
+ for (i = 0; i < nc; i++)
+ {
+ /* f1[i] *= (1.0 + isp[M-1]); */
+
+ /* f2[i] *= (1.0 - isp[M-1]); */
+ t0 = f1[i];
+ t1 = f2[i];
+ t0 = fxp_mul32_by_16b(t0, isp[m - 1]) << 1;
+ t1 = fxp_mul32_by_16b(t1, isp[m - 1]) << 1;
+ f1[i] += t0;
+ f2[i] -= t1;
+
+ }
+
+ /*
+ * A(z) = (F1(z)+F2(z))/2
+ * F1(z) is symmetric and F2(z) is antisymmetric
+ */
+
+ /* a[0] = 1.0; */
+ a[0] = 4096;
+ tmax = 1;
+ j = m - 1;
+ for (i = 1; i < nc; i++)
+ {
+ /* a[i] = 0.5*(f1[i] + f2[i]); */
+
+ t0 = add_int32(f1[i], f2[i]); /* f1[i] + f2[i] */
+ /* compute t1 = abs(t0) */
+ t1 = t0 - (t0 < 0);
+ t1 = t1 ^(t1 >> 31); /* t1 = t1 ^sign(t1) */
+
+ tmax |= t1;
+ /* from Q23 to Q12 and * 0.5 */
+ a[i] = (int16)((t0 >> 12) + ((t0 >> 11) & 1));
+
+
+ /* a[j] = 0.5*(f1[i] - f2[i]); */
+
+ t0 = sub_int32(f1[i], f2[i]); /* f1[i] - f2[i] */
+ /* compute t1 = abs(t0) */
+ t1 = t0 - (t0 < 0);
+ t1 = t1 ^(t1 >> 31); /* t1 = t1 ^sign(t1) */
+
+ tmax |= t1;
+
+ /* from Q23 to Q12 and * 0.5 */
+ a[j--] = (int16)((t0 >> 12) + ((t0 >> 11) & 1));
+
+ }
+
+ /* rescale data if overflow has occured and reprocess the loop */
+
+
+ if (adaptive_scaling == 1)
+ {
+ q = 4 - normalize_amr_wb(tmax); /* adaptive scaling enabled */
+ }
+ else
+ {
+ q = 0; /* adaptive scaling disabled */
+ }
+
+
+ if (q > 0)
+ {
+ q_sug = 12 + q;
+ for (i = 1, j = m - 1; i < nc; i++, j--)
+ {
+ /* a[i] = 0.5*(f1[i] + f2[i]); */
+
+ t0 = add_int32(f1[i], f2[i]); /* f1[i] + f2[i] */
+ /* from Q23 to Q12 and * 0.5 */
+ a[i] = (int16)((t0 >> q_sug) + ((t0 >> (q_sug - 1)) & 1));
+
+
+ /* a[j] = 0.5*(f1[i] - f2[i]); */
+
+ t0 = sub_int32(f1[i], f2[i]); /* f1[i] - f2[i] */
+ /* from Q23 to Q12 and * 0.5 */
+ a[j] = (int16)((t0 >> q_sug) + ((t0 >> (q_sug - 1)) & 1));
+
+ }
+ a[0] >>= q;
+ }
+ else
+ {
+ q_sug = 12;
+ q = 0;
+ }
+
+ /* a[NC] = 0.5*f1[NC]*(1.0 + isp[M-1]); */
+
+
+ t0 = (int32)(((int64)f1[nc] * isp[m - 1]) >> 16) << 1;
+
+
+ t0 = add_int32(f1[nc], t0);
+
+ /* from Q23 to Q12 and * 0.5 */
+ a[nc] = (int16)((t0 >> q_sug) + ((t0 >> (q_sug - 1)) & 1));
+ a[m] = shr_rnd(isp[m - 1], (3 + q)); /* from Q15 to Q12 */
+
+ /* a[m] = isp[m-1]; */
+
+
+ return;
+}
+
+
+
+/*
+Get_isp_pol
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ isp[] : isp vector (cosine domaine) in Q15
+ f[] : the coefficients of F1 or F2 in Q23
+ n : == NC for F1(z); == NC-1 for F2(z)
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Find the polynomial F1(z) or F2(z) from the ISPs.
+ This is performed by expanding the product polynomials:
+
+ F1(z) = product ( 1 - 2 isp_i z^-1 + z^-2 )
+ i=0,2,4,6,8
+ F2(z) = product ( 1 - 2 isp_i z^-1 + z^-2 )
+ i=1,3,5,7
+
+ where isp_i are the ISPs in the cosine domain.
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void Get_isp_pol(int16 * isp, int32 * f, int16 n)
+{
+ int16 i, j;
+ int32 t0;
+
+
+ /* All computation in Q23 */
+
+ f[0] = 0x00800000; /* f[0] = 1.0; in Q23 */
+ f[1] = -isp[0] << 9; /* f[1] = -2.0*isp[0] in Q23 */
+
+ f += 2; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+
+ for (i = 2; i <= n; i++)
+ {
+ *f = f[-2];
+
+ for (j = 1; j < i; j++)
+ {
+
+ t0 = fxp_mul32_by_16b(f[-1], *isp);
+ t0 = shl_int32(t0, 2);
+
+ *f -= t0; /* *f -= t0 */
+ *(f) += f[-2]; /* *f += f[-2] */
+ f--;
+
+
+ }
+ *f -= *isp << 9;
+
+ f += i; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+ }
+}
+
+void Get_isp_pol_16kHz(int16 * isp, int32 * f, int16 n)
+{
+ int16 i, j;
+ int32 t0;
+
+ /* All computation in Q23 */
+
+ f[0] = 0x00200000; /* f[0] = 0.25; in Q23 */
+
+ f[1] = -isp[0] << 7; /* f[1] = -0.5*isp[0] in Q23 */
+
+ f += 2; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+
+ for (i = 2; i <= n; i++)
+ {
+ *f = f[-2];
+
+ for (j = 1; j < i; j++, f--)
+ {
+ t0 = fxp_mul32_by_16b(f[-1], *isp);
+ t0 = shl_int32(t0, 2);
+
+ *f -= t0; /* *f -= t0 */
+ *f += f[-2]; /* *f += f[-2] */
+ }
+ *f -= *isp << 7;
+ f += i; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+ }
+ return;
+}
+
diff --git a/media/codecs/amrwb/dec/src/isp_isf.cpp b/media/codecs/amrwb/dec/src/isp_isf.cpp
new file mode 100644
index 0000000..0552733
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/isp_isf.cpp
@@ -0,0 +1,175 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: isp_isf.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 isf[], (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5)
+ int16 isp[], (o) Q15 : isp[m] (range: -1<=val<1)
+ int16 m (i) : LPC order
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Isf_isp Transformation isf to isp
+
+ The transformation from isf[i] to isp[i] is
+ approximated by a look-up table and interpolation.
+
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* Look-up table for transformations */
+
+/* table of cos(x) in Q15 */
+
+static const int16 table[129] =
+{
+ 32767,
+ 32758, 32729, 32679, 32610, 32522, 32413, 32286, 32138,
+ 31972, 31786, 31581, 31357, 31114, 30853, 30572, 30274,
+ 29957, 29622, 29269, 28899, 28511, 28106, 27684, 27246,
+ 26791, 26320, 25833, 25330, 24812, 24279, 23732, 23170,
+ 22595, 22006, 21403, 20788, 20160, 19520, 18868, 18205,
+ 17531, 16846, 16151, 15447, 14733, 14010, 13279, 12540,
+ 11793, 11039, 10279, 9512, 8740, 7962, 7180, 6393,
+ 5602, 4808, 4011, 3212, 2411, 1608, 804, 0,
+ -804, -1608, -2411, -3212, -4011, -4808, -5602, -6393,
+ -7180, -7962, -8740, -9512, -10279, -11039, -11793, -12540,
+ -13279, -14010, -14733, -15447, -16151, -16846, -17531, -18205,
+ -18868, -19520, -20160, -20788, -21403, -22006, -22595, -23170,
+ -23732, -24279, -24812, -25330, -25833, -26320, -26791, -27246,
+ -27684, -28106, -28511, -28899, -29269, -29622, -29957, -30274,
+ -30572, -30853, -31114, -31357, -31581, -31786, -31972, -32138,
+ -32286, -32413, -32522, -32610, -32679, -32729, -32758, -32768
+};
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void Isf_isp(
+ int16 isf[], /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
+ int16 isp[], /* (o) Q15 : isp[m] (range: -1<=val<1) */
+ int16 m /* (i) : LPC order */
+)
+{
+ int16 i, ind, offset;
+ int32 L_tmp;
+
+ for (i = 0; i < m - 1; i++)
+ {
+ isp[i] = isf[i];
+ }
+ isp[m - 1] = shl_int16(isf[m - 1], 1);
+
+ for (i = 0; i < m; i++)
+ {
+ ind = isp[i] >> 7; /* ind = b7-b15 of isf[i] */
+ offset = (isp[i] & 0x007f); /* offset = b0-b6 of isf[i] */
+
+ /* isp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 128 */
+
+ L_tmp = mul_16by16_to_int32(table[ind + 1] - table[ind], offset);
+ isp[i] = add_int16(table[ind], (int16)(L_tmp >> 8));
+ }
+
+ return;
+}
diff --git a/media/codecs/amrwb/dec/src/lagconceal.cpp b/media/codecs/amrwb/dec/src/lagconceal.cpp
new file mode 100644
index 0000000..c699808
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/lagconceal.cpp
@@ -0,0 +1,364 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: lagconceal.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 gain_hist[], (i) : Gain history
+ int16 lag_hist[], (i) : Subframe size
+ int16 * T0, (i/o): current lag
+ int16 * old_T0, (i/o): previous lag
+ int16 * seed,
+ int16 unusable_frame
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Concealment of LTP lags during bad frames
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define L_LTPHIST 5
+#define ONE_PER_3 10923
+#define ONE_PER_LTPHIST 6554
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+void insertion_sort(int16 array[], int16 n);
+void insert(int16 array[], int16 num, int16 x);
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void Init_Lagconc(int16 lag_hist[])
+{
+ int16 i;
+
+ for (i = 0; i < L_LTPHIST; i++)
+ {
+ lag_hist[i] = 64;
+ }
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void lagconceal(
+ int16 gain_hist[], /* (i) : Gain history */
+ int16 lag_hist[], /* (i) : Subframe size */
+ int16 * T0,
+ int16 * old_T0,
+ int16 * seed,
+ int16 unusable_frame
+)
+{
+ int16 maxLag, minLag, lastLag, lagDif, meanLag = 0;
+ int16 lag_hist2[L_LTPHIST] = {0};
+ int16 i, tmp, tmp2;
+ int16 minGain, lastGain, secLastGain;
+ int16 D, D2;
+
+ /* Is lag index such that it can be aplied directly or does it has to be subtituted */
+
+ lastGain = gain_hist[4];
+ secLastGain = gain_hist[3];
+
+ lastLag = lag_hist[0];
+
+ /******* SMALLEST history lag *******/
+ minLag = lag_hist[0];
+ /******* BIGGEST history lag *******/
+ maxLag = lag_hist[0];
+ for (i = 1; i < L_LTPHIST; i++)
+ {
+ if (lag_hist[i] < minLag)
+ {
+ minLag = lag_hist[i];
+ }
+ if (lag_hist[i] > maxLag)
+ {
+ maxLag = lag_hist[i];
+ }
+ }
+ /***********SMALLEST history gain***********/
+ minGain = gain_hist[0];
+ for (i = 1; i < L_LTPHIST; i++)
+ {
+
+ if (gain_hist[i] < minGain)
+ {
+ minGain = gain_hist[i];
+ }
+ }
+ /***Difference between MAX and MIN lag**/
+ lagDif = sub_int16(maxLag, minLag);
+
+
+ if (unusable_frame != 0)
+ {
+ /* LTP-lag for RX_SPEECH_LOST */
+ /**********Recognition of the LTP-history*********/
+
+ if ((minGain > 8192) && (lagDif < 10))
+ {
+ *T0 = *old_T0;
+ }
+ else if (lastGain > 8192 && secLastGain > 8192)
+ {
+ *T0 = lag_hist[0];
+ }
+ else
+ {
+ /********SORT************/
+ /* The sorting of the lag history */
+ for (i = 0; i < L_LTPHIST; i++)
+ {
+ lag_hist2[i] = lag_hist[i];
+ }
+ insertion_sort(lag_hist2, 5);
+
+ /* Lag is weighted towards bigger lags */
+ /* and random variation is added */
+ lagDif = sub_int16(lag_hist2[4], lag_hist2[2]);
+
+
+ if (lagDif > 40)
+ {
+ lagDif = 40;
+ }
+
+ D = noise_gen_amrwb(seed); /* D={-1, ...,1} */
+ /* D2={-lagDif/2..lagDif/2} */
+ tmp = lagDif >> 1;
+ D2 = mult_int16(tmp, D);
+ tmp = add_int16(add_int16(lag_hist2[2], lag_hist2[3]), lag_hist2[4]);
+ *T0 = add_int16(mult_int16(tmp, ONE_PER_3), D2);
+ }
+ /* New lag is not allowed to be bigger or smaller than last lag values */
+
+ if (*T0 > maxLag)
+ {
+ *T0 = maxLag;
+ }
+
+ if (*T0 < minLag)
+ {
+ *T0 = minLag;
+ }
+ }
+ else
+ {
+ /* LTP-lag for RX_BAD_FRAME */
+
+ /***********MEAN lag**************/
+ meanLag = 0;
+ for (i = 0; i < L_LTPHIST; i++)
+ {
+ meanLag = add_int16(meanLag, lag_hist[i]);
+ }
+ meanLag = mult_int16(meanLag, ONE_PER_LTPHIST);
+
+ tmp = *T0 - maxLag;
+ tmp2 = *T0 - lastLag;
+
+ if ((lagDif < 10) && (*T0 > (minLag - 5)) && (tmp < 5))
+ {
+ *T0 = *T0;
+ }
+ else if ((lastGain > 8192) && (secLastGain > 8192) && ((tmp2 + 10) > 0 && tmp2 < 10))
+ {
+ *T0 = *T0;
+ }
+ else if ((minGain < 6554) && (lastGain == minGain) && (*T0 > minLag && *T0 < maxLag))
+ {
+ *T0 = *T0;
+ }
+ else if ((lagDif < 70) && (*T0 > minLag) && (*T0 < maxLag))
+ {
+ *T0 = *T0;
+ }
+ else if ((*T0 > meanLag) && (*T0 < maxLag))
+ {
+ *T0 = *T0;
+ }
+ else
+ {
+
+
+ if ((minGain > 8192) & (lagDif < 10))
+ {
+ *T0 = lag_hist[0];
+ }
+ else if ((lastGain > 8192) && (secLastGain > 8192))
+ {
+ *T0 = lag_hist[0];
+ }
+ else
+ {
+ /********SORT************/
+ /* The sorting of the lag history */
+ for (i = 0; i < L_LTPHIST; i++)
+ {
+ lag_hist2[i] = lag_hist[i];
+ }
+ insertion_sort(lag_hist2, 5);
+
+ /* Lag is weighted towards bigger lags */
+ /* and random variation is added */
+ lagDif = sub_int16(lag_hist2[4], lag_hist2[2]);
+
+ if (lagDif > 40)
+ {
+ lagDif = 40;
+ }
+
+ D = noise_gen_amrwb(seed); /* D={-1,.., 1} */
+ /* D2={-lagDif/2..lagDif/2} */
+ tmp = lagDif >> 1;
+ D2 = mult_int16(tmp, D);
+ tmp = add_int16(add_int16(lag_hist2[2], lag_hist2[3]), lag_hist2[4]);
+ *T0 = add_int16(mult_int16(tmp, ONE_PER_3), D2);
+ }
+ /* New lag is not allowed to be bigger or smaller than last lag values */
+
+ if (*T0 > maxLag)
+ {
+ *T0 = maxLag;
+ }
+
+ if (*T0 < minLag)
+ {
+ *T0 = minLag;
+ }
+ }
+ }
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void insertion_sort(int16 array[], int16 n)
+{
+ int16 i;
+
+ for (i = 0; i < n; i++)
+ {
+ insert(array, i, array[i]);
+ }
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void insert(int16 array[], int16 n, int16 x)
+{
+ int16 i;
+
+ for (i = (n - 1); i >= 0; i--)
+ {
+
+ if (x < array[i])
+ {
+ array[i + 1] = array[i];
+ }
+ else
+ {
+ break;
+ }
+ }
+ array[i + 1] = x;
+}
diff --git a/media/codecs/amrwb/dec/src/low_pass_filt_7k.cpp b/media/codecs/amrwb/dec/src/low_pass_filt_7k.cpp
new file mode 100644
index 0000000..ec1d6e0
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/low_pass_filt_7k.cpp
@@ -0,0 +1,220 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: low_pass_filt_7k.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 signal[], input signal / output is divided by 16
+ int16 lg, lenght of signal
+ int16 mem[] in/out: memory (size=30)
+ int16 x[] scratch mem ( size= 60)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ 15th order high pass 7kHz FIR filter
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define L_FIR 30
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int16 fir_7k[L_FIR+1] =
+{
+ -21, 47, -89, 146, -203,
+ 229, -177, 0, 335, -839,
+ 1485, -2211, 2931, -3542, 3953,
+ 28682, 3953, -3542, 2931, -2211,
+ 1485, -839, 335, 0, -177,
+ 229, -203, 146, -89, 47,
+ -21
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void low_pass_filt_7k_init(int16 mem[]) /* mem[30] */
+{
+ pv_memset((void *)mem, 0, (L_FIR)*sizeof(*mem));
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void low_pass_filt_7k(
+ int16 signal[], /* input: signal */
+ int16 lg, /* input: length of input */
+ int16 mem[], /* in/out: memory (size=30) */
+ int16 x[]
+)
+{
+ int16 i, j;
+ int32 L_tmp1;
+ int32 L_tmp2;
+ int32 L_tmp3;
+ int32 L_tmp4;
+
+ pv_memcpy((void *)x, (void *)mem, (L_FIR)*sizeof(*x));
+
+ for (i = 0; i < lg >> 2; i++)
+ {
+ x[(i<<2) + L_FIR ] = signal[(i<<2)];
+ x[(i<<2) + L_FIR + 1] = signal[(i<<2)+1];
+ x[(i<<2) + L_FIR + 2] = signal[(i<<2)+2];
+ x[(i<<2) + L_FIR + 3] = signal[(i<<2)+3];
+
+ L_tmp1 = fxp_mac_16by16(x[(i<<2)] + signal[(i<<2)], fir_7k[0], 0x00004000);
+ L_tmp2 = fxp_mac_16by16(x[(i<<2)+1] + signal[(i<<2)+1], fir_7k[0], 0x00004000);
+ L_tmp3 = fxp_mac_16by16(x[(i<<2)+2] + signal[(i<<2)+2], fir_7k[0], 0x00004000);
+ L_tmp4 = fxp_mac_16by16(x[(i<<2)+3] + signal[(i<<2)+3], fir_7k[0], 0x00004000);
+
+ for (j = 1; j < L_FIR - 1; j += 4)
+ {
+
+
+ int16 tmp1 = x[(i<<2)+j ];
+ int16 tmp2 = x[(i<<2)+j+1];
+ int16 tmp3 = x[(i<<2)+j+2];
+
+ L_tmp1 = fxp_mac_16by16(tmp1, fir_7k[j ], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(tmp2, fir_7k[j ], L_tmp2);
+ L_tmp1 = fxp_mac_16by16(tmp2, fir_7k[j+1], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(tmp3, fir_7k[j+1], L_tmp2);
+ L_tmp3 = fxp_mac_16by16(tmp3, fir_7k[j ], L_tmp3);
+ L_tmp1 = fxp_mac_16by16(tmp3, fir_7k[j+2], L_tmp1);
+
+ tmp1 = x[(i<<2)+j+3];
+ tmp2 = x[(i<<2)+j+4];
+
+ L_tmp2 = fxp_mac_16by16(tmp1, fir_7k[j+2], L_tmp2);
+ L_tmp4 = fxp_mac_16by16(tmp1, fir_7k[j ], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(tmp1, fir_7k[j+1], L_tmp3);
+ L_tmp1 = fxp_mac_16by16(tmp1, fir_7k[j+3], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(tmp2, fir_7k[j+3], L_tmp2);
+ L_tmp4 = fxp_mac_16by16(tmp2, fir_7k[j+1], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(tmp2, fir_7k[j+2], L_tmp3);
+
+ tmp1 = x[(i<<2)+j+5];
+ tmp2 = x[(i<<2)+j+6];
+
+ L_tmp4 = fxp_mac_16by16(tmp1, fir_7k[j+2], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(tmp1, fir_7k[j+3], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(tmp2, fir_7k[j+3], L_tmp4);
+
+ }
+
+ L_tmp1 = fxp_mac_16by16(x[(i<<2)+j ], fir_7k[j ], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(x[(i<<2)+j+1], fir_7k[j ], L_tmp2);
+ L_tmp3 = fxp_mac_16by16(x[(i<<2)+j+2], fir_7k[j ], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(x[(i<<2)+j+3], fir_7k[j ], L_tmp4);
+
+ signal[(i<<2)] = (int16)(L_tmp1 >> 15);
+ signal[(i<<2)+1] = (int16)(L_tmp2 >> 15);
+ signal[(i<<2)+2] = (int16)(L_tmp3 >> 15);
+ signal[(i<<2)+3] = (int16)(L_tmp4 >> 15);
+
+ }
+
+ pv_memcpy((void *)mem, (void *)(x + lg), (L_FIR)*sizeof(*mem));
+
+ return;
+}
+
diff --git a/media/codecs/amrwb/dec/src/median5.cpp b/media/codecs/amrwb/dec/src/median5.cpp
new file mode 100644
index 0000000..b922de5
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/median5.cpp
@@ -0,0 +1,180 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: median5.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ INPUT
+ X[-2:2] 16-bit integers.
+
+ RETURN VALUE
+ The median of {X[-2], X[-1],..., X[2]}.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns the median of the set {X[-2], X[-1],..., X[2]},
+ whose elements are 16-bit integers.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "pvamrwb_math_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int16 median5(int16 x[])
+{
+ int16 x1, x2, x3, x4, x5;
+ int16 tmp;
+
+ x1 = x[-2];
+ x2 = x[-1];
+ x3 = x[0];
+ x4 = x[1];
+ x5 = x[2];
+
+
+
+ if (x2 < x1)
+ {
+ tmp = x1;
+ x1 = x2;
+ x2 = tmp;
+ }
+ if (x3 < x1)
+ {
+ tmp = x1;
+ x1 = x3;
+ x3 = tmp;
+ }
+ if (x4 < x1)
+ {
+ tmp = x1;
+ x1 = x4;
+ x4 = tmp;
+ }
+ if (x5 < x1)
+ {
+ x5 = x1;
+ }
+ if (x3 < x2)
+ {
+ tmp = x2;
+ x2 = x3;
+ x3 = tmp;
+ }
+ if (x4 < x2)
+ {
+ tmp = x2;
+ x2 = x4;
+ x4 = tmp;
+ }
+ if (x5 < x2)
+ {
+ x5 = x2;
+ }
+ if (x4 < x3)
+ {
+ x3 = x4;
+ }
+ if (x5 < x3)
+ {
+ x3 = x5;
+ }
+ return (x3);
+}
+
+
diff --git a/media/codecs/amrwb/dec/src/mime_io.cpp b/media/codecs/amrwb/dec/src/mime_io.cpp
new file mode 100644
index 0000000..e1966c6
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/mime_io.cpp
@@ -0,0 +1,729 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+ Pathname: ./src/mime_io.cpp
+
+ Date: 05/07/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ [input_variable_name] = [description of the input to module, its type
+ definition, and length (when applicable)]
+
+ Local Stores/Buffers/Pointers Needed:
+ [local_store_name] = [description of the local store, its type
+ definition, and length (when applicable)]
+ [local_buffer_name] = [description of the local buffer, its type
+ definition, and length (when applicable)]
+ [local_ptr_name] = [description of the local pointer, its type
+ definition, and length (when applicable)]
+
+ Global Stores/Buffers/Pointers Needed:
+ [global_store_name] = [description of the global store, its type
+ definition, and length (when applicable)]
+ [global_buffer_name] = [description of the global buffer, its type
+ definition, and length (when applicable)]
+ [global_ptr_name] = [description of the global pointer, its type
+ definition, and length (when applicable)]
+
+ Outputs:
+ [return_variable_name] = [description of data/pointer returned
+ by module, its type definition, and length
+ (when applicable)]
+
+ Pointers and Buffers Modified:
+ [variable_bfr_ptr] points to the [describe where the
+ variable_bfr_ptr points to, its type definition, and length
+ (when applicable)]
+ [variable_bfr] contents are [describe the new contents of
+ variable_bfr]
+
+ Local Stores Modified:
+ [local_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+ Global Stores Modified:
+ [global_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ [Describe what the module does by using the variable names
+ listed in the Input and Output Definitions Section above.]
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ [List requirements to be satisfied by this module.]
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [List all references used in designing this module.]
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ ------------------------------------------------------------------------------
+ RESOURCES USED
+
+ STACK USAGE:
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES:
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_api.h"
+#include "pvamrwbdecoder.h"
+#include "pvamrwbdecoder_mem_funcs.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "dtx.h"
+#include "mime_io.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define MRSID 9
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+const uint8 toc_byte[16] = {0x04, 0x0C, 0x14, 0x1C, 0x24, 0x2C, 0x34, 0x3C,
+ 0x44, 0x4C, 0x54, 0x5C, 0x64, 0x6C, 0x74, 0x7C
+ };
+
+/* number of speech bits for all modes */
+const int16 unpacked_size[16] =
+{
+ 132, 177, 253, 285,
+ 317, 365, 397, 461,
+ 477, 35, 0, 0,
+ 0, 0, 0, 0
+};
+
+/* size of packed frame for each mode, excluding TOC byte */
+const int16 packed_size[16] = {17, 23, 32, 36, 40, 46, 50, 58,
+ 60, 5, 0, 0, 0, 0, 0, 0
+ };
+
+/* number of unused speech bits in packed format for each mode */
+const int16 unused_size[16] = {4, 7, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0};
+
+/* sorting tables for all modes */
+
+const int16 sort_660[132] =
+{
+ 0, 5, 6, 7, 61, 84, 107, 130, 62, 85,
+ 8, 4, 37, 38, 39, 40, 58, 81, 104, 127,
+ 60, 83, 106, 129, 108, 131, 128, 41, 42, 80,
+ 126, 1, 3, 57, 103, 82, 105, 59, 2, 63,
+ 109, 110, 86, 19, 22, 23, 64, 87, 18, 20,
+ 21, 17, 13, 88, 43, 89, 65, 111, 14, 24,
+ 25, 26, 27, 28, 15, 16, 44, 90, 66, 112,
+ 9, 11, 10, 12, 67, 113, 29, 30, 31, 32,
+ 34, 33, 35, 36, 45, 51, 68, 74, 91, 97,
+ 114, 120, 46, 69, 92, 115, 52, 75, 98, 121,
+ 47, 70, 93, 116, 53, 76, 99, 122, 48, 71,
+ 94, 117, 54, 77, 100, 123, 49, 72, 95, 118,
+ 55, 78, 101, 124, 50, 73, 96, 119, 56, 79,
+ 102, 125
+};
+
+const int16 sort_885[177] =
+{
+ 0, 4, 6, 7, 5, 3, 47, 48, 49, 112,
+ 113, 114, 75, 106, 140, 171, 80, 111, 145, 176,
+ 77, 108, 142, 173, 78, 109, 143, 174, 79, 110,
+ 144, 175, 76, 107, 141, 172, 50, 115, 51, 2,
+ 1, 81, 116, 146, 19, 21, 12, 17, 18, 20,
+ 16, 25, 13, 10, 14, 24, 23, 22, 26, 8,
+ 15, 52, 117, 31, 82, 147, 9, 33, 11, 83,
+ 148, 53, 118, 28, 27, 84, 149, 34, 35, 29,
+ 46, 32, 30, 54, 119, 37, 36, 39, 38, 40,
+ 85, 150, 41, 42, 43, 44, 45, 55, 60, 65,
+ 70, 86, 91, 96, 101, 120, 125, 130, 135, 151,
+ 156, 161, 166, 56, 87, 121, 152, 61, 92, 126,
+ 157, 66, 97, 131, 162, 71, 102, 136, 167, 57,
+ 88, 122, 153, 62, 93, 127, 158, 67, 98, 132,
+ 163, 72, 103, 137, 168, 58, 89, 123, 154, 63,
+ 94, 128, 159, 68, 99, 133, 164, 73, 104, 138,
+ 169, 59, 90, 124, 155, 64, 95, 129, 160, 69,
+ 100, 134, 165, 74, 105, 139, 170
+};
+
+const int16 sort_1265[253] =
+{
+ 0, 4, 6, 93, 143, 196, 246, 7, 5, 3,
+ 47, 48, 49, 50, 51, 150, 151, 152, 153, 154,
+ 94, 144, 197, 247, 99, 149, 202, 252, 96, 146,
+ 199, 249, 97, 147, 200, 250, 100, 203, 98, 148,
+ 201, 251, 95, 145, 198, 248, 52, 2, 1, 101,
+ 204, 155, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 156, 31, 102, 205, 9, 33, 11, 103, 206, 54,
+ 157, 28, 27, 104, 207, 34, 35, 29, 46, 32,
+ 30, 55, 158, 37, 36, 39, 38, 40, 105, 208,
+ 41, 42, 43, 44, 45, 56, 106, 159, 209, 57,
+ 66, 75, 84, 107, 116, 125, 134, 160, 169, 178,
+ 187, 210, 219, 228, 237, 58, 108, 161, 211, 62,
+ 112, 165, 215, 67, 117, 170, 220, 71, 121, 174,
+ 224, 76, 126, 179, 229, 80, 130, 183, 233, 85,
+ 135, 188, 238, 89, 139, 192, 242, 59, 109, 162,
+ 212, 63, 113, 166, 216, 68, 118, 171, 221, 72,
+ 122, 175, 225, 77, 127, 180, 230, 81, 131, 184,
+ 234, 86, 136, 189, 239, 90, 140, 193, 243, 60,
+ 110, 163, 213, 64, 114, 167, 217, 69, 119, 172,
+ 222, 73, 123, 176, 226, 78, 128, 181, 231, 82,
+ 132, 185, 235, 87, 137, 190, 240, 91, 141, 194,
+ 244, 61, 111, 164, 214, 65, 115, 168, 218, 70,
+ 120, 173, 223, 74, 124, 177, 227, 79, 129, 182,
+ 232, 83, 133, 186, 236, 88, 138, 191, 241, 92,
+ 142, 195, 245
+};
+
+const int16 sort_1425[285] =
+{
+ 0, 4, 6, 101, 159, 220, 278, 7, 5, 3,
+ 47, 48, 49, 50, 51, 166, 167, 168, 169, 170,
+ 102, 160, 221, 279, 107, 165, 226, 284, 104, 162,
+ 223, 281, 105, 163, 224, 282, 108, 227, 106, 164,
+ 225, 283, 103, 161, 222, 280, 52, 2, 1, 109,
+ 228, 171, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 172, 31, 110, 229, 9, 33, 11, 111, 230, 54,
+ 173, 28, 27, 112, 231, 34, 35, 29, 46, 32,
+ 30, 55, 174, 37, 36, 39, 38, 40, 113, 232,
+ 41, 42, 43, 44, 45, 56, 114, 175, 233, 62,
+ 120, 181, 239, 75, 133, 194, 252, 57, 115, 176,
+ 234, 63, 121, 182, 240, 70, 128, 189, 247, 76,
+ 134, 195, 253, 83, 141, 202, 260, 92, 150, 211,
+ 269, 84, 142, 203, 261, 93, 151, 212, 270, 85,
+ 143, 204, 262, 94, 152, 213, 271, 86, 144, 205,
+ 263, 95, 153, 214, 272, 64, 122, 183, 241, 77,
+ 135, 196, 254, 65, 123, 184, 242, 78, 136, 197,
+ 255, 87, 145, 206, 264, 96, 154, 215, 273, 58,
+ 116, 177, 235, 66, 124, 185, 243, 71, 129, 190,
+ 248, 79, 137, 198, 256, 88, 146, 207, 265, 97,
+ 155, 216, 274, 59, 117, 178, 236, 67, 125, 186,
+ 244, 72, 130, 191, 249, 80, 138, 199, 257, 89,
+ 147, 208, 266, 98, 156, 217, 275, 60, 118, 179,
+ 237, 68, 126, 187, 245, 73, 131, 192, 250, 81,
+ 139, 200, 258, 90, 148, 209, 267, 99, 157, 218,
+ 276, 61, 119, 180, 238, 69, 127, 188, 246, 74,
+ 132, 193, 251, 82, 140, 201, 259, 91, 149, 210,
+ 268, 100, 158, 219, 277
+};
+
+const int16 sort_1585[317] =
+{
+ 0, 4, 6, 109, 175, 244, 310, 7, 5, 3,
+ 47, 48, 49, 50, 51, 182, 183, 184, 185, 186,
+ 110, 176, 245, 311, 115, 181, 250, 316, 112, 178,
+ 247, 313, 113, 179, 248, 314, 116, 251, 114, 180,
+ 249, 315, 111, 177, 246, 312, 52, 2, 1, 117,
+ 252, 187, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 188, 31, 118, 253, 9, 33, 11, 119, 254, 54,
+ 189, 28, 27, 120, 255, 34, 35, 29, 46, 32,
+ 30, 55, 190, 37, 36, 39, 38, 40, 121, 256,
+ 41, 42, 43, 44, 45, 56, 122, 191, 257, 63,
+ 129, 198, 264, 76, 142, 211, 277, 89, 155, 224,
+ 290, 102, 168, 237, 303, 57, 123, 192, 258, 70,
+ 136, 205, 271, 83, 149, 218, 284, 96, 162, 231,
+ 297, 62, 128, 197, 263, 75, 141, 210, 276, 88,
+ 154, 223, 289, 101, 167, 236, 302, 58, 124, 193,
+ 259, 71, 137, 206, 272, 84, 150, 219, 285, 97,
+ 163, 232, 298, 59, 125, 194, 260, 64, 130, 199,
+ 265, 67, 133, 202, 268, 72, 138, 207, 273, 77,
+ 143, 212, 278, 80, 146, 215, 281, 85, 151, 220,
+ 286, 90, 156, 225, 291, 93, 159, 228, 294, 98,
+ 164, 233, 299, 103, 169, 238, 304, 106, 172, 241,
+ 307, 60, 126, 195, 261, 65, 131, 200, 266, 68,
+ 134, 203, 269, 73, 139, 208, 274, 78, 144, 213,
+ 279, 81, 147, 216, 282, 86, 152, 221, 287, 91,
+ 157, 226, 292, 94, 160, 229, 295, 99, 165, 234,
+ 300, 104, 170, 239, 305, 107, 173, 242, 308, 61,
+ 127, 196, 262, 66, 132, 201, 267, 69, 135, 204,
+ 270, 74, 140, 209, 275, 79, 145, 214, 280, 82,
+ 148, 217, 283, 87, 153, 222, 288, 92, 158, 227,
+ 293, 95, 161, 230, 296, 100, 166, 235, 301, 105,
+ 171, 240, 306, 108, 174, 243, 309
+};
+
+const int16 sort_1825[365] =
+{
+ 0, 4, 6, 121, 199, 280, 358, 7, 5, 3,
+ 47, 48, 49, 50, 51, 206, 207, 208, 209, 210,
+ 122, 200, 281, 359, 127, 205, 286, 364, 124, 202,
+ 283, 361, 125, 203, 284, 362, 128, 287, 126, 204,
+ 285, 363, 123, 201, 282, 360, 52, 2, 1, 129,
+ 288, 211, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 212, 31, 130, 289, 9, 33, 11, 131, 290, 54,
+ 213, 28, 27, 132, 291, 34, 35, 29, 46, 32,
+ 30, 55, 214, 37, 36, 39, 38, 40, 133, 292,
+ 41, 42, 43, 44, 45, 56, 134, 215, 293, 198,
+ 299, 136, 120, 138, 60, 279, 58, 62, 357, 139,
+ 140, 295, 156, 57, 219, 297, 63, 217, 137, 170,
+ 300, 222, 64, 106, 61, 78, 294, 92, 142, 141,
+ 135, 221, 296, 301, 343, 59, 298, 184, 329, 315,
+ 220, 216, 265, 251, 218, 237, 352, 223, 157, 86,
+ 171, 87, 164, 351, 111, 302, 65, 178, 115, 323,
+ 72, 192, 101, 179, 93, 73, 193, 151, 337, 309,
+ 143, 274, 69, 324, 165, 150, 97, 338, 110, 310,
+ 330, 273, 68, 107, 175, 245, 114, 79, 113, 189,
+ 246, 259, 174, 71, 185, 96, 344, 100, 322, 83,
+ 334, 316, 333, 252, 161, 348, 147, 82, 269, 232,
+ 260, 308, 353, 347, 163, 231, 306, 320, 188, 270,
+ 146, 177, 266, 350, 256, 85, 149, 116, 191, 160,
+ 238, 258, 336, 305, 255, 88, 224, 99, 339, 230,
+ 228, 227, 272, 242, 241, 319, 233, 311, 102, 74,
+ 180, 275, 66, 194, 152, 325, 172, 247, 244, 261,
+ 117, 158, 166, 354, 75, 144, 108, 312, 94, 186,
+ 303, 80, 234, 89, 195, 112, 340, 181, 345, 317,
+ 326, 276, 239, 167, 118, 313, 70, 355, 327, 253,
+ 190, 176, 271, 104, 98, 153, 103, 90, 76, 267,
+ 277, 248, 225, 262, 182, 84, 154, 235, 335, 168,
+ 331, 196, 341, 249, 162, 307, 148, 349, 263, 321,
+ 257, 243, 229, 356, 159, 119, 67, 187, 173, 145,
+ 240, 77, 304, 332, 314, 342, 109, 254, 81, 278,
+ 105, 91, 346, 318, 183, 250, 197, 328, 95, 155,
+ 169, 268, 226, 236, 264
+};
+
+const int16 sort_1985[397] =
+{
+ 0, 4, 6, 129, 215, 304, 390, 7, 5, 3,
+ 47, 48, 49, 50, 51, 222, 223, 224, 225, 226,
+ 130, 216, 305, 391, 135, 221, 310, 396, 132, 218,
+ 307, 393, 133, 219, 308, 394, 136, 311, 134, 220,
+ 309, 395, 131, 217, 306, 392, 52, 2, 1, 137,
+ 312, 227, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 228, 31, 138, 313, 9, 33, 11, 139, 314, 54,
+ 229, 28, 27, 140, 315, 34, 35, 29, 46, 32,
+ 30, 55, 230, 37, 36, 39, 38, 40, 141, 316,
+ 41, 42, 43, 44, 45, 56, 142, 231, 317, 63,
+ 73, 92, 340, 82, 324, 149, 353, 159, 334, 165,
+ 338, 178, 163, 254, 77, 168, 257, 153, 343, 57,
+ 248, 238, 79, 252, 166, 67, 80, 201, 101, 267,
+ 143, 164, 341, 255, 339, 187, 376, 318, 78, 328,
+ 362, 115, 232, 242, 253, 290, 276, 62, 58, 158,
+ 68, 93, 179, 319, 148, 169, 154, 72, 385, 329,
+ 333, 344, 102, 83, 144, 233, 323, 124, 243, 192,
+ 354, 237, 64, 247, 202, 209, 150, 116, 335, 268,
+ 239, 299, 188, 196, 298, 94, 195, 258, 123, 363,
+ 384, 109, 325, 371, 170, 370, 84, 110, 295, 180,
+ 74, 210, 191, 106, 291, 205, 367, 381, 377, 206,
+ 355, 122, 119, 120, 383, 160, 105, 108, 277, 380,
+ 294, 284, 285, 345, 208, 269, 249, 366, 386, 300,
+ 297, 259, 125, 369, 197, 97, 194, 286, 211, 281,
+ 280, 183, 372, 87, 155, 283, 59, 348, 327, 184,
+ 76, 111, 330, 203, 349, 69, 98, 152, 145, 189,
+ 66, 320, 337, 173, 358, 251, 198, 174, 263, 262,
+ 126, 241, 193, 88, 388, 117, 95, 387, 112, 359,
+ 287, 244, 103, 272, 301, 171, 162, 234, 273, 127,
+ 373, 181, 292, 85, 378, 302, 121, 107, 364, 346,
+ 356, 212, 278, 213, 65, 382, 288, 207, 113, 175,
+ 99, 296, 374, 368, 199, 260, 185, 336, 331, 161,
+ 270, 264, 250, 240, 75, 350, 151, 60, 89, 321,
+ 156, 274, 360, 326, 70, 282, 167, 146, 352, 81,
+ 91, 389, 266, 245, 177, 235, 190, 256, 204, 342,
+ 128, 118, 303, 104, 379, 182, 114, 375, 200, 96,
+ 293, 172, 214, 365, 279, 86, 289, 351, 347, 357,
+ 261, 186, 176, 271, 90, 100, 147, 322, 275, 361,
+ 71, 332, 61, 265, 157, 246, 236
+};
+
+const int16 sort_2305[461] =
+{
+ 0, 4, 6, 145, 247, 352, 454, 7, 5, 3,
+ 47, 48, 49, 50, 51, 254, 255, 256, 257, 258,
+ 146, 248, 353, 455, 151, 253, 358, 460, 148, 250,
+ 355, 457, 149, 251, 356, 458, 152, 359, 150, 252,
+ 357, 459, 147, 249, 354, 456, 52, 2, 1, 153,
+ 360, 259, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 260, 31, 154, 361, 9, 33, 11, 155, 362, 54,
+ 261, 28, 27, 156, 363, 34, 35, 29, 46, 32,
+ 30, 55, 262, 37, 36, 39, 38, 40, 157, 364,
+ 41, 42, 43, 44, 45, 56, 158, 263, 365, 181,
+ 192, 170, 79, 57, 399, 90, 159, 297, 377, 366,
+ 275, 68, 183, 388, 286, 194, 299, 92 , 70, 182,
+ 401, 172, 59, 91, 58, 400, 368, 161, 81, 160,
+ 264, 171, 80, 389, 390, 378, 379, 193, 298, 69,
+ 266, 265, 367, 277, 288, 276, 287, 184, 60, 195,
+ 82, 93, 71, 369, 402, 173, 162, 444, 300, 391,
+ 98, 76, 278, 61, 267, 374, 135, 411, 167, 102,
+ 380, 200, 87, 178, 65, 94, 204, 124, 72, 342,
+ 189, 305, 381, 396, 433, 301, 226, 407, 289, 237,
+ 113, 215, 185, 128, 309, 403, 116, 320, 196, 331,
+ 370, 422, 174, 64, 392, 83, 425, 219, 134, 188,
+ 432, 112, 427, 139, 279, 163, 436, 208, 447, 218,
+ 236, 229, 97, 294, 385, 230, 166, 268, 177, 443,
+ 225, 426, 101, 272, 138, 127, 290, 117, 347, 199,
+ 414, 95, 140, 240, 410, 395, 209, 129, 283, 346,
+ 105, 241, 437, 86, 308, 448, 203, 345, 186, 107,
+ 220, 415, 334, 319, 106, 313, 118, 123, 73, 207,
+ 421, 214, 384, 373, 438, 62, 371, 341, 75, 449,
+ 168, 323, 164, 242, 416, 324, 304, 197, 335, 404,
+ 271, 63, 191, 325, 96, 169, 231, 280, 312, 187,
+ 406, 84, 201, 100, 67, 382, 175, 336, 202, 330,
+ 269, 393, 376, 383, 293, 307, 409, 179, 285, 314,
+ 302, 372, 398, 190, 180, 89, 99, 103, 232, 78,
+ 88, 77, 136, 387, 165, 198, 394, 125, 176, 428,
+ 74, 375, 238, 227, 66, 273, 282, 141, 306, 412,
+ 114, 85, 130, 348, 119, 291, 296, 386, 233, 397,
+ 303, 405, 284, 445, 423, 221, 210, 205, 450, 108,
+ 274, 434, 216, 343, 337, 142, 243, 321, 408, 451,
+ 310, 292, 120, 109, 281, 439, 270, 429, 332, 295,
+ 418, 211, 315, 222, 326, 131, 430, 244, 327, 349,
+ 417, 316, 143, 338, 440, 234, 110, 212, 452, 245,
+ 121, 419, 350, 223, 132, 441, 328, 413, 317, 339,
+ 126, 104, 137, 446, 344, 239, 435, 115, 333, 206,
+ 322, 217, 228, 424, 453, 311, 351, 111, 442, 224,
+ 213, 122, 431, 340, 235, 246, 133, 144, 420, 329,
+ 318
+};
+
+const int16 sort_2385[477] =
+{
+ 0, 4, 6, 145, 251, 360, 466, 7, 5, 3,
+ 47, 48, 49, 50, 51, 262, 263, 264, 265, 266,
+ 146, 252, 361, 467, 151, 257, 366, 472, 148, 254,
+ 363, 469, 149, 255, 364, 470, 156, 371, 150, 256,
+ 365, 471, 147, 253, 362, 468, 52, 2, 1, 157,
+ 372, 267, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 268, 31, 152, 153, 154, 155, 258, 259, 260, 261,
+ 367, 368, 369, 370, 473, 474, 475, 476, 158, 373,
+ 9, 33, 11, 159, 374, 54, 269, 28, 27, 160,
+ 375, 34, 35, 29, 46, 32, 30, 55, 270, 37,
+ 36, 39, 38, 40, 161, 376, 41, 42, 43, 44,
+ 45, 56, 162, 271, 377, 185, 196, 174, 79, 57,
+ 411, 90, 163, 305, 389, 378, 283, 68, 187, 400,
+ 294, 198, 307, 92, 70, 186, 413, 176, 59, 91,
+ 58, 412, 380, 165, 81, 164, 272, 175, 80, 401,
+ 402, 390, 391, 197, 306, 69, 274, 273, 379, 285,
+ 296, 284, 295, 188, 60, 199, 82, 93, 71, 381,
+ 414, 177, 166, 456, 308, 403, 98, 76, 286, 61,
+ 275, 386, 135, 423, 171, 102, 392, 204, 87, 182,
+ 65, 94, 208, 124, 72, 350, 193, 313, 393, 408,
+ 445, 309, 230, 419, 297, 241, 113, 219, 189, 128,
+ 317, 415, 116, 328, 200, 339, 382, 434, 178, 64,
+ 404, 83, 437, 223, 134, 192, 444, 112, 439, 139,
+ 287, 167, 448, 212, 459, 222, 240, 233, 97, 302,
+ 397, 234, 170, 276, 181, 455, 229, 438, 101, 280,
+ 138, 127, 298, 117, 355, 203, 426, 95, 140, 244,
+ 422, 407, 213, 129, 291, 354, 105, 245, 449, 86,
+ 316, 460, 207, 353, 190, 107, 224, 427, 342, 327,
+ 106, 321, 118, 123, 73, 211, 433, 218, 396, 385,
+ 450, 62, 383, 349, 75, 461, 172, 331, 168, 246,
+ 428, 332, 312, 201, 343, 416, 279, 63, 195, 333,
+ 96, 173, 235, 288, 320, 191, 418, 84, 205, 100,
+ 67, 394, 179, 344, 206, 338, 277, 405, 388, 395,
+ 301, 315, 421, 183, 293, 322, 310, 384, 410, 194,
+ 184, 89, 99, 103, 236, 78, 88, 77, 136, 399,
+ 169, 202, 406, 125, 180, 440, 74, 387, 242, 231,
+ 66, 281, 290, 141, 314, 424, 114, 85, 130, 356,
+ 119, 299, 304, 398, 237, 409, 311, 417, 292, 457,
+ 435, 225, 214, 209, 462, 108, 282, 446, 220, 351,
+ 345, 142, 247, 329, 420, 463, 318, 300, 120, 109,
+ 289, 451, 278, 441, 340, 303, 430, 215, 323, 226,
+ 334, 131, 442, 248, 335, 357, 429, 324, 143, 346,
+ 452, 238, 110, 216, 464, 249, 121, 431, 358, 227,
+ 132, 453, 336, 425, 325, 347, 126, 104, 137, 458,
+ 352, 243, 447, 115, 341, 210, 330, 221, 232, 436,
+ 465, 319, 359, 111, 454, 228, 217, 122, 443, 348,
+ 239, 250, 133, 144, 432, 337, 326
+};
+
+const int16 sort_SID[35] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34
+};
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void mime_unsorting(uint8 unsorted_bits[],
+ int16 sorted_bits_into_int16[],
+ int16 * frame_type,
+ int16 * mode,
+ uint8 quality,
+ RX_State_wb *st)
+{
+
+ int16 i;
+ int16 j;
+ uint8 temp = 0;
+ uint8 *unsorted_bits_ptr = (uint8*)unsorted_bits;
+
+ /* pointer table for bit sorting tables */
+ const int16 *AmrWbSortingTables[16] =
+ {
+ sort_660, sort_885, sort_1265, sort_1425,
+ sort_1585, sort_1825, sort_1985, sort_2305,
+ sort_2385, sort_SID, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ };
+
+ const int16 * pt_AmrWbSortingTables = AmrWbSortingTables[*mode];
+
+ /* clear compressed speech bit buffer */
+ pv_memset(sorted_bits_into_int16,
+ 0,
+ unpacked_size[*mode]*sizeof(*sorted_bits_into_int16));
+
+ /* unpack and unsort speech or SID bits */
+
+
+ for (i = unpacked_size[*mode] >> 3; i != 0; i--)
+ {
+ temp = *(unsorted_bits_ptr++);
+
+ for (j = 2; j != 0; j--)
+ {
+ switch (temp & 0xf0)
+ {
+ case 0xf0:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ case 0xe0:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ break;
+ case 0xd0:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ case 0xc0:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables += 2;
+ break;
+ case 0xb0:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ case 0xa0:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ break;
+ case 0x90:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables += 2;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ case 0x80:
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables += 3;
+ break;
+ case 0x70:
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ case 0x60:
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ break;
+ case 0x50:
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ case 0x40:
+ pt_AmrWbSortingTables++;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables += 2;
+ break;
+ case 0x30:
+ pt_AmrWbSortingTables += 2;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ case 0x20:
+ pt_AmrWbSortingTables += 2;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ pt_AmrWbSortingTables++;
+ break;
+ case 0x10:
+ pt_AmrWbSortingTables += 3;
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ break;
+ default:
+ pt_AmrWbSortingTables += 4;
+ break;
+ }
+ temp <<= 4;
+ }
+ }
+
+ if (unpacked_size[*mode] % 4)
+ {
+ temp <<= 1;
+
+ if (temp & 0x80)
+ {
+ sorted_bits_into_int16[*(pt_AmrWbSortingTables++)] = BIT_1;
+ }
+ }
+
+ /* set frame type */
+ switch (*mode)
+ {
+ case MODE_7k:
+ case MODE_9k:
+ case MODE_12k:
+ case MODE_14k:
+ case MODE_16k:
+ case MODE_18k:
+ case MODE_20k:
+ case MODE_23k:
+ case MODE_24k:
+ if (quality)
+ {
+ *frame_type = RX_SPEECH_GOOD;
+ }
+ else
+ {
+ *frame_type = RX_SPEECH_BAD;
+ }
+ break;
+
+ case MRSID:
+ if (quality)
+ {
+ if (temp & 0x80)
+ {
+ *frame_type = RX_SID_UPDATE;
+ }
+ else
+ {
+ *frame_type = RX_SID_FIRST;
+ }
+ }
+ else
+ {
+ *frame_type = RX_SID_BAD;
+ }
+
+ /* set mode index */
+ *mode = st->prev_mode;
+ break;
+ case 14: /* SPEECH_LOST */
+ *frame_type = RX_SPEECH_LOST;
+ *mode = st->prev_mode;
+ break;
+ case 15: /* NO_DATA */
+ *frame_type = RX_NO_DATA;
+ *mode = st->prev_mode;
+ break;
+ default: /* replace frame with unused mode index by NO_DATA frame */
+ *frame_type = RX_NO_DATA;
+ *mode = st->prev_mode;
+ break;
+ }
+
+ st->prev_mode = *mode;
+
+}
+
+
+
diff --git a/media/codecs/amrwb/dec/src/mime_io.h b/media/codecs/amrwb/dec/src/mime_io.h
new file mode 100644
index 0000000..3be1d9c
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/mime_io.h
@@ -0,0 +1,124 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/mime_io.h
+
+ Date: 01/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef MIME_IO_H
+#define MIME_IO_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+----------------------------------------------------------------------------*/
+
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+extern const uint8 toc_byte[16];
+
+/* number of speech bits for all modes */
+extern const int16 unpacked_size[16];
+
+/* size of packed frame for each mode, excluding TOC byte */
+extern const int16 packed_size[16];
+
+/* number of unused speech bits in packed format for each mode */
+extern const int16 unused_size[16];
+
+/* sorting tables for all modes */
+
+extern const int16 sort_660[132];
+
+extern const int16 sort_885[177];
+
+extern const int16 sort_1265[253];
+
+extern const int16 sort_1425[285];
+
+extern const int16 sort_1585[317];
+
+extern const int16 sort_1825[365];
+
+extern const int16 sort_1985[397];
+
+extern const int16 sort_2305[461];
+
+extern const int16 sort_2385[477];
+
+extern const int16 sort_SID[35];
+
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+#endif /* MIME_IO_H */
diff --git a/media/codecs/amrwb/dec/src/noise_gen_amrwb.cpp b/media/codecs/amrwb/dec/src/noise_gen_amrwb.cpp
new file mode 100644
index 0000000..2c1059f
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/noise_gen_amrwb.cpp
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: noise_gen_amrwb.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 * seed seed for the random ng
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Signed 16 bits random generator
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int16 noise_gen_amrwb(int16 * seed)
+{
+ /* int16 seed = 21845; */
+ *seed = (int16)fxp_mac_16by16(*seed, 31821, 13849L);
+
+ return (*seed);
+}
diff --git a/media/codecs/amrwb/dec/src/normalize_amr_wb.cpp b/media/codecs/amrwb/dec/src/normalize_amr_wb.cpp
new file mode 100644
index 0000000..4d1126e
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/normalize_amr_wb.cpp
@@ -0,0 +1,184 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: normalize_amr_wb.cpp
+
+ Date: 12/10/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ Int32 x 32-bit integer non-zero input
+Returns
+ Int16 i number of leading zeros on x
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns number of leading zeros on the non-zero input
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "normalize_amr_wb.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+#if defined(PV_ARM_V5)
+#elif defined(PV_ARM_GCC_V5)
+
+/* function is inlined in header file */
+
+
+#else
+
+int16 normalize_amr_wb(int32 x)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int16 i;
+
+
+ if (x > 0x0FFFFFFF)
+ {
+ i = 0; /* most likely case */
+ }
+ else if (x > 0x00FFFFFF)
+ {
+ i = 3; /* second most likely case */
+ }
+ else if (x > 0x0000FFFF)
+ {
+ i = x > 0x000FFFFF ? 7 : 11;
+ }
+ else
+ {
+ if (x > 0x000000FF)
+ {
+ i = x > 0x00000FFF ? 15 : 19;
+ }
+ else
+ {
+ i = x > 0x0000000F ? 23 : 27;
+ }
+ }
+
+
+ x <<= i;
+
+ switch (x & 0x78000000)
+ {
+ case 0x08000000:
+ i += 3;
+ break;
+
+ case 0x18000000:
+ case 0x10000000:
+ i += 2;
+ break;
+ case 0x28000000:
+ case 0x20000000:
+ case 0x38000000:
+ case 0x30000000:
+ i++;
+ break;
+
+ default:
+ ;
+ }
+
+ return i;
+
+}
+
+#endif
+
diff --git a/media/codecs/amrwb/dec/src/normalize_amr_wb.h b/media/codecs/amrwb/dec/src/normalize_amr_wb.h
new file mode 100644
index 0000000..e4c80ef
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/normalize_amr_wb.h
@@ -0,0 +1,120 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./c/include/normalize_amr_wb.h
+
+ Date: 12/10/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef NORMALIZE_AMR_WB_H
+#define NORMALIZE_AMR_WB_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES AND SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+#if defined(PV_ARM_V5)
+
+__inline int16 normalize_amr_wb(int32 x)
+{
+ int32 y;
+ __asm
+ {
+ clz y, x;
+ sub y, y, #1
+ }
+ return (y);
+}
+
+
+#elif defined(PV_ARM_GCC_V5)
+
+
+__inline int16 normalize_amr_wb(int32 x)
+{
+ register int32 y;
+ register int32 ra = x;
+
+
+ asm volatile(
+ "clz %0, %1\n\t"
+ "sub %0, %0, #1"
+ : "=&r*i"(y)
+ : "r"(ra));
+ return (y);
+
+}
+
+#else
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int16 normalize_amr_wb(int32 x);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+#endif /* PV_NORMALIZE_H */
diff --git a/media/codecs/amrwb/dec/src/oversamp_12k8_to_16k.cpp b/media/codecs/amrwb/dec/src/oversamp_12k8_to_16k.cpp
new file mode 100644
index 0000000..806851e
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/oversamp_12k8_to_16k.cpp
@@ -0,0 +1,342 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: oversamp_12k8_to_16k.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 signal[], input signal / output is divided by 16
+ int16 lg, lenght of signal
+ int16 mem[] in/out: memory (size=30)
+ int16 x[] scratch mem ( size= 60)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Oversamp_16k : oversampling from 12.8kHz to 16kHz.
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "pvamrwbdecoder_cnst.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define FAC4 4
+#define FAC5 5
+#define INV_FAC5 6554 /* 1/5 in Q15 */
+#define DOWN_FAC 26215 /* 4/5 in Q15 */
+#define UP_FAC 20480 /* 5/4 in Q14 */
+#define NB_COEF_DOWN 15
+#define NB_COEF_UP 12
+#define N_LOOP_COEF_UP 4
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ /* Local functions */
+
+ void AmrWbUp_samp(
+ int16 * sig_d, /* input: signal to oversampling */
+ int16 * sig_u, /* output: oversampled signal */
+ int16 L_frame /* input: length of output */
+ );
+
+
+ int16 AmrWbInterpol( /* return result of interpolation */
+ int16 * x, /* input vector */
+ const int16 * fir, /* filter coefficient */
+ int16 nb_coef /* number of coefficients */
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+
+/* 1/5 resolution interpolation filter (in Q14) */
+/* -1.5dB @ 6kHz, -6dB @ 6.4kHz, -10dB @ 6.6kHz,
+ -20dB @ 6.9kHz, -25dB @ 7kHz, -55dB @ 8kHz */
+
+
+const int16 fir_up[4][24] =
+{
+
+ {
+ -1, 12, -33, 68, -119, 191,
+ -291, 430, -634, 963, -1616, 3792,
+ 15317, -2496, 1288, -809, 542, -369,
+ 247, -160, 96, -52, 23, -6,
+ },
+ {
+ -4, 24, -62, 124, -213, 338,
+ -510, 752, -1111, 1708, -2974, 8219,
+ 12368, -3432, 1881, -1204, 812, -552,
+ 368, -235, 139, -73, 30, -7,
+ },
+ {
+ -7, 30, -73, 139, -235, 368,
+ -552, 812, -1204, 1881, -3432, 12368,
+ 8219, -2974, 1708, -1111, 752, -510,
+ 338, -213, 124, -62, 24, -4,
+ },
+ {
+ -6, 23, -52, 96, -160, 247,
+ -369, 542, -809, 1288, -2496, 15317,
+ 3792, -1616, 963, -634, 430, -291,
+ 191, -119, 68, -33, 12, -1,
+ }
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+/* output: memory (2*NB_COEF_UP) set to zeros */
+void oversamp_12k8_to_16k_init(int16 mem[])
+{
+ pv_memset((void *)mem, 0, (2*NB_COEF_UP)*sizeof(*mem));
+
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void oversamp_12k8_to_16k(
+ int16 sig12k8[], /* input: signal to oversampling */
+ int16 lg, /* input: length of input */
+ int16 sig16k[], /* output: oversampled signal */
+ int16 mem[], /* in/out: memory (2*NB_COEF_UP) */
+ int16 signal[]
+)
+{
+ int16 lg_up;
+
+ pv_memcpy((void *)signal,
+ (void *)mem,
+ (2*NB_COEF_UP)*sizeof(*mem));
+
+ pv_memcpy((void *)(signal + (2*NB_COEF_UP)),
+ (void *)sig12k8,
+ lg*sizeof(*sig12k8));
+
+ lg_up = lg + (lg >> 2); /* 5/4 of lg */
+
+ AmrWbUp_samp(signal + NB_COEF_UP, sig16k, lg_up);
+
+ pv_memcpy((void *)mem,
+ (void *)(signal + lg),
+ (2*NB_COEF_UP)*sizeof(*signal));
+
+ return;
+}
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void AmrWbUp_samp(
+ int16 * sig_d, /* input: signal to oversampling */
+ int16 * sig_u, /* output: oversampled signal */
+ int16 L_frame /* input: length of output */
+)
+{
+
+ int32 i;
+ int16 frac, j;
+ int16 * pt_sig_u = sig_u;
+
+ frac = 1;
+ for (j = 0; j < L_frame; j++)
+ {
+ i = ((int32)j * INV_FAC5) >> 13; /* integer part = pos * 1/5 */
+
+ frac--;
+ if (frac)
+ {
+ *(pt_sig_u++) = AmrWbInterpol(&sig_d[i],
+ fir_up[(FAC5-1) - frac],
+ N_LOOP_COEF_UP);
+ }
+ else
+ {
+ *(pt_sig_u++) = sig_d[i+12 - NB_COEF_UP ];
+ frac = FAC5;
+ }
+ }
+
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+/* Fractional interpolation of signal at position (frac/resol) */
+
+
+int16 AmrWbInterpol( /* return result of interpolation */
+ int16 * x, /* input vector */
+ const int16 *fir, /* filter coefficient */
+ int16 nb_coef /* number of coefficients */
+)
+{
+ int32 L_sum;
+ const int16 *pt_fir = fir;
+
+ int16 tmp1, tmp2, tmp3, tmp4;
+ int16 *pt_x = x - nb_coef - (nb_coef << 1) + 1;
+
+
+ tmp1 = *(pt_x++);
+ tmp2 = *(pt_x++);
+ tmp3 = *(pt_x++);
+ tmp4 = *(pt_x++);
+ L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), 0x00002000L);
+ L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
+ tmp1 = *(pt_x++);
+ tmp2 = *(pt_x++);
+ tmp3 = *(pt_x++);
+ tmp4 = *(pt_x++);
+ L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
+ tmp1 = *(pt_x++);
+ tmp2 = *(pt_x++);
+ tmp3 = *(pt_x++);
+ tmp4 = *(pt_x++);
+ L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
+ tmp1 = *(pt_x++);
+ tmp2 = *(pt_x++);
+ tmp3 = *(pt_x++);
+ tmp4 = *(pt_x++);
+ L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
+ tmp1 = *(pt_x++);
+ tmp2 = *(pt_x++);
+ tmp3 = *(pt_x++);
+ tmp4 = *(pt_x++);
+ L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
+ tmp1 = *(pt_x++);
+ tmp2 = *(pt_x++);
+ tmp3 = *(pt_x++);
+ tmp4 = *(pt_x++);
+ L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
+ L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
+
+
+ L_sum = shl_int32(L_sum, 2); /* saturation can occur here */
+
+ return ((int16)(L_sum >> 16));
+}
+
diff --git a/media/codecs/amrwb/dec/src/phase_dispersion.cpp b/media/codecs/amrwb/dec/src/phase_dispersion.cpp
new file mode 100644
index 0000000..7b08a40
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/phase_dispersion.cpp
@@ -0,0 +1,261 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: phase_dispersion.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 gain_code, (i) Q0 : gain of code
+ int16 gain_pit, (i) Q14 : gain of pitch
+ int16 code[], (i/o) : code vector
+ int16 mode, (i) : level, 0=hi, 1=lo, 2=off
+ int16 disp_mem[], (i/o) : static memory (size = 8)
+ int16 ScratchMem[]
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ post-processing to enhance noise in low bit rate.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_mem_funcs.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "pvamrwb_math_op.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define pitch_0_9 14746 /* 0.9 in Q14 */
+#define pitch_0_6 9830 /* 0.6 in Q14 */
+#define L_SUBFR 64
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+/* impulse response with phase dispersion */
+
+/* 2.0 - 6.4 kHz phase dispersion */
+static const int16 ph_imp_low[L_SUBFR] =
+{
+ 20182, 9693, 3270, -3437, 2864, -5240, 1589, -1357,
+ 600, 3893, -1497, -698, 1203, -5249, 1199, 5371,
+ -1488, -705, -2887, 1976, 898, 721, -3876, 4227,
+ -5112, 6400, -1032, -4725, 4093, -4352, 3205, 2130,
+ -1996, -1835, 2648, -1786, -406, 573, 2484, -3608,
+ 3139, -1363, -2566, 3808, -639, -2051, -541, 2376,
+ 3932, -6262, 1432, -3601, 4889, 370, 567, -1163,
+ -2854, 1914, 39, -2418, 3454, 2975, -4021, 3431
+};
+
+/* 3.2 - 6.4 kHz phase dispersion */
+static const int16 ph_imp_mid[L_SUBFR] =
+{
+ 24098, 10460, -5263, -763, 2048, -927, 1753, -3323,
+ 2212, 652, -2146, 2487, -3539, 4109, -2107, -374,
+ -626, 4270, -5485, 2235, 1858, -2769, 744, 1140,
+ -763, -1615, 4060, -4574, 2982, -1163, 731, -1098,
+ 803, 167, -714, 606, -560, 639, 43, -1766,
+ 3228, -2782, 665, 763, 233, -2002, 1291, 1871,
+ -3470, 1032, 2710, -4040, 3624, -4214, 5292, -4270,
+ 1563, 108, -580, 1642, -2458, 957, 544, 2540
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void phase_dispersion(
+ int16 gain_code, /* (i) Q0 : gain of code */
+ int16 gain_pit, /* (i) Q14 : gain of pitch */
+ int16 code[], /* (i/o) : code vector */
+ int16 mode, /* (i) : level, 0=hi, 1=lo, 2=off */
+ int16 disp_mem[], /* (i/o) : static memory (size = 8) */
+ int16 ScratchMem[]
+)
+{
+ int16 i, j, state;
+ int16 *prev_gain_pit, *prev_gain_code, *prev_state;
+ int16 *code2 = ScratchMem;
+
+ prev_state = disp_mem;
+ prev_gain_code = disp_mem + 1;
+ prev_gain_pit = disp_mem + 2;
+
+ pv_memset((void *)code2, 0, (2*L_SUBFR)*sizeof(*code2));
+
+
+ if (gain_pit < pitch_0_6)
+ {
+ state = 0;
+ }
+ else if (gain_pit < pitch_0_9)
+ {
+ state = 1;
+ }
+ else
+ {
+ state = 2;
+ }
+
+ for (i = 5; i > 0; i--)
+ {
+ prev_gain_pit[i] = prev_gain_pit[i - 1];
+ }
+ prev_gain_pit[0] = gain_pit;
+
+ if (sub_int16(gain_code, *prev_gain_code) > shl_int16(*prev_gain_code, 1))
+ {
+ /* onset */
+ if (state < 2)
+ {
+ state++;
+ }
+ }
+ else
+ {
+ j = 0;
+ for (i = 0; i < 6; i++)
+ {
+ if (prev_gain_pit[i] < pitch_0_6)
+ {
+ j++;
+ }
+ }
+
+ if (j > 2)
+ {
+ state = 0;
+ }
+ if (state > *prev_state + 1)
+ {
+ state--;
+ }
+ }
+
+ *prev_gain_code = gain_code;
+ *prev_state = state;
+
+ /* circular convolution */
+
+ state += mode; /* level of dispersion */
+
+ if (state == 0)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ if (code[i] != 0)
+ {
+ for (j = 0; j < L_SUBFR; j++)
+ {
+ code2[i + j] = add_int16(code2[i + j], mult_int16_r(code[i], ph_imp_low[j]));
+ }
+ }
+ }
+ }
+ else if (state == 1)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ if (code[i] != 0)
+ {
+ for (j = 0; j < L_SUBFR; j++)
+ {
+ code2[i + j] = add_int16(code2[i + j], mult_int16_r(code[i], ph_imp_mid[j]));
+ }
+ }
+ }
+ }
+ if (state < 2)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ code[i] = add_int16(code2[i], code2[i + L_SUBFR]);
+ }
+ }
+ return;
+}
+
diff --git a/media/codecs/amrwb/dec/src/pit_shrp.cpp b/media/codecs/amrwb/dec/src/pit_shrp.cpp
new file mode 100644
index 0000000..4bfcf9c
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pit_shrp.cpp
@@ -0,0 +1,132 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: pit_shrp.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 * x, in/out: impulse response (or algebraic code)
+ int16 pit_lag, input : pitch lag
+ int16 sharp, input : pitch sharpening factor (Q15)
+ int16 L_subfr input : subframe size
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Performs Pitch sharpening routine
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Pit_shrp(
+ int16 * x, /* in/out: impulse response (or algebraic code) */
+ int16 pit_lag, /* input : pitch lag */
+ int16 sharp, /* input : pitch sharpening factor (Q15) */
+ int16 L_subfr /* input : subframe size */
+)
+{
+ int16 i;
+ int32 L_tmp;
+
+ for (i = pit_lag; i < L_subfr; i++)
+ {
+ L_tmp = mac_16by16_to_int32((int32)x[i] << 16, x[i - pit_lag], sharp);
+ x[i] = amr_wb_round(L_tmp);
+
+ }
+
+ return;
+}
diff --git a/media/codecs/amrwb/dec/src/pred_lt4.cpp b/media/codecs/amrwb/dec/src/pred_lt4.cpp
new file mode 100644
index 0000000..d5a7984
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pred_lt4.cpp
@@ -0,0 +1,267 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: pred_lt4.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 signal[], input signal / output is divided by 16
+ int16 lg, lenght of signal
+ int16 mem[] in/out: memory (size=30)
+ int16 x[] scratch mem ( size= 60)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Compute the result of long term prediction with fractionnal
+ interpolation of resolution 1/4.
+
+ On return exc[0..L_subfr-1] contains the interpolated signal
+ (adaptive codebook excitation)
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define UP_SAMP 4
+#define L_INTERPOL2 16
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) in Q14 */
+
+
+const int16 inter4_2[UP_SAMP][ 2*L_INTERPOL2] =
+{
+ {
+ 0, -2, 4, -2, -10, 38,
+ -88, 165, -275, 424, -619, 871,
+ -1207, 1699, -2598, 5531, 14031, -2147,
+ 780, -249, -16, 153, -213, 226,
+ -209, 175, -133, 91, -55, 28,
+ -10, 2
+ },
+ {
+ 1, -7, 19, -33, 47, -52,
+ 43, -9, -60, 175, -355, 626,
+ -1044, 1749, -3267, 10359, 10359, -3267,
+ 1749, -1044, 626, -355, 175, -60,
+ -9, 43, -52, 47, -33, 19,
+ -7, 1
+ },
+ {
+ 2, -10, 28, -55, 91, -133,
+ 175, -209, 226, -213, 153, -16,
+ -249, 780, -2147, 14031, 5531, -2598,
+ 1699, -1207, 871, -619, 424, -275,
+ 165, -88, 38, -10, -2, 4,
+ -2, 0
+ },
+ {
+ 1, -7, 22, -49, 92, -153,
+ 231, -325, 431, -544, 656, -762,
+ 853, -923, 968, 15401, 968, -923,
+ 853, -762, 656, -544, 431, -325,
+ 231, -153, 92, -49, 22, -7,
+ 1, 0
+ }
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Pred_lt4(
+ int16 exc[], /* in/out: excitation buffer */
+ int16 T0, /* input : integer pitch lag */
+ int16 frac, /* input : fraction of lag */
+ int16 L_subfr /* input : subframe size */
+)
+{
+ int16 i, j, *pt_exc;
+ int32 L_sum1;
+ int32 L_sum2;
+ int32 L_sum3;
+ int32 L_sum4;
+ pt_exc = &exc[-T0];
+
+ const int16 *pt_inter4_2;
+
+ frac = -frac;
+
+ if (frac < 0)
+ {
+ frac += UP_SAMP;
+ pt_exc--;
+
+ }
+ pt_exc -= (L_INTERPOL2 - 1);
+
+ pt_inter4_2 = inter4_2[UP_SAMP-1 - frac];
+
+ for (j = 0; j < (L_subfr >> 2); j++)
+ {
+
+ L_sum1 = 0x00002000; /* pre-roundig */
+ L_sum2 = 0x00002000;
+ L_sum3 = 0x00002000;
+ L_sum4 = 0x00002000;
+
+ for (i = 0; i < L_INTERPOL2 << 1; i += 4)
+ {
+ int16 tmp1 = pt_exc[i ];
+ int16 tmp2 = pt_exc[i+1];
+ int16 tmp3 = pt_exc[i+2];
+
+
+ L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i ], L_sum1);
+ L_sum2 = fxp_mac_16by16(tmp2, pt_inter4_2[i ], L_sum2);
+ L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum1);
+ L_sum2 = fxp_mac_16by16(tmp3, pt_inter4_2[i+1], L_sum2);
+ L_sum3 = fxp_mac_16by16(tmp3, pt_inter4_2[i ], L_sum3);
+ L_sum1 = fxp_mac_16by16(tmp3, pt_inter4_2[i+2], L_sum1);
+
+ tmp1 = pt_exc[i+3];
+ tmp2 = pt_exc[i+4];
+
+ L_sum4 = fxp_mac_16by16(tmp1, pt_inter4_2[i ], L_sum4);
+ L_sum3 = fxp_mac_16by16(tmp1, pt_inter4_2[i+1], L_sum3);
+ L_sum2 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum2);
+ L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i+3], L_sum1);
+ L_sum4 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum4);
+ L_sum2 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum2);
+ L_sum3 = fxp_mac_16by16(tmp2, pt_inter4_2[i+2], L_sum3);
+
+ tmp1 = pt_exc[i+5];
+ tmp2 = pt_exc[i+6];
+
+ L_sum4 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum4);
+ L_sum3 = fxp_mac_16by16(tmp1, pt_inter4_2[i+3], L_sum3);
+ L_sum4 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum4);
+
+ }
+
+
+
+ exc[(j<<2)] = (int16)(L_sum1 >> 14);
+ exc[(j<<2)+1] = (int16)(L_sum2 >> 14);
+ exc[(j<<2)+2] = (int16)(L_sum3 >> 14);
+ exc[(j<<2)+3] = (int16)(L_sum4 >> 14);
+
+ pt_exc += 4;
+
+ }
+
+ if (L_subfr&1)
+ {
+ L_sum1 = 0x00002000;
+
+ for (i = 0; i < 2*L_INTERPOL2; i += 4)
+ {
+ int16 tmp1 = pt_exc[i ];
+ int16 tmp2 = pt_exc[i+1];
+ L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i ], L_sum1);
+ L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum1);
+ tmp1 = pt_exc[i+2];
+ tmp2 = pt_exc[i+3];
+ L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum1);
+ L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum1);
+
+ }
+
+ exc[(j<<2)] = (int16)((L_sum1) >> 14);
+
+ }
+
+
+ return;
+}
+
diff --git a/media/codecs/amrwb/dec/src/preemph_amrwb_dec.cpp b/media/codecs/amrwb/dec/src/preemph_amrwb_dec.cpp
new file mode 100644
index 0000000..3eb5cda
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/preemph_amrwb_dec.cpp
@@ -0,0 +1,130 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: preemph_amrwb_dec.cpp
+
+ Date: 12/10/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 x[], (i/o) : input signal overwritten by the output
+ int16 mu, (i) Q15 : preemphasis coefficient
+ int16 lg (i) : lenght of filtering
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Preemphasis: filtering through 1 - g z^-1
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void preemph_amrwb_dec(
+ int16 x[], /* (i/o) : input signal overwritten by the output */
+ int16 mu, /* (i) Q15 : preemphasis coefficient */
+ int16 lg /* (i) : lenght of filtering */
+)
+{
+ int16 i;
+ int32 L_tmp;
+
+ for (i = lg - 1; i != 0; i--)
+ {
+ L_tmp = msu_16by16_from_int32((int32)x[i] << 16, x[i - 1], mu);
+ x[i] = amr_wb_round(L_tmp);
+ }
+
+}
+
diff --git a/media/codecs/amrwb/dec/src/pv_amr_wb_type_defs.h b/media/codecs/amrwb/dec/src/pv_amr_wb_type_defs.h
new file mode 100644
index 0000000..1ebcb86
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pv_amr_wb_type_defs.h
@@ -0,0 +1,173 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/pv_amr_wb_type_defs.h
+
+ Date: 12/12/2006
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file was derived from a number of standards bodies. The type
+ definitions below were created from some of the best practices observed
+ in the standards bodies.
+
+ This file is dependent on limits.h for defining the bit widths. In an
+ ANSI C environment limits.h is expected to always be present and contain
+ the following definitions:
+
+ SCHAR_MIN
+ SCHAR_MAX
+ UCHAR_MAX
+
+ INT_MAX
+ INT_MIN
+ UINT_MAX
+
+ SHRT_MIN
+ SHRT_MAX
+ USHRT_MAX
+
+ LONG_MIN
+ LONG_MAX
+ ULONG_MAX
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PV_AMR_WB_TYPE_DEFS_H
+#define PV_AMR_WB_TYPE_DEFS_H
+
+#include <stdint.h>
+
+typedef int8_t Word8;
+typedef uint8_t UWord8;
+
+/*----------------------------------------------------------------------------
+; Define generic signed and unsigned int
+----------------------------------------------------------------------------*/
+typedef signed int Int;
+
+typedef unsigned int UInt;
+
+/*----------------------------------------------------------------------------
+; Define 16 bit signed and unsigned words
+----------------------------------------------------------------------------*/
+
+#ifndef INT16_MIN
+#define INT16_MIN (-32768)
+#endif
+
+#ifndef INT16_MAX
+#define INT16_MAX 32767
+#endif
+
+/*----------------------------------------------------------------------------
+; Define 32 bit signed and unsigned words
+----------------------------------------------------------------------------*/
+
+
+
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647 - 1)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX 2147483647
+#endif
+
+
+#ifndef UINT32_MIN
+#define UINT32_MIN 0
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX 0xffffffff
+#endif
+
+
+/*----------------------------------------------------------------------------
+; Define 64 bit signed and unsigned words
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Define boolean type
+----------------------------------------------------------------------------*/
+
+#ifndef Flag
+typedef Int Flag;
+#endif
+
+#ifndef Bool
+typedef Int Bool;
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef OFF
+#define OFF 0
+#endif
+#ifndef ON
+#define ON 1
+#endif
+
+#ifndef NO
+#define NO 0
+#endif
+#ifndef YES
+#define YES 1
+#endif
+
+#ifndef SUCCESS
+#define SUCCESS 0
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+typedef int16_t int16;
+typedef int32_t int32;
+typedef int64_t int64;
+typedef uint8_t uint8;
+
+#endif /* PV_AMR_WB_TYPE_DEFS_H */
diff --git a/media/codecs/amrwb/dec/src/pvamrwb_math_op.cpp b/media/codecs/amrwb/dec/src/pvamrwb_math_op.cpp
new file mode 100644
index 0000000..5872512
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwb_math_op.cpp
@@ -0,0 +1,627 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*___________________________________________________________________________
+
+ This file contains mathematic operations in fixed point.
+
+ mult_int16_r() : Same as mult_int16 with rounding
+ shr_rnd() : Same as shr(var1,var2) but with rounding
+ div_16by16() : fractional integer division
+ one_ov_sqrt() : Compute 1/sqrt(L_x)
+ one_ov_sqrt_norm() : Compute 1/sqrt(x)
+ power_of_2() : power of 2
+ Dot_product12() : Compute scalar product of <x[],y[]> using accumulator
+ Isqrt() : inverse square root (16 bits precision).
+ amrwb_log_2() : log2 (16 bits precision).
+
+ These operations are not standard double precision operations.
+ They are used where low complexity is important and the full 32 bits
+ precision is not necessary. For example, the function Div_32() has a
+ 24 bits precision which is enough for our purposes.
+
+ In this file, the values use theses representations:
+
+ int32 L_32 : standard signed 32 bits format
+ int16 hi, lo : L_32 = hi<<16 + lo<<1 (DPF - Double Precision Format)
+ int32 frac, int16 exp : L_32 = frac << exp-31 (normalised format)
+ int16 int, frac : L_32 = int.frac (fractional format)
+ ----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+
+
+/*----------------------------------------------------------------------------
+
+ Function Name : mult_int16_r
+
+ Purpose :
+
+ Same as mult_int16 with rounding, i.e.:
+ mult_int16_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and
+ mult_int16_r(-32768,-32768) = 32767.
+
+ Complexity weight : 2
+
+ Inputs :
+
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ Outputs :
+
+ none
+
+ Return Value :
+
+ var_out
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+ ----------------------------------------------------------------------------*/
+
+int16 mult_int16_r(int16 var1, int16 var2)
+{
+ int32 L_product_arr;
+
+ L_product_arr = (int32) var1 * (int32) var2; /* product */
+ L_product_arr += (int32) 0x00004000L; /* round */
+ L_product_arr >>= 15; /* shift */
+ if ((L_product_arr >> 15) != (L_product_arr >> 31))
+ {
+ L_product_arr = (L_product_arr >> 31) ^ MAX_16;
+ }
+
+ return ((int16)L_product_arr);
+}
+
+
+
+/*----------------------------------------------------------------------------
+
+ Function Name : shr_rnd
+
+ Purpose :
+
+ Same as shr(var1,var2) but with rounding. Saturate the result in case of|
+ underflows or overflows :
+ - If var2 is greater than zero :
+ if (sub(shl_int16(shr(var1,var2),1),shr(var1,sub(var2,1))))
+ is equal to zero
+ then
+ shr_rnd(var1,var2) = shr(var1,var2)
+ else
+ shr_rnd(var1,var2) = add_int16(shr(var1,var2),1)
+ - If var2 is less than or equal to zero :
+ shr_rnd(var1,var2) = shr(var1,var2).
+
+ Complexity weight : 2
+
+ Inputs :
+
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x0000 0000 <= var2 <= 0x0000 7fff.
+
+ Outputs :
+
+ none
+
+ Return Value :
+
+ var_out
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+ ----------------------------------------------------------------------------*/
+
+int16 shr_rnd(int16 var1, int16 var2)
+{
+ int16 var_out;
+
+ var_out = (int16)(var1 >> (var2 & 0xf));
+ if (var2)
+ {
+ if ((var1 & ((int16) 1 << (var2 - 1))) != 0)
+ {
+ var_out++;
+ }
+ }
+ return (var_out);
+}
+
+
+/*----------------------------------------------------------------------------
+
+ Function Name : div_16by16
+
+ Purpose :
+
+ Produces a result which is the fractional integer division of var1 by
+ var2; var1 and var2 must be positive and var2 must be greater or equal
+ to var1; the result is positive (leading bit equal to 0) and truncated
+ to 16 bits.
+ If var1 = var2 then div(var1,var2) = 32767.
+
+ Complexity weight : 18
+
+ Inputs :
+
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x0000 0000 <= var1 <= var2 and var2 != 0.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : var1 <= var2 <= 0x0000 7fff and var2 != 0.
+
+ Outputs :
+
+ none
+
+ Return Value :
+
+ var_out
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x0000 0000 <= var_out <= 0x0000 7fff.
+ It's a Q15 value (point between b15 and b14).
+ ----------------------------------------------------------------------------*/
+
+int16 div_16by16(int16 var1, int16 var2)
+{
+
+ int16 var_out = 0;
+ int16 iteration;
+ int32 L_num;
+ int32 L_denom;
+ int32 L_denom_by_2;
+ int32 L_denom_by_4;
+
+ if ((var1 > var2) || (var1 < 0))
+ {
+ return 0; // used to exit(0);
+ }
+ if (var1)
+ {
+ if (var1 != var2)
+ {
+
+ L_num = (int32) var1;
+ L_denom = (int32) var2;
+ L_denom_by_2 = (L_denom << 1);
+ L_denom_by_4 = (L_denom << 2);
+ for (iteration = 5; iteration > 0; iteration--)
+ {
+ var_out <<= 3;
+ L_num <<= 3;
+
+ if (L_num >= L_denom_by_4)
+ {
+ L_num -= L_denom_by_4;
+ var_out |= 4;
+ }
+
+ if (L_num >= L_denom_by_2)
+ {
+ L_num -= L_denom_by_2;
+ var_out |= 2;
+ }
+
+ if (L_num >= (L_denom))
+ {
+ L_num -= (L_denom);
+ var_out |= 1;
+ }
+
+ }
+ }
+ else
+ {
+ var_out = MAX_16;
+ }
+ }
+
+ return (var_out);
+
+}
+
+
+
+/*----------------------------------------------------------------------------
+
+ Function Name : one_ov_sqrt
+
+ Compute 1/sqrt(L_x).
+ if L_x is negative or zero, result is 1 (7fffffff).
+
+ Algorithm:
+
+ 1- Normalization of L_x.
+ 2- call Isqrt_n(L_x, exponant)
+ 3- L_y = L_x << exponant
+ ----------------------------------------------------------------------------*/
+int32 one_ov_sqrt( /* (o) Q31 : output value (range: 0<=val<1) */
+ int32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */
+)
+{
+ int16 exp;
+ int32 L_y;
+
+ exp = normalize_amr_wb(L_x);
+ L_x <<= exp; /* L_x is normalized */
+ exp = 31 - exp;
+
+ one_ov_sqrt_norm(&L_x, &exp);
+
+ L_y = shl_int32(L_x, exp); /* denormalization */
+
+ return (L_y);
+}
+
+/*----------------------------------------------------------------------------
+
+ Function Name : one_ov_sqrt_norm
+
+ Compute 1/sqrt(value).
+ if value is negative or zero, result is 1 (frac=7fffffff, exp=0).
+
+ Algorithm:
+
+ The function 1/sqrt(value) is approximated by a table and linear
+ interpolation.
+
+ 1- If exponant is odd then shift fraction right once.
+ 2- exponant = -((exponant-1)>>1)
+ 3- i = bit25-b30 of fraction, 16 <= i <= 63 ->because of normalization.
+ 4- a = bit10-b24
+ 5- i -=16
+ 6- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ ----------------------------------------------------------------------------*/
+static const int16 table_isqrt[49] =
+{
+ 32767, 31790, 30894, 30070, 29309, 28602, 27945, 27330, 26755, 26214,
+ 25705, 25225, 24770, 24339, 23930, 23541, 23170, 22817, 22479, 22155,
+ 21845, 21548, 21263, 20988, 20724, 20470, 20225, 19988, 19760, 19539,
+ 19326, 19119, 18919, 18725, 18536, 18354, 18176, 18004, 17837, 17674,
+ 17515, 17361, 17211, 17064, 16921, 16782, 16646, 16514, 16384
+};
+
+void one_ov_sqrt_norm(
+ int32 * frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */
+ int16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */
+)
+{
+ int16 i, a, tmp;
+
+
+ if (*frac <= (int32) 0)
+ {
+ *exp = 0;
+ *frac = 0x7fffffffL;
+ return;
+ }
+
+ if ((*exp & 1) == 1) /* If exponant odd -> shift right */
+ *frac >>= 1;
+
+ *exp = negate_int16((*exp - 1) >> 1);
+
+ *frac >>= 9;
+ i = extract_h(*frac); /* Extract b25-b31 */
+ *frac >>= 1;
+ a = (int16)(*frac); /* Extract b10-b24 */
+ a = (int16)(a & (int16) 0x7fff);
+
+ i -= 16;
+
+ *frac = L_deposit_h(table_isqrt[i]); /* table[i] << 16 */
+ tmp = table_isqrt[i] - table_isqrt[i + 1]; /* table[i] - table[i+1]) */
+
+ *frac = msu_16by16_from_int32(*frac, tmp, a); /* frac -= tmp*a*2 */
+
+ return;
+}
+
+/*----------------------------------------------------------------------------
+
+ Function Name : power_2()
+
+ L_x = pow(2.0, exponant.fraction) (exponant = interger part)
+ = pow(2.0, 0.fraction) << exponant
+
+ Algorithm:
+
+ The function power_2(L_x) is approximated by a table and linear
+ interpolation.
+
+ 1- i = bit10-b15 of fraction, 0 <= i <= 31
+ 2- a = bit0-b9 of fraction
+ 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ 4- L_x = L_x >> (30-exponant) (with rounding)
+ ----------------------------------------------------------------------------*/
+const int16 table_pow2[33] =
+{
+ 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911,
+ 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726,
+ 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706,
+ 31379, 32066, 32767
+};
+
+int32 power_of_2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */
+ int16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */
+ int16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */
+)
+{
+ int16 exp, i, a, tmp;
+ int32 L_x;
+
+ L_x = fraction << 5; /* L_x = fraction<<6 */
+ i = (fraction >> 10); /* Extract b10-b16 of fraction */
+ a = (int16)(L_x); /* Extract b0-b9 of fraction */
+ a = (int16)(a & (int16) 0x7fff);
+
+ L_x = ((int32)table_pow2[i]) << 15; /* table[i] << 16 */
+ tmp = table_pow2[i] - table_pow2[i + 1]; /* table[i] - table[i+1] */
+ L_x -= ((int32)tmp * a); /* L_x -= tmp*a*2 */
+
+ exp = 29 - exponant ;
+
+ if (exp)
+ {
+ L_x = ((L_x >> exp) + ((L_x >> (exp - 1)) & 1));
+ }
+
+ return (L_x);
+}
+
+/*----------------------------------------------------------------------------
+ *
+ * Function Name : Dot_product12()
+ *
+ * Compute scalar product of <x[],y[]> using accumulator.
+ *
+ * The result is normalized (in Q31) with exponent (0..30).
+ *
+ * Algorithm:
+ *
+ * dot_product = sum(x[i]*y[i]) i=0..N-1
+ ----------------------------------------------------------------------------*/
+
+int32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */
+ int16 x[], /* (i) 12bits: x vector */
+ int16 y[], /* (i) 12bits: y vector */
+ int16 lg, /* (i) : vector length */
+ int16 * exp /* (o) : exponent of result (0..+30) */
+)
+{
+ int16 i, sft;
+ int32 L_sum;
+ int16 *pt_x = x;
+ int16 *pt_y = y;
+
+ L_sum = 1L;
+
+
+ for (i = lg >> 3; i != 0; i--)
+ {
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ L_sum = mac_16by16_to_int32(L_sum, *(pt_x++), *(pt_y++));
+ }
+
+ /* Normalize acc in Q31 */
+
+ sft = normalize_amr_wb(L_sum);
+ L_sum <<= sft;
+
+ *exp = 30 - sft; /* exponent = 0..30 */
+
+ return (L_sum);
+}
+
+/* Table for Log2() */
+const int16 Log2_norm_table[33] =
+{
+ 0, 1455, 2866, 4236, 5568, 6863, 8124, 9352, 10549, 11716,
+ 12855, 13967, 15054, 16117, 17156, 18172, 19167, 20142, 21097, 22033,
+ 22951, 23852, 24735, 25603, 26455, 27291, 28113, 28922, 29716, 30497,
+ 31266, 32023, 32767
+};
+
+/*----------------------------------------------------------------------------
+ *
+ * FUNCTION: Lg2_normalized()
+ *
+ * PURPOSE: Computes log2(L_x, exp), where L_x is positive and
+ * normalized, and exp is the normalisation exponent
+ * If L_x is negative or zero, the result is 0.
+ *
+ * DESCRIPTION:
+ * The function Log2(L_x) is approximated by a table and linear
+ * interpolation. The following steps are used to compute Log2(L_x)
+ *
+ * 1- exponent = 30-norm_exponent
+ * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization).
+ * 3- a = bit10-b24
+ * 4- i -=32
+ * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ *
+----------------------------------------------------------------------------*/
+void Lg2_normalized(
+ int32 L_x, /* (i) : input value (normalized) */
+ int16 exp, /* (i) : norm_l (L_x) */
+ int16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ int16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+)
+{
+ int16 i, a, tmp;
+ int32 L_y;
+
+ if (L_x <= (int32) 0)
+ {
+ *exponent = 0;
+ *fraction = 0;;
+ return;
+ }
+
+ *exponent = 30 - exp;
+
+ L_x >>= 9;
+ i = extract_h(L_x); /* Extract b25-b31 */
+ L_x >>= 1;
+ a = (int16)(L_x); /* Extract b10-b24 of fraction */
+ a &= 0x7fff;
+
+ i -= 32;
+
+ L_y = L_deposit_h(Log2_norm_table[i]); /* table[i] << 16 */
+ tmp = Log2_norm_table[i] - Log2_norm_table[i + 1]; /* table[i] - table[i+1] */
+ L_y = msu_16by16_from_int32(L_y, tmp, a); /* L_y -= tmp*a*2 */
+
+ *fraction = extract_h(L_y);
+
+ return;
+}
+
+
+
+/*----------------------------------------------------------------------------
+ *
+ * FUNCTION: amrwb_log_2()
+ *
+ * PURPOSE: Computes log2(L_x), where L_x is positive.
+ * If L_x is negative or zero, the result is 0.
+ *
+ * DESCRIPTION:
+ * normalizes L_x and then calls Lg2_normalized().
+ *
+ ----------------------------------------------------------------------------*/
+void amrwb_log_2(
+ int32 L_x, /* (i) : input value */
+ int16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ int16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+)
+{
+ int16 exp;
+
+ exp = normalize_amr_wb(L_x);
+ Lg2_normalized(shl_int32(L_x, exp), exp, exponent, fraction);
+}
+
+
+/*****************************************************************************
+ *
+ * These operations are not standard double precision operations. *
+ * They are used where single precision is not enough but the full 32 bits *
+ * precision is not necessary. For example, the function Div_32() has a *
+ * 24 bits precision which is enough for our purposes. *
+ * *
+ * The double precision numbers use a special representation: *
+ * *
+ * L_32 = hi<<16 + lo<<1 *
+ * *
+ * L_32 is a 32 bit integer. *
+ * hi and lo are 16 bit signed integers. *
+ * As the low part also contains the sign, this allows fast multiplication. *
+ * *
+ * 0x8000 0000 <= L_32 <= 0x7fff fffe. *
+ * *
+ * We will use DPF (Double Precision Format )in this file to specify *
+ * this special format. *
+ *****************************************************************************
+*/
+
+
+/*----------------------------------------------------------------------------
+ *
+ * Function int32_to_dpf()
+ *
+ * Extract from a 32 bit integer two 16 bit DPF.
+ *
+ * Arguments:
+ *
+ * L_32 : 32 bit integer.
+ * 0x8000 0000 <= L_32 <= 0x7fff ffff.
+ * hi : b16 to b31 of L_32
+ * lo : (L_32 - hi<<16)>>1
+ *
+ ----------------------------------------------------------------------------*/
+
+void int32_to_dpf(int32 L_32, int16 *hi, int16 *lo)
+{
+ *hi = (int16)(L_32 >> 16);
+ *lo = (int16)((L_32 - (*hi << 16)) >> 1);
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+ * Function mpy_dpf_32()
+ *
+ * Multiply two 32 bit integers (DPF). The result is divided by 2**31
+ *
+ * L_32 = (hi1*hi2)<<1 + ( (hi1*lo2)>>15 + (lo1*hi2)>>15 )<<1
+ *
+ * This operation can also be viewed as the multiplication of two Q31
+ * number and the result is also in Q31.
+ *
+ * Arguments:
+ *
+ * hi1 hi part of first number
+ * lo1 lo part of first number
+ * hi2 hi part of second number
+ * lo2 lo part of second number
+ *
+ ----------------------------------------------------------------------------*/
+
+int32 mpy_dpf_32(int16 hi1, int16 lo1, int16 hi2, int16 lo2)
+{
+ int32 L_32;
+
+ L_32 = mul_16by16_to_int32(hi1, hi2);
+ L_32 = mac_16by16_to_int32(L_32, mult_int16(hi1, lo2), 1);
+ L_32 = mac_16by16_to_int32(L_32, mult_int16(lo1, hi2), 1);
+
+ return (L_32);
+}
+
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwb_math_op.h b/media/codecs/amrwb/dec/src/pvamrwb_math_op.h
new file mode 100644
index 0000000..2143c9a
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwb_math_op.h
@@ -0,0 +1,132 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./src/pvamrwb_math_op.h
+
+ Date: 01/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PVAMRWB_MATH_OP_H
+#define PVAMRWB_MATH_OP_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; DEFINES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ int32 one_ov_sqrt( /* (o) Q31 : output value (range: 0<=val<1) */
+ int32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */
+ );
+ void one_ov_sqrt_norm(
+ int32 * frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */
+ int16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */
+ );
+ int32 power_of_2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */
+ int16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */
+ int16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */
+ );
+ int32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */
+ int16 x[], /* (i) 12bits: x vector */
+ int16 y[], /* (i) 12bits: y vector */
+ int16 lg, /* (i) : vector length */
+ int16 * exp /* (o) : exponent of result (0..+30) */
+ );
+
+
+ void amrwb_log_2(
+ int32 L_x, /* (i) : input value */
+ int16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ int16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1)*/
+ );
+
+ void Lg2_normalized(
+ int32 L_x, /* (i) : input value (normalized) */
+ int16 exp, /* (i) : norm_l (L_x) */
+ int16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ int16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ );
+
+
+ int16 mult_int16_r(int16 var1, int16 var2); /* Mult with round, 2 */
+ int16 shr_rnd(int16 var1, int16 var2); /* Shift right with round, 2 */
+
+ int16 div_16by16(int16 var1, int16 var2); /* Short division, 18 */
+
+
+ void int32_to_dpf(int32 L_32, int16 *hi, int16 *lo);
+ int32 mpy_dpf_32(int16 hi1, int16 lo1, int16 hi2, int16 lo2);
+
+
+#define norm_s( x) (normalize_amr_wb( x) - 16)
+
+
+#define extract_h( x) (int16)((x)>>16)
+#define L_deposit_h( x) (int32)((x)<<16)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* PVAMRWB_MATH_OP_H */
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder.cpp b/media/codecs/amrwb/dec/src/pvamrwbdecoder.cpp
new file mode 100644
index 0000000..c9c1cd4
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder.cpp
@@ -0,0 +1,1152 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: pvamrwbdecoder.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 mode, input : used mode
+ int16 prms[], input : parameter vector
+ int16 synth16k[], output: synthesis speech
+ int16 * frame_length, output: lenght of the frame
+ void *spd_state, i/o : State structure
+ int16 frame_type, input : received frame type
+ int16 ScratchMem[]
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Performs the main decoder routine AMR WB ACELP coding algorithm with 20 ms
+ speech frames for wideband speech signals.
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_mem_funcs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "e_pv_amrwbdec.h"
+#include "get_amr_wb_bits.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_api.h"
+#include "pvamrwbdecoder.h"
+#include "synthesis_amr_wb.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* LPC interpolation coef {0.45, 0.8, 0.96, 1.0}; in Q15 */
+static const int16 interpol_frac[NB_SUBFR] = {14746, 26214, 31457, 32767};
+
+
+/* isp tables for initialization */
+
+static const int16 isp_init[M] =
+{
+ 32138, 30274, 27246, 23170, 18205, 12540, 6393, 0,
+ -6393, -12540, -18205, -23170, -27246, -30274, -32138, 1475
+};
+
+static const int16 isf_init[M] =
+{
+ 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192,
+ 9216, 10240, 11264, 12288, 13312, 14336, 15360, 3840
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ FUNCTION DESCRIPTION pvDecoder_AmrWb_Init
+
+ Initialization of variables for the decoder section.
+
+----------------------------------------------------------------------------*/
+
+
+
+
+void pvDecoder_AmrWb_Init(void **spd_state, void *pt_st, int16 **ScratchMem)
+{
+ /* Decoder states */
+ Decoder_State *st = &(((PV_AmrWbDec *)pt_st)->state);
+
+ *ScratchMem = ((PV_AmrWbDec *)pt_st)->ScratchMem;
+ /*
+ * Init dtx decoding
+ */
+ dtx_dec_amr_wb_reset(&(st->dtx_decSt), isf_init);
+
+ pvDecoder_AmrWb_Reset((void *) st, 1);
+
+ *spd_state = (void *) st;
+
+ return;
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvDecoder_AmrWb_Reset(void *st, int16 reset_all)
+{
+ int16 i;
+
+ Decoder_State *dec_state;
+
+ dec_state = (Decoder_State *) st;
+
+ pv_memset((void *)dec_state->old_exc,
+ 0,
+ (PIT_MAX + L_INTERPOL)*sizeof(*dec_state->old_exc));
+
+ pv_memset((void *)dec_state->past_isfq,
+ 0,
+ M*sizeof(*dec_state->past_isfq));
+
+
+ dec_state->old_T0_frac = 0; /* old pitch value = 64.0 */
+ dec_state->old_T0 = 64;
+ dec_state->first_frame = 1;
+ dec_state->L_gc_thres = 0;
+ dec_state->tilt_code = 0;
+
+ pv_memset((void *)dec_state->disp_mem,
+ 0,
+ 8*sizeof(*dec_state->disp_mem));
+
+
+ /* scaling memories for excitation */
+ dec_state->Q_old = Q_MAX;
+ dec_state->Qsubfr[3] = Q_MAX;
+ dec_state->Qsubfr[2] = Q_MAX;
+ dec_state->Qsubfr[1] = Q_MAX;
+ dec_state->Qsubfr[0] = Q_MAX;
+
+ if (reset_all != 0)
+ {
+ /* routines initialization */
+
+ dec_gain2_amr_wb_init(dec_state->dec_gain);
+ oversamp_12k8_to_16k_init(dec_state->mem_oversamp);
+ band_pass_6k_7k_init(dec_state->mem_hf);
+ low_pass_filt_7k_init(dec_state->mem_hf3);
+ highpass_50Hz_at_12k8_init(dec_state->mem_sig_out);
+ highpass_400Hz_at_12k8_init(dec_state->mem_hp400);
+ Init_Lagconc(dec_state->lag_hist);
+
+ /* isp initialization */
+
+ pv_memcpy((void *)dec_state->ispold, (void *)isp_init, M*sizeof(*isp_init));
+
+ pv_memcpy((void *)dec_state->isfold, (void *)isf_init, M*sizeof(*isf_init));
+ for (i = 0; i < L_MEANBUF; i++)
+ {
+ pv_memcpy((void *)&dec_state->isf_buf[i * M],
+ (void *)isf_init,
+ M*sizeof(*isf_init));
+ }
+ /* variable initialization */
+
+ dec_state->mem_deemph = 0;
+
+ dec_state->seed = 21845; /* init random with 21845 */
+ dec_state->seed2 = 21845;
+ dec_state->seed3 = 21845;
+
+ dec_state->state = 0;
+ dec_state->prev_bfi = 0;
+
+ /* Static vectors to zero */
+
+ pv_memset((void *)dec_state->mem_syn_hf,
+ 0,
+ M16k*sizeof(*dec_state->mem_syn_hf));
+
+ pv_memset((void *)dec_state->mem_syn_hi,
+ 0,
+ M*sizeof(*dec_state->mem_syn_hi));
+
+ pv_memset((void *)dec_state->mem_syn_lo,
+ 0,
+ M*sizeof(*dec_state->mem_syn_lo));
+
+
+ dtx_dec_amr_wb_reset(&(dec_state->dtx_decSt), isf_init);
+ dec_state->vad_hist = 0;
+
+ }
+ return;
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int32 pvDecoder_AmrWbMemRequirements()
+{
+ return(sizeof(PV_AmrWbDec));
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/* Main decoder routine. */
+
+int32 pvDecoder_AmrWb(
+ int16 mode, /* input : used mode */
+ int16 prms[], /* input : parameter vector */
+ int16 synth16k[], /* output: synthesis speech */
+ int16 * frame_length, /* output: lenght of the frame */
+ void *spd_state, /* i/o : State structure */
+ int16 frame_type, /* input : received frame type */
+ int16 ScratchMem[]
+)
+{
+
+ /* Decoder states */
+ Decoder_State *st;
+
+ int16 *ScratchMem2 = &ScratchMem[ L_SUBFR + L_SUBFR16k + ((L_SUBFR + M + M16k +1)<<1)];
+
+
+ /* Excitation vector */
+
+
+ int16 *old_exc = ScratchMem2;
+
+ int16 *Aq = &old_exc[(L_FRAME + 1) + PIT_MAX + L_INTERPOL];/* A(z) quantized for the 4 subframes */
+
+ int16 *ispnew = &Aq[NB_SUBFR * (M + 1)];/* immittance spectral pairs at 4nd sfr */
+ int16 *isf = &ispnew[M]; /* ISF (frequency domain) at 4nd sfr */
+ int16 *isf_tmp = &isf[M];
+ int16 *code = &isf_tmp[M]; /* algebraic codevector */
+ int16 *excp = &code[L_SUBFR];
+ int16 *exc2 = &excp[L_SUBFR]; /* excitation vector */
+ int16 *HfIsf = &exc2[L_FRAME];
+
+
+ int16 *exc;
+
+ /* LPC coefficients */
+
+ int16 *p_Aq; /* ptr to A(z) for the 4 subframes */
+
+
+
+ int16 fac, stab_fac, voice_fac, Q_new = 0;
+ int32 L_tmp, L_gain_code;
+
+ /* Scalars */
+
+ int16 i, j, i_subfr, index, ind[8], tmp;
+ int32 max;
+ int16 T0, T0_frac, pit_flag, T0_max, select, T0_min = 0;
+ int16 gain_pit, gain_code;
+ int16 newDTXState, bfi, unusable_frame, nb_bits;
+ int16 vad_flag;
+ int16 pit_sharp;
+
+ int16 corr_gain = 0;
+
+ st = (Decoder_State *) spd_state;
+
+ /* mode verification */
+ if (mode < 0 || mode >= NUM_OF_MODES)
+ {
+ return (-1);
+ }
+ nb_bits = AMR_WB_COMPRESSED[mode];
+
+ *frame_length = AMR_WB_PCM_FRAME;
+
+ /* find the new DTX state SPEECH OR DTX */
+ newDTXState = rx_amr_wb_dtx_handler(&(st->dtx_decSt), frame_type);
+
+
+ if (newDTXState != SPEECH)
+ {
+ dtx_dec_amr_wb(&(st->dtx_decSt), exc2, newDTXState, isf, &prms);
+ }
+ /* SPEECH action state machine */
+
+ if ((frame_type == RX_SPEECH_BAD) ||
+ (frame_type == RX_SPEECH_PROBABLY_DEGRADED))
+ {
+ /* bfi for all index, bits are not usable */
+ bfi = 1;
+ unusable_frame = 0;
+ }
+ else if ((frame_type == RX_NO_DATA) ||
+ (frame_type == RX_SPEECH_LOST))
+ {
+ /* bfi only for lsf, gains and pitch period */
+ bfi = 1;
+ unusable_frame = 1;
+ }
+ else
+ {
+ bfi = 0;
+ unusable_frame = 0;
+ }
+
+ if (bfi != 0)
+ {
+ st->state += 1;
+
+ if (st->state > 6)
+ {
+ st->state = 6;
+ }
+ }
+ else
+ {
+ st->state >>= 1;
+ }
+
+ /* If this frame is the first speech frame after CNI period,
+ * set the BFH state machine to an appropriate state depending
+ * on whether there was DTX muting before start of speech or not
+ * If there was DTX muting, the first speech frame is muted.
+ * If there was no DTX muting, the first speech frame is not
+ * muted. The BFH state machine starts from state 5, however, to
+ * keep the audible noise resulting from a SID frame which is
+ * erroneously interpreted as a good speech frame as small as
+ * possible (the decoder output in this case is quickly muted)
+ */
+
+ if (st->dtx_decSt.dtxGlobalState == DTX)
+ {
+ st->state = 5;
+ st->prev_bfi = 0;
+ }
+ else if (st->dtx_decSt.dtxGlobalState == DTX_MUTE)
+ {
+ st->state = 5;
+ st->prev_bfi = 1;
+ }
+
+ if (newDTXState == SPEECH)
+ {
+ vad_flag = Serial_parm_1bit(&prms);
+
+ if (bfi == 0)
+ {
+ if (vad_flag == 0)
+ {
+ st->vad_hist = add_int16(st->vad_hist, 1);
+ }
+ else
+ {
+ st->vad_hist = 0;
+ }
+ }
+ }
+ /*
+ * DTX-CNG
+ */
+
+ if (newDTXState != SPEECH) /* CNG mode */
+ {
+ /* increase slightly energy of noise below 200 Hz */
+
+ /* Convert ISFs to the cosine domain */
+ Isf_isp(isf, ispnew, M);
+
+ Isp_Az(ispnew, Aq, M, 1);
+
+ pv_memcpy((void *)isf_tmp, (void *)st->isfold, M*sizeof(*isf_tmp));
+
+
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ j = i_subfr >> 6;
+
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = mul_16by16_to_int32(isf_tmp[i], sub_int16(32767, interpol_frac[j]));
+ L_tmp = mac_16by16_to_int32(L_tmp, isf[i], interpol_frac[j]);
+ HfIsf[i] = amr_wb_round(L_tmp);
+ }
+
+ synthesis_amr_wb(Aq,
+ &exc2[i_subfr],
+ 0,
+ &synth16k[i_subfr *5/4],
+ 1,
+ HfIsf,
+ nb_bits,
+ newDTXState,
+ st,
+ bfi,
+ ScratchMem);
+ }
+
+ /* reset speech coder memories */
+ pvDecoder_AmrWb_Reset(st, 0);
+
+ pv_memcpy((void *)st->isfold, (void *)isf, M*sizeof(*isf));
+
+ st->prev_bfi = bfi;
+ st->dtx_decSt.dtxGlobalState = newDTXState;
+
+ return 0;
+ }
+ /*
+ * ACELP
+ */
+
+ /* copy coder memory state into working space (internal memory for DSP) */
+
+ pv_memcpy((void *)old_exc, (void *)st->old_exc, (PIT_MAX + L_INTERPOL)*sizeof(*old_exc));
+
+ exc = old_exc + PIT_MAX + L_INTERPOL;
+
+ /* Decode the ISFs */
+
+ if (nb_bits > NBBITS_7k) /* all rates but 6.6 Kbps */
+ {
+ ind[0] = Serial_parm(8, &prms); /* index of 1st ISP subvector */
+ ind[1] = Serial_parm(8, &prms); /* index of 2nd ISP subvector */
+ ind[2] = Serial_parm(6, &prms); /* index of 3rd ISP subvector */
+ ind[3] = Serial_parm(7, &prms); /* index of 4th ISP subvector */
+ ind[4] = Serial_parm(7, &prms); /* index of 5th ISP subvector */
+ ind[5] = Serial_parm(5, &prms); /* index of 6th ISP subvector */
+ ind[6] = Serial_parm(5, &prms); /* index of 7th ISP subvector */
+
+ Dpisf_2s_46b(ind, isf, st->past_isfq, st->isfold, st->isf_buf, bfi, 1);
+ }
+ else
+ {
+ ind[0] = Serial_parm(8, &prms);
+ ind[1] = Serial_parm(8, &prms);
+ ind[2] = Serial_parm(14, &prms);
+ ind[3] = ind[2] & 0x007F;
+ ind[2] >>= 7;
+ ind[4] = Serial_parm(6, &prms);
+
+ Dpisf_2s_36b(ind, isf, st->past_isfq, st->isfold, st->isf_buf, bfi, 1);
+ }
+
+ /* Convert ISFs to the cosine domain */
+
+ Isf_isp(isf, ispnew, M);
+
+ if (st->first_frame != 0)
+ {
+ st->first_frame = 0;
+ pv_memcpy((void *)st->ispold, (void *)ispnew, M*sizeof(*ispnew));
+
+ }
+ /* Find the interpolated ISPs and convert to a[] for all subframes */
+ interpolate_isp(st->ispold, ispnew, interpol_frac, Aq);
+
+ /* update ispold[] for the next frame */
+ pv_memcpy((void *)st->ispold, (void *)ispnew, M*sizeof(*ispnew));
+
+ /* Check stability on isf : distance between old isf and current isf */
+
+ L_tmp = 0;
+ for (i = 0; i < M - 1; i++)
+ {
+ tmp = sub_int16(isf[i], st->isfold[i]);
+ L_tmp = mac_16by16_to_int32(L_tmp, tmp, tmp);
+ }
+ tmp = extract_h(shl_int32(L_tmp, 8));
+ tmp = mult_int16(tmp, 26214); /* tmp = L_tmp*0.8/256 */
+
+ tmp = 20480 - tmp; /* 1.25 - tmp */
+ stab_fac = shl_int16(tmp, 1); /* Q14 -> Q15 with saturation */
+
+ if (stab_fac < 0)
+ {
+ stab_fac = 0;
+ }
+ pv_memcpy((void *)isf_tmp, (void *)st->isfold, M*sizeof(*isf_tmp));
+
+ pv_memcpy((void *)st->isfold, (void *)isf, M*sizeof(*isf));
+
+ /*
+ * Loop for every subframe in the analysis frame
+ *
+ * The subframe size is L_SUBFR and the loop is repeated L_FRAME/L_SUBFR
+ * times
+ * - decode the pitch delay and filter mode
+ * - decode algebraic code
+ * - decode pitch and codebook gains
+ * - find voicing factor and tilt of code for next subframe.
+ * - find the excitation and compute synthesis speech
+ */
+
+ p_Aq = Aq; /* pointer to interpolated LPC parameters */
+
+
+ /*
+ * Sub process next 3 subframes
+ */
+
+
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ pit_flag = i_subfr;
+
+
+ if ((i_subfr == 2*L_SUBFR) && (nb_bits > NBBITS_7k))
+ {
+ pit_flag = 0; /* set to 0 for 3rd subframe, <=> is not 6.6 kbps */
+ }
+ /*-------------------------------------------------*
+ * - Decode pitch lag *
+ * Lag indeces received also in case of BFI, *
+ * so that the parameter pointer stays in sync. *
+ *-------------------------------------------------*/
+
+ if (pit_flag == 0)
+ {
+
+ if (nb_bits <= NBBITS_9k)
+ {
+ index = Serial_parm(8, &prms);
+
+ if (index < (PIT_FR1_8b - PIT_MIN) * 2)
+ {
+ T0 = PIT_MIN + (index >> 1);
+ T0_frac = sub_int16(index, shl_int16(sub_int16(T0, PIT_MIN), 1));
+ T0_frac = shl_int16(T0_frac, 1);
+ }
+ else
+ {
+ T0 = add_int16(index, PIT_FR1_8b - ((PIT_FR1_8b - PIT_MIN) * 2));
+ T0_frac = 0;
+ }
+ }
+ else
+ {
+ index = Serial_parm(9, &prms);
+
+ if (index < (PIT_FR2 - PIT_MIN) * 4)
+ {
+ T0 = PIT_MIN + (index >> 2);
+ T0_frac = sub_int16(index, shl_int16(sub_int16(T0, PIT_MIN), 2));
+ }
+ else if (index < (((PIT_FR2 - PIT_MIN) << 2) + ((PIT_FR1_9b - PIT_FR2) << 1)))
+ {
+ index -= (PIT_FR2 - PIT_MIN) << 2;
+ T0 = PIT_FR2 + (index >> 1);
+ T0_frac = sub_int16(index, shl_int16(sub_int16(T0, PIT_FR2), 1));
+ T0_frac = shl_int16(T0_frac, 1);
+ }
+ else
+ {
+ T0 = add_int16(index, (PIT_FR1_9b - ((PIT_FR2 - PIT_MIN) * 4) - ((PIT_FR1_9b - PIT_FR2) * 2)));
+ T0_frac = 0;
+ }
+ }
+
+ /* find T0_min and T0_max for subframe 2 and 4 */
+
+ T0_min = T0 - 8;
+
+ if (T0_min < PIT_MIN)
+ {
+ T0_min = PIT_MIN;
+ }
+ T0_max = T0_min + 15;
+
+ if (T0_max > PIT_MAX)
+ {
+ T0_max = PIT_MAX;
+ T0_min = PIT_MAX - 15;
+ }
+ }
+ else
+ { /* if subframe 2 or 4 */
+
+ if (nb_bits <= NBBITS_9k)
+ {
+ index = Serial_parm(5, &prms);
+
+ T0 = T0_min + (index >> 1);
+ T0_frac = sub_int16(index, shl_int16(T0 - T0_min, 1));
+ T0_frac = shl_int16(T0_frac, 1);
+ }
+ else
+ {
+ index = Serial_parm(6, &prms);
+
+ T0 = T0_min + (index >> 2);
+ T0_frac = sub_int16(index, shl_int16(T0 - T0_min, 2));
+ }
+ }
+
+ /* check BFI after pitch lag decoding */
+
+ if (bfi != 0) /* if frame erasure */
+ {
+ lagconceal(&(st->dec_gain[17]), st->lag_hist, &T0, &(st->old_T0), &(st->seed3), unusable_frame);
+ T0_frac = 0;
+ }
+ /*
+ * Find the pitch gain, the interpolation filter
+ * and the adaptive codebook vector.
+ */
+
+ Pred_lt4(&exc[i_subfr], T0, T0_frac, L_SUBFR + 1);
+
+
+ if (unusable_frame)
+ {
+ select = 1;
+ }
+ else
+ {
+
+ if (nb_bits <= NBBITS_9k)
+ {
+ select = 0;
+ }
+ else
+ {
+ select = Serial_parm_1bit(&prms);
+ }
+ }
+
+
+ if (select == 0)
+ {
+ /* find pitch excitation with lp filter */
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ L_tmp = ((int32) exc[i-1+i_subfr] + exc[i+1+i_subfr]);
+ L_tmp *= 5898;
+ L_tmp += ((int32) exc[i+i_subfr] * 20972);
+
+ code[i] = amr_wb_round(L_tmp << 1);
+ }
+ pv_memcpy((void *)&exc[i_subfr], (void *)code, L_SUBFR*sizeof(*code));
+
+ }
+ /*
+ * Decode innovative codebook.
+ * Add the fixed-gain pitch contribution to code[].
+ */
+
+ if (unusable_frame != 0)
+ {
+ /* the innovative code doesn't need to be scaled (see Q_gain2) */
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ code[i] = noise_gen_amrwb(&(st->seed)) >> 3;
+ }
+ }
+ else if (nb_bits <= NBBITS_7k)
+ {
+ ind[0] = Serial_parm(12, &prms);
+ dec_acelp_2p_in_64(ind[0], code);
+ }
+ else if (nb_bits <= NBBITS_9k)
+ {
+ for (i = 0; i < 4; i++)
+ {
+ ind[i] = Serial_parm(5, &prms);
+ }
+ dec_acelp_4p_in_64(ind, 20, code);
+ }
+ else if (nb_bits <= NBBITS_12k)
+ {
+ for (i = 0; i < 4; i++)
+ {
+ ind[i] = Serial_parm(9, &prms);
+ }
+ dec_acelp_4p_in_64(ind, 36, code);
+ }
+ else if (nb_bits <= NBBITS_14k)
+ {
+ ind[0] = Serial_parm(13, &prms);
+ ind[1] = Serial_parm(13, &prms);
+ ind[2] = Serial_parm(9, &prms);
+ ind[3] = Serial_parm(9, &prms);
+ dec_acelp_4p_in_64(ind, 44, code);
+ }
+ else if (nb_bits <= NBBITS_16k)
+ {
+ for (i = 0; i < 4; i++)
+ {
+ ind[i] = Serial_parm(13, &prms);
+ }
+ dec_acelp_4p_in_64(ind, 52, code);
+ }
+ else if (nb_bits <= NBBITS_18k)
+ {
+ for (i = 0; i < 4; i++)
+ {
+ ind[i] = Serial_parm(2, &prms);
+ }
+ for (i = 4; i < 8; i++)
+ {
+ ind[i] = Serial_parm(14, &prms);
+ }
+ dec_acelp_4p_in_64(ind, 64, code);
+ }
+ else if (nb_bits <= NBBITS_20k)
+ {
+ ind[0] = Serial_parm(10, &prms);
+ ind[1] = Serial_parm(10, &prms);
+ ind[2] = Serial_parm(2, &prms);
+ ind[3] = Serial_parm(2, &prms);
+ ind[4] = Serial_parm(10, &prms);
+ ind[5] = Serial_parm(10, &prms);
+ ind[6] = Serial_parm(14, &prms);
+ ind[7] = Serial_parm(14, &prms);
+ dec_acelp_4p_in_64(ind, 72, code);
+ }
+ else
+ {
+ for (i = 0; i < 8; i++)
+ {
+ ind[i] = Serial_parm(11, &prms);
+ }
+
+ dec_acelp_4p_in_64(ind, 88, code);
+ }
+
+ preemph_amrwb_dec(code, st->tilt_code, L_SUBFR);
+
+ tmp = T0;
+
+ if (T0_frac > 2)
+ {
+ tmp++;
+ }
+ Pit_shrp(code, tmp, PIT_SHARP, L_SUBFR);
+
+ /*
+ * Decode codebooks gains.
+ */
+
+ if (nb_bits <= NBBITS_9k)
+ {
+ index = Serial_parm(6, &prms); /* codebook gain index */
+
+ dec_gain2_amr_wb(index,
+ 6,
+ code,
+ L_SUBFR,
+ &gain_pit,
+ &L_gain_code,
+ bfi,
+ st->prev_bfi,
+ st->state,
+ unusable_frame,
+ st->vad_hist,
+ st->dec_gain);
+ }
+ else
+ {
+ index = Serial_parm(7, &prms); /* codebook gain index */
+
+ dec_gain2_amr_wb(index,
+ 7,
+ code,
+ L_SUBFR,
+ &gain_pit,
+ &L_gain_code,
+ bfi,
+ st->prev_bfi,
+ st->state,
+ unusable_frame,
+ st->vad_hist,
+ st->dec_gain);
+ }
+
+ /* find best scaling to perform on excitation (Q_new) */
+
+ tmp = st->Qsubfr[0];
+ for (i = 1; i < 4; i++)
+ {
+ if (st->Qsubfr[i] < tmp)
+ {
+ tmp = st->Qsubfr[i];
+ }
+ }
+
+ /* limit scaling (Q_new) to Q_MAX: see pv_amr_wb_cnst.h and syn_filt_32() */
+
+ if (tmp > Q_MAX)
+ {
+ tmp = Q_MAX;
+ }
+ Q_new = 0;
+ L_tmp = L_gain_code; /* L_gain_code in Q16 */
+
+
+ while ((L_tmp < 0x08000000L) && (Q_new < tmp))
+ {
+ L_tmp <<= 1;
+ Q_new += 1;
+
+ }
+ gain_code = amr_wb_round(L_tmp); /* scaled gain_code with Qnew */
+
+ scale_signal(exc + i_subfr - (PIT_MAX + L_INTERPOL),
+ PIT_MAX + L_INTERPOL + L_SUBFR,
+ (int16)(Q_new - st->Q_old));
+
+ st->Q_old = Q_new;
+
+
+ /*
+ * Update parameters for the next subframe.
+ * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced)
+ */
+
+
+ if (bfi == 0)
+ {
+ /* LTP-Lag history update */
+ for (i = 4; i > 0; i--)
+ {
+ st->lag_hist[i] = st->lag_hist[i - 1];
+ }
+ st->lag_hist[0] = T0;
+
+ st->old_T0 = T0;
+ st->old_T0_frac = 0; /* Remove fraction in case of BFI */
+ }
+ /* find voice factor in Q15 (1=voiced, -1=unvoiced) */
+
+ /*
+ * Scale down by 1/8
+ */
+ for (i = L_SUBFR - 1; i >= 0; i--)
+ {
+ exc2[i] = (exc[i_subfr + i] + (0x0004 * (exc[i_subfr + i] != MAX_16))) >> 3;
+ }
+
+
+ /* post processing of excitation elements */
+
+ if (nb_bits <= NBBITS_9k)
+ {
+ pit_sharp = shl_int16(gain_pit, 1);
+
+ if (pit_sharp > 16384)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ tmp = mult_int16(exc2[i], pit_sharp);
+ L_tmp = mul_16by16_to_int32(tmp, gain_pit);
+ L_tmp >>= 1;
+ excp[i] = amr_wb_round(L_tmp);
+ }
+ }
+ }
+ else
+ {
+ pit_sharp = 0;
+ }
+
+ voice_fac = voice_factor(exc2, -3, gain_pit, code, gain_code, L_SUBFR);
+
+ /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */
+
+ st->tilt_code = (voice_fac >> 2) + 8192;
+
+ /*
+ * - Find the total excitation.
+ * - Find synthesis speech corresponding to exc[].
+ * - Find maximum value of excitation for next scaling
+ */
+
+ pv_memcpy((void *)exc2, (void *)&exc[i_subfr], L_SUBFR*sizeof(*exc2));
+ max = 1;
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ L_tmp = mul_16by16_to_int32(code[i], gain_code);
+ L_tmp = shl_int32(L_tmp, 5);
+ L_tmp = mac_16by16_to_int32(L_tmp, exc[i + i_subfr], gain_pit);
+ L_tmp = shl_int32(L_tmp, 1);
+ tmp = amr_wb_round(L_tmp);
+ exc[i + i_subfr] = tmp;
+ tmp = tmp - (tmp < 0);
+ max |= tmp ^(tmp >> 15); /* |= tmp ^sign(tmp) */
+ }
+
+
+ /* tmp = scaling possible according to max value of excitation */
+ tmp = add_int16(norm_s(max), Q_new) - 1;
+
+ st->Qsubfr[3] = st->Qsubfr[2];
+ st->Qsubfr[2] = st->Qsubfr[1];
+ st->Qsubfr[1] = st->Qsubfr[0];
+ st->Qsubfr[0] = tmp;
+
+ /*
+ * phase dispersion to enhance noise in low bit rate
+ */
+
+
+ if (nb_bits <= NBBITS_7k)
+ {
+ j = 0; /* high dispersion for rate <= 7.5 kbit/s */
+ }
+ else if (nb_bits <= NBBITS_9k)
+ {
+ j = 1; /* low dispersion for rate <= 9.6 kbit/s */
+ }
+ else
+ {
+ j = 2; /* no dispersion for rate > 9.6 kbit/s */
+ }
+
+ /* L_gain_code in Q16 */
+
+ phase_dispersion((int16)(L_gain_code >> 16),
+ gain_pit,
+ code,
+ j,
+ st->disp_mem,
+ ScratchMem);
+
+ /*
+ * noise enhancer
+ * - Enhance excitation on noise. (modify gain of code)
+ * If signal is noisy and LPC filter is stable, move gain
+ * of code 1.5 dB toward gain of code threshold.
+ * This decrease by 3 dB noise energy variation.
+ */
+
+ tmp = 16384 - (voice_fac >> 1); /* 1=unvoiced, 0=voiced */
+ fac = mult_int16(stab_fac, tmp);
+
+ L_tmp = L_gain_code;
+
+ if (L_tmp < st->L_gc_thres)
+ {
+ L_tmp += fxp_mul32_by_16b(L_gain_code, 6226) << 1;
+
+ if (L_tmp > st->L_gc_thres)
+ {
+ L_tmp = st->L_gc_thres;
+ }
+ }
+ else
+ {
+ L_tmp = fxp_mul32_by_16b(L_gain_code, 27536) << 1;
+
+ if (L_tmp < st->L_gc_thres)
+ {
+ L_tmp = st->L_gc_thres;
+ }
+ }
+ st->L_gc_thres = L_tmp;
+
+ L_gain_code = fxp_mul32_by_16b(L_gain_code, (32767 - fac)) << 1;
+
+
+ L_gain_code = add_int32(L_gain_code, fxp_mul32_by_16b(L_tmp, fac) << 1);
+
+ /*
+ * pitch enhancer
+ * - Enhance excitation on voice. (HP filtering of code)
+ * On voiced signal, filtering of code by a smooth fir HP
+ * filter to decrease energy of code in low frequency.
+ */
+
+ tmp = (voice_fac >> 3) + 4096;/* 0.25=voiced, 0=unvoiced */
+
+ /* build excitation */
+
+ gain_code = amr_wb_round(shl_int32(L_gain_code, Q_new));
+
+ L_tmp = (int32)(code[0] << 16);
+ L_tmp = msu_16by16_from_int32(L_tmp, code[1], tmp);
+ L_tmp = mul_16by16_to_int32(amr_wb_round(L_tmp), gain_code);
+ L_tmp = shl_int32(L_tmp, 5);
+ L_tmp = mac_16by16_to_int32(L_tmp, exc2[0], gain_pit);
+ L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */
+ exc2[0] = amr_wb_round(L_tmp);
+
+
+ for (i = 1; i < L_SUBFR - 1; i++)
+ {
+ L_tmp = (int32)(code[i] << 16);
+ L_tmp = msu_16by16_from_int32(L_tmp, (code[i + 1] + code[i - 1]), tmp);
+ L_tmp = mul_16by16_to_int32(amr_wb_round(L_tmp), gain_code);
+ L_tmp = shl_int32(L_tmp, 5);
+ L_tmp = mac_16by16_to_int32(L_tmp, exc2[i], gain_pit);
+ L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */
+ exc2[i] = amr_wb_round(L_tmp);
+ }
+
+ L_tmp = (int32)(code[L_SUBFR - 1] << 16);
+ L_tmp = msu_16by16_from_int32(L_tmp, code[L_SUBFR - 2], tmp);
+ L_tmp = mul_16by16_to_int32(amr_wb_round(L_tmp), gain_code);
+ L_tmp = shl_int32(L_tmp, 5);
+ L_tmp = mac_16by16_to_int32(L_tmp, exc2[L_SUBFR - 1], gain_pit);
+ L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */
+ exc2[L_SUBFR - 1] = amr_wb_round(L_tmp);
+
+
+
+ if (nb_bits <= NBBITS_9k)
+ {
+ if (pit_sharp > 16384)
+ {
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ excp[i] = add_int16(excp[i], exc2[i]);
+ }
+ agc2_amr_wb(exc2, excp, L_SUBFR);
+ pv_memcpy((void *)exc2, (void *)excp, L_SUBFR*sizeof(*exc2));
+
+ }
+ }
+ if (nb_bits <= NBBITS_7k)
+ {
+ j = i_subfr >> 6;
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = mul_16by16_to_int32(isf_tmp[i], sub_int16(32767, interpol_frac[j]));
+ L_tmp = mac_16by16_to_int32(L_tmp, isf[i], interpol_frac[j]);
+ HfIsf[i] = amr_wb_round(L_tmp);
+ }
+ }
+ else
+ {
+ pv_memset((void *)st->mem_syn_hf,
+ 0,
+ (M16k - M)*sizeof(*st->mem_syn_hf));
+ }
+
+ if (nb_bits >= NBBITS_24k)
+ {
+ corr_gain = Serial_parm(4, &prms);
+ }
+ else
+ {
+ corr_gain = 0;
+ }
+
+ synthesis_amr_wb(p_Aq,
+ exc2,
+ Q_new,
+ &synth16k[i_subfr + (i_subfr>>2)],
+ corr_gain,
+ HfIsf,
+ nb_bits,
+ newDTXState,
+ st,
+ bfi,
+ ScratchMem);
+
+ p_Aq += (M + 1); /* interpolated LPC parameters for next subframe */
+ }
+
+ /*
+ * Update signal for next frame.
+ * -> save past of exc[]
+ * -> save pitch parameters
+ */
+
+ pv_memcpy((void *)st->old_exc,
+ (void *)&old_exc[L_FRAME],
+ (PIT_MAX + L_INTERPOL)*sizeof(*old_exc));
+
+ scale_signal(exc, L_FRAME, (int16)(-Q_new));
+
+ dtx_dec_amr_wb_activity_update(&(st->dtx_decSt), isf, exc);
+
+ st->dtx_decSt.dtxGlobalState = newDTXState;
+
+ st->prev_bfi = bfi;
+
+ return 0;
+}
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder.h
new file mode 100644
index 0000000..c40bc10
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder.h
@@ -0,0 +1,158 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Name: pvamrwbdecoder.h
+
+ Date: 05/02/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ Main header file for the Packet Video AMR Wide Band decoder library. The
+ constants, structures, and functions defined within this file, along with
+ a basic data types header file, is all that is needed to use and communicate
+ with the library. The internal data structures within the library are
+ purposely hidden.
+
+ ---* Need description of the input buffering. *-------
+
+ ---* Need an example of calling the library here *----
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ (Normally header files do not have a reference section)
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef _PVAMRWBDECODER_H
+#define _PVAMRWBDECODER_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pv_amr_wb_type_defs.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; MACROS
+ ; Define module specific macros here
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+typedef struct
+{
+ int16 prev_ft;
+ int16 prev_mode;
+} RX_State_wb;
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ void pvDecoder_AmrWb_Init(void **spd_state, void *st, int16 ** ScratchMem);
+
+ int32 pvDecoder_AmrWb(
+ int16 mode, /* input : used mode */
+ int16 prms[], /* input : parameter vector */
+ int16 synth16k[], /* output: synthesis speech */
+ int16 * frame_length, /* output: lenght of the frame */
+ void *spd_state, /* i/o : State structure */
+ int16 frame_type, /* input : received frame type */
+ int16 ScratchMem[]
+ );
+
+ void pvDecoder_AmrWb_Reset(void *st, int16 reset_all);
+
+ int16 pvDecoder_AmrWb_homing_frame_test(int16 input_frame[], int16 mode);
+
+ int16 pvDecoder_AmrWb_homing_frame_test_first(int16 input_frame[], int16 mode);
+
+ int32 pvDecoder_AmrWbMemRequirements();
+
+ void mime_unsorting(uint8 packet[],
+ int16 compressed_data[],
+ int16 *frame_type,
+ int16 *mode,
+ uint8 q,
+ RX_State_wb *st);
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* PVMP4AUDIODECODER_API_H */
+
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder_acelp.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder_acelp.h
new file mode 100644
index 0000000..5967115
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder_acelp.h
@@ -0,0 +1,329 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/pvamrwbdecoder_acelp.h
+
+ Date: 01/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PVAMRWBDECODER_ACELP_H
+#define PVAMRWBDECODER_ACELP_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_mem_funcs.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*-----------------------------------------------------------------*
+ * LPC prototypes *
+ *-----------------------------------------------------------------*/
+
+ void isf_extrapolation(int16 HfIsf[]);
+
+ void Init_Lagconc(int16 lag_hist[]);
+ void lagconceal(
+ int16 gain_hist[], /* (i) : Gain history */
+ int16 lag_hist[], /* (i) : Subframe size */
+ int16 * T0,
+ int16 * old_T0,
+ int16 * seed,
+ int16 unusable_frame
+ );
+
+ void agc2_amr_wb(
+ int16 * sig_in, /* input : postfilter input signal */
+ int16 * sig_out, /* in/out: postfilter output signal */
+ int16 l_trm /* input : subframe size */
+ );
+
+ void low_pass_filt_7k_init(int16 mem[]);
+ void low_pass_filt_7k(
+ int16 signal[], /* input: signal */
+ int16 lg, /* input: length of input */
+ int16 mem[], /* in/out: memory (size=30) */
+ int16 x[]
+ );
+
+ int16 median5(int16 x[]);
+
+ void Isp_Az(
+ int16 isp[], /* (i) Q15 : Immittance spectral pairs */
+ int16 a[], /* (o) Q12 : predictor coefficients (order = M) */
+ int16 m,
+ int16 adaptive_scaling /* (i) 0 : adaptive scaling disabled */
+ /* 1 : adaptive scaling enabled */
+ );
+ void Isf_isp(
+ int16 isf[], /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
+ int16 isp[], /* (o) Q15 : isp[m] (range: -1<=val<1) */
+ int16 m /* (i) : LPC order */
+ );
+ void interpolate_isp(
+ int16 isp_old[], /* input : isps from past frame */
+ int16 isp_new[], /* input : isps from present frame */
+ const int16 frac[], /* input : fraction for 3 first subfr (Q15) */
+ int16 Az[] /* output: LP coefficients in 4 subframes */
+ );
+ void weight_amrwb_lpc(
+ int16 a[], /* (i) Q12 : a[m+1] LPC coefficients */
+ int16 ap[], /* (o) Q12 : Spectral expanded LPC coefficients */
+ int16 gamma, /* (i) Q15 : Spectral expansion factor. */
+ int16 m /* (i) : LPC order. */
+ );
+
+
+ /*-----------------------------------------------------------------*
+ * isf quantizers *
+ *-----------------------------------------------------------------*/
+
+ void Disf_ns(
+ int16 * indice, /* input: quantization indices */
+ int16 * isf_q /* input : ISF in the frequency domain (0..0.5) */
+ );
+
+ void Dpisf_2s_46b(
+ int16 * indice, /* input: quantization indices */
+ int16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ int16 * past_isfq, /* i/0 : past ISF quantizer */
+ int16 * isfold, /* input : past quantized ISF */
+ int16 * isf_buf, /* input : isf buffer */
+ int16 bfi, /* input : Bad frame indicator */
+ int16 enc_dec
+ );
+ void Dpisf_2s_36b(
+ int16 * indice, /* input: quantization indices */
+ int16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ int16 * past_isfq, /* i/0 : past ISF quantizer */
+ int16 * isfold, /* input : past quantized ISF */
+ int16 * isf_buf, /* input : isf buffer */
+ int16 bfi, /* input : Bad frame indicator */
+ int16 enc_dec
+ );
+
+
+ void Reorder_isf(
+ int16 * isf, /* (i/o) Q15: ISF in the frequency domain (0..0.5) */
+ int16 min_dist, /* (i) Q15 : minimum distance to keep */
+ int16 n /* (i) : number of ISF */
+ );
+
+ /*-----------------------------------------------------------------*
+ * filter prototypes *
+ *-----------------------------------------------------------------*/
+
+ void oversamp_12k8_to_16k_init(
+ int16 mem[] /* output: memory (2*NB_COEF_UP) set to zeros */
+ );
+ void oversamp_12k8_to_16k(
+ int16 sig12k8[], /* input: signal to oversampling */
+ int16 lg, /* input: length of input */
+ int16 sig16k[], /* output: oversampled signal */
+ int16 mem[], /* in/out: memory (2*NB_COEF_UP) */
+ int16 signal[]
+ );
+
+ void highpass_50Hz_at_12k8_init(int16 mem[]);
+ void highpass_50Hz_at_12k8(
+ int16 signal[], /* input/output signal */
+ int16 lg, /* lenght of signal */
+ int16 mem[] /* filter memory [6] */
+ );
+ void highpass_400Hz_at_12k8_init(int16 mem[]);
+ void highpass_400Hz_at_12k8(
+ int16 signal[], /* input/output signal */
+ int16 lg, /* lenght of signal */
+ int16 mem[] /* filter memory [6] */
+ );
+
+ void band_pass_6k_7k_init(int16 mem[]);
+ void band_pass_6k_7k(
+ int16 signal[], /* input: signal */
+ int16 lg, /* input: length of input */
+ int16 mem[], /* in/out: memory (size=30) */
+ int16 x[]
+ );
+
+
+ void preemph_amrwb_dec(
+ int16 x[], /* (i/o) : input signal overwritten by the output */
+ int16 mu, /* (i) Q15 : preemphasis coefficient */
+ int16 lg /* (i) : lenght of filtering */
+ );
+
+ void deemphasis_32(
+ int16 x_hi[], /* (i) : input signal (bit31..16) */
+ int16 x_lo[], /* (i) : input signal (bit15..4) */
+ int16 y[], /* (o) : output signal (x16) */
+ int16 mu, /* (i) Q15 : deemphasis factor */
+ int16 L, /* (i) : vector size */
+ int16 * mem /* (i/o) : memory (y[-1]) */
+ );
+
+
+ void wb_syn_filt(
+ int16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ int16 m, /* (i) : order of LP filter */
+ int16 x[], /* (i) : input signal */
+ int16 y[], /* (o) : output signal */
+ int16 lg, /* (i) : size of filtering */
+ int16 mem[], /* (i/o) : memory associated with this filtering. */
+ int16 update, /* (i) : 0=no update, 1=update of memory. */
+ int16 y_buf[]
+ );
+ void Syn_filt_32(
+ int16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ int16 m, /* (i) : order of LP filter */
+ int16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
+ int16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
+ int16 sig_hi[], /* (o) /16 : synthesis high */
+ int16 sig_lo[], /* (o) /16 : synthesis low */
+ int16 lg /* (i) : size of filtering */
+ );
+
+ /*-----------------------------------------------------------------*
+ * pitch prototypes *
+ *-----------------------------------------------------------------*/
+
+
+ void Pred_lt4(
+ int16 exc[], /* in/out: excitation buffer */
+ int16 T0, /* input : integer pitch lag */
+ int16 frac, /* input : fraction of lag */
+ int16 L_subfr /* input : subframe size */
+ );
+
+ /*-----------------------------------------------------------------*
+ * gain prototypes *
+ *-----------------------------------------------------------------*/
+
+
+ void dec_gain2_amr_wb_init(
+ int16 * mem /* output : memory (4 words) */
+ );
+ void dec_gain2_amr_wb(
+ int16 index, /* (i) :index of quantization. */
+ int16 nbits, /* (i) : number of bits (6 or 7) */
+ int16 code[], /* (i) Q9 :Innovative vector. */
+ int16 L_subfr, /* (i) :Subframe lenght. */
+ int16 * gain_pit, /* (o) Q14 :Pitch gain. */
+ int32 * gain_cod, /* (o) Q16 :Code gain. */
+ int16 bfi, /* (i) :bad frame indicator */
+ int16 prev_bfi, /* (i) : Previous BF indicator */
+ int16 state, /* (i) : State of BFH */
+ int16 unusable_frame, /* (i) : UF indicator */
+ int16 vad_hist, /* (i) :number of non-speech frames */
+ int16 * mem /* (i/o) : memory (4 words) */
+ );
+
+ /*-----------------------------------------------------------------*
+ * acelp prototypes *
+ *-----------------------------------------------------------------*/
+
+ void dec_acelp_2p_in_64(
+ int16 index, /* (i) : 12 bits index */
+ int16 code[] /* (o) :Q9 algebraic (fixed) codebook excitation */
+ );
+
+ void dec_acelp_4p_in_64(
+ int16 index[], /* (i) : index (20): 5+5+5+5 = 20 bits. */
+ /* (i) : index (36): 9+9+9+9 = 36 bits. */
+ /* (i) : index (44): 13+9+13+9 = 44 bits. */
+ /* (i) : index (52): 13+13+13+13 = 52 bits. */
+ /* (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits. */
+ /* (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits. */
+ /* (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
+ int16 nbbits, /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits */
+ int16 code[] /* (o) Q9: algebraic (fixed) codebook excitation */
+ );
+ void Pit_shrp(
+ int16 * x, /* in/out: impulse response (or algebraic code) */
+ int16 pit_lag, /* input : pitch lag */
+ int16 sharp, /* input : pitch sharpening factor (Q15) */
+ int16 L_subfr /* input : subframe size */
+ );
+
+
+ /*-----------------------------------------------------------------*
+ * others prototypes *
+ *-----------------------------------------------------------------*/
+
+ int16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
+ int16 exc[], /* (i) Q_exc: pitch excitation */
+ int16 Q_exc, /* (i) : exc format */
+ int16 gain_pit, /* (i) Q14 : gain of pitch */
+ int16 code[], /* (i) Q9 : Fixed codebook excitation */
+ int16 gain_code, /* (i) Q0 : gain of code */
+ int16 L_subfr /* (i) : subframe length */
+ );
+
+ void scale_signal(
+ int16 x[], /* (i/o) : signal to scale */
+ int16 lg, /* (i) : size of x[] */
+ int16 exp /* (i) : exponent: x = round(x << exp) */
+ );
+
+ int16 noise_gen_amrwb(int16 * seed);
+
+
+ void phase_dispersion(
+ int16 gain_code, /* (i) Q0 : gain of code */
+ int16 gain_pit, /* (i) Q14 : gain of pitch */
+ int16 code[], /* (i/o) : code vector */
+ int16 mode, /* (i) : level, 0=hi, 1=lo, 2=off */
+ int16 disp_mem[], /* (i/o) : memory (size = 8) */
+ int16 ScratchMem[]
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ACELP_H */
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op.h
new file mode 100644
index 0000000..88ff9bc
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op.h
@@ -0,0 +1,249 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./src/pvamrwbdecoder_basic_op.h
+
+ Date: 05/07/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+
+#ifndef PVAMRWBDECODER_BASIC_OP_H
+#define PVAMRWBDECODER_BASIC_OP_H
+
+
+#include "normalize_amr_wb.h"
+
+
+#define MAX_32 (int32)0x7fffffffL
+#define MIN_32 (int32)0x80000000L
+
+#define MAX_16 ((int16)+32767) /* 0x7fff */
+#define MIN_16 ((int16)-32768) /* 0x8000 */
+
+
+
+
+/*----------------------------------------------------------------------------
+ Function Name : negate_int16
+
+ Negate var1 with saturation, saturate in the case where input is -32768:
+ negate(var1) = sub(0,var1).
+
+ Inputs :
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x8000 <= var1 <= 0x7fff.
+
+ Outputs :
+ none
+
+ Return Value :
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x8000 <= var_out <= 0x7fff.
+ ----------------------------------------------------------------------------*/
+
+__inline int16 negate_int16(int16 var1)
+{
+ return (((var1 == MIN_16) ? MAX_16 : -var1));
+}
+
+
+/*----------------------------------------------------------------------------
+
+ Function Name : shl_int16
+
+ Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill
+ the var2 LSB of the result. If var2 is negative, arithmetically shift
+ var1 right by -var2 with sign extension. Saturate the result in case of
+ underflows or overflows.
+
+ Inputs :
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x8000 <= var1 <= 0x7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x8000 <= var1 <= 0x7fff.
+
+ Return Value :
+ var_out
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0x8000 <= var_out <= 0x7fff.
+ ----------------------------------------------------------------------------*/
+
+__inline int16 shl_int16(int16 var1, int16 var2)
+{
+ int16 var_out;
+
+ if (var2 < 0)
+ {
+ var2 = (-var2) & (0xf);
+ var_out = var1 >> var2;
+ }
+ else
+ {
+ var2 &= 0xf;
+ var_out = var1 << var2;
+ if (var_out >> var2 != var1)
+ {
+ var_out = (var1 >> 15) ^ MAX_16;
+ }
+ }
+ return (var_out);
+}
+
+
+/*----------------------------------------------------------------------------
+
+ Function Name : shl_int32
+
+ Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero
+ fill the var2 LSB of the result. If var2 is negative, arithmetically
+ shift L_var1 right by -var2 with sign extension. Saturate the result in
+ case of underflows or overflows.
+
+ Inputs :
+ L_var1 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 8000 <= var2 <= 7fff.
+ Return Value :
+ 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+__inline int32 shl_int32(int32 L_var1, int16 var2)
+{
+ int32 L_var_out;
+
+ if (var2 > 0)
+ {
+ L_var_out = L_var1 << var2;
+ if (L_var_out >> var2 != L_var1)
+ {
+ L_var_out = (L_var1 >> 31) ^ MAX_32;
+ }
+ }
+ else
+ {
+ var2 = (-var2) & (0xf);
+ L_var_out = L_var1 >> var2;
+ }
+
+ return (L_var_out);
+}
+
+
+/*----------------------------------------------------------------------------
+
+ Function Name : shr_int32
+
+ Arithmetically shift the 32 bit input L_var1 right var2 positions with
+ sign extension. If var2 is negative, arithmetically shift L_var1 left
+ by -var2 and zero fill the -var2 LSB of the result. Saturate the result
+ in case of underflows or overflows.
+
+ Inputs :
+ L_var1 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 8000 <= var2 <= 7fff.
+ Return Value :
+ 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+__inline int32 shr_int32(int32 L_var1, int16 var2)
+{
+ int32 L_var_out;
+
+ if (var2 >= 0)
+ {
+ L_var_out = L_var1 >> (var2 & 0x1f);
+ }
+ else
+ {
+ var2 = (int16)(-var2);
+ var2 &= 0x1f;
+ L_var_out = L_var1 << var2;
+ if (L_var_out >> var2 != L_var1)
+ {
+ L_var_out = (L_var1 >> 31) ^ MAX_32;
+ }
+
+ }
+ return (L_var_out);
+}
+
+
+
+
+
+
+#if defined(PV_ARM_V5)
+
+#include "pvamrwbdecoder_basic_op_armv5.h"
+
+#elif defined(PV_ARM_GCC_V5)
+
+#include "pvamrwbdecoder_basic_op_gcc_armv5.h"
+
+#else
+
+#ifndef C_EQUIVALENT
+#define C_EQUIVALENT // default to C_EQUIVALENT
+#endif
+
+#include "pvamrwbdecoder_basic_op_cequivalent.h"
+
+#endif
+
+
+#endif /* PVAMRWBDECODER_BASIC_OP_H */
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_armv5.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_armv5.h
new file mode 100644
index 0000000..c800a2e
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_armv5.h
@@ -0,0 +1,253 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./src/pvamrwbdecoder_basic_op_armv5.h
+
+ Date: 05/07/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PVAMRWBDECODER_BASIC_OP_ARMV5_H
+#define PVAMRWBDECODER_BASIC_OP_ARMV5_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+#if defined(PV_ARM_V5)
+
+ __inline int16 add_int16(int16 var1, int16 var2)
+ {
+ int32 L_var_out;
+ int32 L_var_aux;
+
+ __asm
+ {
+ mov L_var_out, var1, lsl #16
+ mov L_var_aux, var2, lsl #16
+ qadd L_var_out, L_var_out, L_var_aux
+ mov L_var_out, L_var_out, asr #16
+
+ }
+ return L_var_out;
+ }
+
+
+ __inline int16 sub_int16(int16 var1, int16 var2)
+ {
+ int32 L_var_out;
+ int32 L_var_aux;
+
+ __asm
+ {
+ mov L_var_out, var1, lsl #16
+ mov L_var_aux, var2, lsl #16
+ qsub L_var_out, L_var_out, L_var_aux
+ mov L_var_out, L_var_out, asr #16
+
+ }
+ return L_var_out;
+ }
+
+
+ __inline int32 add_int32(int32 L_var1, int32 L_var2)
+ {
+ int32 L_var_out;
+
+ __asm
+ {
+ qadd L_var_out, L_var1, L_var2
+ }
+ return L_var_out;
+ }
+
+
+ __inline int32 mac_16by16_to_int32(int32 L_var3, int16 var1, int16 var2)
+ {
+ int32 L_var_out;
+
+
+ __asm
+ {
+ smulbb L_var_out, var1, var2
+ qdadd L_var_out, L_var3, L_var_out
+ }
+ return L_var_out;
+ }
+
+ __inline int32 sub_int32(int32 L_var1, int32 L_var2)
+ {
+ int32 L_var_out;
+
+ __asm
+ {
+ qsub L_var_out, L_var1, L_var2
+ }
+ return L_var_out;
+ }
+
+ __inline int32 msu_16by16_from_int32(int32 L_var3, int16 var1, int16 var2)
+ {
+ int32 L_var_out;
+
+
+ __asm
+ {
+ smulbb L_var_out, var1, var2
+ qdsub L_var_out, L_var3, L_var_out
+ }
+ return L_var_out;
+ }
+
+ __inline int32 mul_16by16_to_int32(int16 var1, int16 var2)
+ {
+ int32 L_var_out;
+
+ __asm
+ {
+ smulbb L_var_out, var1, var2
+ qadd L_var_out, L_var_out, L_var_out
+ }
+ return L_var_out;
+ }
+
+ __inline int16 mult_int16(int16 var1, int16 var2)
+ {
+ int32 L_var_out;
+
+ __asm
+ {
+ smulbb L_var_out, var1, var2
+ mov L_var_out, L_var_out, asr #15
+ }
+ return L_var_out;
+ }
+
+
+ __inline int16 amr_wb_round(int32 L_var1)
+ {
+ int32 L_var_out;
+
+ __asm
+ {
+ qadd L_var_out, L_var1, (int32) 0x00008000L
+ mov L_var_out, L_var_out, asr #16
+ }
+ return L_var_out;
+ }
+
+
+
+ __inline int16 amr_wb_shl1_round(int32 L_var1)
+ {
+ int32 L_var_out;
+
+ __asm
+ {
+ qadd L_var_out, L_var1, L_var1
+ qadd L_var_out, L_var_out, (int32) 0x00008000L
+ mov L_var_out, L_var_out, asr #16
+ }
+ return L_var_out;
+ }
+
+ __inline int32 mul_32by16(int16 hi, int16 lo, int16 n)
+ {
+ int32 H_32;
+ int32 L_32;
+ __asm
+ {
+ smulbb H_32, hi, n
+ smulbb L_32, lo, n
+ add H_32, H_32, L_32, asr #15
+ qadd H_32, H_32, H_32
+ }
+
+ return (H_32);
+ }
+
+ __inline int32 fxp_mac_16by16(const int16 var1, const int16 var2, int32 L_add)
+ {
+ __asm
+ {
+ smlabb L_add, var1, var2, L_add
+ }
+ return (L_add);
+ }
+
+ __inline int32 fxp_mul_16by16(int16 var1, const int16 var2)
+ {
+ int32 L_mult;
+ __asm
+ {
+ smulbb L_mult, var1, var2
+ }
+ return (L_mult);
+ }
+
+ __inline int32 fxp_mul32_by_16b(int32 L_var1, const int32 L_var2)
+ {
+ int32 L_mult;
+ __asm
+ {
+ smulwb L_mult, L_var1, L_var2
+ }
+
+ return L_mult;
+ }
+
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+#endif /* PVAMRWBDECODER_BASIC_OP_ARMV5_H */
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_cequivalent.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_cequivalent.h
new file mode 100644
index 0000000..7a86ec2
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_cequivalent.h
@@ -0,0 +1,503 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./src/pvamrwbdecoder_basic_op_cequivalent.h
+
+ Date: 05/07/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+#ifndef PVAMRWBDECODER_BASIC_OP_CEQUIVALENT_H
+#define PVAMRWBDECODER_BASIC_OP_CEQUIVALENT_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#include "normalize_amr_wb.h"
+
+#if defined(C_EQUIVALENT)
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : add_int16
+
+ Purpose :
+
+ Performs the addition (var1+var2) with overflow control and saturation;
+ the 16 bit result is set at +32767 when overflow occurs or at -32768
+ when underflow occurs.
+
+ Inputs :
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ Outputs :
+ none
+
+ Return Value :
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+
+ ----------------------------------------------------------------------------*/
+ __inline int16 add_int16(int16 var1, int16 var2)
+ {
+ int32 L_sum;
+
+ L_sum = (int32) var1 + var2;
+ if ((L_sum >> 15) != (L_sum >> 31))
+ {
+ L_sum = (L_sum >> 31) ^ MAX_16;
+ }
+ return ((int16)(L_sum));
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : sub_int16
+
+ Performs the subtraction (var1+var2) with overflow control and satu-
+ ration; the 16 bit result is set at +32767 when overflow occurs or at
+ -32768 when underflow occurs.
+
+ Inputs :
+
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ Outputs :
+ none
+
+ Return Value :
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+
+ ----------------------------------------------------------------------------*/
+ __inline int16 sub_int16(int16 var1, int16 var2)
+ {
+ int32 L_diff;
+
+ L_diff = (int32) var1 - var2;
+ if ((L_diff >> 15) != (L_diff >> 31))
+ {
+ L_diff = (L_diff >> 31) ^ MAX_16;
+ }
+ return ((int16)(L_diff));
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : mult_int16
+
+ Performs the multiplication of var1 by var2 and gives a 16 bit result
+ which is scaled i.e.:
+ mult_int16(var1,var2) = extract_l(L_shr((var1 times var2),15)) and
+ mult_int16(-32768,-32768) = 32767.
+
+ Inputs :
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+
+ Return Value :
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+
+ ----------------------------------------------------------------------------*/
+
+ __inline int16 mult_int16(int16 var1, int16 var2)
+ {
+ int32 L_product;
+
+ L_product = ((int32) var1 * (int32) var2) >> 15;
+
+ if ((L_product >> 15) != (L_product >> 31))
+ {
+ L_product = (L_product >> 31) ^ MAX_16;
+ }
+
+ return ((int16)L_product);
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : add_int32
+
+ 32 bits addition of the two 32 bits variables (L_var1+L_var2) with
+ overflow control and saturation; the result is set at +2147483647 when
+ overflow occurs or at -2147483648 when underflow occurs.
+
+ Inputs :
+
+ L_var1 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+ L_var2 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+
+ Return Value :
+ L_var_out
+ 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+
+ __inline int32 add_int32(int32 L_var1, int32 L_var2)
+ {
+ int32 L_var_out;
+
+ //L_var_out = L_var1 + L_var2;
+ if (L_var2 < 0) {
+ if (L_var1 < MIN_32 - L_var2) {
+ return MIN_32;
+ }
+ } else {
+ if (L_var1 > MAX_32 - L_var2) {
+ return MAX_32;
+ }
+ }
+
+ return L_var1 + L_var2;
+ }
+
+
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : sub_int32
+
+ 32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with
+ overflow control and saturation; the result is set at +2147483647 when
+ overflow occurs or at -2147483648 when underflow occurs.
+
+ Inputs :
+
+ L_var1 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+ L_var2 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+
+ Return Value :
+ L_var_out
+ 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+
+ __inline int32 sub_int32(int32 L_var1, int32 L_var2)
+ {
+ //L_var_out = L_var1 - L_var2;
+ if (L_var2 < 0) {
+ if (L_var1 > MAX_32 + L_var2) {
+ return MAX_32;
+ }
+ } else {
+ if (L_var1 < MIN_32 + L_var2) {
+ return MIN_32;
+ }
+ }
+
+ return L_var1 - L_var2;
+ }
+
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : mul_16by16_to_int32
+
+ mul_16by16_to_int32 is the 32 bit result of the multiplication of var1
+ times var2 with one shift left i.e.:
+ L_mult(var1,var2) = L_shl((var1 times var2),1) and
+ L_mult(-32768,-32768) = 2147483647.
+
+ Inputs :
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ Return Value :
+ 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+
+ __inline int32 mul_16by16_to_int32(int16 var1, int16 var2)
+ {
+ int32 L_mul;
+
+ L_mul = ((int32) var1 * (int32) var2);
+
+ if (L_mul != 0x40000000)
+ {
+ L_mul <<= 1;
+ }
+ else
+ {
+ L_mul = MAX_32; /* saturation */
+ }
+
+ return (L_mul);
+
+ }
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : mac_16by16_to_int32
+
+ Multiply var1 by var2 and shift the result left by 1. Add the 32 bit
+ result to L_var3 with saturation, return a 32 bit result:
+ L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)).
+
+ Inputs :
+
+ L_var3 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+
+ Return Value :
+ 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+
+ __inline int32 mac_16by16_to_int32(int32 L_var3, int16 var1, int16 var2)
+ {
+ return add_int32(L_var3, mul_16by16_to_int32(var1, var2));
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : msu_16by16_from_int32
+
+ Multiply var1 by var2 and shift the result left by 1. Subtract the 32 bit
+ result to L_var3 with saturation, return a 32 bit result:
+ L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)).
+
+ Inputs :
+
+ L_var3 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
+
+ var1
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+ var2
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var1 <= 0x0000 7fff.
+
+
+ Return Value :
+ 32 bit long signed integer (int32) whose value falls in the
+ range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
+
+ ----------------------------------------------------------------------------*/
+
+ __inline int32 msu_16by16_from_int32(int32 L_var3, int16 var1, int16 var2)
+ {
+ return sub_int32(L_var3, mul_16by16_to_int32(var1, var2));
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : amr_wb_round
+
+ Round the lower 16 bits of the 32 bit input number into the MS 16 bits
+ with saturation. Shift the resulting bits right by 16 and return the 16
+ bit number:
+ round(L_var1) = extract_h(L_add(L_var1,32768))
+
+ Inputs :
+ L_var1
+ 32 bit long signed integer (int32 ) whose value falls in the
+ range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ Return Value :
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+
+ ----------------------------------------------------------------------------*/
+ __inline int16 amr_wb_round(int32 L_var1)
+ {
+ if (L_var1 <= (MAX_32 - 0x00008000L))
+ {
+ L_var1 += 0x00008000L;
+ }
+ return ((int16)(L_var1 >> 16));
+ }
+
+
+ /*----------------------------------------------------------------------------
+
+ Function Name : amr_wb_shl1_round
+
+ Shift the 32 bit input number to the left by 1, round up the result and
+ shift down by 16
+ amr_wb_shl1_round(L_var1) = round(L_shl(L_var1,1))
+
+ Inputs :
+ L_var1
+ 32 bit long signed integer (int32 ) whose value falls in the
+ range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
+
+ Return Value :
+ 16 bit short signed integer (int16) whose value falls in the
+ range : 0xffff 8000 <= var_out <= 0x0000 7fff.
+
+ ----------------------------------------------------------------------------*/
+ __inline int16 amr_wb_shl1_round(int32 L_var1)
+ {
+ int16 var_out;
+
+ if ((L_var1 << 1) >> 1 == L_var1)
+ {
+ var_out = (int16)((L_var1 + 0x00004000) >> 15);
+ }
+ else
+ {
+ var_out = (int16)(((L_var1 >> 31) ^ MAX_32) >> 16);
+ }
+
+ return (var_out);
+ }
+
+ /*----------------------------------------------------------------------------
+ Function Name : mul_32by16
+
+ Multiply a 16 bit integer by a 32 bit (DPF). The result is divided
+ by 2^15
+
+ L_32 = (hi1*lo2)<<1 + ((lo1*lo2)>>15)<<1
+
+ Inputs :
+
+ hi hi part of 32 bit number.
+ lo lo part of 32 bit number.
+ n 16 bit number.
+
+ ----------------------------------------------------------------------------*/
+
+
+ __inline int32 mul_32by16(int16 hi, int16 lo, int16 n)
+ {
+ return (((((int32)hi*n)) + ((((int32)lo*n) >> 15))) << 1);
+ }
+
+ __inline int32 fxp_mac_16by16(int16 var1, int16 var2, int32 L_add)
+ {
+
+ int32 l_orig = L_add;
+ if (__builtin_add_overflow( (int32)var1 * var2, l_orig, &L_add)) {
+ // needs saturation
+ if (l_orig > 0) L_add = MAX_32;
+ else L_add = MIN_32;
+ }
+
+ return L_add;
+ }
+
+ __inline int32 fxp_mul_16by16(int16 var1, const int16 var2)
+ {
+ int32 L_mul = (int32)var1 * var2;
+
+ return L_mul;
+ }
+
+ __inline int32 fxp_mul32_by_16b(int32 L_var1, const int32 L_var2)
+ {
+
+ int32 L_mul = (int32)(((int64)L_var1 * (L_var2 << 16)) >> 32);
+
+ return L_mul;
+ }
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif /* PVAMRWBDECODER_BASIC_OP_CEQUIVALENT_H */
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_gcc_armv5.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_gcc_armv5.h
new file mode 100644
index 0000000..741b584
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder_basic_op_gcc_armv5.h
@@ -0,0 +1,319 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./src/pvamrwbdecoder_basic_op_gcc_armv5.h
+
+ Date: 05/07/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PVAMRWBDECODER_BASIC_OP_GCC_ARMV5_H
+#define PVAMRWBDECODER_BASIC_OP_GCC_ARMV5_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#if (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
+
+ static inline int16 sub_int16(int16 var1, int16 var2)
+ {
+ register int32 L_var_out;
+ register int32 L_var_aux;
+ register int32 ra = (int32)var1;
+ register int32 rb = (int32)var2;
+
+ asm volatile(
+ "mov %0, %2, lsl #16\n"
+ "mov %1, %3, lsl #16\n"
+ "qsub %0, %0, %1\n"
+ "mov %0, %0, asr #16"
+ : "=&r*i"(L_var_out),
+ "=&r*i"(L_var_aux)
+ : "r"(ra),
+ "r"(rb));
+
+ return (int16)L_var_out;
+
+ }
+
+ static inline int16 add_int16(int16 var1, int16 var2)
+{
+ register int32 L_var_out;
+ register int32 L_var_aux;
+ register int32 ra = (int32)var1;
+ register int32 rb = (int32)var2;
+
+ asm volatile(
+ "mov %0, %2, lsl #16\n"
+ "mov %1, %3, lsl #16\n"
+ "qadd %0, %0, %1\n"
+ "mov %0, %0, asr #16"
+ : "=&r*i"(L_var_out),
+ "=&r*i"(L_var_aux)
+ : "r"(ra),
+ "r"(rb));
+
+ return (int16)L_var_out;
+
+ }
+
+ static inline int32 mul_32by16(int16 hi, int16 lo, int16 n)
+{
+ register int32 H_32;
+ register int32 L_32;
+ register int32 ra = (int32)hi;
+ register int32 rb = (int32)lo;
+ register int32 rc = (int32)n;
+
+
+ asm volatile(
+ "smulbb %0, %2, %4\n"
+ "smulbb %1, %3, %4\n"
+ "add %0, %0, %1, asr #15\n"
+ "qadd %0, %0, %0"
+ : "=&r*i"(H_32),
+ "=&r*i"(L_32)
+ : "r"(ra),
+ "r"(rb),
+ "r"(rc));
+
+ return H_32;
+ }
+
+
+ static inline int32 sub_int32(int32 L_var1, int32 L_var2)
+{
+ register int32 L_var_out;
+ register int32 ra = L_var1;
+ register int32 rb = L_var2;
+
+ asm volatile(
+ "qsub %0, %1, %2"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb));
+
+ return L_var_out;
+ }
+
+ static inline int32 add_int32(int32 L_var1, int32 L_var2)
+{
+ register int32 L_var_out;
+ register int32 ra = L_var1;
+ register int32 rb = L_var2;
+
+ asm volatile(
+ "qadd %0, %1, %2"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb));
+
+ return L_var_out;
+ }
+
+ static inline int32 msu_16by16_from_int32(int32 L_var3, int16 var1, int16 var2)
+{
+ register int32 L_var_out;
+ register int32 ra = (int32)var1;
+ register int32 rb = (int32)var2;
+ register int32 rc = L_var3;
+
+ asm volatile(
+ "smulbb %0, %1, %2\n"
+ "qdsub %0, %3, %0"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb),
+ "r"(rc));
+
+ return L_var_out;
+ }
+
+
+ static inline int32 mac_16by16_to_int32(int32 L_var3, int16 var1, int16 var2)
+{
+ register int32 L_var_out;
+ register int32 ra = (int32)var1;
+ register int32 rb = (int32)var2;
+ register int32 rc = L_var3;
+
+ asm volatile(
+ "smulbb %0, %1, %2\n"
+ "qdadd %0, %3, %0"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb),
+ "r"(rc));
+
+ return L_var_out;
+ }
+
+
+ static inline int32 mul_16by16_to_int32(int16 var1, int16 var2)
+{
+ register int32 L_var_out;
+ register int32 ra = (int32)var1;
+ register int32 rb = (int32)var2;
+
+ asm volatile(
+ "smulbb %0, %1, %2\n"
+ "qadd %0, %0, %0"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb));
+
+ return L_var_out;
+ }
+
+
+ static inline int16 mult_int16(int16 var1, int16 var2)
+{
+ register int32 L_var_out;
+ register int32 ra = (int32)var1;
+ register int32 rb = (int32)var2;
+
+ asm volatile(
+ "smulbb %0, %1, %2\n"
+ "mov %0, %0, asr #15"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb));
+
+ return (int16)L_var_out;
+ }
+
+ static inline int16 amr_wb_round(int32 L_var1)
+{
+ register int32 L_var_out;
+ register int32 ra = (int32)L_var1;
+ register int32 rb = (int32)0x00008000L;
+
+ asm volatile(
+ "qadd %0, %1, %2\n"
+ "mov %0, %0, asr #16"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb));
+ return (int16)L_var_out;
+ }
+
+ static inline int16 amr_wb_shl1_round(int32 L_var1)
+{
+ register int32 L_var_out;
+ register int32 ra = (int32)L_var1;
+ register int32 rb = (int32)0x00008000L;
+
+ asm volatile(
+ "qadd %0, %1, %1\n"
+ "qadd %0, %0, %2\n"
+ "mov %0, %0, asr #16"
+ : "=&r*i"(L_var_out)
+ : "r"(ra),
+ "r"(rb));
+ return (int16)L_var_out;
+ }
+
+
+ static inline int32 fxp_mac_16by16(const int16 L_var1, const int16 L_var2, int32 L_add)
+{
+ register int32 tmp;
+ register int32 ra = (int32)L_var1;
+ register int32 rb = (int32)L_var2;
+ register int32 rc = (int32)L_add;
+
+ asm volatile(
+ "smlabb %0, %1, %2, %3"
+ : "=&r*i"(tmp)
+ : "r"(ra),
+ "r"(rb),
+ "r"(rc));
+ return (tmp);
+ }
+
+ static inline int32 fxp_mul_16by16bb(int16 L_var1, const int16 L_var2)
+{
+ register int32 tmp;
+ register int32 ra = (int32)L_var1;
+ register int32 rb = (int32)L_var2;
+
+ asm volatile(
+ "smulbb %0, %1, %2"
+ : "=&r*i"(tmp)
+ : "r"(ra),
+ "r"(rb));
+ return (tmp);
+ }
+
+
+#define fxp_mul_16by16(a, b) fxp_mul_16by16bb( a, b)
+
+
+ static inline int32 fxp_mul32_by_16(int32 L_var1, const int32 L_var2)
+{
+ register int32 tmp;
+ register int32 ra = (int32)L_var1;
+ register int32 rb = (int32)L_var2;
+
+ asm volatile(
+ "smulwb %0, %1, %2"
+ : "=&r*i"(tmp)
+ : "r"(ra),
+ "r"(rb));
+ return (tmp);
+ }
+
+#define fxp_mul32_by_16b( a, b) fxp_mul32_by_16( a, b)
+
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+#endif /* PVAMRWBDECODER_BASIC_OP_GCC_ARMV5_H */
+
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder_cnst.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder_cnst.h
new file mode 100644
index 0000000..3981ce3
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder_cnst.h
@@ -0,0 +1,142 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+ Name: pvamrwbdecoder_cnst.h
+
+ Date: 05/02/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ Main header file for the Packet Video AMR Wide Band decoder library. The
+ constants, structures, and functions defined within this file, along with
+ a basic data types header file, is all that is needed to use and communicate
+ with the library. The internal data structures within the library are
+ purposely hidden.
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ (Normally header files do not have a reference section)
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+
+#ifndef PVAMRWBDECODER_CNST_H
+#define PVAMRWBDECODER_CNST_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+#define L_FRAME 256 /* Frame size */
+#define L_SUBFR16k 80 /* Subframe size at 16kHz */
+
+#define L_SUBFR 64 /* Subframe size */
+#define NB_SUBFR 4 /* Number of subframe per frame */
+
+#define L_NEXT 64 /* Overhead in LP analysis */
+#define L_WINDOW 384 /* window size in LP analysis */
+#define L_TOTAL 384 /* Total size of speech buffer. */
+#define M 16 /* Order of LP filter */
+#define M16k 20
+
+#define L_FILT16k 15 /* Delay of down-sampling filter */
+#define L_FILT 12 /* Delay of up-sampling filter */
+
+#define GP_CLIP 15565 /* Pitch gain clipping = 0.95 Q14 */
+#define PIT_SHARP 27853 /* pitch sharpening factor = 0.85 Q15 */
+
+#define PIT_MIN 34 /* Minimum pitch lag with resolution 1/4 */
+#define PIT_FR2 128 /* Minimum pitch lag with resolution 1/2 */
+#define PIT_FR1_9b 160 /* Minimum pitch lag with resolution 1 */
+#define PIT_FR1_8b 92 /* Minimum pitch lag with resolution 1 */
+#define PIT_MAX 231 /* Maximum pitch lag */
+#define L_INTERPOL (16+1) /* Length of filter for interpolation */
+
+#define OPL_DECIM 2 /* Decimation in open-loop pitch analysis */
+
+#define PREEMPH_FAC 22282 /* preemphasis factor (0.68 in Q15) */
+#define GAMMA1 30147 /* Weighting factor (numerator) (0.92 in Q15) */
+#define TILT_FAC 22282 /* tilt factor (denominator) (0.68 in Q15) */
+
+#define Q_MAX 8 /* scaling max for signal (see syn_filt_32) */
+
+#define RANDOM_INITSEED 21845 /* own random init value */
+
+#define L_MEANBUF 3
+#define ONE_PER_MEANBUF 10923
+
+#define MODE_7k 0
+#define MODE_9k 1
+#define MODE_12k 2
+#define MODE_14k 3
+#define MODE_16k 4
+#define MODE_18k 5
+#define MODE_20k 6
+#define MODE_23k 7
+#define MODE_24k 8
+#define MRDTX 9
+//#define NUM_OF_MODES 10 /* see bits.h for bits definition */
+
+#define EHF_MASK (int16)0x0008 /* homing frame pattern */
+
+#define BIT_0 ((int16)-127)
+#define BIT_1 (int16)127
+#define BIT_0_ITU (int16)0x007F
+#define BIT_1_ITU (int16)0x0081
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
diff --git a/media/codecs/amrwb/dec/src/pvamrwbdecoder_mem_funcs.h b/media/codecs/amrwb/dec/src/pvamrwbdecoder_mem_funcs.h
new file mode 100644
index 0000000..e348916
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/pvamrwbdecoder_mem_funcs.h
@@ -0,0 +1,67 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: pvamrwbdecoder_mem_funcs.h
+ Funtions:
+
+
+ Date: 05/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+------------------------------------------------------------------------------
+
+
+----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+
+#ifndef PVAMRWBDECODER_MEM_FUNCS_H
+#define PVAMRWBDECODER_MEM_FUNCS_H
+
+#include <string.h>
+
+
+#define pv_memset(to, c, n) memset(to, c, n)
+
+
+#define pv_memcpy(to, from, n) memcpy(to, from, n)
+#define pv_memmove(to, from, n) memmove(to, from, n)
+#define pv_memcmp(p, q, n) memcmp(p, q, n)
+
+
+
+#endif
diff --git a/media/codecs/amrwb/dec/src/q_gain2_tab.cpp b/media/codecs/amrwb/dec/src/q_gain2_tab.cpp
new file mode 100644
index 0000000..92c235f
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/q_gain2_tab.cpp
@@ -0,0 +1,244 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+#include "qisf_ns.h"
+
+
+/*
+ * Tables for function q_gain2()
+ *
+ * g_pitch(Q14), g_code(Q11)
+ *
+ * pitch gain are ordered in table to reduce complexity
+ * during quantization of gains.
+ */
+
+
+
+
+const int16 t_qua_gain6b[NB_QUA_GAIN6B*2] =
+{
+ 1566, 1332,
+ 1577, 3557,
+ 3071, 6490,
+ 4193, 10163,
+ 4496, 2534,
+ 5019, 4488,
+ 5586, 15614,
+ 5725, 1422,
+ 6453, 580,
+ 6724, 6831,
+ 7657, 3527,
+ 8072, 2099,
+ 8232, 5319,
+ 8827, 8775,
+ 9740, 2868,
+ 9856, 1465,
+ 10087, 12488,
+ 10241, 4453,
+ 10859, 6618,
+ 11321, 3587,
+ 11417, 1800,
+ 11643, 2428,
+ 11718, 988,
+ 12312, 5093,
+ 12523, 8413,
+ 12574, 26214,
+ 12601, 3396,
+ 13172, 1623,
+ 13285, 2423,
+ 13418, 6087,
+ 13459, 12810,
+ 13656, 3607,
+ 14111, 4521,
+ 14144, 1229,
+ 14425, 1871,
+ 14431, 7234,
+ 14445, 2834,
+ 14628, 10036,
+ 14860, 17496,
+ 15161, 3629,
+ 15209, 5819,
+ 15299, 2256,
+ 15518, 4722,
+ 15663, 1060,
+ 15759, 7972,
+ 15939, 11964,
+ 16020, 2996,
+ 16086, 1707,
+ 16521, 4254,
+ 16576, 6224,
+ 16894, 2380,
+ 16906, 681,
+ 17213, 8406,
+ 17610, 3418,
+ 17895, 5269,
+ 18168, 11748,
+ 18230, 1575,
+ 18607, 32767,
+ 18728, 21684,
+ 19137, 2543,
+ 19422, 6577,
+ 19446, 4097,
+ 19450, 9056,
+ 20371, 14885
+};
+
+const int16 t_qua_gain7b[NB_QUA_GAIN7B*2] =
+{
+ 204, 441,
+ 464, 1977,
+ 869, 1077,
+ 1072, 3062,
+ 1281, 4759,
+ 1647, 1539,
+ 1845, 7020,
+ 1853, 634,
+ 1995, 2336,
+ 2351, 15400,
+ 2661, 1165,
+ 2702, 3900,
+ 2710, 10133,
+ 3195, 1752,
+ 3498, 2624,
+ 3663, 849,
+ 3984, 5697,
+ 4214, 3399,
+ 4415, 1304,
+ 4695, 2056,
+ 5376, 4558,
+ 5386, 676,
+ 5518, 23554,
+ 5567, 7794,
+ 5644, 3061,
+ 5672, 1513,
+ 5957, 2338,
+ 6533, 1060,
+ 6804, 5998,
+ 6820, 1767,
+ 6937, 3837,
+ 7277, 414,
+ 7305, 2665,
+ 7466, 11304,
+ 7942, 794,
+ 8007, 1982,
+ 8007, 1366,
+ 8326, 3105,
+ 8336, 4810,
+ 8708, 7954,
+ 8989, 2279,
+ 9031, 1055,
+ 9247, 3568,
+ 9283, 1631,
+ 9654, 6311,
+ 9811, 2605,
+ 10120, 683,
+ 10143, 4179,
+ 10245, 1946,
+ 10335, 1218,
+ 10468, 9960,
+ 10651, 3000,
+ 10951, 1530,
+ 10969, 5290,
+ 11203, 2305,
+ 11325, 3562,
+ 11771, 6754,
+ 11839, 1849,
+ 11941, 4495,
+ 11954, 1298,
+ 11975, 15223,
+ 11977, 883,
+ 11986, 2842,
+ 12438, 2141,
+ 12593, 3665,
+ 12636, 8367,
+ 12658, 1594,
+ 12886, 2628,
+ 12984, 4942,
+ 13146, 1115,
+ 13224, 524,
+ 13341, 3163,
+ 13399, 1923,
+ 13549, 5961,
+ 13606, 1401,
+ 13655, 2399,
+ 13782, 3909,
+ 13868, 10923,
+ 14226, 1723,
+ 14232, 2939,
+ 14278, 7528,
+ 14439, 4598,
+ 14451, 984,
+ 14458, 2265,
+ 14792, 1403,
+ 14818, 3445,
+ 14899, 5709,
+ 15017, 15362,
+ 15048, 1946,
+ 15069, 2655,
+ 15405, 9591,
+ 15405, 4079,
+ 15570, 7183,
+ 15687, 2286,
+ 15691, 1624,
+ 15699, 3068,
+ 15772, 5149,
+ 15868, 1205,
+ 15970, 696,
+ 16249, 3584,
+ 16338, 1917,
+ 16424, 2560,
+ 16483, 4438,
+ 16529, 6410,
+ 16620, 11966,
+ 16839, 8780,
+ 17030, 3050,
+ 17033, 18325,
+ 17092, 1568,
+ 17123, 5197,
+ 17351, 2113,
+ 17374, 980,
+ 17566, 26214,
+ 17609, 3912,
+ 17639, 32767,
+ 18151, 7871,
+ 18197, 2516,
+ 18202, 5649,
+ 18679, 3283,
+ 18930, 1370,
+ 19271, 13757,
+ 19317, 4120,
+ 19460, 1973,
+ 19654, 10018,
+ 19764, 6792,
+ 19912, 5135,
+ 20040, 2841,
+ 21234, 19833
+};
+
+
diff --git a/media/codecs/amrwb/dec/src/q_pulse.h b/media/codecs/amrwb/dec/src/q_pulse.h
new file mode 100644
index 0000000..0ac52b3
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/q_pulse.h
@@ -0,0 +1,79 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/q_pulse.h
+
+ Date: 01/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ Coding and decoding of algebraic codebook
+------------------------------------------------------------------------------
+*/
+
+#ifndef Q_PULSE_H
+#define Q_PULSE_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ void dec_1p_N1(int32 index, int16 N, int16 offset, int16 pos[]);
+ void dec_2p_2N1(int32 index, int16 N, int16 offset, int16 pos[]);
+ void dec_3p_3N1(int32 index, int16 N, int16 offset, int16 pos[]);
+ void dec_4p_4N1(int32 index, int16 N, int16 offset, int16 pos[]);
+ void dec_4p_4N(int32 index, int16 N, int16 offset, int16 pos[]);
+ void dec_5p_5N(int32 index, int16 N, int16 offset, int16 pos[]);
+ void dec_6p_6N_2(int32 index, int16 N, int16 offset, int16 pos[]);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* Q_PULSE_H */
diff --git a/media/codecs/amrwb/dec/src/qisf_ns.cpp b/media/codecs/amrwb/dec/src/qisf_ns.cpp
new file mode 100644
index 0000000..07e342b
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/qisf_ns.cpp
@@ -0,0 +1,145 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: qisf_ns.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 indice[] : indices of the selected codebook entries
+ int16 isf[] : quantized ISFs (in frequency domain)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Coding/Decoding of ISF parameters for background noise.
+
+ The ISF vector is quantized using VQ with split-by-5
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "qisf_ns.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Disf_ns(
+ int16 * indice, /* input: quantization indices */
+ int16 * isf_q /* input: ISF in the frequency domain (0..0.5)*/
+)
+{
+ int16 i;
+
+ isf_q[0] = dico1_isf_noise[(indice[0] << 1)];
+ isf_q[1] = dico1_isf_noise[(indice[0] << 1) + 1];
+
+ for (i = 0; i < 3; i++)
+ {
+ isf_q[i + 2] = dico2_isf_noise[(indice[1] << 1) + indice[1] + i];
+ isf_q[i + 5] = dico3_isf_noise[(indice[2] << 1) + indice[2] + i];
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ isf_q[i + 8] = dico4_isf_noise[(indice[3] << 2) + i];
+ isf_q[i + 12] = dico5_isf_noise[(indice[4] << 2) + i];
+ }
+
+ for (i = 0; i < ORDER; i++)
+ {
+ isf_q[i] = add_int16(isf_q[i], mean_isf_noise[i]);
+ }
+
+ Reorder_isf(isf_q, ISF_GAP, ORDER);
+
+}
diff --git a/media/codecs/amrwb/dec/src/qisf_ns.h b/media/codecs/amrwb/dec/src/qisf_ns.h
new file mode 100644
index 0000000..4e9f67e
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/qisf_ns.h
@@ -0,0 +1,113 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/qisf_ns.h
+
+ Date: 01/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef QISF_NS_H
+#define QISF_NS_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; DEFINES
+----------------------------------------------------------------------------*/
+
+
+#define ORDER 16 /* order of linear prediction filter */
+#define ISF_GAP 128
+
+#define SIZE_BK_NOISE1 64
+#define SIZE_BK_NOISE2 64
+#define SIZE_BK_NOISE3 64
+#define SIZE_BK_NOISE4 32
+#define SIZE_BK_NOISE5 32
+
+#define NB_QUA_GAIN6B 64 /* Number of quantization level */
+#define NB_QUA_GAIN7B 128 /* Number of quantization level */
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+extern const int16 mean_isf_noise[ORDER];
+extern const int16 dico1_isf_noise[SIZE_BK_NOISE1*2];
+extern const int16 dico2_isf_noise[SIZE_BK_NOISE2*3];
+extern const int16 dico3_isf_noise[SIZE_BK_NOISE3*3];
+extern const int16 dico4_isf_noise[SIZE_BK_NOISE4*4];
+extern const int16 dico5_isf_noise[SIZE_BK_NOISE5*4];
+
+extern const int16 t_qua_gain6b[NB_QUA_GAIN6B*2];
+extern const int16 t_qua_gain7b[NB_QUA_GAIN7B*2];
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+#endif /* QISF_NS_H */
diff --git a/media/codecs/amrwb/dec/src/qisf_ns_tab.cpp b/media/codecs/amrwb/dec/src/qisf_ns_tab.cpp
new file mode 100644
index 0000000..e5630e8
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/qisf_ns_tab.cpp
@@ -0,0 +1,367 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+ * qisf_ns_tab.cpp
+ *
+ * Quantization tables for split by 5 VQ of ISFs for a background
+ * noise database
+ * Version whith no prediction
+ */
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "qisf_ns.h"
+
+
+/* means of ISFs */
+const int16 mean_isf_noise[ORDER] =
+{
+
+ 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240,
+ 8229, 9153, 10098, 11108, 12144, 13184, 14165, 3803
+};
+
+
+/* 28 bits */
+/*
+ * isf codebooks: split-by-5 VQ
+ *
+ * codebook vector dimension number of vectors
+ * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
+ * 1 2 64
+ * 2 3 64
+ * 3 3 64
+ * 4 4 32
+ * 5 4 32
+ */
+
+/*
+ * 1st split: isf0 to isf1
+ */
+
+
+const int16 dico1_isf_noise[SIZE_BK_NOISE1*2] =
+{
+
+ -269, -673,
+ -222, -537,
+ -233, -430,
+ -138, -451,
+ -212, -331,
+ -192, -241,
+ -87, -231,
+ -191, -128,
+ -70, -106,
+ -164, -6,
+ 74, -179,
+ 27, -33,
+ -102, 74,
+ -162, 115,
+ -94, 172,
+ -6, 130,
+ -143, 234,
+ 14, 218,
+ -65, 270,
+ 88, 182,
+ -124, 341,
+ -44, 381,
+ 38, 335,
+ 117, 274,
+ -112, 454,
+ 74, 431,
+ -5, 488,
+ 175, 384,
+ -83, 561,
+ 122, 529,
+ 21, 601,
+ 229, 481,
+ 231, 303,
+ 226, 608,
+ 300, 372,
+ 210, 187,
+ 306, 265,
+ 328, 473,
+ 382, 331,
+ 371, 132,
+ 139, 58,
+ 365, 21,
+ 250, -82,
+ 443, 218,
+ 483, 110,
+ 426, 415,
+ 579, 222,
+ 518, 333,
+ 573, 448,
+ 455, 529,
+ 685, 329,
+ 332, 580,
+ 595, 593,
+ 468, 645,
+ 762, 517,
+ 326, 709,
+ 485, 793,
+ 130, 684,
+ 671, 737,
+ 354, 876,
+ 88, 806,
+ -65, 706,
+ -35, 1016,
+ 266, 1123
+};
+
+
+/*
+ * 2nd split: isf2 to isf4
+ */
+
+const int16 dico2_isf_noise[SIZE_BK_NOISE2*3] =
+{
+
+ -824, -884, -949,
+ -805, -456, -418,
+ -442, -438, -541,
+ -217, -578, -793,
+ -168, -444, -582,
+ -287, -492, -274,
+ -552, -297, -300,
+ -163, -333, -358,
+ -370, -232, -232,
+ -175, -358, -159,
+ -381, -21, -357,
+ -184, -159, -162,
+ -53, -191, -280,
+ 18, -267, -215,
+ -138, 61, -283,
+ 71, -95, -294,
+ 13, -156, -546,
+ 0, -83, -79,
+ 44, 97, -316,
+ 178, -52, -213,
+ 222, -261, -422,
+ 237, -118, -44,
+ 141, 145, -132,
+ 363, 81, -287,
+ 213, 65, 34,
+ -107, 94, -5,
+ 91, -29, 126,
+ -355, 51, -41,
+ -219, -76, 145,
+ -63, 100, 244,
+ -719, 44, 27,
+ -572, -124, 155,
+ -423, 133, 315,
+ -917, 71, 224,
+ -268, 318, 131,
+ -93, -190, 420,
+ -97, 122, 491,
+ -79, 317, 355,
+ 130, 100, 325,
+ 86, -293, 210,
+ 133, 258, 161,
+ 176, -73, 465,
+ 195, 300, 384,
+ 348, 22, 221,
+ 376, 183, 409,
+ 377, 286, 202,
+ 242, 213, 659,
+ 257, 565, 248,
+ 344, 408, -76,
+ 405, 440, 509,
+ 612, 385, 379,
+ 536, 607, 216,
+ -56, 582, 192,
+ 100, 517, 567,
+ -365, 448, 445,
+ 728, 347, 10,
+ 505, 357, 759,
+ 636, 582, 658,
+ 335, 517, 852,
+ 378, 809, 572,
+ -195, 878, 829,
+ 529, 707, 987,
+ 918, 726, 392,
+ 1250, 997, 1063
+};
+
+/*
+ * 3rd split: isf5 to isf7
+ */
+
+const int16 dico3_isf_noise[SIZE_BK_NOISE3*3] =
+{
+
+ -805, -838, -774,
+ -522, -627, -828,
+ -477, -486, -603,
+ -295, -481, -634,
+ -366, -384, -393,
+ -186, -414, -396,
+ -237, -394, -106,
+ -252, -202, -275,
+ -61, -177, -442,
+ -84, -198, -199,
+ -179, -125, -31,
+ -72, -47, -163,
+ -298, -220, 215,
+ -64, -168, 251,
+ -133, 156, -59,
+ -30, -2, 127,
+ 54, 66, -61,
+ -233, 21, 251,
+ 209, -50, 32,
+ 33, 194, 136,
+ -117, -18, 475,
+ 202, 46, 309,
+ 256, 185, 53,
+ 35, 200, 390,
+ 200, 263, 242,
+ -216, 302, 294,
+ 128, 358, 0,
+ 19, 431, 287,
+ 224, 447, 280,
+ 367, 165, 213,
+ 397, 314, 319,
+ 383, 379, 75,
+ 277, 325, 462,
+ 394, 505, 334,
+ 251, 98, -213,
+ 450, 153, 448,
+ 565, 226, 76,
+ 470, 383, 502,
+ 635, 390, 278,
+ 237, 135, 620,
+ 342, 401, 649,
+ 331, 551, 518,
+ 130, 418, 592,
+ 531, 306, 737,
+ 729, 389, 580,
+ 497, 557, 699,
+ 296, 383, 874,
+ 283, 624, 759,
+ 126, 622, 476,
+ 559, 595, 472,
+ 382, 770, 616,
+ 719, 613, 745,
+ 540, 639, 928,
+ 517, 826, 801,
+ 684, 811, 604,
+ 752, 786, 857,
+ 933, 661, 350,
+ 694, 450, 1061,
+ 562, 911, 1051,
+ 824, 813, 1104,
+ 758, 1047, 882,
+ 1140, 917, 889,
+ 1039, 1246, 1426,
+ 1483, 1666, 1876
+};
+
+/*
+ * 4th split: isf8 to isf11
+ */
+
+const int16 dico4_isf_noise[SIZE_BK_NOISE4*4] =
+{
+
+ -776, -854, -891, -920,
+ -552, -610, -663, -741,
+ -321, -370, -476, -565,
+ 274, -160, -456, 201,
+ 265, 67, -160, -306,
+ -8, -210, 79, 272,
+ 163, 236, 307, 308,
+ 578, 317, 64, 298,
+ -9, 197, 342, 620,
+ 343, 232, 314, 622,
+ 173, 149, 548, 527,
+ 356, 370, 481, 376,
+ 135, 444, 488, 556,
+ 391, 471, 487, 653,
+ 228, 424, 576, 835,
+ 422, 372, 722, 682,
+ 295, 673, 693, 635,
+ 539, 596, 590, 449,
+ 475, 618, 659, 818,
+ 735, 517, 491, 673,
+ 602, 346, 257, 877,
+ 625, 635, 849, 720,
+ 727, 818, 698, 595,
+ 653, 481, 690, 1139,
+ 814, 762, 704, 908,
+ 507, 747, 898, 936,
+ 848, 855, 924, 785,
+ 646, 1037, 882, 795,
+ 772, 845, 1024, 1151,
+ 1133, 983, 818, 921,
+ 940, 1068, 1252, 1302,
+ 1588, 1767, 1718, 1513
+};
+
+/*
+ * 5th split: isf12 to isf15
+ */
+
+const int16 dico5_isf_noise[SIZE_BK_NOISE5*4] =
+{
+ -810, -879, -945, -254,
+ 248, 184, 671, 128,
+ 288, 703, 918, 99,
+ 658, 558, 662, 219,
+ 552, 585, 910, 208,
+ 559, 804, 759, 119,
+ 606, 774, 921, -139,
+ 782, 761, 748, 208,
+ 756, 708, 983, 56,
+ 544, 864, 1010, 152,
+ 737, 698, 987, 299,
+ 771, 924, 879, 103,
+ 536, 785, 961, 405,
+ 667, 916, 801, 328,
+ 738, 705, 773, 439,
+ 823, 871, 992, 355,
+ 640, 1004, 1052, 369,
+ 724, 822, 949, 597,
+ 415, 655, 729, 482,
+ 1009, 896, 793, 363,
+ 908, 803, 687, -25,
+ 1016, 838, 1011, 189,
+ 947, 1112, 942, 222,
+ 914, 1049, 981, 527,
+ 956, 987, 1011, -120,
+ 781, 1049, 1121, 92,
+ 1178, 1053, 884, 47,
+ 1123, 1059, 1182, 118,
+ 933, 972, 1277, 357,
+ 1109, 918, 1101, 503,
+ 1039, 1286, 1220, 317,
+ 1351, 1207, 1010, 326
+};
+
diff --git a/media/codecs/amrwb/dec/src/qpisf_2s.cpp b/media/codecs/amrwb/dec/src/qpisf_2s.cpp
new file mode 100644
index 0000000..0d465c6
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/qpisf_2s.cpp
@@ -0,0 +1,350 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: qpisf_2s.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 * seed seed for the random ng
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Coding/Decoding of ISF parameters with prediction.
+
+ The ISF vector is quantized using two-stage VQ with split-by-2
+ in 1st stage and split-by-5 (or 3)in the second stage.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+#include "qisf_ns.h"
+#include "qpisf_2s.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define MU 10923 /* Prediction factor (1.0/3.0) in Q15 */
+#define N_SURV_MAX 4 /* 4 survivors max */
+#define ALPHA 29491 /* 0. 9 in Q15 */
+#define ONE_ALPHA (32768-ALPHA) /* (1.0 - ALPHA) in Q15 */
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------*
+ * routine: Disf_2s_46b() *
+ * ~~~~~~~~~ *
+ * Decoding of ISF parameters *
+ *-------------------------------------------------------------------*/
+
+void Dpisf_2s_46b(
+ int16 * indice, /* input: quantization indices */
+ int16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ int16 * past_isfq,/* i/0 : past ISF quantizer */
+ int16 * isfold, /* input : past quantized ISF */
+ int16 * isf_buf, /* input : isf buffer */
+ int16 bfi, /* input : Bad frame indicator */
+ int16 enc_dec
+)
+{
+ int16 ref_isf[M];
+ int16 i, j, tmp;
+ int32 L_tmp;
+
+
+ if (bfi == 0) /* Good frame */
+ {
+ for (i = 0; i < 9; i++)
+ {
+ isf_q[i] = dico1_isf[(indice[0] << 3) + indice[0] + i];
+ }
+ for (i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = dico2_isf[(indice[1] << 3) - indice[1] + i];
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ isf_q[i] += dico21_isf[indice[2] * 3 + i];
+ isf_q[i + 3] += dico22_isf[indice[3] * 3 + i];
+ isf_q[i + 6] += dico23_isf[indice[4] * 3 + i];
+ isf_q[i + 9] += dico24_isf[indice[5] * 3 + i];
+ isf_q[i + 12] += dico25_isf[(indice[6] << 2) + i];
+ }
+
+ isf_q[i + 12] += dico25_isf[(indice[6] << 2) + i];
+
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = isf_q[i];
+ isf_q[i] += mean_isf[i];
+ isf_q[i] += ((int32)MU * past_isfq[i]) >> 15;
+ past_isfq[i] = tmp;
+ }
+
+
+ if (enc_dec)
+ {
+ for (i = 0; i < M; i++)
+ {
+ for (j = (L_MEANBUF - 1); j > 0; j--)
+ {
+ isf_buf[j * M + i] = isf_buf[(j - 1) * M + i];
+ }
+ isf_buf[i] = isf_q[i];
+ }
+ }
+ }
+ else
+ { /* bad frame */
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = mul_16by16_to_int32(mean_isf[i], 8192);
+ for (j = 0; j < L_MEANBUF; j++)
+ {
+ L_tmp = mac_16by16_to_int32(L_tmp, isf_buf[j * M + i], 8192);
+ }
+ ref_isf[i] = amr_wb_round(L_tmp);
+ }
+
+ /* use the past ISFs slightly shifted towards their mean */
+ for (i = 0; i < ORDER; i++)
+ {
+ isf_q[i] = add_int16(mult_int16(ALPHA, isfold[i]), mult_int16(ONE_ALPHA, ref_isf[i]));
+ }
+
+ /* estimate past quantized residual to be used in next frame */
+
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = add_int16(ref_isf[i], mult_int16(past_isfq[i], MU)); /* predicted ISF */
+ past_isfq[i] = sub_int16(isf_q[i], tmp);
+ past_isfq[i] >>= 1; /* past_isfq[i] *= 0.5 */
+ }
+
+ }
+
+ Reorder_isf(isf_q, ISF_GAP, ORDER);
+}
+
+/*
+ * routine: Disf_2s_36b()
+ * ~~~~~~~~~
+ * Decoding of ISF parameters
+ */
+
+void Dpisf_2s_36b(
+ int16 * indice, /* input: quantization indices */
+ int16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ int16 * past_isfq, /* i/0 : past ISF quantizer */
+ int16 * isfold, /* input : past quantized ISF */
+ int16 * isf_buf, /* input : isf buffer */
+ int16 bfi, /* input : Bad frame indicator */
+ int16 enc_dec
+)
+{
+ int16 ref_isf[M];
+ int16 i, j, tmp;
+ int32 L_tmp;
+
+
+ if (bfi == 0) /* Good frame */
+ {
+ for (i = 0; i < 9; i++)
+ {
+ isf_q[i] = dico1_isf[indice[0] * 9 + i];
+ }
+ for (i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = add_int16(dico2_isf[indice[1] * 7 + i], dico23_isf_36b[indice[4] * 7 + i]);
+ }
+
+ for (i = 0; i < 5; i++)
+ {
+ isf_q[i] = add_int16(isf_q[i], dico21_isf_36b[indice[2] * 5 + i]);
+ }
+ for (i = 0; i < 4; i++)
+ {
+ isf_q[i + 5] = add_int16(isf_q[i + 5], dico22_isf_36b[(indice[3] << 2) + i]);
+ }
+
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = isf_q[i];
+ isf_q[i] = add_int16(tmp, mean_isf[i]);
+ isf_q[i] = add_int16(isf_q[i], mult_int16(MU, past_isfq[i]));
+ past_isfq[i] = tmp;
+ }
+
+
+ if (enc_dec)
+ {
+ for (i = 0; i < M; i++)
+ {
+ for (j = (L_MEANBUF - 1); j > 0; j--)
+ {
+ isf_buf[j * M + i] = isf_buf[(j - 1) * M + i];
+ }
+ isf_buf[i] = isf_q[i];
+ }
+ }
+ }
+ else
+ { /* bad frame */
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = mul_16by16_to_int32(mean_isf[i], 8192);
+ for (j = 0; j < L_MEANBUF; j++)
+ {
+ L_tmp = mac_16by16_to_int32(L_tmp, isf_buf[j * M + i], 8192);
+ }
+
+ ref_isf[i] = amr_wb_round(L_tmp);
+ }
+
+ /* use the past ISFs slightly shifted towards their mean */
+ for (i = 0; i < ORDER; i++)
+ {
+ isf_q[i] = add_int16(mult_int16(ALPHA, isfold[i]), mult_int16(ONE_ALPHA, ref_isf[i]));
+ }
+
+ /* estimate past quantized residual to be used in next frame */
+
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = add_int16(ref_isf[i], mult_int16(past_isfq[i], MU)); /* predicted ISF */
+ past_isfq[i] = sub_int16(isf_q[i], tmp);
+ past_isfq[i] >>= 1; /* past_isfq[i] *= 0.5 */
+ }
+ }
+
+ Reorder_isf(isf_q, ISF_GAP, ORDER);
+
+ return;
+}
+
+/*
+ * procedure Reorder_isf()
+ * ~~~~~~~~~~~~~
+ * To make sure that the isfs are properly order and to keep a certain
+ * minimum distance between consecutive isfs.
+ *
+ * Argument description in/out
+ * ~~~~~~~~ ~~~~~~~~~~~ ~~~~~~
+ * isf[] vector of isfs i/o
+ * min_dist minimum required distance i
+ * n LPC order i
+ */
+
+void Reorder_isf(
+ int16 * isf, /* (i/o) Q15: ISF in the frequency domain (0..0.5) */
+ int16 min_dist, /* (i) Q15 : minimum distance to keep */
+ int16 n /* (i) : number of ISF */
+)
+{
+ int16 i, isf_min;
+
+ isf_min = min_dist;
+
+ for (i = 0; i < n - 1; i++)
+ {
+ if (isf[i] < isf_min)
+ {
+ isf[i] = isf_min;
+ }
+ isf_min = add_int16(isf[i], min_dist);
+ }
+
+ return;
+}
+
diff --git a/media/codecs/amrwb/dec/src/qpisf_2s.h b/media/codecs/amrwb/dec/src/qpisf_2s.h
new file mode 100644
index 0000000..61f8c06
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/qpisf_2s.h
@@ -0,0 +1,117 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/qpisf_2s.h
+
+ Date: 01/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef QPISF_2S_H
+#define QPISF_2S_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "qisf_ns.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+----------------------------------------------------------------------------*/
+
+#define N_SURV 4
+
+#define SIZE_BK1 256
+#define SIZE_BK2 256
+#define SIZE_BK21 64
+#define SIZE_BK22 128
+#define SIZE_BK23 128
+#define SIZE_BK24 32
+#define SIZE_BK25 32
+
+#define SIZE_BK21_36b 128
+#define SIZE_BK22_36b 128
+#define SIZE_BK23_36b 64
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+extern const int16 mean_isf[ORDER];
+extern const int16 dico1_isf[SIZE_BK1*9];
+extern const int16 dico2_isf[SIZE_BK2*7];
+extern const int16 dico21_isf[SIZE_BK21*3];
+extern const int16 dico22_isf[SIZE_BK22*3];
+extern const int16 dico23_isf[SIZE_BK23*3];
+extern const int16 dico24_isf[SIZE_BK24*3];
+extern const int16 dico25_isf[SIZE_BK25*4];
+extern const int16 dico21_isf_36b[SIZE_BK21_36b*5];
+extern const int16 dico22_isf_36b[SIZE_BK22_36b*4];
+extern const int16 dico23_isf_36b[SIZE_BK23_36b*7];
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+#endif /* QPISF_2S_H */
diff --git a/media/codecs/amrwb/dec/src/qpisf_2s_tab.cpp b/media/codecs/amrwb/dec/src/qpisf_2s_tab.cpp
new file mode 100644
index 0000000..d57522e
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/qpisf_2s_tab.cpp
@@ -0,0 +1,1383 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*-------------------------------------------------------------------*
+ * qpisf_2s_tab.cpp
+ *-------------------------------------------------------------------*
+ * Quantization tables for two-stage of ISFs (split by 2 in 1st stage)
+ * Version whith prediction MU = 0.25
+ *-------------------------------------------------------------------*/
+
+#include "qisf_ns.h"
+#include "qpisf_2s.h"
+
+
+
+
+/* means of ISFs */
+const int16 mean_isf[ORDER] =
+{
+
+ 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730,
+ 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037
+};
+
+/* 46 bits */
+/*
+ * isf codebooks: two-stage VQ with split-by-5 in 2nd stage
+ *
+ * codebook vector dimension number of vectors
+ * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
+ * 1_1 9 256
+ * 1_2 7 256
+ * 2_1 3 64
+ * 2_2 3 128
+ * 2_3 3 128
+ * 2_4 3 32
+ * 2_5 4 32
+ */
+
+/*
+ * 1st stage codebook; 1st split: isf0 to isf8
+ */
+
+const int16 dico1_isf[SIZE_BK1*9] =
+{
+
+ 579, 1081, 1035, 390, 3, -263, -198, -82, 38,
+ 18, -68, -12, 313, 761, 405, 249, 111, -76,
+ 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923,
+ -91, 827, 948, 648, 613, 535, 522, 490, 421,
+ 41, -44, -281, -472, 652, 534, 193, 135, -90,
+ 41, -121, -356, -60, 663, 307, 61, -48, -344,
+ 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241,
+ -118, -204, 328, 512, 870, 793, 610, 402, 186,
+ 156, 293, 74, -338, -475, -897, -594, -161, -497,
+ 226, 131, -138, 307, 169, -271, -164, -387, -624,
+ 62, -32, -61, -252, -541, -828, -1027, -523, -662,
+ 102, -61, 141, 112, -270, -251, -541, 25, -150,
+ 6, -132, -356, -686, -96, -322, -522, -31, -326,
+ -36, -209, -521, -229, 307, -132, -5, -99, -384,
+ 60, -51, -237, -668, -973, -407, -708, -75, -172,
+ 26, -138, -266, 111, -302, 43, -278, -356, -359,
+ 570, 822, 496, -154, -312, -92, 137, 279, 371,
+ -146, 368, 409, 68, 6, 77, 167, 202, 162,
+ 633, 898, 996, 756, 662, 683, 783, 909, 996,
+ -103, 294, 607, 415, 483, 462, 480, 431, 408,
+ -120, -338, -612, -524, 584, 331, 92, 433, 276,
+ -178, -293, -154, -41, 269, 100, -9, 213, 160,
+ 830, 736, 278, 820, 1254, 686, 712, 1039, 473,
+ -218, -304, 463, 454, 397, 273, 202, 286, 273,
+ -232, 7, 6, -388, -472, -427, -378, -167, -100,
+ -294, -183, 134, -47, 101, -88, -84, -117, -3,
+ 57, 17, -202, -634, -989, -1119, -533, 176, -36,
+ 120, -28, 23, 111, -319, 318, -22, -77, 266,
+ -271, -464, -434, -658, -640, -385, -385, -99, -69,
+ -198, -259, -266, -44, -39, -139, -137, 171, 66,
+ 9, -145, -377, -846, -1000, -111, -325, 342, 135,
+ -81, -286, -380, 192, -57, 307, 76, -24, -140,
+ 677, 702, 247, 56, 249, 141, -105, -236, -99,
+ 36, -39, -69, 348, 198, -93, 322, 91, -72,
+ 503, 885, 1508, 1307, 1282, 1172, 1119, 1209, 1061,
+ 416, 719, 989, 1227, 1001, 1052, 954, 741, 1044,
+ -127, -376, -657, 139, 623, 223, 501, 306, 220,
+ -113, -384, -796, 504, 438, 85, 213, -83, -194,
+ 585, 1132, 1233, 1091, 1247, 1433, 1512, 1448, 1314,
+ -174, -422, 7, 1155, 1089, 1182, 1003, 945, 806,
+ 8, -126, -317, -103, -351, -695, -98, -268, -537,
+ 33, -103, -290, 167, -39, -407, 44, -208, -375,
+ 104, -23, -64, -291, -637, -851, -1084, -61, -112,
+ -75, -306, -434, 218, -148, -354, -680, -133, -216,
+ -121, -377, -718, -97, -130, -361, -156, -379, -599,
+ -56, -254, -586, 235, 157, -214, 11, -260, -149,
+ -124, -267, -397, -580, -593, -527, -805, -385, 346,
+ -193, -440, -708, -351, -141, -255, -499, -147, -185,
+ 448, 660, 494, 208, 509, 461, 338, 291, 149,
+ -223, 88, 335, 159, 212, 191, 286, 308, 205,
+ -31, 469, 803, 659, 619, 658, 843, 987, 1113,
+ -171, -242, 514, 362, 295, 524, 552, 694, 585,
+ -64, -308, -448, -21, 284, 786, 446, 289, 92,
+ -218, -390, -7, 169, 206, 330, 352, 408, 358,
+ -36, 702, 959, 859, 861, 1115, 1269, 1357, 1305,
+ -133, -341, -65, 678, 417, 440, 486, 518, 780,
+ 33, -44, -191, -344, -461, -755, -201, 217, -31,
+ -353, -547, -44, 123, -61, -68, -79, 29, 60,
+ 73, -57, -406, -766, -1243, -1203, 240, 400, 165,
+ -73, -282, -601, -213, -171, -375, 332, 35, -103,
+ -29, -207, -553, -476, -638, -908, 172, -22, -135,
+ -192, -239, -164, -103, -111, -47, 153, 125, 110,
+ -1, -203, -570, -1030, -1424, -535, 155, 1, 147,
+ -333, -653, -865, -197, -158, -21, -44, 95, 108,
+ 389, 588, 490, 33, -237, -524, -628, -136, -260,
+ 40, -177, -462, 453, 862, 380, 131, -130, -405,
+ 842, 1678, 1841, 1549, 1474, 1256, 1082, 905, 742,
+ 370, 1216, 1768, 1633, 1212, 636, 22, -330, 71,
+ -76, -281, -741, -742, 898, 619, 277, 71, -222,
+ -32, -265, -556, -25, 994, 682, 305, 126, -165,
+ 73, 738, 893, 968, 993, 1768, 2273, 1840, 1391,
+ -69, -349, -585, 234, 1158, 903, 626, 510, 251,
+ -1, -99, -272, -210, -603, -351, -540, -811, -383,
+ -16, -230, -504, 410, 149, -205, -343, -651, -639,
+ 103, -9, -227, -205, -562, -781, -1079, -1208, -156,
+ 143, 63, -135, -67, -317, -602, -784, -1154, -640,
+ -144, -391, -674, -622, -200, -254, -660, -947, -395,
+ -40, -250, -625, 27, 543, 94, -131, -386, -673,
+ -123, -371, -757, -451, -564, -614, -415, -711, -35,
+ -116, -309, -593, -268, 239, -33, -338, -650, -135,
+ 94, 251, 554, 57, -312, -423, -154, -57, 235,
+ -268, -71, 381, 114, -44, -87, 125, 173, 133,
+ 1513, 1714, 1238, 534, 276, 315, 461, 459, 508,
+ -131, -19, 1149, 670, 486, 356, 309, 369, 296,
+ -223, -501, -899, -722, -70, 6, 131, 310, 394,
+ -99, -303, -517, 249, 64, -53, 135, -11, 453,
+ -147, -399, -730, -401, 817, 738, 802, 749, 575,
+ -154, -435, -739, 800, 593, 366, 529, 318, 326,
+ -224, 45, -39, -387, -515, -518, -608, -384, -321,
+ -315, -377, 143, -101, -113, -377, -177, -144, -12,
+ 117, 40, -239, -651, -1051, -581, -737, -990, -328,
+ 26, -50, -157, -23, -453, -283, -531, -546, 192,
+ -252, -501, -743, -589, -627, -499, -328, -118, -72,
+ -324, -494, -244, -306, -144, -177, -262, -135, -78,
+ -36, -234, -519, -961, -1290, -314, -479, -371, -45,
+ -95, -292, -535, -8, -300, 112, -164, -277, 198,
+ -99, -128, 880, 836, 579, 351, 23, -95, -217,
+ -27, -258, 124, 1011, 597, 425, 144, 7, -73,
+ 421, 1293, 1640, 1623, 1742, 1617, 1499, 1284, 1006,
+ -95, 752, 1680, 1569, 1618, 1436, 1200, 980, 712,
+ -69, -300, -683, -435, 1132, 899, 504, 332, 109,
+ -74, -323, -637, 563, 1074, 608, 371, 105, -49,
+ -78, 831, 1194, 1110, 1378, 1481, 1492, 1365, 1217,
+ -259, -121, 1440, 1334, 1628, 1490, 1438, 1223, 933,
+ -82, -306, -613, -222, -378, -675, -545, -671, -845,
+ 53, -124, -347, 422, 52, -125, -270, -529, 9,
+ 79, -89, -320, -662, -999, -1199, -1243, -676, -297,
+ -68, -273, -611, 137, -146, -397, -627, -845, -220,
+ -112, -346, -797, -826, 234, -132, -188, -278, -522,
+ -159, -405, -734, -419, 293, 74, -167, -167, 184,
+ -153, -437, -833, -1080, -336, -472, -561, -340, -253,
+ -169, -423, -820, -904, -131, -19, -346, -604, 31,
+ 33, -31, 312, 62, -148, 49, -59, 564, 486,
+ -306, -333, 194, -44, 67, 72, 147, 205, 243,
+ -207, -49, 1360, 983, 969, 991, 1014, 1110, 973,
+ -211, -172, 883, 627, 711, 674, 705, 798, 746,
+ -88, -325, -763, -974, 687, 908, 514, 382, 172,
+ -292, -612, -805, 63, 131, 270, 259, 352, 348,
+ -235, -84, 955, 818, 1120, 1289, 1559, 1480, 1285,
+ -180, -461, -614, 657, 691, 745, 854, 783, 713,
+ -97, -309, -477, -614, -777, -734, -768, -526, -472,
+ -344, -476, -35, -169, 49, -77, -150, -240, -141,
+ -52, -268, -639, -919, -1278, -1113, -342, -333, -151,
+ -68, -242, -585, -73, -209, -478, -159, -429, 133,
+ -197, -499, -1005, -1268, -272, -224, -105, -67, 17,
+ -363, -618, -414, -116, -62, 20, 10, 116, 108,
+ -195, -475, -906, -1260, -891, -441, -277, -142, -28,
+ -226, -519, -950, -700, -275, -266, -116, -105, 82,
+ 404, 511, 520, 327, 17, -194, -333, -536, -586,
+ -114, -130, 276, 237, 204, 342, 135, -16, -111,
+ 670, 1208, 1168, 860, 742, 601, 528, 403, 309,
+ 397, 621, 966, 752, 579, 398, 400, 329, 252,
+ 191, 180, -137, -467, 272, 106, -95, 17, -192,
+ -80, -290, -626, 194, 598, 196, 21, -281, 77,
+ 510, 864, 1108, 807, 939, 902, 925, 717, 481,
+ 137, 367, 534, 764, 670, 382, 296, 153, 84,
+ 303, 497, 144, -85, -125, -539, -482, -464, -764,
+ 233, 347, 68, -147, 169, -210, -242, -226, -482,
+ 307, 422, 154, -175, -386, -722, -724, -904, -1015,
+ 309, 308, 160, -60, -470, -420, -598, -791, -219,
+ 68, 121, -137, -560, -146, -446, -515, -494, -729,
+ 130, 53, -227, 46, 474, 32, -161, -192, -490,
+ 213, 164, -71, -465, -876, -161, -456, -587, -48,
+ 218, 117, 39, 177, -194, -88, -226, -418, 50,
+ 210, 547, 569, 279, 121, -44, -50, 10, -84,
+ 58, 140, 182, -5, 267, 117, 106, 211, 198,
+ 539, 835, 913, 719, 617, 544, 591, 565, 642,
+ 153, 559, 872, 460, 222, 108, 188, 180, 183,
+ 158, 119, 284, -153, -271, 229, 87, 110, -57,
+ -183, 82, 118, 21, 13, 40, 118, 191, 185,
+ 162, 889, 654, 108, -34, 244, 488, 561, 532,
+ 163, 56, 609, 341, 50, 329, 68, 266, 218,
+ 100, 206, 18, -304, -107, -436, -487, -65, -306,
+ -86, 154, 134, -30, -45, -73, -104, -80, -96,
+ 245, 330, 10, -440, -849, -1082, 79, 40, -265,
+ 196, 372, 272, -181, -493, -389, 275, 80, -59,
+ 2, -12, -246, -505, -100, -436, 21, -187, -431,
+ -221, -48, 36, -271, -186, -147, -109, 26, 71,
+ 213, 140, 72, -351, -620, -84, -363, 69, 46,
+ 91, 167, -3, -95, -99, -105, -48, 114, 147,
+ 259, 249, 172, 607, 406, 52, 59, -189, -320,
+ 115, -85, -54, 574, 128, 226, -59, -253, 130,
+ -62, 1033, 1308, 1035, 1127, 1098, 1029, 961, 823,
+ 39, 364, 757, 940, 728, 660, 659, 583, 770,
+ -115, -338, -760, -471, 394, 37, 441, 178, 6,
+ -57, -305, -525, 796, 453, 188, -4, -114, 248,
+ 71, 444, 797, 731, 1096, 1157, 1222, 1029, 811,
+ 135, 359, 551, 425, 749, 815, 874, 704, 502,
+ 132, 247, 0, -206, -449, -750, -258, -514, -633,
+ 248, 249, 91, 121, -195, -499, -90, -282, -435,
+ 78, 20, -277, -623, -983, -1224, -415, -458, -639,
+ 347, 509, 208, -179, -464, -728, -76, -237, -486,
+ -103, -343, -756, -713, -265, -609, -191, -398, -636,
+ -121, -383, -749, 567, 252, -36, -354, -417, -50,
+ 204, 100, -149, -650, -1081, -47, -7, -263, 111,
+ -46, -180, -267, -324, -562, -394, -692, 398, 292,
+ 482, 670, 683, 624, 442, 165, 116, 36, -149,
+ 108, 247, 291, 247, 355, 122, 109, 224, 296,
+ -14, 945, 990, 801, 755, 815, 847, 913, 892,
+ 292, 349, 725, 482, 388, 329, 429, 620, 667,
+ -34, 197, 213, -127, 84, 494, 620, 575, 375,
+ 126, 207, 172, 167, 362, 202, 296, 395, 455,
+ -6, 250, 539, 467, 636, 801, 1149, 1287, 1118,
+ 27, 240, 369, 280, 440, 411, 634, 892, 953,
+ 159, 170, -58, -395, -797, -690, 77, -211, -334,
+ -5, -28, -13, -74, -335, -603, 300, 88, -205,
+ 82, -33, -364, -698, -1203, -1153, 110, -146, -289,
+ 113, 1, -243, -588, -994, -496, 414, 160, 42,
+ -56, -247, -440, -693, -996, -479, 11, -178, -357,
+ -151, -353, -327, -211, -340, 141, 65, 425, 453,
+ 34, -169, -455, -932, -1215, 138, 499, 256, 324,
+ 68, 139, -15, -547, -478, 17, 306, 502, 481,
+ -32, -134, 445, 129, -143, -244, -503, -507, -599,
+ 61, -140, -345, 496, 458, -2, 20, -227, -514,
+ 394, 1765, 1666, 1339, 1117, 806, 642, 479, 380,
+ 215, 519, 920, 1053, 1090, 791, 528, 290, 155,
+ -54, -233, -647, -602, 639, 294, -2, -167, -442,
+ -78, -315, -791, -113, 820, 403, 158, -116, -356,
+ 529, 1851, 2003, 1228, 622, -41, -416, 344, 819,
+ -105, -379, -236, 1224, 893, 749, 568, 356, 214,
+ -17, -199, -144, 50, -283, -247, -578, -846, -1087,
+ 69, -11, -381, -206, 209, -284, -387, -416, -716,
+ 39, -5, -145, -374, -682, -909, -1074, -1169, -1066,
+ 287, 226, 67, -221, -662, -171, -421, -642, -707,
+ -132, -348, -538, -448, -20, -4, -354, -748, -933,
+ 4, -75, -289, -598, 317, 52, -208, -297, -559,
+ -88, -264, -358, -589, -631, -248, -523, -822, -1071,
+ 70, -8, 54, -314, -515, 92, -146, -274, -493,
+ 199, 62, 391, 158, -141, 71, -219, -203, -207,
+ 152, 40, 329, 162, -29, 48, -149, 108, 127,
+ 635, 1058, 883, 492, 372, 312, 317, 274, 241,
+ 267, 722, 1256, 882, 625, 248, 8, -81, -60,
+ -58, -138, -291, -600, -12, -2, -39, 147, 117,
+ -107, -345, -513, 459, 76, 92, -272, 388, 262,
+ 362, 516, 203, -409, -716, -831, -331, 185, 209,
+ -117, -391, -298, 671, 292, 538, 257, 166, -38,
+ -102, -319, -194, -283, -573, -262, -579, -219, -444,
+ -235, 78, 11, -168, -101, -229, -263, -321, -123,
+ 70, 50, -170, -599, -996, -588, -263, -516, -455,
+ 394, 363, 229, -136, -538, 21, -183, -348, -201,
+ -124, -368, -640, -879, -847, -209, -409, -494, -515,
+ -127, -341, -541, -425, -510, -10, -252, -473, -291,
+ 84, -69, -201, -676, -868, 103, -311, -132, -320,
+ 5, -173, -188, -297, -628, 197, -57, 7, -11,
+ 49, -160, 56, 558, 111, 33, -311, -440, -463,
+ -1, -246, -307, 862, 453, 139, -170, -355, -232,
+ 279, 966, 1642, 1478, 1463, 1123, 795, 525, 339,
+ -197, -38, 1702, 1331, 1252, 950, 692, 504, 426,
+ -108, -344, -861, -1172, 444, 354, 88, -46, -220,
+ -53, -321, -494, 1113, 744, 364, 198, -34, -75,
+ 457, 955, 1177, 1214, 1427, 1457, 1345, 917, 539,
+ -69, 199, 897, 1140, 1343, 1183, 977, 742, 522,
+ 122, 44, -269, 27, -155, -562, -307, -590, -773,
+ 154, 42, -160, 252, -129, -305, -471, -733, -371,
+ 135, 185, -82, -416, -722, -913, -504, -743, -880,
+ 149, 214, -84, -329, -680, -835, -426, -661, -81,
+ -128, -380, -735, -998, -337, 17, -182, -467, -697,
+ -84, -290, -510, -592, 13, 440, 154, -38, -279,
+ 70, -61, -246, -727, -1047, -80, -381, -535, -704,
+ 178, -2, -146, -670, -938, 482, 138, 63, 65,
+ -11, 15, 772, 443, 142, -20, -209, -126, -161,
+ -32, -249, 95, 552, 124, 30, -343, 82, -86,
+ 148, 751, 1515, 1105, 867, 606, 474, 448, 399,
+ -163, -257, 899, 1097, 906, 751, 502, 390, 294,
+ -51, -258, -447, -806, -368, 763, 464, 364, 183,
+ -166, -374, -367, 87, 35, 399, 418, 856, 833,
+ -205, -310, 588, 778, 785, 1065, 1118, 1245, 1157,
+ -173, -312, 107, 345, 400, 790, 870, 1113, 1001,
+ -7, -120, -387, -410, -614, -943, -226, -384, -491,
+ -203, -288, -51, -331, -90, -178, -408, -573, -338,
+ 56, -29, -273, -627, -1041, -798, -247, -467, 148,
+ 66, -2, -205, -205, -575, -349, -57, -352, -58,
+ -45, -225, -471, -924, -497, 77, -32, 44, -135,
+ -277, -491, -497, -502, -424, -202, -137, 77, 96,
+ 26, -179, -469, -1008, -1260, 262, -35, -132, -259,
+ -66, -232, -447, -533, -789, -191, -100, -267, 364
+};
+
+/*------------------------------------------------*
+ * 1st stage codebook; 2nd split: isf9 to isf15
+ *------------------------------------------------*/
+
+const int16 dico2_isf[SIZE_BK2*7] =
+{
+
+ 1357, 1313, 1136, 784, 438, 181, 145,
+ 636, 648, 667, 568, 442, 217, 362,
+ 427, 440, 674, 524, 332, 117, -417,
+ 121, 295, 468, 465, 230, 44, -221,
+ -147, -240, 149, 80, 390, 278, 106,
+ -418, -556, 552, 511, 235, 144, -95,
+ 43, 193, 274, 150, 67, 34, -273,
+ -43, -126, 171, 416, 282, 63, -354,
+ -372, -86, -344, -108, -94, -182, -89,
+ -600, -840, -200, 465, 258, -11, -253,
+ -48, 329, 97, -290, -543, -795, -354,
+ -570, -117, 187, 10, -133, -416, -76,
+ -618, -129, -247, -371, 45, -76, 277,
+ -1022, -1079, 126, 474, 254, 127, 52,
+ -281, 76, -167, -361, -283, -551, -283,
+ -119, -52, -1, 134, -32, -204, -415,
+ 1064, 827, 637, 684, 464, 209, 12,
+ 482, 416, 449, 371, 335, 294, 194,
+ 719, 576, 365, 135, 113, 91, -199,
+ 298, 176, 493, 366, 194, 163, 36,
+ -35, -236, -259, -36, -4, 99, 152,
+ -98, -306, -27, 228, 90, 111, -86,
+ 91, 13, -211, -258, -106, 86, -64,
+ 73, -35, -57, -31, 162, 35, -192,
+ -109, -335, -629, -66, -61, -128, 322,
+ -495, -669, -728, 193, 31, -220, 122,
+ 324, 95, -89, -91, -409, -710, -154,
+ 0, -234, 92, 33, -343, -609, -220,
+ -343, -408, -476, -655, -153, 82, 222,
+ -490, -745, -255, 49, -48, 135, -127,
+ 119, -67, -328, -390, -272, -545, -56,
+ -57, -130, -10, -7, -164, -47, -22,
+ 984, 1064, 961, 568, 210, -27, 16,
+ 811, 691, 754, 514, 224, -35, 166,
+ 662, 704, 618, 386, 57, -211, -257,
+ 510, 359, 418, 393, 91, -144, -18,
+ -193, -31, -27, 223, 89, -143, 24,
+ -112, -98, 471, 319, 185, 3, 175,
+ 252, 146, -47, 272, 48, -211, -234,
+ 146, 69, 203, 364, 68, -52, 51,
+ -259, -478, -697, -349, -758, -501, 63,
+ -501, -769, -289, 79, -311, -497, -106,
+ 251, 53, -235, -469, -895, -884, 145,
+ -416, -551, 140, -133, -523, -775, 44,
+ -326, -423, -713, -497, -86, -431, 99,
+ -757, -772, -160, -76, -46, -32, 379,
+ 85, -35, -200, -401, -663, -1040, -247,
+ -180, -330, -92, -376, 27, -183, -110,
+ 1279, 1086, 781, 502, 324, 164, 157,
+ 682, 466, 449, 277, 146, 28, 409,
+ 635, 472, 390, 107, -232, -538, -139,
+ 196, 396, 332, 213, 209, -29, -81,
+ 150, -95, -312, 76, -77, -320, -50,
+ 46, 9, 47, 175, 139, 30, 384,
+ 218, 206, -24, -250, -96, -276, -183,
+ 26, 119, 38, 14, -4, -133, -52,
+ -477, -614, -987, -715, -631, -813, 200,
+ -744, -1009, -1065, -745, -631, -171, 18,
+ -137, -251, -483, -613, -980, -1203, 12,
+ -605, -767, -562, -686, -1088, -515, 58,
+ -202, -428, -782, -1072, -96, -234, -179,
+ -480, -709, -1070, -897, -131, -92, 321,
+ -145, -193, -512, -729, -572, -765, -210,
+ -331, -585, -525, -631, -281, -208, -303,
+ 1165, 1104, 939, 828, 716, 426, 155,
+ 6, -109, 820, 778, 415, 113, -27,
+ 381, 339, 314, 265, 121, -9, -474,
+ -373, 47, 584, 442, 99, -231, -113,
+ -496, -38, -285, 262, 305, 170, 4,
+ -587, -556, 69, 66, 471, 354, 13,
+ -138, 70, -18, 106, 67, 167, -302,
+ -445, -141, 185, 191, 151, 83, -133,
+ -257, -521, -720, -198, 134, -46, -182,
+ -819, -1168, -777, 512, 359, 95, -113,
+ 137, -2, -74, -138, -401, -114, -371,
+ -242, -466, 204, 223, -31, -212, -192,
+ -532, -637, -466, -686, 256, 277, -139,
+ -1141, -1244, -381, -75, -54, 14, 88,
+ -311, 115, -143, -499, -343, 124, -416,
+ -616, -147, -135, 43, -4, 121, -369,
+ 835, 783, 641, 390, 355, 350, 64,
+ 72, 194, 443, 467, 436, 219, 372,
+ 464, 369, 192, 4, -156, -72, -226,
+ 57, 206, 303, 205, 188, 101, 265,
+ -40, -205, -488, -184, 276, 64, -26,
+ -217, -433, -297, 137, 328, 308, -289,
+ 378, 81, -308, -465, 57, -37, 227,
+ -100, 24, -36, -151, 199, 8, 143,
+ -426, -697, -1059, -133, 388, 161, 321,
+ -644, -1023, -1271, 39, 66, -123, 70,
+ 372, 177, -173, -556, -553, -304, -189,
+ -117, -369, -425, -122, -462, -152, -73,
+ -649, -850, -1189, -767, 497, 360, 222,
+ -798, -1139, -1455, -190, 430, 234, 179,
+ 42, -94, -405, -692, 38, -202, -246,
+ -169, -366, -290, -88, -64, 32, -292,
+ 1010, 923, 938, 710, 465, 230, 342,
+ 217, 300, 1054, 675, 68, -458, -179,
+ 78, 453, 316, 18, -237, -496, -243,
+ 167, 21, 424, 215, -91, -303, -170,
+ -290, -81, -70, -67, 40, 54, -59,
+ -353, -427, -90, 53, 94, 9, 54,
+ -28, 318, 283, 15, -240, -58, 79,
+ -75, -121, 229, 35, 58, 6, -133,
+ -351, -514, -744, -834, -705, -137, 164,
+ -1124, -1388, -1055, -230, -73, 40, 36,
+ -163, -233, -532, -785, -1170, -697, 96,
+ -788, -959, -246, -430, -624, -165, -8,
+ -856, -540, -630, -907, -337, -70, 76,
+ -937, -1042, -659, -733, -208, 199, -26,
+ -523, 78, -98, -501, -869, -890, -81,
+ -624, -703, -45, -348, -25, 87, -186,
+ 1005, 823, 546, 249, 90, -22, 207,
+ 298, 397, 381, 319, 200, 62, 303,
+ 473, 379, 133, -247, -632, -441, 75,
+ 284, 208, 391, 115, -25, 44, 95,
+ -72, 79, -95, -63, -129, -293, 203,
+ -164, -349, 115, 122, 69, -1, 378,
+ 348, 170, 99, 58, -179, -302, 188,
+ -190, -2, 150, 23, -51, -11, 216,
+ -615, -863, -1090, -1427, -802, -48, -6,
+ -961, -1276, -1548, -727, -58, 56, 223,
+ -124, -255, -561, -988, -1277, -148, -82,
+ -480, -660, -891, -1191, -1339, -325, 20,
+ -621, -917, -1296, -1350, 264, 289, 50,
+ -844, -1022, -1345, -1329, -293, 46, 278,
+ -260, -468, -829, -1176, -533, -560, -78,
+ -215, -484, -822, -1233, -791, 15, -138,
+ 1301, 1317, 1262, 1048, 716, 357, -64,
+ 578, 824, 925, 802, 630, 362, 102,
+ 470, 925, 767, 514, 327, 190, -112,
+ 225, 492, 495, 437, 598, 384, -45,
+ 43, 82, -42, 175, 519, 342, -64,
+ -304, -154, 159, 576, 403, 221, 327,
+ 214, 244, 122, -62, 312, 92, -160,
+ 218, 208, 310, 268, 306, 323, -199,
+ -285, -269, -79, -124, -143, -153, 236,
+ -205, -384, -426, 344, 59, -185, -184,
+ -272, 247, 126, -210, -518, -468, 78,
+ -99, -120, 502, 160, -280, -557, 304,
+ -423, -17, -283, -443, 215, 212, -140,
+ -564, -684, -228, 510, 361, 130, 323,
+ -428, 335, 98, -65, 36, -215, -246,
+ -362, 51, 364, -16, -234, 150, -165,
+ 914, 883, 751, 653, 676, 464, -153,
+ 631, 545, 535, 720, 596, 360, -81,
+ 783, 712, 512, 439, 341, 251, -391,
+ 497, 417, 249, 372, 295, 173, -193,
+ 128, -110, -385, 93, 39, 173, -231,
+ 216, -59, -253, 462, 389, 154, 69,
+ 455, 270, -4, -337, -49, 233, -322,
+ 307, 143, 53, 218, 128, 236, -156,
+ -37, -186, -240, -411, -110, 9, 399,
+ -140, -365, -628, 258, 380, 214, 277,
+ 131, 454, 177, -285, -520, 108, -214,
+ 77, -141, 201, -123, -490, -131, 60,
+ -14, -194, -521, -741, 273, 362, -33,
+ -362, -566, -287, -228, 161, 237, 317,
+ -269, 195, -75, -375, -204, 11, 77,
+ -128, -264, -156, -223, -475, 265, 27,
+ 1238, 1147, 916, 689, 432, 210, -280,
+ 800, 664, 879, 726, 411, 160, -164,
+ 454, 686, 536, 275, 147, 46, 111,
+ 303, 486, 512, 355, 241, 181, -69,
+ 79, 92, 29, 147, 233, 52, 17,
+ -171, 289, 131, 439, 271, 3, -10,
+ 413, 241, 144, 174, 155, -2, 14,
+ 58, 217, 247, 219, 149, 175, -18,
+ 228, -8, -240, -206, -513, -191, 202,
+ -96, -272, -454, 33, -300, -575, 46,
+ -10, -108, -246, -347, -770, -535, 9,
+ -326, -430, -61, -321, -704, -299, 201,
+ -1, -280, -603, -419, -185, 18, -36,
+ -516, -522, -379, -291, -181, -97, 27,
+ -159, -313, -525, -224, -510, -831, -197,
+ -292, -459, -59, -310, -562, -143, -351,
+ 1066, 912, 631, 389, 207, 86, -224,
+ 596, 512, 596, 505, 314, 122, -48,
+ 787, 861, 441, -93, -303, 33, -190,
+ 257, 469, 337, 51, 15, 298, -93,
+ 295, 73, -119, 25, 36, 23, 108,
+ -28, -3, -32, 114, 21, 185, 107,
+ 482, 305, 15, -279, -319, 52, 96,
+ 226, 46, 115, 72, -136, 133, -125,
+ 18, -207, -559, -590, -503, -482, 321,
+ -571, -789, -951, -172, -441, -538, 113,
+ 181, 14, -310, -641, -1001, -202, 159,
+ -136, -393, -433, -513, -911, -144, -22,
+ 72, -265, -706, -954, -159, 53, 332,
+ -338, -591, -852, -383, -395, 56, 44,
+ 43, -158, -464, -897, -631, -157, -294,
+ -161, -128, -328, -573, -483, -125, 11,
+ 1017, 906, 1051, 1005, 679, 341, -102,
+ 359, 334, 1567, 1314, 723, 105, 10,
+ -65, 726, 529, 301, 220, 43, -273,
+ -510, 436, 719, 566, 358, 179, 114,
+ -560, 298, 133, -120, 342, 225, 14,
+ -899, -101, 217, 617, 400, 146, -58,
+ -41, 352, 82, -196, 39, 121, -167,
+ -212, 59, 447, 284, 423, 250, -169,
+ -371, -484, -596, 30, -41, 249, 22,
+ -372, -650, -794, 477, 445, 216, -79,
+ -352, 275, 17, -443, -929, 92, 19,
+ -699, -696, 431, 264, -49, -310, 182,
+ -978, -217, -430, -400, 101, 261, 72,
+ -929, -889, -357, -13, 463, 378, 236,
+ -826, 56, 30, -299, -360, -128, -51,
+ -878, -299, -111, 75, 65, 36, 3,
+ 817, 368, -25, 354, 697, 591, -173,
+ 309, 212, 222, 751, 484, 140, -56,
+ 593, 379, 70, -8, 258, 180, 110,
+ 165, -46, 255, 297, 219, 273, 105,
+ 160, -70, -358, -181, 379, 330, 319,
+ -238, -369, -198, 740, 580, 319, -143,
+ 201, 109, -202, -456, 328, 276, -141,
+ 203, 170, 111, 42, 207, 360, 188,
+ -345, -399, -513, -233, 650, 422, 81,
+ -635, -961, -1220, 463, 539, 204, 209,
+ 202, -25, -194, -498, -787, 193, -143,
+ -449, -538, 195, -106, -331, 68, 62,
+ -228, -477, -840, -576, 317, 128, 283,
+ -671, -937, -807, -114, 391, 335, -62,
+ 246, 2, -314, -679, -303, 180, -88,
+ -107, -272, 90, -198, -28, 290, -112,
+ 885, 1149, 1021, 712, 496, 281, -83,
+ 269, 492, 787, 643, 347, 70, 124,
+ 336, 636, 499, 92, -229, -179, 191,
+ 26, 402, 564, 340, 149, -11, 135,
+ -440, 561, 470, 204, -72, -186, 140,
+ -720, 14, 355, 229, 68, -133, 465,
+ 110, 310, 103, 12, 106, 29, 158,
+ -178, 113, 161, 142, 121, 115, 27,
+ -651, -414, -645, -152, -164, -13, -429,
+ -639, -944, -681, -104, -81, 52, -189,
+ -663, -164, -316, -683, -954, -205, -83,
+ -609, -669, -172, -517, -694, 283, -80,
+ -646, -152, -383, -678, -246, -40, -143,
+ -747, -796, -745, -390, -98, 43, 275,
+ -599, -199, -398, -433, -436, -538, 31,
+ -1107, -568, -376, -265, -126, -21, 1,
+ 847, 573, 308, 392, 305, 101, 55,
+ 273, 293, 201, 267, 346, 201, 123,
+ 727, 480, 226, 2, -65, -138, 164,
+ 273, 208, 173, 292, 12, 253, 174,
+ 340, 207, 180, 88, 116, 46, 475,
+ -460, -166, -30, 13, 110, 173, 396,
+ 137, 88, 43, -137, -94, 34, 284,
+ 96, -14, 226, 40, 63, 70, 130,
+ -467, -735, -1012, -1174, -307, 305, -67,
+ -612, -920, -1146, -567, -8, 92, -25,
+ -182, -271, -492, -754, -857, 287, -75,
+ -494, -787, -689, -683, -709, 137, -326,
+ -288, -550, -903, -1105, 334, 321, -62,
+ -354, -653, -834, -445, 1, 377, -152,
+ -162, -306, -608, -937, -297, 247, -192,
+ -234, -477, -244, -488, -266, 342, -332
+};
+
+/*
+ * 2nd stage codebook; 1st split: isf2_0 to isf2_2
+ */
+
+
+const int16 dico21_isf[SIZE_BK21*3] =
+{
+
+ 329, 409, 249,
+ -33, 505, 160,
+ -29, -14, 582,
+ -262, 127, 354,
+ 145, 237, 175,
+ -152, 245, 122,
+ 27, 42, 340,
+ -84, -93, 311,
+ 285, 222, -156,
+ 47, -43, -504,
+ 234, 121, 385,
+ 104, -317, 45,
+ 176, 195, 8,
+ 104, -59, -94,
+ 177, 53, 192,
+ -34, -127, 152,
+ 570, 277, -34,
+ -67, -329, -639,
+ -157, -272, 462,
+ -177, -462, 198,
+ 322, 179, 115,
+ -386, 171, 19,
+ 19, -12, 195,
+ -120, -252, 201,
+ 304, 36, -336,
+ -128, -221, -380,
+ 171, -185, 296,
+ -242, -312, 23,
+ 198, 39, 16,
+ -3, -177, -111,
+ 111, -93, 76,
+ -92, -223, 4,
+ 177, 406, -44,
+ -168, 380, -149,
+ -4, 273, 331,
+ -420, 513, 277,
+ 21, 247, 47,
+ -58, 131, -2,
+ -3, 134, 180,
+ -145, 40, 175,
+ 189, 74, -145,
+ -27, -45, -325,
+ 370, -114, -21,
+ -83, -415, -173,
+ 77, 95, -51,
+ -40, -30, -67,
+ 71, 88, 86,
+ -35, -98, 14,
+ 69, 197, -334,
+ -196, 79, -231,
+ -348, -137, 218,
+ -352, -89, -85,
+ 47, 201, -130,
+ -165, 37, -15,
+ -43, 3, 86,
+ -161, -108, 79,
+ 83, 21, -237,
+ -81, -149, -238,
+ 150, -186, -251,
+ -186, -249, -162,
+ -19, 66, -139,
+ -26, -50, -181,
+ 24, 11, 0,
+ -130, -105, -98
+};
+
+
+
+/*
+ * 2nd stage codebook; 2nd split: isf2_3 to isf2_5
+ */
+
+
+const int16 dico22_isf[SIZE_BK22*3] =
+{
+
+ -127, 310, 42,
+ -242, 197, 5,
+ -151, 84, -17,
+ -214, 127, -149,
+ -247, -131, 159,
+ -268, -267, -95,
+ -217, 1, -79,
+ -271, -80, -185,
+ -45, 436, 159,
+ 165, 199, 391,
+ -33, 81, 187,
+ -66, -42, 355,
+ -298, -57, 343,
+ -108, -537, 226,
+ -144, -23, 193,
+ 176, -402, 87,
+ 53, 296, 25,
+ -84, 253, -104,
+ -58, 105, -126,
+ -169, 174, -314,
+ -48, 44, -294,
+ -164, -417, -242,
+ -139, 3, -194,
+ -155, -207, -211,
+ 119, 322, 213,
+ 333, 50, 380,
+ 237, 247, -2,
+ 466, -16, 201,
+ 238, -255, -107,
+ 67, -440, -149,
+ 122, -88, -139,
+ 88, -247, -73,
+ -41, 231, 167,
+ -62, 155, 16,
+ -65, 16, 77,
+ -68, -2, -63,
+ -151, -300, 160,
+ -18, -333, 54,
+ -56, -94, 5,
+ 2, -190, 14,
+ 92, 148, 209,
+ 108, 9, 272,
+ 108, 35, 110,
+ 142, -85, 145,
+ 47, -157, 279,
+ 3, -320, 246,
+ 43, -72, 68,
+ 86, -217, 135,
+ 36, 140, 79,
+ 56, 175, -49,
+ 26, 45, 3,
+ 73, 55, -101,
+ 109, -183, -242,
+ -4, -283, -242,
+ 48, -68, -48,
+ -6, -153, -122,
+ 161, 196, 96,
+ 232, 80, 190,
+ 165, 97, 11,
+ 258, -31, 71,
+ 267, -77, -91,
+ 311, -209, 87,
+ 152, -14, -22,
+ 150, -149, 9,
+ -324, 557, 187,
+ -384, 307, 46,
+ -251, 27, 77,
+ -365, 77, -52,
+ -482, -84, 160,
+ -424, -515, -64,
+ -294, -120, -4,
+ -476, -116, -109,
+ -97, 318, 365,
+ 106, 627, 445,
+ -190, 120, 287,
+ -146, 65, 619,
+ -427, 242, 363,
+ -361, -371, 432,
+ -347, 102, 168,
+ -629, 195, -14,
+ -65, 476, -47,
+ -297, 320, -168,
+ -55, 356, -264,
+ -391, 82, -286,
+ -51, -31, -556,
+ -178, -399, -586,
+ -205, -49, -360,
+ -343, -238, -337,
+ 220, 457, 58,
+ 561, 467, 259,
+ 340, 270, -168,
+ 450, 77, -280,
+ 60, 167, -413,
+ 133, -252, -492,
+ 216, 157, -290,
+ 282, 0, -495,
+ -226, 293, 183,
+ -157, 135, 122,
+ -158, -59, 39,
+ -133, -118, -97,
+ -332, -309, 113,
+ -160, -425, -6,
+ -149, -211, 24,
+ -80, -277, -90,
+ -11, 125, 338,
+ 130, -71, 465,
+ 5, -45, 184,
+ 237, -95, 253,
+ -139, -197, 297,
+ -19, -300, 511,
+ -63, -152, 139,
+ 250, -289, 336,
+ 124, 339, -150,
+ 34, 176, -208,
+ 171, 166, -116,
+ 94, 38, -229,
+ 75, -65, -339,
+ -78, -205, -385,
+ 0, -30, -163,
+ -56, -110, -242,
+ 321, 244, 194,
+ 505, 238, -1,
+ 317, 116, 65,
+ 309, 88, -74,
+ 452, -51, -50,
+ 334, -217, -290,
+ 211, 41, -152,
+ 238, -55, -260
+};
+
+
+/*
+ * 2nd stage codebook; 3rd split: isf2_6 to isf2_8
+ */
+
+
+const int16 dico23_isf[SIZE_BK23*3] =
+{
+
+ -10, 151, 359,
+ 136, 298, 223,
+ 255, -104, 290,
+ 423, 6, 183,
+ -270, -269, -98,
+ -52, -82, 13,
+ -82, -274, -97,
+ 90, -246, -72,
+ -299, -70, 421,
+ -88, 365, 430,
+ 187, -318, 381,
+ 380, 37, 488,
+ -373, -316, 79,
+ -308, -101, 5,
+ -135, -451, 8,
+ 72, -421, -154,
+ 180, 170, -121,
+ 62, 177, -40,
+ 326, 80, -105,
+ 248, 263, -5,
+ -168, -181, -221,
+ -2, -23, -158,
+ -14, -149, -121,
+ 119, -91, -147,
+ 119, 332, -153,
+ 49, 303, 34,
+ 442, -55, -69,
+ 217, 454, 58,
+ -359, -187, -375,
+ -42, 50, -274,
+ -8, -267, -249,
+ 85, -86, -346,
+ -77, -40, 345,
+ 89, 134, 219,
+ 156, -80, 160,
+ 108, 40, 116,
+ -158, -206, 29,
+ 5, -32, 175,
+ -65, -158, 146,
+ 55, -78, 73,
+ -114, -222, 353,
+ -47, 81, 211,
+ 49, -151, 268,
+ 105, 4, 302,
+ -263, -132, 183,
+ -151, -28, 201,
+ -177, -307, 166,
+ 101, -221, 130,
+ 74, 58, -98,
+ 32, 44, 13,
+ 194, 30, -142,
+ 170, 96, 8,
+ -136, -119, -91,
+ -65, 8, -55,
+ 3, -188, 12,
+ 45, -63, -49,
+ 149, -21, -19,
+ 24, 144, 95,
+ 254, -22, 60,
+ 161, 196, 96,
+ -158, -61, 48,
+ -70, 33, 82,
+ -23, -321, 58,
+ 155, -147, 5,
+ -364, 328, 77,
+ -21, 453, 173,
+ -108, 82, 630,
+ 367, 263, 208,
+ -300, -62, -176,
+ -205, 143, -158,
+ -169, -410, -264,
+ 257, -269, -100,
+ -636, 289, -2,
+ -292, 627, 173,
+ -382, -363, 387,
+ 248, 524, 447,
+ -521, -111, -107,
+ -395, 118, -274,
+ -343, -680, -125,
+ -172, -447, -663,
+ 75, 148, -367,
+ -79, 263, -94,
+ 249, 148, -286,
+ 380, 271, -162,
+ -142, -4, -186,
+ -57, 111, -125,
+ -35, -108, -254,
+ 100, 29, -242,
+ -80, 303, -264,
+ -78, 464, -57,
+ 248, -22, -494,
+ 661, 662, 44,
+ -193, -40, -330,
+ -178, 145, -337,
+ -90, -199, -400,
+ -40, -23, -498,
+ -192, 114, 315,
+ -41, 244, 190,
+ 88, -97, 485,
+ 241, 80, 212,
+ -246, 40, 87,
+ -156, 147, 134,
+ -2, -334, 239,
+ 308, -203, 110,
+ -459, 251, 422,
+ -218, 310, 228,
+ -86, -346, 654,
+ 184, 175, 425,
+ -481, -63, 169,
+ -349, 117, 188,
+ -125, -560, 310,
+ 158, -416, 94,
+ 46, 171, -192,
+ -63, 157, 14,
+ 256, -35, -271,
+ 322, 123, 53,
+ -214, 4, -76,
+ -156, 86, -18,
+ 128, -197, -232,
+ 265, -90, -98,
+ -308, 332, -145,
+ -131, 308, 58,
+ 509, 59, -339,
+ 562, 196, -14,
+ -378, 100, -47,
+ -234, 202, 1,
+ 104, -270, -493,
+ 319, -210, -325
+};
+
+
+/*
+ * 2nd stage codebook; 4th split: isf2_9 to isf2_11
+ */
+
+const int16 dico24_isf[SIZE_BK24*3] =
+{
+
+ -79, -89, -4,
+ -171, 77, -211,
+ 160, -193, 98,
+ 120, -103, 323,
+ 32, -22, -129,
+ 72, 78, -268,
+ 182, -76, -66,
+ 309, 99, -145,
+ -229, -157, -84,
+ -383, 98, -71,
+ -90, -352, 12,
+ -284, -178, 178,
+ -65, -125, -166,
+ -87, -175, -351,
+ 42, -198, -48,
+ 154, -140, -243,
+ -77, 18, 108,
+ -39, 355, 91,
+ 87, 8, 155,
+ -4, 158, 239,
+ 128, 95, -54,
+ 7, 246, -124,
+ 258, 15, 89,
+ 206, 216, 98,
+ -201, 9, 18,
+ -312, 233, 204,
+ -39, -174, 155,
+ -144, -9, 284,
+ -57, 70, -69,
+ -157, 187, 18,
+ 54, -30, 23,
+ 24, 135, 55
+};
+
+
+/*
+ * 2nd stage codebook; 5th split: isf2_12 to isf2_15
+ */
+
+const int16 dico25_isf[SIZE_BK25*4] =
+{
+
+ 169, 142, -119, 115,
+ 206, -20, 94, 226,
+ -106, 313, -21, 16,
+ -62, 161, 71, 255,
+ -89, 101, -185, 125,
+ 72, -30, -201, 344,
+ -258, 33, -8, 81,
+ -104, -154, 72, 296,
+ 144, -68, -268, -25,
+ 81, -78, -87, 106,
+ 22, 155, -186, -119,
+ -46, -28, 27, 91,
+ -114, -37, -175, -33,
+ -94, -222, -189, 122,
+ -132, -119, -191, -270,
+ -172, -173, 18, -43,
+ 279, 135, -42, -128,
+ 187, -86, 229, -138,
+ 159, 240, 140, 46,
+ 69, 25, 227, 77,
+ 21, 115, 13, 8,
+ 68, -248, 126, 81,
+ -150, 137, 207, -9,
+ -154, -133, 289, 67,
+ 143, -37, -86, -326,
+ 180, -32, 19, -23,
+ 26, 168, 116, -233,
+ -32, -26, 118, -78,
+ 3, -8, -45, -115,
+ 57, -215, -54, -83,
+ -209, 112, -22, -167,
+ -91, -151, 168, -262
+};
+
+
+
+/* 36 bit */
+/*
+ * isf codebooks: two-stage VQ with split-by-3 in 2nd stage
+ * 1st stage is kept the same as the 46 bit quantizer
+ *
+ * codebook vector dimension number of vectors
+ * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
+ * 1_1 9 256
+ * 1_2 7 256
+ * 2_1 5 128
+ * 2_2 4 128
+ * 2_3 7 64
+ */
+
+const int16 dico21_isf_36b[SIZE_BK21_36b*5] =
+{
+
+ -52, -96, 212, 315, -73,
+ 82, -204, 363, 136, -197,
+ -126, -331, 183, 218, 143,
+ -49, -41, 557, 230, 72,
+ 2, -73, 163, 377, 221,
+ 133, 111, 278, 215, -110,
+ -102, -20, 284, 113, 273,
+ 84, 319, 290, 18, 85,
+ -25, -5, 125, 132, -204,
+ -38, -5, 286, -9, -356,
+ -140, -256, 92, 117, -189,
+ -144, 191, 313, 51, -98,
+ 167, -10, 44, 247, 36,
+ 381, 197, 238, 74, 6,
+ 38, -408, 29, -3, -85,
+ 92, 266, 157, -25, -200,
+ 161, -121, 70, 84, -140,
+ -16, -86, 112, -94, -189,
+ -269, -270, 351, 107, -24,
+ -68, -67, 492, -103, -155,
+ -53, -131, 62, 122, 10,
+ 135, 84, 283, -55, -120,
+ -12, -219, 331, -81, 167,
+ 220, -136, 147, -172, -42,
+ 140, -95, -109, -88, -194,
+ 0, -2, -4, -33, -381,
+ -66, -217, 152, -186, -402,
+ 244, 108, 156, -140, -395,
+ 113, -136, -196, 110, -24,
+ 214, 118, 11, -64, -131,
+ -110, -286, -6, -332, 16,
+ 94, 97, 79, -291, -205,
+ -5, -39, -20, 252, -96,
+ 76, 174, 101, 163, 61,
+ -69, -239, -55, 399, 6,
+ -115, 319, 164, 275, 196,
+ -15, 36, -47, 331, 121,
+ 226, 209, 271, 325, 184,
+ 13, -80, -218, 471, 353,
+ 288, 378, 16, -51, 251,
+ 174, 116, 52, 149, -279,
+ 235, 276, 39, 120, -48,
+ 0, -108, -108, 241, -339,
+ -93, 534, 45, 33, -87,
+ 194, 149, -71, 405, -44,
+ 409, 370, 81, -186, -154,
+ 25, -102, -448, 124, -173,
+ 22, 408, -110, -310, -214,
+ -26, 23, -83, 114, 14,
+ -110, 164, 52, 223, -82,
+ 37, -25, -263, 306, -15,
+ -466, 415, 292, 165, -18,
+ 29, -19, -171, 155, 182,
+ 179, 144, -27, 231, 258,
+ -103, -247, -396, 238, 113,
+ 375, -154, -109, -4, 156,
+ 98, 85, -292, -5, -124,
+ 116, 139, -116, -98, -294,
+ -14, -83, -278, -117, -378,
+ 106, 33, -106, -344, -484,
+ 119, 17, -412, 138, 166,
+ 384, 101, -204, 88, -156,
+ -121, -284, -300, -1, -166,
+ 280, 33, -152, -313, -81,
+ -37, 22, 229, 153, 37,
+ -60, -83, 236, -8, -41,
+ -169, -228, 126, -20, 363,
+ -235, 17, 364, -156, 156,
+ -25, -30, 72, 144, 156,
+ 153, -26, 256, 97, 144,
+ -21, -37, 48, -65, 250,
+ 63, 77, 273, -128, 124,
+ -129, -26, 40, 9, -115,
+ -6, 82, 38, -90, -182,
+ -336, -13, 28, 158, 91,
+ -30, 241, 137, -170, -17,
+ 146, 14, -11, 33, 61,
+ 192, 197, 54, -84, 85,
+ 23, -200, -78, -29, 140,
+ 122, 237, 106, -341, 136,
+ -57, -142, -85, -16, -74,
+ -59, -90, -8, -187, -20,
+ -211, -267, 216, -179, -110,
+ -50, -7, 220, -267, -70,
+ -57, -42, -17, -15, 71,
+ 32, 21, 63, -137, 33,
+ -137, -175, 104, -68, 97,
+ -67, -43, 133, -301, 221,
+ -116, -200, -81, -92, -272,
+ -64, -41, -54, -244, -220,
+ -287, -242, -50, -87, -89,
+ -245, 236, 102, -166, -295,
+ 66, 24, -162, -71, 95,
+ 66, 136, -90, -220, -36,
+ -98, -161, -222, -188, 29,
+ -18, 18, -19, -415, 9,
+ 49, 61, 100, 39, -56,
+ -111, 82, 135, -31, 52,
+ -90, -153, -93, 189, 182,
+ -214, 295, 119, -74, 284,
+ 2, 137, 37, 47, 182,
+ 92, 117, 184, -53, 373,
+ -21, -14, -35, 136, 391,
+ 146, 129, -164, -28, 333,
+ 92, 80, -84, 100, -134,
+ -8, 217, -32, 3, -47,
+ -151, 251, -215, 142, 92,
+ -224, 310, -172, -275, 98,
+ 159, 155, -177, 112, 53,
+ 205, 27, 8, -240, 192,
+ 169, 120, -319, -201, 106,
+ 11, 36, -86, -237, 455,
+ -109, -154, -163, 174, -55,
+ -38, 32, -101, -78, -59,
+ -205, -321, -97, 69, 79,
+ -310, 44, 18, -185, 34,
+ -115, -20, -148, -39, 203,
+ -29, 154, -30, -158, 166,
+ -45, -131, -317, -24, 363,
+ -165, -205, -112, -222, 265,
+ -32, -44, -150, 54, -193,
+ -6, -38, -255, -169, -115,
+ -266, 87, -189, -36, -169,
+ -60, -87, -266, -436, -170,
+ -68, -81, -278, 24, 38,
+ -23, -19, -155, -256, 141,
+ -61, -226, -565, -175, 71,
+ 9, -29, -237, -515, 263
+};
+
+const int16 dico22_isf_36b[SIZE_BK22_36b*4] =
+{
+
+ -298, -6, 95, 31,
+ -213, -87, -122, 261,
+ 4, -49, 208, 14,
+ -129, -110, 30, 118,
+ -214, 258, 110, -235,
+ -41, -18, -126, 120,
+ 103, 65, 127, -37,
+ 126, -36, -24, 25,
+ -138, -67, -278, -186,
+ -164, -194, -201, 78,
+ -211, -87, -51, -221,
+ -174, -79, -94, -39,
+ 23, -6, -157, -240,
+ 22, -110, -153, -68,
+ 148, -5, -2, -149,
+ -1, -135, -39, -179,
+ 68, 360, -117, -15,
+ 137, 47, -278, 146,
+ 136, 260, 135, 65,
+ 61, 116, -45, 97,
+ 231, 379, 87, -120,
+ 338, 177, -272, 3,
+ 266, 156, 28, -69,
+ 260, 84, -85, 86,
+ -266, 154, -256, -182,
+ -17, -65, -304, -6,
+ -40, 175, -151, -180,
+ -27, 27, -87, -63,
+ 121, 114, -166, -469,
+ 159, -66, -323, -231,
+ 214, 152, -141, -212,
+ 137, 36, -184, -51,
+ -282, -237, 40, 10,
+ -48, -235, -37, 251,
+ -54, -323, 136, 29,
+ -88, -174, 213, 198,
+ -390, 99, -63, -375,
+ 107, -169, -164, 424,
+ 69, -111, 141, -167,
+ 74, -129, 65, 144,
+ -353, -207, -205, -109,
+ -160, -386, -355, 98,
+ -176, -493, -20, -143,
+ -252, -432, -2, 216,
+ -90, -174, -168, -411,
+ 13, -284, -229, -160,
+ -87, -279, 34, -251,
+ -75, -263, -58, -42,
+ 420, 53, -211, -358,
+ 384, -35, -374, 396,
+ 68, -228, 323, -2,
+ 167, -307, 192, 194,
+ 459, 329, -5, -332,
+ 375, 79, -7, 313,
+ 282, -124, 200, -92,
+ 271, -162, -70, 180,
+ -157, -298, -514, -309,
+ 58, -163, -546, 18,
+ 124, -364, 167, -238,
+ 83, -411, -117, 96,
+ 140, -112, -388, -624,
+ 259, -133, -317, 41,
+ 163, -130, -64, -334,
+ 226, -165, -124, -110,
+ -466, -61, 6, 229,
+ -153, 205, -145, 242,
+ -159, 48, 195, 148,
+ -58, 28, 31, 279,
+ -303, 185, 279, -4,
+ -61, 197, 59, 86,
+ -114, 123, 168, -52,
+ 35, 36, 100, 126,
+ -407, 102, -77, -40,
+ -338, -1, -342, 156,
+ -179, 105, -34, -97,
+ -185, 84, -35, 108,
+ -133, 107, -91, -357,
+ -180, 54, -229, 24,
+ -44, 47, 47, -182,
+ -66, 13, 45, 4,
+ -339, 251, 64, 226,
+ -42, 101, -350, 275,
+ -99, 398, 142, 121,
+ 111, 12, -102, 260,
+ 0, 505, 260, -94,
+ 161, 285, -96, 224,
+ -4, 206, 314, 33,
+ 167, 139, 88, 204,
+ -235, 316, -60, -25,
+ -8, -150, -312, 201,
+ -36, 292, 61, -104,
+ -40, 174, -162, 42,
+ -21, 402, -29, -351,
+ 21, 152, -360, -93,
+ 57, 191, 212, -196,
+ 76, 158, -21, -69,
+ -328, -185, 331, 119,
+ -53, 285, 56, 337,
+ -107, -24, 405, 29,
+ -18, 137, 272, 277,
+ -255, 22, 173, -191,
+ 295, 322, 325, 302,
+ 21, -27, 332, -178,
+ 119, 13, 271, 129,
+ -455, -180, 116, -191,
+ -227, 62, -148, 524,
+ -176, -287, 282, -157,
+ -243, 13, 199, 430,
+ -59, -49, 115, -365,
+ 72, -172, -137, 93,
+ -138, -126, 141, -84,
+ 5, -124, 38, -20,
+ -258, 311, 601, 213,
+ 94, 130, -61, 502,
+ -1, -157, 485, 313,
+ 146, -74, 158, 345,
+ 276, 135, 280, -57,
+ 490, 252, 99, 43,
+ 267, -74, 429, 105,
+ 278, -23, 119, 94,
+ -542, 488, 257, -115,
+ -84, -244, -438, 478,
+ -113, -545, 387, 101,
+ -95, -306, 111, 498,
+ 95, 166, 22, -301,
+ 420, -15, -58, -78,
+ 270, 29, 122, -282,
+ 160, -240, 50, -38
+};
+
+const int16 dico23_isf_36b[SIZE_BK23_36b*7] =
+{
+
+ 81, -18, 68, -27, -122, -280, -4,
+ 45, -177, 209, -30, -136, -74, 131,
+ -44, 101, -75, -88, -48, -137, -54,
+ -245, -28, 63, -18, -112, -103, 58,
+ -79, -6, 220, -65, 114, -35, -50,
+ 109, -65, 143, -114, 129, 76, 125,
+ 166, 90, -61, -242, 186, -74, -43,
+ -46, -92, 49, -227, 24, -155, 39,
+ 67, 85, 99, -42, 53, -184, -281,
+ 142, -122, 0, 21, -142, -15, -17,
+ 223, 92, -21, -48, -82, -14, -167,
+ 51, -37, -243, -30, -90, 18, -56,
+ 54, 105, 74, 86, 69, 13, -101,
+ 196, 72, -89, 43, 65, 19, 39,
+ 121, 34, 131, -82, 25, 213, -156,
+ 101, -102, -136, -21, 57, 214, 22,
+ 36, -124, 205, 204, 58, -156, -83,
+ 83, -117, 137, 137, 85, 116, 44,
+ -92, -148, -68, 11, -102, -197, -220,
+ -76, -185, -58, 132, -26, -183, 85,
+ -7, -31, -2, 23, 205, -151, 10,
+ -27, -37, -5, -18, 292, 131, 1,
+ 117, -168, 9, -93, 80, -59, -125,
+ -182, -244, 98, -24, 135, -22, 94,
+ 221, 97, 106, 42, 43, -160, 83,
+ 25, -64, -21, 6, 14, -15, 154,
+ 126, 15, -140, 150, -10, -207, -114,
+ 79, -63, -211, -70, -28, -217, 165,
+ 46, 38, -22, 281, 132, -62, 109,
+ 112, 54, -112, -93, 208, 27, 296,
+ 115, 10, -147, 41, 216, 42, -276,
+ 50, -115, -254, 167, 117, -2, 61,
+ 17, 144, 34, -72, -186, -150, 272,
+ -29, -66, -89, -95, -149, 129, 251,
+ 122, 0, -50, -234, -91, 36, 26,
+ -105, -102, -88, -121, -236, -7, -11,
+ -204, 109, 5, -191, 105, -15, 163,
+ -80, 32, -24, -209, 41, 294, 70,
+ -106, -94, -204, -118, 120, -50, -37,
+ -82, -241, 46, -131, -29, 150, -55,
+ 33, 155, 120, -89, -8, 7, 62,
+ 213, 82, 61, 18, -161, 144, 152,
+ 30, 131, 65, -87, -255, -17, -107,
+ -8, 85, -64, 51, -162, 223, -53,
+ -134, 261, 69, -56, 218, 72, -111,
+ 2, 155, -113, -87, 49, 85, -28,
+ -163, 42, -1, -196, 7, 39, -245,
+ 14, -137, -79, 11, -160, 202, -293,
+ -94, 33, 208, 100, 56, -44, 326,
+ -78, -41, 232, 13, -142, 227, 80,
+ -16, -87, 201, 33, -133, 15, -183,
+ -58, -192, -47, 184, -128, 133, 99,
+ -205, 11, -155, 78, 52, 72, 141,
+ -246, 26, 99, 151, 59, 115, -64,
+ -79, -47, -16, -14, 6, 47, -43,
+ -72, -178, -27, 162, 112, 43, -174,
+ -175, 238, 186, 71, -54, -188, -76,
+ -225, 233, 39, -39, -158, 122, 44,
+ -26, 43, 84, 130, -93, -51, 22,
+ 3, 92, -150, 136, -182, -57, 97,
+ -131, 179, -78, 80, 91, -165, 90,
+ -2, 148, 15, 130, 65, 175, 117,
+ -138, 114, -137, 132, 3, -10, -186,
+ 140, -4, -37, 254, -62, 92, -109
+};
+
+
diff --git a/media/codecs/amrwb/dec/src/scale_signal.cpp b/media/codecs/amrwb/dec/src/scale_signal.cpp
new file mode 100644
index 0000000..b2b02b1
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/scale_signal.cpp
@@ -0,0 +1,154 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: scale_signal.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 signal[], (i/o) : signal to scale
+ int16 lg, (i) : size of x[]
+ int16 exp (i) : exponent: x = round(x << exp)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Scale signal to get maximum of dynamic range
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void scale_signal(
+ int16 x[], /* (i/o) : signal to scale */
+ int16 lg, /* (i) : size of x[] */
+ int16 exp /* (i) : exponent: x = round(x << exp) */
+)
+{
+ int16 i;
+ int16 tmp;
+ int16 *pt_x;
+
+
+ int32 L_tmp;
+
+
+ if (exp > 0)
+ {
+ for (i = 0; i < lg; i++)
+ {
+ L_tmp = shl_int32(((int32)x[i] << 16), exp); /* saturation can occur here */
+ x[i] = amr_wb_round(L_tmp);
+ }
+ }
+ else if (exp < 0)
+ {
+ exp = -exp;
+ exp &= 0xf;
+ tmp = (int16)(0x00008000 >> (16 - exp));
+ pt_x = x;
+
+ for (i = lg >> 1; i != 0; i--)
+ {
+ *(pt_x) = add_int16(*(pt_x), tmp) >> exp;
+ pt_x++;
+ *(pt_x) = add_int16(*(pt_x), tmp) >> exp;
+ pt_x++;
+ }
+
+ }
+ return;
+}
diff --git a/media/codecs/amrwb/dec/src/synthesis_amr_wb.cpp b/media/codecs/amrwb/dec/src/synthesis_amr_wb.cpp
new file mode 100644
index 0000000..c3aa887
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/synthesis_amr_wb.cpp
@@ -0,0 +1,440 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: synthesis_amr_wb.cpp
+
+ Date: 05/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 Aq[], A(z) : quantized Az
+ int16 exc[], (i) : excitation at 12kHz
+ int16 Q_new, (i) : scaling performed on exc
+ int16 synth16k[], (o) : 16kHz synthesis signal
+ int16 prms, (i) : compressed amr wb
+ int16 HfIsf[],
+ int16 nb_bits,
+ int16 newDTXState,
+ Decoder_State * st, (i/o) : State structure
+ int16 bfi, (i) : bad frame indicator
+ int16 *ScratchMem
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Synthesis of signal at 16kHz with HF extension
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_mem_funcs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+#include "e_pv_amrwbdec.h"
+#include "get_amr_wb_bits.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_api.h"
+#include "synthesis_amr_wb.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+/* High Band encoding */
+const int16 HP_gain[16] =
+{
+ 3624, 4673, 5597, 6479, 7425, 8378, 9324, 10264,
+ 11210, 12206, 13391, 14844, 16770, 19655, 24289, 32728
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void synthesis_amr_wb(
+ int16 Aq[], /* A(z) : quantized Az */
+ int16 exc[], /* (i) : excitation at 12kHz */
+ int16 Q_new, /* (i) : scaling performed on exc */
+ int16 synth16k[], /* (o) : 16kHz synthesis signal */
+ int16 prms, /* (i) : parameter */
+ int16 HfIsf[],
+ int16 nb_bits,
+ int16 newDTXState,
+ Decoder_State * st, /* (i/o) : State structure */
+ int16 bfi, /* (i) : bad frame indicator */
+ int16 *ScratchMem
+)
+{
+ int16 i, fac, exp;
+ int16 tmp;
+ int16 ener, exp_ener;
+ int32 L_tmp;
+ int32 L_tmp2;
+
+ int16 HF_corr_gain;
+ int16 HF_gain_ind;
+ int16 gain1, gain2;
+
+ int16 *pt_synth;
+ int16 *pt_HF;
+ int16 *synth_hi = ScratchMem;
+ int16 *synth_lo = &ScratchMem[M + L_SUBFR];
+ int16 *synth = &synth_lo[M + L_SUBFR];
+ int16 *HF = &synth[L_SUBFR];
+ int16 *Ap = &HF[L_SUBFR16k]; /* High Frequency vector */
+ int16 *HfA = &Ap[M16k + 1];
+ int16 *pt_tmp;
+
+ /*------------------------------------------------------------*
+ * speech synthesis *
+ * ~~~~~~~~~~~~~~~~ *
+ * - Find synthesis speech corresponding to exc2[]. *
+ * - Perform fixed deemphasis and hp 50hz filtering. *
+ * - Oversampling from 12.8kHz to 16kHz. *
+ *------------------------------------------------------------*/
+
+ pv_memcpy((void *)synth_hi,
+ (void *)st->mem_syn_hi,
+ M*sizeof(*synth_hi));
+
+ pv_memcpy((void *)synth_lo,
+ (void *)st->mem_syn_lo,
+ M*sizeof(*synth_lo));
+
+ Syn_filt_32(Aq, M, exc, Q_new, synth_hi + M, synth_lo + M, L_SUBFR);
+
+ pv_memcpy((void *)st->mem_syn_hi,
+ (void *)(synth_hi + L_SUBFR),
+ M*sizeof(*st->mem_syn_hi));
+
+ pv_memcpy((void *)st->mem_syn_lo,
+ (void *)(synth_lo + L_SUBFR),
+ M*sizeof(*st->mem_syn_lo));
+
+ deemphasis_32(synth_hi + M,
+ synth_lo + M,
+ synth,
+ PREEMPH_FAC,
+ L_SUBFR,
+ &(st->mem_deemph));
+
+ highpass_50Hz_at_12k8(synth,
+ L_SUBFR,
+ st->mem_sig_out);
+
+ oversamp_12k8_to_16k(synth,
+ L_SUBFR,
+ synth16k,
+ st->mem_oversamp,
+ ScratchMem);
+
+ /*
+ * HF noise synthesis
+ * - Generate HF noise between 5.5 and 7.5 kHz.
+ * - Set energy of noise according to synthesis tilt.
+ * tilt > 0.8 ==> - 14 dB (voiced)
+ * tilt 0.5 ==> - 6 dB (voiced or noise)
+ * tilt < 0.0 ==> 0 dB (noise)
+ */
+
+ /* generate white noise vector */
+ pt_tmp = HF;
+ for (i = L_SUBFR16k >> 2; i != 0 ; i--)
+ {
+ *(pt_tmp++) = noise_gen_amrwb(&(st->seed2)) >> 3;
+ *(pt_tmp++) = noise_gen_amrwb(&(st->seed2)) >> 3;
+ *(pt_tmp++) = noise_gen_amrwb(&(st->seed2)) >> 3;
+ *(pt_tmp++) = noise_gen_amrwb(&(st->seed2)) >> 3;
+ }
+ /* energy of excitation */
+
+ pt_tmp = exc;
+
+ for (i = L_SUBFR >> 2; i != 0; i--)
+ {
+ *(pt_tmp) = add_int16(*(pt_tmp), 0x0004) >> 3;
+ pt_tmp++;
+ *(pt_tmp) = add_int16(*(pt_tmp), 0x0004) >> 3;
+ pt_tmp++;
+ *(pt_tmp) = add_int16(*(pt_tmp), 0x0004) >> 3;
+ pt_tmp++;
+ *(pt_tmp) = add_int16(*(pt_tmp), 0x0004) >> 3;
+ pt_tmp++;
+ }
+
+
+ Q_new -= 3;
+
+ ener = extract_h(Dot_product12(exc, exc, L_SUBFR, &exp_ener));
+ exp_ener -= Q_new << 1;
+
+ /* set energy of white noise to energy of excitation */
+
+ tmp = extract_h(Dot_product12(HF, HF, L_SUBFR16k, &exp));
+
+ if (tmp > ener)
+ {
+ tmp >>= 1; /* Be sure tmp < ener */
+ exp += 1;
+ }
+ L_tmp = L_deposit_h(div_16by16(tmp, ener)); /* result is normalized */
+ exp -= exp_ener;
+ one_ov_sqrt_norm(&L_tmp, &exp);
+ L_tmp = shl_int32(L_tmp, exp + 1); /* L_tmp x 2, L_tmp in Q31 */
+
+ tmp = (int16)(L_tmp >> 16); /* tmp = 2 x sqrt(ener_exc/ener_hf) */
+
+
+
+ pt_tmp = HF;
+ for (i = L_SUBFR16k >> 2; i != 0 ; i--)
+ {
+ *(pt_tmp) = (int16)(fxp_mul_16by16(*(pt_tmp), tmp) >> 15);
+ pt_tmp++;
+ *(pt_tmp) = (int16)(fxp_mul_16by16(*(pt_tmp), tmp) >> 15);
+ pt_tmp++;
+ *(pt_tmp) = (int16)(fxp_mul_16by16(*(pt_tmp), tmp) >> 15);
+ pt_tmp++;
+ *(pt_tmp) = (int16)(fxp_mul_16by16(*(pt_tmp), tmp) >> 15);
+ pt_tmp++;
+ }
+
+ /* find tilt of synthesis speech (tilt: 1=voiced, -1=unvoiced) */
+
+ highpass_400Hz_at_12k8(synth, L_SUBFR, st->mem_hp400);
+
+ L_tmp = 1L;
+ L_tmp2 = 1L;
+
+
+ L_tmp = mac_16by16_to_int32(L_tmp, synth[0], synth[0]);
+
+ for (i = 1; i < L_SUBFR; i++)
+ {
+ L_tmp = mac_16by16_to_int32(L_tmp, synth[i], synth[i ]);
+ L_tmp2 = mac_16by16_to_int32(L_tmp2, synth[i], synth[i - 1]);
+ }
+
+
+ exp = normalize_amr_wb(L_tmp);
+
+ ener = (int16)((L_tmp << exp) >> 16); /* ener = r[0] */
+ tmp = (int16)((L_tmp2 << exp) >> 16); /* tmp = r[1] */
+
+ if (tmp > 0)
+ {
+ fac = div_16by16(tmp, ener);
+ }
+ else
+ {
+ fac = 0;
+ }
+
+ /* modify energy of white noise according to synthesis tilt */
+ gain1 = 32767 - fac;
+ gain2 = mult_int16(gain1, 20480);
+ gain2 = shl_int16(gain2, 1);
+
+ if (st->vad_hist > 0)
+ {
+ tmp = gain2 - 1;
+ }
+ else
+ {
+ tmp = gain1 - 1;
+ }
+
+
+ if (tmp != 0)
+ {
+ tmp++;
+ }
+
+ if (tmp < 3277)
+ {
+ tmp = 3277; /* 0.1 in Q15 */
+
+ }
+
+
+ if ((nb_bits >= NBBITS_24k) && (bfi == 0))
+ {
+ /* HF correction gain */
+ HF_gain_ind = prms;
+ HF_corr_gain = HP_gain[HF_gain_ind];
+
+ pt_tmp = HF;
+ for (i = L_SUBFR16k >> 2; i != 0 ; i--)
+ {
+ *(pt_tmp) = mult_int16(*(pt_tmp), HF_corr_gain) << 1;
+ pt_tmp++;
+ *(pt_tmp) = mult_int16(*(pt_tmp), HF_corr_gain) << 1;
+ pt_tmp++;
+ *(pt_tmp) = mult_int16(*(pt_tmp), HF_corr_gain) << 1;
+ pt_tmp++;
+ *(pt_tmp) = mult_int16(*(pt_tmp), HF_corr_gain) << 1;
+ pt_tmp++;
+ }
+
+ /* HF gain */
+ }
+ else
+ {
+ pt_tmp = HF;
+ for (i = L_SUBFR16k >> 2; i != 0 ; i--)
+ {
+ *(pt_tmp) = mult_int16(*(pt_tmp), tmp);
+ pt_tmp++;
+ *(pt_tmp) = mult_int16(*(pt_tmp), tmp);
+ pt_tmp++;
+ *(pt_tmp) = mult_int16(*(pt_tmp), tmp);
+ pt_tmp++;
+ *(pt_tmp) = mult_int16(*(pt_tmp), tmp);
+ pt_tmp++;
+ }
+ }
+
+
+ if ((nb_bits <= NBBITS_7k) && (newDTXState == SPEECH))
+ {
+ isf_extrapolation(HfIsf);
+ Isp_Az(HfIsf, HfA, M16k, 0);
+
+ weight_amrwb_lpc(HfA, Ap, 29491, M16k); /* fac=0.9 */
+
+ wb_syn_filt(Ap,
+ M16k,
+ HF,
+ HF,
+ L_SUBFR16k,
+ st->mem_syn_hf,
+ 1,
+ ScratchMem);
+ }
+ else
+ {
+ /* synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz */
+ weight_amrwb_lpc(Aq, Ap, 19661, M); /* fac=0.6 */
+
+ wb_syn_filt(Ap,
+ M,
+ HF,
+ HF,
+ L_SUBFR16k,
+ st->mem_syn_hf + (M16k - M),
+ 1,
+ ScratchMem);
+ }
+
+ /* noise Band Pass filtering (1ms of delay) */
+ band_pass_6k_7k(HF,
+ L_SUBFR16k,
+ st->mem_hf,
+ ScratchMem);
+
+
+ if (nb_bits >= NBBITS_24k)
+ {
+ /* Low Pass filtering (7 kHz) */
+ low_pass_filt_7k(HF,
+ L_SUBFR16k,
+ st->mem_hf3,
+ ScratchMem);
+ }
+ /* add filtered HF noise to speech synthesis */
+
+ pt_synth = synth16k;
+ pt_HF = HF;
+
+ for (i = L_SUBFR16k >> 1; i != 0; i--)
+ {
+ *(pt_synth) = add_int16(*(pt_synth), *(pt_HF++)); /* check 16 bit saturation */
+ pt_synth++;
+ *(pt_synth) = add_int16(*(pt_synth), *(pt_HF++));
+ pt_synth++;
+ }
+
+}
+
diff --git a/media/codecs/amrwb/dec/src/synthesis_amr_wb.h b/media/codecs/amrwb/dec/src/synthesis_amr_wb.h
new file mode 100644
index 0000000..4bfc3c5
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/synthesis_amr_wb.h
@@ -0,0 +1,96 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Pathname: ./cpp/include/synthesis_amr_wb.h
+
+ Date: 05/04/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef SYNTHESIS_AMR_WB_H
+#define SYNTHESIS_AMR_WB_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES AND SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void synthesis_amr_wb(
+ int16 Aq[], /* A(z) : quantized Az */
+ int16 exc[], /* (i) : excitation at 12kHz */
+ int16 Q_new, /* (i) : scaling performed on exc */
+ int16 synth16k[], /* (o) : 16kHz synthesis signal */
+ int16 prms, /* (i) : parameter */
+ int16 HfIsf[],
+ int16 nb_bits,
+ int16 newDTXState,
+ Decoder_State * st, /* (i/o) : State structure */
+ int16 bfi, /* (i) : bad frame indicator */
+ int16 * ScratchMemory
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+#endif /* PV_NORMALIZE_H */
diff --git a/media/codecs/amrwb/dec/src/voice_factor.cpp b/media/codecs/amrwb/dec/src/voice_factor.cpp
new file mode 100644
index 0000000..6153c67
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/voice_factor.cpp
@@ -0,0 +1,175 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: voice_factor.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 exc[], (i) Q_exc : pitch excitation
+ int16 Q_exc, (i) : exc format
+ int16 gain_pit, (i) Q14 : gain of pitch
+ int16 code[], (i) Q9 : Fixed codebook excitation
+ int16 gain_code, (i) Q0 : gain of code
+ int16 L_subfr (i) : subframe length
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Find the voicing factor (1=voice to -1=unvoiced).
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
+ int16 exc[], /* (i) Q_exc : pitch excitation */
+ int16 Q_exc, /* (i) : exc format */
+ int16 gain_pit, /* (i) Q14 : gain of pitch */
+ int16 code[], /* (i) Q9 : Fixed codebook excitation */
+ int16 gain_code, /* (i) Q0 : gain of code */
+ int16 L_subfr /* (i) : subframe length */
+)
+{
+ int16 i, tmp, exp, ener1, exp1, ener2, exp2;
+ int32 L_tmp;
+
+ ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1));
+ exp1 = sub_int16(exp1, Q_exc << 1);
+ L_tmp = mul_16by16_to_int32(gain_pit, gain_pit);
+ exp = normalize_amr_wb(L_tmp);
+
+ tmp = (int16)((L_tmp << exp) >> 16);
+ ener1 = mult_int16(ener1, tmp);
+ exp1 -= (exp + 10); /* 10 -> gain_pit Q14 to Q9 */
+
+ ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2));
+
+ exp = norm_s(gain_code);
+ tmp = shl_int16(gain_code, exp);
+ tmp = mult_int16(tmp, tmp);
+ ener2 = mult_int16(ener2, tmp);
+ exp2 -= (exp << 1);
+
+ i = exp1 - exp2;
+
+
+ if (i >= 0)
+ {
+ ener1 >>= 1;
+ ener2 >>= (i + 1);
+ }
+ else
+ {
+ ener1 >>= (1 - i);
+ ener2 >>= 1;
+ }
+
+ tmp = ener1 - ener2;
+ ener1 += ener2 + 1;
+
+
+ if (tmp >= 0)
+ {
+ tmp = div_16by16(tmp, ener1);
+ }
+ else
+ {
+ tmp = negate_int16(div_16by16(negate_int16(tmp), ener1));
+ }
+
+ return (tmp);
+}
diff --git a/media/codecs/amrwb/dec/src/wb_syn_filt.cpp b/media/codecs/amrwb/dec/src/wb_syn_filt.cpp
new file mode 100644
index 0000000..d960322
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/wb_syn_filt.cpp
@@ -0,0 +1,307 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: wb_syn_filt.cpp
+
+ Date: 05/08/2004
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+wb_syn_filt
+
+ int16 a[], (i) Q12 : a[m+1] prediction coefficients
+ int16 m, (i) : order of LP filter
+ int16 x[], (i) : input signal
+ int16 y[], (o) : output signal
+ int16 lg, (i) : size of filtering
+ int16 mem[], (i/o) : memory associated with this filtering.
+ int16 update, (i) : 0=no update, 1=update of memory.
+ int16 y_buf[]
+
+Syn_filt_32
+
+ int16 a[], (i) Q12 : a[m+1] prediction coefficients
+ int16 m, (i) : order of LP filter
+ int16 exc[], (i) Qnew: excitation (exc[i] >> Qnew)
+ int16 Qnew, (i) : exc scaling = 0(min) to 8(max)
+ int16 sig_hi[], (o) /16 : synthesis high
+ int16 sig_lo[], (o) /16 : synthesis low
+ int16 lg (i) : size of filtering
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Do the synthesis filtering 1/A(z) 16 and 32-bits version
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_mem_funcs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwb_math_op.h"
+#include "pvamrwbdecoder_cnst.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void wb_syn_filt(
+ int16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ int16 m, /* (i) : order of LP filter */
+ int16 x[], /* (i) : input signal */
+ int16 y[], /* (o) : output signal */
+ int16 lg, /* (i) : size of filtering */
+ int16 mem[], /* (i/o) : memory associated with this filtering. */
+ int16 update, /* (i) : 0=no update, 1=update of memory. */
+ int16 y_buf[]
+)
+{
+
+ int16 i, j;
+ int32 L_tmp1;
+ int32 L_tmp2;
+ int32 L_tmp3;
+ int32 L_tmp4;
+ int16 *yy;
+
+ /* copy initial filter states into synthesis buffer */
+ pv_memcpy(y_buf, mem, m*sizeof(*yy));
+
+ yy = &y_buf[m];
+
+ /* Do the filtering. */
+
+ for (i = 0; i < lg >> 2; i++)
+ {
+ L_tmp1 = -((int32)x[(i<<2)] << 11);
+ L_tmp2 = -((int32)x[(i<<2)+1] << 11);
+ L_tmp3 = -((int32)x[(i<<2)+2] << 11);
+ L_tmp4 = -((int32)x[(i<<2)+3] << 11);
+
+ /* a[] uses Q12 and abs(a) =< 1 */
+
+ L_tmp1 = fxp_mac_16by16(yy[(i<<2) -3], a[3], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(yy[(i<<2) -2], a[3], L_tmp2);
+ L_tmp1 = fxp_mac_16by16(yy[(i<<2) -2], a[2], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(yy[(i<<2) -1], a[2], L_tmp2);
+ L_tmp1 = fxp_mac_16by16(yy[(i<<2) -1], a[1], L_tmp1);
+
+ for (j = 4; j < m; j += 2)
+ {
+ L_tmp1 = fxp_mac_16by16(yy[(i<<2)-1 - j], a[j+1], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(yy[(i<<2) - j], a[j+1], L_tmp2);
+ L_tmp1 = fxp_mac_16by16(yy[(i<<2) - j], a[j ], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(yy[(i<<2)+1 - j], a[j ], L_tmp2);
+ L_tmp3 = fxp_mac_16by16(yy[(i<<2)+1 - j], a[j+1], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(yy[(i<<2)+2 - j], a[j+1], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(yy[(i<<2)+2 - j], a[j ], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(yy[(i<<2)+3 - j], a[j ], L_tmp4);
+ }
+
+ L_tmp1 = fxp_mac_16by16(yy[(i<<2) - j], a[j], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(yy[(i<<2)+1 - j], a[j], L_tmp2);
+ L_tmp3 = fxp_mac_16by16(yy[(i<<2)+2 - j], a[j], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(yy[(i<<2)+3 - j], a[j], L_tmp4);
+
+ L_tmp1 = shl_int32(L_tmp1, 4);
+
+ y[(i<<2)] = yy[(i<<2)] = amr_wb_round(-L_tmp1);
+
+ L_tmp2 = fxp_mac_16by16(yy[(i<<2)], a[1], L_tmp2);
+
+ L_tmp2 = shl_int32(L_tmp2, 4);
+
+ y[(i<<2)+1] = yy[(i<<2)+1] = amr_wb_round(-L_tmp2);
+
+ L_tmp3 = fxp_mac_16by16(yy[(i<<2) - 1], a[3], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(yy[(i<<2)], a[3], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(yy[(i<<2)], a[2], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(yy[(i<<2) + 1], a[2], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(yy[(i<<2) + 1], a[1], L_tmp3);
+
+ L_tmp3 = shl_int32(L_tmp3, 4);
+
+ y[(i<<2)+2] = yy[(i<<2)+2] = amr_wb_round(-L_tmp3);
+
+ L_tmp4 = fxp_mac_16by16(yy[(i<<2)+2], a[1], L_tmp4);
+
+ L_tmp4 = shl_int32(L_tmp4, 4);
+
+ y[(i<<2)+3] = yy[(i<<2)+3] = amr_wb_round(-L_tmp4);
+ }
+
+
+ /* Update memory if required */
+
+ if (update)
+ {
+ pv_memcpy(mem, &y[lg - m], m*sizeof(*y));
+ }
+
+ return;
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void Syn_filt_32(
+ int16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ int16 m, /* (i) : order of LP filter */
+ int16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
+ int16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
+ int16 sig_hi[], /* (o) /16 : synthesis high */
+ int16 sig_lo[], /* (o) /16 : synthesis low */
+ int16 lg /* (i) : size of filtering */
+)
+{
+ int16 i, k, a0;
+ int32 L_tmp1;
+ int32 L_tmp2;
+ int32 L_tmp3;
+ int32 L_tmp4;
+
+ a0 = 9 - Qnew; /* input / 16 and >>Qnew */
+
+ /* Do the filtering. */
+
+ for (i = 0; i < lg >> 1; i++)
+ {
+
+ L_tmp3 = 0;
+ L_tmp4 = 0;
+
+ L_tmp1 = fxp_mul_16by16(sig_lo[(i<<1) - 1], a[1]);
+ L_tmp2 = fxp_mul_16by16(sig_hi[(i<<1) - 1], a[1]);
+
+ for (k = 2; k < m; k += 2)
+ {
+
+ L_tmp1 = fxp_mac_16by16(sig_lo[(i<<1)-1 - k], a[k+1], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(sig_hi[(i<<1)-1 - k], a[k+1], L_tmp2);
+ L_tmp1 = fxp_mac_16by16(sig_lo[(i<<1) - k], a[k ], L_tmp1);
+ L_tmp2 = fxp_mac_16by16(sig_hi[(i<<1) - k], a[k ], L_tmp2);
+ L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1) - k], a[k+1], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(sig_hi[(i<<1) - k], a[k+1], L_tmp4);
+ L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1)+1 - k], a[k ], L_tmp3);
+ L_tmp4 = fxp_mac_16by16(sig_hi[(i<<1)+1 - k], a[k ], L_tmp4);
+ }
+
+ L_tmp1 = -fxp_mac_16by16(sig_lo[(i<<1) - k], a[k], L_tmp1);
+ L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1)+1 - k], a[k], L_tmp3);
+ L_tmp2 = fxp_mac_16by16(sig_hi[(i<<1) - k], a[k], L_tmp2);
+ L_tmp4 = fxp_mac_16by16(sig_hi[(i<<1)+1 - k], a[k], L_tmp4);
+
+
+
+ L_tmp1 >>= 11; /* -4 : sig_lo[i] << 4 */
+
+ int64 sig_tmp;
+ sig_tmp = (int64)L_tmp1 + (int32)(exc[(i<<1)] << a0);
+ L_tmp1 = (int32)(sig_tmp - (L_tmp2 << 1));
+
+ /* sig_hi = bit16 to bit31 of synthesis */
+ L_tmp1 = shl_int32(L_tmp1, 3); /* ai in Q12 */
+
+ sig_hi[(i<<1)] = (int16)(L_tmp1 >> 16);
+
+ L_tmp4 = fxp_mac_16by16((int16)(L_tmp1 >> 16), a[1], L_tmp4);
+
+ /* sig_lo = bit4 to bit15 of synthesis */
+ /* L_tmp1 >>= 4 : sig_lo[i] >> 4 */
+ sig_lo[(i<<1)] = (int16)((L_tmp1 >> 4) - ((L_tmp1 >> 16) << 12));
+
+ L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1)], a[1], L_tmp3);
+ L_tmp3 = -L_tmp3 >> 11;
+
+ sig_tmp = (int64)L_tmp3 + (int32)(exc[(i<<1)+1] << a0);
+ L_tmp3 = (int32)(sig_tmp - (L_tmp4 << 1));
+ /* sig_hi = bit16 to bit31 of synthesis */
+ L_tmp3 = shl_int32(L_tmp3, 3); /* ai in Q12 */
+ sig_hi[(i<<1)+1] = (int16)(L_tmp3 >> 16);
+
+ /* sig_lo = bit4 to bit15 of synthesis */
+ /* L_tmp1 >>= 4 : sig_lo[i] >> 4 */
+ sig_lo[(i<<1)+1] = (int16)((L_tmp3 >> 4) - (sig_hi[(i<<1)+1] << 12));
+ }
+
+}
+
+
diff --git a/media/codecs/amrwb/dec/src/weight_amrwb_lpc.cpp b/media/codecs/amrwb/dec/src/weight_amrwb_lpc.cpp
new file mode 100644
index 0000000..63d2e00
--- /dev/null
+++ b/media/codecs/amrwb/dec/src/weight_amrwb_lpc.cpp
@@ -0,0 +1,135 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/****************************************************************************************
+Portions of this file are derived from the following 3GPP standard:
+
+ 3GPP TS 26.173
+ ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
+ Available from http://www.3gpp.org
+
+(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
+Permission to distribute, modify and use this file under the standard license
+terms listed above has been obtained from the copyright holder.
+****************************************************************************************/
+/*
+------------------------------------------------------------------------------
+
+
+
+ Filename: weight_amrwb_lpc.cpp
+
+ Date: 05/08/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ int16 a[], (i) Q12 : a[m+1] LPC coefficients
+ int16 ap[], (o) Q12 : Spectral expanded LPC coefficients
+ int16 gamma, (i) Q15 : Spectral expansion factor.
+ int16 m (i) : LPC order.
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Weighting of LPC coefficients.
+ ap[i] = a[i] (gamma i)
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_amr_wb_type_defs.h"
+#include "pvamrwbdecoder_basic_op.h"
+#include "pvamrwbdecoder_acelp.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void weight_amrwb_lpc(
+ int16 a[], /* (i) Q12 : a[m+1] LPC coefficients */
+ int16 ap[], /* (o) Q12 : Spectral expanded LPC coefficients */
+ int16 gamma, /* (i) Q15 : Spectral expansion factor. */
+ int16 m /* (i) : LPC order. */
+)
+{
+ int16 i, fac;
+ int32 roundFactor = 0x00004000L;
+ ap[0] = a[0];
+ fac = gamma;
+ for (i = 1; i < m; i++)
+ {
+ ap[i] = (int16)(fxp_mac_16by16(a[i], fac, roundFactor) >> 15);
+ fac = (int16)(fxp_mac_16by16(fac, gamma, roundFactor) >> 15);
+ }
+ ap[i] = (int16)(fxp_mac_16by16(a[i], fac, roundFactor) >> 15);
+
+ return;
+}
diff --git a/media/codecs/amrwb/dec/test/AmrwbDecTestEnvironment.h b/media/codecs/amrwb/dec/test/AmrwbDecTestEnvironment.h
new file mode 100644
index 0000000..84d337d
--- /dev/null
+++ b/media/codecs/amrwb/dec/test/AmrwbDecTestEnvironment.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AMRWBDEC_TEST_ENVIRONMENT_H__
+#define __AMRWBDEC_TEST_ENVIRONMENT_H__
+
+#include <gtest/gtest.h>
+
+#include <getopt.h>
+
+using namespace std;
+
+class AmrwbDecTestEnvironment : public ::testing::Environment {
+ public:
+ AmrwbDecTestEnvironment() : res("/data/local/tmp/") {}
+
+ // Parses the command line arguments
+ int initFromOptions(int argc, char **argv);
+
+ void setRes(const char *_res) { res = _res; }
+
+ const string getRes() const { return res; }
+
+ private:
+ string res;
+};
+
+int AmrwbDecTestEnvironment::initFromOptions(int argc, char **argv) {
+ static struct option options[] = {{"res", required_argument, 0, 'P'}, {0, 0, 0, 0}};
+
+ while (true) {
+ int index = 0;
+ int c = getopt_long(argc, argv, "P:", options, &index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'P':
+ setRes(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr,
+ "unrecognized option: %s\n\n"
+ "usage: %s <gtest options> <test options>\n\n"
+ "test options are:\n\n"
+ "-P, --path: Resource files directory location\n",
+ argv[optind ?: 1], argv[0]);
+ return 2;
+ }
+ return 0;
+}
+
+#endif // __AMRWBDEC_TEST_ENVIRONMENT_H__
diff --git a/media/codecs/amrwb/dec/test/AmrwbDecoderTest.cpp b/media/codecs/amrwb/dec/test/AmrwbDecoderTest.cpp
new file mode 100644
index 0000000..7221b92
--- /dev/null
+++ b/media/codecs/amrwb/dec/test/AmrwbDecoderTest.cpp
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "AmrwbDecoderTest"
+#define OUTPUT_FILE "/data/local/tmp/amrwbDecode.out"
+
+#include <utils/Log.h>
+
+#include <audio_utils/sndfile.h>
+#include <stdio.h>
+
+#include "pvamrwbdecoder.h"
+#include "pvamrwbdecoder_api.h"
+
+#include "AmrwbDecTestEnvironment.h"
+
+// Constants for AMR-WB.
+constexpr int32_t kInputBufferSize = 64;
+constexpr int32_t kSamplesPerFrame = 320;
+constexpr int32_t kBitsPerSample = 16;
+constexpr int32_t kSampleRate = 16000;
+constexpr int32_t kChannels = 1;
+constexpr int32_t kMaxSourceDataUnitSize = KAMRWB_NB_BITS_MAX * sizeof(int16_t);
+constexpr int32_t kOutputBufferSize = kSamplesPerFrame * kBitsPerSample / 8;
+const int32_t kFrameSizes[16] = {17, 23, 32, 36, 40, 46, 50, 58, 60, -1, -1, -1, -1, -1, -1, -1};
+constexpr int32_t kNumFrameReset = 150;
+
+constexpr int32_t kMaxCount = 10;
+
+static AmrwbDecTestEnvironment *gEnv = nullptr;
+
+class AmrwbDecoderTest : public ::testing::TestWithParam<string> {
+ public:
+ AmrwbDecoderTest() : mFpInput(nullptr) {}
+
+ ~AmrwbDecoderTest() {
+ if (mFpInput) {
+ fclose(mFpInput);
+ mFpInput = nullptr;
+ }
+ }
+
+ FILE *mFpInput;
+ int32_t DecodeFrames(int16_t *decoderCookie, void *decoderBuf, SNDFILE *outFileHandle,
+ int32_t frameCount = INT32_MAX);
+ SNDFILE *openOutputFile(SF_INFO *sfInfo);
+};
+
+SNDFILE *AmrwbDecoderTest::openOutputFile(SF_INFO *sfInfo) {
+ memset(sfInfo, 0, sizeof(SF_INFO));
+ sfInfo->channels = kChannels;
+ sfInfo->format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ sfInfo->samplerate = kSampleRate;
+ SNDFILE *outFileHandle = sf_open(OUTPUT_FILE, SFM_WRITE, sfInfo);
+ return outFileHandle;
+}
+
+int32_t AmrwbDecoderTest::DecodeFrames(int16_t *decoderCookie, void *decoderBuf,
+ SNDFILE *outFileHandle, int32_t frameCount) {
+ uint8_t inputBuf[kInputBufferSize];
+ int16_t inputSampleBuf[kMaxSourceDataUnitSize];
+ int16_t outputBuf[kOutputBufferSize];
+ RX_State_wb rx_state{};
+
+ while (frameCount > 0) {
+ uint8_t modeByte;
+ int32_t bytesRead = fread(&modeByte, 1, 1, mFpInput);
+ if (bytesRead != 1) break;
+
+ int16 mode = ((modeByte >> 3) & 0x0f);
+ if (mode >= 9) {
+ // Produce silence for comfort noise, speech lost and no data.
+ int32_t outputBufferSize = kSamplesPerFrame * kBitsPerSample / 8;
+ memset(outputBuf, 0, outputBufferSize);
+ } else {
+ // Read rest of the frame.
+ int32_t frameSize = kFrameSizes[mode];
+ // AMR-WB file format cannot have mode 10, 11, 12 and 13.
+ if (frameSize < 0) {
+ ALOGE("Illegal frame mode");
+ return -1;
+ }
+ bytesRead = fread(inputBuf, 1, frameSize, mFpInput);
+ if (bytesRead != frameSize) break;
+
+ int16 frameMode = mode;
+ int16 frameType;
+ mime_unsorting(inputBuf, inputSampleBuf, &frameType, &frameMode, 1, &rx_state);
+
+ int16_t numSamplesOutput;
+ pvDecoder_AmrWb(frameMode, inputSampleBuf, outputBuf, &numSamplesOutput, decoderBuf,
+ frameType, decoderCookie);
+ if (numSamplesOutput != kSamplesPerFrame) {
+ ALOGE("Failed to decode the input file");
+ return -1;
+ }
+ for (int count = 0; count < kSamplesPerFrame; ++count) {
+ /* Delete the 2 LSBs (14-bit output) */
+ outputBuf[count] &= 0xfffc;
+ }
+ }
+ sf_writef_short(outFileHandle, outputBuf, kSamplesPerFrame / kChannels);
+ frameCount--;
+ }
+ return 0;
+}
+
+TEST_F(AmrwbDecoderTest, MultiCreateAmrwbDecoderTest) {
+ uint32_t memRequirements = pvDecoder_AmrWbMemRequirements();
+ void *decoderBuf = malloc(memRequirements);
+ ASSERT_NE(decoderBuf, nullptr)
+ << "Failed to allocate decoder memory of size " << memRequirements;
+
+ // Create AMR-WB decoder instance.
+ void *amrHandle = nullptr;
+ int16_t *decoderCookie;
+ for (int count = 0; count < kMaxCount; count++) {
+ pvDecoder_AmrWb_Init(&amrHandle, decoderBuf, &decoderCookie);
+ ASSERT_NE(amrHandle, nullptr) << "Failed to initialize decoder";
+ ALOGV("Decoder created successfully");
+ }
+ if (decoderBuf) {
+ free(decoderBuf);
+ decoderBuf = nullptr;
+ }
+}
+
+TEST_P(AmrwbDecoderTest, DecodeTest) {
+ uint32_t memRequirements = pvDecoder_AmrWbMemRequirements();
+ void *decoderBuf = malloc(memRequirements);
+ ASSERT_NE(decoderBuf, nullptr)
+ << "Failed to allocate decoder memory of size " << memRequirements;
+
+ void *amrHandle = nullptr;
+ int16_t *decoderCookie;
+ pvDecoder_AmrWb_Init(&amrHandle, decoderBuf, &decoderCookie);
+ ASSERT_NE(amrHandle, nullptr) << "Failed to initialize decoder";
+
+ string inputFile = gEnv->getRes() + GetParam();
+ mFpInput = fopen(inputFile.c_str(), "rb");
+ ASSERT_NE(mFpInput, nullptr) << "Error opening input file " << inputFile;
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ SNDFILE *outFileHandle = openOutputFile(&sfInfo);
+ ASSERT_NE(outFileHandle, nullptr) << "Error opening output file for writing decoded output";
+
+ int32_t decoderErr = DecodeFrames(decoderCookie, decoderBuf, outFileHandle);
+ ASSERT_EQ(decoderErr, 0) << "DecodeFrames returned error";
+
+ sf_close(outFileHandle);
+ if (decoderBuf) {
+ free(decoderBuf);
+ decoderBuf = nullptr;
+ }
+}
+
+TEST_P(AmrwbDecoderTest, ResetDecoderTest) {
+ uint32_t memRequirements = pvDecoder_AmrWbMemRequirements();
+ void *decoderBuf = malloc(memRequirements);
+ ASSERT_NE(decoderBuf, nullptr)
+ << "Failed to allocate decoder memory of size " << memRequirements;
+
+ void *amrHandle = nullptr;
+ int16_t *decoderCookie;
+ pvDecoder_AmrWb_Init(&amrHandle, decoderBuf, &decoderCookie);
+ ASSERT_NE(amrHandle, nullptr) << "Failed to initialize decoder";
+
+ string inputFile = gEnv->getRes() + GetParam();
+ mFpInput = fopen(inputFile.c_str(), "rb");
+ ASSERT_NE(mFpInput, nullptr) << "Error opening input file " << inputFile;
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ SNDFILE *outFileHandle = openOutputFile(&sfInfo);
+ ASSERT_NE(outFileHandle, nullptr) << "Error opening output file for writing decoded output";
+
+ // Decode 150 frames first
+ int32_t decoderErr = DecodeFrames(decoderCookie, decoderBuf, outFileHandle, kNumFrameReset);
+ ASSERT_EQ(decoderErr, 0) << "DecodeFrames returned error";
+
+ // Reset Decoder
+ pvDecoder_AmrWb_Reset(decoderBuf, 1);
+
+ // Start decoding again
+ decoderErr = DecodeFrames(decoderCookie, decoderBuf, outFileHandle);
+ ASSERT_EQ(decoderErr, 0) << "DecodeFrames returned error";
+
+ sf_close(outFileHandle);
+ if (decoderBuf) {
+ free(decoderBuf);
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(AmrwbDecoderTestAll, AmrwbDecoderTest,
+ ::testing::Values(("bbb_amrwb_1ch_14kbps_16000hz.amrwb"),
+ ("bbb_16000hz_1ch_9kbps_amrwb_30sec.amrwb")));
+
+int main(int argc, char **argv) {
+ gEnv = new AmrwbDecTestEnvironment();
+ ::testing::AddGlobalTestEnvironment(gEnv);
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = gEnv->initFromOptions(argc, argv);
+ if (status == 0) {
+ status = RUN_ALL_TESTS();
+ ALOGV("Test result = %d\n", status);
+ }
+ return status;
+}
diff --git a/media/codecs/amrwb/dec/test/Android.bp b/media/codecs/amrwb/dec/test/Android.bp
new file mode 100644
index 0000000..968215a
--- /dev/null
+++ b/media/codecs/amrwb/dec/test/Android.bp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_test {
+ name: "AmrwbDecoderTest",
+ gtest: true,
+
+ srcs: [
+ "AmrwbDecoderTest.cpp",
+ ],
+
+ static_libs: [
+ "libstagefright_amrwbdec",
+ "libsndfile",
+ "libaudioutils",
+ ],
+
+ shared_libs: [
+ "liblog",
+ ],
+
+ cflags: [
+ "-Werror",
+ "-Wall",
+ ],
+
+ sanitize: {
+ cfi: true,
+ misc_undefined: [
+ "unsigned-integer-overflow",
+ "signed-integer-overflow",
+ ],
+ },
+}
diff --git a/media/codecs/amrwb/dec/test/AndroidTest.xml b/media/codecs/amrwb/dec/test/AndroidTest.xml
new file mode 100644
index 0000000..e211a1f
--- /dev/null
+++ b/media/codecs/amrwb/dec/test/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for Amr-wb Decoder unit test">
+ <option name="test-suite-tag" value="AmrwbDecoderTest" />
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="AmrwbDecoderTest->/data/local/tmp/AmrwbDecoderTest" />
+ <option name="push-file"
+ key="https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrwb/test/AmrwbDecoderTest.zip?unzip=true"
+ value="/data/local/tmp/AmrwbDecoderTestRes/" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="AmrwbDecoderTest" />
+ <option name="native-test-flag" value="-P /data/local/tmp/AmrwbDecoderTestRes/" />
+ </test>
+</configuration>
diff --git a/media/codecs/amrwb/dec/test/README.md b/media/codecs/amrwb/dec/test/README.md
new file mode 100644
index 0000000..a9d5c06
--- /dev/null
+++ b/media/codecs/amrwb/dec/test/README.md
@@ -0,0 +1,39 @@
+## Media Testing ##
+---
+#### AMR-WB Decoder :
+The Amr-Wb Decoder Test Suite validates the amrwb decoder available in libstagefright.
+
+Run the following steps to build the test suite:
+```
+m AmrwbDecoderTest
+```
+
+The 32-bit binaries will be created in the following path : ${OUT}/data/nativetest/
+
+The 64-bit binaries will be created in the following path : ${OUT}/data/nativetest64/
+
+To test 64-bit binary push binaries from nativetest64.
+```
+adb push ${OUT}/data/nativetest64/AmrwbDecoderTest/AmrwbDecoderTest /data/local/tmp/
+```
+
+To test 32-bit binary push binaries from nativetest.
+```
+adb push ${OUT}/data/nativetest/AmrwbDecoderTest/AmrwbDecoderTest /data/local/tmp/
+```
+
+The resource file for the tests is taken from [here](https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrwb/test/AmrwbDecoderTest.zip). Download, unzip and push these files into device for testing.
+
+```
+adb push AmrwbDecoderTestRes/. /data/local/tmp/
+```
+
+usage: AmrwbDecoderTest -P \<path_to_folder\>
+```
+adb shell /data/local/tmp/AmrwbDecoderTest -P /data/local/tmp/AmrwbDecoderTestRes/
+```
+Alternatively, the test can also be run using atest command.
+
+```
+atest AmrwbDecoderTest -- --enable-module-dynamic-download=true
+```
diff --git a/media/codecs/amrwb/dec/test/amrwbdec_test.cpp b/media/codecs/amrwb/dec/test/amrwbdec_test.cpp
new file mode 100644
index 0000000..1bc90e8
--- /dev/null
+++ b/media/codecs/amrwb/dec/test/amrwbdec_test.cpp
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include "pvamrwbdecoder.h"
+#include <audio_utils/sndfile.h>
+
+// Constants for AMR-WB.
+enum {
+ kInputBufferSize = 64,
+ kSamplesPerFrame = 320,
+ kBitsPerSample = 16,
+ kOutputBufferSize = kSamplesPerFrame * kBitsPerSample/8,
+ kSampleRate = 16000,
+ kChannels = 1,
+ kFileHeaderSize = 9,
+ kMaxSourceDataUnitSize = 477 * sizeof(int16_t)
+};
+
+const uint32_t kFrameSizes[] = { 17, 23, 32, 36, 40, 46, 50, 58, 60 };
+
+int main(int argc, char *argv[]) {
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage %s <input file> <output file>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ // Open the input file.
+ FILE* fpInput = fopen(argv[1], "rb");
+ if (fpInput == NULL) {
+ fprintf(stderr, "Could not open %s\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ // Validate the input AMR file.
+ char header[kFileHeaderSize];
+ int bytesRead = fread(header, 1, kFileHeaderSize, fpInput);
+ if ((bytesRead != kFileHeaderSize) ||
+ (memcmp(header, "#!AMR-WB\n", kFileHeaderSize) != 0)) {
+ fprintf(stderr, "Invalid AMR-WB file\n");
+ fclose(fpInput);
+ return EXIT_FAILURE;
+ }
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ memset(&sfInfo, 0, sizeof(SF_INFO));
+ sfInfo.channels = kChannels;
+ sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ sfInfo.samplerate = kSampleRate;
+ SNDFILE *handle = sf_open(argv[2], SFM_WRITE, &sfInfo);
+ if (handle == NULL) {
+ fprintf(stderr, "Could not create %s\n", argv[2]);
+ fclose(fpInput);
+ return EXIT_FAILURE;
+ }
+
+ // Allocate the decoder memory.
+ uint32_t memRequirements = pvDecoder_AmrWbMemRequirements();
+ void *decoderBuf = malloc(memRequirements);
+ assert(decoderBuf != NULL);
+
+ // Create AMR-WB decoder instance.
+ void *amrHandle;
+ int16_t *decoderCookie;
+ pvDecoder_AmrWb_Init(&amrHandle, decoderBuf, &decoderCookie);
+
+ // Allocate input buffer.
+ uint8_t *inputBuf = (uint8_t*) malloc(kInputBufferSize);
+ assert(inputBuf != NULL);
+
+ // Allocate input sample buffer.
+ int16_t *inputSampleBuf = (int16_t*) malloc(kMaxSourceDataUnitSize);
+ assert(inputSampleBuf != NULL);
+
+ // Allocate output buffer.
+ int16_t *outputBuf = (int16_t*) malloc(kOutputBufferSize);
+ assert(outputBuf != NULL);
+
+ // Decode loop.
+ int retVal = EXIT_SUCCESS;
+ RX_State_wb rx_state{};
+ while (1) {
+ // Read mode.
+ uint8_t modeByte;
+ bytesRead = fread(&modeByte, 1, 1, fpInput);
+ if (bytesRead != 1) break;
+ int16 mode = ((modeByte >> 3) & 0x0f);
+
+ // AMR-WB file format cannot have mode 10, 11, 12 and 13.
+ if (mode >= 10 && mode <= 13) {
+ fprintf(stderr, "Encountered illegal frame type %d\n", mode);
+ retVal = EXIT_FAILURE;
+ break;
+ }
+
+ if (mode >= 9) {
+ // Produce silence for comfort noise, speech lost and no data.
+ memset(outputBuf, 0, kOutputBufferSize);
+ } else /* if (mode < 9) */ {
+ // Read rest of the frame.
+ int32_t frameSize = kFrameSizes[mode];
+ bytesRead = fread(inputBuf, 1, frameSize, fpInput);
+ if (bytesRead != frameSize) break;
+
+ int16 frameType, frameMode;
+ frameMode = mode;
+ mime_unsorting(
+ (uint8_t *)inputBuf,
+ inputSampleBuf,
+ &frameType, &frameMode, 1, &rx_state);
+
+ int16_t numSamplesOutput;
+ pvDecoder_AmrWb(
+ frameMode, inputSampleBuf,
+ outputBuf,
+ &numSamplesOutput,
+ decoderBuf, frameType, decoderCookie);
+
+ if (numSamplesOutput != kSamplesPerFrame) {
+ fprintf(stderr, "Decoder encountered error\n");
+ retVal = EXIT_FAILURE;
+ break;
+ }
+
+ for (int i = 0; i < kSamplesPerFrame; ++i) {
+ outputBuf[i] &= 0xfffC;
+ }
+ }
+
+ // Write output to wav.
+ sf_writef_short(handle, outputBuf, kSamplesPerFrame / kChannels);
+ }
+
+ // Close input and output file.
+ fclose(fpInput);
+ sf_close(handle);
+
+ // Free allocated memory.
+ free(inputBuf);
+ free(inputSampleBuf);
+ free(outputBuf);
+
+ return retVal;
+}
diff --git a/media/codecs/amrwb/enc/Android.bp b/media/codecs/amrwb/enc/Android.bp
new file mode 100644
index 0000000..1521a45
--- /dev/null
+++ b/media/codecs/amrwb/enc/Android.bp
@@ -0,0 +1,149 @@
+cc_library_static {
+ name: "libstagefright_amrwbenc",
+ vendor_available: true,
+ min_sdk_version: "29",
+
+ srcs: [
+ "src/autocorr.c",
+ "src/az_isp.c",
+ "src/bits.c",
+ "src/c2t64fx.c",
+ "src/c4t64fx.c",
+ "src/convolve.c",
+ "src/cor_h_x.c",
+ "src/decim54.c",
+ "src/deemph.c",
+ "src/dtx.c",
+ "src/g_pitch.c",
+ "src/gpclip.c",
+ "src/homing.c",
+ "src/hp400.c",
+ "src/hp50.c",
+ "src/hp6k.c",
+ "src/hp_wsp.c",
+ "src/int_lpc.c",
+ "src/isp_az.c",
+ "src/isp_isf.c",
+ "src/lag_wind.c",
+ "src/levinson.c",
+ "src/log2.c",
+ "src/lp_dec2.c",
+ "src/math_op.c",
+ "src/oper_32b.c",
+ "src/p_med_ol.c",
+ "src/pit_shrp.c",
+ "src/pitch_f4.c",
+ "src/pred_lt4.c",
+ "src/preemph.c",
+ "src/q_gain2.c",
+ "src/q_pulse.c",
+ "src/qisf_ns.c",
+ "src/qpisf_2s.c",
+ "src/random.c",
+ "src/residu.c",
+ "src/scale.c",
+ "src/stream.c",
+ "src/syn_filt.c",
+ "src/updt_tar.c",
+ "src/util.c",
+ "src/voAMRWBEnc.c",
+ "src/voicefac.c",
+ "src/wb_vad.c",
+ "src/weight_a.c",
+ "src/mem_align.c",
+ ],
+
+ arch: {
+ arm: {
+ srcs: [
+ "src/asm/ARMV5E/convolve_opt.s",
+ "src/asm/ARMV5E/cor_h_vec_opt.s",
+ "src/asm/ARMV5E/Deemph_32_opt.s",
+ "src/asm/ARMV5E/Dot_p_opt.s",
+ "src/asm/ARMV5E/Filt_6k_7k_opt.s",
+ "src/asm/ARMV5E/Norm_Corr_opt.s",
+ "src/asm/ARMV5E/pred_lt4_1_opt.s",
+ "src/asm/ARMV5E/residu_asm_opt.s",
+ "src/asm/ARMV5E/scale_sig_opt.s",
+ "src/asm/ARMV5E/Syn_filt_32_opt.s",
+ "src/asm/ARMV5E/syn_filt_opt.s",
+ ],
+
+ cflags: [
+ "-DARM",
+ "-DASM_OPT",
+ ],
+ local_include_dirs: ["src/asm/ARMV5E"],
+
+ instruction_set: "arm",
+
+ neon: {
+ exclude_srcs: [
+ "src/asm/ARMV5E/convolve_opt.s",
+ "src/asm/ARMV5E/cor_h_vec_opt.s",
+ "src/asm/ARMV5E/Deemph_32_opt.s",
+ "src/asm/ARMV5E/Dot_p_opt.s",
+ "src/asm/ARMV5E/Filt_6k_7k_opt.s",
+ "src/asm/ARMV5E/Norm_Corr_opt.s",
+ "src/asm/ARMV5E/pred_lt4_1_opt.s",
+ "src/asm/ARMV5E/residu_asm_opt.s",
+ "src/asm/ARMV5E/scale_sig_opt.s",
+ "src/asm/ARMV5E/Syn_filt_32_opt.s",
+ "src/asm/ARMV5E/syn_filt_opt.s",
+ ],
+
+ srcs: [
+ "src/asm/ARMV7/convolve_neon.s",
+ "src/asm/ARMV7/cor_h_vec_neon.s",
+ "src/asm/ARMV7/Deemph_32_neon.s",
+ "src/asm/ARMV7/Dot_p_neon.s",
+ "src/asm/ARMV7/Filt_6k_7k_neon.s",
+ "src/asm/ARMV7/Norm_Corr_neon.s",
+ "src/asm/ARMV7/pred_lt4_1_neon.s",
+ "src/asm/ARMV7/residu_asm_neon.s",
+ "src/asm/ARMV7/scale_sig_neon.s",
+ "src/asm/ARMV7/Syn_filt_32_neon.s",
+ "src/asm/ARMV7/syn_filt_neon.s",
+ ],
+
+ // don't actually generate neon instructions, see bug 26932980
+ cflags: [
+ "-DARMV7",
+ "-mfpu=vfpv3",
+ ],
+ local_include_dirs: [
+ "src/asm/ARMV5E",
+ "src/asm/ARMV7",
+ ],
+ },
+
+ },
+ },
+
+ include_dirs: [
+ "frameworks/av/include",
+ "frameworks/av/media/libstagefright/include",
+ ],
+
+ local_include_dirs: ["src"],
+ export_include_dirs: ["inc"],
+
+ shared_libs: [
+ "libstagefright_enc_common",
+ "liblog",
+ ],
+
+ cflags: ["-Werror"],
+ sanitize: {
+ cfi: true,
+ },
+
+ host_supported: true,
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+
diff --git a/media/codecs/amrwb/enc/MODULE_LICENSE_APACHE2 b/media/codecs/amrwb/enc/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/amrwb/enc/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/amrwb/enc/NOTICE b/media/codecs/amrwb/enc/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/amrwb/enc/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/amrwb/enc/SampleCode/AMRWB_E_SAMPLE.c b/media/codecs/amrwb/enc/SampleCode/AMRWB_E_SAMPLE.c
new file mode 100644
index 0000000..7282de4
--- /dev/null
+++ b/media/codecs/amrwb/enc/SampleCode/AMRWB_E_SAMPLE.c
@@ -0,0 +1,369 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+#ifdef LINUX
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "voAMRWB.h"
+#include "cmnMemory.h"
+
+#define VOAMRWB_RFC3267_HEADER_INFO "#!AMR-WB\n"
+
+#define INPUT_SIZE 640
+#define OUTPUT_SIZE 1024
+unsigned char InputBuf[INPUT_SIZE];
+unsigned char OutputBuf[OUTPUT_SIZE];
+
+void usage (void) {
+ printf ("AMR_WB Encoder HELP Displays this text\n");
+ printf ("\n");
+ printf ("Usage:\n");
+ printf ("AMRWBEnc [options] Input_file output_file \n");
+ printf ("\n");
+ printf ("Options +M* +F* +DTX \n");
+ printf ("Support \n");
+ printf ("Options +M* for seting compression bitrate mode, default is 23.85kbps\n");
+ printf (" +M0 = 6.6kbps \n");
+ printf (" +M1 = 8.85kbps \n");
+ printf (" +M2 = 12.65kbps \n");
+ printf (" +M3 = 14.25kbps \n");
+ printf (" +M4 = 15.58kbps \n");
+ printf (" +M5 = 18.25kbps \n");
+ printf (" +M6 = 19.85kbps \n");
+ printf (" +M7 = 23.05kbps \n");
+ printf (" +M8 = 23.85kbps \n");
+ printf ("\n");
+ printf ("Options +F* for setting output frame Type, default is RFC3267 \n");
+ printf ("+F0 for AMR_WB Defualt bit extern short data frame type \n");
+ printf ("+F1 for AMR_WB_ITU bit extern short data frame type \n");
+ printf ("+F2 for RFC3267\n ");
+ printf ("\n");
+ printf ("Options +DTX enable DTX mode, default is disable.\n");
+ printf ("File names, input raw PCM data, and output is AMR_WB bit-stream file.\n");
+ printf ("\n");
+}
+
+int GetNextBuf(FILE* inFile,unsigned char* dst,int size)
+{
+ int size2 = (int)fread(dst, sizeof(signed char), size,inFile);
+ return size2;
+}
+
+typedef int (VO_API * VOGETAUDIOENCAPI) (VO_AUDIO_CODECAPI * pEncHandle);
+
+int encode(
+ int mode,
+ short allow_dtx,
+ VOAMRWBFRAMETYPE frameType,
+ const char* srcfile,
+ const char* dstfile
+ )
+{
+ int ret = 0;
+ int returnCode;
+ FILE *fsrc = NULL;
+ FILE *fdst = NULL;
+ int framenum = 0;
+ int eofFile = 0;
+ int size1 = 0;
+ int Relens;
+
+ VO_AUDIO_CODECAPI AudioAPI;
+ VO_MEM_OPERATOR moper;
+ VO_CODEC_INIT_USERDATA useData;
+ VO_HANDLE hCodec = NULL;
+ VO_CODECBUFFER inData;
+ VO_CODECBUFFER outData;
+ VO_AUDIO_OUTPUTINFO outFormat;
+
+ unsigned char *inBuf = InputBuf;
+ unsigned char *outBuf = OutputBuf;
+
+
+#ifdef LINUX
+ void *handle = NULL;
+ void *pfunc;
+ VOGETAUDIOENCAPI pGetAPI;
+#endif
+
+ clock_t start, finish;
+ double duration = 0.0;
+
+ if ((fsrc = fopen (srcfile, "rb")) == NULL)
+ {
+ ret = -1;
+ goto safe_exit;
+ }
+
+ if ((fdst = fopen (dstfile, "wb")) == NULL)
+ {
+ ret = -1;
+ goto safe_exit;
+ }
+
+ moper.Alloc = cmnMemAlloc;
+ moper.Copy = cmnMemCopy;
+ moper.Free = cmnMemFree;
+ moper.Set = cmnMemSet;
+ moper.Check = cmnMemCheck;
+
+ useData.memflag = VO_IMF_USERMEMOPERATOR;
+ useData.memData = (VO_PTR)(&moper);
+
+#ifdef LINUX
+ handle = dlopen("libstagefright.so", RTLD_NOW);
+ if(handle == 0)
+ {
+ printf("open dll error......");
+ ret = -1;
+ goto safe_exit;
+ }
+
+ pfunc = dlsym(handle, "voGetAMRWBEncAPI");
+ if(pfunc == 0)
+ {
+ printf("open function error......");
+ ret = -1;
+ goto safe_exit;
+ }
+
+ pGetAPI = (VOGETAUDIOENCAPI)pfunc;
+
+ returnCode = pGetAPI(&AudioAPI);
+ if(returnCode)
+ {
+ printf("get APIs error......");
+ ret = -1;
+ goto safe_exit;
+ }
+#else
+ ret = voGetAMRWBEncAPI(&AudioAPI);
+ if(ret)
+ {
+ ret = -1;
+ printf("get APIs error......");
+ goto safe_exit;
+ }
+#endif
+
+ //####################################### Init Encoding Section #########################################
+ ret = AudioAPI.Init(&hCodec, VO_AUDIO_CodingAMRWB, &useData);
+
+ if(ret)
+ {
+ ret = -1;
+ printf("APIs init error......");
+ goto safe_exit;
+ }
+
+ Relens = GetNextBuf(fsrc,InputBuf,INPUT_SIZE);
+ if(Relens!=INPUT_SIZE && !feof(fsrc))
+ {
+ ret = -1; //Invalid magic number
+ printf("get next buffer error......");
+ goto safe_exit;
+ }
+
+ //###################################### set encode Mode ##################################################
+ ret = AudioAPI.SetParam(hCodec, VO_PID_AMRWB_FRAMETYPE, &frameType);
+ ret = AudioAPI.SetParam(hCodec, VO_PID_AMRWB_MODE, &mode);
+ ret = AudioAPI.SetParam(hCodec, VO_PID_AMRWB_DTX, &allow_dtx);
+
+ if(frameType == VOAMRWB_RFC3267)
+ {
+ /* write RFC3267 Header info to indicate single channel AMR file storage format */
+ size1 = (int)strlen(VOAMRWB_RFC3267_HEADER_INFO);
+ memcpy(outBuf, VOAMRWB_RFC3267_HEADER_INFO, size1);
+ outBuf += size1;
+ }
+
+ //####################################### Encoding Section #########################################
+ printf(" \n ---------------- Running -------------------------\n ");
+
+ do{
+ inData.Buffer = (unsigned char *)inBuf;
+ inData.Length = Relens;
+ outData.Buffer = outBuf;
+
+ start = clock();
+
+ /* decode one amr block */
+ returnCode = AudioAPI.SetInputData(hCodec,&inData);
+
+ do {
+ returnCode = AudioAPI.GetOutputData(hCodec,&outData, &outFormat);
+ if(returnCode == 0)
+ {
+ framenum++;
+ printf(" Frames processed: %d\r", framenum);
+ if(framenum == 1)
+ {
+ fwrite(OutputBuf, 1, outData.Length + size1, fdst);
+ fflush(fdst);
+ }
+ else
+ {
+ fwrite(outData.Buffer, 1, outData.Length, fdst);
+ fflush(fdst);
+ }
+ }
+ else if((unsigned)returnCode == VO_ERR_LICENSE_ERROR)
+ {
+ printf("Encoder time reach upper limit......");
+ goto safe_exit;
+ }
+ } while((unsigned)returnCode != VO_ERR_INPUT_BUFFER_SMALL);
+
+ finish = clock();
+ duration += finish - start;
+
+ if (!eofFile) {
+ Relens = GetNextBuf(fsrc, InputBuf, INPUT_SIZE);
+ inBuf = InputBuf;
+ if (feof(fsrc) && Relens == 0)
+ eofFile = 1;
+ }
+ } while (!eofFile && returnCode);
+ //####################################### End Encoding Section #########################################
+
+safe_exit:
+ returnCode = AudioAPI.Uninit(hCodec);
+
+ printf( "\n%2.5f seconds\n", (double)duration/CLOCKS_PER_SEC);
+
+ if (fsrc)
+ fclose(fsrc);
+ if (fdst)
+ fclose(fdst);
+
+#ifdef LINUX
+ if (handle)
+ dlclose(handle);
+#endif
+
+ return ret;
+}
+
+int main(int argc, char **argv) // for gcc compiler;
+{
+ int mode, r;
+ int arg, filename=0;
+ char *inFileName = NULL;
+ char *outFileName = NULL;
+ short allow_dtx;
+ VOAMRWBFRAMETYPE frameType;
+
+ printf("\n");
+ printf("************************Adaptive Multi-Rate Wide Band Encoder (AMR-WB)*******************************\n");
+ printf("***********************************DEFINITIONS:*******************************************************\n");
+ printf("AMR-WB encoder scheme is based on the principle of Algebraic Code Excited Linear Prediction algorithm\n");
+ printf("The AMR-WB encoder compression MONO liner PCM speech input data at 16kHz sampling rate\n");
+ printf("to one of nine data rate modes-6.60, 8.85, 12.65, 14.25, 15.85, 18.25, 19.25, 23.05 and 23.85kbps.\n");
+ printf("The encoder supports output format AMRWB ITU, AMRWB RFC3267.\n");
+ printf("\n");
+
+ /*Encoder Default setting */
+ mode = VOAMRWB_MD2385;
+ allow_dtx = 0;
+ frameType = VOAMRWB_RFC3267;
+
+ if(argc < 3){
+ usage();
+ return 0;
+ }else{
+ for (arg = 1; arg < argc; arg++) {
+ if (argv [arg] [0] == '+') {
+ if(argv[arg][1] == 'M')
+ {
+ switch(argv[arg][2])
+ {
+ case '0': mode = VOAMRWB_MD66;
+ break;
+ case '1': mode = VOAMRWB_MD885;
+ break;
+ case '2': mode = VOAMRWB_MD1265;
+ break;
+ case '3': mode = VOAMRWB_MD1425;
+ break;
+ case '4': mode = VOAMRWB_MD1585;
+ break;
+ case '5': mode = VOAMRWB_MD1825;
+ break;
+ case '6': mode = VOAMRWB_MD1985;
+ break;
+ case '7': mode = VOAMRWB_MD2305;
+ break;
+ case '8': mode = VOAMRWB_MD2385;
+ break;
+ default:
+ usage();
+ printf ("Invalid parameter '%s'.\n", argv [arg]);
+ break;
+ }
+ }else if(argv[arg][1] == 'F')
+ {
+ switch(argv[arg][2])
+ {
+ case '0': frameType = VOAMRWB_DEFAULT;
+ break;
+ case '1': frameType = VOAMRWB_ITU;
+ break;
+ case '2': frameType = VOAMRWB_RFC3267 ;
+ break;
+ default:
+ usage();
+ printf ("Invalid parameter '%s'.\n", argv [arg]);
+ break;
+
+
+ }
+ }else if(strcmp (argv[arg], "+DTX") == 0)
+ {
+ allow_dtx = 1;
+ }
+
+ } else {
+ switch (filename) {
+ case 0:
+ inFileName = argv[arg];
+ break;
+ case 1:
+ outFileName = argv[arg];
+ break;
+ default:
+ usage ();
+ fprintf (stderr, "Invalid parameter '%s'.\n", argv [arg]);
+ return 0;
+ }
+ filename++;
+ }
+ }
+ }
+
+ r = encode(mode, allow_dtx, frameType, inFileName, outFileName);
+ if(r)
+ {
+ fprintf(stderr, "error: %d\n", r);
+ }
+ return r;
+}
+
diff --git a/media/codecs/amrwb/enc/SampleCode/Android.bp b/media/codecs/amrwb/enc/SampleCode/Android.bp
new file mode 100644
index 0000000..9442fc4
--- /dev/null
+++ b/media/codecs/amrwb/enc/SampleCode/Android.bp
@@ -0,0 +1,28 @@
+cc_test {
+ name: "AMRWBEncTest",
+ gtest: false,
+
+ srcs: ["AMRWB_E_SAMPLE.c"],
+
+ cflags: ["-Wall", "-Werror"],
+
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ },
+ },
+
+ shared_libs: [
+ "libdl",
+ "liblog",
+ ],
+
+ static_libs: [
+ "libstagefright_amrwbenc",
+ "libstagefright_enc_common",
+ ],
+
+ sanitize: {
+ cfi: true,
+ },
+}
diff --git a/media/codecs/amrwb/enc/SampleCode/MODULE_LICENSE_APACHE2 b/media/codecs/amrwb/enc/SampleCode/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/amrwb/enc/SampleCode/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/amrwb/enc/SampleCode/NOTICE b/media/codecs/amrwb/enc/SampleCode/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/amrwb/enc/SampleCode/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/amrwb/enc/TEST_MAPPING b/media/codecs/amrwb/enc/TEST_MAPPING
new file mode 100644
index 0000000..045e8b3
--- /dev/null
+++ b/media/codecs/amrwb/enc/TEST_MAPPING
@@ -0,0 +1,10 @@
+// mappings for frameworks/av/media/libstagefright/codecs/amrwbenc
+{
+ // tests which require dynamic content
+ // invoke with: atest -- --enable-module-dynamic-download=true
+ // TODO(b/148094059): unit tests not allowed to download content
+ "dynamic-presubmit": [
+ { "name": "AmrwbEncoderTest"}
+
+ ]
+}
diff --git a/media/codecs/amrwb/enc/doc/voAMRWBEncoderSDK.pdf b/media/codecs/amrwb/enc/doc/voAMRWBEncoderSDK.pdf
new file mode 100644
index 0000000..5bade44
--- /dev/null
+++ b/media/codecs/amrwb/enc/doc/voAMRWBEncoderSDK.pdf
Binary files differ
diff --git a/media/codecs/amrwb/enc/fuzzer/Android.bp b/media/codecs/amrwb/enc/fuzzer/Android.bp
new file mode 100644
index 0000000..e3473d6
--- /dev/null
+++ b/media/codecs/amrwb/enc/fuzzer/Android.bp
@@ -0,0 +1,41 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+
+cc_fuzz {
+ name: "amrwb_enc_fuzzer",
+ host_supported: true,
+
+ srcs: [
+ "amrwb_enc_fuzzer.cpp",
+ ],
+
+ static_libs: [
+ "liblog",
+ "libstagefright_amrwbenc",
+ "libstagefright_enc_common",
+ ],
+
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
diff --git a/media/codecs/amrwb/enc/fuzzer/README.md b/media/codecs/amrwb/enc/fuzzer/README.md
new file mode 100644
index 0000000..447fbfa
--- /dev/null
+++ b/media/codecs/amrwb/enc/fuzzer/README.md
@@ -0,0 +1,60 @@
+# Fuzzer for libstagefright_amrwbenc encoder
+
+## Plugin Design Considerations
+The fuzzer plugin for AMR-WB is designed based on the understanding of the
+codec and tries to achieve the following:
+
+##### Maximize code coverage
+The configuration parameters are not hardcoded, but instead selected based on
+incoming data. This ensures more code paths are reached by the fuzzer.
+
+AMR-WB supports the following parameters:
+1. Frame Type (parameter name: `frameType`)
+2. Mode (parameter name: `mode`)
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `frameType` | 0. `VOAMRWB_DEFAULT` 1. `VOAMRWB_ITU` 2. `VOAMRWB_RFC3267` | Bits 0, 1 and 2 of 1st byte of data. |
+| `mode` | 0. `VOAMRWB_MD66` 1. `VOAMRWB_MD885` 2. `VOAMRWB_MD1265` 3. `VOAMRWB_MD1425` 4. `VOAMRWB_MD1585 ` 5. `VOAMRWB_MD1825` 6. `VOAMRWB_MD1985` 7. `VOAMRWB_MD2305` 8. `VOAMRWB_MD2385` 9. `VOAMRWB_N_MODES` | Bits 4, 5, 6 and 7 of 1st byte of data. |
+
+This also ensures that the plugin is always deterministic for any given input.
+
+##### Maximize utilization of input data
+The plugin feeds the entire input data to the codec using a loop.
+If the encode operation was successful, the input is advanced by the frame size.
+If the encode operation was un-successful, the input is still advanced by frame size so
+that the fuzzer can proceed to feed the next frame.
+
+This ensures that the plugin tolerates any kind of input (empty, huge,
+malformed, etc) and doesnt `exit()` on any input and thereby increasing the
+chance of identifying vulnerabilities.
+
+## Build
+
+This describes steps to build amrwb_enc_fuzzer binary.
+
+### Android
+
+#### Steps to build
+Build the fuzzer
+```
+ $ mm -j$(nproc) amrwb_enc_fuzzer
+```
+
+#### Steps to run
+Create a directory CORPUS_DIR and copy some pcm files to that folder
+Push this directory to device.
+
+To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/amrwb_enc_fuzzer/amrwb_enc_fuzzer CORPUS_DIR
+```
+To run on host
+```
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/amrwb_enc_fuzzer/amrwb_enc_fuzzer CORPUS_DIR
+```
+
+## References:
+ * http://llvm.org/docs/LibFuzzer.html
+ * https://github.com/google/oss-fuzz
diff --git a/media/codecs/amrwb/enc/fuzzer/amrwb_enc_fuzzer.cpp b/media/codecs/amrwb/enc/fuzzer/amrwb_enc_fuzzer.cpp
new file mode 100644
index 0000000..4773a1f
--- /dev/null
+++ b/media/codecs/amrwb/enc/fuzzer/amrwb_enc_fuzzer.cpp
@@ -0,0 +1,142 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+#include <string.h>
+#include <utils/Log.h>
+#include <algorithm>
+#include "cmnMemory.h"
+#include "voAMRWB.h"
+#include "cnst.h"
+
+typedef int(VO_API *VOGETAUDIOENCAPI)(VO_AUDIO_CODECAPI *pEncHandle);
+const int32_t kInputBufferSize = L_FRAME16k * sizeof(int16_t) * 2;
+const int32_t kOutputBufferSize = 2 * kInputBufferSize;
+const int32_t kModes[] = {VOAMRWB_MD66 /* 6.60kbps */, VOAMRWB_MD885 /* 8.85kbps */,
+ VOAMRWB_MD1265 /* 12.65kbps */, VOAMRWB_MD1425 /* 14.25kbps */,
+ VOAMRWB_MD1585 /* 15.85kbps */, VOAMRWB_MD1825 /* 18.25kbps */,
+ VOAMRWB_MD1985 /* 19.85kbps */, VOAMRWB_MD2305 /* 23.05kbps */,
+ VOAMRWB_MD2385 /* 23.85kbps */, VOAMRWB_N_MODES /* Invalid Mode */};
+const VOAMRWBFRAMETYPE kFrameTypes[] = {VOAMRWB_DEFAULT, VOAMRWB_ITU, VOAMRWB_RFC3267};
+
+class Codec {
+ public:
+ Codec() = default;
+ ~Codec() { deInitEncoder(); }
+ bool initEncoder(const uint8_t *data);
+ void deInitEncoder();
+ void encodeFrames(const uint8_t *data, size_t size);
+
+ private:
+ VO_AUDIO_CODECAPI *mApiHandle = nullptr;
+ VO_MEM_OPERATOR *mMemOperator = nullptr;
+ VO_HANDLE mEncoderHandle = nullptr;
+};
+
+bool Codec::initEncoder(const uint8_t *data) {
+ uint8_t startByte = *data;
+ int32_t mode = kModes[(startByte >> 4) % 10];
+ VOAMRWBFRAMETYPE frameType = kFrameTypes[startByte % 3];
+ mMemOperator = new VO_MEM_OPERATOR;
+ if (!mMemOperator) {
+ return false;
+ }
+
+ mMemOperator->Alloc = cmnMemAlloc;
+ mMemOperator->Copy = cmnMemCopy;
+ mMemOperator->Free = cmnMemFree;
+ mMemOperator->Set = cmnMemSet;
+ mMemOperator->Check = cmnMemCheck;
+
+ VO_CODEC_INIT_USERDATA userData;
+ memset(&userData, 0, sizeof(userData));
+ userData.memflag = VO_IMF_USERMEMOPERATOR;
+ userData.memData = (VO_PTR)mMemOperator;
+
+ mApiHandle = new VO_AUDIO_CODECAPI;
+ if (!mApiHandle) {
+ return false;
+ }
+ if (VO_ERR_NONE != voGetAMRWBEncAPI(mApiHandle)) {
+ // Failed to get api handle
+ return false;
+ }
+ if (VO_ERR_NONE != mApiHandle->Init(&mEncoderHandle, VO_AUDIO_CodingAMRWB, &userData)) {
+ // Failed to init AMRWB encoder
+ return false;
+ }
+ if (VO_ERR_NONE != mApiHandle->SetParam(mEncoderHandle, VO_PID_AMRWB_FRAMETYPE, &frameType)) {
+ // Failed to set AMRWB encoder frame type
+ return false;
+ }
+ if (VO_ERR_NONE != mApiHandle->SetParam(mEncoderHandle, VO_PID_AMRWB_MODE, &mode)) {
+ // Failed to set AMRWB encoder mode
+ return false;
+ }
+ return true;
+}
+
+void Codec::deInitEncoder() {
+ if (mEncoderHandle) {
+ mApiHandle->Uninit(mEncoderHandle);
+ mEncoderHandle = nullptr;
+ }
+ if (mApiHandle) {
+ delete mApiHandle;
+ mApiHandle = nullptr;
+ }
+ if (mMemOperator) {
+ delete mMemOperator;
+ mMemOperator = nullptr;
+ }
+}
+
+void Codec::encodeFrames(const uint8_t *data, size_t size) {
+ do {
+ int32_t minSize = std::min((int32_t)size, kInputBufferSize);
+ uint8_t outputBuf[kOutputBufferSize] = {};
+ VO_CODECBUFFER inData;
+ VO_CODECBUFFER outData;
+ VO_AUDIO_OUTPUTINFO outFormat;
+ inData.Buffer = (unsigned char *)data;
+ inData.Length = minSize;
+ outData.Buffer = outputBuf;
+ mApiHandle->SetInputData(mEncoderHandle, &inData);
+ mApiHandle->GetOutputData(mEncoderHandle, &outData, &outFormat);
+ data += minSize;
+ size -= minSize;
+ } while (size > 0);
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size < 1) {
+ return 0;
+ }
+ Codec *codec = new Codec();
+ if (!codec) {
+ return 0;
+ }
+ if (codec->initEncoder(data)) {
+ // Consume first byte
+ ++data;
+ --size;
+ codec->encodeFrames(data, size);
+ }
+ delete codec;
+ return 0;
+}
diff --git a/media/codecs/amrwb/enc/inc/acelp.h b/media/codecs/amrwb/enc/inc/acelp.h
new file mode 100644
index 0000000..97555d5
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/acelp.h
@@ -0,0 +1,521 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+ * ACELP.H *
+ *--------------------------------------------------------------------------*
+ * Function *
+ *--------------------------------------------------------------------------*/
+#ifndef __ACELP_H__
+#define __ACELP_H__
+
+#include "typedef.h"
+#include "cod_main.h"
+
+/*-----------------------------------------------------------------*
+ * LPC prototypes *
+ *-----------------------------------------------------------------*/
+
+Word16 median5(Word16 x[]);
+
+void Autocorr(
+ Word16 x[], /* (i) : Input signal */
+ Word16 m, /* (i) : LPC order */
+ Word16 r_h[], /* (o) : Autocorrelations (msb) */
+ Word16 r_l[] /* (o) : Autocorrelations (lsb) */
+ );
+
+void Lag_window(
+ Word16 r_h[], /* (i/o) : Autocorrelations (msb) */
+ Word16 r_l[] /* (i/o) : Autocorrelations (lsb) */
+ );
+
+void Init_Levinson(
+ Word16 * mem /* output :static memory (18 words) */
+ );
+
+void Levinson(
+ Word16 Rh[], /* (i) : Rh[M+1] Vector of autocorrelations (msb) */
+ Word16 Rl[], /* (i) : Rl[M+1] Vector of autocorrelations (lsb) */
+ Word16 A[], /* (o) Q12 : A[M] LPC coefficients (m = 16) */
+ Word16 rc[], /* (o) Q15 : rc[M] Reflection coefficients. */
+ Word16 * mem /* (i/o) :static memory (18 words) */
+ );
+
+void Az_isp(
+ Word16 a[], /* (i) Q12 : predictor coefficients */
+ Word16 isp[], /* (o) Q15 : Immittance spectral pairs */
+ Word16 old_isp[] /* (i) : old isp[] (in case not found M roots) */
+ );
+
+void Isp_Az(
+ Word16 isp[], /* (i) Q15 : Immittance spectral pairs */
+ Word16 a[], /* (o) Q12 : predictor coefficients (order = M) */
+ Word16 m,
+ Word16 adaptive_scaling /* (i) 0 : adaptive scaling disabled */
+ /* 1 : adaptive scaling enabled */
+ );
+
+void Isp_isf(
+ Word16 isp[], /* (i) Q15 : isp[m] (range: -1<=val<1) */
+ Word16 isf[], /* (o) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 m /* (i) : LPC order */
+ );
+
+void Isf_isp(
+ Word16 isf[], /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 isp[], /* (o) Q15 : isp[m] (range: -1<=val<1) */
+ Word16 m /* (i) : LPC order */
+ );
+
+void Int_isp(
+ Word16 isp_old[], /* input : isps from past frame */
+ Word16 isp_new[], /* input : isps from present frame */
+ Word16 frac[], /* input : fraction for 3 first subfr (Q15) */
+ Word16 Az[] /* output: LP coefficients in 4 subframes */
+ );
+
+void Weight_a(
+ Word16 a[], /* (i) Q12 : a[m+1] LPC coefficients */
+ Word16 ap[], /* (o) Q12 : Spectral expanded LPC coefficients */
+ Word16 gamma, /* (i) Q15 : Spectral expansion factor. */
+ Word16 m /* (i) : LPC order. */
+ );
+
+
+/*-----------------------------------------------------------------*
+ * isf quantizers *
+ *-----------------------------------------------------------------*/
+
+void Qpisf_2s_46b(
+ Word16 * isf1, /* (i) Q15 : ISF in the frequency domain (0..0.5) */
+ Word16 * isf_q, /* (o) Q15 : quantized ISF (0..0.5) */
+ Word16 * past_isfq, /* (io)Q15 : past ISF quantizer */
+ Word16 * indice, /* (o) : quantization indices */
+ Word16 nb_surv /* (i) : number of survivor (1, 2, 3 or 4) */
+ );
+
+void Qpisf_2s_36b(
+ Word16 * isf1, /* (i) Q15 : ISF in the frequency domain (0..0.5) */
+ Word16 * isf_q, /* (o) Q15 : quantized ISF (0..0.5) */
+ Word16 * past_isfq, /* (io)Q15 : past ISF quantizer */
+ Word16 * indice, /* (o) : quantization indices */
+ Word16 nb_surv /* (i) : number of survivor (1, 2, 3 or 4) */
+ );
+
+void Dpisf_2s_46b(
+ Word16 * indice, /* input: quantization indices */
+ Word16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ Word16 * past_isfq, /* i/0 : past ISF quantizer */
+ Word16 * isfold, /* input : past quantized ISF */
+ Word16 * isf_buf, /* input : isf buffer */
+ Word16 bfi, /* input : Bad frame indicator */
+ Word16 enc_dec
+ );
+
+void Dpisf_2s_36b(
+ Word16 * indice, /* input: quantization indices */
+ Word16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ Word16 * past_isfq, /* i/0 : past ISF quantizer */
+ Word16 * isfold, /* input : past quantized ISF */
+ Word16 * isf_buf, /* input : isf buffer */
+ Word16 bfi, /* input : Bad frame indicator */
+ Word16 enc_dec
+ );
+
+void Qisf_ns(
+ Word16 * isf1, /* input : ISF in the frequency domain (0..0.5) */
+ Word16 * isf_q, /* output: quantized ISF */
+ Word16 * indice /* output: quantization indices */
+ );
+
+void Disf_ns(
+ Word16 * indice, /* input: quantization indices */
+ Word16 * isf_q /* input : ISF in the frequency domain (0..0.5) */
+ );
+
+Word16 Sub_VQ( /* output: return quantization index */
+ Word16 * x, /* input : ISF residual vector */
+ Word16 * dico, /* input : quantization codebook */
+ Word16 dim, /* input : dimention of vector */
+ Word16 dico_size, /* input : size of quantization codebook */
+ Word32 * distance /* output: error of quantization */
+ );
+
+void Reorder_isf(
+ Word16 * isf, /* (i/o) Q15: ISF in the frequency domain (0..0.5) */
+ Word16 min_dist, /* (i) Q15 : minimum distance to keep */
+ Word16 n /* (i) : number of ISF */
+ );
+
+/*-----------------------------------------------------------------*
+ * filter prototypes *
+ *-----------------------------------------------------------------*/
+
+void Init_Decim_12k8(
+ Word16 mem[] /* output: memory (2*NB_COEF_DOWN) set to zeros */
+ );
+void Decim_12k8(
+ Word16 sig16k[], /* input: signal to downsampling */
+ Word16 lg, /* input: length of input */
+ Word16 sig12k8[], /* output: decimated signal */
+ Word16 mem[] /* in/out: memory (2*NB_COEF_DOWN) */
+ );
+
+void Init_HP50_12k8(Word16 mem[]);
+void HP50_12k8(
+ Word16 signal[], /* input/output signal */
+ Word16 lg, /* lenght of signal */
+ Word16 mem[] /* filter memory [6] */
+ );
+void Init_HP400_12k8(Word16 mem[]);
+void HP400_12k8(
+ Word16 signal[], /* input/output signal */
+ Word16 lg, /* lenght of signal */
+ Word16 mem[] /* filter memory [6] */
+ );
+
+void Init_Filt_6k_7k(Word16 mem[]);
+void Filt_6k_7k(
+ Word16 signal[], /* input: signal */
+ Word16 lg, /* input: length of input */
+ Word16 mem[] /* in/out: memory (size=30) */
+ );
+void Filt_6k_7k_asm(
+ Word16 signal[], /* input: signal */
+ Word16 lg, /* input: length of input */
+ Word16 mem[] /* in/out: memory (size=30) */
+ );
+
+void LP_Decim2(
+ Word16 x[], /* in/out: signal to process */
+ Word16 l, /* input : size of filtering */
+ Word16 mem[] /* in/out: memory (size=3) */
+ );
+
+void Preemph(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : preemphasis coefficient */
+ Word16 lg, /* (i) : lenght of filtering */
+ Word16 * mem /* (i/o) : memory (x[-1]) */
+ );
+void Preemph2(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : preemphasis coefficient */
+ Word16 lg, /* (i) : lenght of filtering */
+ Word16 * mem /* (i/o) : memory (x[-1]) */
+ );
+void Deemph(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : deemphasis factor */
+ Word16 L, /* (i) : vector size */
+ Word16 * mem /* (i/o) : memory (y[-1]) */
+ );
+void Deemph2(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : deemphasis factor */
+ Word16 L, /* (i) : vector size */
+ Word16 * mem /* (i/o) : memory (y[-1]) */
+ );
+void Deemph_32(
+ Word16 x_hi[], /* (i) : input signal (bit31..16) */
+ Word16 x_lo[], /* (i) : input signal (bit15..4) */
+ Word16 y[], /* (o) : output signal (x16) */
+ Word16 mu, /* (i) Q15 : deemphasis factor */
+ Word16 L, /* (i) : vector size */
+ Word16 * mem /* (i/o) : memory (y[-1]) */
+ );
+
+void Deemph_32_asm(
+ Word16 x_hi[], /* (i) : input signal (bit31..16) */
+ Word16 x_lo[], /* (i) : input signal (bit15..4) */
+ Word16 y[], /* (o) : output signal (x16) */
+ Word16 * mem /* (i/o) : memory (y[-1]) */
+ );
+
+void Convolve(
+ Word16 x[], /* (i) : input vector */
+ Word16 h[], /* (i) Q15 : impulse response */
+ Word16 y[], /* (o) 12 bits: output vector */
+ Word16 L /* (i) : vector size */
+ );
+
+void Convolve_asm(
+ Word16 x[], /* (i) : input vector */
+ Word16 h[], /* (i) Q15 : impulse response */
+ Word16 y[], /* (o) 12 bits: output vector */
+ Word16 L /* (i) : vector size */
+ );
+
+void Residu(
+ Word16 a[], /* (i) Q12 : prediction coefficients */
+ Word16 x[], /* (i) : speech (values x[-m..-1] are needed */
+ Word16 y[], /* (o) : residual signal */
+ Word16 lg /* (i) : size of filtering */
+ );
+
+void Residu_opt(
+ Word16 a[], /* (i) Q12 : prediction coefficients */
+ Word16 x[], /* (i) : speech (values x[-m..-1] are needed */
+ Word16 y[], /* (o) : residual signal */
+ Word16 lg /* (i) : size of filtering */
+ );
+
+void Syn_filt(
+ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ Word16 x[], /* (i) : input signal */
+ Word16 y[], /* (o) : output signal */
+ Word16 lg, /* (i) : size of filtering */
+ Word16 mem[], /* (i/o) : memory associated with this filtering. */
+ Word16 update /* (i) : 0=no update, 1=update of memory. */
+ );
+
+void Syn_filt_asm(
+ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ Word16 x[], /* (i) : input signal */
+ Word16 y[], /* (o) : output signal */
+ Word16 mem[] /* (i/o) : memory associated with this filtering. */
+ );
+
+void Syn_filt_32(
+ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ Word16 m, /* (i) : order of LP filter */
+ Word16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
+ Word16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
+ Word16 sig_hi[], /* (o) /16 : synthesis high */
+ Word16 sig_lo[], /* (o) /16 : synthesis low */
+ Word16 lg /* (i) : size of filtering */
+ );
+
+void Syn_filt_32_asm(
+ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ Word16 m, /* (i) : order of LP filter */
+ Word16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
+ Word16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
+ Word16 sig_hi[], /* (o) /16 : synthesis high */
+ Word16 sig_lo[], /* (o) /16 : synthesis low */
+ Word16 lg /* (i) : size of filtering */
+ );
+/*-----------------------------------------------------------------*
+ * pitch prototypes *
+ *-----------------------------------------------------------------*/
+
+Word16 Pitch_ol( /* output: open loop pitch lag */
+ Word16 signal[], /* input : signal used to compute the open loop pitch */
+/* signal[-pit_max] to signal[-1] should be known */
+ Word16 pit_min, /* input : minimum pitch lag */
+ Word16 pit_max, /* input : maximum pitch lag */
+ Word16 L_frame /* input : length of frame to compute pitch */
+);
+
+Word16 Pitch_med_ol( /* output: open loop pitch lag */
+ Word16 wsp[], /* input : signal used to compute the open loop pitch */
+ /* wsp[-pit_max] to wsp[-1] should be known */
+ Coder_State *st, /* i/o : global codec structure */
+ Word16 L_frame /* input : length of frame to compute pitch */
+);
+
+Word16 Med_olag( /* output : median of 5 previous open-loop lags */
+ Word16 prev_ol_lag, /* input : previous open-loop lag */
+ Word16 old_ol_lag[5]
+);
+
+void Init_Hp_wsp(Word16 mem[]);
+void scale_mem_Hp_wsp(Word16 mem[], Word16 exp);
+void Hp_wsp(
+ Word16 wsp[], /* i : wsp[] signal */
+ Word16 hp_wsp[], /* o : hypass wsp[] */
+ Word16 lg, /* i : lenght of signal */
+ Word16 mem[] /* i/o : filter memory [9] */
+);
+
+Word16 Pitch_fr4( /* (o) : pitch period. */
+ Word16 exc[], /* (i) : excitation buffer */
+ Word16 xn[], /* (i) : target vector */
+ Word16 h[], /* (i) Q15 : impulse response of synth/wgt filters */
+ Word16 t0_min, /* (i) : minimum value in the searched range. */
+ Word16 t0_max, /* (i) : maximum value in the searched range. */
+ Word16 * pit_frac, /* (o) : chosen fraction (0, 1, 2 or 3). */
+ Word16 i_subfr, /* (i) : indicator for first subframe. */
+ Word16 t0_fr2, /* (i) : minimum value for resolution 1/2 */
+ Word16 t0_fr1, /* (i) : minimum value for resolution 1 */
+ Word16 L_subfr /* (i) : Length of subframe */
+);
+void Pred_lt4(
+ Word16 exc[], /* in/out: excitation buffer */
+ Word16 T0, /* input : integer pitch lag */
+ Word16 frac, /* input : fraction of lag */
+ Word16 L_subfr /* input : subframe size */
+);
+
+void pred_lt4_asm(
+ Word16 exc[], /* in/out: excitation buffer */
+ Word16 T0, /* input : integer pitch lag */
+ Word16 frac, /* input : fraction of lag */
+ Word16 L_subfr /* input : subframe size */
+);
+
+/*-----------------------------------------------------------------*
+ * gain prototypes *
+ *-----------------------------------------------------------------*/
+
+Word16 G_pitch( /* (o) Q14 : Gain of pitch lag saturated to 1.2 */
+ Word16 xn[], /* (i) : Pitch target. */
+ Word16 y1[], /* (i) : filtered adaptive codebook. */
+ Word16 g_coeff[], /* : Correlations need for gain quantization. */
+ Word16 L_subfr /* : Length of subframe. */
+);
+void Init_Q_gain2(
+ Word16 * mem /* output :static memory (2 words) */
+);
+Word16 Q_gain2( /* Return index of quantization. */
+ Word16 xn[], /* (i) Q_xn:Target vector. */
+ Word16 y1[], /* (i) Q_xn:Adaptive codebook. */
+ Word16 Q_xn, /* (i) :xn and y1 format */
+ Word16 y2[], /* (i) Q9 :Filtered innovative vector. */
+ Word16 code[], /* (i) Q9 :Innovative vector. */
+ Word16 g_coeff[], /* (i) :Correlations <xn y1> <y1 y1> */
+/* Compute in G_pitch(). */
+ Word16 L_subfr, /* (i) :Subframe lenght. */
+ Word16 nbits, /* (i) : number of bits (6 or 7) */
+ Word16 * gain_pit, /* (i/o)Q14:Pitch gain. */
+ Word32 * gain_cod, /* (o) Q16 :Code gain. */
+ Word16 gp_clip, /* (i) : Gp Clipping flag */
+ Word16 * mem /* (i/o) :static memory (2 words) */
+);
+
+void Init_D_gain2(
+ Word16 * mem /* output :static memory (4 words) */
+);
+void D_gain2(
+ Word16 index, /* (i) :index of quantization. */
+ Word16 nbits, /* (i) : number of bits (6 or 7) */
+ Word16 code[], /* (i) Q9 :Innovative vector. */
+ Word16 L_subfr, /* (i) :Subframe lenght. */
+ Word16 * gain_pit, /* (o) Q14 :Pitch gain. */
+ Word32 * gain_cod, /* (o) Q16 :Code gain. */
+ Word16 bfi, /* (i) :bad frame indicator */
+ Word16 prev_bfi, /* (i) : Previous BF indicator */
+ Word16 state, /* (i) : State of BFH */
+ Word16 unusable_frame, /* (i) : UF indicator */
+ Word16 vad_hist, /* (i) :number of non-speech frames */
+ Word16 * mem /* (i/o) :static memory (4 words) */
+);
+
+/*-----------------------------------------------------------------*
+ * acelp prototypes *
+ *-----------------------------------------------------------------*/
+
+void cor_h_x(
+ Word16 h[], /* (i) Q12 : impulse response of weighted synthesis filter */
+ Word16 x[], /* (i) Q0 : target vector */
+ Word16 dn[] /* (o) <12bit : correlation between target and h[] */
+);
+void ACELP_2t64_fx(
+ Word16 dn[], /* (i) <12b : correlation between target x[] and H[] */
+ Word16 cn[], /* (i) <12b : residual after long term prediction */
+ Word16 H[], /* (i) Q12: impulse response of weighted synthesis filter */
+ Word16 code[], /* (o) Q9 : algebraic (fixed) codebook excitation */
+ Word16 y[], /* (o) Q9 : filtered fixed codebook excitation */
+ Word16 * index /* (o) : index (12): 5+1+5+1 = 11 bits. */
+);
+
+void ACELP_4t64_fx(
+ Word16 dn[], /* (i) <12b : correlation between target x[] and H[] */
+ Word16 cn[], /* (i) <12b : residual after long term prediction */
+ Word16 H[], /* (i) Q12: impulse response of weighted synthesis filter */
+ Word16 code[], /* (o) Q9 : algebraic (fixed) codebook excitation */
+ Word16 y[], /* (o) Q9 : filtered fixed codebook excitation */
+ Word16 nbbits, /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits */
+ Word16 ser_size, /* (i) : bit rate */
+ Word16 _index[] /* (o) : index (20): 5+5+5+5 = 20 bits. */
+ /* (o) : index (36): 9+9+9+9 = 36 bits. */
+ /* (o) : index (44): 13+9+13+9 = 44 bits. */
+ /* (o) : index (52): 13+13+13+13 = 52 bits. */
+ /* (o) : index (64): 2+2+2+2+14+14+14+14 = 64 bits. */
+ /* (o) : index (72): 10+2+10+2+10+14+10+14 = 72 bits. */
+ /* (o) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
+);
+
+void Pit_shrp(
+ Word16 * x, /* in/out: impulse response (or algebraic code) */
+ Word16 pit_lag, /* input : pitch lag */
+ Word16 sharp, /* input : pitch sharpening factor (Q15) */
+ Word16 L_subfr /* input : subframe size */
+);
+
+
+/*-----------------------------------------------------------------*
+ * others prototypes *
+ *-----------------------------------------------------------------*/
+
+void Copy(
+ Word16 x[], /* (i) : input vector */
+ Word16 y[], /* (o) : output vector */
+ Word16 L /* (i) : vector length */
+);
+void Set_zero(
+ Word16 x[], /* (o) : vector to clear */
+ Word16 L /* (i) : length of vector */
+);
+void Updt_tar(
+ Word16 * x, /* (i) Q0 : old target (for pitch search) */
+ Word16 * x2, /* (o) Q0 : new target (for codebook search) */
+ Word16 * y, /* (i) Q0 : filtered adaptive codebook vector */
+ Word16 gain, /* (i) Q14 : adaptive codebook gain */
+ Word16 L /* (i) : subframe size */
+);
+Word16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
+ Word16 exc[], /* (i) Q_exc: pitch excitation */
+ Word16 Q_exc, /* (i) : exc format */
+ Word16 gain_pit, /* (i) Q14 : gain of pitch */
+ Word16 code[], /* (i) Q9 : Fixed codebook excitation */
+ Word16 gain_code, /* (i) Q0 : gain of code */
+ Word16 L_subfr /* (i) : subframe length */
+);
+void Scale_sig(
+ Word16 x[], /* (i/o) : signal to scale */
+ Word16 lg, /* (i) : size of x[] */
+ Word16 exp /* (i) : exponent: x = round(x << exp) */
+);
+
+void Scale_sig_opt(
+ Word16 x[], /* (i/o) : signal to scale */
+ Word16 lg, /* (i) : size of x[] */
+ Word16 exp /* (i) : exponent: x = round(x << exp) */
+);
+
+Word16 Random(Word16 * seed);
+
+void Init_gp_clip(
+ Word16 mem[] /* (o) : memory of gain of pitch clipping algorithm */
+);
+Word16 Gp_clip(
+ Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */
+);
+void Gp_clip_test_isf(
+ Word16 isf[], /* (i) : isf values (in frequency domain) */
+ Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */
+);
+void Gp_clip_test_gain_pit(
+ Word16 gain_pit, /* (i) : gain of quantized pitch */
+ Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */
+);
+
+
+#endif //__ACELP_H__
+
diff --git a/media/codecs/amrwb/enc/inc/basic_op.h b/media/codecs/amrwb/enc/inc/basic_op.h
new file mode 100644
index 0000000..80ad7f1
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/basic_op.h
@@ -0,0 +1,1096 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+#ifndef __BASIC_OP_H__
+#define __BASIC_OP_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "typedef.h"
+
+#define MAX_32 (Word32)0x7fffffffL
+#define MIN_32 (Word32)0x80000000L
+
+#define MAX_16 ((Word16)+32767) /* 0x7fff */
+#define MIN_16 ((Word16)-32768) /* 0x8000 */
+
+
+#define static_vo static __inline
+
+#define saturate(L_var1) (((L_var1) > 0X00007fffL) ? (MAX_16): (((L_var1) < (Word32) 0xffff8000L) ? (MIN_16): ((L_var1) & 0xffff)))
+
+#define abs_s(x) ((Word16)(((x) != MIN_16) ? (((x) >= 0) ? (x) : (-(x))) : MAX_16)) /* Short abs, 1 */
+#define L_deposit_h(x) (((Word32)(x)) << 16) /* 16 bit var1 -> MSB, 2 */
+#define L_deposit_l(x) ((Word32)(x)) /* 16 bit var1 -> LSB, 2 */
+#define L_abs(x) (((x) != MIN_32) ? (((x) >= 0) ? (x) : (-(x))) : MAX_32) /* Long abs, 3*/
+#define negate(var1) ((Word16)(((var1) == MIN_16) ? MAX_16 : (-(var1)))) /* Short negate, 1*/
+#define L_negate(L_var1) (((L_var1) == (MIN_32)) ? (MAX_32) : (-(L_var1))) /* Long negate, 2*/
+
+
+#define extract_h(a) ((Word16)((a) >> 16))
+#define extract_l(x) (Word16)((x))
+#define add1(a,b) ((a) + (b))
+#define vo_L_msu(a,b,c) ((a) - (((b) * (c)) << 1))
+#define vo_mult32(a, b) ((a) * (b))
+#define vo_mult(a,b) (((a) * (b)) >> 15)
+#define vo_L_mult(a,b) (((a) * (b)) << 1)
+#define vo_shr_r(var1, var2) (((var1)+((Word16)(1L<<((var2)-1))))>>(var2))
+#define vo_sub(a,b) ((a) - (b))
+#define vo_L_deposit_h(a) ((Word32)((a) << 16))
+#define vo_round(a) ((((a) >> 15) + 1) >> 1)
+#define vo_extract_l(a) ((Word16)(a))
+#define vo_L_add(a,b) ((a) + (b))
+#define vo_L_sub(a,b) ((a) - (b))
+#define vo_mult_r(a,b) (((( (a) * (b) ) >> 14) + 1 ) >> 1 )
+#define vo_negate(a) (-(a))
+#define vo_L_shr_r(L_var1, var2) (((L_var1)+((Word32)(1L<<((var2)-1))))>>(var2))
+
+
+/*___________________________________________________________________________
+| |
+| Prototypes for basic arithmetic operators |
+|___________________________________________________________________________|
+*/
+static_vo Word16 add (Word16 var1, Word16 var2); /* Short add,1 */
+static_vo Word16 sub (Word16 var1, Word16 var2); /* Short sub,1 */
+static_vo Word16 shl (Word16 var1, Word16 var2); /* Short shift left, 1 */
+static_vo Word16 shr (Word16 var1, Word16 var2); /* Short shift right, 1 */
+static_vo Word16 mult (Word16 var1, Word16 var2); /* Short mult, 1 */
+static_vo Word32 L_mult (Word16 var1, Word16 var2); /* Long mult, 1 */
+static_vo Word16 voround (Word32 L_var1); /* Round, 1 */
+static_vo Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2); /* Mac, 1 */
+static_vo Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2); /* Msu, 1 */
+static_vo Word32 L_add (Word32 L_var1, Word32 L_var2); /* Long add, 2 */
+static_vo Word32 L_sub (Word32 L_var1, Word32 L_var2); /* Long sub, 2 */
+static_vo Word16 mult_r (Word16 var1, Word16 var2); /* Mult with round, 2 */
+static_vo Word32 L_shl2(Word32 L_var1, Word16 var2); /* var2 > 0*/
+static_vo Word32 L_shl (Word32 L_var1, Word16 var2); /* Long shift left, 2 */
+static_vo Word32 L_shr (Word32 L_var1, Word16 var2); /* Long shift right, 2*/
+static_vo Word32 L_shr_r (Word32 L_var1, Word16 var2); /* Long shift right with round, 3 */
+static_vo Word16 norm_s (Word16 var1); /* Short norm, 15 */
+static_vo Word16 div_s (Word16 var1, Word16 var2); /* Short division, 18 */
+static_vo Word16 norm_l (Word32 L_var1); /* Long norm, 30 */
+
+/*___________________________________________________________________________
+| |
+| Functions |
+|___________________________________________________________________________|
+*/
+/*___________________________________________________________________________
+| |
+| Function Name : add |
+| |
+| Purpose : |
+| |
+| Performs the addition (var1+var2) with overflow control and saturation;|
+| the 16 bit result is set at +32767 when overflow occurs or at -32768 |
+| when underflow occurs. |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+|___________________________________________________________________________|
+*/
+static_vo Word16 add (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_sum;
+ L_sum = (Word32) var1 + var2;
+ var_out = saturate (L_sum);
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : sub |
+| |
+| Purpose : |
+| |
+| Performs the subtraction (var1+var2) with overflow control and satu- |
+| ration; the 16 bit result is set at +32767 when overflow occurs or at |
+| -32768 when underflow occurs. |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 sub (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_diff;
+ L_diff = (Word32) var1 - var2;
+ var_out = saturate (L_diff);
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : shl |
+| |
+| Purpose : |
+| |
+| Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
+| the var2 LSB of the result. If var2 is negative, arithmetically shift |
+| var1 right by -var2 with sign extension. Saturate the result in case of |
+| underflows or overflows. |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 shl (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 result;
+ if (var2 < 0)
+ {
+ if (var2 < -16)
+ var2 = -16;
+ var_out = var1 >> ((Word16)-var2);
+ }
+ else
+ {
+ if (var2 > 15 && var1 != 0)
+ {
+ var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
+ }
+ else
+ {
+ result = (Word32) var1 *((Word32) 1 << var2);
+ if ((result != (Word32) ((Word16) result))) {
+ var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
+ } else {
+ var_out = extract_l (result);
+ }
+ }
+ }
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : shr |
+| |
+| Purpose : |
+| |
+| Arithmetically shift the 16 bit input var1 right var2 positions with |
+| sign extension. If var2 is negative, arithmetically shift var1 left by |
+| -var2 with sign extension. Saturate the result in case of underflows or |
+| overflows. |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 shr (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ if (var2 < 0)
+ {
+ if (var2 < -16)
+ var2 = -16;
+ var_out = shl(var1, (Word16)-var2);
+ }
+ else
+ {
+ if (var2 >= 15)
+ {
+ var_out = (Word16)((var1 < 0) ? -1 : 0);
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var_out = (Word16)(~((~var1) >> var2));
+ }
+ else
+ {
+ var_out = (Word16)(var1 >> var2);
+ }
+ }
+ }
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : mult |
+| |
+| Purpose : |
+| |
+| Performs the multiplication of var1 by var2 and gives a 16 bit result |
+| which is scaled i.e.: |
+| mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and |
+| mult(-32768,-32768) = 32767. |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 mult (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_product;
+ L_product = (Word32) var1 *(Word32) var2;
+ L_product = (L_product & (Word32) 0xffff8000L) >> 15;
+ if (L_product & (Word32) 0x00010000L)
+ L_product = L_product | (Word32) 0xffff0000L;
+ var_out = saturate (L_product);
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_mult |
+| |
+| Purpose : |
+| |
+| L_mult is the 32 bit result of the multiplication of var1 times var2 |
+| with one shift left i.e.: |
+| L_mult(var1,var2) = L_shl((var1 times var2),1) and |
+| L_mult(-32768,-32768) = 2147483647. |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word32 L_mult (Word16 var1, Word16 var2)
+{
+ Word32 L_var_out;
+ L_var_out = (Word32) var1 *(Word32) var2;
+ if (L_var_out != (Word32) 0x40000000L)
+ {
+ L_var_out *= 2;
+ }
+ else
+ {
+ L_var_out = MAX_32;
+ }
+ return (L_var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : round |
+| |
+| Purpose : |
+| |
+| Round the lower 16 bits of the 32 bit input number into the MS 16 bits |
+| with saturation. Shift the resulting bits right by 16 and return the 16 |
+| bit number: |
+| round(L_var1) = extract_h(L_add(L_var1,32768)) |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| L_var1 |
+| 32 bit long signed integer (Word32 ) whose value falls in the |
+| range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 voround (Word32 L_var1)
+{
+ Word16 var_out;
+ Word32 L_rounded;
+ L_rounded = L_add (L_var1, (Word32) 0x00008000L);
+ var_out = extract_h (L_rounded);
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_mac |
+| |
+| Purpose : |
+| |
+| Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
+| result to L_var3 with saturation, return a 32 bit result: |
+| L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)). |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| L_var3 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word32 L_var_out;
+ Word32 L_product;
+ L_product = ((var1 * var2) << 1);
+ L_var_out = L_add (L_var3, L_product);
+ return (L_var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_msu |
+| |
+| Purpose : |
+| |
+| Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
+| bit result to L_var3 with saturation, return a 32 bit result: |
+| L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)). |
+| |
+| Complexity weight : 1 |
+| |
+| Inputs : |
+| |
+| L_var3 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word32 L_var_out;
+ Word32 L_product;
+ L_product = (var1 * var2)<<1;
+ L_var_out = L_sub (L_var3, L_product);
+ return (L_var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_add |
+| |
+| Purpose : |
+| |
+| 32 bits addition of the two 32 bits variables (L_var1+L_var2) with |
+| overflow control and saturation; the result is set at +2147483647 when |
+| overflow occurs or at -2147483648 when underflow occurs. |
+| |
+| Complexity weight : 2 |
+| |
+| Inputs : |
+| |
+| L_var1 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| L_var2 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+__attribute__((no_sanitize("integer")))
+static_vo Word32 L_add (Word32 L_var1, Word32 L_var2)
+{
+ Word32 L_var_out;
+ L_var_out = L_var1 + L_var2;
+ if (((L_var1 ^ L_var2) & MIN_32) == 0)
+ {
+ if ((L_var_out ^ L_var1) & MIN_32)
+ {
+ L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
+ }
+ }
+ return (L_var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_sub |
+| |
+| Purpose : |
+| |
+| 32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with |
+| overflow control and saturation; the result is set at +2147483647 when |
+| overflow occurs or at -2147483648 when underflow occurs. |
+| |
+| Complexity weight : 2 |
+| |
+| Inputs : |
+| |
+| L_var1 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| L_var2 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+__attribute__((no_sanitize("integer")))
+static_vo Word32 L_sub (Word32 L_var1, Word32 L_var2)
+{
+ Word32 L_var_out;
+ L_var_out = L_var1 - L_var2;
+ if (((L_var1 ^ L_var2) & MIN_32) != 0)
+ {
+ if ((L_var_out ^ L_var1) & MIN_32)
+ {
+ L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
+ }
+ }
+ return (L_var_out);
+}
+
+
+/*___________________________________________________________________________
+| |
+| Function Name : mult_r |
+| |
+| Purpose : |
+| |
+| Same as mult with rounding, i.e.: |
+| mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and |
+| mult_r(-32768,-32768) = 32767. |
+| |
+| Complexity weight : 2 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 mult_r (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_product_arr;
+ L_product_arr = (Word32) var1 *(Word32) var2; /* product */
+ L_product_arr += (Word32) 0x00004000L; /* round */
+ L_product_arr &= (Word32) 0xffff8000L;
+ L_product_arr >>= 15; /* shift */
+ if (L_product_arr & (Word32) 0x00010000L) /* sign extend when necessary */
+ {
+ L_product_arr |= (Word32) 0xffff0000L;
+ }
+ var_out = saturate (L_product_arr);
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_shl |
+| |
+| Purpose : |
+| |
+| Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero |
+| fill the var2 LSB of the result. If var2 is negative, arithmetically |
+| shift L_var1 right by -var2 with sign extension. Saturate the result in |
+| case of underflows or overflows. |
+| |
+| Complexity weight : 2 |
+| |
+| Inputs : |
+| |
+| L_var1 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word32 L_shl (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out = 0L;
+ if (var2 <= 0)
+ {
+ if (var2 < -32)
+ var2 = -32;
+ L_var_out = (L_var1 >> (Word16)-var2);
+ }
+ else
+ {
+ for (; var2 > 0; var2--)
+ {
+ if (L_var1 > (Word32) 0X3fffffffL)
+ {
+ L_var_out = MAX_32;
+ break;
+ }
+ else
+ {
+ if (L_var1 < (Word32) 0xc0000000L)
+ {
+ //Overflow = 1;
+ L_var_out = MIN_32;
+ break;
+ }
+ }
+ L_var1 *= 2;
+ L_var_out = L_var1;
+ }
+ }
+ return (L_var_out);
+}
+
+static_vo Word32 L_shl2(Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out = 0L;
+
+ for (; var2 > 0; var2--)
+ {
+ if (L_var1 > (Word32) 0X3fffffffL)
+ {
+ L_var_out = MAX_32;
+ break;
+ }
+ else
+ {
+ if (L_var1 < (Word32) 0xc0000000L)
+ {
+ L_var_out = MIN_32;
+ break;
+ }
+ }
+ L_var1 *= 2 ;
+ L_var_out = L_var1;
+ }
+ return (L_var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_shr |
+| |
+| Purpose : |
+| |
+| Arithmetically shift the 32 bit input L_var1 right var2 positions with |
+| sign extension. If var2 is negative, arithmetically shift L_var1 left |
+| by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
+| in case of underflows or overflows. |
+| |
+| Complexity weight : 2 |
+| |
+| Inputs : |
+| |
+| L_var1 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word32 L_shr (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out;
+ if (var2 < 0)
+ {
+ if (var2 < -32)
+ var2 = -32;
+ L_var_out = L_shl2(L_var1, (Word16)-var2);
+ }
+ else
+ {
+ if (var2 >= 31)
+ {
+ L_var_out = (L_var1 < 0L) ? -1 : 0;
+ }
+ else
+ {
+ if (L_var1 < 0)
+ {
+ L_var_out = ~((~L_var1) >> var2);
+ }
+ else
+ {
+ L_var_out = L_var1 >> var2;
+ }
+ }
+ }
+ return (L_var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : L_shr_r |
+| |
+| Purpose : |
+| |
+| Same as L_shr(L_var1,var2) but with rounding. Saturate the result in |
+| case of underflows or overflows : |
+| - If var2 is greater than zero : |
+| if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|
+| is equal to zero |
+| then |
+| L_shr_r(L_var1,var2) = L_shr(L_var1,var2) |
+| else |
+| L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1) |
+| - If var2 is less than or equal to zero : |
+| L_shr_r(L_var1,var2) = L_shr(L_var1,var2). |
+| |
+| Complexity weight : 3 |
+| |
+| Inputs : |
+| |
+| L_var1 |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| L_var_out |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word32 L_shr_r (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out;
+ if (var2 > 31)
+ {
+ L_var_out = 0;
+ }
+ else
+ {
+ L_var_out = L_shr (L_var1, var2);
+ if (var2 > 0)
+ {
+ if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
+ {
+ L_var_out++;
+ }
+ }
+ }
+ return (L_var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : norm_s |
+| |
+| Purpose : |
+| |
+| Produces the number of left shift needed to normalize the 16 bit varia- |
+| ble var1 for positive values on the interval with minimum of 16384 and |
+| maximum of 32767, and for negative values on the interval with minimum |
+| of -32768 and maximum of -16384; in order to normalize the result, the |
+| following operation must be done : |
+| norm_var1 = shl(var1,norm_s(var1)). |
+| |
+| Complexity weight : 15 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0x0000 0000 <= var_out <= 0x0000 000f. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 norm_s (Word16 var1)
+{
+ Word16 var_out = 0;
+ if (var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (var1 == -1)
+ {
+ var_out = 15;
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var1 = (Word16)~var1;
+ }
+ for (var_out = 0; var1 < 0x4000; var_out++)
+ {
+ var1 <<= 1;
+ }
+ }
+ }
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : div_s |
+| |
+| Purpose : |
+| |
+| Produces a result which is the fractional integer division of var1 by |
+| var2; var1 and var2 must be positive and var2 must be greater or equal |
+| to var1; the result is positive (leading bit equal to 0) and truncated |
+| to 16 bits. |
+| If var1 = var2 then div(var1,var2) = 32767. |
+| |
+| Complexity weight : 18 |
+| |
+| Inputs : |
+| |
+| var1 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0x0000 0000 <= var1 <= var2 and var2 != 0. |
+| |
+| var2 |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : var1 <= var2 <= 0x0000 7fff and var2 != 0. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
+| It's a Q15 value (point between b15 and b14). |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 div_s (Word16 var1, Word16 var2)
+{
+ Word16 var_out = 0;
+ Word16 iteration;
+ Word32 L_num;
+ Word32 L_denom;
+ if ((var1 < 0) || (var2 < 0))
+ {
+ var_out = MAX_16;
+ return var_out;
+ }
+ if (var2 == 0)
+ {
+ var_out = MAX_16;
+ return var_out;
+ }
+ if (var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (var1 == var2)
+ {
+ var_out = MAX_16;
+ }
+ else
+ {
+ L_num = L_deposit_l (var1);
+ L_denom = L_deposit_l(var2);
+ for (iteration = 0; iteration < 15; iteration++)
+ {
+ var_out <<= 1;
+ L_num <<= 1;
+ if (L_num >= L_denom)
+ {
+ L_num -= L_denom;
+ var_out += 1;
+ }
+ }
+ }
+ }
+ return (var_out);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : norm_l |
+| |
+| Purpose : |
+| |
+| Produces the number of left shifts needed to normalize the 32 bit varia-|
+| ble L_var1 for positive values on the interval with minimum of |
+| 1073741824 and maximum of 2147483647, and for negative values on the in-|
+| terval with minimum of -2147483648 and maximum of -1073741824; in order |
+| to normalize the result, the following operation must be done : |
+| norm_L_var1 = L_shl(L_var1,norm_l(L_var1)). |
+| |
+| Complexity weight : 30 |
+| |
+| Inputs : |
+| |
+| L_var1 |
+| 32 bit long signed integer (Word32) whose value falls in the |
+| range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+| |
+| Outputs : |
+| |
+| none |
+| |
+| Return Value : |
+| |
+| var_out |
+| 16 bit short signed integer (Word16) whose value falls in the |
+| range : 0x0000 0000 <= var_out <= 0x0000 001f. |
+|___________________________________________________________________________|
+*/
+
+static_vo Word16 norm_l (Word32 L_var1)
+{
+ Word16 var_out = 0;
+ if (L_var1 != 0)
+ {
+ var_out = 31;
+ if (L_var1 != (Word32) 0xffffffffL)
+ {
+ L_var1 ^= (L_var1 >>31);
+ for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
+ {
+ L_var1 <<= 1;
+ }
+ }
+ }
+ return (var_out);
+}
+
+#endif //__BASIC_OP_H__
+
diff --git a/media/codecs/amrwb/enc/inc/bits.h b/media/codecs/amrwb/enc/inc/bits.h
new file mode 100644
index 0000000..57e71f7
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/bits.h
@@ -0,0 +1,92 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+* BITS.H *
+*--------------------------------------------------------------------------*
+* Number of bits for different modes *
+*--------------------------------------------------------------------------*/
+
+#ifndef __BITS_H__
+#define __BITS_H__
+
+#include <stdio.h>
+#include "typedef.h"
+#include "cnst.h"
+#include "cod_main.h"
+
+#define NBBITS_7k 132 /* 6.60k */
+#define NBBITS_9k 177 /* 8.85k */
+#define NBBITS_12k 253 /* 12.65k */
+#define NBBITS_14k 285 /* 14.25k */
+#define NBBITS_16k 317 /* 15.85k */
+#define NBBITS_18k 365 /* 18.25k */
+#define NBBITS_20k 397 /* 19.85k */
+#define NBBITS_23k 461 /* 23.05k */
+#define NBBITS_24k 477 /* 23.85k */
+
+#define NBBITS_SID 35
+#define NB_BITS_MAX NBBITS_24k
+
+#define BIT_0 ((Word16)-127)
+#define BIT_1 (Word16)127
+#define BIT_0_ITU (Word16)0x007F
+#define BIT_1_ITU (Word16)0x0081
+
+#define SIZE_MAX1 (3+NB_BITS_MAX) /* serial size max */
+#define TX_FRAME_TYPE (Word16)0x6b21
+#define RX_FRAME_TYPE (Word16)0x6b20
+
+static const Word16 nb_of_bits[NUM_OF_MODES] = {
+ NBBITS_7k,
+ NBBITS_9k,
+ NBBITS_12k,
+ NBBITS_14k,
+ NBBITS_16k,
+ NBBITS_18k,
+ NBBITS_20k,
+ NBBITS_23k,
+ NBBITS_24k,
+ NBBITS_SID
+};
+
+/*typedef struct
+{
+Word16 sid_update_counter;
+Word16 sid_handover_debt;
+Word16 prev_ft;
+} TX_State;
+*/
+
+//typedef struct
+//{
+// Word16 prev_ft;
+// Word16 prev_mode;
+//} RX_State;
+
+int PackBits(Word16 prms[], Word16 coding_mode, Word16 mode, Coder_State *st);
+
+
+void Parm_serial(
+ Word16 value, /* input : parameter value */
+ Word16 no_of_bits, /* input : number of bits */
+ Word16 ** prms
+ );
+
+
+#endif //__BITS_H__
+
diff --git a/media/codecs/amrwb/enc/inc/cnst.h b/media/codecs/amrwb/enc/inc/cnst.h
new file mode 100644
index 0000000..5395d2d
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/cnst.h
@@ -0,0 +1,81 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+ * CNST.H *
+ *--------------------------------------------------------------------------*
+ * Codec constant parameters (coder and decoder) *
+ *--------------------------------------------------------------------------*/
+
+#ifndef __CNST_H__
+#define __CNST_H__
+
+#define L_FRAME16k 320 /* Frame size at 16kHz */
+#define L_FRAME 256 /* Frame size */
+#define L_SUBFR16k 80 /* Subframe size at 16kHz */
+
+#define L_SUBFR 64 /* Subframe size */
+#define NB_SUBFR 4 /* Number of subframe per frame */
+
+#define L_NEXT 64 /* Overhead in LP analysis */
+#define L_WINDOW 384 /* window size in LP analysis */
+#define L_TOTAL 384 /* Total size of speech buffer. */
+#define M 16 /* Order of LP filter */
+#define M16k 20
+
+#define L_FILT16k 15 /* Delay of down-sampling filter */
+#define L_FILT 12 /* Delay of up-sampling filter */
+
+#define GP_CLIP 15565 /* Pitch gain clipping = 0.95 Q14 */
+#define PIT_SHARP 27853 /* pitch sharpening factor = 0.85 Q15 */
+
+#define PIT_MIN 34 /* Minimum pitch lag with resolution 1/4 */
+#define PIT_FR2 128 /* Minimum pitch lag with resolution 1/2 */
+#define PIT_FR1_9b 160 /* Minimum pitch lag with resolution 1 */
+#define PIT_FR1_8b 92 /* Minimum pitch lag with resolution 1 */
+#define PIT_MAX 231 /* Maximum pitch lag */
+#define L_INTERPOL (16+1) /* Length of filter for interpolation */
+
+#define OPL_DECIM 2 /* Decimation in open-loop pitch analysis */
+
+#define PREEMPH_FAC 22282 /* preemphasis factor (0.68 in Q15) */
+#define GAMMA1 30147 /* Weighting factor (numerator) (0.92 in Q15) */
+#define TILT_FAC 22282 /* tilt factor (denominator) (0.68 in Q15) */
+
+#define Q_MAX 8 /* scaling max for signal (see syn_filt_32) */
+
+#define RANDOM_INITSEED 21845 /* own random init value */
+
+#define L_MEANBUF 3
+#define ONE_PER_MEANBUF 10923
+
+#define MODE_7k 0
+#define MODE_9k 1
+#define MODE_12k 2
+#define MODE_14k 3
+#define MODE_16k 4
+#define MODE_18k 5
+#define MODE_20k 6
+#define MODE_23k 7
+#define MODE_24k 8
+#define MRDTX 9
+#define NUM_OF_MODES 10 /* see bits.h for bits definition */
+
+#define EHF_MASK (Word16)0x0008 /* homing frame pattern */
+
+#endif //__CNST_H__
+
diff --git a/media/codecs/amrwb/enc/inc/cod_main.h b/media/codecs/amrwb/enc/inc/cod_main.h
new file mode 100644
index 0000000..170981e
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/cod_main.h
@@ -0,0 +1,103 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+ * COD_MAIN.H *
+ *--------------------------------------------------------------------------*
+ * Static memory in the encoder *
+ *--------------------------------------------------------------------------*/
+#ifndef __COD_MAIN_H__
+#define __COD_MAIN_H__
+
+#include "cnst.h" /* coder constant parameters */
+
+#include "wb_vad.h"
+#include "dtx.h"
+#include "stream.h"
+#include "voAMRWB.h"
+
+typedef struct
+{
+ Word16 mem_decim[2 * L_FILT16k]; /* speech decimated filter memory */
+ Word16 mem_sig_in[6]; /* hp50 filter memory */
+ Word16 mem_preemph; /* speech preemph filter memory */
+ Word16 old_speech[L_TOTAL - L_FRAME]; /* old speech vector at 12.8kHz */
+ Word16 old_wsp[PIT_MAX / OPL_DECIM]; /* old decimated weighted speech vector */
+ Word16 old_exc[PIT_MAX + L_INTERPOL]; /* old excitation vector */
+ Word16 mem_levinson[M + 2]; /* levinson routine memory */
+ Word16 ispold[M]; /* old isp (immittance spectral pairs) */
+ Word16 ispold_q[M]; /* quantized old isp */
+ Word16 past_isfq[M]; /* past isf quantizer */
+ Word16 mem_wsp; /* wsp vector memory */
+ Word16 mem_decim2[3]; /* wsp decimation filter memory */
+ Word16 mem_w0; /* target vector memory */
+ Word16 mem_syn[M]; /* synthesis memory */
+ Word16 tilt_code; /* tilt of code */
+ Word16 old_wsp_max; /* old wsp maximum value */
+ Word16 old_wsp_shift; /* old wsp shift */
+ Word16 Q_old; /* old scaling factor */
+ Word16 Q_max[2]; /* old maximum scaling factor */
+ Word16 gp_clip[2]; /* gain of pitch clipping memory */
+ Word16 qua_gain[4]; /* gain quantizer memory */
+
+ Word16 old_T0_med;
+ Word16 ol_gain;
+ Word16 ada_w;
+ Word16 ol_wght_flg;
+ Word16 old_ol_lag[5];
+ Word16 hp_wsp_mem[9];
+ Word16 old_hp_wsp[L_FRAME / OPL_DECIM + (PIT_MAX / OPL_DECIM)];
+ VadVars *vadSt;
+ dtx_encState *dtx_encSt;
+ Word16 first_frame;
+ Word16 isfold[M]; /* old isf (frequency domain) */
+ Word32 L_gc_thres; /* threshold for noise enhancer */
+ Word16 mem_syn_hi[M]; /* modified synthesis memory (MSB) */
+ Word16 mem_syn_lo[M]; /* modified synthesis memory (LSB) */
+ Word16 mem_deemph; /* speech deemph filter memory */
+ Word16 mem_sig_out[6]; /* hp50 filter memory for synthesis */
+ Word16 mem_hp400[6]; /* hp400 filter memory for synthesis */
+ Word16 mem_oversamp[2 * L_FILT]; /* synthesis oversampled filter memory */
+ Word16 mem_syn_hf[M]; /* HF synthesis memory */
+ Word16 mem_hf[2 * L_FILT16k]; /* HF band-pass filter memory */
+ Word16 mem_hf2[2 * L_FILT16k]; /* HF band-pass filter memory */
+ Word16 seed2; /* random memory for HF generation */
+ Word16 vad_hist;
+ Word16 gain_alpha;
+ /* TX_State structure */
+ Word16 sid_update_counter;
+ Word16 sid_handover_debt;
+ Word16 prev_ft;
+ Word16 allow_dtx;
+ /*some input/output buffer parameters */
+ unsigned char *inputStream;
+ int inputSize;
+ VOAMRWBMODE mode;
+ VOAMRWBFRAMETYPE frameType;
+ unsigned short *outputStream;
+ int outputSize;
+ FrameStream *stream;
+ VO_MEM_OPERATOR *pvoMemop;
+ VO_MEM_OPERATOR voMemoprator;
+ VO_PTR hCheck;
+} Coder_State;
+
+typedef void* HAMRENC;
+
+#endif //__COD_MAIN_H__
+
+
diff --git a/media/codecs/amrwb/enc/inc/dtx.h b/media/codecs/amrwb/enc/inc/dtx.h
new file mode 100644
index 0000000..7d7ebd8
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/dtx.h
@@ -0,0 +1,115 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+ * DTX.H *
+ *--------------------------------------------------------------------------*
+ * Static memory, constants and frametypes for the DTX *
+ *--------------------------------------------------------------------------*/
+
+#ifndef __DTX_H__
+#define __DTX_H__
+
+#define DTX_MAX_EMPTY_THRESH 50
+#define DTX_HIST_SIZE 8
+#define DTX_HIST_SIZE_MIN_ONE 7
+#define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1)
+#define DTX_HANG_CONST 7 /* yields eight frames of SP HANGOVER */
+#define INV_MED_THRESH 14564
+#define ISF_GAP 128 /* 50 */
+#define ONE_MINUS_ISF_GAP (16384 - ISF_GAP)
+#define ISF_GAP 128
+#define ISF_DITH_GAP 448
+#define ISF_FACTOR_LOW 256
+#define ISF_FACTOR_STEP 2
+#define GAIN_THR 180
+#define GAIN_FACTOR 75
+
+typedef struct
+{
+ Word16 isf_hist[M * DTX_HIST_SIZE];
+ Word16 log_en_hist[DTX_HIST_SIZE];
+ Word16 hist_ptr;
+ Word16 log_en_index;
+ Word16 cng_seed;
+ /* DTX handler stuff */
+ Word16 dtxHangoverCount;
+ Word16 decAnaElapsedCount;
+ Word32 D[28];
+ Word32 sumD[DTX_HIST_SIZE];
+} dtx_encState;
+
+#define SPEECH 0
+#define DTX 1
+#define DTX_MUTE 2
+
+#define TX_SPEECH 0
+#define TX_SID_FIRST 1
+#define TX_SID_UPDATE 2
+#define TX_NO_DATA 3
+
+#define RX_SPEECH_GOOD 0
+#define RX_SPEECH_PROBABLY_DEGRADED 1
+#define RX_SPEECH_LOST 2
+#define RX_SPEECH_BAD 3
+#define RX_SID_FIRST 4
+#define RX_SID_UPDATE 5
+#define RX_SID_BAD 6
+#define RX_NO_DATA 7
+
+/*****************************************************************************
+ *
+ * DEFINITION OF DATA TYPES
+ *****************************************************************************/
+
+Word16 dtx_enc_init(dtx_encState ** st, Word16 isf_init[], VO_MEM_OPERATOR *pMemOP);
+Word16 dtx_enc_reset(dtx_encState * st, Word16 isf_init[]);
+void dtx_enc_exit(dtx_encState ** st, VO_MEM_OPERATOR *pMemOP);
+
+Word16 dtx_enc(
+ dtx_encState * st, /* i/o : State struct */
+ Word16 isf[M], /* o : CN ISF vector */
+ Word16 * exc2, /* o : CN excitation */
+ Word16 ** prms
+);
+
+Word16 dtx_buffer(
+ dtx_encState * st, /* i/o : State struct */
+ Word16 isf_new[], /* i : isf vector */
+ Word32 enr, /* i : residual energy (in L_FRAME) */
+ Word16 codec_mode
+);
+
+void tx_dtx_handler(dtx_encState * st, /* i/o : State struct */
+ Word16 vad_flag, /* i : vad decision */
+ Word16 * usedMode /* i/o : mode changed or not */
+);
+
+void Qisf_ns(
+ Word16 * isf1, /* input : ISF in the frequency domain (0..0.5) */
+ Word16 * isf_q, /* output: quantized ISF */
+ Word16 * indice /* output: quantization indices */
+);
+
+
+void Disf_ns(
+ Word16 * indice, /* input: quantization indices */
+ Word16 * isf_q /* input : ISF in the frequency domain (0..0.5) */
+);
+
+#endif //__DTX_H__
+
diff --git a/media/codecs/amrwb/enc/inc/grid100.tab b/media/codecs/amrwb/enc/inc/grid100.tab
new file mode 100644
index 0000000..658d28d
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/grid100.tab
@@ -0,0 +1,53 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+
+/*-------------------------------------------------------------*
+ * Table for az_isp() *
+ * *
+ * Vector grid[] is in Q15 *
+ * *
+ * grid[0] = 1.0; *
+ * grid[grid_points+1] = -1.0; *
+ * for (i = 1; i < grid_points; i++) *
+ * grid[i] = cos((6.283185307*i)/(2.0*grid_points)); *
+ * *
+ *-------------------------------------------------------------*/
+
+/* Version 101 points */
+
+#define GRID_POINTS 100
+
+const Word16 vogrid[GRID_POINTS+1] ={
+ 32767, 32751, 32703, 32622, 32509, 32364,
+ 32187, 31978, 31738, 31466, 31164, 30830,
+ 30466, 30072, 29649, 29196, 28714, 28204,
+ 27666, 27101, 26509, 25891, 25248, 24579,
+ 23886, 23170, 22431, 21669, 20887, 20083,
+ 19260, 18418, 17557, 16680, 15786, 14876,
+ 13951, 13013, 12062, 11099, 10125, 9141,
+ 8149, 7148, 6140, 5126, 4106, 3083,
+ 2057, 1029, 0, -1029, -2057, -3083,
+ -4106, -5126, -6140, -7148, -8149, -9141,
+ -10125, -11099, -12062, -13013, -13951, -14876,
+ -15786, -16680, -17557, -18418, -19260, -20083,
+ -20887, -21669, -22431, -23170, -23886, -24579,
+ -25248, -25891, -26509, -27101, -27666, -28204,
+ -28714, -29196, -29649, -30072, -30466, -30830,
+ -31164, -31466, -31738, -31978, -32187, -32364,
+ -32509, -32622, -32703, -32751, -32760};
+
diff --git a/media/codecs/amrwb/enc/inc/ham_wind.tab b/media/codecs/amrwb/enc/inc/ham_wind.tab
new file mode 100644
index 0000000..560a997
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/ham_wind.tab
@@ -0,0 +1,73 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/* Hamming_cos window for LPC analysis. */
+/* Create with function hamm_cos(window,384-128,128) */
+
+#define L_WINDOW 384
+
+const Word16 vo_window[L_WINDOW] = {
+ 2621, 2622, 2626, 2632, 2640, 2650, 2662, 2677,
+ 2694, 2714, 2735, 2759, 2785, 2814, 2844, 2877,
+ 2912, 2949, 2989, 3031, 3075, 3121, 3169, 3220,
+ 3273, 3328, 3385, 3444, 3506, 3569, 3635, 3703,
+ 3773, 3845, 3919, 3996, 4074, 4155, 4237, 4321,
+ 4408, 4496, 4587, 4680, 4774, 4870, 4969, 5069,
+ 5171, 5275, 5381, 5489, 5599, 5710, 5824, 5939,
+ 6056, 6174, 6295, 6417, 6541, 6666, 6793, 6922,
+ 7052, 7185, 7318, 7453, 7590, 7728, 7868, 8009,
+ 8152, 8296, 8442, 8589, 8737, 8887, 9038, 9191,
+ 9344, 9499, 9655, 9813, 9971, 10131, 10292, 10454,
+ 10617, 10781, 10946, 11113, 11280, 11448, 11617, 11787,
+ 11958, 12130, 12303, 12476, 12650, 12825, 13001, 13178,
+ 13355, 13533, 13711, 13890, 14070, 14250, 14431, 14612,
+ 14793, 14975, 15158, 15341, 15524, 15708, 15891, 16076,
+ 16260, 16445, 16629, 16814, 16999, 17185, 17370, 17555,
+ 17740, 17926, 18111, 18296, 18481, 18666, 18851, 19036,
+ 19221, 19405, 19589, 19773, 19956, 20139, 20322, 20504,
+ 20686, 20867, 21048, 21229, 21408, 21588, 21767, 21945,
+ 22122, 22299, 22475, 22651, 22825, 22999, 23172, 23344,
+ 23516, 23686, 23856, 24025, 24192, 24359, 24525, 24689,
+ 24853, 25016, 25177, 25337, 25496, 25654, 25811, 25967,
+ 26121, 26274, 26426, 26576, 26725, 26873, 27019, 27164,
+ 27308, 27450, 27590, 27729, 27867, 28003, 28137, 28270,
+ 28401, 28531, 28659, 28785, 28910, 29033, 29154, 29274,
+ 29391, 29507, 29622, 29734, 29845, 29953, 30060, 30165,
+ 30268, 30370, 30469, 30566, 30662, 30755, 30847, 30936,
+ 31024, 31109, 31193, 31274, 31354, 31431, 31506, 31579,
+ 31651, 31719, 31786, 31851, 31914, 31974, 32032, 32088,
+ 32142, 32194, 32243, 32291, 32336, 32379, 32419, 32458,
+ 32494, 32528, 32560, 32589, 32617, 32642, 32664, 32685,
+ 32703, 32719, 32733, 32744, 32753, 32760, 32764, 32767,
+ 32767, 32765, 32757, 32745, 32727, 32705, 32678, 32646,
+ 32609, 32567, 32520, 32468, 32411, 32349, 32283, 32211,
+ 32135, 32054, 31968, 31877, 31781, 31681, 31575, 31465,
+ 31351, 31231, 31107, 30978, 30844, 30706, 30563, 30415,
+ 30263, 30106, 29945, 29779, 29609, 29434, 29255, 29071,
+ 28883, 28691, 28494, 28293, 28087, 27878, 27664, 27446,
+ 27224, 26997, 26767, 26533, 26294, 26052, 25806, 25555,
+ 25301, 25043, 24782, 24516, 24247, 23974, 23698, 23418,
+ 23134, 22847, 22557, 22263, 21965, 21665, 21361, 21054,
+ 20743, 20430, 20113, 19794, 19471, 19146, 18817, 18486,
+ 18152, 17815, 17476, 17134, 16789, 16442, 16092, 15740,
+ 15385, 15028, 14669, 14308, 13944, 13579, 13211, 12841,
+ 12470, 12096, 11721, 11344, 10965, 10584, 10202, 9819,
+ 9433, 9047, 8659, 8270, 7879, 7488, 7095, 6701,
+ 6306, 5910, 5514, 5116, 4718, 4319, 3919, 3519,
+ 3118, 2716, 2315, 1913, 1510, 1108, 705, 302};
+
+
diff --git a/media/codecs/amrwb/enc/inc/homing.tab b/media/codecs/amrwb/enc/inc/homing.tab
new file mode 100644
index 0000000..6408d3a
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/homing.tab
@@ -0,0 +1,123 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+
+#define DHF_PARMS_MAX 32 /* homing frame pattern */
+#define NUM_OF_SPMODES 9
+
+#define PRML 15
+#define PRMN_7k (NBBITS_7k/PRML + 1)
+#define PRMN_9k (NBBITS_9k/PRML + 1)
+#define PRMN_12k (NBBITS_12k/PRML + 1)
+#define PRMN_14k (NBBITS_14k/PRML + 1)
+#define PRMN_16k (NBBITS_16k/PRML + 1)
+#define PRMN_18k (NBBITS_18k/PRML + 1)
+#define PRMN_20k (NBBITS_20k/PRML + 1)
+#define PRMN_23k (NBBITS_23k/PRML + 1)
+#define PRMN_24k (NBBITS_24k/PRML + 1)
+
+static const Word16 dfh_M7k[PRMN_7k] =
+{
+ 3168, 29954, 29213, 16121,
+ 64, 13440, 30624, 16430,
+ 19008
+};
+
+static const Word16 dfh_M9k[PRMN_9k] =
+{
+ 3168, 31665, 9943, 9123,
+ 15599, 4358, 20248, 2048,
+ 17040, 27787, 16816, 13888
+};
+
+static const Word16 dfh_M12k[PRMN_12k] =
+{
+ 3168, 31665, 9943, 9128,
+ 3647, 8129, 30930, 27926,
+ 18880, 12319, 496, 1042,
+ 4061, 20446, 25629, 28069,
+ 13948
+};
+
+static const Word16 dfh_M14k[PRMN_14k] =
+{
+ 3168, 31665, 9943, 9131,
+ 24815, 655, 26616, 26764,
+ 7238, 19136, 6144, 88,
+ 4158, 25733, 30567, 30494,
+ 221, 20321, 17823
+};
+
+static const Word16 dfh_M16k[PRMN_16k] =
+{
+ 3168, 31665, 9943, 9131,
+ 24815, 700, 3824, 7271,
+ 26400, 9528, 6594, 26112,
+ 108, 2068, 12867, 16317,
+ 23035, 24632, 7528, 1752,
+ 6759, 24576
+};
+
+static const Word16 dfh_M18k[PRMN_18k] =
+{
+ 3168, 31665, 9943, 9135,
+ 14787, 14423, 30477, 24927,
+ 25345, 30154, 916, 5728,
+ 18978, 2048, 528, 16449,
+ 2436, 3581, 23527, 29479,
+ 8237, 16810, 27091, 19052,
+ 0
+};
+
+static const Word16 dfh_M20k[PRMN_20k] =
+{
+ 3168, 31665, 9943, 9129,
+ 8637, 31807, 24646, 736,
+ 28643, 2977, 2566, 25564,
+ 12930, 13960, 2048, 834,
+ 3270, 4100, 26920, 16237,
+ 31227, 17667, 15059, 20589,
+ 30249, 29123, 0
+};
+
+static const Word16 dfh_M23k[PRMN_23k] =
+{
+ 3168, 31665, 9943, 9132,
+ 16748, 3202, 28179, 16317,
+ 30590, 15857, 19960, 8818,
+ 21711, 21538, 4260, 16690,
+ 20224, 3666, 4194, 9497,
+ 16320, 15388, 5755, 31551,
+ 14080, 3574, 15932, 50,
+ 23392, 26053, 31216
+};
+
+static const Word16 dfh_M24k[PRMN_24k] =
+{
+ 3168, 31665, 9943, 9134,
+ 24776, 5857, 18475, 28535,
+ 29662, 14321, 16725, 4396,
+ 29353, 10003, 17068, 20504,
+ 720, 0, 8465, 12581,
+ 28863, 24774, 9709, 26043,
+ 7941, 27649, 13965, 15236,
+ 18026, 22047, 16681, 3968
+};
+
+
+
diff --git a/media/codecs/amrwb/enc/inc/isp_isf.tab b/media/codecs/amrwb/enc/inc/isp_isf.tab
new file mode 100644
index 0000000..865eea0
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/isp_isf.tab
@@ -0,0 +1,62 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*-----------------------------------------------------*
+ | Tables for function Isf_isp() and Isp_isf() |
+ *-----------------------------------------------------*/
+
+/* table of cos(x) in Q15 */
+
+static const Word16 table[129] = {
+ 32767,
+ 32758, 32729, 32679, 32610, 32522, 32413, 32286, 32138,
+ 31972, 31786, 31581, 31357, 31114, 30853, 30572, 30274,
+ 29957, 29622, 29269, 28899, 28511, 28106, 27684, 27246,
+ 26791, 26320, 25833, 25330, 24812, 24279, 23732, 23170,
+ 22595, 22006, 21403, 20788, 20160, 19520, 18868, 18205,
+ 17531, 16846, 16151, 15447, 14733, 14010, 13279, 12540,
+ 11793, 11039, 10279, 9512, 8740, 7962, 7180, 6393,
+ 5602, 4808, 4011, 3212, 2411, 1608, 804, 0,
+ -804, -1608, -2411, -3212, -4011, -4808, -5602, -6393,
+ -7180, -7962, -8740, -9512, -10279, -11039, -11793, -12540,
+ -13279, -14010, -14733, -15447, -16151, -16846, -17531, -18205,
+ -18868, -19520, -20160, -20788, -21403, -22006, -22595, -23170,
+ -23732, -24279, -24812, -25330, -25833, -26320, -26791, -27246,
+ -27684, -28106, -28511, -28899, -29269, -29622, -29957, -30274,
+ -30572, -30853, -31114, -31357, -31581, -31786, -31972, -32138,
+ -32286, -32413, -32522, -32610, -32679, -32729, -32758, -32768};
+
+/* slope in Q11 used to compute y = acos(x) */
+
+static const Word16 slope[128] = {
+ -26214, -9039, -5243, -3799, -2979, -2405, -2064, -1771,
+ -1579, -1409, -1279, -1170, -1079, -1004, -933, -880,
+ -827, -783, -743, -708, -676, -647, -621, -599,
+ -576, -557, -538, -521, -506, -492, -479, -466,
+ -456, -445, -435, -426, -417, -410, -402, -395,
+ -389, -383, -377, -372, -367, -363, -359, -355,
+ -351, -348, -345, -342, -340, -337, -335, -333,
+ -331, -330, -329, -328, -327, -326, -326, -326,
+ -326, -326, -326, -327, -328, -329, -330, -331,
+ -333, -335, -337, -340, -342, -345, -348, -351,
+ -355, -359, -363, -367, -372, -377, -383, -389,
+ -395, -402, -410, -417, -426, -435, -445, -456,
+ -466, -479, -492, -506, -521, -538, -557, -576,
+ -599, -621, -647, -676, -708, -743, -783, -827,
+ -880, -933, -1004, -1079, -1170, -1279, -1409, -1579,
+ -1771, -2064, -2405, -2979, -3799, -5243, -9039, -26214};
+
diff --git a/media/codecs/amrwb/enc/inc/lag_wind.tab b/media/codecs/amrwb/enc/inc/lag_wind.tab
new file mode 100644
index 0000000..9c73357
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/lag_wind.tab
@@ -0,0 +1,81 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*-----------------------------------------------------*
+ | Table of lag_window for autocorrelation. |
+ | noise floor = 1.0001 = (0.9999 on r[1] ..r[16]) |
+ | Bandwidth expansion = 60 Hz |
+ | Sampling frequency = 12800 Hz |
+ | |
+ | Special double precision format. See "math_op.c" |
+ | |
+ | lag_wind[0] = 1.00000000 (not stored) |
+ | lag_wind[1] = 0.99946642 |
+ | lag_wind[2] = 0.99816680 |
+ | lag_wind[3] = 0.99600452 |
+ | lag_wind[4] = 0.99298513 |
+ | lag_wind[5] = 0.98911655 |
+ | lag_wind[6] = 0.98440880 |
+ | lag_wind[7] = 0.97887397 |
+ | lag_wind[8] = 0.97252619 |
+ | lag_wind[9] = 0.96538186 |
+ | lag_wind[10]= 0.95745903 |
+ | lag_wind[11]= 0.94877797 |
+ | lag_wind[12]= 0.93936038 |
+ | lag_wind[13]= 0.92922986 |
+ | lag_wind[14]= 0.91841155 |
+ | lag_wind[15]= 0.90693212 |
+ | lag_wind[16]= 0.89481968 |
+ ------------------------------------------------------*/
+
+#define M 16
+
+static Word16 volag_h[M] = {
+ 32750,
+ 32707,
+ 32637,
+ 32538,
+ 32411,
+ 32257,
+ 32075,
+ 31867,
+ 31633,
+ 31374,
+ 31089,
+ 30780,
+ 30449,
+ 30094,
+ 29718,
+ 29321};
+
+static Word16 volag_l[M] = {
+ 16896,
+ 30464,
+ 2496,
+ 4480,
+ 12160,
+ 3520,
+ 24320,
+ 24192,
+ 20736,
+ 576,
+ 18240,
+ 31488,
+ 128,
+ 16704,
+ 11520,
+ 14784};
diff --git a/media/codecs/amrwb/enc/inc/log2.h b/media/codecs/amrwb/enc/inc/log2.h
new file mode 100644
index 0000000..3d9a6c4
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/log2.h
@@ -0,0 +1,62 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/********************************************************************************
+*
+* File : log2.h
+* Purpose : Computes log2(L_x)
+*
+********************************************************************************
+*/
+#ifndef __LOG2_H__
+#define __LOG2_H__
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+
+/*
+********************************************************************************
+* DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+* DECLARATION OF PROTOTYPES
+********************************************************************************
+*/
+void Log2 (
+ Word32 L_x, /* (i) : input value */
+ Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1)*/
+ );
+
+void Log2_norm (
+ Word32 L_x, /* (i) : input value (normalized) */
+ Word16 exp, /* (i) : norm_l (L_x) */
+ Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ );
+
+#endif //__LOG2_H__
+
+
diff --git a/media/codecs/amrwb/enc/inc/log2_tab.h b/media/codecs/amrwb/enc/inc/log2_tab.h
new file mode 100644
index 0000000..85fa73c
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/log2_tab.h
@@ -0,0 +1,35 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+
+/*******************************************************************************
+*
+* File : log2.tab
+* Purpose : Table for routine Log2().
+* $Id $
+*
+********************************************************************************
+*/
+static const Word16 table[33] =
+{
+ 0, 1455, 2866, 4236, 5568, 6863, 8124, 9352, 10549, 11716,
+ 12855, 13967, 15054, 16117, 17156, 18172, 19167, 20142, 21097, 22033,
+ 22951, 23852, 24735, 25603, 26455, 27291, 28113, 28922, 29716, 30497,
+ 31266, 32023, 32767
+};
+
diff --git a/media/codecs/amrwb/enc/inc/main.h b/media/codecs/amrwb/enc/inc/main.h
new file mode 100644
index 0000000..adef2df
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/main.h
@@ -0,0 +1,45 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+ * MAIN.H *
+ *--------------------------------------------------------------------------*
+ * Main functions *
+ *--------------------------------------------------------------------------*/
+
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+void coder(
+ Word16 * mode, /* input : used mode */
+ Word16 speech16k[], /* input : 320 new speech samples (at 16 kHz) */
+ Word16 prms[], /* output: output parameters */
+ Word16 * ser_size, /* output: bit rate of the used mode */
+ void *spe_state, /* i/o : State structure */
+ Word16 allow_dtx /* input : DTX ON/OFF */
+);
+
+
+
+void Reset_encoder(void *st, Word16 reset_all);
+
+
+Word16 encoder_homing_frame_test(Word16 input_frame[]);
+
+#endif //__MAIN_H__
+
diff --git a/media/codecs/amrwb/enc/inc/math_op.h b/media/codecs/amrwb/enc/inc/math_op.h
new file mode 100644
index 0000000..c3c00bc
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/math_op.h
@@ -0,0 +1,55 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+ * MATH_OP.H *
+ *--------------------------------------------------------------------------*
+ * Mathematical operations *
+ *--------------------------------------------------------------------------*/
+
+#ifndef __MATH_OP_H__
+#define __MATH_OP_H__
+
+Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */
+ Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */
+ );
+
+void Isqrt_n(
+ Word32 * frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */
+ Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */
+ );
+
+Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */
+ Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */
+ Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */
+ );
+
+Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */
+ Word16 x[], /* (i) 12bits: x vector */
+ Word16 y[], /* (i) 12bits: y vector */
+ Word16 lg, /* (i) : vector length */
+ Word16 * exp /* (o) : exponent of result (0..+30) */
+ );
+
+Word32 Dot_product12_asm( /* (o) Q31: normalized result (1 < val <= -1) */
+ Word16 x[], /* (i) 12bits: x vector */
+ Word16 y[], /* (i) 12bits: y vector */
+ Word16 lg, /* (i) : vector length */
+ Word16 * exp /* (o) : exponent of result (0..+30) */
+ );
+#endif //__MATH_OP_H__
+
diff --git a/media/codecs/amrwb/enc/inc/mem_align.h b/media/codecs/amrwb/enc/inc/mem_align.h
new file mode 100644
index 0000000..2ae5a6c
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/mem_align.h
@@ -0,0 +1,35 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+ File: mem_align.h
+
+ Content: Memory alloc alignments functions
+
+*******************************************************************************/
+
+#ifndef __VO_MEM_ALIGN_H__
+#define __VO_MEM_ALIGN_H__
+
+#include "voMem.h"
+#include "typedef.h"
+
+extern void *mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID);
+extern void mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID);
+
+#endif /* __VO_MEM_ALIGN_H__ */
+
+
+
diff --git a/media/codecs/amrwb/enc/inc/mime_io.tab b/media/codecs/amrwb/enc/inc/mime_io.tab
new file mode 100644
index 0000000..7b485ea
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/mime_io.tab
@@ -0,0 +1,368 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+#include <stdio.h>
+#include "typedef.h"
+
+static UWord8 toc_byte[16] = {0x04, 0x0C, 0x14, 0x1C, 0x24, 0x2C, 0x34, 0x3C,
+ 0x44, 0x4C, 0x54, 0x5C, 0x64, 0x6C, 0x74, 0x7C};
+
+/* number of speech bits for all modes */
+static Word16 unpacked_size[16] = {132, 177, 253, 285, 317, 365, 397, 461,
+ 477, 35, 0, 0, 0, 0, 0, 0};
+
+/* size of packed frame for each mode, excluding TOC byte */
+static Word16 packed_size[16] = {17, 23, 32, 36, 40, 46, 50, 58,
+ 60, 5, 0, 0, 0, 0, 0, 0};
+
+/* number of unused speech bits in packed format for each mode */
+static Word16 unused_size[16] = {4, 7, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0};
+
+/* sorting tables for all modes */
+
+static Word16 sort_660[132] = {
+ 0, 5, 6, 7, 61, 84, 107, 130, 62, 85,
+ 8, 4, 37, 38, 39, 40, 58, 81, 104, 127,
+ 60, 83, 106, 129, 108, 131, 128, 41, 42, 80,
+ 126, 1, 3, 57, 103, 82, 105, 59, 2, 63,
+ 109, 110, 86, 19, 22, 23, 64, 87, 18, 20,
+ 21, 17, 13, 88, 43, 89, 65, 111, 14, 24,
+ 25, 26, 27, 28, 15, 16, 44, 90, 66, 112,
+ 9, 11, 10, 12, 67, 113, 29, 30, 31, 32,
+ 34, 33, 35, 36, 45, 51, 68, 74, 91, 97,
+ 114, 120, 46, 69, 92, 115, 52, 75, 98, 121,
+ 47, 70, 93, 116, 53, 76, 99, 122, 48, 71,
+ 94, 117, 54, 77, 100, 123, 49, 72, 95, 118,
+ 55, 78, 101, 124, 50, 73, 96, 119, 56, 79,
+ 102, 125
+};
+
+static Word16 sort_885[177] = {
+ 0, 4, 6, 7, 5, 3, 47, 48, 49, 112,
+ 113, 114, 75, 106, 140, 171, 80, 111, 145, 176,
+ 77, 108, 142, 173, 78, 109, 143, 174, 79, 110,
+ 144, 175, 76, 107, 141, 172, 50, 115, 51, 2,
+ 1, 81, 116, 146, 19, 21, 12, 17, 18, 20,
+ 16, 25, 13, 10, 14, 24, 23, 22, 26, 8,
+ 15, 52, 117, 31, 82, 147, 9, 33, 11, 83,
+ 148, 53, 118, 28, 27, 84, 149, 34, 35, 29,
+ 46, 32, 30, 54, 119, 37, 36, 39, 38, 40,
+ 85, 150, 41, 42, 43, 44, 45, 55, 60, 65,
+ 70, 86, 91, 96, 101, 120, 125, 130, 135, 151,
+ 156, 161, 166, 56, 87, 121, 152, 61, 92, 126,
+ 157, 66, 97, 131, 162, 71, 102, 136, 167, 57,
+ 88, 122, 153, 62, 93, 127, 158, 67, 98, 132,
+ 163, 72, 103, 137, 168, 58, 89, 123, 154, 63,
+ 94, 128, 159, 68, 99, 133, 164, 73, 104, 138,
+ 169, 59, 90, 124, 155, 64, 95, 129, 160, 69,
+ 100, 134, 165, 74, 105, 139, 170
+};
+
+static Word16 sort_1265[253] = {
+ 0, 4, 6, 93, 143, 196, 246, 7, 5, 3,
+ 47, 48, 49, 50, 51, 150, 151, 152, 153, 154,
+ 94, 144, 197, 247, 99, 149, 202, 252, 96, 146,
+ 199, 249, 97, 147, 200, 250, 100, 203, 98, 148,
+ 201, 251, 95, 145, 198, 248, 52, 2, 1, 101,
+ 204, 155, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 156, 31, 102, 205, 9, 33, 11, 103, 206, 54,
+ 157, 28, 27, 104, 207, 34, 35, 29, 46, 32,
+ 30, 55, 158, 37, 36, 39, 38, 40, 105, 208,
+ 41, 42, 43, 44, 45, 56, 106, 159, 209, 57,
+ 66, 75, 84, 107, 116, 125, 134, 160, 169, 178,
+ 187, 210, 219, 228, 237, 58, 108, 161, 211, 62,
+ 112, 165, 215, 67, 117, 170, 220, 71, 121, 174,
+ 224, 76, 126, 179, 229, 80, 130, 183, 233, 85,
+ 135, 188, 238, 89, 139, 192, 242, 59, 109, 162,
+ 212, 63, 113, 166, 216, 68, 118, 171, 221, 72,
+ 122, 175, 225, 77, 127, 180, 230, 81, 131, 184,
+ 234, 86, 136, 189, 239, 90, 140, 193, 243, 60,
+ 110, 163, 213, 64, 114, 167, 217, 69, 119, 172,
+ 222, 73, 123, 176, 226, 78, 128, 181, 231, 82,
+ 132, 185, 235, 87, 137, 190, 240, 91, 141, 194,
+ 244, 61, 111, 164, 214, 65, 115, 168, 218, 70,
+ 120, 173, 223, 74, 124, 177, 227, 79, 129, 182,
+ 232, 83, 133, 186, 236, 88, 138, 191, 241, 92,
+ 142, 195, 245
+};
+
+static Word16 sort_1425[285] = {
+ 0, 4, 6, 101, 159, 220, 278, 7, 5, 3,
+ 47, 48, 49, 50, 51, 166, 167, 168, 169, 170,
+ 102, 160, 221, 279, 107, 165, 226, 284, 104, 162,
+ 223, 281, 105, 163, 224, 282, 108, 227, 106, 164,
+ 225, 283, 103, 161, 222, 280, 52, 2, 1, 109,
+ 228, 171, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 172, 31, 110, 229, 9, 33, 11, 111, 230, 54,
+ 173, 28, 27, 112, 231, 34, 35, 29, 46, 32,
+ 30, 55, 174, 37, 36, 39, 38, 40, 113, 232,
+ 41, 42, 43, 44, 45, 56, 114, 175, 233, 62,
+ 120, 181, 239, 75, 133, 194, 252, 57, 115, 176,
+ 234, 63, 121, 182, 240, 70, 128, 189, 247, 76,
+ 134, 195, 253, 83, 141, 202, 260, 92, 150, 211,
+ 269, 84, 142, 203, 261, 93, 151, 212, 270, 85,
+ 143, 204, 262, 94, 152, 213, 271, 86, 144, 205,
+ 263, 95, 153, 214, 272, 64, 122, 183, 241, 77,
+ 135, 196, 254, 65, 123, 184, 242, 78, 136, 197,
+ 255, 87, 145, 206, 264, 96, 154, 215, 273, 58,
+ 116, 177, 235, 66, 124, 185, 243, 71, 129, 190,
+ 248, 79, 137, 198, 256, 88, 146, 207, 265, 97,
+ 155, 216, 274, 59, 117, 178, 236, 67, 125, 186,
+ 244, 72, 130, 191, 249, 80, 138, 199, 257, 89,
+ 147, 208, 266, 98, 156, 217, 275, 60, 118, 179,
+ 237, 68, 126, 187, 245, 73, 131, 192, 250, 81,
+ 139, 200, 258, 90, 148, 209, 267, 99, 157, 218,
+ 276, 61, 119, 180, 238, 69, 127, 188, 246, 74,
+ 132, 193, 251, 82, 140, 201, 259, 91, 149, 210,
+ 268, 100, 158, 219, 277
+};
+
+static Word16 sort_1585[317] = {
+ 0, 4, 6, 109, 175, 244, 310, 7, 5, 3,
+ 47, 48, 49, 50, 51, 182, 183, 184, 185, 186,
+ 110, 176, 245, 311, 115, 181, 250, 316, 112, 178,
+ 247, 313, 113, 179, 248, 314, 116, 251, 114, 180,
+ 249, 315, 111, 177, 246, 312, 52, 2, 1, 117,
+ 252, 187, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 188, 31, 118, 253, 9, 33, 11, 119, 254, 54,
+ 189, 28, 27, 120, 255, 34, 35, 29, 46, 32,
+ 30, 55, 190, 37, 36, 39, 38, 40, 121, 256,
+ 41, 42, 43, 44, 45, 56, 122, 191, 257, 63,
+ 129, 198, 264, 76, 142, 211, 277, 89, 155, 224,
+ 290, 102, 168, 237, 303, 57, 123, 192, 258, 70,
+ 136, 205, 271, 83, 149, 218, 284, 96, 162, 231,
+ 297, 62, 128, 197, 263, 75, 141, 210, 276, 88,
+ 154, 223, 289, 101, 167, 236, 302, 58, 124, 193,
+ 259, 71, 137, 206, 272, 84, 150, 219, 285, 97,
+ 163, 232, 298, 59, 125, 194, 260, 64, 130, 199,
+ 265, 67, 133, 202, 268, 72, 138, 207, 273, 77,
+ 143, 212, 278, 80, 146, 215, 281, 85, 151, 220,
+ 286, 90, 156, 225, 291, 93, 159, 228, 294, 98,
+ 164, 233, 299, 103, 169, 238, 304, 106, 172, 241,
+ 307, 60, 126, 195, 261, 65, 131, 200, 266, 68,
+ 134, 203, 269, 73, 139, 208, 274, 78, 144, 213,
+ 279, 81, 147, 216, 282, 86, 152, 221, 287, 91,
+ 157, 226, 292, 94, 160, 229, 295, 99, 165, 234,
+ 300, 104, 170, 239, 305, 107, 173, 242, 308, 61,
+ 127, 196, 262, 66, 132, 201, 267, 69, 135, 204,
+ 270, 74, 140, 209, 275, 79, 145, 214, 280, 82,
+ 148, 217, 283, 87, 153, 222, 288, 92, 158, 227,
+ 293, 95, 161, 230, 296, 100, 166, 235, 301, 105,
+ 171, 240, 306, 108, 174, 243, 309
+};
+
+static Word16 sort_1825[365] = {
+ 0, 4, 6, 121, 199, 280, 358, 7, 5, 3,
+ 47, 48, 49, 50, 51, 206, 207, 208, 209, 210,
+ 122, 200, 281, 359, 127, 205, 286, 364, 124, 202,
+ 283, 361, 125, 203, 284, 362, 128, 287, 126, 204,
+ 285, 363, 123, 201, 282, 360, 52, 2, 1, 129,
+ 288, 211, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 212, 31, 130, 289, 9, 33, 11, 131, 290, 54,
+ 213, 28, 27, 132, 291, 34, 35, 29, 46, 32,
+ 30, 55, 214, 37, 36, 39, 38, 40, 133, 292,
+ 41, 42, 43, 44, 45, 56, 134, 215, 293, 198,
+ 299, 136, 120, 138, 60, 279, 58, 62, 357, 139,
+ 140, 295, 156, 57, 219, 297, 63, 217, 137, 170,
+ 300, 222, 64, 106, 61, 78, 294, 92, 142, 141,
+ 135, 221, 296, 301, 343, 59, 298, 184, 329, 315,
+ 220, 216, 265, 251, 218, 237, 352, 223, 157, 86,
+ 171, 87, 164, 351, 111, 302, 65, 178, 115, 323,
+ 72, 192, 101, 179, 93, 73, 193, 151, 337, 309,
+ 143, 274, 69, 324, 165, 150, 97, 338, 110, 310,
+ 330, 273, 68, 107, 175, 245, 114, 79, 113, 189,
+ 246, 259, 174, 71, 185, 96, 344, 100, 322, 83,
+ 334, 316, 333, 252, 161, 348, 147, 82, 269, 232,
+ 260, 308, 353, 347, 163, 231, 306, 320, 188, 270,
+ 146, 177, 266, 350, 256, 85, 149, 116, 191, 160,
+ 238, 258, 336, 305, 255, 88, 224, 99, 339, 230,
+ 228, 227, 272, 242, 241, 319, 233, 311, 102, 74,
+ 180, 275, 66, 194, 152, 325, 172, 247, 244, 261,
+ 117, 158, 166, 354, 75, 144, 108, 312, 94, 186,
+ 303, 80, 234, 89, 195, 112, 340, 181, 345, 317,
+ 326, 276, 239, 167, 118, 313, 70, 355, 327, 253,
+ 190, 176, 271, 104, 98, 153, 103, 90, 76, 267,
+ 277, 248, 225, 262, 182, 84, 154, 235, 335, 168,
+ 331, 196, 341, 249, 162, 307, 148, 349, 263, 321,
+ 257, 243, 229, 356, 159, 119, 67, 187, 173, 145,
+ 240, 77, 304, 332, 314, 342, 109, 254, 81, 278,
+ 105, 91, 346, 318, 183, 250, 197, 328, 95, 155,
+ 169, 268, 226, 236, 264
+};
+
+static Word16 sort_1985[397] = {
+ 0, 4, 6, 129, 215, 304, 390, 7, 5, 3,
+ 47, 48, 49, 50, 51, 222, 223, 224, 225, 226,
+ 130, 216, 305, 391, 135, 221, 310, 396, 132, 218,
+ 307, 393, 133, 219, 308, 394, 136, 311, 134, 220,
+ 309, 395, 131, 217, 306, 392, 52, 2, 1, 137,
+ 312, 227, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 228, 31, 138, 313, 9, 33, 11, 139, 314, 54,
+ 229, 28, 27, 140, 315, 34, 35, 29, 46, 32,
+ 30, 55, 230, 37, 36, 39, 38, 40, 141, 316,
+ 41, 42, 43, 44, 45, 56, 142, 231, 317, 63,
+ 73, 92, 340, 82, 324, 149, 353, 159, 334, 165,
+ 338, 178, 163, 254, 77, 168, 257, 153, 343, 57,
+ 248, 238, 79, 252, 166, 67, 80, 201, 101, 267,
+ 143, 164, 341, 255, 339, 187, 376, 318, 78, 328,
+ 362, 115, 232, 242, 253, 290, 276, 62, 58, 158,
+ 68, 93, 179, 319, 148, 169, 154, 72, 385, 329,
+ 333, 344, 102, 83, 144, 233, 323, 124, 243, 192,
+ 354, 237, 64, 247, 202, 209, 150, 116, 335, 268,
+ 239, 299, 188, 196, 298, 94, 195, 258, 123, 363,
+ 384, 109, 325, 371, 170, 370, 84, 110, 295, 180,
+ 74, 210, 191, 106, 291, 205, 367, 381, 377, 206,
+ 355, 122, 119, 120, 383, 160, 105, 108, 277, 380,
+ 294, 284, 285, 345, 208, 269, 249, 366, 386, 300,
+ 297, 259, 125, 369, 197, 97, 194, 286, 211, 281,
+ 280, 183, 372, 87, 155, 283, 59, 348, 327, 184,
+ 76, 111, 330, 203, 349, 69, 98, 152, 145, 189,
+ 66, 320, 337, 173, 358, 251, 198, 174, 263, 262,
+ 126, 241, 193, 88, 388, 117, 95, 387, 112, 359,
+ 287, 244, 103, 272, 301, 171, 162, 234, 273, 127,
+ 373, 181, 292, 85, 378, 302, 121, 107, 364, 346,
+ 356, 212, 278, 213, 65, 382, 288, 207, 113, 175,
+ 99, 296, 374, 368, 199, 260, 185, 336, 331, 161,
+ 270, 264, 250, 240, 75, 350, 151, 60, 89, 321,
+ 156, 274, 360, 326, 70, 282, 167, 146, 352, 81,
+ 91, 389, 266, 245, 177, 235, 190, 256, 204, 342,
+ 128, 118, 303, 104, 379, 182, 114, 375, 200, 96,
+ 293, 172, 214, 365, 279, 86, 289, 351, 347, 357,
+ 261, 186, 176, 271, 90, 100, 147, 322, 275, 361,
+ 71, 332, 61, 265, 157, 246, 236
+};
+
+static Word16 sort_2305[461] = {
+ 0, 4, 6, 145, 247, 352, 454, 7, 5, 3,
+ 47, 48, 49, 50, 51, 254, 255, 256, 257, 258,
+ 146, 248, 353, 455, 151, 253, 358, 460, 148, 250,
+ 355, 457, 149, 251, 356, 458, 152, 359, 150, 252,
+ 357, 459, 147, 249, 354, 456, 52, 2, 1, 153,
+ 360, 259, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 260, 31, 154, 361, 9, 33, 11, 155, 362, 54,
+ 261, 28, 27, 156, 363, 34, 35, 29, 46, 32,
+ 30, 55, 262, 37, 36, 39, 38, 40, 157, 364,
+ 41, 42, 43, 44, 45, 56, 158, 263, 365, 181,
+ 192, 170, 79, 57, 399, 90, 159, 297, 377, 366,
+ 275, 68, 183, 388, 286, 194, 299, 92 , 70, 182,
+ 401, 172, 59, 91, 58, 400, 368, 161, 81, 160,
+ 264, 171, 80, 389, 390, 378, 379, 193, 298, 69,
+ 266, 265, 367, 277, 288, 276, 287, 184, 60, 195,
+ 82, 93, 71, 369, 402, 173, 162, 444, 300, 391,
+ 98, 76, 278, 61, 267, 374, 135, 411, 167, 102,
+ 380, 200, 87, 178, 65, 94, 204, 124, 72, 342,
+ 189, 305, 381, 396, 433, 301, 226, 407, 289, 237,
+ 113, 215, 185, 128, 309, 403, 116, 320, 196, 331,
+ 370, 422, 174, 64, 392, 83, 425, 219, 134, 188,
+ 432, 112, 427, 139, 279, 163, 436, 208, 447, 218,
+ 236, 229, 97, 294, 385, 230, 166, 268, 177, 443,
+ 225, 426, 101, 272, 138, 127, 290, 117, 347, 199,
+ 414, 95, 140, 240, 410, 395, 209, 129, 283, 346,
+ 105, 241, 437, 86, 308, 448, 203, 345, 186, 107,
+ 220, 415, 334, 319, 106, 313, 118, 123, 73, 207,
+ 421, 214, 384, 373, 438, 62, 371, 341, 75, 449,
+ 168, 323, 164, 242, 416, 324, 304, 197, 335, 404,
+ 271, 63, 191, 325, 96, 169, 231, 280, 312, 187,
+ 406, 84, 201, 100, 67, 382, 175, 336, 202, 330,
+ 269, 393, 376, 383, 293, 307, 409, 179, 285, 314,
+ 302, 372, 398, 190, 180, 89, 99, 103, 232, 78,
+ 88, 77, 136, 387, 165, 198, 394, 125, 176, 428,
+ 74, 375, 238, 227, 66, 273, 282, 141, 306, 412,
+ 114, 85, 130, 348, 119, 291, 296, 386, 233, 397,
+ 303, 405, 284, 445, 423, 221, 210, 205, 450, 108,
+ 274, 434, 216, 343, 337, 142, 243, 321, 408, 451,
+ 310, 292, 120, 109, 281, 439, 270, 429, 332, 295,
+ 418, 211, 315, 222, 326, 131, 430, 244, 327, 349,
+ 417, 316, 143, 338, 440, 234, 110, 212, 452, 245,
+ 121, 419, 350, 223, 132, 441, 328, 413, 317, 339,
+ 126, 104, 137, 446, 344, 239, 435, 115, 333, 206,
+ 322, 217, 228, 424, 453, 311, 351, 111, 442, 224,
+ 213, 122, 431, 340, 235, 246, 133, 144, 420, 329,
+ 318
+};
+
+static Word16 sort_2385[477] = {
+ 0, 4, 6, 145, 251, 360, 466, 7, 5, 3,
+ 47, 48, 49, 50, 51, 262, 263, 264, 265, 266,
+ 146, 252, 361, 467, 151, 257, 366, 472, 148, 254,
+ 363, 469, 149, 255, 364, 470, 156, 371, 150, 256,
+ 365, 471, 147, 253, 362, 468, 52, 2, 1, 157,
+ 372, 267, 19, 21, 12, 17, 18, 20, 16, 25,
+ 13, 10, 14, 24, 23, 22, 26, 8, 15, 53,
+ 268, 31, 152, 153, 154, 155, 258, 259, 260, 261,
+ 367, 368, 369, 370, 473, 474, 475, 476, 158, 373,
+ 9, 33, 11, 159, 374, 54, 269, 28, 27, 160,
+ 375, 34, 35, 29, 46, 32, 30, 55, 270, 37,
+ 36, 39, 38, 40, 161, 376, 41, 42, 43, 44,
+ 45, 56, 162, 271, 377, 185, 196, 174, 79, 57,
+ 411, 90, 163, 305, 389, 378, 283, 68, 187, 400,
+ 294, 198, 307, 92, 70, 186, 413, 176, 59, 91,
+ 58, 412, 380, 165, 81, 164, 272, 175, 80, 401,
+ 402, 390, 391, 197, 306, 69, 274, 273, 379, 285,
+ 296, 284, 295, 188, 60, 199, 82, 93, 71, 381,
+ 414, 177, 166, 456, 308, 403, 98, 76, 286, 61,
+ 275, 386, 135, 423, 171, 102, 392, 204, 87, 182,
+ 65, 94, 208, 124, 72, 350, 193, 313, 393, 408,
+ 445, 309, 230, 419, 297, 241, 113, 219, 189, 128,
+ 317, 415, 116, 328, 200, 339, 382, 434, 178, 64,
+ 404, 83, 437, 223, 134, 192, 444, 112, 439, 139,
+ 287, 167, 448, 212, 459, 222, 240, 233, 97, 302,
+ 397, 234, 170, 276, 181, 455, 229, 438, 101, 280,
+ 138, 127, 298, 117, 355, 203, 426, 95, 140, 244,
+ 422, 407, 213, 129, 291, 354, 105, 245, 449, 86,
+ 316, 460, 207, 353, 190, 107, 224, 427, 342, 327,
+ 106, 321, 118, 123, 73, 211, 433, 218, 396, 385,
+ 450, 62, 383, 349, 75, 461, 172, 331, 168, 246,
+ 428, 332, 312, 201, 343, 416, 279, 63, 195, 333,
+ 96, 173, 235, 288, 320, 191, 418, 84, 205, 100,
+ 67, 394, 179, 344, 206, 338, 277, 405, 388, 395,
+ 301, 315, 421, 183, 293, 322, 310, 384, 410, 194,
+ 184, 89, 99, 103, 236, 78, 88, 77, 136, 399,
+ 169, 202, 406, 125, 180, 440, 74, 387, 242, 231,
+ 66, 281, 290, 141, 314, 424, 114, 85, 130, 356,
+ 119, 299, 304, 398, 237, 409, 311, 417, 292, 457,
+ 435, 225, 214, 209, 462, 108, 282, 446, 220, 351,
+ 345, 142, 247, 329, 420, 463, 318, 300, 120, 109,
+ 289, 451, 278, 441, 340, 303, 430, 215, 323, 226,
+ 334, 131, 442, 248, 335, 357, 429, 324, 143, 346,
+ 452, 238, 110, 216, 464, 249, 121, 431, 358, 227,
+ 132, 453, 336, 425, 325, 347, 126, 104, 137, 458,
+ 352, 243, 447, 115, 341, 210, 330, 221, 232, 436,
+ 465, 319, 359, 111, 454, 228, 217, 122, 443, 348,
+ 239, 250, 133, 144, 432, 337, 326
+};
+
+static Word16 sort_SID[35] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34
+};
+
+/* pointer table for bit sorting tables */
+static Word16 *sort_ptr[16] = { sort_660, sort_885, sort_1265, sort_1425, sort_1585, sort_1825, sort_1985, sort_2305,
+ sort_2385, sort_SID, NULL, NULL, NULL, NULL, NULL, NULL};
+
+
+
+
diff --git a/media/codecs/amrwb/enc/inc/oper_32b.h b/media/codecs/amrwb/enc/inc/oper_32b.h
new file mode 100644
index 0000000..7a0f564
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/oper_32b.h
@@ -0,0 +1,31 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/* Double precision operations */
+/* $Id$ */
+
+#ifndef __OPER_32B_H__
+#define __OPER_32B_H__
+
+void VO_L_Extract (Word32 L_32, Word16 *hi, Word16 *lo);
+Word32 L_Comp (Word16 hi, Word16 lo);
+Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2);
+Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n);
+Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo);
+
+#endif //__OPER_32B_H__
+
diff --git a/media/codecs/amrwb/enc/inc/p_med_o.h b/media/codecs/amrwb/enc/inc/p_med_o.h
new file mode 100644
index 0000000..77487ed
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/p_med_o.h
@@ -0,0 +1,52 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/*--------------------------------------------------------------------------*
+ * P_MED_O.H *
+ *--------------------------------------------------------------------------*
+ * Median open-loop lag search *
+ *--------------------------------------------------------------------------*/
+
+#ifndef __P_MED_O_H__
+#define __P_MED_O_H__
+
+Word16 Pitch_med_ol( /* output: open loop pitch lag */
+ Word16 wsp[], /* input : signal used to compute the open loop pitch */
+ /* wsp[-pit_max] to wsp[-1] should be known */
+ Word16 L_min, /* input : minimum pitch lag */
+ Word16 L_max, /* input : maximum pitch lag */
+ Word16 L_frame, /* input : length of frame to compute pitch */
+ Word16 L_0, /* input : old_ open-loop pitch */
+ Word16 * gain, /* output: normalize correlation of hp_wsp for the Lag */
+ Word16 * hp_wsp_mem, /* i:o : memory of the hypass filter for hp_wsp[] (lg=9) */
+ Word16 * old_hp_wsp, /* i:o : hypass wsp[] */
+ Word16 wght_flg /* input : is weighting function used */
+ );
+
+Word16 Med_olag( /* output : median of 5 previous open-loop lags */
+ Word16 prev_ol_lag, /* input : previous open-loop lag */
+ Word16 old_ol_lag[5]
+ );
+
+void Hp_wsp(
+ Word16 wsp[], /* i : wsp[] signal */
+ Word16 hp_wsp[], /* o : hypass wsp[] */
+ Word16 lg, /* i : lenght of signal */
+ Word16 mem[] /* i/o : filter memory [9] */
+ );
+
+#endif //__P_MED_O_H__
+
diff --git a/media/codecs/amrwb/enc/inc/p_med_ol.tab b/media/codecs/amrwb/enc/inc/p_med_ol.tab
new file mode 100644
index 0000000..d74ec8e
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/p_med_ol.tab
@@ -0,0 +1,47 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*-----------------------------------------------------*
+ | Table for function Pitch_med_ol() |
+ *-----------------------------------------------------*/
+
+ static Word16 corrweight[199]= {
+
+ 10772, 10794, 10816, 10839, 10862, 10885, 10908, 10932, 10955, 10980,
+ 11004, 11029, 11054, 11079, 11105, 11131, 11157, 11183, 11210, 11238,
+ 11265, 11293, 11322, 11350, 11379, 11409, 11439, 11469, 11500, 11531,
+ 11563, 11595, 11628, 11661, 11694, 11728, 11763, 11798, 11834, 11870,
+ 11907, 11945, 11983, 12022, 12061, 12101, 12142, 12184, 12226, 12270,
+ 12314, 12358, 12404, 12451, 12498, 12547, 12596, 12647, 12699, 12751,
+ 12805, 12861, 12917, 12975, 13034, 13095, 13157, 13221, 13286, 13353,
+ 13422, 13493, 13566, 13641, 13719, 13798, 13880, 13965, 14053, 14143,
+ 14237, 14334, 14435, 14539, 14648, 14761, 14879, 15002, 15130, 15265,
+ 15406, 15554, 15710, 15874, 16056, 16384, 16384, 16384, 16384, 16384,
+ 16384, 16384, 16056, 15874, 15710, 15554, 15406, 15265, 15130, 15002,
+ 14879, 14761, 14648, 14539, 14435, 14334, 14237, 14143, 14053, 13965,
+ 13880, 13798, 13719, 13641, 13566, 13493, 13422, 13353, 13286, 13221,
+ 13157, 13095, 13034, 12975, 12917, 12861, 12805, 12751, 12699, 12647,
+ 12596, 12547, 12498, 12451, 12404, 12358, 12314, 12270, 12226, 12184,
+ 12142, 12101, 12061, 12022, 11983, 11945, 11907, 11870, 11834, 11798,
+ 11763, 11728, 11694, 11661, 11628, 11595, 11563, 11531, 11500, 11469,
+ 11439, 11409, 11379, 11350, 11322, 11293, 11265, 11238, 11210, 11183,
+ 11157, 11131, 11105, 11079, 11054, 11029, 11004, 10980, 10955, 10932,
+ 10908, 10885, 10862, 10839, 10816, 10794, 10772, 10750, 10728};
+
+
+
diff --git a/media/codecs/amrwb/enc/inc/q_gain2.tab b/media/codecs/amrwb/enc/inc/q_gain2.tab
new file mode 100644
index 0000000..bc36489
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/q_gain2.tab
@@ -0,0 +1,228 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*------------------------------------------------------*
+ * Tables for function q_gain2() *
+ * *
+ * g_pitch(Q14), g_code(Q11) *
+ * *
+ * pitch gain are ordered in table to reduce complexity *
+ * during quantization of gains. *
+ *------------------------------------------------------*/
+
+#define nb_qua_gain6b 64 /* Number of quantization level */
+#define nb_qua_gain7b 128 /* Number of quantization level */
+
+
+static Word16 t_qua_gain6b[64*2] = {
+ 1566, 1332,
+ 1577, 3557,
+ 3071, 6490,
+ 4193, 10163,
+ 4496, 2534,
+ 5019, 4488,
+ 5586, 15614,
+ 5725, 1422,
+ 6453, 580,
+ 6724, 6831,
+ 7657, 3527,
+ 8072, 2099,
+ 8232, 5319,
+ 8827, 8775,
+ 9740, 2868,
+ 9856, 1465,
+ 10087, 12488,
+ 10241, 4453,
+ 10859, 6618,
+ 11321, 3587,
+ 11417, 1800,
+ 11643, 2428,
+ 11718, 988,
+ 12312, 5093,
+ 12523, 8413,
+ 12574, 26214,
+ 12601, 3396,
+ 13172, 1623,
+ 13285, 2423,
+ 13418, 6087,
+ 13459, 12810,
+ 13656, 3607,
+ 14111, 4521,
+ 14144, 1229,
+ 14425, 1871,
+ 14431, 7234,
+ 14445, 2834,
+ 14628, 10036,
+ 14860, 17496,
+ 15161, 3629,
+ 15209, 5819,
+ 15299, 2256,
+ 15518, 4722,
+ 15663, 1060,
+ 15759, 7972,
+ 15939, 11964,
+ 16020, 2996,
+ 16086, 1707,
+ 16521, 4254,
+ 16576, 6224,
+ 16894, 2380,
+ 16906, 681,
+ 17213, 8406,
+ 17610, 3418,
+ 17895, 5269,
+ 18168, 11748,
+ 18230, 1575,
+ 18607, 32767,
+ 18728, 21684,
+ 19137, 2543,
+ 19422, 6577,
+ 19446, 4097,
+ 19450, 9056,
+ 20371, 14885};
+
+static Word16 t_qua_gain7b[128*2] = {
+ 204, 441,
+ 464, 1977,
+ 869, 1077,
+ 1072, 3062,
+ 1281, 4759,
+ 1647, 1539,
+ 1845, 7020,
+ 1853, 634,
+ 1995, 2336,
+ 2351, 15400,
+ 2661, 1165,
+ 2702, 3900,
+ 2710, 10133,
+ 3195, 1752,
+ 3498, 2624,
+ 3663, 849,
+ 3984, 5697,
+ 4214, 3399,
+ 4415, 1304,
+ 4695, 2056,
+ 5376, 4558,
+ 5386, 676,
+ 5518, 23554,
+ 5567, 7794,
+ 5644, 3061,
+ 5672, 1513,
+ 5957, 2338,
+ 6533, 1060,
+ 6804, 5998,
+ 6820, 1767,
+ 6937, 3837,
+ 7277, 414,
+ 7305, 2665,
+ 7466, 11304,
+ 7942, 794,
+ 8007, 1982,
+ 8007, 1366,
+ 8326, 3105,
+ 8336, 4810,
+ 8708, 7954,
+ 8989, 2279,
+ 9031, 1055,
+ 9247, 3568,
+ 9283, 1631,
+ 9654, 6311,
+ 9811, 2605,
+ 10120, 683,
+ 10143, 4179,
+ 10245, 1946,
+ 10335, 1218,
+ 10468, 9960,
+ 10651, 3000,
+ 10951, 1530,
+ 10969, 5290,
+ 11203, 2305,
+ 11325, 3562,
+ 11771, 6754,
+ 11839, 1849,
+ 11941, 4495,
+ 11954, 1298,
+ 11975, 15223,
+ 11977, 883,
+ 11986, 2842,
+ 12438, 2141,
+ 12593, 3665,
+ 12636, 8367,
+ 12658, 1594,
+ 12886, 2628,
+ 12984, 4942,
+ 13146, 1115,
+ 13224, 524,
+ 13341, 3163,
+ 13399, 1923,
+ 13549, 5961,
+ 13606, 1401,
+ 13655, 2399,
+ 13782, 3909,
+ 13868, 10923,
+ 14226, 1723,
+ 14232, 2939,
+ 14278, 7528,
+ 14439, 4598,
+ 14451, 984,
+ 14458, 2265,
+ 14792, 1403,
+ 14818, 3445,
+ 14899, 5709,
+ 15017, 15362,
+ 15048, 1946,
+ 15069, 2655,
+ 15405, 9591,
+ 15405, 4079,
+ 15570, 7183,
+ 15687, 2286,
+ 15691, 1624,
+ 15699, 3068,
+ 15772, 5149,
+ 15868, 1205,
+ 15970, 696,
+ 16249, 3584,
+ 16338, 1917,
+ 16424, 2560,
+ 16483, 4438,
+ 16529, 6410,
+ 16620, 11966,
+ 16839, 8780,
+ 17030, 3050,
+ 17033, 18325,
+ 17092, 1568,
+ 17123, 5197,
+ 17351, 2113,
+ 17374, 980,
+ 17566, 26214,
+ 17609, 3912,
+ 17639, 32767,
+ 18151, 7871,
+ 18197, 2516,
+ 18202, 5649,
+ 18679, 3283,
+ 18930, 1370,
+ 19271, 13757,
+ 19317, 4120,
+ 19460, 1973,
+ 19654, 10018,
+ 19764, 6792,
+ 19912, 5135,
+ 20040, 2841,
+ 21234, 19833};
+
+
diff --git a/media/codecs/amrwb/enc/inc/q_pulse.h b/media/codecs/amrwb/enc/inc/q_pulse.h
new file mode 100644
index 0000000..67140fc
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/q_pulse.h
@@ -0,0 +1,66 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*--------------------------------------------------------------------------*
+ * Q_PULSE.H *
+ *--------------------------------------------------------------------------*
+ * Coding and decoding of algebraic codebook *
+ *--------------------------------------------------------------------------*/
+
+#ifndef __Q_PULSE_H__
+#define __Q_PULSE_H__
+
+#include "typedef.h"
+
+Word32 quant_1p_N1( /* (o) return (N+1) bits */
+ Word16 pos, /* (i) position of the pulse */
+ Word16 N); /* (i) number of bits for position */
+
+Word32 quant_2p_2N1( /* (o) return (2*N)+1 bits */
+ Word16 pos1, /* (i) position of the pulse 1 */
+ Word16 pos2, /* (i) position of the pulse 2 */
+ Word16 N); /* (i) number of bits for position */
+
+Word32 quant_3p_3N1( /* (o) return (3*N)+1 bits */
+ Word16 pos1, /* (i) position of the pulse 1 */
+ Word16 pos2, /* (i) position of the pulse 2 */
+ Word16 pos3, /* (i) position of the pulse 3 */
+ Word16 N); /* (i) number of bits for position */
+
+Word32 quant_4p_4N1( /* (o) return (4*N)+1 bits */
+ Word16 pos1, /* (i) position of the pulse 1 */
+ Word16 pos2, /* (i) position of the pulse 2 */
+ Word16 pos3, /* (i) position of the pulse 3 */
+ Word16 pos4, /* (i) position of the pulse 4 */
+ Word16 N); /* (i) number of bits for position */
+
+Word32 quant_4p_4N( /* (o) return 4*N bits */
+ Word16 pos[], /* (i) position of the pulse 1..4 */
+ Word16 N); /* (i) number of bits for position */
+
+Word32 quant_5p_5N( /* (o) return 5*N bits */
+ Word16 pos[], /* (i) position of the pulse 1..5 */
+ Word16 N); /* (i) number of bits for position */
+
+Word32 quant_6p_6N_2( /* (o) return (6*N)-2 bits */
+ Word16 pos[], /* (i) position of the pulse 1..6 */
+ Word16 N); /* (i) number of bits for position */
+
+
+#endif //__Q_PULSE_H__
+
diff --git a/media/codecs/amrwb/enc/inc/qisf_ns.tab b/media/codecs/amrwb/enc/inc/qisf_ns.tab
new file mode 100644
index 0000000..43c47e9
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/qisf_ns.tab
@@ -0,0 +1,347 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*-------------------------------------------------------------------*
+ * qisf_ns.h
+ *-------------------------------------------------------------------*
+ * Quantization tables for split by 5 VQ of ISFs for a background noise database
+ * Version whith no prediction
+ *-------------------------------------------------------------------*/
+
+#define ORDER 16 /* order of linear prediction filter */
+#define ISF_GAP 128
+
+#define SIZE_BK_NOISE1 64
+#define SIZE_BK_NOISE2 64
+#define SIZE_BK_NOISE3 64
+#define SIZE_BK_NOISE4 32
+#define SIZE_BK_NOISE5 32
+
+
+/* means of ISFs */
+ static Word16 mean_isf_noise[ORDER] = {
+
+ 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240,
+ 8229, 9153, 10098, 11108, 12144, 13184, 14165, 3803};
+
+
+/* 28 bits */
+/*-------------------------------------------------------------------*
+ * isf codebooks: split-by-5 VQ *
+ * *
+ * codebook vector dimension number of vectors *
+ * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ *
+ * 1 2 64 *
+ * 2 3 64 *
+ * 3 3 64 *
+ * 4 4 32 *
+ * 5 4 32 *
+ *-------------------------------------------------------------------*/
+
+/*------------------------------------------------*
+ * 1st split: isf0 to isf1
+ *------------------------------------------------*/
+
+
+ static Word16 dico1_isf_noise[SIZE_BK_NOISE1*2] = {
+
+ -269, -673,
+ -222, -537,
+ -233, -430,
+ -138, -451,
+ -212, -331,
+ -192, -241,
+ -87, -231,
+ -191, -128,
+ -70, -106,
+ -164, -6,
+ 74, -179,
+ 27, -33,
+ -102, 74,
+ -162, 115,
+ -94, 172,
+ -6, 130,
+ -143, 234,
+ 14, 218,
+ -65, 270,
+ 88, 182,
+ -124, 341,
+ -44, 381,
+ 38, 335,
+ 117, 274,
+ -112, 454,
+ 74, 431,
+ -5, 488,
+ 175, 384,
+ -83, 561,
+ 122, 529,
+ 21, 601,
+ 229, 481,
+ 231, 303,
+ 226, 608,
+ 300, 372,
+ 210, 187,
+ 306, 265,
+ 328, 473,
+ 382, 331,
+ 371, 132,
+ 139, 58,
+ 365, 21,
+ 250, -82,
+ 443, 218,
+ 483, 110,
+ 426, 415,
+ 579, 222,
+ 518, 333,
+ 573, 448,
+ 455, 529,
+ 685, 329,
+ 332, 580,
+ 595, 593,
+ 468, 645,
+ 762, 517,
+ 326, 709,
+ 485, 793,
+ 130, 684,
+ 671, 737,
+ 354, 876,
+ 88, 806,
+ -65, 706,
+ -35, 1016,
+ 266, 1123};
+
+
+/*------------------------------------------------*
+ * 2nd split: isf2 to isf4
+ *------------------------------------------------*/
+
+ static Word16 dico2_isf_noise[SIZE_BK_NOISE2*3] = {
+
+ -824, -884, -949,
+ -805, -456, -418,
+ -442, -438, -541,
+ -217, -578, -793,
+ -168, -444, -582,
+ -287, -492, -274,
+ -552, -297, -300,
+ -163, -333, -358,
+ -370, -232, -232,
+ -175, -358, -159,
+ -381, -21, -357,
+ -184, -159, -162,
+ -53, -191, -280,
+ 18, -267, -215,
+ -138, 61, -283,
+ 71, -95, -294,
+ 13, -156, -546,
+ 0, -83, -79,
+ 44, 97, -316,
+ 178, -52, -213,
+ 222, -261, -422,
+ 237, -118, -44,
+ 141, 145, -132,
+ 363, 81, -287,
+ 213, 65, 34,
+ -107, 94, -5,
+ 91, -29, 126,
+ -355, 51, -41,
+ -219, -76, 145,
+ -63, 100, 244,
+ -719, 44, 27,
+ -572, -124, 155,
+ -423, 133, 315,
+ -917, 71, 224,
+ -268, 318, 131,
+ -93, -190, 420,
+ -97, 122, 491,
+ -79, 317, 355,
+ 130, 100, 325,
+ 86, -293, 210,
+ 133, 258, 161,
+ 176, -73, 465,
+ 195, 300, 384,
+ 348, 22, 221,
+ 376, 183, 409,
+ 377, 286, 202,
+ 242, 213, 659,
+ 257, 565, 248,
+ 344, 408, -76,
+ 405, 440, 509,
+ 612, 385, 379,
+ 536, 607, 216,
+ -56, 582, 192,
+ 100, 517, 567,
+ -365, 448, 445,
+ 728, 347, 10,
+ 505, 357, 759,
+ 636, 582, 658,
+ 335, 517, 852,
+ 378, 809, 572,
+ -195, 878, 829,
+ 529, 707, 987,
+ 918, 726, 392,
+ 1250, 997, 1063};
+
+/*------------------------------------------------*
+ * 3rd split: isf5 to isf7
+ *------------------------------------------------*/
+
+ static Word16 dico3_isf_noise[SIZE_BK_NOISE3*3] = {
+
+ -805, -838, -774,
+ -522, -627, -828,
+ -477, -486, -603,
+ -295, -481, -634,
+ -366, -384, -393,
+ -186, -414, -396,
+ -237, -394, -106,
+ -252, -202, -275,
+ -61, -177, -442,
+ -84, -198, -199,
+ -179, -125, -31,
+ -72, -47, -163,
+ -298, -220, 215,
+ -64, -168, 251,
+ -133, 156, -59,
+ -30, -2, 127,
+ 54, 66, -61,
+ -233, 21, 251,
+ 209, -50, 32,
+ 33, 194, 136,
+ -117, -18, 475,
+ 202, 46, 309,
+ 256, 185, 53,
+ 35, 200, 390,
+ 200, 263, 242,
+ -216, 302, 294,
+ 128, 358, 0,
+ 19, 431, 287,
+ 224, 447, 280,
+ 367, 165, 213,
+ 397, 314, 319,
+ 383, 379, 75,
+ 277, 325, 462,
+ 394, 505, 334,
+ 251, 98, -213,
+ 450, 153, 448,
+ 565, 226, 76,
+ 470, 383, 502,
+ 635, 390, 278,
+ 237, 135, 620,
+ 342, 401, 649,
+ 331, 551, 518,
+ 130, 418, 592,
+ 531, 306, 737,
+ 729, 389, 580,
+ 497, 557, 699,
+ 296, 383, 874,
+ 283, 624, 759,
+ 126, 622, 476,
+ 559, 595, 472,
+ 382, 770, 616,
+ 719, 613, 745,
+ 540, 639, 928,
+ 517, 826, 801,
+ 684, 811, 604,
+ 752, 786, 857,
+ 933, 661, 350,
+ 694, 450, 1061,
+ 562, 911, 1051,
+ 824, 813, 1104,
+ 758, 1047, 882,
+ 1140, 917, 889,
+ 1039, 1246, 1426,
+ 1483, 1666, 1876};
+
+/*------------------------------------------------*
+ * 4th split: isf8 to isf11
+ *------------------------------------------------*/
+
+ static Word16 dico4_isf_noise[SIZE_BK_NOISE4*4] = {
+
+ -776, -854, -891, -920,
+ -552, -610, -663, -741,
+ -321, -370, -476, -565,
+ 274, -160, -456, 201,
+ 265, 67, -160, -306,
+ -8, -210, 79, 272,
+ 163, 236, 307, 308,
+ 578, 317, 64, 298,
+ -9, 197, 342, 620,
+ 343, 232, 314, 622,
+ 173, 149, 548, 527,
+ 356, 370, 481, 376,
+ 135, 444, 488, 556,
+ 391, 471, 487, 653,
+ 228, 424, 576, 835,
+ 422, 372, 722, 682,
+ 295, 673, 693, 635,
+ 539, 596, 590, 449,
+ 475, 618, 659, 818,
+ 735, 517, 491, 673,
+ 602, 346, 257, 877,
+ 625, 635, 849, 720,
+ 727, 818, 698, 595,
+ 653, 481, 690, 1139,
+ 814, 762, 704, 908,
+ 507, 747, 898, 936,
+ 848, 855, 924, 785,
+ 646, 1037, 882, 795,
+ 772, 845, 1024, 1151,
+ 1133, 983, 818, 921,
+ 940, 1068, 1252, 1302,
+ 1588, 1767, 1718, 1513};
+
+/*------------------------------------------------*
+ * 5th split: isf12 to isf15
+ *------------------------------------------------*/
+
+ static Word16 dico5_isf_noise[SIZE_BK_NOISE5*4] = {
+ -810, -879, -945, -254,
+ 248, 184, 671, 128,
+ 288, 703, 918, 99,
+ 658, 558, 662, 219,
+ 552, 585, 910, 208,
+ 559, 804, 759, 119,
+ 606, 774, 921, -139,
+ 782, 761, 748, 208,
+ 756, 708, 983, 56,
+ 544, 864, 1010, 152,
+ 737, 698, 987, 299,
+ 771, 924, 879, 103,
+ 536, 785, 961, 405,
+ 667, 916, 801, 328,
+ 738, 705, 773, 439,
+ 823, 871, 992, 355,
+ 640, 1004, 1052, 369,
+ 724, 822, 949, 597,
+ 415, 655, 729, 482,
+ 1009, 896, 793, 363,
+ 908, 803, 687, -25,
+ 1016, 838, 1011, 189,
+ 947, 1112, 942, 222,
+ 914, 1049, 981, 527,
+ 956, 987, 1011, -120,
+ 781, 1049, 1121, 92,
+ 1178, 1053, 884, 47,
+ 1123, 1059, 1182, 118,
+ 933, 972, 1277, 357,
+ 1109, 918, 1101, 503,
+ 1039, 1286, 1220, 317,
+ 1351, 1207, 1010, 326};
+
diff --git a/media/codecs/amrwb/enc/inc/qpisf_2s.tab b/media/codecs/amrwb/enc/inc/qpisf_2s.tab
new file mode 100644
index 0000000..b6b4e81
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/qpisf_2s.tab
@@ -0,0 +1,1360 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*-------------------------------------------------------------------*
+ * qpisf_2s.h
+ *-------------------------------------------------------------------*
+ * Quantization tables for two-stage of ISFs (split by 2 in 1st stage)
+ * Version whith prediction MU = 0.25
+ *-------------------------------------------------------------------*/
+
+#define ORDER 16 /* order of linear prediction filter */
+#define ISF_GAP 128 /* 50 Hz */
+#define N_SURV 4
+
+#define SIZE_BK1 256
+#define SIZE_BK2 256
+#define SIZE_BK21 64
+#define SIZE_BK22 128
+#define SIZE_BK23 128
+#define SIZE_BK24 32
+#define SIZE_BK25 32
+
+#define SIZE_BK21_36b 128
+#define SIZE_BK22_36b 128
+#define SIZE_BK23_36b 64
+
+/* means of ISFs */
+static Word16 mean_isf[ORDER] = {
+
+ 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730,
+ 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037};
+
+/* 46 bits */
+/*-------------------------------------------------------------------*
+ * isf codebooks: two-stage VQ with split-by-5 in 2nd stage *
+ * *
+ * codebook vector dimension number of vectors *
+ * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ *
+ * 1_1 9 256 *
+ * 1_2 7 256 *
+ * 2_1 3 64 *
+ * 2_2 3 128 *
+ * 2_3 3 128 *
+ * 2_4 3 32 *
+ * 2_5 4 32 *
+ *-------------------------------------------------------------------*/
+
+/*------------------------------------------------*
+ * 1st stage codebook; 1st split: isf0 to isf8
+ *------------------------------------------------*/
+
+static Word16 dico1_isf[SIZE_BK1*9] = {
+
+ 579, 1081, 1035, 390, 3, -263, -198, -82, 38,
+ 18, -68, -12, 313, 761, 405, 249, 111, -76,
+ 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923,
+ -91, 827, 948, 648, 613, 535, 522, 490, 421,
+ 41, -44, -281, -472, 652, 534, 193, 135, -90,
+ 41, -121, -356, -60, 663, 307, 61, -48, -344,
+ 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241,
+ -118, -204, 328, 512, 870, 793, 610, 402, 186,
+ 156, 293, 74, -338, -475, -897, -594, -161, -497,
+ 226, 131, -138, 307, 169, -271, -164, -387, -624,
+ 62, -32, -61, -252, -541, -828, -1027, -523, -662,
+ 102, -61, 141, 112, -270, -251, -541, 25, -150,
+ 6, -132, -356, -686, -96, -322, -522, -31, -326,
+ -36, -209, -521, -229, 307, -132, -5, -99, -384,
+ 60, -51, -237, -668, -973, -407, -708, -75, -172,
+ 26, -138, -266, 111, -302, 43, -278, -356, -359,
+ 570, 822, 496, -154, -312, -92, 137, 279, 371,
+ -146, 368, 409, 68, 6, 77, 167, 202, 162,
+ 633, 898, 996, 756, 662, 683, 783, 909, 996,
+ -103, 294, 607, 415, 483, 462, 480, 431, 408,
+ -120, -338, -612, -524, 584, 331, 92, 433, 276,
+ -178, -293, -154, -41, 269, 100, -9, 213, 160,
+ 830, 736, 278, 820, 1254, 686, 712, 1039, 473,
+ -218, -304, 463, 454, 397, 273, 202, 286, 273,
+ -232, 7, 6, -388, -472, -427, -378, -167, -100,
+ -294, -183, 134, -47, 101, -88, -84, -117, -3,
+ 57, 17, -202, -634, -989, -1119, -533, 176, -36,
+ 120, -28, 23, 111, -319, 318, -22, -77, 266,
+ -271, -464, -434, -658, -640, -385, -385, -99, -69,
+ -198, -259, -266, -44, -39, -139, -137, 171, 66,
+ 9, -145, -377, -846, -1000, -111, -325, 342, 135,
+ -81, -286, -380, 192, -57, 307, 76, -24, -140,
+ 677, 702, 247, 56, 249, 141, -105, -236, -99,
+ 36, -39, -69, 348, 198, -93, 322, 91, -72,
+ 503, 885, 1508, 1307, 1282, 1172, 1119, 1209, 1061,
+ 416, 719, 989, 1227, 1001, 1052, 954, 741, 1044,
+ -127, -376, -657, 139, 623, 223, 501, 306, 220,
+ -113, -384, -796, 504, 438, 85, 213, -83, -194,
+ 585, 1132, 1233, 1091, 1247, 1433, 1512, 1448, 1314,
+ -174, -422, 7, 1155, 1089, 1182, 1003, 945, 806,
+ 8, -126, -317, -103, -351, -695, -98, -268, -537,
+ 33, -103, -290, 167, -39, -407, 44, -208, -375,
+ 104, -23, -64, -291, -637, -851, -1084, -61, -112,
+ -75, -306, -434, 218, -148, -354, -680, -133, -216,
+ -121, -377, -718, -97, -130, -361, -156, -379, -599,
+ -56, -254, -586, 235, 157, -214, 11, -260, -149,
+ -124, -267, -397, -580, -593, -527, -805, -385, 346,
+ -193, -440, -708, -351, -141, -255, -499, -147, -185,
+ 448, 660, 494, 208, 509, 461, 338, 291, 149,
+ -223, 88, 335, 159, 212, 191, 286, 308, 205,
+ -31, 469, 803, 659, 619, 658, 843, 987, 1113,
+ -171, -242, 514, 362, 295, 524, 552, 694, 585,
+ -64, -308, -448, -21, 284, 786, 446, 289, 92,
+ -218, -390, -7, 169, 206, 330, 352, 408, 358,
+ -36, 702, 959, 859, 861, 1115, 1269, 1357, 1305,
+ -133, -341, -65, 678, 417, 440, 486, 518, 780,
+ 33, -44, -191, -344, -461, -755, -201, 217, -31,
+ -353, -547, -44, 123, -61, -68, -79, 29, 60,
+ 73, -57, -406, -766, -1243, -1203, 240, 400, 165,
+ -73, -282, -601, -213, -171, -375, 332, 35, -103,
+ -29, -207, -553, -476, -638, -908, 172, -22, -135,
+ -192, -239, -164, -103, -111, -47, 153, 125, 110,
+ -1, -203, -570, -1030, -1424, -535, 155, 1, 147,
+ -333, -653, -865, -197, -158, -21, -44, 95, 108,
+ 389, 588, 490, 33, -237, -524, -628, -136, -260,
+ 40, -177, -462, 453, 862, 380, 131, -130, -405,
+ 842, 1678, 1841, 1549, 1474, 1256, 1082, 905, 742,
+ 370, 1216, 1768, 1633, 1212, 636, 22, -330, 71,
+ -76, -281, -741, -742, 898, 619, 277, 71, -222,
+ -32, -265, -556, -25, 994, 682, 305, 126, -165,
+ 73, 738, 893, 968, 993, 1768, 2273, 1840, 1391,
+ -69, -349, -585, 234, 1158, 903, 626, 510, 251,
+ -1, -99, -272, -210, -603, -351, -540, -811, -383,
+ -16, -230, -504, 410, 149, -205, -343, -651, -639,
+ 103, -9, -227, -205, -562, -781, -1079, -1208, -156,
+ 143, 63, -135, -67, -317, -602, -784, -1154, -640,
+ -144, -391, -674, -622, -200, -254, -660, -947, -395,
+ -40, -250, -625, 27, 543, 94, -131, -386, -673,
+ -123, -371, -757, -451, -564, -614, -415, -711, -35,
+ -116, -309, -593, -268, 239, -33, -338, -650, -135,
+ 94, 251, 554, 57, -312, -423, -154, -57, 235,
+ -268, -71, 381, 114, -44, -87, 125, 173, 133,
+ 1513, 1714, 1238, 534, 276, 315, 461, 459, 508,
+ -131, -19, 1149, 670, 486, 356, 309, 369, 296,
+ -223, -501, -899, -722, -70, 6, 131, 310, 394,
+ -99, -303, -517, 249, 64, -53, 135, -11, 453,
+ -147, -399, -730, -401, 817, 738, 802, 749, 575,
+ -154, -435, -739, 800, 593, 366, 529, 318, 326,
+ -224, 45, -39, -387, -515, -518, -608, -384, -321,
+ -315, -377, 143, -101, -113, -377, -177, -144, -12,
+ 117, 40, -239, -651, -1051, -581, -737, -990, -328,
+ 26, -50, -157, -23, -453, -283, -531, -546, 192,
+ -252, -501, -743, -589, -627, -499, -328, -118, -72,
+ -324, -494, -244, -306, -144, -177, -262, -135, -78,
+ -36, -234, -519, -961, -1290, -314, -479, -371, -45,
+ -95, -292, -535, -8, -300, 112, -164, -277, 198,
+ -99, -128, 880, 836, 579, 351, 23, -95, -217,
+ -27, -258, 124, 1011, 597, 425, 144, 7, -73,
+ 421, 1293, 1640, 1623, 1742, 1617, 1499, 1284, 1006,
+ -95, 752, 1680, 1569, 1618, 1436, 1200, 980, 712,
+ -69, -300, -683, -435, 1132, 899, 504, 332, 109,
+ -74, -323, -637, 563, 1074, 608, 371, 105, -49,
+ -78, 831, 1194, 1110, 1378, 1481, 1492, 1365, 1217,
+ -259, -121, 1440, 1334, 1628, 1490, 1438, 1223, 933,
+ -82, -306, -613, -222, -378, -675, -545, -671, -845,
+ 53, -124, -347, 422, 52, -125, -270, -529, 9,
+ 79, -89, -320, -662, -999, -1199, -1243, -676, -297,
+ -68, -273, -611, 137, -146, -397, -627, -845, -220,
+ -112, -346, -797, -826, 234, -132, -188, -278, -522,
+ -159, -405, -734, -419, 293, 74, -167, -167, 184,
+ -153, -437, -833, -1080, -336, -472, -561, -340, -253,
+ -169, -423, -820, -904, -131, -19, -346, -604, 31,
+ 33, -31, 312, 62, -148, 49, -59, 564, 486,
+ -306, -333, 194, -44, 67, 72, 147, 205, 243,
+ -207, -49, 1360, 983, 969, 991, 1014, 1110, 973,
+ -211, -172, 883, 627, 711, 674, 705, 798, 746,
+ -88, -325, -763, -974, 687, 908, 514, 382, 172,
+ -292, -612, -805, 63, 131, 270, 259, 352, 348,
+ -235, -84, 955, 818, 1120, 1289, 1559, 1480, 1285,
+ -180, -461, -614, 657, 691, 745, 854, 783, 713,
+ -97, -309, -477, -614, -777, -734, -768, -526, -472,
+ -344, -476, -35, -169, 49, -77, -150, -240, -141,
+ -52, -268, -639, -919, -1278, -1113, -342, -333, -151,
+ -68, -242, -585, -73, -209, -478, -159, -429, 133,
+ -197, -499, -1005, -1268, -272, -224, -105, -67, 17,
+ -363, -618, -414, -116, -62, 20, 10, 116, 108,
+ -195, -475, -906, -1260, -891, -441, -277, -142, -28,
+ -226, -519, -950, -700, -275, -266, -116, -105, 82,
+ 404, 511, 520, 327, 17, -194, -333, -536, -586,
+ -114, -130, 276, 237, 204, 342, 135, -16, -111,
+ 670, 1208, 1168, 860, 742, 601, 528, 403, 309,
+ 397, 621, 966, 752, 579, 398, 400, 329, 252,
+ 191, 180, -137, -467, 272, 106, -95, 17, -192,
+ -80, -290, -626, 194, 598, 196, 21, -281, 77,
+ 510, 864, 1108, 807, 939, 902, 925, 717, 481,
+ 137, 367, 534, 764, 670, 382, 296, 153, 84,
+ 303, 497, 144, -85, -125, -539, -482, -464, -764,
+ 233, 347, 68, -147, 169, -210, -242, -226, -482,
+ 307, 422, 154, -175, -386, -722, -724, -904, -1015,
+ 309, 308, 160, -60, -470, -420, -598, -791, -219,
+ 68, 121, -137, -560, -146, -446, -515, -494, -729,
+ 130, 53, -227, 46, 474, 32, -161, -192, -490,
+ 213, 164, -71, -465, -876, -161, -456, -587, -48,
+ 218, 117, 39, 177, -194, -88, -226, -418, 50,
+ 210, 547, 569, 279, 121, -44, -50, 10, -84,
+ 58, 140, 182, -5, 267, 117, 106, 211, 198,
+ 539, 835, 913, 719, 617, 544, 591, 565, 642,
+ 153, 559, 872, 460, 222, 108, 188, 180, 183,
+ 158, 119, 284, -153, -271, 229, 87, 110, -57,
+ -183, 82, 118, 21, 13, 40, 118, 191, 185,
+ 162, 889, 654, 108, -34, 244, 488, 561, 532,
+ 163, 56, 609, 341, 50, 329, 68, 266, 218,
+ 100, 206, 18, -304, -107, -436, -487, -65, -306,
+ -86, 154, 134, -30, -45, -73, -104, -80, -96,
+ 245, 330, 10, -440, -849, -1082, 79, 40, -265,
+ 196, 372, 272, -181, -493, -389, 275, 80, -59,
+ 2, -12, -246, -505, -100, -436, 21, -187, -431,
+ -221, -48, 36, -271, -186, -147, -109, 26, 71,
+ 213, 140, 72, -351, -620, -84, -363, 69, 46,
+ 91, 167, -3, -95, -99, -105, -48, 114, 147,
+ 259, 249, 172, 607, 406, 52, 59, -189, -320,
+ 115, -85, -54, 574, 128, 226, -59, -253, 130,
+ -62, 1033, 1308, 1035, 1127, 1098, 1029, 961, 823,
+ 39, 364, 757, 940, 728, 660, 659, 583, 770,
+ -115, -338, -760, -471, 394, 37, 441, 178, 6,
+ -57, -305, -525, 796, 453, 188, -4, -114, 248,
+ 71, 444, 797, 731, 1096, 1157, 1222, 1029, 811,
+ 135, 359, 551, 425, 749, 815, 874, 704, 502,
+ 132, 247, 0, -206, -449, -750, -258, -514, -633,
+ 248, 249, 91, 121, -195, -499, -90, -282, -435,
+ 78, 20, -277, -623, -983, -1224, -415, -458, -639,
+ 347, 509, 208, -179, -464, -728, -76, -237, -486,
+ -103, -343, -756, -713, -265, -609, -191, -398, -636,
+ -121, -383, -749, 567, 252, -36, -354, -417, -50,
+ 204, 100, -149, -650, -1081, -47, -7, -263, 111,
+ -46, -180, -267, -324, -562, -394, -692, 398, 292,
+ 482, 670, 683, 624, 442, 165, 116, 36, -149,
+ 108, 247, 291, 247, 355, 122, 109, 224, 296,
+ -14, 945, 990, 801, 755, 815, 847, 913, 892,
+ 292, 349, 725, 482, 388, 329, 429, 620, 667,
+ -34, 197, 213, -127, 84, 494, 620, 575, 375,
+ 126, 207, 172, 167, 362, 202, 296, 395, 455,
+ -6, 250, 539, 467, 636, 801, 1149, 1287, 1118,
+ 27, 240, 369, 280, 440, 411, 634, 892, 953,
+ 159, 170, -58, -395, -797, -690, 77, -211, -334,
+ -5, -28, -13, -74, -335, -603, 300, 88, -205,
+ 82, -33, -364, -698, -1203, -1153, 110, -146, -289,
+ 113, 1, -243, -588, -994, -496, 414, 160, 42,
+ -56, -247, -440, -693, -996, -479, 11, -178, -357,
+ -151, -353, -327, -211, -340, 141, 65, 425, 453,
+ 34, -169, -455, -932, -1215, 138, 499, 256, 324,
+ 68, 139, -15, -547, -478, 17, 306, 502, 481,
+ -32, -134, 445, 129, -143, -244, -503, -507, -599,
+ 61, -140, -345, 496, 458, -2, 20, -227, -514,
+ 394, 1765, 1666, 1339, 1117, 806, 642, 479, 380,
+ 215, 519, 920, 1053, 1090, 791, 528, 290, 155,
+ -54, -233, -647, -602, 639, 294, -2, -167, -442,
+ -78, -315, -791, -113, 820, 403, 158, -116, -356,
+ 529, 1851, 2003, 1228, 622, -41, -416, 344, 819,
+ -105, -379, -236, 1224, 893, 749, 568, 356, 214,
+ -17, -199, -144, 50, -283, -247, -578, -846, -1087,
+ 69, -11, -381, -206, 209, -284, -387, -416, -716,
+ 39, -5, -145, -374, -682, -909, -1074, -1169, -1066,
+ 287, 226, 67, -221, -662, -171, -421, -642, -707,
+ -132, -348, -538, -448, -20, -4, -354, -748, -933,
+ 4, -75, -289, -598, 317, 52, -208, -297, -559,
+ -88, -264, -358, -589, -631, -248, -523, -822, -1071,
+ 70, -8, 54, -314, -515, 92, -146, -274, -493,
+ 199, 62, 391, 158, -141, 71, -219, -203, -207,
+ 152, 40, 329, 162, -29, 48, -149, 108, 127,
+ 635, 1058, 883, 492, 372, 312, 317, 274, 241,
+ 267, 722, 1256, 882, 625, 248, 8, -81, -60,
+ -58, -138, -291, -600, -12, -2, -39, 147, 117,
+ -107, -345, -513, 459, 76, 92, -272, 388, 262,
+ 362, 516, 203, -409, -716, -831, -331, 185, 209,
+ -117, -391, -298, 671, 292, 538, 257, 166, -38,
+ -102, -319, -194, -283, -573, -262, -579, -219, -444,
+ -235, 78, 11, -168, -101, -229, -263, -321, -123,
+ 70, 50, -170, -599, -996, -588, -263, -516, -455,
+ 394, 363, 229, -136, -538, 21, -183, -348, -201,
+ -124, -368, -640, -879, -847, -209, -409, -494, -515,
+ -127, -341, -541, -425, -510, -10, -252, -473, -291,
+ 84, -69, -201, -676, -868, 103, -311, -132, -320,
+ 5, -173, -188, -297, -628, 197, -57, 7, -11,
+ 49, -160, 56, 558, 111, 33, -311, -440, -463,
+ -1, -246, -307, 862, 453, 139, -170, -355, -232,
+ 279, 966, 1642, 1478, 1463, 1123, 795, 525, 339,
+ -197, -38, 1702, 1331, 1252, 950, 692, 504, 426,
+ -108, -344, -861, -1172, 444, 354, 88, -46, -220,
+ -53, -321, -494, 1113, 744, 364, 198, -34, -75,
+ 457, 955, 1177, 1214, 1427, 1457, 1345, 917, 539,
+ -69, 199, 897, 1140, 1343, 1183, 977, 742, 522,
+ 122, 44, -269, 27, -155, -562, -307, -590, -773,
+ 154, 42, -160, 252, -129, -305, -471, -733, -371,
+ 135, 185, -82, -416, -722, -913, -504, -743, -880,
+ 149, 214, -84, -329, -680, -835, -426, -661, -81,
+ -128, -380, -735, -998, -337, 17, -182, -467, -697,
+ -84, -290, -510, -592, 13, 440, 154, -38, -279,
+ 70, -61, -246, -727, -1047, -80, -381, -535, -704,
+ 178, -2, -146, -670, -938, 482, 138, 63, 65,
+ -11, 15, 772, 443, 142, -20, -209, -126, -161,
+ -32, -249, 95, 552, 124, 30, -343, 82, -86,
+ 148, 751, 1515, 1105, 867, 606, 474, 448, 399,
+ -163, -257, 899, 1097, 906, 751, 502, 390, 294,
+ -51, -258, -447, -806, -368, 763, 464, 364, 183,
+ -166, -374, -367, 87, 35, 399, 418, 856, 833,
+ -205, -310, 588, 778, 785, 1065, 1118, 1245, 1157,
+ -173, -312, 107, 345, 400, 790, 870, 1113, 1001,
+ -7, -120, -387, -410, -614, -943, -226, -384, -491,
+ -203, -288, -51, -331, -90, -178, -408, -573, -338,
+ 56, -29, -273, -627, -1041, -798, -247, -467, 148,
+ 66, -2, -205, -205, -575, -349, -57, -352, -58,
+ -45, -225, -471, -924, -497, 77, -32, 44, -135,
+ -277, -491, -497, -502, -424, -202, -137, 77, 96,
+ 26, -179, -469, -1008, -1260, 262, -35, -132, -259,
+ -66, -232, -447, -533, -789, -191, -100, -267, 364};
+
+/*------------------------------------------------*
+ * 1st stage codebook; 2nd split: isf9 to isf15
+ *------------------------------------------------*/
+
+static Word16 dico2_isf[SIZE_BK2*7] = {
+
+ 1357, 1313, 1136, 784, 438, 181, 145,
+ 636, 648, 667, 568, 442, 217, 362,
+ 427, 440, 674, 524, 332, 117, -417,
+ 121, 295, 468, 465, 230, 44, -221,
+ -147, -240, 149, 80, 390, 278, 106,
+ -418, -556, 552, 511, 235, 144, -95,
+ 43, 193, 274, 150, 67, 34, -273,
+ -43, -126, 171, 416, 282, 63, -354,
+ -372, -86, -344, -108, -94, -182, -89,
+ -600, -840, -200, 465, 258, -11, -253,
+ -48, 329, 97, -290, -543, -795, -354,
+ -570, -117, 187, 10, -133, -416, -76,
+ -618, -129, -247, -371, 45, -76, 277,
+ -1022, -1079, 126, 474, 254, 127, 52,
+ -281, 76, -167, -361, -283, -551, -283,
+ -119, -52, -1, 134, -32, -204, -415,
+ 1064, 827, 637, 684, 464, 209, 12,
+ 482, 416, 449, 371, 335, 294, 194,
+ 719, 576, 365, 135, 113, 91, -199,
+ 298, 176, 493, 366, 194, 163, 36,
+ -35, -236, -259, -36, -4, 99, 152,
+ -98, -306, -27, 228, 90, 111, -86,
+ 91, 13, -211, -258, -106, 86, -64,
+ 73, -35, -57, -31, 162, 35, -192,
+ -109, -335, -629, -66, -61, -128, 322,
+ -495, -669, -728, 193, 31, -220, 122,
+ 324, 95, -89, -91, -409, -710, -154,
+ 0, -234, 92, 33, -343, -609, -220,
+ -343, -408, -476, -655, -153, 82, 222,
+ -490, -745, -255, 49, -48, 135, -127,
+ 119, -67, -328, -390, -272, -545, -56,
+ -57, -130, -10, -7, -164, -47, -22,
+ 984, 1064, 961, 568, 210, -27, 16,
+ 811, 691, 754, 514, 224, -35, 166,
+ 662, 704, 618, 386, 57, -211, -257,
+ 510, 359, 418, 393, 91, -144, -18,
+ -193, -31, -27, 223, 89, -143, 24,
+ -112, -98, 471, 319, 185, 3, 175,
+ 252, 146, -47, 272, 48, -211, -234,
+ 146, 69, 203, 364, 68, -52, 51,
+ -259, -478, -697, -349, -758, -501, 63,
+ -501, -769, -289, 79, -311, -497, -106,
+ 251, 53, -235, -469, -895, -884, 145,
+ -416, -551, 140, -133, -523, -775, 44,
+ -326, -423, -713, -497, -86, -431, 99,
+ -757, -772, -160, -76, -46, -32, 379,
+ 85, -35, -200, -401, -663, -1040, -247,
+ -180, -330, -92, -376, 27, -183, -110,
+ 1279, 1086, 781, 502, 324, 164, 157,
+ 682, 466, 449, 277, 146, 28, 409,
+ 635, 472, 390, 107, -232, -538, -139,
+ 196, 396, 332, 213, 209, -29, -81,
+ 150, -95, -312, 76, -77, -320, -50,
+ 46, 9, 47, 175, 139, 30, 384,
+ 218, 206, -24, -250, -96, -276, -183,
+ 26, 119, 38, 14, -4, -133, -52,
+ -477, -614, -987, -715, -631, -813, 200,
+ -744, -1009, -1065, -745, -631, -171, 18,
+ -137, -251, -483, -613, -980, -1203, 12,
+ -605, -767, -562, -686, -1088, -515, 58,
+ -202, -428, -782, -1072, -96, -234, -179,
+ -480, -709, -1070, -897, -131, -92, 321,
+ -145, -193, -512, -729, -572, -765, -210,
+ -331, -585, -525, -631, -281, -208, -303,
+ 1165, 1104, 939, 828, 716, 426, 155,
+ 6, -109, 820, 778, 415, 113, -27,
+ 381, 339, 314, 265, 121, -9, -474,
+ -373, 47, 584, 442, 99, -231, -113,
+ -496, -38, -285, 262, 305, 170, 4,
+ -587, -556, 69, 66, 471, 354, 13,
+ -138, 70, -18, 106, 67, 167, -302,
+ -445, -141, 185, 191, 151, 83, -133,
+ -257, -521, -720, -198, 134, -46, -182,
+ -819, -1168, -777, 512, 359, 95, -113,
+ 137, -2, -74, -138, -401, -114, -371,
+ -242, -466, 204, 223, -31, -212, -192,
+ -532, -637, -466, -686, 256, 277, -139,
+ -1141, -1244, -381, -75, -54, 14, 88,
+ -311, 115, -143, -499, -343, 124, -416,
+ -616, -147, -135, 43, -4, 121, -369,
+ 835, 783, 641, 390, 355, 350, 64,
+ 72, 194, 443, 467, 436, 219, 372,
+ 464, 369, 192, 4, -156, -72, -226,
+ 57, 206, 303, 205, 188, 101, 265,
+ -40, -205, -488, -184, 276, 64, -26,
+ -217, -433, -297, 137, 328, 308, -289,
+ 378, 81, -308, -465, 57, -37, 227,
+ -100, 24, -36, -151, 199, 8, 143,
+ -426, -697, -1059, -133, 388, 161, 321,
+ -644, -1023, -1271, 39, 66, -123, 70,
+ 372, 177, -173, -556, -553, -304, -189,
+ -117, -369, -425, -122, -462, -152, -73,
+ -649, -850, -1189, -767, 497, 360, 222,
+ -798, -1139, -1455, -190, 430, 234, 179,
+ 42, -94, -405, -692, 38, -202, -246,
+ -169, -366, -290, -88, -64, 32, -292,
+ 1010, 923, 938, 710, 465, 230, 342,
+ 217, 300, 1054, 675, 68, -458, -179,
+ 78, 453, 316, 18, -237, -496, -243,
+ 167, 21, 424, 215, -91, -303, -170,
+ -290, -81, -70, -67, 40, 54, -59,
+ -353, -427, -90, 53, 94, 9, 54,
+ -28, 318, 283, 15, -240, -58, 79,
+ -75, -121, 229, 35, 58, 6, -133,
+ -351, -514, -744, -834, -705, -137, 164,
+ -1124, -1388, -1055, -230, -73, 40, 36,
+ -163, -233, -532, -785, -1170, -697, 96,
+ -788, -959, -246, -430, -624, -165, -8,
+ -856, -540, -630, -907, -337, -70, 76,
+ -937, -1042, -659, -733, -208, 199, -26,
+ -523, 78, -98, -501, -869, -890, -81,
+ -624, -703, -45, -348, -25, 87, -186,
+ 1005, 823, 546, 249, 90, -22, 207,
+ 298, 397, 381, 319, 200, 62, 303,
+ 473, 379, 133, -247, -632, -441, 75,
+ 284, 208, 391, 115, -25, 44, 95,
+ -72, 79, -95, -63, -129, -293, 203,
+ -164, -349, 115, 122, 69, -1, 378,
+ 348, 170, 99, 58, -179, -302, 188,
+ -190, -2, 150, 23, -51, -11, 216,
+ -615, -863, -1090, -1427, -802, -48, -6,
+ -961, -1276, -1548, -727, -58, 56, 223,
+ -124, -255, -561, -988, -1277, -148, -82,
+ -480, -660, -891, -1191, -1339, -325, 20,
+ -621, -917, -1296, -1350, 264, 289, 50,
+ -844, -1022, -1345, -1329, -293, 46, 278,
+ -260, -468, -829, -1176, -533, -560, -78,
+ -215, -484, -822, -1233, -791, 15, -138,
+ 1301, 1317, 1262, 1048, 716, 357, -64,
+ 578, 824, 925, 802, 630, 362, 102,
+ 470, 925, 767, 514, 327, 190, -112,
+ 225, 492, 495, 437, 598, 384, -45,
+ 43, 82, -42, 175, 519, 342, -64,
+ -304, -154, 159, 576, 403, 221, 327,
+ 214, 244, 122, -62, 312, 92, -160,
+ 218, 208, 310, 268, 306, 323, -199,
+ -285, -269, -79, -124, -143, -153, 236,
+ -205, -384, -426, 344, 59, -185, -184,
+ -272, 247, 126, -210, -518, -468, 78,
+ -99, -120, 502, 160, -280, -557, 304,
+ -423, -17, -283, -443, 215, 212, -140,
+ -564, -684, -228, 510, 361, 130, 323,
+ -428, 335, 98, -65, 36, -215, -246,
+ -362, 51, 364, -16, -234, 150, -165,
+ 914, 883, 751, 653, 676, 464, -153,
+ 631, 545, 535, 720, 596, 360, -81,
+ 783, 712, 512, 439, 341, 251, -391,
+ 497, 417, 249, 372, 295, 173, -193,
+ 128, -110, -385, 93, 39, 173, -231,
+ 216, -59, -253, 462, 389, 154, 69,
+ 455, 270, -4, -337, -49, 233, -322,
+ 307, 143, 53, 218, 128, 236, -156,
+ -37, -186, -240, -411, -110, 9, 399,
+ -140, -365, -628, 258, 380, 214, 277,
+ 131, 454, 177, -285, -520, 108, -214,
+ 77, -141, 201, -123, -490, -131, 60,
+ -14, -194, -521, -741, 273, 362, -33,
+ -362, -566, -287, -228, 161, 237, 317,
+ -269, 195, -75, -375, -204, 11, 77,
+ -128, -264, -156, -223, -475, 265, 27,
+ 1238, 1147, 916, 689, 432, 210, -280,
+ 800, 664, 879, 726, 411, 160, -164,
+ 454, 686, 536, 275, 147, 46, 111,
+ 303, 486, 512, 355, 241, 181, -69,
+ 79, 92, 29, 147, 233, 52, 17,
+ -171, 289, 131, 439, 271, 3, -10,
+ 413, 241, 144, 174, 155, -2, 14,
+ 58, 217, 247, 219, 149, 175, -18,
+ 228, -8, -240, -206, -513, -191, 202,
+ -96, -272, -454, 33, -300, -575, 46,
+ -10, -108, -246, -347, -770, -535, 9,
+ -326, -430, -61, -321, -704, -299, 201,
+ -1, -280, -603, -419, -185, 18, -36,
+ -516, -522, -379, -291, -181, -97, 27,
+ -159, -313, -525, -224, -510, -831, -197,
+ -292, -459, -59, -310, -562, -143, -351,
+ 1066, 912, 631, 389, 207, 86, -224,
+ 596, 512, 596, 505, 314, 122, -48,
+ 787, 861, 441, -93, -303, 33, -190,
+ 257, 469, 337, 51, 15, 298, -93,
+ 295, 73, -119, 25, 36, 23, 108,
+ -28, -3, -32, 114, 21, 185, 107,
+ 482, 305, 15, -279, -319, 52, 96,
+ 226, 46, 115, 72, -136, 133, -125,
+ 18, -207, -559, -590, -503, -482, 321,
+ -571, -789, -951, -172, -441, -538, 113,
+ 181, 14, -310, -641, -1001, -202, 159,
+ -136, -393, -433, -513, -911, -144, -22,
+ 72, -265, -706, -954, -159, 53, 332,
+ -338, -591, -852, -383, -395, 56, 44,
+ 43, -158, -464, -897, -631, -157, -294,
+ -161, -128, -328, -573, -483, -125, 11,
+ 1017, 906, 1051, 1005, 679, 341, -102,
+ 359, 334, 1567, 1314, 723, 105, 10,
+ -65, 726, 529, 301, 220, 43, -273,
+ -510, 436, 719, 566, 358, 179, 114,
+ -560, 298, 133, -120, 342, 225, 14,
+ -899, -101, 217, 617, 400, 146, -58,
+ -41, 352, 82, -196, 39, 121, -167,
+ -212, 59, 447, 284, 423, 250, -169,
+ -371, -484, -596, 30, -41, 249, 22,
+ -372, -650, -794, 477, 445, 216, -79,
+ -352, 275, 17, -443, -929, 92, 19,
+ -699, -696, 431, 264, -49, -310, 182,
+ -978, -217, -430, -400, 101, 261, 72,
+ -929, -889, -357, -13, 463, 378, 236,
+ -826, 56, 30, -299, -360, -128, -51,
+ -878, -299, -111, 75, 65, 36, 3,
+ 817, 368, -25, 354, 697, 591, -173,
+ 309, 212, 222, 751, 484, 140, -56,
+ 593, 379, 70, -8, 258, 180, 110,
+ 165, -46, 255, 297, 219, 273, 105,
+ 160, -70, -358, -181, 379, 330, 319,
+ -238, -369, -198, 740, 580, 319, -143,
+ 201, 109, -202, -456, 328, 276, -141,
+ 203, 170, 111, 42, 207, 360, 188,
+ -345, -399, -513, -233, 650, 422, 81,
+ -635, -961, -1220, 463, 539, 204, 209,
+ 202, -25, -194, -498, -787, 193, -143,
+ -449, -538, 195, -106, -331, 68, 62,
+ -228, -477, -840, -576, 317, 128, 283,
+ -671, -937, -807, -114, 391, 335, -62,
+ 246, 2, -314, -679, -303, 180, -88,
+ -107, -272, 90, -198, -28, 290, -112,
+ 885, 1149, 1021, 712, 496, 281, -83,
+ 269, 492, 787, 643, 347, 70, 124,
+ 336, 636, 499, 92, -229, -179, 191,
+ 26, 402, 564, 340, 149, -11, 135,
+ -440, 561, 470, 204, -72, -186, 140,
+ -720, 14, 355, 229, 68, -133, 465,
+ 110, 310, 103, 12, 106, 29, 158,
+ -178, 113, 161, 142, 121, 115, 27,
+ -651, -414, -645, -152, -164, -13, -429,
+ -639, -944, -681, -104, -81, 52, -189,
+ -663, -164, -316, -683, -954, -205, -83,
+ -609, -669, -172, -517, -694, 283, -80,
+ -646, -152, -383, -678, -246, -40, -143,
+ -747, -796, -745, -390, -98, 43, 275,
+ -599, -199, -398, -433, -436, -538, 31,
+ -1107, -568, -376, -265, -126, -21, 1,
+ 847, 573, 308, 392, 305, 101, 55,
+ 273, 293, 201, 267, 346, 201, 123,
+ 727, 480, 226, 2, -65, -138, 164,
+ 273, 208, 173, 292, 12, 253, 174,
+ 340, 207, 180, 88, 116, 46, 475,
+ -460, -166, -30, 13, 110, 173, 396,
+ 137, 88, 43, -137, -94, 34, 284,
+ 96, -14, 226, 40, 63, 70, 130,
+ -467, -735, -1012, -1174, -307, 305, -67,
+ -612, -920, -1146, -567, -8, 92, -25,
+ -182, -271, -492, -754, -857, 287, -75,
+ -494, -787, -689, -683, -709, 137, -326,
+ -288, -550, -903, -1105, 334, 321, -62,
+ -354, -653, -834, -445, 1, 377, -152,
+ -162, -306, -608, -937, -297, 247, -192,
+ -234, -477, -244, -488, -266, 342, -332};
+
+/*---------------------------------------------------*
+ * 2nd stage codebook; 1st split: isf2_0 to isf2_2
+ *---------------------------------------------------*/
+
+
+static Word16 dico21_isf[SIZE_BK21*3] = {
+
+ 329, 409, 249,
+ -33, 505, 160,
+ -29, -14, 582,
+ -262, 127, 354,
+ 145, 237, 175,
+ -152, 245, 122,
+ 27, 42, 340,
+ -84, -93, 311,
+ 285, 222, -156,
+ 47, -43, -504,
+ 234, 121, 385,
+ 104, -317, 45,
+ 176, 195, 8,
+ 104, -59, -94,
+ 177, 53, 192,
+ -34, -127, 152,
+ 570, 277, -34,
+ -67, -329, -639,
+ -157, -272, 462,
+ -177, -462, 198,
+ 322, 179, 115,
+ -386, 171, 19,
+ 19, -12, 195,
+ -120, -252, 201,
+ 304, 36, -336,
+ -128, -221, -380,
+ 171, -185, 296,
+ -242, -312, 23,
+ 198, 39, 16,
+ -3, -177, -111,
+ 111, -93, 76,
+ -92, -223, 4,
+ 177, 406, -44,
+ -168, 380, -149,
+ -4, 273, 331,
+ -420, 513, 277,
+ 21, 247, 47,
+ -58, 131, -2,
+ -3, 134, 180,
+ -145, 40, 175,
+ 189, 74, -145,
+ -27, -45, -325,
+ 370, -114, -21,
+ -83, -415, -173,
+ 77, 95, -51,
+ -40, -30, -67,
+ 71, 88, 86,
+ -35, -98, 14,
+ 69, 197, -334,
+ -196, 79, -231,
+ -348, -137, 218,
+ -352, -89, -85,
+ 47, 201, -130,
+ -165, 37, -15,
+ -43, 3, 86,
+ -161, -108, 79,
+ 83, 21, -237,
+ -81, -149, -238,
+ 150, -186, -251,
+ -186, -249, -162,
+ -19, 66, -139,
+ -26, -50, -181,
+ 24, 11, 0,
+ -130, -105, -98};
+
+
+
+/*---------------------------------------------------*
+ * 2nd stage codebook; 2nd split: isf2_3 to isf2_5
+ *---------------------------------------------------*/
+
+
+static Word16 dico22_isf[SIZE_BK22*3] = {
+
+ -127, 310, 42,
+ -242, 197, 5,
+ -151, 84, -17,
+ -214, 127, -149,
+ -247, -131, 159,
+ -268, -267, -95,
+ -217, 1, -79,
+ -271, -80, -185,
+ -45, 436, 159,
+ 165, 199, 391,
+ -33, 81, 187,
+ -66, -42, 355,
+ -298, -57, 343,
+ -108, -537, 226,
+ -144, -23, 193,
+ 176, -402, 87,
+ 53, 296, 25,
+ -84, 253, -104,
+ -58, 105, -126,
+ -169, 174, -314,
+ -48, 44, -294,
+ -164, -417, -242,
+ -139, 3, -194,
+ -155, -207, -211,
+ 119, 322, 213,
+ 333, 50, 380,
+ 237, 247, -2,
+ 466, -16, 201,
+ 238, -255, -107,
+ 67, -440, -149,
+ 122, -88, -139,
+ 88, -247, -73,
+ -41, 231, 167,
+ -62, 155, 16,
+ -65, 16, 77,
+ -68, -2, -63,
+ -151, -300, 160,
+ -18, -333, 54,
+ -56, -94, 5,
+ 2, -190, 14,
+ 92, 148, 209,
+ 108, 9, 272,
+ 108, 35, 110,
+ 142, -85, 145,
+ 47, -157, 279,
+ 3, -320, 246,
+ 43, -72, 68,
+ 86, -217, 135,
+ 36, 140, 79,
+ 56, 175, -49,
+ 26, 45, 3,
+ 73, 55, -101,
+ 109, -183, -242,
+ -4, -283, -242,
+ 48, -68, -48,
+ -6, -153, -122,
+ 161, 196, 96,
+ 232, 80, 190,
+ 165, 97, 11,
+ 258, -31, 71,
+ 267, -77, -91,
+ 311, -209, 87,
+ 152, -14, -22,
+ 150, -149, 9,
+ -324, 557, 187,
+ -384, 307, 46,
+ -251, 27, 77,
+ -365, 77, -52,
+ -482, -84, 160,
+ -424, -515, -64,
+ -294, -120, -4,
+ -476, -116, -109,
+ -97, 318, 365,
+ 106, 627, 445,
+ -190, 120, 287,
+ -146, 65, 619,
+ -427, 242, 363,
+ -361, -371, 432,
+ -347, 102, 168,
+ -629, 195, -14,
+ -65, 476, -47,
+ -297, 320, -168,
+ -55, 356, -264,
+ -391, 82, -286,
+ -51, -31, -556,
+ -178, -399, -586,
+ -205, -49, -360,
+ -343, -238, -337,
+ 220, 457, 58,
+ 561, 467, 259,
+ 340, 270, -168,
+ 450, 77, -280,
+ 60, 167, -413,
+ 133, -252, -492,
+ 216, 157, -290,
+ 282, 0, -495,
+ -226, 293, 183,
+ -157, 135, 122,
+ -158, -59, 39,
+ -133, -118, -97,
+ -332, -309, 113,
+ -160, -425, -6,
+ -149, -211, 24,
+ -80, -277, -90,
+ -11, 125, 338,
+ 130, -71, 465,
+ 5, -45, 184,
+ 237, -95, 253,
+ -139, -197, 297,
+ -19, -300, 511,
+ -63, -152, 139,
+ 250, -289, 336,
+ 124, 339, -150,
+ 34, 176, -208,
+ 171, 166, -116,
+ 94, 38, -229,
+ 75, -65, -339,
+ -78, -205, -385,
+ 0, -30, -163,
+ -56, -110, -242,
+ 321, 244, 194,
+ 505, 238, -1,
+ 317, 116, 65,
+ 309, 88, -74,
+ 452, -51, -50,
+ 334, -217, -290,
+ 211, 41, -152,
+ 238, -55, -260};
+
+
+/*---------------------------------------------------*
+ * 2nd stage codebook; 3rd split: isf2_6 to isf2_8
+ *---------------------------------------------------*/
+
+
+static Word16 dico23_isf[SIZE_BK23*3] = {
+
+ -10, 151, 359,
+ 136, 298, 223,
+ 255, -104, 290,
+ 423, 6, 183,
+ -270, -269, -98,
+ -52, -82, 13,
+ -82, -274, -97,
+ 90, -246, -72,
+ -299, -70, 421,
+ -88, 365, 430,
+ 187, -318, 381,
+ 380, 37, 488,
+ -373, -316, 79,
+ -308, -101, 5,
+ -135, -451, 8,
+ 72, -421, -154,
+ 180, 170, -121,
+ 62, 177, -40,
+ 326, 80, -105,
+ 248, 263, -5,
+ -168, -181, -221,
+ -2, -23, -158,
+ -14, -149, -121,
+ 119, -91, -147,
+ 119, 332, -153,
+ 49, 303, 34,
+ 442, -55, -69,
+ 217, 454, 58,
+ -359, -187, -375,
+ -42, 50, -274,
+ -8, -267, -249,
+ 85, -86, -346,
+ -77, -40, 345,
+ 89, 134, 219,
+ 156, -80, 160,
+ 108, 40, 116,
+ -158, -206, 29,
+ 5, -32, 175,
+ -65, -158, 146,
+ 55, -78, 73,
+ -114, -222, 353,
+ -47, 81, 211,
+ 49, -151, 268,
+ 105, 4, 302,
+ -263, -132, 183,
+ -151, -28, 201,
+ -177, -307, 166,
+ 101, -221, 130,
+ 74, 58, -98,
+ 32, 44, 13,
+ 194, 30, -142,
+ 170, 96, 8,
+ -136, -119, -91,
+ -65, 8, -55,
+ 3, -188, 12,
+ 45, -63, -49,
+ 149, -21, -19,
+ 24, 144, 95,
+ 254, -22, 60,
+ 161, 196, 96,
+ -158, -61, 48,
+ -70, 33, 82,
+ -23, -321, 58,
+ 155, -147, 5,
+ -364, 328, 77,
+ -21, 453, 173,
+ -108, 82, 630,
+ 367, 263, 208,
+ -300, -62, -176,
+ -205, 143, -158,
+ -169, -410, -264,
+ 257, -269, -100,
+ -636, 289, -2,
+ -292, 627, 173,
+ -382, -363, 387,
+ 248, 524, 447,
+ -521, -111, -107,
+ -395, 118, -274,
+ -343, -680, -125,
+ -172, -447, -663,
+ 75, 148, -367,
+ -79, 263, -94,
+ 249, 148, -286,
+ 380, 271, -162,
+ -142, -4, -186,
+ -57, 111, -125,
+ -35, -108, -254,
+ 100, 29, -242,
+ -80, 303, -264,
+ -78, 464, -57,
+ 248, -22, -494,
+ 661, 662, 44,
+ -193, -40, -330,
+ -178, 145, -337,
+ -90, -199, -400,
+ -40, -23, -498,
+ -192, 114, 315,
+ -41, 244, 190,
+ 88, -97, 485,
+ 241, 80, 212,
+ -246, 40, 87,
+ -156, 147, 134,
+ -2, -334, 239,
+ 308, -203, 110,
+ -459, 251, 422,
+ -218, 310, 228,
+ -86, -346, 654,
+ 184, 175, 425,
+ -481, -63, 169,
+ -349, 117, 188,
+ -125, -560, 310,
+ 158, -416, 94,
+ 46, 171, -192,
+ -63, 157, 14,
+ 256, -35, -271,
+ 322, 123, 53,
+ -214, 4, -76,
+ -156, 86, -18,
+ 128, -197, -232,
+ 265, -90, -98,
+ -308, 332, -145,
+ -131, 308, 58,
+ 509, 59, -339,
+ 562, 196, -14,
+ -378, 100, -47,
+ -234, 202, 1,
+ 104, -270, -493,
+ 319, -210, -325};
+
+
+/*---------------------------------------------------*
+ * 2nd stage codebook; 4th split: isf2_9 to isf2_11
+ *---------------------------------------------------*/
+
+static Word16 dico24_isf[SIZE_BK24*3] = {
+
+ -79, -89, -4,
+ -171, 77, -211,
+ 160, -193, 98,
+ 120, -103, 323,
+ 32, -22, -129,
+ 72, 78, -268,
+ 182, -76, -66,
+ 309, 99, -145,
+ -229, -157, -84,
+ -383, 98, -71,
+ -90, -352, 12,
+ -284, -178, 178,
+ -65, -125, -166,
+ -87, -175, -351,
+ 42, -198, -48,
+ 154, -140, -243,
+ -77, 18, 108,
+ -39, 355, 91,
+ 87, 8, 155,
+ -4, 158, 239,
+ 128, 95, -54,
+ 7, 246, -124,
+ 258, 15, 89,
+ 206, 216, 98,
+ -201, 9, 18,
+ -312, 233, 204,
+ -39, -174, 155,
+ -144, -9, 284,
+ -57, 70, -69,
+ -157, 187, 18,
+ 54, -30, 23,
+ 24, 135, 55};
+
+
+/*---------------------------------------------------*
+ * 2nd stage codebook; 5th split: isf2_12 to isf2_15
+ *---------------------------------------------------*/
+
+static Word16 dico25_isf[SIZE_BK25*4] = {
+
+ 169, 142, -119, 115,
+ 206, -20, 94, 226,
+ -106, 313, -21, 16,
+ -62, 161, 71, 255,
+ -89, 101, -185, 125,
+ 72, -30, -201, 344,
+ -258, 33, -8, 81,
+ -104, -154, 72, 296,
+ 144, -68, -268, -25,
+ 81, -78, -87, 106,
+ 22, 155, -186, -119,
+ -46, -28, 27, 91,
+ -114, -37, -175, -33,
+ -94, -222, -189, 122,
+ -132, -119, -191, -270,
+ -172, -173, 18, -43,
+ 279, 135, -42, -128,
+ 187, -86, 229, -138,
+ 159, 240, 140, 46,
+ 69, 25, 227, 77,
+ 21, 115, 13, 8,
+ 68, -248, 126, 81,
+ -150, 137, 207, -9,
+ -154, -133, 289, 67,
+ 143, -37, -86, -326,
+ 180, -32, 19, -23,
+ 26, 168, 116, -233,
+ -32, -26, 118, -78,
+ 3, -8, -45, -115,
+ 57, -215, -54, -83,
+ -209, 112, -22, -167,
+ -91, -151, 168, -262};
+
+
+
+ /* 36 bit */
+/*-------------------------------------------------------------------*
+ * isf codebooks: two-stage VQ with split-by-3 in 2nd stage *
+ * 1st stage is kept the same as the 46 bit quantizer *
+ * *
+ * codebook vector dimension number of vectors *
+ * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ *
+ * 1_1 9 256 *
+ * 1_2 7 256 *
+ * 2_1 5 128 *
+ * 2_2 4 128 *
+ * 2_3 7 64 *
+ *-------------------------------------------------------------------*/
+
+static Word16 dico21_isf_36b[SIZE_BK21_36b*5] = {
+
+ -52, -96, 212, 315, -73,
+ 82, -204, 363, 136, -197,
+ -126, -331, 183, 218, 143,
+ -49, -41, 557, 230, 72,
+ 2, -73, 163, 377, 221,
+ 133, 111, 278, 215, -110,
+ -102, -20, 284, 113, 273,
+ 84, 319, 290, 18, 85,
+ -25, -5, 125, 132, -204,
+ -38, -5, 286, -9, -356,
+ -140, -256, 92, 117, -189,
+ -144, 191, 313, 51, -98,
+ 167, -10, 44, 247, 36,
+ 381, 197, 238, 74, 6,
+ 38, -408, 29, -3, -85,
+ 92, 266, 157, -25, -200,
+ 161, -121, 70, 84, -140,
+ -16, -86, 112, -94, -189,
+ -269, -270, 351, 107, -24,
+ -68, -67, 492, -103, -155,
+ -53, -131, 62, 122, 10,
+ 135, 84, 283, -55, -120,
+ -12, -219, 331, -81, 167,
+ 220, -136, 147, -172, -42,
+ 140, -95, -109, -88, -194,
+ 0, -2, -4, -33, -381,
+ -66, -217, 152, -186, -402,
+ 244, 108, 156, -140, -395,
+ 113, -136, -196, 110, -24,
+ 214, 118, 11, -64, -131,
+ -110, -286, -6, -332, 16,
+ 94, 97, 79, -291, -205,
+ -5, -39, -20, 252, -96,
+ 76, 174, 101, 163, 61,
+ -69, -239, -55, 399, 6,
+ -115, 319, 164, 275, 196,
+ -15, 36, -47, 331, 121,
+ 226, 209, 271, 325, 184,
+ 13, -80, -218, 471, 353,
+ 288, 378, 16, -51, 251,
+ 174, 116, 52, 149, -279,
+ 235, 276, 39, 120, -48,
+ 0, -108, -108, 241, -339,
+ -93, 534, 45, 33, -87,
+ 194, 149, -71, 405, -44,
+ 409, 370, 81, -186, -154,
+ 25, -102, -448, 124, -173,
+ 22, 408, -110, -310, -214,
+ -26, 23, -83, 114, 14,
+ -110, 164, 52, 223, -82,
+ 37, -25, -263, 306, -15,
+ -466, 415, 292, 165, -18,
+ 29, -19, -171, 155, 182,
+ 179, 144, -27, 231, 258,
+ -103, -247, -396, 238, 113,
+ 375, -154, -109, -4, 156,
+ 98, 85, -292, -5, -124,
+ 116, 139, -116, -98, -294,
+ -14, -83, -278, -117, -378,
+ 106, 33, -106, -344, -484,
+ 119, 17, -412, 138, 166,
+ 384, 101, -204, 88, -156,
+ -121, -284, -300, -1, -166,
+ 280, 33, -152, -313, -81,
+ -37, 22, 229, 153, 37,
+ -60, -83, 236, -8, -41,
+ -169, -228, 126, -20, 363,
+ -235, 17, 364, -156, 156,
+ -25, -30, 72, 144, 156,
+ 153, -26, 256, 97, 144,
+ -21, -37, 48, -65, 250,
+ 63, 77, 273, -128, 124,
+ -129, -26, 40, 9, -115,
+ -6, 82, 38, -90, -182,
+ -336, -13, 28, 158, 91,
+ -30, 241, 137, -170, -17,
+ 146, 14, -11, 33, 61,
+ 192, 197, 54, -84, 85,
+ 23, -200, -78, -29, 140,
+ 122, 237, 106, -341, 136,
+ -57, -142, -85, -16, -74,
+ -59, -90, -8, -187, -20,
+ -211, -267, 216, -179, -110,
+ -50, -7, 220, -267, -70,
+ -57, -42, -17, -15, 71,
+ 32, 21, 63, -137, 33,
+ -137, -175, 104, -68, 97,
+ -67, -43, 133, -301, 221,
+ -116, -200, -81, -92, -272,
+ -64, -41, -54, -244, -220,
+ -287, -242, -50, -87, -89,
+ -245, 236, 102, -166, -295,
+ 66, 24, -162, -71, 95,
+ 66, 136, -90, -220, -36,
+ -98, -161, -222, -188, 29,
+ -18, 18, -19, -415, 9,
+ 49, 61, 100, 39, -56,
+ -111, 82, 135, -31, 52,
+ -90, -153, -93, 189, 182,
+ -214, 295, 119, -74, 284,
+ 2, 137, 37, 47, 182,
+ 92, 117, 184, -53, 373,
+ -21, -14, -35, 136, 391,
+ 146, 129, -164, -28, 333,
+ 92, 80, -84, 100, -134,
+ -8, 217, -32, 3, -47,
+ -151, 251, -215, 142, 92,
+ -224, 310, -172, -275, 98,
+ 159, 155, -177, 112, 53,
+ 205, 27, 8, -240, 192,
+ 169, 120, -319, -201, 106,
+ 11, 36, -86, -237, 455,
+ -109, -154, -163, 174, -55,
+ -38, 32, -101, -78, -59,
+ -205, -321, -97, 69, 79,
+ -310, 44, 18, -185, 34,
+ -115, -20, -148, -39, 203,
+ -29, 154, -30, -158, 166,
+ -45, -131, -317, -24, 363,
+ -165, -205, -112, -222, 265,
+ -32, -44, -150, 54, -193,
+ -6, -38, -255, -169, -115,
+ -266, 87, -189, -36, -169,
+ -60, -87, -266, -436, -170,
+ -68, -81, -278, 24, 38,
+ -23, -19, -155, -256, 141,
+ -61, -226, -565, -175, 71,
+ 9, -29, -237, -515, 263};
+
+static Word16 dico22_isf_36b[SIZE_BK22_36b*4] = {
+
+ -298, -6, 95, 31,
+ -213, -87, -122, 261,
+ 4, -49, 208, 14,
+ -129, -110, 30, 118,
+ -214, 258, 110, -235,
+ -41, -18, -126, 120,
+ 103, 65, 127, -37,
+ 126, -36, -24, 25,
+ -138, -67, -278, -186,
+ -164, -194, -201, 78,
+ -211, -87, -51, -221,
+ -174, -79, -94, -39,
+ 23, -6, -157, -240,
+ 22, -110, -153, -68,
+ 148, -5, -2, -149,
+ -1, -135, -39, -179,
+ 68, 360, -117, -15,
+ 137, 47, -278, 146,
+ 136, 260, 135, 65,
+ 61, 116, -45, 97,
+ 231, 379, 87, -120,
+ 338, 177, -272, 3,
+ 266, 156, 28, -69,
+ 260, 84, -85, 86,
+ -266, 154, -256, -182,
+ -17, -65, -304, -6,
+ -40, 175, -151, -180,
+ -27, 27, -87, -63,
+ 121, 114, -166, -469,
+ 159, -66, -323, -231,
+ 214, 152, -141, -212,
+ 137, 36, -184, -51,
+ -282, -237, 40, 10,
+ -48, -235, -37, 251,
+ -54, -323, 136, 29,
+ -88, -174, 213, 198,
+ -390, 99, -63, -375,
+ 107, -169, -164, 424,
+ 69, -111, 141, -167,
+ 74, -129, 65, 144,
+ -353, -207, -205, -109,
+ -160, -386, -355, 98,
+ -176, -493, -20, -143,
+ -252, -432, -2, 216,
+ -90, -174, -168, -411,
+ 13, -284, -229, -160,
+ -87, -279, 34, -251,
+ -75, -263, -58, -42,
+ 420, 53, -211, -358,
+ 384, -35, -374, 396,
+ 68, -228, 323, -2,
+ 167, -307, 192, 194,
+ 459, 329, -5, -332,
+ 375, 79, -7, 313,
+ 282, -124, 200, -92,
+ 271, -162, -70, 180,
+ -157, -298, -514, -309,
+ 58, -163, -546, 18,
+ 124, -364, 167, -238,
+ 83, -411, -117, 96,
+ 140, -112, -388, -624,
+ 259, -133, -317, 41,
+ 163, -130, -64, -334,
+ 226, -165, -124, -110,
+ -466, -61, 6, 229,
+ -153, 205, -145, 242,
+ -159, 48, 195, 148,
+ -58, 28, 31, 279,
+ -303, 185, 279, -4,
+ -61, 197, 59, 86,
+ -114, 123, 168, -52,
+ 35, 36, 100, 126,
+ -407, 102, -77, -40,
+ -338, -1, -342, 156,
+ -179, 105, -34, -97,
+ -185, 84, -35, 108,
+ -133, 107, -91, -357,
+ -180, 54, -229, 24,
+ -44, 47, 47, -182,
+ -66, 13, 45, 4,
+ -339, 251, 64, 226,
+ -42, 101, -350, 275,
+ -99, 398, 142, 121,
+ 111, 12, -102, 260,
+ 0, 505, 260, -94,
+ 161, 285, -96, 224,
+ -4, 206, 314, 33,
+ 167, 139, 88, 204,
+ -235, 316, -60, -25,
+ -8, -150, -312, 201,
+ -36, 292, 61, -104,
+ -40, 174, -162, 42,
+ -21, 402, -29, -351,
+ 21, 152, -360, -93,
+ 57, 191, 212, -196,
+ 76, 158, -21, -69,
+ -328, -185, 331, 119,
+ -53, 285, 56, 337,
+ -107, -24, 405, 29,
+ -18, 137, 272, 277,
+ -255, 22, 173, -191,
+ 295, 322, 325, 302,
+ 21, -27, 332, -178,
+ 119, 13, 271, 129,
+ -455, -180, 116, -191,
+ -227, 62, -148, 524,
+ -176, -287, 282, -157,
+ -243, 13, 199, 430,
+ -59, -49, 115, -365,
+ 72, -172, -137, 93,
+ -138, -126, 141, -84,
+ 5, -124, 38, -20,
+ -258, 311, 601, 213,
+ 94, 130, -61, 502,
+ -1, -157, 485, 313,
+ 146, -74, 158, 345,
+ 276, 135, 280, -57,
+ 490, 252, 99, 43,
+ 267, -74, 429, 105,
+ 278, -23, 119, 94,
+ -542, 488, 257, -115,
+ -84, -244, -438, 478,
+ -113, -545, 387, 101,
+ -95, -306, 111, 498,
+ 95, 166, 22, -301,
+ 420, -15, -58, -78,
+ 270, 29, 122, -282,
+ 160, -240, 50, -38};
+
+static Word16 dico23_isf_36b[SIZE_BK23_36b*7] = {
+
+ 81, -18, 68, -27, -122, -280, -4,
+ 45, -177, 209, -30, -136, -74, 131,
+ -44, 101, -75, -88, -48, -137, -54,
+ -245, -28, 63, -18, -112, -103, 58,
+ -79, -6, 220, -65, 114, -35, -50,
+ 109, -65, 143, -114, 129, 76, 125,
+ 166, 90, -61, -242, 186, -74, -43,
+ -46, -92, 49, -227, 24, -155, 39,
+ 67, 85, 99, -42, 53, -184, -281,
+ 142, -122, 0, 21, -142, -15, -17,
+ 223, 92, -21, -48, -82, -14, -167,
+ 51, -37, -243, -30, -90, 18, -56,
+ 54, 105, 74, 86, 69, 13, -101,
+ 196, 72, -89, 43, 65, 19, 39,
+ 121, 34, 131, -82, 25, 213, -156,
+ 101, -102, -136, -21, 57, 214, 22,
+ 36, -124, 205, 204, 58, -156, -83,
+ 83, -117, 137, 137, 85, 116, 44,
+ -92, -148, -68, 11, -102, -197, -220,
+ -76, -185, -58, 132, -26, -183, 85,
+ -7, -31, -2, 23, 205, -151, 10,
+ -27, -37, -5, -18, 292, 131, 1,
+ 117, -168, 9, -93, 80, -59, -125,
+ -182, -244, 98, -24, 135, -22, 94,
+ 221, 97, 106, 42, 43, -160, 83,
+ 25, -64, -21, 6, 14, -15, 154,
+ 126, 15, -140, 150, -10, -207, -114,
+ 79, -63, -211, -70, -28, -217, 165,
+ 46, 38, -22, 281, 132, -62, 109,
+ 112, 54, -112, -93, 208, 27, 296,
+ 115, 10, -147, 41, 216, 42, -276,
+ 50, -115, -254, 167, 117, -2, 61,
+ 17, 144, 34, -72, -186, -150, 272,
+ -29, -66, -89, -95, -149, 129, 251,
+ 122, 0, -50, -234, -91, 36, 26,
+ -105, -102, -88, -121, -236, -7, -11,
+ -204, 109, 5, -191, 105, -15, 163,
+ -80, 32, -24, -209, 41, 294, 70,
+ -106, -94, -204, -118, 120, -50, -37,
+ -82, -241, 46, -131, -29, 150, -55,
+ 33, 155, 120, -89, -8, 7, 62,
+ 213, 82, 61, 18, -161, 144, 152,
+ 30, 131, 65, -87, -255, -17, -107,
+ -8, 85, -64, 51, -162, 223, -53,
+ -134, 261, 69, -56, 218, 72, -111,
+ 2, 155, -113, -87, 49, 85, -28,
+ -163, 42, -1, -196, 7, 39, -245,
+ 14, -137, -79, 11, -160, 202, -293,
+ -94, 33, 208, 100, 56, -44, 326,
+ -78, -41, 232, 13, -142, 227, 80,
+ -16, -87, 201, 33, -133, 15, -183,
+ -58, -192, -47, 184, -128, 133, 99,
+ -205, 11, -155, 78, 52, 72, 141,
+ -246, 26, 99, 151, 59, 115, -64,
+ -79, -47, -16, -14, 6, 47, -43,
+ -72, -178, -27, 162, 112, 43, -174,
+ -175, 238, 186, 71, -54, -188, -76,
+ -225, 233, 39, -39, -158, 122, 44,
+ -26, 43, 84, 130, -93, -51, 22,
+ 3, 92, -150, 136, -182, -57, 97,
+ -131, 179, -78, 80, 91, -165, 90,
+ -2, 148, 15, 130, 65, 175, 117,
+ -138, 114, -137, 132, 3, -10, -186,
+ 140, -4, -37, 254, -62, 92, -109};
+
+
diff --git a/media/codecs/amrwb/enc/inc/stream.h b/media/codecs/amrwb/enc/inc/stream.h
new file mode 100644
index 0000000..fbaae9e
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/stream.h
@@ -0,0 +1,47 @@
+
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/***********************************************************************
+File: stream.h
+
+Contains: VOME API Buffer Operator Implement Header
+
+************************************************************************/
+#ifndef __STREAM_H__
+#define __STREAM_H__
+
+#include "voMem.h"
+#define Frame_Maxsize (1024 * 2) //Work Buffer 10K
+#define Frame_MaxByte 640 //AMR_WB Encoder one frame 320 samples = 640 Bytes
+#define MIN(a,b) ((a) < (b)? (a) : (b))
+
+typedef struct{
+ unsigned char *set_ptr;
+ unsigned char *frame_ptr;
+ unsigned char *frame_ptr_bk;
+ int set_len;
+ int framebuffer_len;
+ int frame_storelen;
+ int used_len;
+}FrameStream;
+
+void voAWB_UpdateFrameBuffer(FrameStream *stream, VO_MEM_OPERATOR *pMemOP);
+void voAWB_InitFrameBuffer(FrameStream *stream);
+void voAWB_FlushFrameBuffer(FrameStream *stream);
+#endif //__STREAM_H__
+
diff --git a/media/codecs/amrwb/enc/inc/typedef.h b/media/codecs/amrwb/enc/inc/typedef.h
new file mode 100644
index 0000000..f08a678
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/typedef.h
@@ -0,0 +1,65 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+*
+* File : typedef.c
+* Purpose : Basic types.
+*
+************************************************************************/
+
+#ifndef __TYPEDEF_H__
+#define __TYPEDEF_H__
+
+#undef ORIGINAL_TYPEDEF_H /* define to get "original" ETSI version
+ of typedef.h */
+
+#ifdef ORIGINAL_TYPEDEF_H
+/*
+ * this is the original code from the ETSI file typedef.h
+ */
+
+#if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(_MSC_VER) || defined(__ZTC__)
+typedef signed char Word8;
+typedef short Word16;
+typedef long Word32;
+typedef int Flag;
+
+#elif defined(__sun)
+typedef signed char Word8;
+typedef short Word16;
+typedef long Word32;
+typedef int Flag;
+
+#elif defined(__unix__) || defined(__unix)
+typedef signed char Word8;
+typedef short Word16;
+typedef int Word32;
+typedef int Flag;
+
+#endif
+#else /* not original typedef.h */
+
+/*
+ * use (improved) type definition file typdefs.h and add a "Flag" type
+ */
+#include "typedefs.h"
+typedef int Flag;
+
+#endif
+
+#endif //__TYPEDEF_H__
+
diff --git a/media/codecs/amrwb/enc/inc/typedefs.h b/media/codecs/amrwb/enc/inc/typedefs.h
new file mode 100644
index 0000000..0062584
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/typedefs.h
@@ -0,0 +1,211 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/*
+*
+* File : typedefs.h
+* Description : Definition of platform independent data
+* types and constants
+*
+*
+* The following platform independent data types and corresponding
+* preprocessor (#define) constants are defined:
+*
+* defined type meaning corresponding constants
+* ----------------------------------------------------------
+* Char character (none)
+* Bool boolean true, false
+* Word8 8-bit signed minWord8, maxWord8
+* UWord8 8-bit unsigned minUWord8, maxUWord8
+* Word16 16-bit signed minWord16, maxWord16
+* UWord16 16-bit unsigned minUWord16, maxUWord16
+* Word32 32-bit signed minWord32, maxWord32
+* UWord32 32-bit unsigned minUWord32, maxUWord32
+* Float floating point minFloat, maxFloat
+*
+*
+* The following compile switches are #defined:
+*
+* PLATFORM string indicating platform progam is compiled on
+* possible values: "OSF", "PC", "SUN"
+*
+* OSF only defined if the current platform is an Alpha
+* PC only defined if the current platform is a PC
+* SUN only defined if the current platform is a Sun
+*
+* LSBFIRST is defined if the byte order on this platform is
+* "least significant byte first" -> defined on DEC Alpha
+* and PC, undefined on Sun
+*
+********************************************************************************
+*/
+
+#ifndef __TYPEDEFS_H__
+#define __TYPEDEFS_H__
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include <float.h>
+#include <limits.h>
+
+
+
+/*
+********************************************************************************
+* DEFINITION OF CONSTANTS
+********************************************************************************
+*/
+/*
+ ********* define char type
+ */
+typedef char Char;
+
+/*
+ ********* define 8 bit signed/unsigned types & constants
+ */
+#if SCHAR_MAX == 127
+typedef signed char Word8;
+#define minWord8 SCHAR_MIN
+#define maxWord8 SCHAR_MAX
+
+typedef unsigned char UWord8;
+#define minUWord8 0
+#define maxUWord8 UCHAR_MAX
+#else
+#error cannot find 8-bit type
+#endif
+
+
+/*
+ ********* define 16 bit signed/unsigned types & constants
+ */
+#if INT_MAX == 32767
+typedef int Word16;
+#define minWord16 INT_MIN
+#define maxWord16 INT_MAX
+typedef unsigned int UWord16;
+#define minUWord16 0
+#define maxUWord16 UINT_MAX
+#elif SHRT_MAX == 32767
+typedef short Word16;
+#define minWord16 SHRT_MIN
+#define maxWord16 SHRT_MAX
+typedef unsigned short UWord16;
+#define minUWord16 0
+#define maxUWord16 USHRT_MAX
+#else
+#error cannot find 16-bit type
+#endif
+
+
+/*
+ ********* define 32 bit signed/unsigned types & constants
+ */
+#if INT_MAX == 2147483647
+typedef int Word32;
+#define minWord32 INT_MIN
+#define maxWord32 INT_MAX
+typedef unsigned int UWord32;
+#define minUWord32 0
+#define maxUWord32 UINT_MAX
+#elif LONG_MAX == 2147483647
+typedef long Word32;
+#define minWord32 LONG_MIN
+#define maxWord32 LONG_MAX
+typedef unsigned long UWord32;
+#define minUWord32 0
+#define maxUWord32 ULONG_MAX
+#else
+#error cannot find 32-bit type
+#endif
+
+/*
+ ********* define floating point type & constants
+ */
+/* use "#if 0" below if Float should be double;
+ use "#if 1" below if Float should be float
+ */
+#if 0
+typedef float Float;
+#define maxFloat FLT_MAX
+#define minFloat FLT_MIN
+#else
+typedef double Float;
+#define maxFloat DBL_MAX
+#define minFloat DBL_MIN
+#endif
+
+/*
+ ********* define complex type
+ */
+typedef struct {
+ Float r; /* real part */
+ Float i; /* imaginary part */
+} CPX;
+
+/*
+ ********* define boolean type
+ */
+typedef int Bool;
+#define false 0
+#define true 1
+
+/* ******Avoid function multiple definition****** */
+#define Autocorr voAWB_Autocorr
+#define Convolve voAWB_Convolve
+#define cor_h_x voAWB_cor_h_x
+#define dtx_enc_init voAWB_dtx_enc_init
+#define dtx_enc_reset voAWB_dtx_enc_reset
+#define dtx_enc_exit voAWB_dtx_enc_exit
+#define dtx_enc voAWB_dtx_enc
+#define dtx_buffer voAWB_dtx_buffer
+#define tx_dtx_handler voAWB_tx_dtx_handler
+#define G_pitch voAWB_G_pitch
+#define Isp_Az voAWB_Isp_Az
+#define Lag_window voAWB_Lag_window
+#define Log2_norm voAWB_Log2_norm
+#define Log2 voAWB_Log2
+#define Pow2 voAWB_Pow2
+#define L_Comp voAWB_L_Comp
+#define Mpy_32 voAWB_Mpy_32
+#define Mpy_32_16 voAWB_Mpy_32_16
+#define Div_32 voAWB_Div_32
+#define Pit_shrp voAWB_Pit_shrp
+#define Qisf_ns voAWB_Qisf_ns
+#define Disf_ns voAWB_Disf_ns
+#define Residu voAWB_Residu
+#define Syn_filt voAWB_Syn_filt
+#define Set_zero voAWB_Set_zero
+#define Copy voAWB_Copy
+#define voice_factor voAWB_voice_factor
+#define Syn_filt_32 voAWB_Syn_filt_32
+#define Isf_isp voAWB_Isf_isp
+#define Levinson voAWB_Levinson
+#define median5 voAWB_median5
+#define Pred_lt4 voAWB_Pred_lt4
+#define Reorder_isf voAWB_Reorder_isf
+#define Dpisf_2s_36b voAWB_Dpisf_2s_36b
+#define Dpisf_2s_46b voAWB_Dpisf_2s_46b
+#define Dot_product12 voAWB_Dot_product12
+#define mem_malloc voAWB_mem_malloc
+#define mem_free voAWB_mem_free
+/******************************************************/
+
+#endif //#define __TYPEDEFS_H__
+
diff --git a/media/codecs/amrwb/enc/inc/wb_vad.h b/media/codecs/amrwb/enc/inc/wb_vad.h
new file mode 100644
index 0000000..9a9af4f
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/wb_vad.h
@@ -0,0 +1,78 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*-------------------------------------------------------------------*
+ * WB_VAD.H *
+ *-------------------------------------------------------------------*
+ * Functions and static memory for Voice Activity Detection. *
+ *-------------------------------------------------------------------*/
+
+#ifndef __WB_VAD_H__
+#define __WB_VAD_H__
+
+/******************************************************************************
+ * INCLUDE FILES
+ ******************************************************************************/
+#include "typedef.h"
+#include "wb_vad_c.h"
+#include "voMem.h"
+
+/******************************************************************************
+ * DEFINITION OF DATA TYPES
+ ******************************************************************************/
+
+typedef struct
+{
+ Word16 bckr_est[COMPLEN]; /* background noise estimate */
+ Word16 ave_level[COMPLEN]; /* averaged input components for stationary */
+ /* estimation */
+ Word16 old_level[COMPLEN]; /* input levels of the previous frame */
+ Word16 sub_level[COMPLEN]; /* input levels calculated at the end of a frame (lookahead) */
+ Word16 a_data5[F_5TH_CNT][2]; /* memory for the filter bank */
+ Word16 a_data3[F_3TH_CNT]; /* memory for the filter bank */
+
+ Word16 burst_count; /* counts length of a speech burst */
+ Word16 hang_count; /* hangover counter */
+ Word16 stat_count; /* stationary counter */
+
+ /* Note that each of the following two variables holds 15 flags. Each flag reserves 1 bit of the
+ * variable. The newest flag is in the bit 15 (assuming that LSB is bit 1 and MSB is bit 16). */
+ Word16 vadreg; /* flags for intermediate VAD decisions */
+ Word16 tone_flag; /* tone detection flags */
+
+ Word16 sp_est_cnt; /* counter for speech level estimation */
+ Word16 sp_max; /* maximum level */
+ Word16 sp_max_cnt; /* counts frames that contains speech */
+ Word16 speech_level; /* estimated speech level */
+ Word32 prev_pow_sum; /* power of previous frame */
+
+} VadVars;
+
+/********************************************************************************
+ *
+ * DECLARATION OF PROTOTYPES
+ ********************************************************************************/
+
+Word16 wb_vad_init(VadVars ** st, VO_MEM_OPERATOR *pMemOP);
+Word16 wb_vad_reset(VadVars * st);
+void wb_vad_exit(VadVars ** st, VO_MEM_OPERATOR *pMemOP);
+void wb_vad_tone_detection(VadVars * st, Word16 p_gain);
+Word16 wb_vad(VadVars * st, Word16 in_buf[]);
+
+#endif //__WB_VAD_H__
+
+
diff --git a/media/codecs/amrwb/enc/inc/wb_vad_c.h b/media/codecs/amrwb/enc/inc/wb_vad_c.h
new file mode 100644
index 0000000..00b1779
--- /dev/null
+++ b/media/codecs/amrwb/enc/inc/wb_vad_c.h
@@ -0,0 +1,109 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/*-------------------------------------------------------------------*
+ * WB_VAD_C.H *
+ *-------------------------------------------------------------------*
+ * Constants for Voice Activity Detection. *
+ *-------------------------------------------------------------------*/
+
+#ifndef __WB_VAD_C_H__
+#define __WB_VAD_C_H__
+
+#define FRAME_LEN 256 /* Length (samples) of the input frame */
+#define COMPLEN 12 /* Number of sub-bands used by VAD */
+
+#define UNIRSHFT 7 /* = log2(MAX_16/UNITY), UNITY = 256 */
+#define SCALE 128 /* (UNITY*UNITY)/512 */
+
+#define TONE_THR (Word16)(0.65*MAX_16) /* Threshold for tone detection */
+
+/* constants for speech level estimation */
+#define SP_EST_COUNT 80
+#define SP_ACTIVITY_COUNT 25
+#define ALPHA_SP_UP (Word16)((1.0 - 0.85)*MAX_16)
+#define ALPHA_SP_DOWN (Word16)((1.0 - 0.85)*MAX_16)
+
+#define NOM_LEVEL 2050 /* about -26 dBov Q15 */
+#define SPEECH_LEVEL_INIT NOM_LEVEL /* initial speech level */
+#define MIN_SPEECH_LEVEL1 (Word16)(NOM_LEVEL * 0.063) /* NOM_LEVEL -24 dB */
+#define MIN_SPEECH_LEVEL2 (Word16)(NOM_LEVEL * 0.2) /* NOM_LEVEL -14 dB */
+#define MIN_SPEECH_SNR 4096 /* 0 dB, lowest SNR estimation, Q12 */
+
+/* Time constants for background spectrum update */
+#define ALPHA_UP1 (Word16)((1.0 - 0.95)*MAX_16) /* Normal update, upwards: */
+#define ALPHA_DOWN1 (Word16)((1.0 - 0.936)*MAX_16) /* Normal update, downwards */
+#define ALPHA_UP2 (Word16)((1.0 - 0.985)*MAX_16) /* Forced update, upwards */
+#define ALPHA_DOWN2 (Word16)((1.0 - 0.943)*MAX_16) /* Forced update, downwards */
+#define ALPHA3 (Word16)((1.0 - 0.95)*MAX_16) /* Update downwards */
+#define ALPHA4 (Word16)((1.0 - 0.9)*MAX_16) /* For stationary estimation */
+#define ALPHA5 (Word16)((1.0 - 0.5)*MAX_16) /* For stationary estimation */
+
+/* Constants for VAD threshold */
+#define THR_MIN (Word16)(1.6*SCALE) /* Minimum threshold */
+#define THR_HIGH (Word16)(6*SCALE) /* Highest threshold */
+#define THR_LOW (Word16)(1.7*SCALE) /* Lowest threshold */
+#define NO_P1 31744 /* ilog2(1), Noise level for highest threshold */
+#define NO_P2 19786 /* ilog2(0.1*MAX_16), Noise level for lowest threshold */
+#define NO_SLOPE (Word16)(MAX_16*(float)(THR_LOW-THR_HIGH)/(float)(NO_P2-NO_P1))
+
+#define SP_CH_MIN (Word16)(-0.75*SCALE)
+#define SP_CH_MAX (Word16)(0.75*SCALE)
+#define SP_P1 22527 /* ilog2(NOM_LEVEL/4) */
+#define SP_P2 17832 /* ilog2(NOM_LEVEL*4) */
+#define SP_SLOPE (Word16)(MAX_16*(float)(SP_CH_MAX-SP_CH_MIN)/(float)(SP_P2-SP_P1))
+
+/* Constants for hangover length */
+#define HANG_HIGH 12 /* longest hangover */
+#define HANG_LOW 2 /* shortest hangover */
+#define HANG_P1 THR_LOW /* threshold for longest hangover */
+#define HANG_P2 (Word16)(4*SCALE) /* threshold for shortest hangover */
+#define HANG_SLOPE (Word16)(MAX_16*(float)(HANG_LOW-HANG_HIGH)/(float)(HANG_P2-HANG_P1))
+
+/* Constants for burst length */
+#define BURST_HIGH 8 /* longest burst length */
+#define BURST_LOW 3 /* shortest burst length */
+#define BURST_P1 THR_HIGH /* threshold for longest burst */
+#define BURST_P2 THR_LOW /* threshold for shortest burst */
+#define BURST_SLOPE (Word16)(MAX_16*(float)(BURST_LOW-BURST_HIGH)/(float)(BURST_P2-BURST_P1))
+
+/* Parameters for background spectrum recovery function */
+#define STAT_COUNT 20 /* threshold of stationary detection counter */
+
+#define STAT_THR_LEVEL 184 /* Threshold level for stationarity detection */
+#define STAT_THR 1000 /* Threshold for stationarity detection */
+
+/* Limits for background noise estimate */
+#define NOISE_MIN 40 /* minimum */
+#define NOISE_MAX 20000 /* maximum */
+#define NOISE_INIT 150 /* initial */
+
+/* Thresholds for signal power (now calculated on 2 frames) */
+#define VAD_POW_LOW (Word32)30000L /* If input power is lower than this, VAD is set to 0 */
+#define POW_TONE_THR (Word32)686080L /* If input power is lower,tone detection flag is ignored */
+
+/* Constants for the filter bank */
+#define COEFF3 13363 /* coefficient for the 3rd order filter */
+#define COEFF5_1 21955 /* 1st coefficient the for 5th order filter */
+#define COEFF5_2 6390 /* 2nd coefficient the for 5th order filter */
+#define F_5TH_CNT 5 /* number of 5th order filters */
+#define F_3TH_CNT 6 /* number of 3th order filters */
+
+#endif //__WB_VAD_C_H__
+
+
+
diff --git a/media/codecs/amrwb/enc/patent_disclaimer.txt b/media/codecs/amrwb/enc/patent_disclaimer.txt
new file mode 100644
index 0000000..b4bf11d
--- /dev/null
+++ b/media/codecs/amrwb/enc/patent_disclaimer.txt
@@ -0,0 +1,9 @@
+
+THIS IS NOT A GRANT OF PATENT RIGHTS.
+
+Google makes no representation or warranty that the codecs for which
+source code is made available hereunder are unencumbered by
+third-party patents. Those intending to use this source code in
+hardware or software products are advised that implementations of
+these codecs, including in open source software or shareware, may
+require patent licenses from the relevant patent holders.
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/Deemph_32_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/Deemph_32_opt.s
new file mode 100644
index 0000000..42ebc32
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/Deemph_32_opt.s
@@ -0,0 +1,104 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+
+@void Deemph_32(
+@ Word16 x_hi[], /* (i) : input signal (bit31..16) */
+@ Word16 x_lo[], /* (i) : input signal (bit15..4) */
+@ Word16 y[], /* (o) : output signal (x16) */
+@ Word16 mu, /* (i) Q15 : deemphasis factor */
+@ Word16 L, /* (i) : vector size */
+@ Word16 * mem /* (i/o) : memory (y[-1]) */
+@ )
+
+@x_hi RN R0
+@x_lo RN R1
+@y[] RN R2
+@*mem RN R3
+
+ .section .text
+ .global Deemph_32_asm
+
+Deemph_32_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ MOV r4, #2 @i=0
+ LDRSH r6, [r0], #2 @load x_hi[0]
+ LDRSH r7, [r1], #2 @load x_lo[0]
+ LDR r5, =22282 @r5---mu
+ MOV r11, #0x8000
+
+ @y[0]
+ MOV r10, r6, LSL #16 @L_tmp = x_hi[0]<<16
+ MOV r8, r5, ASR #1 @fac = mu >> 1
+ LDR r5, [r3]
+ ADD r12, r10, r7, LSL #4 @L_tmp += x_lo[0] << 4
+ MOV r10, r12, LSL #3 @L_tmp <<= 3
+ MUL r9, r5, r8
+ LDRSH r6, [r0], #2 @load x_hi[1]
+ QDADD r10, r10, r9
+ LDRSH r7, [r1], #2 @load x_lo[1]
+ MOV r12, r10, LSL #1 @L_tmp = L_mac(L_tmp, *mem, fac)
+ QADD r10, r12, r11
+ MOV r14, r10, ASR #16 @y[0] = round(L_tmp)
+
+
+ MOV r10, r6, LSL #16
+ ADD r12, r10, r7, LSL #4
+ STRH r14, [r2], #2 @update y[0]
+ MOV r10, r12, LSL #3
+ MUL r9, r14, r8
+ QDADD r10, r10, r9
+ MOV r12, r10, LSL #1
+ QADD r10, r12, r11
+ MOV r14, r10, ASR #16 @y[1] = round(L_tmp)
+
+LOOP:
+ LDRSH r6, [r0], #2 @load x_hi[]
+ LDRSH r7, [r1], #2
+ STRH r14, [r2], #2
+ MOV r10, r6, LSL #16
+ ADD r12, r10, r7, LSL #4
+ MUL r9, r14, r8
+ MOV r10, r12, LSL #3
+ QDADD r10, r10, r9
+ LDRSH r6, [r0], #2 @load x_hi[]
+ MOV r12, r10, LSL #1
+ QADD r10, r12, r11
+ LDRSH r7, [r1], #2
+ MOV r14, r10, ASR #16
+
+ MOV r10, r6, LSL #16
+ ADD r12, r10, r7, LSL #4
+ STRH r14, [r2], #2
+ MUL r9, r14, r8
+ MOV r10, r12, LSL #3
+ QDADD r10, r10, r9
+ ADD r4, r4, #2
+ MOV r12, r10, LSL #1
+ QADD r10, r12, r11
+ CMP r4, #64
+ MOV r14, r10, ASR #16
+
+ BLT LOOP
+ STR r14, [r3]
+ STRH r14, [r2]
+
+ LDMFD r13!, {r4 - r12, r15}
+
+ @ENDP
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/Dot_p_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/Dot_p_opt.s
new file mode 100644
index 0000000..3f060ff
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/Dot_p_opt.s
@@ -0,0 +1,80 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */
+@ Word16 x[], /* (i) 12bits: x vector */
+@ Word16 y[], /* (i) 12bits: y vector */
+@ Word16 lg, /* (i) : vector length */
+@ Word16 * exp /* (o) : exponent of result (0..+30) */
+@)
+@****************************************************************
+@ x[] --- r0
+@ y[] --- r1
+@ lg --- r2
+@ *exp --- r3
+
+ .section .text
+ .global Dot_product12_asm
+
+Dot_product12_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ MOV r4, #0 @ L_sum = 0
+ MOV r5, #0 @ i = 0
+
+LOOP:
+ LDR r6, [r0], #4
+ LDR r7, [r1], #4
+ LDR r8, [r0], #4
+ SMLABB r4, r6, r7, r4
+ LDR r9, [r1], #4
+ SMLATT r4, r6, r7, r4
+
+ LDR r6, [r0], #4
+ SMLABB r4, r8, r9, r4
+
+ LDR r7, [r1], #4
+ SMLATT r4, r8, r9, r4
+ LDR r8, [r0], #4
+
+ SMLABB r4, r6, r7, r4
+ LDR r9, [r1], #4
+ SMLATT r4, r6, r7, r4
+ ADD r5, r5, #8
+ SMLABB r4, r8, r9, r4
+ CMP r5, r2
+ SMLATT r4, r8, r9, r4
+ BLT LOOP
+
+ MOV r12, r4, LSL #1
+ ADD r12, r12, #1 @ L_sum = (L_sum << 1) + 1
+ MOV r4, r12
+
+ CMP r12, #0
+ RSBLT r4, r12, #0
+ CLZ r10, r4
+ SUB r10, r10, #1 @ sft = norm_l(L_sum)
+ MOV r0, r12, LSL r10 @ L_sum = L_sum << sft
+ RSB r11, r10, #30 @ *exp = 30 - sft
+ STRH r11, [r3]
+
+Dot_product12_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/Filt_6k_7k_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/Filt_6k_7k_opt.s
new file mode 100644
index 0000000..9cad479
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/Filt_6k_7k_opt.s
@@ -0,0 +1,188 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+
+@**********************************************************************/
+@void Filt_6k_7k(
+@ Word16 signal[], /* input: signal */
+@ Word16 lg, /* input: length of input */
+@ Word16 mem[] /* in/out: memory (size=30) */
+@)
+@******************************************************************
+@ r0 --- signal[]
+@ r1 --- lg
+@ r2 --- mem[]
+
+ .section .text
+ .global Filt_6k_7k_asm
+ .extern voAWB_Copy
+ .extern fir_6k_7k
+ .hidden fir_6k_7k
+
+Filt_6k_7k_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r13, r13, #240 @ x[L_SUBFR16k + (L_FIR - 1)]
+ MOV r8, r0 @ copy signal[] address
+ MOV r4, r1 @ copy lg address
+ MOV r5, r2 @ copy mem[] address
+
+ MOV r1, r13
+ MOV r0, r2
+ MOV r2, #30 @ L_FIR - 1
+ BL voAWB_Copy @ memcpy(x, mem, (L_FIR - 1)<<1)
+
+ ADR r3, Lable1 @ get fir_7k address
+ LDR r10, [r3]
+ ADD r10, r3
+
+ MOV r14, #0
+ MOV r3, r8 @ change myMemCopy to Copy, due to Copy will change r3 content
+ ADD r6, r13, #60 @ get x[L_FIR - 1] address
+ MOV r7, r3 @ get signal[i]
+LOOP1:
+ LDRSH r8, [r7], #2
+ LDRSH r9, [r7], #2
+ MOV r8, r8, ASR #2
+ MOV r9, r9, ASR #2
+ LDRSH r11, [r7], #2
+ LDRSH r12, [r7], #2
+ MOV r11, r11, ASR #2
+ MOV r12, r12, ASR #2
+ STRH r8, [r6], #2
+ STRH r9, [r6], #2
+ STRH r11, [r6], #2
+ STRH r12, [r6], #2
+ LDRSH r8, [r7], #2
+ LDRSH r9, [r7], #2
+ MOV r8, r8, ASR #2
+ MOV r9, r9, ASR #2
+ LDRSH r11, [r7], #2
+ LDRSH r12, [r7], #2
+ MOV r11, r11, ASR #2
+ MOV r12, r12, ASR #2
+ STRH r8, [r6], #2
+ STRH r9, [r6], #2
+ STRH r11, [r6], #2
+ STRH r12, [r6], #2
+ ADD r14, r14, #8
+ CMP r14, #80
+ BLT LOOP1
+
+
+ STR r5, [sp, #-4] @ PUSH r5 to stack
+
+ @ not use registers: r4, r10, r12, r14, r5
+ MOV r4, r13
+ MOV r5, #0 @ i = 0
+LOOP2:
+ LDR r0, [r10]
+
+ LDRSH r1, [r4] @ load x[i]
+ LDRSH r2, [r4, #60] @ load x[i + 30]
+ LDRSH r6, [r4, #2] @ load x[i + 1]
+ LDRSH r7, [r4, #58] @ load x[i + 29]
+ ADD r1, r1, r2 @ x[i] + x[i + 30]
+ ADD r6, r6, r7 @ x[i + 1] + x[i + 29]
+ LDRSH r8, [r4, #4] @ load x[i + 2]
+ LDRSH r9, [r4, #56] @ load x[i + 28]
+
+ SMULBB r14, r1, r0 @ (x[i] + x[i + 30]) * fir_7k[0]
+ ADD r8, r8, r9 @ x[i + 2] + x[i + 28]
+ SMLABT r14, r6, r0, r14 @ (x[i + 1] + x[i + 29]) * fir_7k[1]
+
+ LDR r0, [r10, #4]
+ LDRSH r1, [r4, #6] @ load x[i+3]
+ LDRSH r2, [r4, #54] @ load x[i+27]
+ LDRSH r6, [r4, #8] @ load x[i+4]
+ LDRSH r7, [r4, #52] @ load x[i+26]
+ ADD r1, r1, r2 @ x[i+3] + x[i+27]
+ ADD r6, r6, r7 @ x[i+4] + x[i+26]
+ SMLABB r14, r8, r0, r14 @ (x[i + 2] + x[i + 28]) * fir_7k[2]
+ LDRSH r8, [r4, #10] @ load x[i+5]
+ LDRSH r9, [r4, #50] @ load x[i+25]
+ SMLABT r14, r1, r0, r14 @ (x[i+3] + x[i+27]) * fir_7k[3]
+ ADD r8, r8, r9 @ x[i+5] + x[i+25]
+
+ LDR r0, [r10, #8]
+ LDRSH r1, [r4, #12] @ x[i+6]
+ LDRSH r2, [r4, #48] @ x[i+24]
+ SMLABB r14, r6, r0, r14 @ (x[i+4] + x[i+26]) * fir_7k[4]
+ LDRSH r6, [r4, #14] @ x[i+7]
+ LDRSH r7, [r4, #46] @ x[i+23]
+ SMLABT r14, r8, r0, r14 @ (x[i+5] + x[i+25]) * fir_7k[5]
+ LDR r0, [r10, #12]
+ ADD r1, r1, r2 @ (x[i+6] + x[i+24])
+ ADD r6, r6, r7 @ (x[i+7] + x[i+23])
+ SMLABB r14, r1, r0, r14 @ (x[i+6] + x[i+24]) * fir_7k[6]
+ LDRSH r8, [r4, #16] @ x[i+8]
+ LDRSH r9, [r4, #44] @ x[i+22]
+ SMLABT r14, r6, r0, r14 @ (x[i+7] + x[i+23]) * fir_7k[7]
+ LDR r0, [r10, #16]
+ LDRSH r1, [r4, #18] @ x[i+9]
+ LDRSH r2, [r4, #42] @ x[i+21]
+ LDRSH r6, [r4, #20] @ x[i+10]
+ LDRSH r7, [r4, #40] @ x[i+20]
+ ADD r8, r8, r9 @ (x[i+8] + x[i+22])
+ ADD r1, r1, r2 @ (x[i+9] + x[i+21])
+ ADD r6, r6, r7 @ (x[i+10] + x[i+20])
+ SMLABB r14, r8, r0, r14 @ (x[i+8] + x[i+22]) * fir_7k[8]
+ LDRSH r8, [r4, #22] @ x[i+11]
+ LDRSH r9, [r4, #38] @ x[i+19]
+ SMLABT r14, r1, r0, r14 @ (x[i+9] + x[i+21]) * fir_7k[9]
+ LDR r0, [r10, #20]
+ LDRSH r1, [r4, #24] @ x[i+12]
+ LDRSH r2, [r4, #36] @ x[i+18]
+ SMLABB r14, r6, r0, r14 @ (x[i+10] + x[i+20]) * fir_7k[10]
+ LDRSH r6, [r4, #26] @ x[i+13]
+ ADD r8, r8, r9 @ (x[i+11] + x[i+19])
+ LDRSH r7, [r4, #34] @ x[i+17]
+ SMLABT r14, r8, r0, r14 @ (x[i+11] + x[i+19]) * fir_7k[11]
+ LDR r0, [r10, #24]
+ ADD r1, r1, r2 @ x[i+12] + x[i+18]
+ LDRSH r8, [r4, #28] @ x[i+14]
+ SMLABB r14, r1, r0, r14 @ (x[i+12] + x[i+18]) * fir_7k[12]
+ ADD r6, r6, r7 @ (x[i+13] + x[i+17])
+ LDRSH r9, [r4, #32] @ x[i+16]
+ SMLABT r14, r6, r0, r14 @ (x[i+13] + x[i+17]) * fir_7k[13]
+ LDR r0, [r10, #28]
+ ADD r8, r8, r9 @ (x[i+14] + x[i+16])
+ LDRSH r1, [r4, #30] @ x[i+15]
+ SMLABB r14, r8, r0, r14 @ (x[i+14] + x[i+16]) * fir_7k[14]
+ SMLABT r14, r1, r0, r14 @ x[i+15] * fir_7k[15]
+
+ ADD r5, r5, #1
+ ADD r14, r14, #0x4000
+ ADD r4, r4, #2
+ MOV r1, r14, ASR #15
+ CMP r5, #80
+ STRH r1, [r3], #2 @signal[i] = (L_tmp + 0x4000) >> 15
+ BLT LOOP2
+
+ LDR r1, [sp, #-4] @mem address
+ ADD r0, r13, #160 @x + lg
+ MOV r2, #30
+ BL voAWB_Copy
+
+Filt_6k_7k_end:
+ ADD r13, r13, #240
+ LDMFD r13!, {r4 - r12, r15}
+
+Lable1:
+ .word fir_6k_7k-Lable1
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/Norm_Corr_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/Norm_Corr_opt.s
new file mode 100644
index 0000000..ffedbde
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/Norm_Corr_opt.s
@@ -0,0 +1,231 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+
+@static void Norm_Corr (Word16 exc[], /* (i) : excitation buffer */
+@ Word16 xn[], /* (i) : target vector */
+@ Word16 h[], /* (i) Q15 : impulse response of synth/wgt filters */
+@ Word16 L_subfr, /* (i) : sub-frame length */
+@ Word16 t_min, /* (i) : minimum value of pitch lag. */
+@ Word16 t_max, /* (i) : maximum value of pitch lag. */
+@ Word16 corr_norm[]) /* (o) Q15 : normalized correlation */
+@
+
+@ r0 --- exc[]
+@ r1 --- xn[]
+@ r2 --- h[]
+@ r3 --- L_subfr
+@ r4 --- t_min
+@ r5 --- t_max
+@ r6 --- corr_norm[]
+
+
+ .section .text
+ .global Norm_corr_asm
+ .extern Convolve_asm
+ .extern Isqrt_n
+@******************************
+@ constant
+@******************************
+.equ EXC , 0
+.equ XN , 4
+.equ H , 8
+.equ L_SUBFR , 12
+.equ voSTACK , 172
+.equ T_MIN , 212
+.equ T_MAX , 216
+.equ CORR_NORM , 220
+
+Norm_corr_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r13, r13, #voSTACK
+
+ ADD r8, r13, #20 @get the excf[L_SUBFR]
+ LDR r4, [r13, #T_MIN] @get t_min
+ RSB r11, r4, #0 @k = -t_min
+ ADD r5, r0, r11, LSL #1 @get the &exc[k]
+
+ @transfer Convolve function
+ STMFD sp!, {r0 - r3}
+ MOV r0, r5
+ MOV r1, r2
+ MOV r2, r8 @r2 --- excf[]
+ BL Convolve_asm
+ LDMFD sp!, {r0 - r3}
+
+ @ r8 --- excf[]
+
+ MOV r14, r1 @copy xn[] address
+ MOV r5, #64
+ MOV r6, #0 @L_tmp = 0
+ MOV r7, #1
+
+LOOP1:
+ LDR r9, [r14], #4
+ LDR r10, [r14], #4
+ LDR r11, [r14], #4
+ LDR r12, [r14], #4
+ SMLABB r6, r9, r9, r6 @L_tmp += (xn[i] * xn[i])
+ SMLATT r6, r9, r9, r6 @L_tmp += (xn[i+1] * xn[i+1])
+ SMLABB r6, r10, r10, r6
+ SMLATT r6, r10, r10, r6
+ SMLABB r6, r11, r11, r6
+ SMLATT r6, r11, r11, r6
+ SMLABB r6, r12, r12, r6
+ SMLATT r6, r12, r12, r6
+ SUBS r5, r5, #8
+ BNE LOOP1
+
+ ADD r9, r7, r6, LSL #1 @L_tmp = (L_tmp << 1) + 1
+ CLZ r7, r9
+ SUB r6, r7, #1 @exp = norm_l(L_tmp)
+ RSB r7, r6, #32 @exp = 32 - exp
+ MOV r6, r7, ASR #1
+ RSB r7, r6, #0 @scale = -(exp >> 1)
+
+ @loop for every possible period
+ @for(t = t_min@ t <= t_max@ t++)
+ @r7 --- scale r4 --- t_min r8 --- excf[]
+
+LOOPFOR:
+ MOV r5, #0 @L_tmp = 0
+ MOV r6, #0 @L_tmp1 = 0
+ MOV r9, #64
+ MOV r12, r1 @copy of xn[]
+ ADD r14, r13, #20 @copy of excf[]
+ MOV r8, #0x8000
+
+LOOPi:
+ LDR r11, [r14], #4 @load excf[i], excf[i+1]
+ LDR r10, [r12], #4 @load xn[i], xn[i+1]
+ SMLABB r6, r11, r11, r6 @L_tmp1 += excf[i] * excf[i]
+ SMLATT r6, r11, r11, r6 @L_tmp1 += excf[i+1] * excf[i+1]
+ SMLABB r5, r10, r11, r5 @L_tmp += xn[i] * excf[i]
+ SMLATT r5, r10, r11, r5 @L_tmp += xn[i+1] * excf[i+1]
+ LDR r11, [r14], #4 @load excf[i+2], excf[i+3]
+ LDR r10, [r12], #4 @load xn[i+2], xn[i+3]
+ SMLABB r6, r11, r11, r6
+ SMLATT r6, r11, r11, r6
+ SMLABB r5, r10, r11, r5
+ SMLATT r5, r10, r11, r5
+ SUBS r9, r9, #4
+ BNE LOOPi
+
+ @r5 --- L_tmp, r6 --- L_tmp1
+ MOV r10, #1
+ ADD r5, r10, r5, LSL #1 @L_tmp = (L_tmp << 1) + 1
+ ADD r6, r10, r6, LSL #1 @L_tmp1 = (L_tmp1 << 1) + 1
+
+ CLZ r10, r5
+ CMP r5, #0
+ RSBLT r11, r5, #0
+ CLZLT r10, r11
+ SUB r10, r10, #1 @exp = norm_l(L_tmp)
+
+ MOV r5, r5, LSL r10 @L_tmp = (L_tmp << exp)
+ RSB r10, r10, #30 @exp_corr = 30 - exp
+ MOV r11, r5, ASR #16 @corr = extract_h(L_tmp)
+
+ CLZ r5, r6
+ SUB r5, r5, #1
+ MOV r6, r6, LSL r5 @L_tmp = (L_tmp1 << exp)
+ RSB r5, r5, #30 @exp_norm = 30 - exp
+
+ @r10 --- exp_corr, r11 --- corr
+ @r6 --- L_tmp, r5 --- exp_norm
+
+ @Isqrt_n(&L_tmp, &exp_norm)
+
+ MOV r14, r0
+ MOV r12, r1
+
+ STMFD sp!, {r0 - r4, r7 - r12, r14}
+ ADD r1, sp, #4
+ ADD r0, sp, #0
+ STR r6, [sp]
+ STRH r5, [sp, #4]
+ BL Isqrt_n
+ LDR r6, [sp]
+ LDRSH r5, [sp, #4]
+ LDMFD sp!, {r0 - r4, r7 - r12, r14}
+ MOV r0, r14
+ MOV r1, r12
+
+
+ MOV r6, r6, ASR #16 @norm = extract_h(L_tmp)
+ MUL r12, r6, r11
+ ADD r12, r12, r12 @L_tmp = vo_L_mult(corr, norm)
+
+ ADD r6, r10, r5
+ ADD r6, r6, r7 @exp_corr + exp_norm + scale
+
+ CMP r6, #0
+ RSBLT r6, r6, #0
+ MOVLT r12, r12, ASR r6
+ MOVGT r12, r12, LSL r6 @L_tmp = L_shl(L_tmp, exp_corr + exp_norm + scale)
+
+ ADD r12, r12, r8
+ MOV r12, r12, ASR #16 @vo_round(L_tmp)
+
+ LDR r5, [r13, #CORR_NORM] @ get corr_norm address
+ LDR r6, [r13, #T_MAX] @ get t_max
+ ADD r10, r5, r4, LSL #1 @ get corr_norm[t] address
+ STRH r12, [r10] @ corr_norm[t] = vo_round(L_tmp)
+
+ CMP r4, r6
+ BEQ Norm_corr_asm_end
+
+ ADD r4, r4, #1 @ t_min ++
+
+ RSB r5, r4, #0 @ k
+
+ MOV r6, #63 @ i = 63
+ MOV r8, r0 @ exc[]
+ MOV r9, r2 @ h[]
+ ADD r10, r13, #20 @ excf[]
+
+ ADD r8, r8, r5, LSL #1 @ exc[k] address
+ ADD r9, r9, r6, LSL #1 @ h[i] address
+ ADD r10, r10, r6, LSL #1 @ excf[i] address
+ LDRSH r11, [r8] @ tmp = exc[k]
+
+LOOPK:
+ LDRSH r8, [r9], #-2 @ load h[i]
+ LDRSH r12, [r10, #-2] @ load excf[i - 1]
+ MUL r14, r11, r8
+ MOV r8, r14, ASR #15
+ ADD r14, r8, r12
+ STRH r14, [r10], #-2
+ SUBS r6, r6, #1
+ BGT LOOPK
+
+ LDRSH r8, [r9] @ load h[0]
+ MUL r14, r11, r8
+ LDR r6, [r13, #T_MAX] @ get t_max
+ MOV r8, r14, ASR #15
+ STRH r8, [r10]
+
+ CMP r4, r6
+ BLE LOOPFOR
+
+Norm_corr_asm_end:
+
+ ADD r13, r13, #voSTACK
+ LDMFD r13!, {r4 - r12, r15}
+
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/Syn_filt_32_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/Syn_filt_32_opt.s
new file mode 100644
index 0000000..9743b9e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/Syn_filt_32_opt.s
@@ -0,0 +1,226 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Syn_filt_32(
+@ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+@ Word16 m, /* (i) : order of LP filter */
+@ Word16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
+@ Word16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
+@ Word16 sig_hi[], /* (o) /16 : synthesis high */
+@ Word16 sig_lo[], /* (o) /16 : synthesis low */
+@ Word16 lg /* (i) : size of filtering */
+@)
+@***************************************************************
+@
+@ a[] --- r0
+@ m --- r1
+@ exc[] --- r2
+@ Qnew --- r3
+@ sig_hi[] --- r4
+@ sig_lo[] --- r5
+@ lg --- r6
+
+ .section .text
+ .global Syn_filt_32_asm
+
+Syn_filt_32_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ LDR r4, [r13, #40] @ get sig_hi[] address
+ LDR r5, [r13, #44] @ get sig_lo[] address
+
+ LDRSH r6, [r0] @ load Aq[0]
+ ADD r7, r3, #4 @ 4 + Q_new
+ MOV r3, r6, ASR r7 @ a0 = Aq[0] >> (4 + Q_new)
+
+ LDR r14, =0xffff
+ LDRSH r6, [r0, #2] @ load Aq[1]
+ LDRSH r7, [r0, #4] @ load Aq[2]
+ LDRSH r8, [r0, #6] @ load Aq[3]
+ LDRSH r9, [r0, #8] @ load Aq[4]
+ AND r6, r6, r14
+ AND r8, r8, r14
+ ORR r10, r6, r7, LSL #16 @ Aq[2] -- Aq[1]
+ ORR r11, r8, r9, LSL #16 @ Aq[4] -- Aq[3]
+ STR r10, [r13, #-4]
+ STR r11, [r13, #-8]
+
+ LDRSH r6, [r0, #10] @ load Aq[5]
+ LDRSH r7, [r0, #12] @ load Aq[6]
+ LDRSH r8, [r0, #14] @ load Aq[7]
+ LDRSH r9, [r0, #16] @ load Aq[8]
+ AND r6, r6, r14
+ AND r8, r8, r14
+ ORR r10, r6, r7, LSL #16 @ Aq[6] -- Aq[5]
+ ORR r11, r8, r9, LSL #16 @ Aq[8] -- Aq[7]
+ STR r10, [r13, #-12]
+ STR r11, [r13, #-16]
+
+ LDRSH r6, [r0, #18] @ load Aq[9]
+ LDRSH r7, [r0, #20] @ load Aq[10]
+ LDRSH r8, [r0, #22] @ load Aq[11]
+ LDRSH r9, [r0, #24] @ load Aq[12]
+ AND r6, r6, r14
+ AND r8, r8, r14
+ ORR r10, r6, r7, LSL #16 @ Aq[10] -- Aq[9]
+ ORR r11, r8, r9, LSL #16 @ Aq[12] -- Aq[11]
+ STR r10, [r13, #-20]
+ STR r11, [r13, #-24]
+
+ LDRSH r6, [r0, #26] @ load Aq[13]
+ LDRSH r7, [r0, #28] @ load Aq[14]
+ LDRSH r8, [r0, #30] @ load Aq[15]
+ LDRSH r9, [r0, #32] @ load Aq[16]
+ AND r6, r6, r14
+ AND r8, r8, r14
+ ORR r10, r6, r7, LSL #16 @ Aq[14] -- Aq[13]
+ ORR r11, r8, r9, LSL #16 @ Aq[16] -- Aq[15]
+ STR r10, [r13, #-28]
+ STR r11, [r13, #-32]
+
+ MOV r8, #0 @ i = 0
+
+LOOP:
+ LDRSH r6, [r5, #-2] @ load sig_lo[i-1]
+ LDRSH r7, [r5, #-4] @ load sig_lo[i-2]
+
+ LDR r11, [r13, #-4] @ Aq[2] -- Aq[1]
+ LDRSH r9, [r5, #-6] @ load sig_lo[i-3]
+ LDRSH r10, [r5, #-8] @ load sig_lo[i-4]
+
+ SMULBB r12, r6, r11 @ sig_lo[i-1] * Aq[1]
+
+ LDRSH r6, [r5, #-10] @ load sig_lo[i-5]
+ SMLABT r12, r7, r11, r12 @ sig_lo[i-2] * Aq[2]
+ LDR r11, [r13, #-8] @ Aq[4] -- Aq[3]
+ LDRSH r7, [r5, #-12] @ load sig_lo[i-6]
+ SMLABB r12, r9, r11, r12 @ sig_lo[i-3] * Aq[3]
+ LDRSH r9, [r5, #-14] @ load sig_lo[i-7]
+ SMLABT r12, r10, r11, r12 @ sig_lo[i-4] * Aq[4]
+ LDR r11, [r13, #-12] @ Aq[6] -- Aq[5]
+ LDRSH r10, [r5, #-16] @ load sig_lo[i-8]
+ SMLABB r12, r6, r11, r12 @ sig_lo[i-5] * Aq[5]
+ LDRSH r6, [r5, #-18] @ load sig_lo[i-9]
+ SMLABT r12, r7, r11, r12 @ sig_lo[i-6] * Aq[6]
+ LDR r11, [r13, #-16] @ Aq[8] -- Aq[7]
+ LDRSH r7, [r5, #-20] @ load sig_lo[i-10]
+ SMLABB r12, r9, r11, r12 @ sig_lo[i-7] * Aq[7]
+ LDRSH r9, [r5, #-22] @ load sig_lo[i-11]
+ SMLABT r12, r10, r11, r12 @ sig_lo[i-8] * Aq[8]
+ LDR r11, [r13, #-20] @ Aq[10] -- Aq[9]
+ LDRSH r10,[r5, #-24] @ load sig_lo[i-12]
+ SMLABB r12, r6, r11, r12 @ sig_lo[i-9] * Aq[9]
+ LDRSH r6, [r5, #-26] @ load sig_lo[i-13]
+ SMLABT r12, r7, r11, r12 @ sig_lo[i-10] * Aq[10]
+ LDR r11, [r13, #-24] @ Aq[12] -- Aq[11]
+ LDRSH r7, [r5, #-28] @ load sig_lo[i-14]
+ SMLABB r12, r9, r11, r12 @ sig_lo[i-11] * Aq[11]
+ LDRSH r9, [r5, #-30] @ load sig_lo[i-15]
+ SMLABT r12, r10, r11, r12 @ sig_lo[i-12] * Aq[12]
+
+ LDR r11, [r13, #-28] @ Aq[14] -- Aq[13]
+ LDRSH r10, [r5, #-32] @ load sig_lo[i-16]
+ SMLABB r12, r6, r11, r12 @ sig_lo[i-13] * Aq[13]
+ SMLABT r12, r7, r11, r12 @ sig_lo[i-14] * Aq[14]
+
+ LDR r11, [r13, #-32] @ Aq[16] -- Aq[15]
+ LDRSH r6, [r2],#2 @ load exc[i]
+ SMLABB r12, r9, r11, r12 @ sig_lo[i-15] * Aq[15]
+ SMLABT r12, r10, r11, r12 @ sig_lo[i-16] * Aq[16]
+ MUL r7, r6, r3 @ exc[i] * a0
+ RSB r14, r12, #0 @ L_tmp
+ MOV r14, r14, ASR #11 @ L_tmp >>= 11
+ ADD r14, r14, r7, LSL #1 @ L_tmp += (exc[i] * a0) << 1
+
+
+ LDRSH r6, [r4, #-2] @ load sig_hi[i-1]
+ LDRSH r7, [r4, #-4] @ load sig_hi[i-2]
+
+ LDR r11, [r13, #-4] @ Aq[2] -- Aq[1]
+ LDRSH r9, [r4, #-6] @ load sig_hi[i-3]
+ LDRSH r10, [r4, #-8] @ load sig_hi[i-4]
+ SMULBB r12, r6, r11 @ sig_hi[i-1] * Aq[1]
+ LDRSH r6, [r4, #-10] @ load sig_hi[i-5]
+ SMLABT r12, r7, r11, r12 @ sig_hi[i-2] * Aq[2]
+
+ LDR r11, [r13, #-8] @ Aq[4] -- Aq[3]
+ LDRSH r7, [r4, #-12] @ load sig_hi[i-6]
+
+ SMLABB r12, r9, r11, r12 @ sig_hi[i-3] * Aq[3]
+ LDRSH r9, [r4, #-14] @ load sig_hi[i-7]
+
+ SMLABT r12, r10, r11, r12 @ sig_hi[i-4] * Aq[4]
+
+ LDR r11, [r13, #-12] @ Aq[6] -- Aq[5]
+ LDRSH r10, [r4, #-16] @ load sig_hi[i-8]
+
+ SMLABB r12, r6, r11, r12 @ sig_hi[i-5] * Aq[5]
+
+ LDRSH r6, [r4, #-18] @ load sig_hi[i-9]
+ SMLABT r12, r7, r11, r12 @ sig_hi[i-6] * Aq[6]
+
+ LDR r11, [r13, #-16] @ Aq[8] -- Aq[7]
+ LDRSH r7, [r4, #-20] @ load sig_hi[i-10]
+
+ SMLABB r12, r9, r11, r12 @ sig_hi[i-7] * Aq[7]
+
+ LDRSH r9, [r4, #-22] @ load sig_hi[i-11]
+
+ SMLABT r12, r10, r11, r12 @ sig_hi[i-8] * Aq[8]
+
+ LDR r11, [r13, #-20] @ Aq[10] -- Aq[9]
+ LDRSH r10,[r4, #-24] @ load sig_hi[i-12]
+
+ SMLABB r12, r6, r11, r12 @ sig_hi[i-9] * Aq[9]
+ LDRSH r6, [r4, #-26] @ load sig_hi[i-13]
+ SMLABT r12, r7, r11, r12 @ sig_hi[i-10] * Aq[10]
+
+ LDR r11, [r13, #-24] @ Aq[12] -- Aq[11]
+ LDRSH r7, [r4, #-28] @ load sig_hi[i-14]
+ SMLABB r12, r9, r11, r12 @ sig_hi[i-11] * Aq[11]
+ LDRSH r9, [r4, #-30] @ load sig_hi[i-15]
+ SMLABT r12, r10, r11, r12 @ sig_hi[i-12] * Aq[12]
+
+ LDR r11, [r13, #-28] @ Aq[14] -- Aq[13]
+ LDRSH r10, [r4, #-32] @ load sig_hi[i-16]
+ SMLABB r12, r6, r11, r12 @ sig_hi[i-13] * Aq[13]
+ SMLABT r12, r7, r11, r12 @ sig_hi[i-14] * Aq[14]
+
+ LDR r11, [r13, #-32] @ Aq[16] -- Aq[15]
+ SMLABB r12, r9, r11, r12 @ sig_hi[i-15] * Aq[15]
+ SMLABT r12, r10, r11, r12 @ sig_hi[i-16] * Aq[16]
+ ADD r6, r12, r12 @ r12 << 1
+ SUB r14, r14, r6
+ MOV r14, r14, LSL #3 @ L_tmp <<=3
+
+ MOV r7, r14, ASR #16 @ L_tmp >> 16
+
+ MOV r14, r14, ASR #4 @ L_tmp >>=4
+ STRH r7, [r4], #2 @ sig_hi[i] = L_tmp >> 16
+ SUB r9, r14, r7, LSL #12 @ sig_lo[i] = L_tmp - (sig_hi[i] << 12)
+
+ ADD r8, r8, #1
+ STRH r9, [r5], #2
+ CMP r8, #64
+ BLT LOOP
+
+Syn_filt_32_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/convolve_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/convolve_opt.s
new file mode 100644
index 0000000..cd75179
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/convolve_opt.s
@@ -0,0 +1,186 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+
+
+@*void Convolve (
+@* Word16 x[], /* (i) : input vector */
+@* Word16 h[], /* (i) : impulse response */
+@* Word16 y[], /* (o) : output vector */
+@* Word16 L /* (i) : vector size */
+@*)
+@ r0 --- x[]
+@ r1 --- h[]
+@ r2 --- y[]
+@ r3 --- L
+
+ .section .text
+ .global Convolve_asm
+
+Convolve_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ MOV r3, #0 @ n
+ MOV r11, #0x8000
+
+LOOP:
+ ADD r4, r1, r3, LSL #1 @ tmpH address
+ ADD r5, r3, #1 @ i = n + 1
+ MOV r6, r0 @ tmpX = x
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ SUB r5, r5, #1
+ MUL r8, r9, r10
+
+LOOP1:
+ CMP r5, #0
+ BLE L1
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ MLA r8, r12, r14, r8
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ SUBS r5, r5, #4
+ MLA r8, r12, r14, r8
+
+ B LOOP1
+
+L1:
+
+ ADD r5, r11, r8, LSL #1
+ MOV r5, r5, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r5, [r2], #2 @y[n]
+
+
+ ADD r4, r1, r3, LSL #1 @tmpH address
+ ADD r5, r3, #1
+ MOV r6, r0
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2
+ LDRSH r12, [r6], #2
+ LDRSH r14, [r4], #-2
+
+ MUL r8, r9, r10
+ SUB r5, r5, #2
+ MLA r8, r12, r14, r8
+
+LOOP2:
+ CMP r5, #0
+ BLE L2
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ MLA r8, r12, r14, r8
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ SUBS r5, r5, #4
+ MLA r8, r12, r14, r8
+ B LOOP2
+
+L2:
+ ADD r8, r11, r8, LSL #1
+ MOV r8, r8, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r8, [r2], #2 @y[n]
+
+ ADD r4, r1, r3, LSL #1
+ ADD r5, r3, #1
+ MOV r6, r0
+ LDRSH r9, [r6], #2
+ LDRSH r10, [r4], #-2
+ LDRSH r12, [r6], #2
+ LDRSH r14, [r4], #-2
+ MUL r8, r9, r10
+ LDRSH r9, [r6], #2
+ LDRSH r10, [r4], #-2
+ MLA r8, r12, r14, r8
+ SUB r5, r5, #3
+ MLA r8, r9, r10, r8
+
+LOOP3:
+ CMP r5, #0
+ BLE L3
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ MLA r8, r12, r14, r8
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ SUBS r5, r5, #4
+ MLA r8, r12, r14, r8
+ B LOOP3
+
+L3:
+ ADD r8, r11, r8, LSL #1
+ MOV r8, r8, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r8, [r2], #2 @y[n]
+
+ ADD r5, r3, #1 @ i = n + 1
+ ADD r4, r1, r3, LSL #1 @ tmpH address
+ MOV r6, r0
+ MOV r8, #0
+
+LOOP4:
+ CMP r5, #0
+ BLE L4
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ MLA r8, r12, r14, r8
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2 @ *tmpH--
+ LDRSH r12, [r6], #2 @ *tmpX++
+ LDRSH r14, [r4], #-2 @ *tmpH--
+ MLA r8, r9, r10, r8
+ SUBS r5, r5, #4
+ MLA r8, r12, r14, r8
+ B LOOP4
+L4:
+ ADD r5, r11, r8, LSL #1
+ MOV r5, r5, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r5, [r2], #2 @y[n]
+
+ CMP r3, #64
+ BLT LOOP
+
+Convolve_asm_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/cor_h_vec_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/cor_h_vec_opt.s
new file mode 100644
index 0000000..eedccc7
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/cor_h_vec_opt.s
@@ -0,0 +1,151 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@static void cor_h_vec_012(
+@ Word16 h[], /* (i) scaled impulse response */
+@ Word16 vec[], /* (i) scaled vector (/8) to correlate with h[] */
+@ Word16 track, /* (i) track to use */
+@ Word16 sign[], /* (i) sign vector */
+@ Word16 rrixix[][NB_POS], /* (i) correlation of h[x] with h[x] */
+@ Word16 cor_1[], /* (o) result of correlation (NB_POS elements) */
+@ Word16 cor_2[] /* (o) result of correlation (NB_POS elements) */
+@)
+@r0 ---- h[]
+@r1 ---- vec[]
+@r2 ---- track
+@r3 ---- sign[]
+@r4 ---- rrixix[][NB_POS]
+@r5 ---- cor_1[]
+@r6 ---- cor_2[]
+
+
+ .section .text
+ .global cor_h_vec_012_asm
+
+cor_h_vec_012_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ LDR r4, [r13, #40] @load rrixix[][NB_POS]
+ ADD r7, r4, r2, LSL #5 @r7 --- p0 = rrixix[track]
+ MOV r4, #0 @i=0
+
+ @r0 --- h[], r1 --- vec[], r2 --- pos
+ @r3 --- sign[], r4 --- i, r7 --- p0
+LOOPi:
+ MOV r5, #0 @L_sum1 = 0
+ MOV r6, #0 @L_sum2 = 0
+ ADD r9, r1, r2, LSL #1 @p2 = &vec[pos]
+ MOV r10, r0 @p1 = h
+ RSB r11, r2, #62 @j=62-pos
+
+LOOPj1:
+ LDRSH r12, [r10], #2
+ LDRSH r8, [r9], #2
+ LDRSH r14, [r9]
+ SUBS r11, r11, #1
+ MLA r5, r12, r8, r5
+ MLA r6, r12, r14, r6
+ BGE LOOPj1
+
+ LDRSH r12, [r10], #2 @*p1++
+ MOV r6, r6, LSL #2 @L_sum2 = (L_sum2 << 2)
+ MLA r5, r12, r14, r5
+ MOV r14, #0x8000
+ MOV r5, r5, LSL #2 @L_sum1 = (L_sum1 << 2)
+ ADD r10, r6, r14
+ ADD r9, r5, r14
+ MOV r5, r9, ASR #16
+ MOV r6, r10, ASR #16
+ ADD r9, r3, r2, LSL #1 @address of sign[pos]
+ ADD r8, r7, #32
+ LDRSH r10, [r9], #2 @sign[pos]
+ LDRSH r11, [r9] @sign[pos + 1]
+ MUL r12, r5, r10
+ MUL r14, r6, r11
+ MOV r5, r12, ASR #15
+ MOV r6, r14, ASR #15
+ LDR r9, [r13, #44]
+ LDR r12, [r13, #48]
+ LDRSH r10, [r7], #2 @*p0++
+ LDRSH r11, [r8] @*p3++
+ ADD r9, r9, r4, LSL #1
+ ADD r12, r12, r4, LSL #1
+ ADD r5, r5, r10
+ ADD r6, r6, r11
+ STRH r5, [r9]
+ STRH r6, [r12]
+
+ ADD r2, r2, #4
+
+ MOV r5, #0 @L_sum1 = 0
+ MOV r6, #0 @L_sum2 = 0
+ ADD r9, r1, r2, LSL #1 @p2 = &vec[pos]
+ MOV r10, r0 @p1 = h
+ RSB r11, r2, #62 @j=62-pos
+ ADD r4, r4, #1 @i++
+
+LOOPj2:
+ LDRSH r12, [r10], #2
+ LDRSH r8, [r9], #2
+ LDRSH r14, [r9]
+ SUBS r11, r11, #1
+ MLA r5, r12, r8, r5
+ MLA r6, r12, r14, r6
+ BGE LOOPj2
+
+ LDRSH r12, [r10], #2 @*p1++
+ MOV r6, r6, LSL #2 @L_sum2 = (L_sum2 << 2)
+ MLA r5, r12, r14, r5
+ MOV r14, #0x8000
+ MOV r5, r5, LSL #2 @L_sum1 = (L_sum1 << 2)
+ ADD r10, r6, r14
+ ADD r9, r5, r14
+
+ MOV r5, r9, ASR #16
+ MOV r6, r10, ASR #16
+ ADD r9, r3, r2, LSL #1 @address of sign[pos]
+ ADD r8, r7, #32
+ LDRSH r10, [r9], #2 @sign[pos]
+ LDRSH r11, [r9] @sign[pos + 1]
+ MUL r12, r5, r10
+ MUL r14, r6, r11
+ MOV r5, r12, ASR #15
+ MOV r6, r14, ASR #15
+ LDR r9, [r13, #44]
+ LDR r12, [r13, #48]
+ LDRSH r10, [r7], #2 @*p0++
+ LDRSH r11, [r8] @*p3++
+ ADD r9, r9, r4, LSL #1
+ ADD r12, r12, r4, LSL #1
+ ADD r5, r5, r10
+ ADD r6, r6, r11
+ STRH r5, [r9]
+ STRH r6, [r12]
+ ADD r4, r4, #1 @i+1
+ ADD r2, r2, #4 @pos += STEP
+ CMP r4, #16
+
+ BLT LOOPi
+
+the_end:
+ LDMFD r13!, {r4 - r12, r15}
+
+ @ENDFUNC
+ .end
+
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/pred_lt4_1_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/pred_lt4_1_opt.s
new file mode 100644
index 0000000..60c2a47
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/pred_lt4_1_opt.s
@@ -0,0 +1,464 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Pred_lt4(
+@ Word16 exc[], /* in/out: excitation buffer */
+@ Word16 T0, /* input : integer pitch lag */
+@ Word16 frac, /* input : fraction of lag */
+@ Word16 L_subfr /* input : subframe size */
+@ )
+
+@******************************
+@ ARM Register
+@******************************
+@ r0 --- exc[]
+@ r1 --- T0
+@ r2 --- frac
+@ r3 --- L_subfr
+
+ .section .text
+ .global pred_lt4_asm
+ .extern inter4_2
+ .hidden inter4_2
+
+pred_lt4_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ RSB r4, r1, #0 @-T0
+ RSB r2, r2, #0 @frac = -frac
+ ADD r5, r0, r4, LSL #1 @x = exc - T0
+ CMP r2, #0
+ ADDLT r2, r2, #4 @frac += UP_SAMP
+ SUBLT r5, r5, #2 @x--
+ SUB r5, r5, #30 @x -= 15
+ RSB r4, r2, #3 @k = 3 - frac
+ ADR r8, Table
+ NOP @space for fixed up relative address of ADR
+ LDR r6, [r8]
+ ADD r6, r8
+ MOV r8, r4, LSL #6
+ @MOV r7, #0 @j = 0
+ ADD r8, r6, r8 @ptr2 = &(inter4_2[k][0])
+
+ MOV r1, r5
+ MOV r5, #0x8000
+ MOV r14, #21
+@ used register
+ @r0 --- exc[] r1 --- x r7 --- j r8 --- ptr2 r5 --- 0x8000
+THREE_LOOP:
+
+ @MOV r1, r5 @ptr1 = x
+ MOV r2, r8 @ptr = ptr2
+ LDR r3, [r2], #4 @h[0], h[1]
+ LDRSH r4, [r1], #2 @x[0]
+ LDRSH r6, [r1], #2 @x[1]
+ LDRSH r9, [r1], #2 @x[2]
+
+ SMULBB r10, r4, r3 @x[0] * h[0]
+ SMULBB r11, r6, r3 @x[1] * h[0]
+ SMULBB r12, r9, r3 @x[2] * h[0]
+
+ LDRSH r4, [r1], #2 @x[3]
+ SMLABT r10, r6, r3, r10 @x[1] * h[1]
+ SMLABT r11, r9, r3, r11 @x[2] * h[1]
+ SMLABT r12, r4, r3, r12 @x[3] * h[1]
+
+ LDR r3, [r2], #4 @h[2], h[3]
+ LDRSH r6, [r1], #2 @x[4]
+ SMLABB r10, r9, r3, r10 @x[2] * h[2]
+ SMLABB r11, r4, r3, r11 @x[3] * h[2]
+ SMLABB r12, r6, r3, r12 @x[4] * h[2]
+
+ LDRSH r9, [r1], #2 @x[5]
+ SMLABT r10, r4, r3, r10 @x[3] * h[3]
+ SMLABT r11, r6, r3, r11 @x[4] * h[3]
+ SMLABT r12, r9, r3, r12 @x[5] * h[3]
+
+ LDR r3, [r2], #4 @h[4], h[5]
+ LDRSH r4, [r1], #2 @x[6]
+ SMLABB r10, r6, r3, r10 @x[4] * h[4]
+ SMLABB r11, r9, r3, r11 @x[5] * h[4]
+ SMLABB r12, r4, r3, r12 @x[6] * h[4]
+
+ LDRSH r6, [r1], #2 @x[7]
+ SMLABT r10, r9, r3, r10 @x[5] * h[5]
+ SMLABT r11, r4, r3, r11 @x[6] * h[5]
+ SMLABT r12, r6, r3, r12 @x[7] * h[5]
+
+ LDR r3, [r2], #4 @h[6], h[7]
+ LDRSH r9, [r1], #2 @x[8]
+ SMLABB r10, r4, r3, r10 @x[6] * h[6]
+ SMLABB r11, r6, r3, r11 @x[7] * h[6]
+ SMLABB r12, r9, r3, r12 @x[8] * h[6]
+
+ LDRSH r4, [r1], #2 @x[9]
+ SMLABT r10, r6, r3, r10 @x[7] * h[7]
+ SMLABT r11, r9, r3, r11 @x[8] * h[7]
+ SMLABT r12, r4, r3, r12 @x[9] * h[7]
+
+ LDR r3, [r2], #4 @h[8], h[9]
+ LDRSH r6, [r1], #2 @x[10]
+ SMLABB r10, r9, r3, r10 @x[8] * h[8]
+ SMLABB r11, r4, r3, r11 @x[9] * h[8]
+ SMLABB r12, r6, r3, r12 @x[10] * h[8]
+
+ LDRSH r9, [r1], #2 @x[11]
+ SMLABT r10, r4, r3, r10 @x[9] * h[9]
+ SMLABT r11, r6, r3, r11 @x[10] * h[9]
+ SMLABT r12, r9, r3, r12 @x[11] * h[9]
+
+ LDR r3, [r2], #4 @h[10], h[11]
+ LDRSH r4, [r1], #2 @x[12]
+ SMLABB r10, r6, r3, r10 @x[10] * h[10]
+ SMLABB r11, r9, r3, r11 @x[11] * h[10]
+ SMLABB r12, r4, r3, r12 @x[12] * h[10]
+
+ LDRSH r6, [r1], #2 @x[13]
+ SMLABT r10, r9, r3, r10 @x[11] * h[11]
+ SMLABT r11, r4, r3, r11 @x[12] * h[11]
+ SMLABT r12, r6, r3, r12 @x[13] * h[11]
+
+ LDR r3, [r2], #4 @h[12], h[13]
+ LDRSH r9, [r1], #2 @x[14]
+ SMLABB r10, r4, r3, r10 @x[12] * h[12]
+ SMLABB r11, r6, r3, r11 @x[13] * h[12]
+ SMLABB r12, r9, r3, r12 @x[14] * h[12]
+
+ LDRSH r4, [r1], #2 @x[15]
+ SMLABT r10, r6, r3, r10 @x[13] * h[13]
+ SMLABT r11, r9, r3, r11 @x[14] * h[13]
+ SMLABT r12, r4, r3, r12 @x[15] * h[13]
+
+ LDR r3, [r2], #4 @h[14], h[15]
+ LDRSH r6, [r1], #2 @x[16]
+ SMLABB r10, r9, r3, r10 @x[14] * h[14]
+ SMLABB r11, r4, r3, r11 @x[15] * h[14]
+ SMLABB r12, r6, r3, r12 @x[16] * h[14]
+
+ LDRSH r9, [r1], #2 @x[17]
+ SMLABT r10, r4, r3, r10 @x[15] * h[15]
+ SMLABT r11, r6, r3, r11 @x[16] * h[15]
+ SMLABT r12, r9, r3, r12 @x[17] * h[15]
+
+ LDR r3, [r2], #4 @h[16], h[17]
+ LDRSH r4, [r1], #2 @x[18]
+ SMLABB r10, r6, r3, r10 @x[16] * h[16]
+ SMLABB r11, r9, r3, r11 @x[17] * h[16]
+ SMLABB r12, r4, r3, r12 @x[18] * h[16]
+
+ LDRSH r6, [r1], #2 @x[19]
+ SMLABT r10, r9, r3, r10 @x[17] * h[17]
+ SMLABT r11, r4, r3, r11 @x[18] * h[17]
+ SMLABT r12, r6, r3, r12 @x[19] * h[17]
+
+ LDR r3, [r2], #4 @h[18], h[19]
+ LDRSH r9, [r1], #2 @x[20]
+ SMLABB r10, r4, r3, r10 @x[18] * h[18]
+ SMLABB r11, r6, r3, r11 @x[19] * h[18]
+ SMLABB r12, r9, r3, r12 @x[20] * h[18]
+
+ LDRSH r4, [r1], #2 @x[21]
+ SMLABT r10, r6, r3, r10 @x[19] * h[19]
+ SMLABT r11, r9, r3, r11 @x[20] * h[19]
+ SMLABT r12, r4, r3, r12 @x[21] * h[19]
+
+ LDR r3, [r2], #4 @h[20], h[21]
+ LDRSH r6, [r1], #2 @x[22]
+ SMLABB r10, r9, r3, r10 @x[20] * h[20]
+ SMLABB r11, r4, r3, r11 @x[21] * h[20]
+ SMLABB r12, r6, r3, r12 @x[22] * h[20]
+
+ LDRSH r9, [r1], #2 @x[23]
+ SMLABT r10, r4, r3, r10 @x[21] * h[21]
+ SMLABT r11, r6, r3, r11 @x[22] * h[21]
+ SMLABT r12, r9, r3, r12 @x[23] * h[21]
+
+ LDR r3, [r2], #4 @h[22], h[23]
+ LDRSH r4, [r1], #2 @x[24]
+ SMLABB r10, r6, r3, r10 @x[22] * h[22]
+ SMLABB r11, r9, r3, r11 @x[23] * h[22]
+ SMLABB r12, r4, r3, r12 @x[24] * h[22]
+
+ LDRSH r6, [r1], #2 @x[25]
+ SMLABT r10, r9, r3, r10 @x[23] * h[23]
+ SMLABT r11, r4, r3, r11 @x[24] * h[23]
+ SMLABT r12, r6, r3, r12 @x[25] * h[23]
+
+ LDR r3, [r2], #4 @h[24], h[25]
+ LDRSH r9, [r1], #2 @x[26]
+ SMLABB r10, r4, r3, r10 @x[24] * h[24]
+ SMLABB r11, r6, r3, r11 @x[25] * h[24]
+ SMLABB r12, r9, r3, r12 @x[26] * h[24]
+
+ LDRSH r4, [r1], #2 @x[27]
+ SMLABT r10, r6, r3, r10 @x[25] * h[25]
+ SMLABT r11, r9, r3, r11 @x[26] * h[25]
+ SMLABT r12, r4, r3, r12 @x[27] * h[25]
+
+ LDR r3, [r2], #4 @h[26], h[27]
+ LDRSH r6, [r1], #2 @x[28]
+ SMLABB r10, r9, r3, r10 @x[26] * h[26]
+ SMLABB r11, r4, r3, r11 @x[27] * h[26]
+ SMLABB r12, r6, r3, r12 @x[28] * h[26]
+
+ LDRSH r9, [r1], #2 @x[29]
+ SMLABT r10, r4, r3, r10 @x[27] * h[27]
+ SMLABT r11, r6, r3, r11 @x[28] * h[27]
+ SMLABT r12, r9, r3, r12 @x[29] * h[27]
+
+ LDR r3, [r2], #4 @h[28], h[29]
+ LDRSH r4, [r1], #2 @x[30]
+ SMLABB r10, r6, r3, r10 @x[28] * h[28]
+ SMLABB r11, r9, r3, r11 @x[29] * h[28]
+ SMLABB r12, r4, r3, r12 @x[30] * h[28]
+
+ LDRSH r6, [r1], #2 @x[31]
+ SMLABT r10, r9, r3, r10 @x[29] * h[29]
+ SMLABT r11, r4, r3, r11 @x[30] * h[29]
+ SMLABT r12, r6, r3, r12 @x[31] * h[29]
+
+ LDR r3, [r2], #4 @h[30], h[31]
+ LDRSH r9, [r1], #2 @x[32]
+ SMLABB r10, r4, r3, r10 @x[30] * h[30]
+ SMLABB r11, r6, r3, r11 @x[31] * h[30]
+ SMLABB r12, r9, r3, r12 @x[32] * h[30]
+
+ LDRSH r4, [r1], #-60 @x[33]
+ SMLABT r10, r6, r3, r10 @x[31] * h[31]
+ SMLABT r11, r9, r3, r11 @x[32] * h[31]
+ SMLABT r12, r4, r3, r12 @x[33] * h[31]
+
+ @SSAT r10, #32, r10, LSL #2
+ @SSAT r11, #32, r11, LSL #2
+ @SSAT r12, #32, r12, LSL #2
+
+ MOV r10, r10, LSL #1
+ MOV r11, r11, LSL #1
+ MOV r12, r12, LSL #1
+
+ QADD r10, r10, r10
+ QADD r11, r11, r11
+ QADD r12, r12, r12
+
+ QADD r10, r10, r5
+ QADD r11, r11, r5
+ QADD r12, r12, r5
+
+ SUBS r14, r14, #1
+
+ MOV r10, r10, ASR #16
+ MOV r11, r11, ASR #16
+ MOV r12, r12, ASR #16
+
+ STRH r10, [r0], #2
+ STRH r11, [r0], #2
+ STRH r12, [r0], #2
+ BNE THREE_LOOP
+
+ MOV r2, r8 @ptr = ptr2
+
+Last2LOOP:
+
+ LDR r3, [r2], #4 @h[0], h[1]
+ LDRSH r4, [r1], #2 @x[0]
+ LDRSH r6, [r1], #2 @x[1]
+ LDRSH r9, [r1], #2 @x[2]
+
+ SMULBB r10, r4, r3 @x[0] * h[0]
+ SMULBB r11, r6, r3 @x[1] * h[0]
+
+ SMLABT r10, r6, r3, r10 @x[1] * h[1]
+ SMLABT r11, r9, r3, r11 @x[2] * h[1]
+
+ LDR r3, [r2], #4 @h[2], h[3]
+ LDRSH r4, [r1], #2 @x[3]
+ LDRSH r6, [r1], #2 @x[4]
+
+ SMLABB r10, r9, r3, r10 @x[2] * h[2]
+ SMLABB r11, r4, r3, r11 @x[3] * h[2]
+
+ SMLABT r10, r4, r3, r10 @x[3] * h[3]
+ SMLABT r11, r6, r3, r11 @x[4] * h[3]
+
+ LDR r3, [r2], #4 @h[4], h[5]
+ LDRSH r9, [r1], #2 @x[5]
+ LDRSH r4, [r1], #2 @x[6]
+
+ SMLABB r10, r6, r3, r10 @x[4] * h[4]
+ SMLABB r11, r9, r3, r11 @x[5] * h[4]
+
+ SMLABT r10, r9, r3, r10 @x[5] * h[5]
+ SMLABT r11, r4, r3, r11 @x[6] * h[5]
+
+ LDR r3, [r2], #4 @h[6], h[7]
+ LDRSH r6, [r1], #2 @x[7]
+ LDRSH r9, [r1], #2 @x[8]
+
+ SMLABB r10, r4, r3, r10 @x[6] * h[6]
+ SMLABB r11, r6, r3, r11 @x[7] * h[6]
+
+ SMLABT r10, r6, r3, r10 @x[7] * h[7]
+ SMLABT r11, r9, r3, r11 @x[8] * h[7]
+
+ LDR r3, [r2], #4 @h[8], h[9]
+ LDRSH r4, [r1], #2 @x[9]
+ LDRSH r6, [r1], #2 @x[10]
+
+ SMLABB r10, r9, r3, r10 @x[8] * h[8]
+ SMLABB r11, r4, r3, r11 @x[9] * h[8]
+
+ SMLABT r10, r4, r3, r10 @x[9] * h[9]
+ SMLABT r11, r6, r3, r11 @x[10] * h[9]
+
+ LDR r3, [r2], #4 @h[10], h[11]
+ LDRSH r9, [r1], #2 @x[11]
+ LDRSH r4, [r1], #2 @x[12]
+
+ SMLABB r10, r6, r3, r10 @x[10] * h[10]
+ SMLABB r11, r9, r3, r11 @x[11] * h[10]
+
+ SMLABT r10, r9, r3, r10 @x[11] * h[11]
+ SMLABT r11, r4, r3, r11 @x[12] * h[11]
+
+ LDR r3, [r2], #4 @h[12], h[13]
+ LDRSH r6, [r1], #2 @x[13]
+ LDRSH r9, [r1], #2 @x[14]
+
+ SMLABB r10, r4, r3, r10 @x[12] * h[12]
+ SMLABB r11, r6, r3, r11 @x[13] * h[12]
+
+ SMLABT r10, r6, r3, r10 @x[13] * h[13]
+ SMLABT r11, r9, r3, r11 @x[14] * h[13]
+
+ LDR r3, [r2], #4 @h[14], h[15]
+ LDRSH r4, [r1], #2 @x[15]
+ LDRSH r6, [r1], #2 @x[16]
+
+ SMLABB r10, r9, r3, r10 @x[14] * h[14]
+ SMLABB r11, r4, r3, r11 @x[15] * h[14]
+
+ SMLABT r10, r4, r3, r10 @x[15] * h[15]
+ SMLABT r11, r6, r3, r11 @x[16] * h[15]
+
+ LDR r3, [r2], #4 @h[16], h[17]
+ LDRSH r9, [r1], #2 @x[17]
+ LDRSH r4, [r1], #2 @x[18]
+
+ SMLABB r10, r6, r3, r10 @x[16] * h[16]
+ SMLABB r11, r9, r3, r11 @x[17] * h[16]
+
+ SMLABT r10, r9, r3, r10 @x[17] * h[17]
+ SMLABT r11, r4, r3, r11 @x[18] * h[17]
+
+ LDR r3, [r2], #4 @h[18], h[19]
+ LDRSH r6, [r1], #2 @x[19]
+ LDRSH r9, [r1], #2 @x[20]
+
+ SMLABB r10, r4, r3, r10 @x[18] * h[18]
+ SMLABB r11, r6, r3, r11 @x[19] * h[18]
+
+ SMLABT r10, r6, r3, r10 @x[19] * h[19]
+ SMLABT r11, r9, r3, r11 @x[20] * h[19]
+
+ LDR r3, [r2], #4 @h[20], h[21]
+ LDRSH r4, [r1], #2 @x[21]
+ LDRSH r6, [r1], #2 @x[22]
+
+ SMLABB r10, r9, r3, r10 @x[20] * h[20]
+ SMLABB r11, r4, r3, r11 @x[21] * h[20]
+
+ SMLABT r10, r4, r3, r10 @x[21] * h[21]
+ SMLABT r11, r6, r3, r11 @x[22] * h[21]
+
+ LDR r3, [r2], #4 @h[22], h[23]
+ LDRSH r9, [r1], #2 @x[23]
+ LDRSH r4, [r1], #2 @x[24]
+
+ SMLABB r10, r6, r3, r10 @x[22] * h[22]
+ SMLABB r11, r9, r3, r11 @x[23] * h[22]
+
+ SMLABT r10, r9, r3, r10 @x[23] * h[23]
+ SMLABT r11, r4, r3, r11 @x[24] * h[23]
+
+ LDR r3, [r2], #4 @h[24], h[25]
+ LDRSH r6, [r1], #2 @x[25]
+ LDRSH r9, [r1], #2 @x[26]
+
+ SMLABB r10, r4, r3, r10 @x[24] * h[24]
+ SMLABB r11, r6, r3, r11 @x[25] * h[24]
+
+ SMLABT r10, r6, r3, r10 @x[25] * h[25]
+ SMLABT r11, r9, r3, r11 @x[26] * h[25]
+
+ LDR r3, [r2], #4 @h[26], h[27]
+ LDRSH r4, [r1], #2 @x[27]
+ LDRSH r6, [r1], #2 @x[28]
+
+ SMLABB r10, r9, r3, r10 @x[26] * h[26]
+ SMLABB r11, r4, r3, r11 @x[27] * h[26]
+
+ SMLABT r10, r4, r3, r10 @x[27] * h[27]
+ SMLABT r11, r6, r3, r11 @x[28] * h[27]
+
+ LDR r3, [r2], #4 @h[28], h[29]
+ LDRSH r9, [r1], #2 @x[29]
+ LDRSH r4, [r1], #2 @x[30]
+
+ SMLABB r10, r6, r3, r10 @x[28] * h[28]
+ SMLABB r11, r9, r3, r11 @x[29] * h[28]
+
+ SMLABT r10, r9, r3, r10 @x[29] * h[29]
+ SMLABT r11, r4, r3, r11 @x[30] * h[29]
+
+ LDR r3, [r2], #4 @h[30], h[31]
+ LDRSH r6, [r1], #2 @x[31]
+ LDRSH r9, [r1], #2 @x[32]
+
+ SMLABB r10, r4, r3, r10 @x[30] * h[30]
+ SMLABB r11, r6, r3, r11 @x[31] * h[30]
+
+ SMLABT r10, r6, r3, r10 @x[31] * h[31]
+ SMLABT r11, r9, r3, r11 @x[32] * h[31]
+
+ @SSAT r10, #32, r10, LSL #2
+ @SSAT r11, #32, r11, LSL #2
+ MOV r10, r10, LSL #1
+ MOV r11, r11, LSL #1
+
+ QADD r10, r10, r10
+ QADD r11, r11, r11
+
+ QADD r10, r10, r5
+ QADD r11, r11, r5
+
+ MOV r10, r10, ASR #16
+ MOV r11, r11, ASR #16
+
+ STRH r10, [r0], #2
+ STRH r11, [r0], #2
+
+
+pred_lt4_end:
+ LDMFD r13!, {r4 - r12, r15}
+
+Table:
+ .word inter4_2-Table
+ @ENDFUNC
+ .end
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/residu_asm_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/residu_asm_opt.s
new file mode 100644
index 0000000..d71d790
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/residu_asm_opt.s
@@ -0,0 +1,228 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Residu(
+@ Word16 a[], /* (i) Q12 : prediction coefficients */
+@ Word16 x[], /* (i) : speech (values x[-m..-1] are needed */
+@ Word16 y[], /* (o) x2 : residual signal */
+@ Word16 lg /* (i) : size of filtering */
+@ )
+@a[] --- r0
+@x[] --- r1
+@y[] --- r2
+@lg --- r3
+
+ .section .text
+ .global Residu_opt
+
+Residu_opt:
+
+ STMFD r13!, {r4 - r12, r14}
+
+ LDRH r5, [r0], #2
+ LDRH r6, [r0], #2
+ ORR r5, r6, r5, LSL #16 @r5 --- a0, a1
+
+ LDRH r6, [r0], #2
+ LDRH r7, [r0], #2
+ ORR r6, r7, r6, LSL #16 @r6 --- a2, a3
+
+ LDRH r7, [r0], #2
+ LDRH r8, [r0], #2
+ ORR r7, r8, r7, LSL #16 @r7 --- a4, a5
+
+ LDRH r8, [r0], #2
+ LDRH r9, [r0], #2
+ ORR r8, r9, r8, LSL #16 @r8 --- a6, a7
+
+ LDRH r9, [r0], #2
+ LDRH r10, [r0], #2
+ ORR r9, r10, r9, LSL #16 @r9 --- a8, a9
+
+ LDRH r10, [r0], #2
+ LDRH r11, [r0], #2
+ ORR r10, r11, r10, LSL #16 @r10 --- a10, a11
+
+ LDRH r11, [r0], #2
+ LDRH r12, [r0], #2
+ ORR r11, r12, r11, LSL #16 @r11 --- a12, a13
+
+ LDRH r12, [r0], #2
+ LDRH r4, [r0], #2
+ ORR r12, r4, r12, LSL #16 @r12 --- a14, a15
+
+
+ STMFD r13!, {r8 - r12} @store r8-r12
+ LDRH r4, [r0], #2 @load a16
+ MOV r14, r3, ASR #2 @one loop get 4 outputs
+ ADD r1, r1, #4
+ MOV r0, r2
+ ORR r14, r4, r14, LSL #16 @r14 --- loopnum, a16
+
+residu_loop:
+
+ LDR r10, [r1], #-4 @r10 --- x[3], x[2]
+ LDR r2, [r1], #-4 @r2 --- x[1], x[0]
+
+ SMULTB r3, r5, r2 @i1(0) --- r3 = x[0] * a0
+ SMULTT r4, r5, r2 @i2(0) --- r4 = x[1] * a0
+ SMULTB r11, r5, r10 @i3(0) --- r11 = x[2] * a0
+ SMULTT r12, r5, r10 @i4(0) --- r12 = x[3] * a0
+
+ SMLABB r4, r5, r2, r4 @i2(1) --- r4 += x[0] * a1
+ SMLABT r11, r5, r2, r11 @i3(1) --- r11 += x[1] * a0
+ SMLABB r12, r5, r10, r12 @i4(1) --- r12 += x[2] * a1
+
+ SMLATB r11, r6, r2, r11 @i3(2) --- r11 += x[0] * a2
+ SMLATT r12, r6, r2, r12 @i4(2) --- r12 += x[1] * a2
+ SMLABB r12, r6, r2, r12 @i4(3) --- r12 += x[0] * a3
+
+ LDR r2, [r1], #-4 @r2 ---- x[-1], x[-2]
+
+ SMLABT r3, r5, r2, r3 @i1(1) --- r3 += x[-1] * a1
+ SMLATT r4, r6, r2, r4 @i2(2) --- r4 += x[-1] * a2
+ SMLABT r11, r6, r2, r11 @i3(3) --- r11 += x[-1] * a3
+ SMLATT r12, r7, r2, r12 @i4(4) --- r12 += x[-1] * a4
+ SMLATB r3, r6, r2, r3 @i1(2) --- r3 += x[-2] * a2
+
+ SMLABB r4, r6, r2, r4 @ i2 (3)
+ SMLATB r11,r7, r2, r11 @ i3 (4)
+ SMLABB r12,r7, r2, r12 @ i4 (5)
+
+ LDR r2,[r1],#-4
+ SMLABT r3, r6, r2, r3 @ i1 (3)
+ SMLATT r4, r7, r2, r4 @ i2 (4)
+ SMLABT r11,r7, r2, r11 @ i3 (5)
+ SMLATT r12,r8, r2, r12 @ i4 (6)
+ SMLATB r3, r7, r2, r3 @ i1 (4)
+ SMLABB r4, r7, r2, r4 @ i2 (5)
+ SMLATB r11,r8, r2, r11 @ i3 (6)
+ SMLABB r12,r8, r2, r12 @ i4 (7)
+
+ LDR r2,[r1],#-4
+ SMLABT r3, r7, r2, r3 @ i1 (5)
+ SMLATT r4, r8, r2, r4 @ i2 (6)
+ SMLABT r11,r8, r2, r11 @ i3 (7)
+ SMLATT r12,r9, r2, r12 @ i4 (8)
+ SMLATB r3, r8, r2, r3 @ i1 (6)
+ SMLABB r4, r8, r2, r4 @ i2 (7)
+ SMLATB r11,r9, r2, r11 @ i3 (8)
+ SMLABB r12,r9, r2, r12 @ i4 (9)
+ LDR r10, [r13, #8] @ [ a10 | a11]
+
+ LDR r2,[r1],#-4
+ SMLABT r3, r8, r2, r3 @ i1 (7)
+ SMLATT r4, r9, r2, r4 @ i2 (8)
+ SMLABT r11,r9, r2, r11 @ i3 (9)
+ SMLATT r12,r10, r2, r12 @ i4 (10)
+ SMLATB r3, r9, r2, r3 @ i1 (8)
+ SMLABB r4, r9, r2, r4 @ i2 (9)
+ SMLATB r11,r10, r2, r11 @ i3 (10)
+ SMLABB r12,r10, r2, r12 @ i4 (11)
+ LDR r8, [r13, #12] @ [ a12 | a13 ]
+
+ LDR r2,[r1],#-4
+ SMLABT r3, r9, r2, r3 @ i1 (9)
+ SMLATT r4, r10, r2, r4 @ i2 (10)
+ SMLABT r11,r10, r2, r11 @ i3 (11)
+ SMLATT r12,r8, r2, r12 @ i4 (12)
+ SMLATB r3, r10, r2, r3 @ i1 (10)
+ SMLABB r4, r10, r2, r4 @ i2 (11)
+ SMLATB r11,r8, r2, r11 @ i3 (12)
+ SMLABB r12,r8, r2, r12 @ i4 (13)
+ LDR r9, [r13, #16] @ [ a14 | a15 ]
+
+ LDR r2,[r1],#-4
+ SMLABT r3, r10, r2, r3 @ i1 (11)
+ SMLATT r4, r8, r2, r4 @ i2 (12)
+ SMLABT r11,r8, r2, r11 @ i3 (13)
+ SMLATT r12,r9, r2, r12 @ i4 (14)
+ SMLATB r3, r8, r2, r3 @ i1 (12)
+ SMLABB r4, r8, r2, r4 @ i2 (13)
+ SMLATB r11,r9, r2, r11 @ i3 (14)
+ SMLABB r12,r9, r2, r12 @ i4 (15)
+
+
+ LDR r2,[r1],#-4
+ SMLABT r3, r8, r2, r3 @ i1 (13)
+ SMLATT r4, r9, r2, r4 @ i2 (14)
+ SMLABT r11,r9, r2, r11 @ i3 (15)
+ SMLABT r12,r14, r2, r12 @ i4 (16)
+ SMLATB r3, r9, r2, r3 @ i1 (14)
+ SMLABB r4, r9, r2, r4 @ i2 (15)
+ SMLABB r11,r14, r2, r11 @ i3 (16)
+ LDR r8, [r13] @ [ a6 | a7 ]
+
+ LDR r2,[r1],#44 @ Change
+ SMLABT r3, r9, r2, r3
+ SMLABB r3, r14, r2, r3
+ SMLABT r4, r14, r2, r4
+ LDR r9, [r13, #4] @ [ a8 | a9 ]
+
+
+ QADD r3,r3,r3
+ QADD r4,r4,r4
+ QADD r11,r11,r11
+ QADD r12,r12,r12
+
+ QADD r3,r3,r3
+ QADD r4,r4,r4
+ QADD r11,r11,r11
+ QADD r12,r12,r12
+
+ QADD r3,r3,r3
+ QADD r4,r4,r4
+ QADD r11,r11,r11
+ QADD r12,r12,r12
+
+ QADD r3,r3,r3
+ QADD r4,r4,r4
+ QADD r11,r11,r11
+ QADD r12,r12,r12
+
+ MOV r2,#32768
+
+ QDADD r3,r2,r3
+ QDADD r4,r2,r4
+ QDADD r11,r2,r11
+ QDADD r12,r2,r12
+
+
+ MOV r3,r3,asr #16
+ MOV r4,r4,asr #16
+ MOV r11,r11,asr #16
+ MOV r12,r12,asr #16
+
+ STRH r3,[r0],#2
+ STRH r4,[r0],#2
+ STRH r11,[r0],#2
+ STRH r12,[r0],#2
+
+ MOV r2,r14,asr #16
+ SUB r14, r14, #0x10000
+ SUBS r2,r2,#1
+ BNE residu_loop
+end:
+ LDMFD r13!, {r8 -r12}
+ LDMFD r13!, {r4 -r12,pc}
+
+ @ENDFUNC
+ .end
+
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/scale_sig_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/scale_sig_opt.s
new file mode 100644
index 0000000..e8802f5
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/scale_sig_opt.s
@@ -0,0 +1,75 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Scale_sig(
+@ Word16 x[], /* (i/o) : signal to scale */
+@ Word16 lg, /* (i) : size of x[] */
+@ Word16 exp /* (i) : exponent: x = round(x << exp) */
+@ )
+@
+@r0 --- x[]
+@r1 --- lg
+@r2 --- exp
+
+ .section .text
+ .global Scale_sig_opt
+
+Scale_sig_opt:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r3, r1, #1 @i = lg - 1
+ CMP r2, #0 @Compare exp and 0
+ RSB r7, r2, #0 @exp = -exp
+ ADD r10, r2, #16 @16 + exp
+ ADD r4, r0, r3, LSL #1 @x[i] address
+ MOV r8, #0x7fffffff
+ MOV r9, #0x8000
+ BLE LOOP2
+
+LOOP1:
+
+ LDRSH r5, [r4] @load x[i]
+ MOV r12, r5, LSL r10
+ TEQ r5, r12, ASR r10
+ EORNE r12, r8, r5, ASR #31
+ SUBS r3, r3, #1
+ QADD r11, r12, r9
+ MOV r12, r11, ASR #16
+ STRH r12, [r4], #-2
+ BGE LOOP1
+ BL The_end
+
+LOOP2:
+
+ LDRSH r5, [r4] @load x[i]
+ MOV r6, r5, LSL #16 @L_tmp = x[i] << 16
+ MOV r5, r6, ASR r7 @L_tmp >>= exp
+ QADD r11, r5, r9
+ MOV r12, r11, ASR #16
+ SUBS r3, r3, #1
+ STRH r12, [r4], #-2
+ BGE LOOP2
+
+The_end:
+ LDMFD r13!, {r4 - r12, r15}
+
+ @ENDFUNC
+ .end
+
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV5E/syn_filt_opt.s b/media/codecs/amrwb/enc/src/asm/ARMV5E/syn_filt_opt.s
new file mode 100644
index 0000000..2a1e0d7
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV5E/syn_filt_opt.s
@@ -0,0 +1,238 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@**********************************************************************/
+@void Syn_filt(
+@ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+@ Word16 x[], /* (i) : input signal */
+@ Word16 y[], /* (o) : output signal */
+@ Word16 mem[], /* (i/o) : memory associated with this filtering. */
+@)
+@***********************************************************************
+@ a[] --- r0
+@ x[] --- r1
+@ y[] --- r2
+@ mem[] --- r3
+@ m --- 16 lg --- 80 update --- 1
+
+ .section .text
+ .global Syn_filt_asm
+ .extern voAWB_Copy
+
+Syn_filt_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r13, r13, #700 @ y_buf[L_FRAME16k + M16k]
+
+ MOV r4, r3 @ copy mem[] address
+ MOV r5, r13 @ copy yy = y_buf address
+
+ @ for(i = 0@ i < m@ i++)
+ @{
+ @ *yy++ = mem[i]@
+ @}
+
+ LDRH r6, [r4], #2
+ LDRH r7, [r4], #2
+ LDRH r8, [r4], #2
+ LDRH r9, [r4], #2
+ LDRH r10, [r4], #2
+ LDRH r11, [r4], #2
+ LDRH r12, [r4], #2
+ LDRH r14, [r4], #2
+
+ STRH r6, [r5], #2
+ STRH r7, [r5], #2
+ STRH r8, [r5], #2
+ STRH r9, [r5], #2
+ STRH r10, [r5], #2
+ STRH r11, [r5], #2
+ STRH r12, [r5], #2
+ STRH r14, [r5], #2
+
+ LDRH r6, [r4], #2
+ LDRH r7, [r4], #2
+ LDRH r8, [r4], #2
+ LDRH r9, [r4], #2
+ LDRH r10, [r4], #2
+ LDRH r11, [r4], #2
+ LDRH r12, [r4], #2
+ LDRH r14, [r4], #2
+
+ STRH r6, [r5], #2
+ STRH r7, [r5], #2
+ STRH r8, [r5], #2
+ STRH r9, [r5], #2
+ STRH r10, [r5], #2
+ STRH r11, [r5], #2
+ STRH r12, [r5], #2
+ STRH r14, [r5], #2
+
+ LDRSH r5, [r0] @ load a[0]
+ MOV r8, #0 @ i = 0
+ MOV r5, r5, ASR #1 @ a0 = a[0] >> 1
+ @MOV r4, r13
+ @ load all a[]
+
+ LDR r14, =0xffff
+ LDRSH r6, [r0, #2] @ load a[1]
+ LDRSH r7, [r0, #4] @ load a[2]
+ LDRSH r9, [r0, #6] @ load a[3]
+ LDRSH r11,[r0, #8] @ load a[4]
+ AND r6, r6, r14
+ AND r9, r9, r14
+ ORR r10, r6, r7, LSL #16 @ -a[2] -- -a[1]
+ ORR r12, r9, r11, LSL #16 @ -a[4] -- -a[3]
+ STR r10, [r13, #-4]
+ STR r12, [r13, #-8]
+
+ LDRSH r6, [r0, #10] @ load a[5]
+ LDRSH r7, [r0, #12] @ load a[6]
+ LDRSH r9, [r0, #14] @ load a[7]
+ LDRSH r11,[r0, #16] @ load a[8]
+ AND r6, r6, r14
+ AND r9, r9, r14
+ ORR r10, r6, r7, LSL #16 @ -a[6] -- -a[5]
+ ORR r12, r9, r11, LSL #16 @ -a[8] -- -a[7]
+ STR r10, [r13, #-12]
+ STR r12, [r13, #-16]
+
+ LDRSH r6, [r0, #18] @ load a[9]
+ LDRSH r7, [r0, #20] @ load a[10]
+ LDRSH r9, [r0, #22] @ load a[11]
+ LDRSH r11,[r0, #24] @ load a[12]
+ AND r6, r6, r14
+ AND r9, r9, r14
+ ORR r10, r6, r7, LSL #16 @ -a[10] -- -a[9]
+ ORR r12, r9, r11, LSL #16 @ -a[12] -- -a[11]
+ STR r10, [r13, #-20]
+ STR r12, [r13, #-24]
+
+ LDRSH r6, [r0, #26] @ load a[13]
+ LDRSH r7, [r0, #28] @ load a[14]
+ LDRSH r9, [r0, #30] @ load a[15]
+ LDRSH r11,[r0, #32] @ load a[16]
+ AND r6, r6, r14
+ AND r9, r9, r14
+ ORR r10, r6, r7, LSL #16 @ -a[14] -- -a[13]
+ ORR r12, r9, r11, LSL #16 @ -a[16] -- -a[15]
+ STR r10, [r13, #-28]
+ STR r12, [r13, #-32]
+
+ ADD r4, r13, #32
+LOOP:
+ LDRSH r6, [r1], #2 @ load x[i]
+ ADD r10, r4, r8, LSL #1 @ temp_p = yy + i
+
+ MUL r0, r5, r6 @ L_tmp = x[i] * a0
+ @ for(j = 1@ j <= m, j+=8)
+ LDR r7, [r13, #-4] @ -a[2] -a[1]
+ LDRSH r9, [r10, #-2] @ *(temp_p - 1)
+ LDRSH r12, [r10, #-4] @ *(temp_p - 2)
+
+
+ SMULBB r14, r9, r7 @ -a[1] * (*(temp_p -1))
+
+ LDRSH r6, [r10, #-6] @ *(temp_p - 3)
+
+ SMLABT r14, r12, r7, r14 @ -a[2] * (*(temp_p - 2))
+
+ LDR r7, [r13, #-8] @ -a[4] -a[3]
+ LDRSH r11, [r10, #-8] @ *(temp_p - 4)
+
+ SMLABB r14, r6, r7, r14 @ -a[3] * (*(temp_p -3))
+
+ LDRSH r9, [r10, #-10] @ *(temp_p - 5)
+
+ SMLABT r14, r11, r7, r14 @ -a[4] * (*(temp_p -4))
+
+ LDR r7, [r13, #-12] @ -a[6] -a[5]
+ LDRSH r12, [r10, #-12] @ *(temp_p - 6)
+
+ SMLABB r14, r9, r7, r14 @ -a[5] * (*(temp_p -5))
+
+ LDRSH r6, [r10, #-14] @ *(temp_p - 7)
+
+ SMLABT r14, r12, r7, r14 @ -a[6] * (*(temp_p - 6))
+
+ LDR r7, [r13, #-16] @ -a[8] -a[7]
+ LDRSH r11, [r10, #-16] @ *(temp_p - 8)
+
+ SMLABB r14, r6, r7, r14 @ -a[7] * (*(temp_p -7))
+
+ LDRSH r9, [r10, #-18] @ *(temp_p - 9)
+
+ SMLABT r14, r11, r7, r14 @ -a[8] * (*(temp_p -8))
+
+ LDR r7, [r13, #-20] @ -a[10] -a[9]
+ LDRSH r12, [r10, #-20] @ *(temp_p - 10)
+
+ SMLABB r14, r9, r7, r14 @ -a[9] * (*(temp_p -9))
+
+ LDRSH r6, [r10, #-22] @ *(temp_p - 11)
+
+ SMLABT r14, r12, r7, r14 @ -a[10] * (*(temp_p - 10))
+
+ LDR r7, [r13, #-24] @ -a[12] -a[11]
+ LDRSH r11, [r10, #-24] @ *(temp_p - 12)
+
+ SMLABB r14, r6, r7, r14 @ -a[11] * (*(temp_p -11))
+
+ LDRSH r9, [r10, #-26] @ *(temp_p - 13)
+
+ SMLABT r14, r11, r7, r14 @ -a[12] * (*(temp_p -12))
+
+ LDR r7, [r13, #-28] @ -a[14] -a[13]
+ LDRSH r12, [r10, #-28] @ *(temp_p - 14)
+
+ SMLABB r14, r9, r7, r14 @ -a[13] * (*(temp_p -13))
+
+ LDRSH r6, [r10, #-30] @ *(temp_p - 15)
+
+ SMLABT r14, r12, r7, r14 @ -a[14] * (*(temp_p - 14))
+
+ LDR r7, [r13, #-32] @ -a[16] -a[15]
+ LDRSH r11, [r10, #-32] @ *(temp_p - 16)
+
+ SMLABB r14, r6, r7, r14 @ -a[15] * (*(temp_p -15))
+
+ SMLABT r14, r11, r7, r14 @ -a[16] * (*(temp_p -16))
+
+ RSB r14, r14, r0
+
+ MOV r7, r14, LSL #4 @ L_tmp <<=4
+ ADD r8, r8, #1
+ ADD r14, r7, #0x8000
+ MOV r7, r14, ASR #16 @ (L_tmp + 0x8000) >> 16
+ CMP r8, #80
+ STRH r7, [r10] @ yy[i]
+ STRH r7, [r2], #2 @ y[i]
+ BLT LOOP
+
+ @ update mem[]
+ ADD r5, r13, #160 @ yy[64] address
+ MOV r1, r3
+ MOV r0, r5
+ MOV r2, #16
+ BL voAWB_Copy
+
+Syn_filt_asm_end:
+
+ ADD r13, r13, #700
+ LDMFD r13!, {r4 - r12, r15}
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/Deemph_32_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/Deemph_32_neon.s
new file mode 100644
index 0000000..91feea0
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/Deemph_32_neon.s
@@ -0,0 +1,102 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Deemph_32(
+@ Word16 x_hi[], /* (i) : input signal (bit31..16) */
+@ Word16 x_lo[], /* (i) : input signal (bit15..4) */
+@ Word16 y[], /* (o) : output signal (x16) */
+@ Word16 mu, /* (i) Q15 : deemphasis factor */
+@ Word16 L, /* (i) : vector size */
+@ Word16 * mem /* (i/o) : memory (y[-1]) */
+@ )
+
+@x_hi RN R0
+@x_lo RN R1
+@y[] RN R2
+@*mem RN R3
+
+ .section .text
+ .global Deemph_32_asm
+
+Deemph_32_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ MOV r4, #2 @i=0
+ LDRSH r6, [r0], #2 @load x_hi[0]
+ LDRSH r7, [r1], #2 @load x_lo[0]
+ LDR r5, =22282 @r5---mu
+ MOV r11, #0x8000
+
+ @y[0]
+ MOV r10, r6, LSL #16 @L_tmp = x_hi[0]<<16
+ MOV r8, r5, ASR #1 @fac = mu >> 1
+ LDR r5, [r3]
+ ADD r12, r10, r7, LSL #4 @L_tmp += x_lo[0] << 4
+ MOV r10, r12, LSL #3 @L_tmp <<= 3
+ MUL r9, r5, r8
+ LDRSH r6, [r0], #2 @load x_hi[1]
+ QDADD r10, r10, r9
+ LDRSH r7, [r1], #2 @load x_lo[1]
+ MOV r12, r10, LSL #1 @L_tmp = L_mac(L_tmp, *mem, fac)
+ QADD r10, r12, r11
+ MOV r14, r10, ASR #16 @y[0] = round(L_tmp)
+
+
+ MOV r10, r6, LSL #16
+ ADD r12, r10, r7, LSL #4
+ STRH r14, [r2], #2 @update y[0]
+ MOV r10, r12, LSL #3
+ MUL r9, r14, r8
+ QDADD r10, r10, r9
+ MOV r12, r10, LSL #1
+ QADD r10, r12, r11
+ MOV r14, r10, ASR #16 @y[1] = round(L_tmp)
+
+LOOP:
+ LDRSH r6, [r0], #2 @load x_hi[]
+ LDRSH r7, [r1], #2
+ STRH r14, [r2], #2
+ MOV r10, r6, LSL #16
+ ADD r12, r10, r7, LSL #4
+ MUL r9, r14, r8
+ MOV r10, r12, LSL #3
+ QDADD r10, r10, r9
+ LDRSH r6, [r0], #2 @load x_hi[]
+ MOV r12, r10, LSL #1
+ QADD r10, r12, r11
+ LDRSH r7, [r1], #2
+ MOV r14, r10, ASR #16
+
+ MOV r10, r6, LSL #16
+ ADD r12, r10, r7, LSL #4
+ STRH r14, [r2], #2
+ MUL r9, r14, r8
+ MOV r10, r12, LSL #3
+ QDADD r10, r10, r9
+ ADD r4, r4, #2
+ MOV r12, r10, LSL #1
+ QADD r10, r12, r11
+ CMP r4, #64
+ MOV r14, r10, ASR #16
+
+ BLT LOOP
+ STR r14, [r3]
+ STRH r14, [r2]
+
+ LDMFD r13!, {r4 - r12, r15}
+
+ .end
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/Dot_p_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/Dot_p_neon.s
new file mode 100644
index 0000000..7149a49
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/Dot_p_neon.s
@@ -0,0 +1,127 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@**********************************************************************/
+@Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */
+@ Word16 x[], /* (i) 12bits: x vector */
+@ Word16 y[], /* (i) 12bits: y vector */
+@ Word16 lg, /* (i) : vector length */
+@ Word16 * exp /* (o) : exponent of result (0..+30) */
+@)
+@************************************************************************
+@ x[] --- r0
+@ y[] --- r1
+@ lg --- r2
+@ *exp --- r3
+
+ .section .text
+ .global Dot_product12_asm
+
+Dot_product12_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ CMP r0, r1
+ BEQ LOOP_EQ
+
+ VLD1.S16 {Q0, Q1}, [r0]! @load 16 Word16 x[]
+ VLD1.S16 {Q2, Q3}, [r0]! @load 16 Word16 x[]
+ VLD1.S16 {Q4, Q5}, [r0]! @load 16 Word16 x[]
+ VLD1.S16 {Q6, Q7}, [r0]! @load 16 Word16 x[]
+ VLD1.S16 {Q8, Q9}, [r1]! @load 16 Word16 y[]
+ VLD1.S16 {Q10, Q11}, [r1]! @load 16 Word16 y[]
+ VLD1.S16 {Q12, Q13}, [r1]! @load 16 Word16 y[]
+
+ VMULL.S16 Q15, D16, D0
+ VMLAL.S16 Q15, D17, D1
+ VMLAL.S16 Q15, D18, D2
+ VMLAL.S16 Q15, D19, D3
+ VLD1.S16 {Q0, Q1}, [r1]! @load 16 Word16 y[]
+ VMLAL.S16 Q15, D20, D4
+ VMLAL.S16 Q15, D21, D5
+ VMLAL.S16 Q15, D22, D6
+ VMLAL.S16 Q15, D23, D7
+ VMLAL.S16 Q15, D24, D8
+ VMLAL.S16 Q15, D25, D9
+ VMLAL.S16 Q15, D26, D10
+ VMLAL.S16 Q15, D27, D11
+ VMLAL.S16 Q15, D0, D12
+ VMLAL.S16 Q15, D1, D13
+ VMLAL.S16 Q15, D2, D14
+ VMLAL.S16 Q15, D3, D15
+
+ CMP r2, #64
+ BEQ Lable1
+ VLD1.S16 {Q0, Q1}, [r0]! @load 16 Word16 x[]
+ VLD1.S16 {Q2, Q3}, [r1]!
+ VMLAL.S16 Q15, D4, D0
+ VMLAL.S16 Q15, D5, D1
+ VMLAL.S16 Q15, D6, D2
+ VMLAL.S16 Q15, D7, D3
+ BL Lable1
+
+LOOP_EQ:
+ VLD1.S16 {Q0, Q1}, [r0]!
+ VLD1.S16 {Q2, Q3}, [r0]!
+ VLD1.S16 {Q4, Q5}, [r0]!
+ VLD1.S16 {Q6, Q7}, [r0]!
+ VMULL.S16 Q15, D0, D0
+ VMLAL.S16 Q15, D1, D1
+ VMLAL.S16 Q15, D2, D2
+ VMLAL.S16 Q15, D3, D3
+ VMLAL.S16 Q15, D4, D4
+ VMLAL.S16 Q15, D5, D5
+ VMLAL.S16 Q15, D6, D6
+ VMLAL.S16 Q15, D7, D7
+ VMLAL.S16 Q15, D8, D8
+ VMLAL.S16 Q15, D9, D9
+ VMLAL.S16 Q15, D10, D10
+ VMLAL.S16 Q15, D11, D11
+ VMLAL.S16 Q15, D12, D12
+ VMLAL.S16 Q15, D13, D13
+ VMLAL.S16 Q15, D14, D14
+ VMLAL.S16 Q15, D15, D15
+
+ CMP r2, #64
+ BEQ Lable1
+ VLD1.S16 {Q0, Q1}, [r0]!
+ VMLAL.S16 Q15, D0, D0
+ VMLAL.S16 Q15, D1, D1
+ VMLAL.S16 Q15, D2, D2
+ VMLAL.S16 Q15, D3, D3
+
+Lable1:
+
+ VQADD.S32 D30, D30, D31
+ VPADD.S32 D30, D30, D30
+ VMOV.S32 r12, D30[0]
+
+ ADD r12, r12, r12
+ ADD r12, r12, #1 @ L_sum = (L_sum << 1) + 1
+ MOV r4, r12
+ CMP r12, #0
+ RSBLT r4, r12, #0
+ CLZ r10, r4
+ SUB r10, r10, #1 @ sft = norm_l(L_sum)
+ MOV r0, r12, LSL r10 @ L_sum = L_sum << sft
+ RSB r11, r10, #30 @ *exp = 30 - sft
+ STRH r11, [r3]
+
+Dot_product12_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+
+ .end
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/Filt_6k_7k_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/Filt_6k_7k_neon.s
new file mode 100644
index 0000000..e0f992f
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/Filt_6k_7k_neon.s
@@ -0,0 +1,231 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@**********************************************************************/
+@void Filt_6k_7k(
+@ Word16 signal[], /* input: signal */
+@ Word16 lg, /* input: length of input */
+@ Word16 mem[] /* in/out: memory (size=30) */
+@)
+@***********************************************************************
+@ r0 --- signal[]
+@ r1 --- lg
+@ r2 --- mem[]
+
+ .section .text
+ .global Filt_6k_7k_asm
+ .extern fir_6k_7k
+ .hidden fir_6k_7k
+
+Filt_6k_7k_asm:
+
+ STMFD r13!, {r0 - r12, r14}
+ SUB r13, r13, #240 @ x[L_SUBFR16k + (L_FIR - 1)]
+ MOV r8, r0 @ copy signal[] address
+ MOV r5, r2 @ copy mem[] address
+
+ MOV r0, r2
+ MOV r1, r13
+
+ VLD1.S16 {D0, D1, D2, D3}, [r0]!
+ VLD1.S16 {D4, D5, D6, D7}, [r0]!
+
+ VST1.S16 {D0, D1, D2, D3}, [r1]!
+ VST1.S16 {D4, D5, D6}, [r1]!
+ VST1.S16 D7[0], [r1]!
+ VST1.S16 D7[1], [r1]!
+
+
+
+ ADR r3, Lable1 @ get fir_7k address
+ LDR r10, [r3]
+ ADD r10, r3
+ MOV r3, r8 @ change myMemCopy to Copy, due to Copy will change r3 content
+ ADD r6, r13, #60 @ get x[L_FIR - 1] address
+ MOV r7, r3 @ get signal[i]
+ @for (i = lg - 1@ i >= 0@ i--)
+ @{
+ @ x[i + L_FIR - 1] = signal[i] >> 2@
+ @}
+ VLD1.S16 {Q0, Q1}, [r7]! @ signal[0] ~ signal[15]
+ VLD1.S16 {Q2, Q3}, [r7]! @ signal[16] ~ signal[31]
+ VLD1.S16 {Q4, Q5}, [r7]! @ signal[32] ~ signal[47]
+ VLD1.S16 {Q6, Q7}, [r7]! @ signal[48] ~ signal[63]
+ VLD1.S16 {Q8, Q9}, [r7]! @ signal[64] ~ signal[79]
+ VSHR.S16 Q10, Q0, #2
+ VSHR.S16 Q11, Q1, #2
+ VSHR.S16 Q12, Q2, #2
+ VSHR.S16 Q13, Q3, #2
+ VST1.S16 {Q10, Q11}, [r6]!
+ VSHR.S16 Q0, Q4, #2
+ VSHR.S16 Q1, Q5, #2
+ VSHR.S16 Q10, Q6, #2
+ VSHR.S16 Q11, Q7, #2
+ VSHR.S16 Q2, Q8, #2
+ VSHR.S16 Q3, Q9, #2
+ VST1.S16 {Q12, Q13}, [r6]!
+ VST1.S16 {Q0, Q1}, [r6]!
+ VST1.S16 {Q10, Q11}, [r6]!
+ VST1.S16 {Q2, Q3}, [r6]!
+
+ MOV r12, r5
+ @STR r5, [sp, #-4] @ PUSH r5 to stack
+ @ not use registers: r4, r10, r12, r14, r5
+ MOV r4, r13
+ MOV r5, #0 @ i = 0
+
+ @ r4 --- x[i], r10 ---- fir_6k_7k
+ VLD1.S16 {Q0, Q1}, [r10]! @fir_6k_7k[0] ~ fir_6k_7k[15]
+ VLD1.S16 {Q2, Q3}, [r10]! @fir_6k_7k[16] ~ fir_6k_7k[31]
+ VMOV.S16 D7[3], r5 @set fir_6k_7K = 0
+
+ VLD1.S16 {Q4, Q5}, [r4]! @x[0] ~ x[15]
+ VLD1.S16 {Q6, Q7}, [r4]! @x[16] ~ X[31]
+ VLD1.S16 {Q8}, [r4]!
+ VMOV.S16 Q15, #0
+
+LOOP_6K7K:
+
+ VMULL.S16 Q9,D8,D0[0]
+ VMULL.S16 Q10,D9,D1[0]
+ VMULL.S16 Q11,D9,D0[0]
+ VMULL.S16 Q12,D10,D1[0]
+ VEXT.8 Q4,Q4,Q5,#2
+ VMLAL.S16 Q9,D10,D2[0]
+ VMLAL.S16 Q10,D11,D3[0]
+ VMLAL.S16 Q11,D11,D2[0]
+ VMLAL.S16 Q12,D12,D3[0]
+ VEXT.8 Q5,Q5,Q6,#2
+ VMLAL.S16 Q9,D12,D4[0]
+ VMLAL.S16 Q10,D13,D5[0]
+ VMLAL.S16 Q11,D13,D4[0]
+ VMLAL.S16 Q12,D14,D5[0]
+ VEXT.8 Q6,Q6,Q7,#2
+ VMLAL.S16 Q9,D14,D6[0]
+ VMLAL.S16 Q10,D15,D7[0]
+ VMLAL.S16 Q11,D15,D6[0]
+ VMLAL.S16 Q12,D16,D7[0]
+ VEXT.8 Q7,Q7,Q8,#2
+
+ VMLAL.S16 Q9,D8,D0[1]
+ VMLAL.S16 Q10,D9,D1[1]
+ VEXT.8 Q8,Q8,Q15,#2
+ VMLAL.S16 Q11,D9,D0[1]
+ VMLAL.S16 Q12,D10,D1[1]
+ VEXT.8 Q4,Q4,Q5,#2
+ VMLAL.S16 Q9,D10,D2[1]
+ VMLAL.S16 Q10,D11,D3[1]
+ VMLAL.S16 Q11,D11,D2[1]
+ VMLAL.S16 Q12,D12,D3[1]
+ VEXT.8 Q5,Q5,Q6,#2
+ VMLAL.S16 Q9,D12,D4[1]
+ VMLAL.S16 Q10,D13,D5[1]
+ VMLAL.S16 Q11,D13,D4[1]
+ VMLAL.S16 Q12,D14,D5[1]
+ VEXT.8 Q6,Q6,Q7,#2
+ VMLAL.S16 Q9,D14,D6[1]
+ VMLAL.S16 Q10,D15,D7[1]
+ VMLAL.S16 Q11,D15,D6[1]
+ VMLAL.S16 Q12,D16,D7[1]
+ VEXT.8 Q7,Q7,Q8,#2
+
+ VMLAL.S16 Q9,D8,D0[2]
+ VMLAL.S16 Q10,D9,D1[2]
+ VEXT.8 Q8,Q8,Q15,#2
+ VMLAL.S16 Q11,D9,D0[2]
+ VMLAL.S16 Q12,D10,D1[2]
+ VEXT.8 Q4,Q4,Q5,#2
+ VMLAL.S16 Q9,D10,D2[2]
+ VMLAL.S16 Q10,D11,D3[2]
+ VMLAL.S16 Q11,D11,D2[2]
+ VMLAL.S16 Q12,D12,D3[2]
+ VEXT.8 Q5,Q5,Q6,#2
+ VMLAL.S16 Q9,D12,D4[2]
+ VMLAL.S16 Q10,D13,D5[2]
+ VMLAL.S16 Q11,D13,D4[2]
+ VMLAL.S16 Q12,D14,D5[2]
+ VEXT.8 Q6,Q6,Q7,#2
+ VMLAL.S16 Q9,D14,D6[2]
+ VMLAL.S16 Q10,D15,D7[2]
+ VMLAL.S16 Q11,D15,D6[2]
+ VMLAL.S16 Q12,D16,D7[2]
+ VEXT.8 Q7,Q7,Q8,#2
+
+ VMLAL.S16 Q9,D8,D0[3]
+ VMLAL.S16 Q10,D9,D1[3]
+ VEXT.8 Q8,Q8,Q15,#2
+ VMLAL.S16 Q11,D9,D0[3]
+ VMLAL.S16 Q12,D10,D1[3]
+ VEXT.8 Q4,Q4,Q5,#2
+ VMLAL.S16 Q9,D10,D2[3]
+ VMLAL.S16 Q10,D11,D3[3]
+ VMLAL.S16 Q11,D11,D2[3]
+ VMLAL.S16 Q12,D12,D3[3]
+ VEXT.8 Q5,Q5,Q6,#2
+ VMLAL.S16 Q9,D12,D4[3]
+ VMLAL.S16 Q10,D13,D5[3]
+ VMLAL.S16 Q11,D13,D4[3]
+ VMLAL.S16 Q12,D14,D5[3]
+ VEXT.8 Q6,Q6,Q7,#2
+ VMLAL.S16 Q9,D14,D6[3]
+ VMLAL.S16 Q10,D15,D7[3]
+ VMLAL.S16 Q11,D15,D6[3]
+ VMLAL.S16 Q12,D16,D7[3]
+ VEXT.8 Q7,Q7,Q8,#2
+
+ VMOV.S16 D8,D9
+ VEXT.8 Q8,Q8,Q15,#2
+ VMOV.S16 D9,D10
+ VADD.S32 Q9,Q9,Q10
+ VMOV.S16 D10,D11
+ VMOV.S16 D11,D12
+ VADD.S32 Q11,Q11,Q12
+ VMOV.S16 D12,D13
+ VQRSHRN.S32 D28,Q9,#15
+ VMOV.S16 D13,D14
+ VMOV.S16 D14,D15
+ VQRSHRN.S32 D29,Q11,#15
+ VMOV.S16 D15,D16
+
+ VLD1.S16 {Q8},[r4]!
+ ADD r5, r5, #8
+ CMP r5, #80
+ VST1.S16 {D28,D29},[r3]!
+ BLT LOOP_6K7K
+
+ ADD r0, r13, #160 @x + lg
+ MOV r1, r12
+ @LDR r1, [sp, #-4] @mem address
+
+ VLD1.S16 {D0, D1, D2, D3}, [r0]!
+ VLD1.S16 {D4, D5, D6, D7}, [r0]!
+
+ VST1.S16 {D0, D1, D2, D3}, [r1]!
+ VST1.S16 {D4, D5, D6}, [r1]!
+ VST1.S16 D7[0], [r1]!
+ VST1.S16 D7[1], [r1]!
+
+Filt_6k_7k_end:
+
+ ADD r13, r13, #240
+ LDMFD r13!, {r0 - r12, r15}
+
+Lable1:
+ .word fir_6k_7k-Lable1
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/Norm_Corr_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/Norm_Corr_neon.s
new file mode 100644
index 0000000..28e6d6c
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/Norm_Corr_neon.s
@@ -0,0 +1,270 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@static void Norm_Corr (Word16 exc[], /* (i) : excitation buffer */
+@ Word16 xn[], /* (i) : target vector */
+@ Word16 h[], /* (i) Q15 : impulse response of synth/wgt filters */
+@ Word16 L_subfr, /* (i) : sub-frame length */
+@ Word16 t_min, /* (i) : minimum value of pitch lag. */
+@ Word16 t_max, /* (i) : maximum value of pitch lag. */
+@ Word16 corr_norm[]) /* (o) Q15 : normalized correlation */
+@
+
+@ r0 --- exc[]
+@ r1 --- xn[]
+@ r2 --- h[]
+@ r3 --- L_subfr
+@ r4 --- t_min
+@ r5 --- t_max
+@ r6 --- corr_norm[]
+
+
+ .section .text
+ .global Norm_corr_asm
+ .extern Convolve_asm
+ .extern Isqrt_n
+@******************************
+@ constant
+@******************************
+.equ EXC , 0
+.equ XN , 4
+.equ H , 8
+.equ L_SUBFR , 12
+.equ voSTACK , 172
+.equ T_MIN , 212
+.equ T_MAX , 216
+.equ CORR_NORM , 220
+
+Norm_corr_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r13, r13, #voSTACK
+
+ ADD r8, r13, #20 @get the excf[L_SUBFR]
+ LDR r4, [r13, #T_MIN] @get t_min
+ RSB r11, r4, #0 @k = -t_min
+ ADD r5, r0, r11, LSL #1 @get the &exc[k]
+
+ @transfer Convolve function
+ STMFD sp!, {r0 - r3}
+ MOV r0, r5
+ MOV r1, r2
+ MOV r2, r8 @r2 --- excf[]
+ BL Convolve_asm
+ LDMFD sp!, {r0 - r3}
+
+ @ r8 --- excf[]
+
+ MOV r14, r1 @copy xn[] address
+ MOV r7, #1
+ VLD1.S16 {Q0, Q1}, [r14]!
+ VLD1.S16 {Q2, Q3}, [r14]!
+ VLD1.S16 {Q4, Q5}, [r14]!
+ VLD1.S16 {Q6, Q7}, [r14]!
+
+ VMULL.S16 Q10, D0, D0
+ VMLAL.S16 Q10, D1, D1
+ VMLAL.S16 Q10, D2, D2
+ VMLAL.S16 Q10, D3, D3
+ VMLAL.S16 Q10, D4, D4
+ VMLAL.S16 Q10, D5, D5
+ VMLAL.S16 Q10, D6, D6
+ VMLAL.S16 Q10, D7, D7
+ VMLAL.S16 Q10, D8, D8
+ VMLAL.S16 Q10, D9, D9
+ VMLAL.S16 Q10, D10, D10
+ VMLAL.S16 Q10, D11, D11
+ VMLAL.S16 Q10, D12, D12
+ VMLAL.S16 Q10, D13, D13
+ VMLAL.S16 Q10, D14, D14
+ VMLAL.S16 Q10, D15, D15
+
+ VQADD.S32 D20, D20, D21
+ VMOV.S32 r9, D20[0]
+ VMOV.S32 r10, D20[1]
+ QADD r6, r9, r10
+ QADD r6, r6, r6
+ QADD r9, r6, r7 @L_tmp = (L_tmp << 1) + 1;
+ CLZ r7, r9
+ SUB r6, r7, #1 @exp = norm_l(L_tmp)
+ RSB r7, r6, #32 @exp = 32 - exp
+ MOV r6, r7, ASR #1
+ RSB r7, r6, #0 @scale = -(exp >> 1)
+
+ @loop for every possible period
+ @for(t = t_min@ t <= t_max@ t++)
+ @r7 --- scale r4 --- t_min r8 --- excf[]
+
+LOOPFOR:
+ ADD r14, r13, #20 @copy of excf[]
+ MOV r12, r1 @copy of xn[]
+ MOV r8, #0x8000
+
+ VLD1.S16 {Q0, Q1}, [r14]! @ load 16 excf[]
+ VLD1.S16 {Q2, Q3}, [r14]! @ load 16 excf[]
+ VLD1.S16 {Q4, Q5}, [r12]! @ load 16 x[]
+ VLD1.S16 {Q6, Q7}, [r12]! @ load 16 x[]
+ VMULL.S16 Q10, D0, D0 @L_tmp1 += excf[] * excf[]
+ VMULL.S16 Q11, D0, D8 @L_tmp += x[] * excf[]
+ VMLAL.S16 Q10, D1, D1
+ VMLAL.S16 Q11, D1, D9
+ VMLAL.S16 Q10, D2, D2
+ VMLAL.S16 Q11, D2, D10
+ VMLAL.S16 Q10, D3, D3
+ VMLAL.S16 Q11, D3, D11
+ VMLAL.S16 Q10, D4, D4
+ VMLAL.S16 Q11, D4, D12
+ VMLAL.S16 Q10, D5, D5
+ VMLAL.S16 Q11, D5, D13
+ VMLAL.S16 Q10, D6, D6
+ VMLAL.S16 Q11, D6, D14
+ VMLAL.S16 Q10, D7, D7
+ VMLAL.S16 Q11, D7, D15
+
+ VLD1.S16 {Q0, Q1}, [r14]! @ load 16 excf[]
+ VLD1.S16 {Q2, Q3}, [r14]! @ load 16 excf[]
+ VLD1.S16 {Q4, Q5}, [r12]! @ load 16 x[]
+ VLD1.S16 {Q6, Q7}, [r12]! @ load 16 x[]
+ VMLAL.S16 Q10, D0, D0
+ VMLAL.S16 Q11, D0, D8
+ VMLAL.S16 Q10, D1, D1
+ VMLAL.S16 Q11, D1, D9
+ VMLAL.S16 Q10, D2, D2
+ VMLAL.S16 Q11, D2, D10
+ VMLAL.S16 Q10, D3, D3
+ VMLAL.S16 Q11, D3, D11
+ VMLAL.S16 Q10, D4, D4
+ VMLAL.S16 Q11, D4, D12
+ VMLAL.S16 Q10, D5, D5
+ VMLAL.S16 Q11, D5, D13
+ VMLAL.S16 Q10, D6, D6
+ VMLAL.S16 Q11, D6, D14
+ VMLAL.S16 Q10, D7, D7
+ VMLAL.S16 Q11, D7, D15
+
+ VQADD.S32 D20, D20, D21
+ VQADD.S32 D22, D22, D23
+
+ VPADD.S32 D20, D20, D20 @D20[0] --- L_tmp1 << 1
+ VPADD.S32 D22, D22, D22 @D22[0] --- L_tmp << 1
+
+ VMOV.S32 r6, D20[0]
+ VMOV.S32 r5, D22[0]
+
+ @r5 --- L_tmp, r6 --- L_tmp1
+ MOV r10, #1
+ ADD r5, r10, r5, LSL #1 @L_tmp = (L_tmp << 1) + 1
+ ADD r6, r10, r6, LSL #1 @L_tmp1 = (L_tmp1 << 1) + 1
+
+ CLZ r10, r5
+ CMP r5, #0
+ RSBLT r11, r5, #0
+ CLZLT r10, r11
+ SUB r10, r10, #1 @exp = norm_l(L_tmp)
+
+ MOV r5, r5, LSL r10 @L_tmp = (L_tmp << exp)
+ RSB r10, r10, #30 @exp_corr = 30 - exp
+ MOV r11, r5, ASR #16 @corr = extract_h(L_tmp)
+
+ CLZ r5, r6
+ SUB r5, r5, #1
+ MOV r6, r6, LSL r5 @L_tmp = (L_tmp1 << exp)
+ RSB r5, r5, #30 @exp_norm = 30 - exp
+
+ @r10 --- exp_corr, r11 --- corr
+ @r6 --- L_tmp, r5 --- exp_norm
+
+ @Isqrt_n(&L_tmp, &exp_norm)
+
+ MOV r14, r0
+ MOV r12, r1
+
+ STMFD sp!, {r0 - r4, r7 - r12, r14}
+ ADD r1, sp, #4
+ ADD r0, sp, #0
+ STR r6, [sp]
+ STRH r5, [sp, #4]
+ BL Isqrt_n
+ LDR r6, [sp]
+ LDRSH r5, [sp, #4]
+ LDMFD sp!, {r0 - r4, r7 - r12, r14}
+ MOV r0, r14
+ MOV r1, r12
+
+
+ MOV r6, r6, ASR #16 @norm = extract_h(L_tmp)
+ MUL r12, r6, r11
+ ADD r12, r12, r12 @L_tmp = vo_L_mult(corr, norm)
+
+ ADD r6, r10, r5
+ ADD r6, r6, r7 @exp_corr + exp_norm + scale
+
+ CMP r6, #0
+ RSBLT r6, r6, #0
+ MOVLT r12, r12, ASR r6
+ MOVGT r12, r12, LSL r6 @L_tmp = L_shl(L_tmp, exp_corr + exp_norm + scale)
+
+ ADD r12, r12, r8
+ MOV r12, r12, ASR #16 @vo_round(L_tmp)
+
+ LDR r5, [r13, #CORR_NORM] @ get corr_norm address
+ LDR r6, [r13, #T_MAX] @ get t_max
+ ADD r10, r5, r4, LSL #1 @ get corr_norm[t] address
+ STRH r12, [r10] @ corr_norm[t] = vo_round(L_tmp)
+
+ CMP r4, r6
+ BEQ Norm_corr_asm_end
+
+ ADD r4, r4, #1 @ t_min ++
+ RSB r5, r4, #0 @ k
+
+ MOV r6, #63 @ i = 63
+ MOV r8, r0 @ exc[]
+ MOV r9, r2 @ h[]
+ ADD r10, r13, #20 @ excf[]
+
+ ADD r8, r8, r5, LSL #1 @ exc[k] address
+ ADD r9, r9, r6, LSL #1 @ h[i] address
+ ADD r10, r10, r6, LSL #1 @ excf[i] address
+ LDRSH r11, [r8] @ tmp = exc[k]
+
+LOOPK:
+ LDRSH r8, [r9], #-2 @ load h[i]
+ LDRSH r12, [r10, #-2] @ load excf[i - 1]
+ MUL r14, r11, r8
+ MOV r8, r14, ASR #15
+ ADD r14, r8, r12
+ STRH r14, [r10], #-2
+ SUBS r6, r6, #1
+ BGT LOOPK
+
+ LDRSH r8, [r9] @ load h[0]
+ MUL r14, r11, r8
+ LDR r6, [r13, #T_MAX] @ get t_max
+ MOV r8, r14, ASR #15
+ STRH r8, [r10]
+
+ CMP r4, r6
+ BLE LOOPFOR
+
+Norm_corr_asm_end:
+
+ ADD r13, r13, #voSTACK
+ LDMFD r13!, {r4 - r12, r15}
+
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/Syn_filt_32_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/Syn_filt_32_neon.s
new file mode 100644
index 0000000..9687431
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/Syn_filt_32_neon.s
@@ -0,0 +1,133 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@**********************************************************************/
+@void Syn_filt_32(
+@ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+@ Word16 m, /* (i) : order of LP filter */
+@ Word16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
+@ Word16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
+@ Word16 sig_hi[], /* (o) /16 : synthesis high */
+@ Word16 sig_lo[], /* (o) /16 : synthesis low */
+@ Word16 lg /* (i) : size of filtering */
+@)
+@***********************************************************************
+@ a[] --- r0
+@ m --- r1
+@ exc[] --- r2
+@ Qnew --- r3
+@ sig_hi[] --- r4
+@ sig_lo[] --- r5
+@ lg --- r6
+
+ .section .text
+ .global Syn_filt_32_asm
+
+Syn_filt_32_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ LDR r4, [r13, #40] @ get sig_hi[] address
+ LDR r5, [r13, #44] @ get sig_lo[] address
+
+ LDRSH r6, [r0], #2 @ load Aq[0]
+ ADD r7, r3, #4 @ 4 + Q_new
+ MOV r3, r6, ASR r7 @ a0 = Aq[0] >> (4 + Q_new)
+
+ SUB r10, r4, #32 @ sig_hi[-16] address
+ SUB r11, r5, #32 @ sig_lo[-16] address
+
+ VLD1.S16 {D0, D1, D2, D3}, [r0]! @a[1] ~ a[16]
+
+ MOV r8, #0 @ i = 0
+
+ VLD1.S16 {D4, D5, D6, D7}, [r10]! @ sig_hi[-16] ~ sig_hi[-1]
+ VREV64.16 D0, D0
+ VREV64.16 D1, D1
+ VLD1.S16 {D8, D9, D10, D11}, [r11]! @ sig_lo[-16] ~ sig_lo[-1]
+ VREV64.16 D2, D2
+ VREV64.16 D3, D3
+ VDUP.S32 Q15, r8
+
+SYN_LOOP:
+
+ LDRSH r6, [r2], #2 @exc[i]
+ @L_tmp = L_msu(L_tmp, sig_lo[i - j], a[j])@
+ VMULL.S16 Q10, D8, D3
+ VEXT.8 D8, D8, D9, #2
+ VMLAL.S16 Q10, D9, D2
+ VMLAL.S16 Q10, D10, D1
+ VMLAL.S16 Q10, D11, D0
+
+ VEXT.8 D9, D9, D10, #2
+ VEXT.8 D10, D10, D11, #2
+
+ VPADD.S32 D28, D20, D21
+ MUL r12, r6, r3 @exc[i] * a0
+ VPADD.S32 D29, D28, D28
+ VDUP.S32 Q10, D29[0] @result1
+
+ VMULL.S16 Q11, D4, D3
+ VMLAL.S16 Q11, D5, D2
+ VSUB.S32 Q10, Q15, Q10
+ @L_tmp = L_msu(L_tmp, sig_hi[i - j], a[j])@
+
+ VMLAL.S16 Q11, D6, D1
+ VEXT.8 D4, D4, D5, #2
+ VMLAL.S16 Q11, D7, D0
+
+
+ VEXT.8 D5, D5, D6, #2
+ VEXT.8 D6, D6, D7, #2
+
+ VPADD.S32 D28, D22, D23
+ VPADD.S32 D29, D28, D28
+ MOV r14, r12, LSL #1 @exc[i] * a0 << 1
+ VDUP.S32 Q11, D29[0] @result2
+
+
+
+ VSHR.S32 Q10, Q10, #11 @result1 >>= 11
+ VSHL.S32 Q11, Q11, #1 @result2 <<= 1
+ VDUP.S32 Q12, r14
+ VADD.S32 Q12, Q12, Q10 @L_tmp = L_tmp - (result1 >>= 11) - (result2 <<= 1)
+ VSUB.S32 Q12, Q12, Q11
+
+ VSHL.S32 Q12, Q12, #3 @L_tmp <<= 3
+
+
+ VSHRN.S32 D20, Q12, #16 @sig_hi[i] = L_tmp >> 16@
+ VMOV.S16 r10, D20[0]
+ VSHR.S32 Q12, Q12, #4 @L_tmp >>= 4
+ VEXT.8 D7, D7, D20, #2
+ STRH r10, [r4], #2 @store sig_hi[i]
+ VMOV.S32 r11, D24[0] @r11 --- L_tmp >>= 4
+ ADD r8, r8, #1
+ SUB r12, r11, r10, LSL #12
+ @MOV r11, r12, ASR #16 @sig_lo[i]
+ VDUP.S16 D21, r12
+ VEXT.8 D11, D11, D21, #2
+ STRH r12, [r5], #2 @stroe sig_lo[i]
+
+ CMP r8, #64
+ BLT SYN_LOOP
+
+Syn_filt_32_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/convolve_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/convolve_neon.s
new file mode 100644
index 0000000..9fb3a6e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/convolve_neon.s
@@ -0,0 +1,178 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@*void Convolve (
+@* Word16 x[], /* (i) : input vector */
+@* Word16 h[], /* (i) : impulse response */
+@* Word16 y[], /* (o) : output vector */
+@* Word16 L /* (i) : vector size */
+@*)
+@
+@ r0 --- x[]
+@ r1 --- h[]
+@ r2 --- y[]
+@ r3 --- L
+
+ .section .text
+ .global Convolve_asm
+
+Convolve_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ MOV r3, #0
+ MOV r11, #0x8000
+
+LOOP:
+ @MOV r8, #0 @ s = 0
+ ADD r4, r1, r3, LSL #1 @ tmpH address
+ ADD r5, r3, #1 @ i = n + 1
+ MOV r6, r0
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4] @ *tmpH--
+ SUB r5, r5, #1
+ VMOV.S32 Q10, #0
+ MUL r8, r9, r10
+
+LOOP1:
+ CMP r5, #0
+ BLE L1
+ SUB r4, r4, #8
+ MOV r9, r4
+ VLD1.S16 D0, [r6]!
+ VLD1.S16 D1, [r9]!
+ VREV64.16 D1, D1
+ SUBS r5, r5, #4
+ VMLAL.S16 Q10, D0, D1
+ B LOOP1
+L1:
+ VADD.S32 D20, D20, D21
+ VPADD.S32 D20, D20, D20
+ VMOV.S32 r5, D20[0]
+ ADD r5, r5, r8
+ ADD r5, r11, r5, LSL #1
+ MOV r5, r5, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r5, [r2], #2 @y[n]
+
+
+ @MOV r8, #0
+ ADD r4, r1, r3, LSL #1 @tmpH address
+ ADD r5, r3, #1
+ MOV r6, r0
+ LDRSH r9, [r6], #2 @ *tmpX++
+ LDRSH r10, [r4], #-2
+ LDRSH r12, [r6], #2
+ LDRSH r14, [r4]
+
+ MUL r8, r9, r10
+ SUB r5, r5, #2
+ MLA r8, r12, r14, r8
+
+ VMOV.S32 Q10, #0
+LOOP2:
+ CMP r5, #0
+ BLE L2
+ SUB r4, r4, #8
+ MOV r9, r4
+ VLD1.S16 D0, [r6]!
+ VLD1.S16 D1, [r9]!
+ SUBS r5, r5, #4
+ VREV64.16 D1, D1
+ VMLAL.S16 Q10, D0, D1
+ B LOOP2
+L2:
+ VADD.S32 D20, D20, D21
+ VPADD.S32 D20, D20, D20
+ VMOV.S32 r5, D20[0]
+ ADD r8, r8, r5
+ ADD r8, r11, r8, LSL #1
+ MOV r8, r8, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r8, [r2], #2 @y[n]
+
+
+ @MOV r8, #0
+ ADD r4, r1, r3, LSL #1
+ ADD r5, r3, #1
+ MOV r6, r0
+ LDRSH r9, [r6], #2
+ LDRSH r10, [r4], #-2
+ LDRSH r12, [r6], #2
+ LDRSH r14, [r4], #-2
+ MUL r8, r9, r10
+ LDRSH r9, [r6], #2
+ LDRSH r10, [r4]
+ MLA r8, r12, r14, r8
+ SUB r5, r5, #3
+ MLA r8, r9, r10, r8
+
+ VMOV.S32 Q10, #0
+LOOP3:
+ CMP r5, #0
+ BLE L3
+ SUB r4, r4, #8
+ MOV r9, r4
+ VLD1.S16 D0, [r6]!
+ VLD1.S16 D1, [r9]!
+ VREV64.16 D1, D1
+ SUBS r5, r5, #4
+ VMLAL.S16 Q10, D0, D1
+ B LOOP3
+
+L3:
+ VADD.S32 D20, D20, D21
+ VPADD.S32 D20, D20, D20
+ VMOV.S32 r5, D20[0]
+ ADD r8, r8, r5
+ ADD r8, r11, r8, LSL #1
+ MOV r8, r8, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r8, [r2], #2 @y[n]
+
+ ADD r5, r3, #1 @ i = n + 1
+ ADD r4, r1, r5, LSL #1 @ tmpH address
+ MOV r6, r0
+ VMOV.S32 Q10, #0
+LOOP4:
+ CMP r5, #0
+ BLE L4
+ SUB r4, r4, #8
+ MOV r9, r4
+ VLD1.S16 D0, [r6]!
+ VLD1.S16 D1, [r9]!
+ VREV64.16 D1, D1
+ SUBS r5, r5, #4
+ VMLAL.S16 Q10, D0, D1
+ B LOOP4
+L4:
+ VADD.S32 D20, D20, D21
+ VPADD.S32 D20, D20, D20
+ VMOV.S32 r5, D20[0]
+ ADD r5, r11, r5, LSL #1
+ MOV r5, r5, LSR #16 @extract_h(s)
+ ADD r3, r3, #1
+ STRH r5, [r2], #2 @y[n]
+
+ CMP r3, #64
+ BLT LOOP
+
+Convolve_asm_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+
+ @ENDFUNC
+ .end
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/cor_h_vec_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/cor_h_vec_neon.s
new file mode 100644
index 0000000..a4deda3
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/cor_h_vec_neon.s
@@ -0,0 +1,151 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@static void cor_h_vec_012(
+@ Word16 h[], /* (i) scaled impulse response */
+@ Word16 vec[], /* (i) scaled vector (/8) to correlate with h[] */
+@ Word16 track, /* (i) track to use */
+@ Word16 sign[], /* (i) sign vector */
+@ Word16 rrixix[][NB_POS], /* (i) correlation of h[x] with h[x] */
+@ Word16 cor_1[], /* (o) result of correlation (NB_POS elements) */
+@ Word16 cor_2[] /* (o) result of correlation (NB_POS elements) */
+@)
+@r0 ---- h[]
+@r1 ---- vec[]
+@r2 ---- track
+@r3 ---- sign[]
+@r4 ---- rrixix[][NB_POS]
+@r5 ---- cor_1[]
+@r6 ---- cor_2[]
+
+ .section .text
+ .global cor_h_vec_012_asm
+
+cor_h_vec_012_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ LDR r4, [r13, #40] @load rrixix[][NB_POS]
+ ADD r7, r4, r2, LSL #5 @r7 --- p0 = rrixix[track]
+ MOV r4, #0 @i=0
+
+ @r0 --- h[], r1 --- vec[], r2 --- pos
+ @r3 --- sign[], r4 --- i, r7 --- p0
+
+LOOPi:
+ MOV r5, #0 @L_sum1 = 0
+ MOV r6, #0 @L_sum2 = 0
+ ADD r9, r1, r2, LSL #1 @p2 = &vec[pos]
+ MOV r10, r0 @p1 = h
+ RSB r11, r2, #62 @j=62-pos
+
+LOOPj1:
+ LDRSH r12, [r10], #2
+ LDRSH r8, [r9], #2
+ LDRSH r14, [r9]
+ SUBS r11, r11, #1
+ MLA r5, r12, r8, r5
+ MLA r6, r12, r14, r6
+ BGE LOOPj1
+
+ LDRSH r12, [r10], #2 @*p1++
+ MOV r6, r6, LSL #2 @L_sum2 = (L_sum2 << 2)
+ MLA r5, r12, r14, r5
+ MOV r14, #0x8000
+ MOV r5, r5, LSL #2 @L_sum1 = (L_sum1 << 2)
+ ADD r10, r6, r14
+ ADD r9, r5, r14
+ MOV r5, r9, ASR #16
+ MOV r6, r10, ASR #16
+ ADD r9, r3, r2, LSL #1 @address of sign[pos]
+ ADD r8, r7, #32
+ LDRSH r10, [r9], #2 @sign[pos]
+ LDRSH r11, [r9] @sign[pos + 1]
+ MUL r12, r5, r10
+ MUL r14, r6, r11
+ MOV r5, r12, ASR #15
+ MOV r6, r14, ASR #15
+ LDR r9, [r13, #44]
+ LDR r12, [r13, #48]
+ LDRSH r10, [r7], #2 @*p0++
+ LDRSH r11, [r8] @*p3++
+ ADD r9, r9, r4, LSL #1
+ ADD r12, r12, r4, LSL #1
+ ADD r5, r5, r10
+ ADD r6, r6, r11
+ STRH r5, [r9]
+ STRH r6, [r12]
+
+ ADD r2, r2, #4
+
+ MOV r5, #0 @L_sum1 = 0
+ MOV r6, #0 @L_sum2 = 0
+ ADD r9, r1, r2, LSL #1 @p2 = &vec[pos]
+ MOV r10, r0 @p1 = h
+ RSB r11, r2, #62 @j=62-pos
+ ADD r4, r4, #1 @i++
+
+LOOPj2:
+ LDRSH r12, [r10], #2
+ LDRSH r8, [r9], #2
+ LDRSH r14, [r9]
+ SUBS r11, r11, #1
+ MLA r5, r12, r8, r5
+ MLA r6, r12, r14, r6
+ BGE LOOPj2
+
+ LDRSH r12, [r10], #2 @*p1++
+ MOV r6, r6, LSL #2 @L_sum2 = (L_sum2 << 2)
+ MLA r5, r12, r14, r5
+ MOV r14, #0x8000
+ MOV r5, r5, LSL #2 @L_sum1 = (L_sum1 << 2)
+ ADD r10, r6, r14
+ ADD r9, r5, r14
+
+ MOV r5, r9, ASR #16
+ MOV r6, r10, ASR #16
+ ADD r9, r3, r2, LSL #1 @address of sign[pos]
+ ADD r8, r7, #32
+ LDRSH r10, [r9], #2 @sign[pos]
+ LDRSH r11, [r9] @sign[pos + 1]
+ MUL r12, r5, r10
+ MUL r14, r6, r11
+ MOV r5, r12, ASR #15
+ MOV r6, r14, ASR #15
+ LDR r9, [r13, #44]
+ LDR r12, [r13, #48]
+ LDRSH r10, [r7], #2 @*p0++
+ LDRSH r11, [r8] @*p3++
+ ADD r9, r9, r4, LSL #1
+ ADD r12, r12, r4, LSL #1
+ ADD r5, r5, r10
+ ADD r6, r6, r11
+ STRH r5, [r9]
+ STRH r6, [r12]
+ ADD r4, r4, #1 @i+1
+ ADD r2, r2, #4 @pos += STEP
+ CMP r4, #16
+
+ BLT LOOPi
+
+the_end:
+ LDMFD r13!, {r4 - r12, r15}
+
+ .end
+
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/pred_lt4_1_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/pred_lt4_1_neon.s
new file mode 100644
index 0000000..f8b634f
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/pred_lt4_1_neon.s
@@ -0,0 +1,103 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Pred_lt4(
+@ Word16 exc[], /* in/out: excitation buffer */
+@ Word16 T0, /* input : integer pitch lag */
+@ Word16 frac, /* input : fraction of lag */
+@ Word16 L_subfr /* input : subframe size */
+@)
+@***********************************************************************
+@ r0 --- exc[]
+@ r1 --- T0
+@ r2 --- frac
+@ r3 --- L_subfr
+
+ .section .text
+ .global pred_lt4_asm
+ .extern inter4_2
+ .hidden inter4_2
+
+pred_lt4_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r4, r0, r1, LSL #1 @ x = exc - T0
+ RSB r2, r2, #0 @ frac = - frac
+ SUB r4, r4, #30 @ x -= L_INTERPOL2 - 1
+ CMP r2, #0
+ ADDLT r2, r2, #4 @ frac += UP_SAMP
+ SUBLT r4, r4, #2 @ x--
+
+ ADR r8, Lable1
+ LDR r11, [r8]
+ ADD r11, r8
+ RSB r2, r2, #3 @ k = UP_SAMP - 1 - frac
+ MOV r8, #0 @ j = 0
+ ADD r11, r11, r2, LSL #6 @ get inter4_2[k][]
+
+ VLD1.S16 {Q0, Q1}, [r11]!
+ VLD1.S16 {Q2, Q3}, [r11]!
+
+ MOV r6, #0x8000
+
+ VLD1.S16 {Q4, Q5}, [r4]! @load 16 x[]
+ VLD1.S16 {Q6, Q7}, [r4]! @load 16 x[]
+
+LOOP:
+ VQDMULL.S16 Q15, D8, D0
+ VQDMLAL.S16 Q15, D9, D1
+ VQDMLAL.S16 Q15, D10, D2
+ VQDMLAL.S16 Q15, D11, D3
+
+ VQDMLAL.S16 Q15, D12, D4
+ VQDMLAL.S16 Q15, D13, D5
+ VQDMLAL.S16 Q15, D14, D6
+ VQDMLAL.S16 Q15, D15, D7
+
+ LDRSH r12, [r4], #2
+
+ VEXT.S16 D8, D8, D9, #1
+ VEXT.S16 D9, D9, D10, #1
+ VEXT.S16 D10, D10, D11, #1
+ VEXT.S16 D11, D11, D12, #1
+ VDUP.S16 D24, r12
+ VEXT.S16 D12, D12, D13, #1
+ VEXT.S16 D13, D13, D14, #1
+
+ VQADD.S32 D30, D30, D31
+ MOV r11, #0x8000
+ VPADD.S32 D30, D30, D30
+ ADD r8, r8, #1
+ VMOV.S32 r12, D30[0]
+ VEXT.S16 D14, D14, D15, #1
+
+ QADD r1, r12, r12 @ L_sum = (L_sum << 2)
+ VEXT.S16 D15, D15, D24, #1
+ QADD r5, r1, r6
+ MOV r1, r5, ASR #16
+ CMP r8, r3
+ STRH r1, [r0], #2 @ exc[j] = (L_sum + 0x8000) >> 16
+ BLT LOOP
+
+pred_lt4_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+
+Lable1:
+ .word inter4_2-Lable1
+ @ENDFUNC
+ .end
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/residu_asm_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/residu_asm_neon.s
new file mode 100644
index 0000000..bc3d780
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/residu_asm_neon.s
@@ -0,0 +1,127 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Residu (
+@ Word16 a[], /* (i) : prediction coefficients */
+@ Word16 x[], /* (i) : speech signal */
+@ Word16 y[], /* (o) : residual signal */
+@ Word16 lg /* (i) : size of filtering */
+@)
+@a[] RN r0
+@x[] RN r1
+@y[] RN r2
+@lg RN r3
+
+ .section .text
+ .global Residu_opt
+
+Residu_opt:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r7, r3, #4 @i = lg - 4
+
+ VLD1.S16 {D0, D1, D2, D3}, [r0]! @get all a[]
+ VLD1.S16 {D4}, [r0]!
+ VMOV.S32 Q8, #0x8000
+
+LOOP1:
+ ADD r9, r1, r7, LSL #1 @copy the address
+ ADD r10, r2, r7, LSL #1
+ MOV r8, r9
+ VLD1.S16 D5, [r8]! @get x[i], x[i+1], x[i+2], x[i+3]
+ VQDMULL.S16 Q10, D5, D0[0] @finish the first L_mult
+
+ SUB r8, r9, #2 @get the x[i-1] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D0[1]
+
+ SUB r8, r9, #4 @load the x[i-2] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D0[2]
+
+ SUB r8, r9, #6 @load the x[i-3] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D0[3]
+
+ SUB r8, r9, #8 @load the x[i-4] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D1[0]
+
+ SUB r8, r9, #10 @load the x[i-5] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D1[1]
+
+ SUB r8, r9, #12 @load the x[i-6] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D1[2]
+
+ SUB r8, r9, #14 @load the x[i-7] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D1[3]
+
+ SUB r8, r9, #16 @load the x[i-8] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D2[0]
+
+ SUB r8, r9, #18 @load the x[i-9] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D2[1]
+
+ SUB r8, r9, #20 @load the x[i-10] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D2[2]
+
+ SUB r8, r9, #22 @load the x[i-11] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D2[3]
+
+ SUB r8, r9, #24 @load the x[i-12] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D3[0]
+
+ SUB r8, r9, #26 @load the x[i-13] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D3[1]
+
+ SUB r8, r9, #28 @load the x[i-14] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D3[2]
+
+ SUB r8, r9, #30 @load the x[i-15] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D3[3]
+
+ SUB r8, r9, #32 @load the x[i-16] address
+ VLD1.S16 D5, [r8]!
+ VQDMLAL.S16 Q10, D5, D4[0]
+
+ SUB r7, r7, #4 @i-=4
+ VQSHL.S32 Q10, Q10, #4
+ VQADD.S32 Q10, Q10, Q8
+ VSHRN.S32 D5, Q10, #16
+ VST1.S16 D5, [r10]!
+ CMP r7, #0
+
+ BGE LOOP1
+
+Residu_asm_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/scale_sig_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/scale_sig_neon.s
new file mode 100644
index 0000000..89c0572
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/scale_sig_neon.s
@@ -0,0 +1,138 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@**********************************************************************/
+@void Scale_sig(
+@ Word16 x[], /* (i/o) : signal to scale */
+@ Word16 lg, /* (i) : size of x[] */
+@ Word16 exp /* (i) : exponent: x = round(x << exp) */
+@)
+@***********************************************************************
+@ x[] --- r0
+@ lg --- r1
+@ exp --- r2
+
+ .section .text
+ .global Scale_sig_opt
+
+Scale_sig_opt:
+
+ STMFD r13!, {r4 - r12, r14}
+ MOV r4, #4
+ VMOV.S32 Q15, #0x8000
+ VDUP.S32 Q14, r2
+ MOV r5, r0 @ copy x[] address
+ CMP r1, #64
+ MOVEQ r4, #1
+ BEQ LOOP
+ CMP r1, #128
+ MOVEQ r4, #2
+ BEQ LOOP
+ CMP r1, #256
+ BEQ LOOP
+ CMP r1, #80
+ MOVEQ r4, #1
+ BEQ LOOP1
+
+LOOP1:
+ VLD1.S16 {Q0, Q1}, [r5]! @load 16 Word16 x[]
+ VSHLL.S16 Q10, D0, #16
+ VSHLL.S16 Q11, D1, #16
+ VSHLL.S16 Q12, D2, #16
+ VSHLL.S16 Q13, D3, #16
+ VSHL.S32 Q10, Q10, Q14
+ VSHL.S32 Q11, Q11, Q14
+ VSHL.S32 Q12, Q12, Q14
+ VSHL.S32 Q13, Q13, Q14
+ VADDHN.S32 D16, Q10, Q15
+ VADDHN.S32 D17, Q11, Q15
+ VADDHN.S32 D18, Q12, Q15
+ VADDHN.S32 D19, Q13, Q15
+ VST1.S16 {Q8, Q9}, [r0]! @store 16 Word16 x[]
+
+LOOP:
+ VLD1.S16 {Q0, Q1}, [r5]! @load 16 Word16 x[]
+ VLD1.S16 {Q2, Q3}, [r5]! @load 16 Word16 x[]
+ VLD1.S16 {Q4, Q5}, [r5]! @load 16 Word16 x[]
+ VLD1.S16 {Q6, Q7}, [r5]! @load 16 Word16 x[]
+
+ VSHLL.S16 Q8, D0, #16
+ VSHLL.S16 Q9, D1, #16
+ VSHLL.S16 Q10, D2, #16
+ VSHLL.S16 Q11, D3, #16
+ VSHL.S32 Q8, Q8, Q14
+ VSHL.S32 Q9, Q9, Q14
+ VSHL.S32 Q10, Q10, Q14
+ VSHL.S32 Q11, Q11, Q14
+ VADDHN.S32 D16, Q8, Q15
+ VADDHN.S32 D17, Q9, Q15
+ VADDHN.S32 D18, Q10, Q15
+ VADDHN.S32 D19, Q11, Q15
+ VST1.S16 {Q8, Q9}, [r0]! @store 16 Word16 x[]
+
+
+ VSHLL.S16 Q12, D4, #16
+ VSHLL.S16 Q13, D5, #16
+ VSHLL.S16 Q10, D6, #16
+ VSHLL.S16 Q11, D7, #16
+ VSHL.S32 Q12, Q12, Q14
+ VSHL.S32 Q13, Q13, Q14
+ VSHL.S32 Q10, Q10, Q14
+ VSHL.S32 Q11, Q11, Q14
+ VADDHN.S32 D16, Q12, Q15
+ VADDHN.S32 D17, Q13, Q15
+ VADDHN.S32 D18, Q10, Q15
+ VADDHN.S32 D19, Q11, Q15
+ VST1.S16 {Q8, Q9}, [r0]! @store 16 Word16 x[]
+
+ VSHLL.S16 Q10, D8, #16
+ VSHLL.S16 Q11, D9, #16
+ VSHLL.S16 Q12, D10, #16
+ VSHLL.S16 Q13, D11, #16
+ VSHL.S32 Q10, Q10, Q14
+ VSHL.S32 Q11, Q11, Q14
+ VSHL.S32 Q12, Q12, Q14
+ VSHL.S32 Q13, Q13, Q14
+ VADDHN.S32 D16, Q10, Q15
+ VADDHN.S32 D17, Q11, Q15
+ VADDHN.S32 D18, Q12, Q15
+ VADDHN.S32 D19, Q13, Q15
+ VST1.S16 {Q8, Q9}, [r0]! @store 16 Word16 x[]
+
+ VSHLL.S16 Q10, D12, #16
+ VSHLL.S16 Q11, D13, #16
+ VSHLL.S16 Q12, D14, #16
+ VSHLL.S16 Q13, D15, #16
+ VSHL.S32 Q10, Q10, Q14
+ VSHL.S32 Q11, Q11, Q14
+ VSHL.S32 Q12, Q12, Q14
+ VSHL.S32 Q13, Q13, Q14
+ VADDHN.S32 D16, Q10, Q15
+ VADDHN.S32 D17, Q11, Q15
+ VADDHN.S32 D18, Q12, Q15
+ VADDHN.S32 D19, Q13, Q15
+ VST1.S16 {Q8, Q9}, [r0]! @store 16 Word16 x[]
+ SUBS r4, r4, #1
+ BGT LOOP
+
+
+Scale_sig_asm_end:
+
+ LDMFD r13!, {r4 - r12, r15}
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/asm/ARMV7/syn_filt_neon.s b/media/codecs/amrwb/enc/src/asm/ARMV7/syn_filt_neon.s
new file mode 100644
index 0000000..029560e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/asm/ARMV7/syn_filt_neon.s
@@ -0,0 +1,106 @@
+@/*
+@ ** Copyright 2003-2010, VisualOn, Inc.
+@ **
+@ ** Licensed under the Apache License, Version 2.0 (the "License");
+@ ** you may not use this file except in compliance with the License.
+@ ** You may obtain a copy of the License at
+@ **
+@ ** http://www.apache.org/licenses/LICENSE-2.0
+@ **
+@ ** Unless required by applicable law or agreed to in writing, software
+@ ** distributed under the License is distributed on an "AS IS" BASIS,
+@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@ ** See the License for the specific language governing permissions and
+@ ** limitations under the License.
+@ */
+@
+@void Syn_filt(
+@ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+@ Word16 x[], /* (i) : input signal */
+@ Word16 y[], /* (o) : output signal */
+@ Word16 mem[], /* (i/o) : memory associated with this filtering. */
+@)
+@***********************************************************************
+@ a[] --- r0
+@ x[] --- r1
+@ y[] --- r2
+@ mem[] --- r3
+@ m --- 16 lg --- 80 update --- 1
+
+ .section .text
+ .global Syn_filt_asm
+
+Syn_filt_asm:
+
+ STMFD r13!, {r4 - r12, r14}
+ SUB r13, r13, #700 @ y_buf[L_FRAME16k + M16k]
+
+ MOV r4, r3 @ copy mem[] address
+ MOV r5, r13 @ copy yy = y_buf address
+
+ @ for(i = 0@ i < m@ i++)
+ @{
+ @ *yy++ = mem[i]@
+ @}
+ VLD1.S16 {D0, D1, D2, D3}, [r4]! @load 16 mems
+ VST1.S16 {D0, D1, D2, D3}, [r5]! @store 16 mem[] to *yy
+
+ LDRSH r5, [r0], #2 @ load a[0]
+ MOV r8, #0 @ i = 0
+ MOV r5, r5, ASR #1 @ a0 = a[0] >> 1
+ VMOV.S16 D8[0], r5
+ @ load all a[]
+ VLD1.S16 {D0, D1, D2, D3}, [r0]! @ load a[1] ~ a[16]
+ VREV64.16 D0, D0
+ VREV64.16 D1, D1
+ VREV64.16 D2, D2
+ VREV64.16 D3, D3
+ MOV r8, #0 @ loop times
+ MOV r10, r13 @ temp = y_buf
+ ADD r4, r13, #32 @ yy[i] address
+
+ VLD1.S16 {D4, D5, D6, D7}, [r10]! @ first 16 temp_p
+
+SYN_LOOP:
+
+ LDRSH r6, [r1], #2 @ load x[i]
+ MUL r12, r6, r5 @ L_tmp = x[i] * a0
+ ADD r10, r4, r8, LSL #1 @ y[i], yy[i] address
+
+ VDUP.S32 Q10, r12
+ VMULL.S16 Q5, D3, D4
+ VMLAL.S16 Q5, D2, D5
+ VMLAL.S16 Q5, D1, D6
+ VMLAL.S16 Q5, D0, D7
+ VEXT.8 D4, D4, D5, #2
+ VEXT.8 D5, D5, D6, #2
+ VEXT.8 D6, D6, D7, #2
+ VPADD.S32 D12, D10, D11
+ ADD r8, r8, #1
+ VPADD.S32 D10, D12, D12
+
+ VDUP.S32 Q7, D10[0]
+
+ VSUB.S32 Q9, Q10, Q7
+ VQRSHRN.S32 D20, Q9, #12
+ VMOV.S16 r9, D20[0]
+ VEXT.8 D7, D7, D20, #2
+ CMP r8, #80
+ STRH r9, [r10] @ yy[i]
+ STRH r9, [r2], #2 @ y[i]
+
+ BLT SYN_LOOP
+
+ @ update mem[]
+ ADD r5, r13, #160 @ yy[64] address
+ VLD1.S16 {D0, D1, D2, D3}, [r5]!
+ VST1.S16 {D0, D1, D2, D3}, [r3]!
+
+Syn_filt_asm_end:
+
+ ADD r13, r13, #700
+ LDMFD r13!, {r4 - r12, r15}
+ @ENDFUNC
+ .end
+
+
diff --git a/media/codecs/amrwb/enc/src/autocorr.c b/media/codecs/amrwb/enc/src/autocorr.c
new file mode 100644
index 0000000..3ea53f7
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/autocorr.c
@@ -0,0 +1,131 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+
+/***********************************************************************
+* File: autocorr.c *
+* *
+* Description:Compute autocorrelations of signal with windowing *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "acelp.h"
+#include "ham_wind.tab"
+
+#define UNUSED(x) (void)(x)
+
+void Autocorr(
+ Word16 x[], /* (i) : Input signal */
+ Word16 m, /* (i) : LPC order */
+ Word16 r_h[], /* (o) Q15: Autocorrelations (msb) */
+ Word16 r_l[] /* (o) : Autocorrelations (lsb) */
+ )
+{
+ Word32 i, norm, shift;
+ Word16 y[L_WINDOW];
+ Word32 L_sum, L_sum1, L_tmp, F_LEN;
+ Word16 *p1,*p2,*p3;
+ const Word16 *p4;
+ UNUSED(m);
+
+ /* Windowing of signal */
+ p1 = x;
+ p4 = vo_window;
+ p3 = y;
+
+ for (i = 0; i < L_WINDOW; i+=4)
+ {
+ *p3++ = vo_mult_r((*p1++), (*p4++));
+ *p3++ = vo_mult_r((*p1++), (*p4++));
+ *p3++ = vo_mult_r((*p1++), (*p4++));
+ *p3++ = vo_mult_r((*p1++), (*p4++));
+ }
+
+ /* calculate energy of signal */
+ L_sum = vo_L_deposit_h(16); /* sqrt(256), avoid overflow after rounding */
+ for (i = 0; i < L_WINDOW; i++)
+ {
+ L_tmp = vo_L_mult(y[i], y[i]);
+ L_tmp = (L_tmp >> 8);
+ L_sum += L_tmp;
+ }
+
+ /* scale signal to avoid overflow in autocorrelation */
+ norm = norm_l(L_sum);
+ shift = 4 - (norm >> 1);
+ if(shift > 0)
+ {
+ p1 = y;
+ for (i = 0; i < L_WINDOW; i+=4)
+ {
+ *p1 = vo_shr_r(*p1, shift);
+ p1++;
+ *p1 = vo_shr_r(*p1, shift);
+ p1++;
+ *p1 = vo_shr_r(*p1, shift);
+ p1++;
+ *p1 = vo_shr_r(*p1, shift);
+ p1++;
+ }
+ }
+
+ /* Compute and normalize r[0] */
+ L_sum = 1;
+ for (i = 0; i < L_WINDOW; i+=4)
+ {
+ L_sum += vo_L_mult(y[i], y[i]);
+ L_sum += vo_L_mult(y[i+1], y[i+1]);
+ L_sum += vo_L_mult(y[i+2], y[i+2]);
+ L_sum += vo_L_mult(y[i+3], y[i+3]);
+ }
+
+ norm = norm_l(L_sum);
+ L_sum = (L_sum << norm);
+
+ r_h[0] = L_sum >> 16;
+ r_l[0] = (L_sum & 0xffff)>>1;
+
+ /* Compute r[1] to r[m] */
+ for (i = 1; i <= 8; i++)
+ {
+ L_sum1 = 0;
+ L_sum = 0;
+ F_LEN = (Word32)(L_WINDOW - 2*i);
+ p1 = y;
+ p2 = y + (2*i)-1;
+ do{
+ L_sum1 += *p1 * *p2++;
+ L_sum += *p1++ * *p2;
+ }while(--F_LEN!=0);
+
+ L_sum1 += *p1 * *p2++;
+
+ L_sum1 = L_sum1<<norm;
+ L_sum = L_sum<<norm;
+
+ r_h[(2*i)-1] = L_sum1 >> 15;
+ r_l[(2*i)-1] = L_sum1 & 0x00007fff;
+ r_h[(2*i)] = L_sum >> 15;
+ r_l[(2*i)] = L_sum & 0x00007fff;
+ }
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/az_isp.c b/media/codecs/amrwb/enc/src/az_isp.c
new file mode 100644
index 0000000..d7074f0
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/az_isp.c
@@ -0,0 +1,268 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: az_isp.c
+*
+* Description:
+*-----------------------------------------------------------------------*
+* Compute the ISPs from the LPC coefficients (order=M) *
+*-----------------------------------------------------------------------*
+* *
+* The ISPs are the roots of the two polynomials F1(z) and F2(z) *
+* defined as *
+* F1(z) = A(z) + z^-m A(z^-1) *
+* and F2(z) = A(z) - z^-m A(z^-1) *
+* *
+* For a even order m=2n, F1(z) has M/2 conjugate roots on the unit *
+* circle and F2(z) has M/2-1 conjugate roots on the unit circle in *
+* addition to two roots at 0 and pi. *
+* *
+* For a 16th order LP analysis, F1(z) and F2(z) can be written as *
+* *
+* F1(z) = (1 + a[M]) PRODUCT (1 - 2 cos(w_i) z^-1 + z^-2 ) *
+* i=0,2,4,6,8,10,12,14 *
+* *
+* F2(z) = (1 - a[M]) (1 - z^-2) PRODUCT (1 - 2 cos(w_i) z^-1 + z^-2 ) *
+* i=1,3,5,7,9,11,13 *
+* *
+* The ISPs are the M-1 frequencies w_i, i=0...M-2 plus the last *
+* predictor coefficient a[M]. *
+*-----------------------------------------------------------------------*
+
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "stdio.h"
+#include "grid100.tab"
+
+#define M 16
+#define NC (M/2)
+
+/* local function */
+static __inline Word16 Chebps2(Word16 x, Word16 f[], Word32 n);
+
+void Az_isp(
+ Word16 a[], /* (i) Q12 : predictor coefficients */
+ Word16 isp[], /* (o) Q15 : Immittance spectral pairs */
+ Word16 old_isp[] /* (i) : old isp[] (in case not found M roots) */
+ )
+{
+ Word32 i, j, nf, ip, order;
+ Word16 xlow, ylow, xhigh, yhigh, xmid, ymid, xint;
+ Word16 x, y, sign, exp;
+ Word16 *coef;
+ Word16 f1[NC + 1], f2[NC];
+ Word32 t0;
+ /*-------------------------------------------------------------*
+ * find the sum and diff polynomials F1(z) and F2(z) *
+ * F1(z) = [A(z) + z^M A(z^-1)] *
+ * F2(z) = [A(z) - z^M A(z^-1)]/(1-z^-2) *
+ * *
+ * for (i=0; i<NC; i++) *
+ * { *
+ * f1[i] = a[i] + a[M-i]; *
+ * f2[i] = a[i] - a[M-i]; *
+ * } *
+ * f1[NC] = 2.0*a[NC]; *
+ * *
+ * for (i=2; i<NC; i++) Divide by (1-z^-2) *
+ * f2[i] += f2[i-2]; *
+ *-------------------------------------------------------------*/
+ for (i = 0; i < NC; i++)
+ {
+ t0 = a[i] << 15;
+ f1[i] = vo_round(t0 + (a[M - i] << 15)); /* =(a[i]+a[M-i])/2 */
+ f2[i] = vo_round(t0 - (a[M - i] << 15)); /* =(a[i]-a[M-i])/2 */
+ }
+ f1[NC] = a[NC];
+ for (i = 2; i < NC; i++) /* Divide by (1-z^-2) */
+ f2[i] = add1(f2[i], f2[i - 2]);
+
+ /*---------------------------------------------------------------------*
+ * Find the ISPs (roots of F1(z) and F2(z) ) using the *
+ * Chebyshev polynomial evaluation. *
+ * The roots of F1(z) and F2(z) are alternatively searched. *
+ * We start by finding the first root of F1(z) then we switch *
+ * to F2(z) then back to F1(z) and so on until all roots are found. *
+ * *
+ * - Evaluate Chebyshev pol. at grid points and check for sign change.*
+ * - If sign change track the root by subdividing the interval *
+ * 2 times and ckecking sign change. *
+ *---------------------------------------------------------------------*/
+ nf = 0; /* number of found frequencies */
+ ip = 0; /* indicator for f1 or f2 */
+ coef = f1;
+ order = NC;
+ xlow = vogrid[0];
+ ylow = Chebps2(xlow, coef, order);
+ j = 0;
+ while ((nf < M - 1) && (j < GRID_POINTS))
+ {
+ j ++;
+ xhigh = xlow;
+ yhigh = ylow;
+ xlow = vogrid[j];
+ ylow = Chebps2(xlow, coef, order);
+ if ((ylow * yhigh) <= (Word32) 0)
+ {
+ /* divide 2 times the interval */
+ for (i = 0; i < 2; i++)
+ {
+ xmid = (xlow >> 1) + (xhigh >> 1); /* xmid = (xlow + xhigh)/2 */
+ ymid = Chebps2(xmid, coef, order);
+ if ((ylow * ymid) <= (Word32) 0)
+ {
+ yhigh = ymid;
+ xhigh = xmid;
+ } else
+ {
+ ylow = ymid;
+ xlow = xmid;
+ }
+ }
+ /*-------------------------------------------------------------*
+ * Linear interpolation *
+ * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow); *
+ *-------------------------------------------------------------*/
+ x = xhigh - xlow;
+ y = yhigh - ylow;
+ if (y == 0)
+ {
+ xint = xlow;
+ } else
+ {
+ sign = y;
+ y = abs_s(y);
+ exp = norm_s(y);
+ y = y << exp;
+ y = div_s((Word16) 16383, y);
+ t0 = x * y;
+ t0 = (t0 >> (19 - exp));
+ y = vo_extract_l(t0); /* y= (xhigh-xlow)/(yhigh-ylow) in Q11 */
+ if (sign < 0)
+ y = -y;
+ t0 = ylow * y; /* result in Q26 */
+ t0 = (t0 >> 10); /* result in Q15 */
+ xint = vo_sub(xlow, vo_extract_l(t0)); /* xint = xlow - ylow*y */
+ }
+ isp[nf] = xint;
+ xlow = xint;
+ nf++;
+ if (ip == 0)
+ {
+ ip = 1;
+ coef = f2;
+ order = NC - 1;
+ } else
+ {
+ ip = 0;
+ coef = f1;
+ order = NC;
+ }
+ ylow = Chebps2(xlow, coef, order);
+ }
+ }
+ /* Check if M-1 roots found */
+ if(nf < M - 1)
+ {
+ for (i = 0; i < M; i++)
+ {
+ isp[i] = old_isp[i];
+ }
+ } else
+ {
+ isp[M - 1] = a[M] << 3; /* From Q12 to Q15 with saturation */
+ }
+ return;
+}
+
+/*--------------------------------------------------------------*
+* function Chebps2: *
+* ~~~~~~~ *
+* Evaluates the Chebishev polynomial series *
+*--------------------------------------------------------------*
+* *
+* The polynomial order is *
+* n = M/2 (M is the prediction order) *
+* The polynomial is given by *
+* C(x) = f(0)T_n(x) + f(1)T_n-1(x) + ... +f(n-1)T_1(x) + f(n)/2 *
+* Arguments: *
+* x: input value of evaluation; x = cos(frequency) in Q15 *
+* f[]: coefficients of the pol. in Q11 *
+* n: order of the pol. *
+* *
+* The value of C(x) is returned. (Satured to +-1.99 in Q14) *
+* *
+*--------------------------------------------------------------*/
+
+static __inline Word16 Chebps2(Word16 x, Word16 f[], Word32 n)
+{
+ Word32 i, cheb;
+ Word16 b0_h, b0_l, b1_h, b1_l, b2_h, b2_l;
+ Word32 t0;
+
+ /* Note: All computation are done in Q24. */
+
+ t0 = f[0] << 13;
+ b2_h = t0 >> 16;
+ b2_l = (t0 & 0xffff)>>1;
+
+ t0 = ((b2_h * x)<<1) + (((b2_l * x)>>15)<<1);
+ t0 <<= 1;
+ t0 += (f[1] << 13); /* + f[1] in Q24 */
+
+ b1_h = t0 >> 16;
+ b1_l = (t0 & 0xffff) >> 1;
+
+ for (i = 2; i < n; i++)
+ {
+ t0 = ((b1_h * x)<<1) + (((b1_l * x)>>15)<<1);
+
+ t0 += (b2_h * (-16384))<<1;
+ t0 += (f[i] << 12);
+ t0 <<= 1;
+ t0 -= (b2_l << 1); /* t0 = 2.0*x*b1 - b2 + f[i]; */
+
+ b0_h = t0 >> 16;
+ b0_l = (t0 & 0xffff) >> 1;
+
+ b2_l = b1_l; /* b2 = b1; */
+ b2_h = b1_h;
+ b1_l = b0_l; /* b1 = b0; */
+ b1_h = b0_h;
+ }
+
+ t0 = ((b1_h * x)<<1) + (((b1_l * x)>>15)<<1);
+ t0 += (b2_h * (-32768))<<1; /* t0 = x*b1 - b2 */
+ t0 -= (b2_l << 1);
+ t0 += (f[n] << 12); /* t0 = x*b1 - b2 + f[i]/2 */
+
+ t0 = L_shl2(t0, 6); /* Q24 to Q30 with saturation */
+
+ cheb = extract_h(t0); /* Result in Q14 */
+
+ if (cheb == -32768)
+ {
+ cheb = -32767; /* to avoid saturation in Az_isp */
+ }
+ return (cheb);
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/bits.c b/media/codecs/amrwb/enc/src/bits.c
new file mode 100644
index 0000000..6b8bddd
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/bits.c
@@ -0,0 +1,210 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+ File: bits.c
+
+ Description: Performs bit stream manipulation
+
+************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "bits.h"
+#include "acelp.h"
+#include "dtx.h"
+#include "mime_io.tab"
+
+
+int PackBits(Word16 prms[], /* i: analysis parameters */
+ Word16 coding_mode, /* i: coding bit-stream ratio mode */
+ Word16 mode, /* i: coding bit-stream ratio mode*/
+ Coder_State *st /*i/o: coder global parameters struct */
+ )
+{
+ Word16 i, frame_type;
+ UWord8 temp;
+ UWord8 *stream_ptr;
+ Word16 bitstreamformat = st->frameType;
+
+ unsigned short* dataOut = st->outputStream;
+
+ if (coding_mode == MRDTX)
+ {
+ st->sid_update_counter--;
+
+ if (st->prev_ft == TX_SPEECH)
+ {
+ frame_type = TX_SID_FIRST;
+ st->sid_update_counter = 3;
+ } else
+ {
+ if ((st->sid_handover_debt > 0) && (st->sid_update_counter > 2))
+ {
+ /* ensure extra updates are properly delayed after a possible SID_FIRST */
+ frame_type = TX_SID_UPDATE;
+ st->sid_handover_debt--;
+ } else
+ {
+ if (st->sid_update_counter == 0)
+ {
+ frame_type = TX_SID_UPDATE;
+ st->sid_update_counter = 8;
+ } else
+ {
+ frame_type = TX_NO_DATA;
+ }
+ }
+ }
+ } else
+ {
+ st->sid_update_counter = 8;
+ frame_type = TX_SPEECH;
+ }
+ st->prev_ft = frame_type;
+
+ if(bitstreamformat == 0) /* default file format */
+ {
+ *(dataOut) = TX_FRAME_TYPE;
+ *(dataOut + 1) = frame_type;
+ *(dataOut + 2) = mode;
+ for (i = 0; i < nb_of_bits[coding_mode]; i++)
+ {
+ *(dataOut + 3 + i) = prms[i];
+ }
+ return (3 + nb_of_bits[coding_mode])<<1;
+ } else
+ {
+ if (bitstreamformat == 1) /* ITU file format */
+ {
+ *(dataOut) = 0x6b21;
+ if(frame_type != TX_NO_DATA && frame_type != TX_SID_FIRST)
+ {
+ *(dataOut + 1) = nb_of_bits[coding_mode];
+ for (i = 0; i < nb_of_bits[coding_mode]; i++)
+ {
+ if(prms[i] == BIT_0){
+ *(dataOut + 2 + i) = BIT_0_ITU;
+ }
+ else{
+ *(dataOut + 2 + i) = BIT_1_ITU;
+ }
+ }
+ return (2 + nb_of_bits[coding_mode])<<1;
+ } else
+ {
+ *(dataOut + 1) = 0;
+ return 2<<1;
+ }
+ } else /* MIME/storage file format */
+ {
+#define MRSID 9
+ /* change mode index in case of SID frame */
+ if (coding_mode == MRDTX)
+ {
+ coding_mode = MRSID;
+ if (frame_type == TX_SID_FIRST)
+ {
+ for (i = 0; i < NBBITS_SID; i++) prms[i] = BIT_0;
+ }
+ }
+ /* -> force NO_DATA frame */
+ if (coding_mode < 0 || coding_mode > 15 || (coding_mode > MRSID && coding_mode < 14))
+ {
+ coding_mode = 15;
+ }
+ /* mark empty frames between SID updates as NO_DATA frames */
+ if (coding_mode == MRSID && frame_type == TX_NO_DATA)
+ {
+ coding_mode = 15;
+ }
+ /* set pointer for packed frame, note that we handle data as bytes */
+ stream_ptr = (UWord8*)dataOut;
+ /* insert table of contents (ToC) byte at the beginning of the packet */
+ *stream_ptr = toc_byte[coding_mode];
+ stream_ptr++;
+ temp = 0;
+ /* sort and pack AMR-WB speech or SID bits */
+ for (i = 1; i < unpacked_size[coding_mode] + 1; i++)
+ {
+ if (prms[sort_ptr[coding_mode][i-1]] == BIT_1)
+ {
+ temp++;
+ }
+ if (i&0x7)
+ {
+ temp <<= 1;
+ }
+ else
+ {
+ *stream_ptr = temp;
+ stream_ptr++;
+ temp = 0;
+ }
+ }
+ /* insert SID type indication and speech mode in case of SID frame */
+ if (coding_mode == MRSID)
+ {
+ if (frame_type == TX_SID_UPDATE)
+ {
+ temp++;
+ }
+ temp <<= 4;
+ temp += mode & 0x000F;
+ }
+ /* insert unused bits (zeros) at the tail of the last byte */
+ if (unused_size[coding_mode])
+ {
+ temp <<= (unused_size[coding_mode] - 1);
+ }
+ *stream_ptr = temp;
+ /* write packed frame into file (1 byte added to cover ToC entry) */
+ return (1 + packed_size[coding_mode]);
+ }
+ }
+}
+
+/*-----------------------------------------------------*
+* Parm_serial -> convert parameters to serial stream *
+*-----------------------------------------------------*/
+
+void Parm_serial(
+ Word16 value, /* input : parameter value */
+ Word16 no_of_bits, /* input : number of bits */
+ Word16 ** prms
+ )
+{
+ Word16 i, bit;
+ *prms += no_of_bits;
+ for (i = 0; i < no_of_bits; i++)
+ {
+ bit = (Word16) (value & 0x0001); /* get lsb */
+ if (bit == 0)
+ *--(*prms) = BIT_0;
+ else
+ *--(*prms) = BIT_1;
+ value >>= 1;
+ }
+ *prms += no_of_bits;
+ return;
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/c2t64fx.c b/media/codecs/amrwb/enc/src/c2t64fx.c
new file mode 100644
index 0000000..dbb94c6
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/c2t64fx.c
@@ -0,0 +1,300 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/************************************************************************
+* File: c2t64fx.c *
+* *
+* Description:Performs algebraic codebook search for 6.60kbits mode*
+* *
+*************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+#include "acelp.h"
+#include "cnst.h"
+
+#define NB_TRACK 2
+#define STEP 2
+#define NB_POS 32
+#define MSIZE 1024
+
+/*************************************************************************
+* Function: ACELP_2t64_fx() *
+* *
+* 12 bits algebraic codebook. *
+* 2 tracks x 32 positions per track = 64 samples. *
+* *
+* 12 bits --> 2 pulses in a frame of 64 samples. *
+* *
+* All pulses can have two (2) possible amplitudes: +1 or -1. *
+* Each pulse can have 32 possible positions. *
+**************************************************************************/
+
+void ACELP_2t64_fx(
+ Word16 dn[], /* (i) <12b : correlation between target x[] and H[] */
+ Word16 cn[], /* (i) <12b : residual after long term prediction */
+ Word16 H[], /* (i) Q12: impulse response of weighted synthesis filter */
+ Word16 code[], /* (o) Q9 : algebraic (fixed) codebook excitation */
+ Word16 y[], /* (o) Q9 : filtered fixed codebook excitation */
+ Word16 * index /* (o) : index (12): 5+1+5+1 = 11 bits. */
+ )
+{
+ Word32 i, j, k, i0, i1, ix, iy, pos, pos2;
+ Word16 ps, psk, ps1, ps2, alpk, alp1, alp2, sq;
+ Word16 alp, val, exp, k_cn, k_dn;
+ Word16 *p0, *p1, *p2, *psign;
+ Word16 *h, *h_inv, *ptr_h1, *ptr_h2, *ptr_hf;
+
+ Word16 sign[L_SUBFR], vec[L_SUBFR], dn2[L_SUBFR];
+ Word16 h_buf[4 * L_SUBFR] = {0};
+ Word16 rrixix[NB_TRACK][NB_POS];
+ Word16 rrixiy[MSIZE];
+ Word32 s, cor;
+
+ /*----------------------------------------------------------------*
+ * Find sign for each pulse position. *
+ *----------------------------------------------------------------*/
+ alp = 8192; /* alp = 2.0 (Q12) */
+
+ /* calculate energy for normalization of cn[] and dn[] */
+ /* set k_cn = 32..32767 (ener_cn = 2^30..256-0) */
+#ifdef ASM_OPT /* asm optimization branch */
+ s = Dot_product12_asm(cn, cn, L_SUBFR, &exp);
+#else
+ s = Dot_product12(cn, cn, L_SUBFR, &exp);
+#endif
+
+ Isqrt_n(&s, &exp);
+ s = L_shl(s, add1(exp, 5));
+ if (s > INT_MAX - 0x8000) {
+ s = INT_MAX - 0x8000;
+ }
+ k_cn = vo_round(s);
+
+ /* set k_dn = 32..512 (ener_dn = 2^30..2^22) */
+#ifdef ASM_OPT /* asm optimization branch */
+ s = Dot_product12_asm(dn, dn, L_SUBFR, &exp);
+#else
+ s = Dot_product12(dn, dn, L_SUBFR, &exp);
+#endif
+
+ Isqrt_n(&s, &exp);
+ k_dn = voround(L_shl(s, (exp + 8))); /* k_dn = 256..4096 */
+ k_dn = vo_mult_r(alp, k_dn); /* alp in Q12 */
+
+ /* mix normalized cn[] and dn[] */
+ p0 = cn;
+ p1 = dn;
+ p2 = dn2;
+
+ for (i = 0; i < L_SUBFR/4; i++)
+ {
+ s = (k_cn* (*p0++))+(k_dn * (*p1++));
+ *p2++ = s >> 7;
+ s = (k_cn* (*p0++))+(k_dn * (*p1++));
+ *p2++ = s >> 7;
+ s = (k_cn* (*p0++))+(k_dn * (*p1++));
+ *p2++ = s >> 7;
+ s = (k_cn* (*p0++))+(k_dn * (*p1++));
+ *p2++ = s >> 7;
+ }
+
+ /* set sign according to dn2[] = k_cn*cn[] + k_dn*dn[] */
+ for (i = 0; i < L_SUBFR; i ++)
+ {
+ val = dn[i];
+ ps = dn2[i];
+ if (ps >= 0)
+ {
+ sign[i] = 32767; /* sign = +1 (Q12) */
+ vec[i] = -32768;
+ } else
+ {
+ sign[i] = -32768; /* sign = -1 (Q12) */
+ vec[i] = 32767;
+ dn[i] = -val;
+ }
+ }
+ /*------------------------------------------------------------*
+ * Compute h_inv[i]. *
+ *------------------------------------------------------------*/
+ /* impulse response buffer for fast computation */
+ h = h_buf + L_SUBFR;
+ h_inv = h + (L_SUBFR<<1);
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ h[i] = H[i];
+ h_inv[i] = vo_negate(h[i]);
+ }
+
+ /*------------------------------------------------------------*
+ * Compute rrixix[][] needed for the codebook search. *
+ * Result is multiplied by 0.5 *
+ *------------------------------------------------------------*/
+ /* Init pointers to last position of rrixix[] */
+ p0 = &rrixix[0][NB_POS - 1];
+ p1 = &rrixix[1][NB_POS - 1];
+
+ ptr_h1 = h;
+ cor = 0x00010000L; /* for rounding */
+ for (i = 0; i < NB_POS; i++)
+ {
+ cor += ((*ptr_h1) * (*ptr_h1) << 1);
+ ptr_h1++;
+ *p1-- = (extract_h(cor) >> 1);
+ cor += ((*ptr_h1) * (*ptr_h1) << 1);
+ ptr_h1++;
+ *p0-- = (extract_h(cor) >> 1);
+ }
+
+ /*------------------------------------------------------------*
+ * Compute rrixiy[][] needed for the codebook search. *
+ *------------------------------------------------------------*/
+ pos = MSIZE - 1;
+ pos2 = MSIZE - 2;
+ ptr_hf = h + 1;
+
+ for (k = 0; k < NB_POS; k++)
+ {
+ p1 = &rrixiy[pos];
+ p0 = &rrixiy[pos2];
+ cor = 0x00008000L; /* for rounding */
+ ptr_h1 = h;
+ ptr_h2 = ptr_hf;
+
+ for (i = (k + 1); i < NB_POS; i++)
+ {
+ cor += ((*ptr_h1) * (*ptr_h2))<<1;
+ ptr_h1++;
+ ptr_h2++;
+ *p1 = extract_h(cor);
+ cor += ((*ptr_h1) * (*ptr_h2))<<1;
+ ptr_h1++;
+ ptr_h2++;
+ *p0 = extract_h(cor);
+
+ p1 -= (NB_POS + 1);
+ p0 -= (NB_POS + 1);
+ }
+ cor += ((*ptr_h1) * (*ptr_h2))<<1;
+ ptr_h1++;
+ ptr_h2++;
+ *p1 = extract_h(cor);
+
+ pos -= NB_POS;
+ pos2--;
+ ptr_hf += STEP;
+ }
+
+ /*------------------------------------------------------------*
+ * Modification of rrixiy[][] to take signs into account. *
+ *------------------------------------------------------------*/
+ p0 = rrixiy;
+ for (i = 0; i < L_SUBFR; i += STEP)
+ {
+ psign = sign;
+ if (psign[i] < 0)
+ {
+ psign = vec;
+ }
+ for (j = 1; j < L_SUBFR; j += STEP)
+ {
+ *p0 = vo_mult(*p0, psign[j]);
+ p0++;
+ }
+ }
+ /*-------------------------------------------------------------------*
+ * search 2 pulses: *
+ * ~@~~~~~~~~~~~~~~ *
+ * 32 pos x 32 pos = 1024 tests (all combinaisons is tested) *
+ *-------------------------------------------------------------------*/
+ p0 = rrixix[0];
+ p1 = rrixix[1];
+ p2 = rrixiy;
+
+ psk = -1;
+ alpk = 1;
+ ix = 0;
+ iy = 1;
+
+ for (i0 = 0; i0 < L_SUBFR; i0 += STEP)
+ {
+ ps1 = dn[i0];
+ alp1 = (*p0++);
+ pos = -1;
+ for (i1 = 1; i1 < L_SUBFR; i1 += STEP)
+ {
+ ps2 = add1(ps1, dn[i1]);
+ alp2 = add1(alp1, add1(*p1++, *p2++));
+ sq = vo_mult(ps2, ps2);
+ s = vo_L_mult(alpk, sq) - ((psk * alp2)<<1);
+ if (s > 0)
+ {
+ psk = sq;
+ alpk = alp2;
+ pos = i1;
+ }
+ }
+ p1 -= NB_POS;
+ if (pos >= 0)
+ {
+ ix = i0;
+ iy = pos;
+ }
+ }
+ /*-------------------------------------------------------------------*
+ * Build the codeword, the filtered codeword and index of codevector.*
+ *-------------------------------------------------------------------*/
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ code[i] = 0;
+ }
+
+ i0 = (ix >> 1); /* pos of pulse 1 (0..31) */
+ i1 = (iy >> 1); /* pos of pulse 2 (0..31) */
+ if (sign[ix] > 0)
+ {
+ code[ix] = 512; /* codeword in Q9 format */
+ p0 = h - ix;
+ } else
+ {
+ code[ix] = -512;
+ i0 += NB_POS;
+ p0 = h_inv - ix;
+ }
+ if (sign[iy] > 0)
+ {
+ code[iy] = 512;
+ p1 = h - iy;
+ } else
+ {
+ code[iy] = -512;
+ i1 += NB_POS;
+ p1 = h_inv - iy;
+ }
+ *index = add1((i0 << 6), i1);
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ y[i] = vo_shr_r(add1((*p0++), (*p1++)), 3);
+ }
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/c4t64fx.c b/media/codecs/amrwb/enc/src/c4t64fx.c
new file mode 100644
index 0000000..f2e28c4
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/c4t64fx.c
@@ -0,0 +1,1060 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: c4t64fx.c *
+* *
+* Description:Performs algebraic codebook search for higher modes *
+* *
+************************************************************************/
+
+/************************************************************************
+* Function: ACELP_4t64_fx() *
+* *
+* 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook. *
+* 4 tracks x 16 positions per track = 64 samples. *
+* *
+* 20 bits --> 4 pulses in a frame of 64 samples. *
+* 36 bits --> 8 pulses in a frame of 64 samples. *
+* 44 bits --> 10 pulses in a frame of 64 samples. *
+* 52 bits --> 12 pulses in a frame of 64 samples. *
+* 64 bits --> 16 pulses in a frame of 64 samples. *
+* 72 bits --> 18 pulses in a frame of 64 samples. *
+* 88 bits --> 24 pulses in a frame of 64 samples. *
+* *
+* All pulses can have two (2) possible amplitudes: +1 or -1. *
+* Each pulse can have sixteen (16) possible positions. *
+*************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+#include "acelp.h"
+#include "cnst.h"
+
+#include "q_pulse.h"
+
+#undef LOG_TAG
+#define LOG_TAG "amrwbenc"
+#include "log/log.h"
+
+static Word16 tipos[36] = {
+ 0, 1, 2, 3, /* starting point &ipos[0], 1st iter */
+ 1, 2, 3, 0, /* starting point &ipos[4], 2nd iter */
+ 2, 3, 0, 1, /* starting point &ipos[8], 3rd iter */
+ 3, 0, 1, 2, /* starting point &ipos[12], 4th iter */
+ 0, 1, 2, 3,
+ 1, 2, 3, 0,
+ 2, 3, 0, 1,
+ 3, 0, 1, 2,
+ 0, 1, 2, 3}; /* end point for 24 pulses &ipos[35], 4th iter */
+
+#define NB_PULSE_MAX 24
+
+#define L_SUBFR 64
+#define NB_TRACK 4
+#define STEP 4
+#define NB_POS 16
+#define MSIZE 256
+#define NB_MAX 8
+#define NPMAXPT ((NB_PULSE_MAX+NB_TRACK-1)/NB_TRACK)
+
+/* Private functions */
+void cor_h_vec_012(
+ Word16 h[], /* (i) scaled impulse response */
+ Word16 vec[], /* (i) scaled vector (/8) to correlate with h[] */
+ Word16 track, /* (i) track to use */
+ Word16 sign[], /* (i) sign vector */
+ Word16 rrixix[][NB_POS], /* (i) correlation of h[x] with h[x] */
+ Word16 cor_1[], /* (o) result of correlation (NB_POS elements) */
+ Word16 cor_2[] /* (o) result of correlation (NB_POS elements) */
+ );
+
+void cor_h_vec_012_asm(
+ Word16 h[], /* (i) scaled impulse response */
+ Word16 vec[], /* (i) scaled vector (/8) to correlate with h[] */
+ Word16 track, /* (i) track to use */
+ Word16 sign[], /* (i) sign vector */
+ Word16 rrixix[][NB_POS], /* (i) correlation of h[x] with h[x] */
+ Word16 cor_1[], /* (o) result of correlation (NB_POS elements) */
+ Word16 cor_2[] /* (o) result of correlation (NB_POS elements) */
+ );
+
+void cor_h_vec_30(
+ Word16 h[], /* (i) scaled impulse response */
+ Word16 vec[], /* (i) scaled vector (/8) to correlate with h[] */
+ Word16 track, /* (i) track to use */
+ Word16 sign[], /* (i) sign vector */
+ Word16 rrixix[][NB_POS], /* (i) correlation of h[x] with h[x] */
+ Word16 cor_1[], /* (o) result of correlation (NB_POS elements) */
+ Word16 cor_2[] /* (o) result of correlation (NB_POS elements) */
+ );
+
+void search_ixiy(
+ Word16 nb_pos_ix, /* (i) nb of pos for pulse 1 (1..8) */
+ Word16 track_x, /* (i) track of pulse 1 */
+ Word16 track_y, /* (i) track of pulse 2 */
+ Word16 * ps, /* (i/o) correlation of all fixed pulses */
+ Word16 * alp, /* (i/o) energy of all fixed pulses */
+ Word16 * ix, /* (o) position of pulse 1 */
+ Word16 * iy, /* (o) position of pulse 2 */
+ Word16 dn[], /* (i) corr. between target and h[] */
+ Word16 dn2[], /* (i) vector of selected positions */
+ Word16 cor_x[], /* (i) corr. of pulse 1 with fixed pulses */
+ Word16 cor_y[], /* (i) corr. of pulse 2 with fixed pulses */
+ Word16 rrixiy[][MSIZE] /* (i) corr. of pulse 1 with pulse 2 */
+ );
+
+
+void ACELP_4t64_fx(
+ Word16 dn[], /* (i) <12b : correlation between target x[] and H[] */
+ Word16 cn[], /* (i) <12b : residual after long term prediction */
+ Word16 H[], /* (i) Q12: impulse response of weighted synthesis filter */
+ Word16 code[], /* (o) Q9 : algebraic (fixed) codebook excitation */
+ Word16 y[], /* (o) Q9 : filtered fixed codebook excitation */
+ Word16 nbbits, /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits */
+ Word16 ser_size, /* (i) : bit rate */
+ Word16 _index[] /* (o) : index (20): 5+5+5+5 = 20 bits. */
+ /* (o) : index (36): 9+9+9+9 = 36 bits. */
+ /* (o) : index (44): 13+9+13+9 = 44 bits. */
+ /* (o) : index (52): 13+13+13+13 = 52 bits. */
+ /* (o) : index (64): 2+2+2+2+14+14+14+14 = 64 bits. */
+ /* (o) : index (72): 10+2+10+2+10+14+10+14 = 72 bits. */
+ /* (o) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
+ )
+{
+ Word32 i, j, k;
+ Word16 st, ix, iy, pos, index, track, nb_pulse, nbiter, j_temp;
+ Word16 psk, ps, alpk, alp, val, k_cn, k_dn, exp;
+ Word16 *p0, *p1, *p2, *p3, *psign;
+ Word16 *h, *h_inv, *ptr_h1, *ptr_h2, *ptr_hf, h_shift;
+ Word32 s, cor, L_tmp, L_index;
+ Word16 dn2[L_SUBFR], sign[L_SUBFR], vec[L_SUBFR];
+ Word16 ind[NPMAXPT * NB_TRACK];
+ Word16 codvec[NB_PULSE_MAX], nbpos[10];
+ Word16 cor_x[NB_POS], cor_y[NB_POS], pos_max[NB_TRACK];
+ Word16 h_buf[4 * L_SUBFR];
+ Word16 rrixix[NB_TRACK][NB_POS], rrixiy[NB_TRACK][MSIZE];
+ Word16 ipos[NB_PULSE_MAX];
+
+ switch (nbbits)
+ {
+ case 20: /* 20 bits, 4 pulses, 4 tracks */
+ nbiter = 4; /* 4x16x16=1024 loop */
+ alp = 8192; /* alp = 2.0 (Q12) */
+ nb_pulse = 4;
+ nbpos[0] = 4;
+ nbpos[1] = 8;
+ break;
+ case 36: /* 36 bits, 8 pulses, 4 tracks */
+ nbiter = 4; /* 4x20x16=1280 loop */
+ alp = 4096; /* alp = 1.0 (Q12) */
+ nb_pulse = 8;
+ nbpos[0] = 4;
+ nbpos[1] = 8;
+ nbpos[2] = 8;
+ break;
+ case 44: /* 44 bits, 10 pulses, 4 tracks */
+ nbiter = 4; /* 4x26x16=1664 loop */
+ alp = 4096; /* alp = 1.0 (Q12) */
+ nb_pulse = 10;
+ nbpos[0] = 4;
+ nbpos[1] = 6;
+ nbpos[2] = 8;
+ nbpos[3] = 8;
+ break;
+ case 52: /* 52 bits, 12 pulses, 4 tracks */
+ nbiter = 4; /* 4x26x16=1664 loop */
+ alp = 4096; /* alp = 1.0 (Q12) */
+ nb_pulse = 12;
+ nbpos[0] = 4;
+ nbpos[1] = 6;
+ nbpos[2] = 8;
+ nbpos[3] = 8;
+ break;
+ case 64: /* 64 bits, 16 pulses, 4 tracks */
+ nbiter = 3; /* 3x36x16=1728 loop */
+ alp = 3277; /* alp = 0.8 (Q12) */
+ nb_pulse = 16;
+ nbpos[0] = 4;
+ nbpos[1] = 4;
+ nbpos[2] = 6;
+ nbpos[3] = 6;
+ nbpos[4] = 8;
+ nbpos[5] = 8;
+ break;
+ case 72: /* 72 bits, 18 pulses, 4 tracks */
+ nbiter = 3; /* 3x35x16=1680 loop */
+ alp = 3072; /* alp = 0.75 (Q12) */
+ nb_pulse = 18;
+ nbpos[0] = 2;
+ nbpos[1] = 3;
+ nbpos[2] = 4;
+ nbpos[3] = 5;
+ nbpos[4] = 6;
+ nbpos[5] = 7;
+ nbpos[6] = 8;
+ break;
+ case 88: /* 88 bits, 24 pulses, 4 tracks */
+ if(ser_size > 462)
+ nbiter = 1;
+ else
+ nbiter = 2; /* 2x53x16=1696 loop */
+
+ alp = 2048; /* alp = 0.5 (Q12) */
+ nb_pulse = 24;
+ nbpos[0] = 2;
+ nbpos[1] = 2;
+ nbpos[2] = 3;
+ nbpos[3] = 4;
+ nbpos[4] = 5;
+ nbpos[5] = 6;
+ nbpos[6] = 7;
+ nbpos[7] = 8;
+ nbpos[8] = 8;
+ nbpos[9] = 8;
+ break;
+ default:
+ nbiter = 0;
+ alp = 0;
+ nb_pulse = 0;
+ }
+
+ for (i = 0; i < nb_pulse; i++)
+ {
+ codvec[i] = i;
+ }
+
+ /*----------------------------------------------------------------*
+ * Find sign for each pulse position. *
+ *----------------------------------------------------------------*/
+ /* calculate energy for normalization of cn[] and dn[] */
+ /* set k_cn = 32..32767 (ener_cn = 2^30..256-0) */
+#ifdef ASM_OPT /* asm optimization branch */
+ s = Dot_product12_asm(cn, cn, L_SUBFR, &exp);
+#else
+ s = Dot_product12(cn, cn, L_SUBFR, &exp);
+#endif
+
+ Isqrt_n(&s, &exp);
+ s = L_shl(s, (exp + 5));
+ k_cn = extract_h(L_add(s, 0x8000));
+
+ /* set k_dn = 32..512 (ener_dn = 2^30..2^22) */
+#ifdef ASM_OPT /* asm optimization branch */
+ s = Dot_product12_asm(dn, dn, L_SUBFR, &exp);
+#else
+ s = Dot_product12(dn, dn, L_SUBFR, &exp);
+#endif
+
+ Isqrt_n(&s, &exp);
+ k_dn = voround(L_shl(s, (exp + 5 + 3))); /* k_dn = 256..4096 */
+ k_dn = vo_mult_r(alp, k_dn); /* alp in Q12 */
+
+ /* mix normalized cn[] and dn[] */
+ p0 = cn;
+ p1 = dn;
+ p2 = dn2;
+
+ for (i = 0; i < L_SUBFR/4; i++)
+ {
+ s = L_add((k_cn* (*p0++)), (k_dn * (*p1++)));
+ *p2++ = s >> 7;
+ s = L_add((k_cn* (*p0++)), (k_dn * (*p1++)));
+ *p2++ = s >> 7;
+ s = L_add((k_cn* (*p0++)), (k_dn * (*p1++)));
+ *p2++ = s >> 7;
+ s = L_add((k_cn* (*p0++)), (k_dn * (*p1++)));
+ *p2++ = s >> 7;
+ }
+
+ /* set sign according to dn2[] = k_cn*cn[] + k_dn*dn[] */
+ for(i = 0; i < L_SUBFR; i++)
+ {
+ val = dn[i];
+ ps = dn2[i];
+ if (ps >= 0)
+ {
+ sign[i] = 32767; /* sign = +1 (Q12) */
+ vec[i] = -32768;
+ } else
+ {
+ sign[i] = -32768; /* sign = -1 (Q12) */
+ vec[i] = 32767;
+ dn[i] = -val;
+ dn2[i] = -ps;
+ }
+ }
+ /*----------------------------------------------------------------*
+ * Select NB_MAX position per track according to max of dn2[]. *
+ *----------------------------------------------------------------*/
+ pos = 0;
+ for (i = 0; i < NB_TRACK; i++)
+ {
+ for (k = 0; k < NB_MAX; k++)
+ {
+ ps = -1;
+ for (j = i; j < L_SUBFR; j += STEP)
+ {
+ if(dn2[j] > ps)
+ {
+ ps = dn2[j];
+ pos = j;
+ }
+ }
+ dn2[pos] = (k - NB_MAX); /* dn2 < 0 when position is selected */
+ if (k == 0)
+ {
+ pos_max[i] = pos;
+ }
+ }
+ }
+
+ /*--------------------------------------------------------------*
+ * Scale h[] to avoid overflow and to get maximum of precision *
+ * on correlation. *
+ * *
+ * Maximum of h[] (h[0]) is fixed to 2048 (MAX16 / 16). *
+ * ==> This allow addition of 16 pulses without saturation. *
+ * *
+ * Energy worst case (on resonant impulse response), *
+ * - energy of h[] is approximately MAX/16. *
+ * - During search, the energy is divided by 8 to avoid *
+ * overflow on "alp". (energy of h[] = MAX/128). *
+ * ==> "alp" worst case detected is 22854 on sinusoidal wave. *
+ *--------------------------------------------------------------*/
+
+ /* impulse response buffer for fast computation */
+
+ h = h_buf;
+ h_inv = h_buf + (2 * L_SUBFR);
+ L_tmp = 0;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ *h++ = 0;
+ *h_inv++ = 0;
+ L_tmp = L_add(L_tmp, (H[i] * H[i]) << 1);
+ }
+ /* scale h[] down (/2) when energy of h[] is high with many pulses used */
+ val = extract_h(L_tmp);
+ h_shift = 0;
+
+ if ((nb_pulse >= 12) && (val > 1024))
+ {
+ h_shift = 1;
+ }
+ p0 = H;
+ p1 = h;
+ p2 = h_inv;
+
+ for (i = 0; i < L_SUBFR/4; i++)
+ {
+ *p1 = *p0++ >> h_shift;
+ *p2++ = -(*p1++);
+ *p1 = *p0++ >> h_shift;
+ *p2++ = -(*p1++);
+ *p1 = *p0++ >> h_shift;
+ *p2++ = -(*p1++);
+ *p1 = *p0++ >> h_shift;
+ *p2++ = -(*p1++);
+ }
+
+ /*------------------------------------------------------------*
+ * Compute rrixix[][] needed for the codebook search. *
+ * This algorithm compute impulse response energy of all *
+ * positions (16) in each track (4). Total = 4x16 = 64. *
+ *------------------------------------------------------------*/
+
+ /* storage order --> i3i3, i2i2, i1i1, i0i0 */
+
+ /* Init pointers to last position of rrixix[] */
+ p0 = &rrixix[0][NB_POS - 1];
+ p1 = &rrixix[1][NB_POS - 1];
+ p2 = &rrixix[2][NB_POS - 1];
+ p3 = &rrixix[3][NB_POS - 1];
+
+ ptr_h1 = h;
+ cor = 0x00008000L; /* for rounding */
+ for (i = 0; i < NB_POS; i++)
+ {
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h1)));
+ ptr_h1++;
+ *p3-- = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h1)));
+ ptr_h1++;
+ *p2-- = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h1)));
+ ptr_h1++;
+ *p1-- = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h1)));
+ ptr_h1++;
+ *p0-- = extract_h(cor);
+ }
+
+ /*------------------------------------------------------------*
+ * Compute rrixiy[][] needed for the codebook search. *
+ * This algorithm compute correlation between 2 pulses *
+ * (2 impulses responses) in 4 possible adjacents tracks. *
+ * (track 0-1, 1-2, 2-3 and 3-0). Total = 4x16x16 = 1024. *
+ *------------------------------------------------------------*/
+
+ /* storage order --> i2i3, i1i2, i0i1, i3i0 */
+
+ pos = MSIZE - 1;
+ ptr_hf = h + 1;
+
+ for (k = 0; k < NB_POS; k++)
+ {
+ p3 = &rrixiy[2][pos];
+ p2 = &rrixiy[1][pos];
+ p1 = &rrixiy[0][pos];
+ p0 = &rrixiy[3][pos - NB_POS];
+
+ cor = 0x00008000L; /* for rounding */
+ ptr_h1 = h;
+ ptr_h2 = ptr_hf;
+
+ for (i = k + 1; i < NB_POS; i++)
+ {
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p3 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p2 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p1 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p0 = extract_h(cor);
+
+ p3 -= (NB_POS + 1);
+ p2 -= (NB_POS + 1);
+ p1 -= (NB_POS + 1);
+ p0 -= (NB_POS + 1);
+ }
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p3 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p2 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p1 = extract_h(cor);
+
+ pos -= NB_POS;
+ ptr_hf += STEP;
+ }
+
+ /* storage order --> i3i0, i2i3, i1i2, i0i1 */
+
+ pos = MSIZE - 1;
+ ptr_hf = h + 3;
+
+ for (k = 0; k < NB_POS; k++)
+ {
+ p3 = &rrixiy[3][pos];
+ p2 = &rrixiy[2][pos - 1];
+ p1 = &rrixiy[1][pos - 1];
+ p0 = &rrixiy[0][pos - 1];
+
+ cor = 0x00008000L; /* for rounding */
+ ptr_h1 = h;
+ ptr_h2 = ptr_hf;
+
+ for (i = k + 1; i < NB_POS; i++)
+ {
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p3 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p2 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p1 = extract_h(cor);
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p0 = extract_h(cor);
+
+ p3 -= (NB_POS + 1);
+ p2 -= (NB_POS + 1);
+ p1 -= (NB_POS + 1);
+ p0 -= (NB_POS + 1);
+ }
+ cor = L_add(cor, vo_L_mult((*ptr_h1), (*ptr_h2)));
+ ptr_h1++;
+ ptr_h2++;
+ *p3 = extract_h(cor);
+
+ pos--;
+ ptr_hf += STEP;
+ }
+
+ /*------------------------------------------------------------*
+ * Modification of rrixiy[][] to take signs into account. *
+ *------------------------------------------------------------*/
+
+ p0 = &rrixiy[0][0];
+
+ for (k = 0; k < NB_TRACK; k++)
+ {
+ j_temp = (k + 1)&0x03;
+ for (i = k; i < L_SUBFR; i += STEP)
+ {
+ psign = sign;
+ if (psign[i] < 0)
+ {
+ psign = vec;
+ }
+ j = j_temp;
+ for (; j < L_SUBFR; j += STEP)
+ {
+ *p0 = vo_mult(*p0, psign[j]);
+ p0++;
+ }
+ }
+ }
+
+ /*-------------------------------------------------------------------*
+ * Deep first search *
+ *-------------------------------------------------------------------*/
+
+ psk = -1;
+ alpk = 1;
+
+ for (k = 0; k < nbiter; k++)
+ {
+ j_temp = k<<2;
+ for (i = 0; i < nb_pulse; i++)
+ ipos[i] = tipos[j_temp + i];
+
+ if(nbbits == 20)
+ {
+ pos = 0;
+ ps = 0;
+ alp = 0;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ vec[i] = 0;
+ }
+ } else if ((nbbits == 36) || (nbbits == 44))
+ {
+ /* first stage: fix 2 pulses */
+ pos = 2;
+
+ ix = ind[0] = pos_max[ipos[0]];
+ iy = ind[1] = pos_max[ipos[1]];
+ ps = dn[ix] + dn[iy];
+ i = ix >> 2; /* ix / STEP */
+ j = iy >> 2; /* iy / STEP */
+ s = rrixix[ipos[0]][i] << 13;
+ s += rrixix[ipos[1]][j] << 13;
+ i = (i << 4) + j; /* (ix/STEP)*NB_POS + (iy/STEP) */
+ s += rrixiy[ipos[0]][i] << 14;
+ alp = (s + 0x8000) >> 16;
+ if (sign[ix] < 0)
+ p0 = h_inv - ix;
+ else
+ p0 = h - ix;
+ if (sign[iy] < 0)
+ p1 = h_inv - iy;
+ else
+ p1 = h - iy;
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ vec[i] = (*p0++) + (*p1++);
+ }
+
+ if(nbbits == 44)
+ {
+ ipos[8] = 0;
+ ipos[9] = 1;
+ }
+ } else
+ {
+ /* first stage: fix 4 pulses */
+ pos = 4;
+
+ ix = ind[0] = pos_max[ipos[0]];
+ iy = ind[1] = pos_max[ipos[1]];
+ i = ind[2] = pos_max[ipos[2]];
+ j = ind[3] = pos_max[ipos[3]];
+ ps = add1(add1(add1(dn[ix], dn[iy]), dn[i]), dn[j]);
+
+ if (sign[ix] < 0)
+ p0 = h_inv - ix;
+ else
+ p0 = h - ix;
+
+ if (sign[iy] < 0)
+ p1 = h_inv - iy;
+ else
+ p1 = h - iy;
+
+ if (sign[i] < 0)
+ p2 = h_inv - i;
+ else
+ p2 = h - i;
+
+ if (sign[j] < 0)
+ p3 = h_inv - j;
+ else
+ p3 = h - j;
+
+ L_tmp = 0L;
+ for(i = 0; i < L_SUBFR; i++)
+ {
+ Word32 vecSq2;
+ vec[i] = add1(add1(add1(*p0++, *p1++), *p2++), *p3++);
+ vecSq2 = (vec[i] * vec[i]) << 1;
+ if (vecSq2 > 0 && L_tmp > INT_MAX - vecSq2) {
+ L_tmp = INT_MAX;
+ } else if (vecSq2 < 0 && L_tmp < INT_MIN - vecSq2) {
+ L_tmp = INT_MIN;
+ } else {
+ L_tmp += vecSq2;
+ }
+ }
+
+ alp = ((L_tmp >> 3) + 0x8000) >> 16;
+
+ if(nbbits == 72)
+ {
+ ipos[16] = 0;
+ ipos[17] = 1;
+ }
+ }
+
+ /* other stages of 2 pulses */
+
+ for (j = pos, st = 0; j < nb_pulse; j += 2, st++)
+ {
+ /*--------------------------------------------------*
+ * Calculate correlation of all possible positions *
+ * of the next 2 pulses with previous fixed pulses. *
+ * Each pulse can have 16 possible positions. *
+ *--------------------------------------------------*/
+ if(ipos[j] == 3)
+ {
+ cor_h_vec_30(h, vec, ipos[j], sign, rrixix, cor_x, cor_y);
+ }
+ else
+ {
+#ifdef ASM_OPT /* asm optimization branch */
+ cor_h_vec_012_asm(h, vec, ipos[j], sign, rrixix, cor_x, cor_y);
+#else
+ cor_h_vec_012(h, vec, ipos[j], sign, rrixix, cor_x, cor_y);
+#endif
+ }
+ /*--------------------------------------------------*
+ * Find best positions of 2 pulses. *
+ *--------------------------------------------------*/
+ search_ixiy(nbpos[st], ipos[j], ipos[j + 1], &ps, &alp,
+ &ix, &iy, dn, dn2, cor_x, cor_y, rrixiy);
+
+ ind[j] = ix;
+ ind[j + 1] = iy;
+
+ if (sign[ix] < 0)
+ p0 = h_inv - ix;
+ else
+ p0 = h - ix;
+ if (sign[iy] < 0)
+ p1 = h_inv - iy;
+ else
+ p1 = h - iy;
+
+ for (i = 0; i < L_SUBFR; i+=4)
+ {
+ vec[i] += add1((*p0++), (*p1++));
+ vec[i+1] += add1((*p0++), (*p1++));
+ vec[i+2] += add1((*p0++), (*p1++));
+ vec[i+3] += add1((*p0++), (*p1++));
+ }
+ }
+ /* memorise the best codevector */
+ ps = vo_mult(ps, ps);
+ s = L_sub(vo_L_mult(alpk, ps), vo_L_mult(psk, alp));
+ if (s > 0)
+ {
+ psk = ps;
+ alpk = alp;
+ for (i = 0; i < nb_pulse; i++)
+ {
+ codvec[i] = ind[i];
+ }
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ y[i] = vec[i];
+ }
+ }
+ }
+ /*-------------------------------------------------------------------*
+ * Build the codeword, the filtered codeword and index of codevector.*
+ *-------------------------------------------------------------------*/
+ for (i = 0; i < NPMAXPT * NB_TRACK; i++)
+ {
+ ind[i] = -1;
+ }
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ code[i] = 0;
+ y[i] = vo_shr_r(y[i], 3); /* Q12 to Q9 */
+ }
+ val = (512 >> h_shift); /* codeword in Q9 format */
+ for (k = 0; k < nb_pulse; k++)
+ {
+ i = codvec[k]; /* read pulse position */
+ j = sign[i]; /* read sign */
+ index = i >> 2; /* index = pos of pulse (0..15) */
+ track = (Word16) (i & 0x03); /* track = i % NB_TRACK (0..3) */
+
+ if (j > 0)
+ {
+ code[i] += val;
+ codvec[k] += 128;
+ } else
+ {
+ code[i] -= val;
+ index += NB_POS;
+ }
+
+ i = (Word16)((vo_L_mult(track, NPMAXPT) >> 1));
+
+ while (i < NPMAXPT * NB_TRACK && ind[i] >= 0)
+ {
+ i += 1;
+ }
+ if (i < NPMAXPT * NB_TRACK) {
+ ind[i] = index;
+ } else {
+ ALOGE("b/132647222, OOB access in ind array track=%d i=%d", track, i);
+ android_errorWriteLog(0x534e4554, "132647222");
+ }
+ }
+
+ k = 0;
+ /* Build index of codevector */
+ if(nbbits == 20)
+ {
+ for (track = 0; track < NB_TRACK; track++)
+ {
+ _index[track] = (Word16)(quant_1p_N1(ind[k], 4));
+ k += NPMAXPT;
+ }
+ } else if(nbbits == 36)
+ {
+ for (track = 0; track < NB_TRACK; track++)
+ {
+ _index[track] = (Word16)(quant_2p_2N1(ind[k], ind[k + 1], 4));
+ k += NPMAXPT;
+ }
+ } else if(nbbits == 44)
+ {
+ for (track = 0; track < NB_TRACK - 2; track++)
+ {
+ _index[track] = (Word16)(quant_3p_3N1(ind[k], ind[k + 1], ind[k + 2], 4));
+ k += NPMAXPT;
+ }
+ for (track = 2; track < NB_TRACK; track++)
+ {
+ _index[track] = (Word16)(quant_2p_2N1(ind[k], ind[k + 1], 4));
+ k += NPMAXPT;
+ }
+ } else if(nbbits == 52)
+ {
+ for (track = 0; track < NB_TRACK; track++)
+ {
+ _index[track] = (Word16)(quant_3p_3N1(ind[k], ind[k + 1], ind[k + 2], 4));
+ k += NPMAXPT;
+ }
+ } else if(nbbits == 64)
+ {
+ for (track = 0; track < NB_TRACK; track++)
+ {
+ L_index = quant_4p_4N(&ind[k], 4);
+ _index[track] = (Word16)((L_index >> 14) & 3);
+ _index[track + NB_TRACK] = (Word16)(L_index & 0x3FFF);
+ k += NPMAXPT;
+ }
+ } else if(nbbits == 72)
+ {
+ for (track = 0; track < NB_TRACK - 2; track++)
+ {
+ L_index = quant_5p_5N(&ind[k], 4);
+ _index[track] = (Word16)((L_index >> 10) & 0x03FF);
+ _index[track + NB_TRACK] = (Word16)(L_index & 0x03FF);
+ k += NPMAXPT;
+ }
+ for (track = 2; track < NB_TRACK; track++)
+ {
+ L_index = quant_4p_4N(&ind[k], 4);
+ _index[track] = (Word16)((L_index >> 14) & 3);
+ _index[track + NB_TRACK] = (Word16)(L_index & 0x3FFF);
+ k += NPMAXPT;
+ }
+ } else if(nbbits == 88)
+ {
+ for (track = 0; track < NB_TRACK; track++)
+ {
+ L_index = quant_6p_6N_2(&ind[k], 4);
+ _index[track] = (Word16)((L_index >> 11) & 0x07FF);
+ _index[track + NB_TRACK] = (Word16)(L_index & 0x07FF);
+ k += NPMAXPT;
+ }
+ }
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * Function cor_h_vec() *
+ * ~~~~~~~~~~~~~~~~~~~~~ *
+ * Compute correlations of h[] with vec[] for the specified track. *
+ *-------------------------------------------------------------------*/
+void cor_h_vec_30(
+ Word16 h[], /* (i) scaled impulse response */
+ Word16 vec[], /* (i) scaled vector (/8) to correlate with h[] */
+ Word16 track, /* (i) track to use */
+ Word16 sign[], /* (i) sign vector */
+ Word16 rrixix[][NB_POS], /* (i) correlation of h[x] with h[x] */
+ Word16 cor_1[], /* (o) result of correlation (NB_POS elements) */
+ Word16 cor_2[] /* (o) result of correlation (NB_POS elements) */
+ )
+{
+ Word32 i, j, pos, corr;
+ Word16 *p0, *p1, *p2,*p3,*cor_x,*cor_y;
+ Word32 L_sum1,L_sum2;
+ cor_x = cor_1;
+ cor_y = cor_2;
+ p0 = rrixix[track];
+ p3 = rrixix[0];
+ pos = track;
+
+ for (i = 0; i < NB_POS; i+=2)
+ {
+ L_sum1 = L_sum2 = 0L;
+ p1 = h;
+ p2 = &vec[pos];
+ for (j=pos;j < L_SUBFR; j++)
+ {
+ L_sum1 = L_add(L_sum1, *p1 * *p2);
+ p2-=3;
+ L_sum2 = L_add(L_sum2, *p1++ * *p2);
+ p2+=4;
+ }
+ p2-=3;
+ L_sum2 = L_add(L_sum2, *p1++ * *p2++);
+ L_sum2 = L_add(L_sum2, *p1++ * *p2++);
+ L_sum2 = L_add(L_sum2, *p1++ * *p2++);
+
+ L_sum1 = L_shl(L_sum1, 2);
+ L_sum2 = L_shl(L_sum2, 2);
+
+ corr = voround(L_sum1);
+ *cor_x++ = mult(corr, sign[pos]) + (*p0++);
+ corr = voround(L_sum2);
+ *cor_y++ = mult(corr, sign[pos-3]) + (*p3++);
+ pos += STEP;
+
+ L_sum1 = L_sum2 = 0L;
+ p1 = h;
+ p2 = &vec[pos];
+ for (j=pos;j < L_SUBFR; j++)
+ {
+ L_sum1 = L_add(L_sum1, *p1 * *p2);
+ p2-=3;
+ L_sum2 = L_add(L_sum2, *p1++ * *p2);
+ p2+=4;
+ }
+ p2-=3;
+ L_sum2 = L_add(L_sum2, *p1++ * *p2++);
+ L_sum2 = L_add(L_sum2, *p1++ * *p2++);
+ L_sum2 = L_add(L_sum2, *p1++ * *p2++);
+
+ L_sum1 = L_shl(L_sum1, 2);
+ L_sum2 = L_shl(L_sum2, 2);
+
+ corr = voround(L_sum1);
+ *cor_x++ = mult(corr, sign[pos]) + (*p0++);
+ corr = voround(L_sum2);
+ *cor_y++ = mult(corr, sign[pos-3]) + (*p3++);
+ pos += STEP;
+ }
+ return;
+}
+
+void cor_h_vec_012(
+ Word16 h[], /* (i) scaled impulse response */
+ Word16 vec[], /* (i) scaled vector (/8) to correlate with h[] */
+ Word16 track, /* (i) track to use */
+ Word16 sign[], /* (i) sign vector */
+ Word16 rrixix[][NB_POS], /* (i) correlation of h[x] with h[x] */
+ Word16 cor_1[], /* (o) result of correlation (NB_POS elements) */
+ Word16 cor_2[] /* (o) result of correlation (NB_POS elements) */
+ )
+{
+ Word32 i, j, pos, corr;
+ Word16 *p0, *p1, *p2,*p3,*cor_x,*cor_y;
+ Word32 L_sum1,L_sum2;
+ cor_x = cor_1;
+ cor_y = cor_2;
+ p0 = rrixix[track];
+ p3 = rrixix[track+1];
+ pos = track;
+
+ for (i = 0; i < NB_POS; i+=2)
+ {
+ L_sum1 = L_sum2 = 0L;
+ p1 = h;
+ p2 = &vec[pos];
+ for (j=62-pos ;j >= 0; j--)
+ {
+ L_sum1 = L_add(L_sum1, *p1 * *p2++);
+ L_sum2 = L_add(L_sum2, *p1++ * *p2);
+ }
+ L_sum1 = L_add(L_sum1, *p1 * *p2);
+ L_sum1 = L_shl(L_sum1, 2);
+ L_sum2 = L_shl(L_sum2, 2);
+
+ corr = voround(L_sum1);
+ cor_x[i] = vo_mult(corr, sign[pos]) + (*p0++);
+ corr = voround(L_sum2);
+ cor_y[i] = vo_mult(corr, sign[pos + 1]) + (*p3++);
+ pos += STEP;
+
+ L_sum1 = L_sum2 = 0L;
+ p1 = h;
+ p2 = &vec[pos];
+ for (j= 62-pos;j >= 0; j--)
+ {
+ L_sum1 = L_add(L_sum1, *p1 * *p2++);
+ L_sum2 = L_add(L_sum2, *p1++ * *p2);
+ }
+ L_sum1 = L_add(L_sum1, *p1 * *p2);
+ L_sum1 = L_shl(L_sum1, 2);
+ L_sum2 = L_shl(L_sum2, 2);
+
+ corr = voround(L_sum1);
+ cor_x[i+1] = vo_mult(corr, sign[pos]) + (*p0++);
+ corr = voround(L_sum2);
+ cor_y[i+1] = vo_mult(corr, sign[pos + 1]) + (*p3++);
+ pos += STEP;
+ }
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * Function search_ixiy() *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * Find the best positions of 2 pulses in a subframe. *
+ *-------------------------------------------------------------------*/
+
+void search_ixiy(
+ Word16 nb_pos_ix, /* (i) nb of pos for pulse 1 (1..8) */
+ Word16 track_x, /* (i) track of pulse 1 */
+ Word16 track_y, /* (i) track of pulse 2 */
+ Word16 * ps, /* (i/o) correlation of all fixed pulses */
+ Word16 * alp, /* (i/o) energy of all fixed pulses */
+ Word16 * ix, /* (o) position of pulse 1 */
+ Word16 * iy, /* (o) position of pulse 2 */
+ Word16 dn[], /* (i) corr. between target and h[] */
+ Word16 dn2[], /* (i) vector of selected positions */
+ Word16 cor_x[], /* (i) corr. of pulse 1 with fixed pulses */
+ Word16 cor_y[], /* (i) corr. of pulse 2 with fixed pulses */
+ Word16 rrixiy[][MSIZE] /* (i) corr. of pulse 1 with pulse 2 */
+ )
+{
+ Word32 x, y, pos, thres_ix;
+ Word16 ps1, ps2, sq, sqk;
+ Word16 alp_16, alpk;
+ Word16 *p0, *p1, *p2;
+ Word32 s, alp0, alp1, alp2;
+
+ p0 = cor_x;
+ p1 = cor_y;
+ p2 = rrixiy[track_x];
+
+ thres_ix = nb_pos_ix - NB_MAX;
+
+ alp0 = L_deposit_h(*alp);
+ alp0 = (alp0 + 0x00008000L); /* for rounding */
+
+ sqk = -1;
+ alpk = 1;
+
+ for (x = track_x; x < L_SUBFR; x += STEP)
+ {
+ ps1 = *ps + dn[x];
+ alp1 = L_add(alp0, ((*p0++)<<13));
+
+ if (dn2[x] < thres_ix)
+ {
+ pos = -1;
+ for (y = track_y; y < L_SUBFR; y += STEP)
+ {
+ ps2 = add1(ps1, dn[y]);
+
+ alp2 = L_add(alp1, ((*p1++)<<13));
+ alp2 = L_add(alp2, ((*p2++)<<14));
+ alp_16 = extract_h(alp2);
+ sq = vo_mult(ps2, ps2);
+ s = L_sub(vo_L_mult(alpk, sq), L_mult(sqk, alp_16));
+
+ if (s > 0)
+ {
+ sqk = sq;
+ alpk = alp_16;
+ pos = y;
+ }
+ }
+ p1 -= NB_POS;
+
+ if (pos >= 0)
+ {
+ *ix = x;
+ *iy = pos;
+ }
+ } else
+ {
+ p2 += NB_POS;
+ }
+ }
+
+ *ps = add1(*ps, add1(dn[*ix], dn[*iy]));
+ *alp = alpk;
+
+ return;
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/convolve.c b/media/codecs/amrwb/enc/src/convolve.c
new file mode 100644
index 0000000..8c24414
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/convolve.c
@@ -0,0 +1,118 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+ File: convolve.c
+
+ Description:Perform the convolution between two vectors x[] and h[]
+ and write the result in the vector y[]
+
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+#define UNUSED(x) (void)(x)
+
+void Convolve (
+ Word16 x[], /* (i) : input vector */
+ Word16 h[], /* (i) : impulse response */
+ Word16 y[], /* (o) : output vector */
+ Word16 L /* (i) : vector size */
+ )
+{
+ Word32 i, n;
+ Word16 *tmpH,*tmpX;
+ Word32 s;
+ UNUSED(L);
+
+ for (n = 0; n < 64;)
+ {
+ tmpH = h+n;
+ tmpX = x;
+ i=n+1;
+ s = vo_mult32((*tmpX++), (*tmpH--));i--;
+ while(i>0)
+ {
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ i -= 4;
+ }
+ y[n] = voround(L_shl(s, 1));
+ n++;
+
+ tmpH = h+n;
+ tmpX = x;
+ i=n+1;
+ s = vo_mult32((*tmpX++), (*tmpH--));
+ i--;
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ i--;
+
+ while(i>0)
+ {
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ i -= 4;
+ }
+ y[n] = voround(L_shl(s, 1));
+ n++;
+
+ tmpH = h+n;
+ tmpX = x;
+ i=n+1;
+ s = vo_mult32((*tmpX++), (*tmpH--));
+ i--;
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ i--;
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ i--;
+
+ while(i>0)
+ {
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ i -= 4;
+ }
+ y[n] = voround(L_shl(s, 1));
+ n++;
+
+ s = 0;
+ tmpH = h+n;
+ tmpX = x;
+ i=n+1;
+ while(i>0)
+ {
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
+ i -= 4;
+ }
+ y[n] = voround(L_shl(s, 1));
+ n++;
+ }
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/cor_h_x.c b/media/codecs/amrwb/enc/src/cor_h_x.c
new file mode 100644
index 0000000..e834396
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/cor_h_x.c
@@ -0,0 +1,133 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: cor_h_x.c *
+* *
+* Description:Compute correlation between target "x[]" and "h[]" *
+* Designed for codebook search (24 pulses, 4 tracks, *
+* 4 pulses per track, 16 positions in each track) to *
+* avoid saturation. *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+
+#define L_SUBFR 64
+#define NB_TRACK 4
+#define STEP 4
+
+void cor_h_x(
+ Word16 h[], /* (i) Q12 : impulse response of weighted synthesis filter */
+ Word16 x[], /* (i) Q0 : target vector */
+ Word16 dn[] /* (o) <12bit : correlation between target and h[] */
+ )
+{
+ Word32 i, j;
+ Word32 L_tmp, y32[L_SUBFR], L_tot;
+ Word16 *p1, *p2;
+ Word32 *p3;
+ Word32 L_max, L_max1, L_max2, L_max3;
+ /* first keep the result on 32 bits and find absolute maximum */
+ L_tot = 1;
+ L_max = 0;
+ L_max1 = 0;
+ L_max2 = 0;
+ L_max3 = 0;
+ for (i = 0; i < L_SUBFR; i += STEP)
+ {
+ L_tmp = 1; /* 1 -> to avoid null dn[] */
+ p1 = &x[i];
+ p2 = &h[0];
+ for (j = i; j < L_SUBFR; j++)
+ L_tmp = L_add(L_tmp, vo_L_mult(*p1++, *p2++));
+
+ y32[i] = L_tmp;
+ L_tmp = (L_tmp > 0)? L_tmp: (L_tmp == INT_MIN ? INT_MAX : -L_tmp);
+ if(L_tmp > L_max)
+ {
+ L_max = L_tmp;
+ }
+
+ L_tmp = 1L;
+ p1 = &x[i+1];
+ p2 = &h[0];
+ for (j = i+1; j < L_SUBFR; j++)
+ L_tmp = L_add(L_tmp, vo_L_mult(*p1++, *p2++));
+
+ y32[i+1] = L_tmp;
+ L_tmp = (L_tmp > 0)? L_tmp: (L_tmp == INT_MIN ? INT_MAX : -L_tmp);
+ if(L_tmp > L_max1)
+ {
+ L_max1 = L_tmp;
+ }
+
+ L_tmp = 1;
+ p1 = &x[i+2];
+ p2 = &h[0];
+ for (j = i+2; j < L_SUBFR; j++)
+ L_tmp = L_add(L_tmp, vo_L_mult(*p1++, *p2++));
+
+ y32[i+2] = L_tmp;
+ L_tmp = (L_tmp > 0)? L_tmp: (L_tmp == INT_MIN ? INT_MAX : -L_tmp);
+ if(L_tmp > L_max2)
+ {
+ L_max2 = L_tmp;
+ }
+
+ L_tmp = 1;
+ p1 = &x[i+3];
+ p2 = &h[0];
+ for (j = i+3; j < L_SUBFR; j++)
+ L_tmp = L_add(L_tmp, vo_L_mult(*p1++, *p2++));
+
+ y32[i+3] = L_tmp;
+ L_tmp = (L_tmp > 0)? L_tmp: (L_tmp == INT_MIN ? INT_MAX : -L_tmp);
+ if(L_tmp > L_max3)
+ {
+ L_max3 = L_tmp;
+ }
+ }
+ /* tot += 3*max / 8 */
+ if (L_max > INT_MAX - L_max1 ||
+ L_max + L_max1 > INT_MAX - L_max2 ||
+ L_max + L_max1 + L_max2 > INT_MAX - L_max3) {
+ L_max = INT_MAX >> 2;
+ } else {
+ L_max = ((L_max + L_max1 + L_max2 + L_max3) >> 2);
+ }
+ L_tot = vo_L_add(L_tot, L_max); /* +max/4 */
+ L_tot = vo_L_add(L_tot, (L_max >> 1)); /* +max/8 */
+
+ /* Find the number of right shifts to do on y32[] so that */
+ /* 6.0 x sumation of max of dn[] in each track not saturate. */
+ j = norm_l(L_tot) - 4; /* 4 -> 16 x tot */
+ p1 = dn;
+ p3 = y32;
+ for (i = 0; i < L_SUBFR; i+=4)
+ {
+ *p1++ = vo_round(L_shl(*p3++, j));
+ *p1++ = vo_round(L_shl(*p3++, j));
+ *p1++ = vo_round(L_shl(*p3++, j));
+ *p1++ = vo_round(L_shl(*p3++, j));
+ }
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/decim54.c b/media/codecs/amrwb/enc/src/decim54.c
new file mode 100644
index 0000000..e4c7940
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/decim54.c
@@ -0,0 +1,146 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: decim54.c *
+* *
+* Description:Decimation of 16kHz signal to 12.8kHz *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "acelp.h"
+#include "cnst.h"
+
+#define FAC5 5
+#define DOWN_FAC 26215 /* 4/5 in Q15 */
+
+#define NB_COEF_DOWN 15
+
+/* Local functions */
+static void Down_samp(
+ Word16 * sig, /* input: signal to downsampling */
+ Word16 * sig_d, /* output: downsampled signal */
+ Word16 L_frame_d /* input: length of output */
+ );
+
+/* 1/5 resolution interpolation filter (in Q14) */
+/* -1.5dB @ 6kHz, -6dB @ 6.4kHz, -10dB @ 6.6kHz, -20dB @ 6.9kHz, -25dB @ 7kHz, -55dB @ 8kHz */
+
+static Word16 fir_down1[4][30] =
+{
+ {-5, 24, -50, 54, 0, -128, 294, -408, 344, 0, -647, 1505, -2379, 3034, 13107, 3034, -2379, 1505, -647, 0, 344, -408,
+ 294, -128, 0, 54, -50, 24, -5, 0},
+
+ {-6, 19, -26, 0, 77, -188, 270, -233, 0, 434, -964, 1366, -1293, 0, 12254, 6575, -2746, 1030, 0, -507, 601, -441,
+ 198, 0, -95, 99, -58, 18, 0, -1},
+
+ {-3, 9, 0, -41, 111, -170, 153, 0, -295, 649, -888, 770, 0, -1997, 9894, 9894, -1997, 0, 770, -888, 649, -295, 0,
+ 153, -170, 111, -41, 0, 9, -3},
+
+ {-1, 0, 18, -58, 99, -95, 0, 198, -441, 601, -507, 0, 1030, -2746, 6575, 12254, 0, -1293, 1366, -964, 434, 0,
+ -233, 270, -188, 77, 0, -26, 19, -6}
+};
+
+void Init_Decim_12k8(
+ Word16 mem[] /* output: memory (2*NB_COEF_DOWN) set to zeros */
+ )
+{
+ Set_zero(mem, 2 * NB_COEF_DOWN);
+ return;
+}
+
+void Decim_12k8(
+ Word16 sig16k[], /* input: signal to downsampling */
+ Word16 lg, /* input: length of input */
+ Word16 sig12k8[], /* output: decimated signal */
+ Word16 mem[] /* in/out: memory (2*NB_COEF_DOWN) */
+ )
+{
+ Word16 lg_down;
+ Word16 signal[L_FRAME16k + (2 * NB_COEF_DOWN)];
+
+ Copy(mem, signal, 2 * NB_COEF_DOWN);
+
+ Copy(sig16k, signal + (2 * NB_COEF_DOWN), lg);
+
+ lg_down = (lg * DOWN_FAC)>>15;
+
+ Down_samp(signal + NB_COEF_DOWN, sig12k8, lg_down);
+
+ Copy(signal + lg, mem, 2 * NB_COEF_DOWN);
+
+ return;
+}
+
+static void Down_samp(
+ Word16 * sig, /* input: signal to downsampling */
+ Word16 * sig_d, /* output: downsampled signal */
+ Word16 L_frame_d /* input: length of output */
+ )
+{
+ Word32 i, j, frac, pos;
+ Word16 *x, *y;
+ Word32 L_sum;
+
+ pos = 0; /* position is in Q2 -> 1/4 resolution */
+ for (j = 0; j < L_frame_d; j++)
+ {
+ i = (pos >> 2); /* integer part */
+ frac = pos & 3; /* fractional part */
+ x = sig + i - NB_COEF_DOWN + 1;
+ y = (Word16 *)(fir_down1 + frac);
+
+ L_sum = vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x++),(*y++));
+ L_sum += vo_mult32((*x),(*y));
+
+ L_sum = L_shl2(L_sum, 2);
+ sig_d[j] = extract_h(L_add(L_sum, 0x8000));
+ pos += FAC5; /* pos + 5/4 */
+ }
+ return;
+}
+
+
diff --git a/media/codecs/amrwb/enc/src/deemph.c b/media/codecs/amrwb/enc/src/deemph.c
new file mode 100644
index 0000000..cc27f6e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/deemph.c
@@ -0,0 +1,120 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: deemph.c *
+* *
+* Description:filtering through 1/(1-mu z^ -1) *
+* Deemph2 --> signal is divided by 2 *
+* Deemph_32 --> for 32 bits signal. *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+
+void Deemph(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : deemphasis factor */
+ Word16 L, /* (i) : vector size */
+ Word16 * mem /* (i/o) : memory (y[-1]) */
+ )
+{
+ Word32 i;
+ Word32 L_tmp;
+
+ L_tmp = L_deposit_h(x[0]);
+ L_tmp = L_mac(L_tmp, *mem, mu);
+ x[0] = vo_round(L_tmp);
+
+ for (i = 1; i < L; i++)
+ {
+ L_tmp = L_deposit_h(x[i]);
+ L_tmp = L_mac(L_tmp, x[i - 1], mu);
+ x[i] = voround(L_tmp);
+ }
+
+ *mem = x[L - 1];
+
+ return;
+}
+
+
+void Deemph2(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : deemphasis factor */
+ Word16 L, /* (i) : vector size */
+ Word16 * mem /* (i/o) : memory (y[-1]) */
+ )
+{
+ Word32 i;
+ Word32 L_tmp;
+ L_tmp = x[0] << 15;
+ i = L_mult(*mem, mu);
+ L_tmp = L_add(L_tmp, i);
+ x[0] = voround(L_tmp);
+ for (i = 1; i < L; i++)
+ {
+ Word32 tmp;
+ L_tmp = x[i] << 15;
+ tmp = (x[i - 1] * mu)<<1;
+ L_tmp = L_add(L_tmp, tmp);
+ x[i] = voround(L_tmp);
+ }
+ *mem = x[L - 1];
+ return;
+}
+
+
+void Deemph_32(
+ Word16 x_hi[], /* (i) : input signal (bit31..16) */
+ Word16 x_lo[], /* (i) : input signal (bit15..4) */
+ Word16 y[], /* (o) : output signal (x16) */
+ Word16 mu, /* (i) Q15 : deemphasis factor */
+ Word16 L, /* (i) : vector size */
+ Word16 * mem /* (i/o) : memory (y[-1]) */
+ )
+{
+ Word16 fac;
+ Word32 i, L_tmp;
+
+ fac = mu >> 1; /* Q15 --> Q14 */
+
+ L_tmp = L_deposit_h(x_hi[0]);
+ L_tmp += (x_lo[0] * 8)<<1;
+ L_tmp = (L_tmp << 3);
+ L_tmp += ((*mem) * fac)<<1;
+ L_tmp = (L_tmp << 1);
+ y[0] = (L_tmp + 0x8000)>>16;
+
+ for (i = 1; i < L; i++)
+ {
+ L_tmp = L_deposit_h(x_hi[i]);
+ L_tmp += (x_lo[i] * 8)<<1;
+ L_tmp = (L_tmp << 3);
+ L_tmp += (y[i - 1] * fac)<<1;
+ L_tmp = (L_tmp << 1);
+ y[i] = (L_tmp + 0x8000)>>16;
+ }
+
+ *mem = y[L - 1];
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/dtx.c b/media/codecs/amrwb/enc/src/dtx.c
new file mode 100644
index 0000000..6be8683
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/dtx.c
@@ -0,0 +1,605 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: dtx.c *
+* *
+* Description:DTX functions *
+* *
+************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "math_op.h"
+#include "cnst.h"
+#include "acelp.h" /* prototype of functions */
+#include "bits.h"
+#include "dtx.h"
+#include "log2.h"
+#include "mem_align.h"
+
+static void aver_isf_history(
+ Word16 isf_old[],
+ Word16 indices[],
+ Word32 isf_aver[]
+ );
+
+static void find_frame_indices(
+ Word16 isf_old_tx[],
+ Word16 indices[],
+ dtx_encState * st
+ );
+
+static Word16 dithering_control(
+ dtx_encState * st
+ );
+
+/* excitation energy adjustment depending on speech coder mode used, Q7 */
+static Word16 en_adjust[9] =
+{
+ 230, /* mode0 = 7k : -5.4dB */
+ 179, /* mode1 = 9k : -4.2dB */
+ 141, /* mode2 = 12k : -3.3dB */
+ 128, /* mode3 = 14k : -3.0dB */
+ 122, /* mode4 = 16k : -2.85dB */
+ 115, /* mode5 = 18k : -2.7dB */
+ 115, /* mode6 = 20k : -2.7dB */
+ 115, /* mode7 = 23k : -2.7dB */
+ 115 /* mode8 = 24k : -2.7dB */
+};
+
+/**************************************************************************
+*
+* Function : dtx_enc_init
+*
+**************************************************************************/
+Word16 dtx_enc_init(dtx_encState ** st, Word16 isf_init[], VO_MEM_OPERATOR *pMemOP)
+{
+ dtx_encState *s;
+
+ if (st == (dtx_encState **) NULL)
+ {
+ fprintf(stderr, "dtx_enc_init: invalid parameter\n");
+ return -1;
+ }
+ *st = NULL;
+
+ /* allocate memory */
+ if ((s = (dtx_encState *)mem_malloc(pMemOP, sizeof(dtx_encState), 32, VO_INDEX_ENC_AMRWB)) == NULL)
+ {
+ fprintf(stderr, "dtx_enc_init: can not malloc state structure\n");
+ return -1;
+ }
+ dtx_enc_reset(s, isf_init);
+ *st = s;
+ return 0;
+}
+
+/**************************************************************************
+*
+* Function : dtx_enc_reset
+*
+**************************************************************************/
+Word16 dtx_enc_reset(dtx_encState * st, Word16 isf_init[])
+{
+ Word32 i;
+
+ if (st == (dtx_encState *) NULL)
+ {
+ fprintf(stderr, "dtx_enc_reset: invalid parameter\n");
+ return -1;
+ }
+ st->hist_ptr = 0;
+ st->log_en_index = 0;
+
+ /* Init isf_hist[] */
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ Copy(isf_init, &st->isf_hist[i * M], M);
+ }
+ st->cng_seed = RANDOM_INITSEED;
+
+ /* Reset energy history */
+ Set_zero(st->log_en_hist, DTX_HIST_SIZE);
+
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ st->decAnaElapsedCount = 32767;
+
+ for (i = 0; i < 28; i++)
+ {
+ st->D[i] = 0;
+ }
+
+ for (i = 0; i < DTX_HIST_SIZE - 1; i++)
+ {
+ st->sumD[i] = 0;
+ }
+
+ return 1;
+}
+
+/**************************************************************************
+*
+* Function : dtx_enc_exit
+*
+**************************************************************************/
+void dtx_enc_exit(dtx_encState ** st, VO_MEM_OPERATOR *pMemOP)
+{
+ if (st == NULL || *st == NULL)
+ return;
+ /* deallocate memory */
+ mem_free(pMemOP, *st, VO_INDEX_ENC_AMRWB);
+ *st = NULL;
+ return;
+}
+
+
+/**************************************************************************
+*
+* Function : dtx_enc
+*
+**************************************************************************/
+Word16 dtx_enc(
+ dtx_encState * st, /* i/o : State struct */
+ Word16 isf[M], /* o : CN ISF vector */
+ Word16 * exc2, /* o : CN excitation */
+ Word16 ** prms
+ )
+{
+ Word32 i, j;
+ Word16 indice[7];
+ Word16 log_en, gain, level, exp, exp0, tmp;
+ Word16 log_en_int_e, log_en_int_m;
+ Word32 L_isf[M], ener32, level32;
+ Word16 isf_order[3];
+ Word16 CN_dith;
+
+ /* VOX mode computation of SID parameters */
+ log_en = 0;
+ for (i = 0; i < M; i++)
+ {
+ L_isf[i] = 0;
+ }
+ /* average energy and isf */
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ /* Division by DTX_HIST_SIZE = 8 has been done in dtx_buffer. log_en is in Q10 */
+ log_en = add(log_en, st->log_en_hist[i]);
+
+ }
+ find_frame_indices(st->isf_hist, isf_order, st);
+ aver_isf_history(st->isf_hist, isf_order, L_isf);
+
+ for (j = 0; j < M; j++)
+ {
+ isf[j] = (Word16)(L_isf[j] >> 3); /* divide by 8 */
+ }
+
+ /* quantize logarithmic energy to 6 bits (-6 : 66 dB) which corresponds to -2:22 in log2(E). */
+ /* st->log_en_index = (short)( (log_en + 2.0) * 2.625 ); */
+
+ /* increase dynamics to 7 bits (Q8) */
+ log_en = (log_en >> 2);
+
+ /* Add 2 in Q8 = 512 to get log2(E) between 0:24 */
+ log_en = add(log_en, 512);
+
+ /* Multiply by 2.625 to get full 6 bit range. 2.625 = 21504 in Q13. The result is in Q6 */
+ log_en = mult(log_en, 21504);
+
+ /* Quantize Energy */
+ st->log_en_index = shr(log_en, 6);
+
+ if(st->log_en_index > 63)
+ {
+ st->log_en_index = 63;
+ }
+ if (st->log_en_index < 0)
+ {
+ st->log_en_index = 0;
+ }
+ /* Quantize ISFs */
+ Qisf_ns(isf, isf, indice);
+
+
+ Parm_serial(indice[0], 6, prms);
+ Parm_serial(indice[1], 6, prms);
+ Parm_serial(indice[2], 6, prms);
+ Parm_serial(indice[3], 5, prms);
+ Parm_serial(indice[4], 5, prms);
+
+ Parm_serial((st->log_en_index), 6, prms);
+
+ CN_dith = dithering_control(st);
+ Parm_serial(CN_dith, 1, prms);
+
+ /* level = (float)( pow( 2.0f, (float)st->log_en_index / 2.625 - 2.0 ) ); */
+ /* log2(E) in Q9 (log2(E) lies in between -2:22) */
+ log_en = shl(st->log_en_index, 15 - 6);
+
+ /* Divide by 2.625; log_en will be between 0:24 */
+ log_en = mult(log_en, 12483);
+ /* the result corresponds to log2(gain) in Q10 */
+
+ /* Find integer part */
+ log_en_int_e = (log_en >> 10);
+
+ /* Find fractional part */
+ log_en_int_m = (Word16) (log_en & 0x3ff);
+ log_en_int_m = shl(log_en_int_m, 5);
+
+ /* Subtract 2 from log_en in Q9, i.e divide the gain by 2 (energy by 4) */
+ /* Add 16 in order to have the result of pow2 in Q16 */
+ log_en_int_e = add(log_en_int_e, 16 - 1);
+
+ level32 = Pow2(log_en_int_e, log_en_int_m); /* Q16 */
+ exp0 = norm_l(level32);
+ level32 = (level32 << exp0); /* level in Q31 */
+ exp0 = (15 - exp0);
+ level = extract_h(level32); /* level in Q15 */
+
+ /* generate white noise vector */
+ for (i = 0; i < L_FRAME; i++)
+ {
+ exc2[i] = (Random(&(st->cng_seed)) >> 4);
+ }
+
+ /* gain = level / sqrt(ener) * sqrt(L_FRAME) */
+
+ /* energy of generated excitation */
+ ener32 = Dot_product12(exc2, exc2, L_FRAME, &exp);
+
+ Isqrt_n(&ener32, &exp);
+
+ gain = extract_h(ener32);
+
+ gain = mult(level, gain); /* gain in Q15 */
+
+ exp = add(exp0, exp);
+
+ /* Multiply by sqrt(L_FRAME)=16, i.e. shift left by 4 */
+ exp += 4;
+
+ for (i = 0; i < L_FRAME; i++)
+ {
+ tmp = mult(exc2[i], gain); /* Q0 * Q15 */
+ exc2[i] = shl(tmp, exp);
+ }
+
+ return 0;
+}
+
+/**************************************************************************
+*
+* Function : dtx_buffer Purpose : handles the DTX buffer
+*
+**************************************************************************/
+Word16 dtx_buffer(
+ dtx_encState * st, /* i/o : State struct */
+ Word16 isf_new[], /* i : isf vector */
+ Word32 enr, /* i : residual energy (in L_FRAME) */
+ Word16 codec_mode
+ )
+{
+ Word16 log_en;
+
+ Word16 log_en_e;
+ Word16 log_en_m;
+ st->hist_ptr = add(st->hist_ptr, 1);
+ if(st->hist_ptr == DTX_HIST_SIZE)
+ {
+ st->hist_ptr = 0;
+ }
+ /* copy lsp vector into buffer */
+ Copy(isf_new, &st->isf_hist[st->hist_ptr * M], M);
+
+ /* log_en = (float)log10(enr*0.0059322)/(float)log10(2.0f); */
+ Log2(enr, &log_en_e, &log_en_m);
+
+ /* convert exponent and mantissa to Word16 Q7. Q7 is used to simplify averaging in dtx_enc */
+ log_en = shl(log_en_e, 7); /* Q7 */
+ log_en = add(log_en, shr(log_en_m, 15 - 7));
+
+ /* Find energy per sample by multiplying with 0.0059322, i.e subtract log2(1/0.0059322) = 7.39722 The
+ * constant 0.0059322 takes into account windowings and analysis length from autocorrelation
+ * computations; 7.39722 in Q7 = 947 */
+ /* Subtract 3 dB = 0.99658 in log2(E) = 127 in Q7. */
+ /* log_en = sub( log_en, 947 + en_adjust[codec_mode] ); */
+
+ /* Find energy per sample (divide by L_FRAME=256), i.e subtract log2(256) = 8.0 (1024 in Q7) */
+ /* Subtract 3 dB = 0.99658 in log2(E) = 127 in Q7. */
+
+ log_en = sub(log_en, add(1024, en_adjust[codec_mode]));
+
+ /* Insert into the buffer */
+ st->log_en_hist[st->hist_ptr] = log_en;
+ return 0;
+}
+
+/**************************************************************************
+*
+* Function : tx_dtx_handler Purpose : adds extra speech hangover
+* to analyze speech on
+* the decoding side.
+**************************************************************************/
+void tx_dtx_handler(dtx_encState * st, /* i/o : State struct */
+ Word16 vad_flag, /* i : vad decision */
+ Word16 * usedMode /* i/o : mode changed or not */
+ )
+{
+
+ /* this state machine is in synch with the GSMEFR txDtx machine */
+ st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1);
+
+ if (vad_flag != 0)
+ {
+ st->dtxHangoverCount = DTX_HANG_CONST;
+ } else
+ { /* non-speech */
+ if (st->dtxHangoverCount == 0)
+ { /* out of decoder analysis hangover */
+ st->decAnaElapsedCount = 0;
+ *usedMode = MRDTX;
+ } else
+ { /* in possible analysis hangover */
+ st->dtxHangoverCount = sub(st->dtxHangoverCount, 1);
+
+ /* decAnaElapsedCount + dtxHangoverCount < DTX_ELAPSED_FRAMES_THRESH */
+ if (sub(add(st->decAnaElapsedCount, st->dtxHangoverCount),
+ DTX_ELAPSED_FRAMES_THRESH) < 0)
+ {
+ *usedMode = MRDTX;
+ /* if short time since decoder update, do not add extra HO */
+ }
+ /* else override VAD and stay in speech mode *usedMode and add extra hangover */
+ }
+ }
+
+ return;
+}
+
+
+
+static void aver_isf_history(
+ Word16 isf_old[],
+ Word16 indices[],
+ Word32 isf_aver[]
+ )
+{
+ Word32 i, j, k;
+ Word16 isf_tmp[2 * M];
+ Word32 L_tmp;
+
+ /* Memorize in isf_tmp[][] the ISF vectors to be replaced by */
+ /* the median ISF vector prior to the averaging */
+ for (k = 0; k < 2; k++)
+ {
+ if ((indices[k] + 1) != 0)
+ {
+ for (i = 0; i < M; i++)
+ {
+ isf_tmp[k * M + i] = isf_old[indices[k] * M + i];
+ isf_old[indices[k] * M + i] = isf_old[indices[2] * M + i];
+ }
+ }
+ }
+
+ /* Perform the ISF averaging */
+ for (j = 0; j < M; j++)
+ {
+ L_tmp = 0;
+
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ L_tmp = L_add(L_tmp, L_deposit_l(isf_old[i * M + j]));
+ }
+ isf_aver[j] = L_tmp;
+ }
+
+ /* Retrieve from isf_tmp[][] the ISF vectors saved prior to averaging */
+ for (k = 0; k < 2; k++)
+ {
+ if ((indices[k] + 1) != 0)
+ {
+ for (i = 0; i < M; i++)
+ {
+ isf_old[indices[k] * M + i] = isf_tmp[k * M + i];
+ }
+ }
+ }
+
+ return;
+}
+
+static void find_frame_indices(
+ Word16 isf_old_tx[],
+ Word16 indices[],
+ dtx_encState * st
+ )
+{
+ Word32 L_tmp, summin, summax, summax2nd;
+ Word16 i, j, tmp;
+ Word16 ptr;
+
+ /* Remove the effect of the oldest frame from the column */
+ /* sum sumD[0..DTX_HIST_SIZE-1]. sumD[DTX_HIST_SIZE] is */
+ /* not updated since it will be removed later. */
+
+ tmp = DTX_HIST_SIZE_MIN_ONE;
+ j = -1;
+ for (i = 0; i < DTX_HIST_SIZE_MIN_ONE; i++)
+ {
+ j = add(j, tmp);
+ st->sumD[i] = L_sub(st->sumD[i], st->D[j]);
+ tmp = sub(tmp, 1);
+ }
+
+ /* Shift the column sum sumD. The element sumD[DTX_HIST_SIZE-1] */
+ /* corresponding to the oldest frame is removed. The sum of */
+ /* the distances between the latest isf and other isfs, */
+ /* i.e. the element sumD[0], will be computed during this call. */
+ /* Hence this element is initialized to zero. */
+
+ for (i = DTX_HIST_SIZE_MIN_ONE; i > 0; i--)
+ {
+ st->sumD[i] = st->sumD[i - 1];
+ }
+ st->sumD[0] = 0;
+
+ /* Remove the oldest frame from the distance matrix. */
+ /* Note that the distance matrix is replaced by a one- */
+ /* dimensional array to save static memory. */
+
+ tmp = 0;
+ for (i = 27; i >= 12; i = (Word16) (i - tmp))
+ {
+ tmp = add(tmp, 1);
+ for (j = tmp; j > 0; j--)
+ {
+ st->D[i - j + 1] = st->D[i - j - tmp];
+ }
+ }
+
+ /* Compute the first column of the distance matrix D */
+ /* (squared Euclidean distances from isf1[] to isf_old_tx[][]). */
+
+ ptr = st->hist_ptr;
+ for (i = 1; i < DTX_HIST_SIZE; i++)
+ {
+ /* Compute the distance between the latest isf and the other isfs. */
+ ptr = sub(ptr, 1);
+ if (ptr < 0)
+ {
+ ptr = DTX_HIST_SIZE_MIN_ONE;
+ }
+ L_tmp = 0;
+ for (j = 0; j < M; j++)
+ {
+ tmp = sub(isf_old_tx[st->hist_ptr * M + j], isf_old_tx[ptr * M + j]);
+ L_tmp = L_mac(L_tmp, tmp, tmp);
+ }
+ st->D[i - 1] = L_tmp;
+
+ /* Update also the column sums. */
+ st->sumD[0] = L_add(st->sumD[0], st->D[i - 1]);
+ st->sumD[i] = L_add(st->sumD[i], st->D[i - 1]);
+ }
+
+ /* Find the minimum and maximum distances */
+ summax = st->sumD[0];
+ summin = st->sumD[0];
+ indices[0] = 0;
+ indices[2] = 0;
+ for (i = 1; i < DTX_HIST_SIZE; i++)
+ {
+ if (L_sub(st->sumD[i], summax) > 0)
+ {
+ indices[0] = i;
+ summax = st->sumD[i];
+ }
+ if (L_sub(st->sumD[i], summin) < 0)
+ {
+ indices[2] = i;
+ summin = st->sumD[i];
+ }
+ }
+
+ /* Find the second largest distance */
+ summax2nd = -2147483647L;
+ indices[1] = -1;
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ if ((L_sub(st->sumD[i], summax2nd) > 0) && (sub(i, indices[0]) != 0))
+ {
+ indices[1] = i;
+ summax2nd = st->sumD[i];
+ }
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ indices[i] = sub(st->hist_ptr, indices[i]);
+ if (indices[i] < 0)
+ {
+ indices[i] = add(indices[i], DTX_HIST_SIZE);
+ }
+ }
+
+ /* If maximum distance/MED_THRESH is smaller than minimum distance */
+ /* then the median ISF vector replacement is not performed */
+ tmp = norm_l(summax);
+ summax = (summax << tmp);
+ summin = (summin << tmp);
+ L_tmp = L_mult(voround(summax), INV_MED_THRESH);
+ if(L_tmp <= summin)
+ {
+ indices[0] = -1;
+ }
+ /* If second largest distance/MED_THRESH is smaller than */
+ /* minimum distance then the median ISF vector replacement is */
+ /* not performed */
+ summax2nd = L_shl(summax2nd, tmp);
+ L_tmp = L_mult(voround(summax2nd), INV_MED_THRESH);
+ if(L_tmp <= summin)
+ {
+ indices[1] = -1;
+ }
+ return;
+}
+
+static Word16 dithering_control(
+ dtx_encState * st
+ )
+{
+ Word16 tmp, mean, CN_dith, gain_diff;
+ Word32 i, ISF_diff;
+
+ /* determine how stationary the spectrum of background noise is */
+ ISF_diff = 0;
+ for (i = 0; i < 8; i++)
+ {
+ ISF_diff = L_add(ISF_diff, st->sumD[i]);
+ }
+ if ((ISF_diff >> 26) > 0)
+ {
+ CN_dith = 1;
+ } else
+ {
+ CN_dith = 0;
+ }
+
+ /* determine how stationary the energy of background noise is */
+ mean = 0;
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ mean = add(mean, st->log_en_hist[i]);
+ }
+ mean = (mean >> 3);
+ gain_diff = 0;
+ for (i = 0; i < DTX_HIST_SIZE; i++)
+ {
+ tmp = abs_s(sub(st->log_en_hist[i], mean));
+ gain_diff = add(gain_diff, tmp);
+ }
+ if (gain_diff > GAIN_THR)
+ {
+ CN_dith = 1;
+ }
+ return CN_dith;
+}
diff --git a/media/codecs/amrwb/enc/src/g_pitch.c b/media/codecs/amrwb/enc/src/g_pitch.c
new file mode 100644
index 0000000..98ee87e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/g_pitch.c
@@ -0,0 +1,79 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: g_pitch.c *
+* *
+* Description:Compute the gain of pitch. Result in Q12 *
+* if(gain < 0) gain = 0 *
+* if(gain > 1.2) gain = 1.2 *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+
+Word16 G_pitch( /* (o) Q14 : Gain of pitch lag saturated to 1.2 */
+ Word16 xn[], /* (i) : Pitch target. */
+ Word16 y1[], /* (i) : filtered adaptive codebook. */
+ Word16 g_coeff[], /* : Correlations need for gain quantization. */
+ Word16 L_subfr /* : Length of subframe. */
+ )
+{
+ Word32 i;
+ Word16 xy, yy, exp_xy, exp_yy, gain;
+ /* Compute scalar product <y1[],y1[]> */
+#ifdef ASM_OPT /* asm optimization branch */
+ /* Compute scalar product <xn[],y1[]> */
+ xy = extract_h(Dot_product12_asm(xn, y1, L_subfr, &exp_xy));
+ yy = extract_h(Dot_product12_asm(y1, y1, L_subfr, &exp_yy));
+
+#else
+ /* Compute scalar product <xn[],y1[]> */
+ xy = extract_h(Dot_product12(xn, y1, L_subfr, &exp_xy));
+ yy = extract_h(Dot_product12(y1, y1, L_subfr, &exp_yy));
+
+#endif
+
+ g_coeff[0] = yy;
+ g_coeff[1] = exp_yy;
+ g_coeff[2] = xy;
+ g_coeff[3] = exp_xy;
+
+ /* If (xy < 0) gain = 0 */
+ if (xy < 0)
+ return ((Word16) 0);
+
+ /* compute gain = xy/yy */
+
+ xy >>= 1; /* Be sure xy < yy */
+ gain = div_s(xy, yy);
+
+ i = exp_xy;
+ i -= exp_yy;
+
+ gain = shl(gain, i);
+
+ /* if (gain > 1.2) gain = 1.2 in Q14 */
+ if(gain > 19661)
+ {
+ gain = 19661;
+ }
+ return (gain);
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/gpclip.c b/media/codecs/amrwb/enc/src/gpclip.c
new file mode 100644
index 0000000..4ce3daa
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/gpclip.c
@@ -0,0 +1,110 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/**************************************************************************
+* File: gpclip.c *
+* *
+* Description:To avoid unstable synthesis on frame erasure, the gain *
+* need to be limited(gain pitch < 1.0) when the following *
+* case occurs *
+* a resonance on LPC filter(lp_disp < 60Hz) *
+* a good pitch prediction (lp_gp > 0.95) *
+* *
+***************************************************************************/
+#include "typedef.h"
+#include "basic_op.h"
+
+#define DIST_ISF_MAX 307 /* 120 Hz (6400Hz=16384) */
+#define DIST_ISF_THRES 154 /* 60 (6400Hz=16384) */
+#define GAIN_PIT_THRES 14746 /* 0.9 in Q14 */
+#define GAIN_PIT_MIN 9830 /* 0.6 in Q14 */
+#define M 16
+
+
+void Init_gp_clip(
+ Word16 mem[] /* (o) : memory of gain of pitch clipping algorithm */
+ )
+{
+ mem[0] = DIST_ISF_MAX;
+ mem[1] = GAIN_PIT_MIN;
+}
+
+
+Word16 Gp_clip(
+ Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */
+ )
+{
+ Word16 clip = 0;
+ if ((mem[0] < DIST_ISF_THRES) && (mem[1] > GAIN_PIT_THRES))
+ clip = 1;
+
+ return (clip);
+}
+
+
+void Gp_clip_test_isf(
+ Word16 isf[], /* (i) : isf values (in frequency domain) */
+ Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */
+ )
+{
+ Word16 dist, dist_min;
+ Word32 i;
+
+ dist_min = vo_sub(isf[1], isf[0]);
+
+ for (i = 2; i < M - 1; i++)
+ {
+ dist = vo_sub(isf[i], isf[i - 1]);
+ if(dist < dist_min)
+ {
+ dist_min = dist;
+ }
+ }
+
+ dist = extract_h(L_mac(vo_L_mult(26214, mem[0]), 6554, dist_min));
+
+ if (dist > DIST_ISF_MAX)
+ {
+ dist = DIST_ISF_MAX;
+ }
+ mem[0] = dist;
+
+ return;
+}
+
+
+void Gp_clip_test_gain_pit(
+ Word16 gain_pit, /* (i) Q14 : gain of quantized pitch */
+ Word16 mem[] /* (i/o) : memory of gain of pitch clipping algorithm */
+ )
+{
+ Word16 gain;
+ Word32 L_tmp;
+ L_tmp = (29491 * mem[1])<<1;
+ L_tmp += (3277 * gain_pit)<<1;
+
+ gain = extract_h(L_tmp);
+
+ if(gain < GAIN_PIT_MIN)
+ {
+ gain = GAIN_PIT_MIN;
+ }
+ mem[1] = gain;
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/homing.c b/media/codecs/amrwb/enc/src/homing.c
new file mode 100644
index 0000000..a96e7db
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/homing.c
@@ -0,0 +1,46 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: homing.c *
+* *
+* Description:Performs the homing routines *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "cnst.h"
+#include "basic_op.h"
+#include "bits.h"
+#include "homing.tab"
+
+Word16 encoder_homing_frame_test(Word16 input_frame[])
+{
+ Word32 i;
+ Word16 j = 0;
+
+ /* check 320 input samples for matching EHF_MASK: defined in e_homing.h */
+ for (i = 0; i < L_FRAME16k; i++)
+ {
+ j = (Word16) (input_frame[i] ^ EHF_MASK);
+
+ if (j)
+ break;
+ }
+
+ return (Word16) (!j);
+}
+
diff --git a/media/codecs/amrwb/enc/src/hp400.c b/media/codecs/amrwb/enc/src/hp400.c
new file mode 100644
index 0000000..c658a92
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/hp400.c
@@ -0,0 +1,106 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: hp400.c *
+* *
+* Description: *
+* 2nd order high pass filter with cut off frequency at 400 Hz. *
+* Designed with cheby2 function in MATLAB. *
+* Optimized for fixed-point to get the following frequency response: *
+* *
+* frequency: 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz *
+* dB loss: -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB *
+* *
+* Algorithm: *
+* *
+* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] *
+* + a[1]*y[i-1] + a[2]*y[i-2]; *
+* *
+* Word16 b[3] = {3660, -7320, 3660}; in Q12 *
+* Word16 a[3] = {4096, 7320, -3540}; in Q12 *
+* *
+* float --> b[3] = {0.893554687, -1.787109375, 0.893554687}; *
+* a[3] = {1.000000000, 1.787109375, -0.864257812}; *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "acelp.h"
+
+/* filter coefficients */
+static Word16 b[3] = {915, -1830, 915}; /* Q12 (/4) */
+static Word16 a[3] = {16384, 29280, -14160}; /* Q12 (x4) */
+/* Initialization of static values */
+
+void Init_HP400_12k8(Word16 mem[])
+{
+ Set_zero(mem, 6);
+}
+
+
+void HP400_12k8(
+ Word16 signal[], /* input signal / output is divided by 16 */
+ Word16 lg, /* lenght of signal */
+ Word16 mem[] /* filter memory [6] */
+ )
+{
+ Word16 x2;
+ Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1;
+ Word32 L_tmp;
+ Word32 num;
+ y2_hi = *mem++;
+ y2_lo = *mem++;
+ y1_hi = *mem++;
+ y1_lo = *mem++;
+ x0 = *mem++;
+ x1 = *mem;
+ num = (Word32)lg;
+ do
+ {
+ x2 = x1;
+ x1 = x0;
+ x0 = *signal;
+ /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2] */
+ /* + a[1]*y[i-1] + a[2] * y[i-2]; */
+ L_tmp = 8192L; /* rounding to maximise precision */
+ L_tmp += y1_lo * a[1];
+ L_tmp += y2_lo * a[2];
+ L_tmp = L_tmp >> 14;
+ L_tmp += (y1_hi * a[1] + y2_hi * a[2] + (x0 + x2)* b[0] + x1 * b[1]) << 1;
+ L_tmp <<= 1; /* coeff Q12 --> Q13 */
+ y2_hi = y1_hi;
+ y2_lo = y1_lo;
+ y1_hi = (Word16)(L_tmp>>16);
+ y1_lo = (Word16)((L_tmp & 0xffff)>>1);
+
+ /* signal is divided by 16 to avoid overflow in energy computation */
+ *signal++ = (L_tmp + 0x8000) >> 16;
+ }while(--num !=0);
+
+ *mem-- = x1;
+ *mem-- = x0;
+ *mem-- = y1_lo;
+ *mem-- = y1_hi;
+ *mem-- = y2_lo;
+ *mem = y2_hi;
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/hp50.c b/media/codecs/amrwb/enc/src/hp50.c
new file mode 100644
index 0000000..807d672
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/hp50.c
@@ -0,0 +1,106 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: hp50.c *
+* *
+* Description: *
+* 2nd order high pass filter with cut off frequency at 31 Hz. *
+* Designed with cheby2 function in MATLAB. *
+* Optimized for fixed-point to get the following frequency response: *
+* *
+* frequency: 0Hz 14Hz 24Hz 31Hz 37Hz 41Hz 47Hz *
+* dB loss: -infdB -15dB -6dB -3dB -1.5dB -1dB -0.5dB *
+* *
+* Algorithm: *
+* *
+* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] *
+* + a[1]*y[i-1] + a[2]*y[i-2]; *
+* *
+* Word16 b[3] = {4053, -8106, 4053}; in Q12 *
+* Word16 a[3] = {8192, 16211, -8021}; in Q12 *
+* *
+* float --> b[3] = {0.989501953, -1.979003906, 0.989501953}; *
+* a[3] = {1.000000000, 1.978881836, -0.979125977}; *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "cnst.h"
+#include "acelp.h"
+
+/* filter coefficients */
+static Word16 b[3] = {4053, -8106, 4053}; /* Q12 */
+static Word16 a[3] = {8192, 16211, -8021}; /* Q12 (x2) */
+
+/* Initialization of static values */
+
+void Init_HP50_12k8(Word16 mem[])
+{
+ Set_zero(mem, 6);
+}
+
+
+void HP50_12k8(
+ Word16 signal[], /* input/output signal */
+ Word16 lg, /* lenght of signal */
+ Word16 mem[] /* filter memory [6] */
+ )
+{
+ Word16 x2;
+ Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1;
+ Word32 L_tmp;
+ Word32 num;
+
+ y2_hi = *mem++;
+ y2_lo = *mem++;
+ y1_hi = *mem++;
+ y1_lo = *mem++;
+ x0 = *mem++;
+ x1 = *mem;
+ num = (Word32)lg;
+ do
+ {
+ x2 = x1;
+ x1 = x0;
+ x0 = *signal;
+ /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2] */
+ /* + a[1]*y[i-1] + a[2] * y[i-2]; */
+ L_tmp = 8192 ; /* rounding to maximise precision */
+ L_tmp += y1_lo * a[1];
+ L_tmp += y2_lo * a[2];
+ L_tmp = L_tmp >> 14;
+ L_tmp += (y1_hi * a[1] + y2_hi * a[2] + (x0 + x2) * b[0] + x1 * b[1]) << 1;
+ L_tmp <<= 2; /* coeff Q12 --> Q13 */
+ y2_hi = y1_hi;
+ y2_lo = y1_lo;
+ y1_hi = (Word16)(L_tmp>>16);
+ y1_lo = (Word16)((L_tmp & 0xffff)>>1);
+ *signal++ = extract_h((L_add((L_tmp<<1), 0x8000)));
+ }while(--num !=0);
+
+ *mem-- = x1;
+ *mem-- = x0;
+ *mem-- = y1_lo;
+ *mem-- = y1_hi;
+ *mem-- = y2_lo;
+ *mem-- = y2_hi;
+
+ return;
+}
+
+
diff --git a/media/codecs/amrwb/enc/src/hp6k.c b/media/codecs/amrwb/enc/src/hp6k.c
new file mode 100644
index 0000000..0baf612
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/hp6k.c
@@ -0,0 +1,93 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: hp6k.c *
+* *
+* Description:15th order band pass 6kHz to 7kHz FIR filter *
+* frequency: 4kHz 5kHz 5.5kHz 6kHz 6.5kHz 7kHz 7.5kHz 8kHz *
+* dB loss: -60dB -45dB -13dB -3dB 0dB -3dB -13dB -45dB *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "acelp.h"
+#include "cnst.h"
+
+#define L_FIR 31
+
+/* filter coefficients (gain=4.0) */
+
+Word16 fir_6k_7k[L_FIR] =
+{
+ -32, 47, 32, -27, -369,
+ 1122, -1421, 0, 3798, -8880,
+ 12349, -10984, 3548, 7766, -18001,
+ 22118, -18001, 7766, 3548, -10984,
+ 12349, -8880, 3798, 0, -1421,
+ 1122, -369, -27, 32, 47,
+ -32
+};
+
+
+void Init_Filt_6k_7k(Word16 mem[]) /* mem[30] */
+{
+ Set_zero(mem, L_FIR - 1);
+ return;
+}
+
+void Filt_6k_7k(
+ Word16 signal[], /* input: signal */
+ Word16 lg, /* input: length of input */
+ Word16 mem[] /* in/out: memory (size=30) */
+ )
+{
+ Word16 x[L_SUBFR16k + (L_FIR - 1)];
+ Word32 i, L_tmp;
+
+ Copy(mem, x, L_FIR - 1);
+ for (i = lg - 1; i >= 0; i--)
+ {
+ x[i + L_FIR - 1] = signal[i] >> 2; /* gain of filter = 4 */
+ }
+ for (i = 0; i < lg; i++)
+ {
+ L_tmp = (x[i] + x[i+ 30]) * fir_6k_7k[0];
+ L_tmp += (x[i+1] + x[i + 29]) * fir_6k_7k[1];
+ L_tmp += (x[i+2] + x[i + 28]) * fir_6k_7k[2];
+ L_tmp += (x[i+3] + x[i + 27]) * fir_6k_7k[3];
+ L_tmp += (x[i+4] + x[i + 26]) * fir_6k_7k[4];
+ L_tmp += (x[i+5] + x[i + 25]) * fir_6k_7k[5];
+ L_tmp += (x[i+6] + x[i + 24]) * fir_6k_7k[6];
+ L_tmp += (x[i+7] + x[i + 23]) * fir_6k_7k[7];
+ L_tmp += (x[i+8] + x[i + 22]) * fir_6k_7k[8];
+ L_tmp += (x[i+9] + x[i + 21]) * fir_6k_7k[9];
+ L_tmp += (x[i+10] + x[i + 20]) * fir_6k_7k[10];
+ L_tmp += (x[i+11] + x[i + 19]) * fir_6k_7k[11];
+ L_tmp += (x[i+12] + x[i + 18]) * fir_6k_7k[12];
+ L_tmp += (x[i+13] + x[i + 17]) * fir_6k_7k[13];
+ L_tmp += (x[i+14] + x[i + 16]) * fir_6k_7k[14];
+ L_tmp += (x[i+15]) * fir_6k_7k[15];
+ signal[i] = (L_tmp + 0x4000) >> 15;
+ }
+
+ Copy(x + lg, mem, L_FIR - 1);
+
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/hp_wsp.c b/media/codecs/amrwb/enc/src/hp_wsp.c
new file mode 100644
index 0000000..f0347cb
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/hp_wsp.c
@@ -0,0 +1,148 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: hp_wsp.c *
+* Description: *
+* 3nd order high pass filter with cut off frequency at 180Hz *
+* Algorithm: *
+* *
+* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] + b[3]*x[i-3] *
+* + a[1]*y[i-1] + a[2]*y[i-2] + a[3]*y[i-3]; *
+* *
+* float a_coef[HP_ORDER]= { *
+* -2.64436711600664f, *
+* 2.35087386625360f, *
+* -0.70001156927424f}; *
+* *
+* float b_coef[HP_ORDER+1]= { *
+* -0.83787057505665f, *
+* 2.50975570071058f, *
+* -2.50975570071058f, *
+* 0.83787057505665f}; *
+* *
+*************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "acelp.h"
+
+/* filter coefficients in Q12 */
+static Word16 a[4] = {8192, 21663, -19258, 5734};
+static Word16 b[4] = {-3432, +10280, -10280, +3432};
+
+/* Initialization of static values */
+void Init_Hp_wsp(Word16 mem[])
+{
+ Set_zero(mem, 9);
+
+ return;
+}
+
+void scale_mem_Hp_wsp(Word16 mem[], Word16 exp)
+{
+ Word32 i;
+ Word32 L_tmp;
+
+ for (i = 0; i < 6; i += 2)
+ {
+ L_tmp = ((mem[i] << 16) + (mem[i + 1]<<1));
+ L_tmp = L_shl(L_tmp, exp);
+ mem[i] = L_tmp >> 16;
+ mem[i + 1] = (L_tmp & 0xffff)>>1;
+ }
+
+ for (i = 6; i < 9; i++)
+ {
+ L_tmp = L_deposit_h(mem[i]); /* x[i] */
+ L_tmp = L_shl(L_tmp, exp);
+ mem[i] = vo_round(L_tmp);
+ }
+
+ return;
+}
+
+
+void Hp_wsp(
+ Word16 wsp[], /* i : wsp[] signal */
+ Word16 hp_wsp[], /* o : hypass wsp[] */
+ Word16 lg, /* i : lenght of signal */
+ Word16 mem[] /* i/o : filter memory [9] */
+ )
+{
+ Word16 x0, x1, x2, x3;
+ Word16 y3_hi, y3_lo, y2_hi, y2_lo, y1_hi, y1_lo;
+ Word32 i, L_tmp;
+
+ y3_hi = mem[0];
+ y3_lo = mem[1];
+ y2_hi = mem[2];
+ y2_lo = mem[3];
+ y1_hi = mem[4];
+ y1_lo = mem[5];
+ x0 = mem[6];
+ x1 = mem[7];
+ x2 = mem[8];
+
+ for (i = 0; i < lg; i++)
+ {
+ x3 = x2;
+ x2 = x1;
+ x1 = x0;
+ x0 = wsp[i];
+ /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2] + b[3]*x[i-3] */
+ /* + a[1]*y[i-1] + a[2] * y[i-2] + a[3]*y[i-3] */
+
+ L_tmp = 16384L; /* rounding to maximise precision */
+ L_tmp += (y1_lo * a[1])<<1;
+ L_tmp += (y2_lo * a[2])<<1;
+ L_tmp += (y3_lo * a[3])<<1;
+ L_tmp = L_tmp >> 15;
+ L_tmp += (y1_hi * a[1])<<1;
+ L_tmp += (y2_hi * a[2])<<1;
+ L_tmp += (y3_hi * a[3])<<1;
+ L_tmp += (x0 * b[0])<<1;
+ L_tmp += (x1 * b[1])<<1;
+ L_tmp += (x2 * b[2])<<1;
+ L_tmp += (x3 * b[3])<<1;
+
+ L_tmp = L_tmp << 2;
+
+ y3_hi = y2_hi;
+ y3_lo = y2_lo;
+ y2_hi = y1_hi;
+ y2_lo = y1_lo;
+ y1_hi = L_tmp >> 16;
+ y1_lo = (L_tmp & 0xffff) >>1;
+
+ hp_wsp[i] = (L_tmp + 0x4000)>>15;
+ }
+
+ mem[0] = y3_hi;
+ mem[1] = y3_lo;
+ mem[2] = y2_hi;
+ mem[3] = y2_lo;
+ mem[4] = y1_hi;
+ mem[5] = y1_lo;
+ mem[6] = x0;
+ mem[7] = x1;
+ mem[8] = x2;
+
+ return;
+}
+
+
diff --git a/media/codecs/amrwb/enc/src/int_lpc.c b/media/codecs/amrwb/enc/src/int_lpc.c
new file mode 100644
index 0000000..3d8b8cb
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/int_lpc.c
@@ -0,0 +1,66 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: int_lpc.c *
+* *
+* Description:Interpolation of the LP parameters in 4 subframes. *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "acelp.h"
+
+#define MP1 (M+1)
+
+
+void Int_isp(
+ Word16 isp_old[], /* input : isps from past frame */
+ Word16 isp_new[], /* input : isps from present frame */
+ Word16 frac[], /* input : fraction for 3 first subfr (Q15) */
+ Word16 Az[] /* output: LP coefficients in 4 subframes */
+ )
+{
+ Word32 i, k;
+ Word16 fac_old, fac_new;
+ Word16 isp[M];
+ Word32 L_tmp;
+
+ for (k = 0; k < 3; k++)
+ {
+ fac_new = frac[k];
+ fac_old = (32767 - fac_new) + 1; /* 1.0 - fac_new */
+
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = (isp_old[i] * fac_old)<<1;
+ L_tmp += (isp_new[i] * fac_new)<<1;
+ isp[i] = (L_tmp + 0x8000)>>16;
+ }
+ Isp_Az(isp, Az, M, 0);
+ Az += MP1;
+ }
+
+ /* 4th subframe: isp_new (frac=1.0) */
+ Isp_Az(isp_new, Az, M, 0);
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/isp_az.c b/media/codecs/amrwb/enc/src/isp_az.c
new file mode 100644
index 0000000..62e29e7
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/isp_az.c
@@ -0,0 +1,247 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: isp_az.c *
+* *
+* Description:Compute the LPC coefficients from isp (order=M) *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "cnst.h"
+
+#define NC (M/2)
+#define NC16k (M16k/2)
+
+/* local function */
+
+static void Get_isp_pol(Word16 * isp, Word32 * f, Word16 n);
+static void Get_isp_pol_16kHz(Word16 * isp, Word32 * f, Word16 n);
+
+void Isp_Az(
+ Word16 isp[], /* (i) Q15 : Immittance spectral pairs */
+ Word16 a[], /* (o) Q12 : predictor coefficients (order = M) */
+ Word16 m,
+ Word16 adaptive_scaling /* (i) 0 : adaptive scaling disabled */
+ /* 1 : adaptive scaling enabled */
+ )
+{
+ Word32 i, j;
+ Word16 hi, lo;
+ Word32 f1[NC16k + 1], f2[NC16k];
+ Word16 nc;
+ Word32 t0;
+ Word16 q, q_sug;
+ Word32 tmax;
+
+ nc = (m >> 1);
+ if(nc > 8)
+ {
+ Get_isp_pol_16kHz(&isp[0], f1, nc);
+ for (i = 0; i <= nc; i++)
+ {
+ f1[i] = f1[i] << 2;
+ }
+ } else
+ Get_isp_pol(&isp[0], f1, nc);
+
+ if (nc > 8)
+ {
+ Get_isp_pol_16kHz(&isp[1], f2, (nc - 1));
+ for (i = 0; i <= nc - 1; i++)
+ {
+ f2[i] = f2[i] << 2;
+ }
+ } else
+ Get_isp_pol(&isp[1], f2, (nc - 1));
+
+ /*-----------------------------------------------------*
+ * Multiply F2(z) by (1 - z^-2) *
+ *-----------------------------------------------------*/
+
+ for (i = (nc - 1); i > 1; i--)
+ {
+ f2[i] = vo_L_sub(f2[i], f2[i - 2]); /* f2[i] -= f2[i-2]; */
+ }
+
+ /*----------------------------------------------------------*
+ * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1]) *
+ *----------------------------------------------------------*/
+
+ for (i = 0; i < nc; i++)
+ {
+ /* f1[i] *= (1.0 + isp[M-1]); */
+
+ hi = f1[i] >> 16;
+ lo = (f1[i] & 0xffff)>>1;
+
+ t0 = Mpy_32_16(hi, lo, isp[m - 1]);
+ f1[i] = vo_L_add(f1[i], t0);
+
+ /* f2[i] *= (1.0 - isp[M-1]); */
+
+ hi = f2[i] >> 16;
+ lo = (f2[i] & 0xffff)>>1;
+ t0 = Mpy_32_16(hi, lo, isp[m - 1]);
+ f2[i] = vo_L_sub(f2[i], t0);
+ }
+
+ /*-----------------------------------------------------*
+ * A(z) = (F1(z)+F2(z))/2 *
+ * F1(z) is symmetric and F2(z) is antisymmetric *
+ *-----------------------------------------------------*/
+
+ /* a[0] = 1.0; */
+ a[0] = 4096;
+ tmax = 1;
+ for (i = 1, j = m - 1; i < nc; i++, j--)
+ {
+ /* a[i] = 0.5*(f1[i] + f2[i]); */
+
+ t0 = vo_L_add(f1[i], f2[i]); /* f1[i] + f2[i] */
+ tmax |= L_abs(t0);
+ a[i] = (Word16)(vo_L_shr_r(t0, 12)); /* from Q23 to Q12 and * 0.5 */
+
+ /* a[j] = 0.5*(f1[i] - f2[i]); */
+
+ t0 = vo_L_sub(f1[i], f2[i]); /* f1[i] - f2[i] */
+ tmax |= L_abs(t0);
+ a[j] = (Word16)(vo_L_shr_r(t0, 12)); /* from Q23 to Q12 and * 0.5 */
+ }
+
+ /* rescale data if overflow has occured and reprocess the loop */
+ if(adaptive_scaling == 1)
+ q = 4 - norm_l(tmax); /* adaptive scaling enabled */
+ else
+ q = 0; /* adaptive scaling disabled */
+
+ if (q > 0)
+ {
+ q_sug = (12 + q);
+ for (i = 1, j = m - 1; i < nc; i++, j--)
+ {
+ /* a[i] = 0.5*(f1[i] + f2[i]); */
+ t0 = vo_L_add(f1[i], f2[i]); /* f1[i] + f2[i] */
+ a[i] = (Word16)(vo_L_shr_r(t0, q_sug)); /* from Q23 to Q12 and * 0.5 */
+
+ /* a[j] = 0.5*(f1[i] - f2[i]); */
+ t0 = vo_L_sub(f1[i], f2[i]); /* f1[i] - f2[i] */
+ a[j] = (Word16)(vo_L_shr_r(t0, q_sug)); /* from Q23 to Q12 and * 0.5 */
+ }
+ a[0] = shr(a[0], q);
+ }
+ else
+ {
+ q_sug = 12;
+ q = 0;
+ }
+ /* a[NC] = 0.5*f1[NC]*(1.0 + isp[M-1]); */
+ hi = f1[nc] >> 16;
+ lo = (f1[nc] & 0xffff)>>1;
+ t0 = Mpy_32_16(hi, lo, isp[m - 1]);
+ t0 = vo_L_add(f1[nc], t0);
+ a[nc] = (Word16)(L_shr_r(t0, q_sug)); /* from Q23 to Q12 and * 0.5 */
+ /* a[m] = isp[m-1]; */
+
+ a[m] = vo_shr_r(isp[m - 1], (3 + q)); /* from Q15 to Q12 */
+ return;
+}
+
+/*-----------------------------------------------------------*
+* procedure Get_isp_pol: *
+* ~~~~~~~~~~~ *
+* Find the polynomial F1(z) or F2(z) from the ISPs. *
+* This is performed by expanding the product polynomials: *
+* *
+* F1(z) = product ( 1 - 2 isp_i z^-1 + z^-2 ) *
+* i=0,2,4,6,8 *
+* F2(z) = product ( 1 - 2 isp_i z^-1 + z^-2 ) *
+* i=1,3,5,7 *
+* *
+* where isp_i are the ISPs in the cosine domain. *
+*-----------------------------------------------------------*
+* *
+* Parameters: *
+* isp[] : isp vector (cosine domaine) in Q15 *
+* f[] : the coefficients of F1 or F2 in Q23 *
+* n : == NC for F1(z); == NC-1 for F2(z) *
+*-----------------------------------------------------------*/
+
+static void Get_isp_pol(Word16 * isp, Word32 * f, Word16 n)
+{
+ Word16 hi, lo;
+ Word32 i, j, t0;
+ /* All computation in Q23 */
+
+ f[0] = vo_L_mult(4096, 1024); /* f[0] = 1.0; in Q23 */
+ f[1] = vo_L_mult(isp[0], -256); /* f[1] = -2.0*isp[0] in Q23 */
+
+ f += 2; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+ for (i = 2; i <= n; i++)
+ {
+ *f = f[-2];
+ for (j = 1; j < i; j++, f--)
+ {
+ hi = f[-1]>>16;
+ lo = (f[-1] & 0xffff)>>1;
+
+ t0 = Mpy_32_16(hi, lo, *isp); /* t0 = f[-1] * isp */
+ t0 = t0 << 1;
+ *f = vo_L_sub(*f, t0); /* *f -= t0 */
+ *f = vo_L_add(*f, f[-2]); /* *f += f[-2] */
+ }
+ *f -= (*isp << 9); /* *f -= isp<<8 */
+ f += i; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+ }
+ return;
+}
+
+static void Get_isp_pol_16kHz(Word16 * isp, Word32 * f, Word16 n)
+{
+ Word16 hi, lo;
+ Word32 i, j, t0;
+
+ /* All computation in Q23 */
+ f[0] = L_mult(4096, 256); /* f[0] = 1.0; in Q23 */
+ f[1] = L_mult(isp[0], -64); /* f[1] = -2.0*isp[0] in Q23 */
+
+ f += 2; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+
+ for (i = 2; i <= n; i++)
+ {
+ *f = f[-2];
+ for (j = 1; j < i; j++, f--)
+ {
+ VO_L_Extract(f[-1], &hi, &lo);
+ t0 = Mpy_32_16(hi, lo, *isp); /* t0 = f[-1] * isp */
+ t0 = L_shl2(t0, 1);
+ *f = L_sub(*f, t0); /* *f -= t0 */
+ *f = L_add(*f, f[-2]); /* *f += f[-2] */
+ }
+ *f = L_msu(*f, *isp, 64); /* *f -= isp<<8 */
+ f += i; /* Advance f pointer */
+ isp += 2; /* Advance isp pointer */
+ }
+ return;
+}
+
+
diff --git a/media/codecs/amrwb/enc/src/isp_isf.c b/media/codecs/amrwb/enc/src/isp_isf.c
new file mode 100644
index 0000000..56798e0
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/isp_isf.c
@@ -0,0 +1,91 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: isp_isf.c *
+* *
+* Description: *
+* Isp_isf Transformation isp to isf *
+* Isf_isp Transformation isf to isp *
+* *
+* The transformation from isp[i] to isf[i] and isf[i] to isp[i] *
+* are approximated by a look-up table and interpolation *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "isp_isf.tab" /* Look-up table for transformations */
+
+void Isp_isf(
+ Word16 isp[], /* (i) Q15 : isp[m] (range: -1<=val<1) */
+ Word16 isf[], /* (o) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 m /* (i) : LPC order */
+ )
+{
+ Word32 i, ind;
+ Word32 L_tmp;
+ ind = 127; /* beging at end of table -1 */
+ for (i = (m - 1); i >= 0; i--)
+ {
+ if (i >= (m - 2))
+ { /* m-2 is a constant */
+ ind = 127; /* beging at end of table -1 */
+ }
+ /* find value in table that is just greater than isp[i] */
+ while (table[ind] < isp[i])
+ ind--;
+ /* acos(isp[i])= ind*128 + ( ( isp[i]-table[ind] ) * slope[ind] )/2048 */
+ L_tmp = vo_L_mult(vo_sub(isp[i], table[ind]), slope[ind]);
+ isf[i] = vo_round((L_tmp << 4)); /* (isp[i]-table[ind])*slope[ind])>>11 */
+ isf[i] = add1(isf[i], (ind << 7));
+ }
+ isf[m - 1] = (isf[m - 1] >> 1);
+ return;
+}
+
+
+void Isf_isp(
+ Word16 isf[], /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
+ Word16 isp[], /* (o) Q15 : isp[m] (range: -1<=val<1) */
+ Word16 m /* (i) : LPC order */
+ )
+{
+ Word16 offset;
+ Word32 i, ind, L_tmp;
+
+ for (i = 0; i < m - 1; i++)
+ {
+ isp[i] = isf[i];
+ }
+ isp[m - 1] = (isf[m - 1] << 1);
+
+ for (i = 0; i < m; i++)
+ {
+ ind = (isp[i] >> 7); /* ind = b7-b15 of isf[i] */
+ offset = (Word16) (isp[i] & 0x007f); /* offset = b0-b6 of isf[i] */
+
+ /* isp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 128 */
+ L_tmp = vo_L_mult(vo_sub(table[ind + 1], table[ind]), offset);
+ isp[i] = add1(table[ind], (Word16)((L_tmp >> 8)));
+ }
+
+ return;
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/lag_wind.c b/media/codecs/amrwb/enc/src/lag_wind.c
new file mode 100644
index 0000000..527430b
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/lag_wind.c
@@ -0,0 +1,49 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: lag_wind.c *
+* *
+* Description: Lag_windows on autocorrelations *
+* r[i] *= lag_wind[i] *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "lag_wind.tab"
+
+
+void Lag_window(
+ Word16 r_h[], /* (i/o) : Autocorrelations (msb) */
+ Word16 r_l[] /* (i/o) : Autocorrelations (lsb) */
+ )
+{
+ Word32 i;
+ Word32 x;
+
+ for (i = 1; i <= M; i++)
+ {
+ x = Mpy_32(r_h[i], r_l[i], volag_h[i - 1], volag_l[i - 1]);
+ r_h[i] = x >> 16;
+ r_l[i] = (x & 0xffff)>>1;
+ }
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/levinson.c b/media/codecs/amrwb/enc/src/levinson.c
new file mode 100644
index 0000000..9d5a3bd
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/levinson.c
@@ -0,0 +1,250 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: levinson.c *
+* *
+* Description:LEVINSON-DURBIN algorithm in double precision *
+* *
+************************************************************************/
+/*---------------------------------------------------------------------------*
+ * LEVINSON.C *
+ *---------------------------------------------------------------------------*
+ * *
+ * LEVINSON-DURBIN algorithm in double precision *
+ * *
+ * *
+ * Algorithm *
+ * *
+ * R[i] autocorrelations. *
+ * A[i] filter coefficients. *
+ * K reflection coefficients. *
+ * Alpha prediction gain. *
+ * *
+ * Initialization: *
+ * A[0] = 1 *
+ * K = -R[1]/R[0] *
+ * A[1] = K *
+ * Alpha = R[0] * (1-K**2] *
+ * *
+ * Do for i = 2 to M *
+ * *
+ * S = SUM ( R[j]*A[i-j] ,j=1,i-1 ) + R[i] *
+ * *
+ * K = -S / Alpha *
+ * *
+ * An[j] = A[j] + K*A[i-j] for j=1 to i-1 *
+ * where An[i] = new A[i] *
+ * An[i]=K *
+ * *
+ * Alpha=Alpha * (1-K**2) *
+ * *
+ * END *
+ * *
+ * Remarks on the dynamics of the calculations. *
+ * *
+ * The numbers used are in double precision in the following format : *
+ * A = AH <<16 + AL<<1. AH and AL are 16 bit signed integers. *
+ * Since the LSB's also contain a sign bit, this format does not *
+ * correspond to standard 32 bit integers. We use this format since *
+ * it allows fast execution of multiplications and divisions. *
+ * *
+ * "DPF" will refer to this special format in the following text. *
+ * See oper_32b.c *
+ * *
+ * The R[i] were normalized in routine AUTO (hence, R[i] < 1.0). *
+ * The K[i] and Alpha are theoretically < 1.0. *
+ * The A[i], for a sampling frequency of 8 kHz, are in practice *
+ * always inferior to 16.0. *
+ * *
+ * These characteristics allow straigthforward fixed-point *
+ * implementation. We choose to represent the parameters as *
+ * follows : *
+ * *
+ * R[i] Q31 +- .99.. *
+ * K[i] Q31 +- .99.. *
+ * Alpha Normalized -> mantissa in Q31 plus exponent *
+ * A[i] Q27 +- 15.999.. *
+ * *
+ * The additions are performed in 32 bit. For the summation used *
+ * to calculate the K[i], we multiply numbers in Q31 by numbers *
+ * in Q27, with the result of the multiplications in Q27, *
+ * resulting in a dynamic of +- 16. This is sufficient to avoid *
+ * overflow, since the final result of the summation is *
+ * necessarily < 1.0 as both the K[i] and Alpha are *
+ * theoretically < 1.0. *
+ *___________________________________________________________________________*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "acelp.h"
+
+#define M 16
+#define NC (M/2)
+
+void Init_Levinson(
+ Word16 * mem /* output :static memory (18 words) */
+ )
+{
+ Set_zero(mem, 18); /* old_A[0..M-1] = 0, old_rc[0..1] = 0 */
+ return;
+}
+
+
+void Levinson(
+ Word16 Rh[], /* (i) : Rh[M+1] Vector of autocorrelations (msb) */
+ Word16 Rl[], /* (i) : Rl[M+1] Vector of autocorrelations (lsb) */
+ Word16 A[], /* (o) Q12 : A[M] LPC coefficients (m = 16) */
+ Word16 rc[], /* (o) Q15 : rc[M] Reflection coefficients. */
+ Word16 * mem /* (i/o) :static memory (18 words) */
+ )
+{
+ Word32 i, j;
+ Word16 hi, lo;
+ Word16 Kh, Kl; /* reflection coefficient; hi and lo */
+ Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */
+ Word16 Ah[M + 1], Al[M + 1]; /* LPC coef. in double prec. */
+ Word16 Anh[M + 1], Anl[M + 1]; /* LPC coef.for next iteration in double prec. */
+ Word32 t0, t1, t2; /* temporary variable */
+ Word16 *old_A, *old_rc;
+
+ /* Last A(z) for case of unstable filter */
+ old_A = mem;
+ old_rc = mem + M;
+
+ /* K = A[1] = -R[1] / R[0] */
+
+ t1 = ((Rh[1] << 16) + (Rl[1] << 1)); /* R[1] in Q31 */
+ t2 = L_abs(t1); /* abs R[1] */
+ t0 = Div_32(t2, Rh[0], Rl[0]); /* R[1]/R[0] in Q31 */
+ if (t1 > 0)
+ t0 = -t0; /* -R[1]/R[0] */
+
+ Kh = t0 >> 16;
+ Kl = (t0 & 0xffff)>>1;
+ rc[0] = Kh;
+ t0 = (t0 >> 4); /* A[1] in Q27 */
+
+ Ah[1] = t0 >> 16;
+ Al[1] = (t0 & 0xffff)>>1;
+
+ /* Alpha = R[0] * (1-K**2) */
+ t0 = Mpy_32(Kh, Kl, Kh, Kl); /* K*K in Q31 */
+ t0 = L_abs(t0); /* Some case <0 !! */
+ t0 = vo_L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */
+
+ hi = t0 >> 16;
+ lo = (t0 & 0xffff)>>1;
+
+ t0 = Mpy_32(Rh[0], Rl[0], hi, lo); /* Alpha in Q31 */
+
+ /* Normalize Alpha */
+ alp_exp = norm_l(t0);
+ t0 = (t0 << alp_exp);
+
+ alp_h = t0 >> 16;
+ alp_l = (t0 & 0xffff)>>1;
+ /*--------------------------------------*
+ * ITERATIONS I=2 to M *
+ *--------------------------------------*/
+ for (i = 2; i <= M; i++)
+ {
+ /* t0 = SUM ( R[j]*A[i-j] ,j=1,i-1 ) + R[i] */
+ t0 = 0;
+ for (j = 1; j < i; j++)
+ t0 = vo_L_add(t0, Mpy_32(Rh[j], Rl[j], Ah[i - j], Al[i - j]));
+
+ t0 = t0 << 4; /* result in Q27 -> convert to Q31 */
+ /* No overflow possible */
+ t1 = ((Rh[i] << 16) + (Rl[i] << 1));
+ t0 = vo_L_add(t0, t1); /* add R[i] in Q31 */
+
+ /* K = -t0 / Alpha */
+ t1 = L_abs(t0);
+ t2 = Div_32(t1, alp_h, alp_l); /* abs(t0)/Alpha */
+ if (t0 > 0)
+ t2 = -t2; /* K =-t0/Alpha */
+ t2 = (t2 << alp_exp); /* denormalize; compare to Alpha */
+
+ Kh = t2 >> 16;
+ Kl = (t2 & 0xffff)>>1;
+
+ rc[i - 1] = Kh;
+ /* Test for unstable filter. If unstable keep old A(z) */
+ if (abs_s(Kh) > 32750)
+ {
+ A[0] = 4096; /* Ai[0] not stored (always 1.0) */
+ for (j = 0; j < M; j++)
+ {
+ A[j + 1] = old_A[j];
+ }
+ rc[0] = old_rc[0]; /* only two rc coefficients are needed */
+ rc[1] = old_rc[1];
+ return;
+ }
+ /*------------------------------------------*
+ * Compute new LPC coeff. -> An[i] *
+ * An[j]= A[j] + K*A[i-j] , j=1 to i-1 *
+ * An[i]= K *
+ *------------------------------------------*/
+ for (j = 1; j < i; j++)
+ {
+ t0 = Mpy_32(Kh, Kl, Ah[i - j], Al[i - j]);
+ t0 = vo_L_add(t0, ((Ah[j] << 16) + (Al[j] << 1)));
+ Anh[j] = t0 >> 16;
+ Anl[j] = (t0 & 0xffff)>>1;
+ }
+ t2 = (t2 >> 4); /* t2 = K in Q31 ->convert to Q27 */
+
+ VO_L_Extract(t2, &Anh[i], &Anl[i]); /* An[i] in Q27 */
+
+ /* Alpha = Alpha * (1-K**2) */
+ t0 = Mpy_32(Kh, Kl, Kh, Kl); /* K*K in Q31 */
+ t0 = L_abs(t0); /* Some case <0 !! */
+ t0 = vo_L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */
+ hi = t0 >> 16;
+ lo = (t0 & 0xffff)>>1;
+ t0 = Mpy_32(alp_h, alp_l, hi, lo); /* Alpha in Q31 */
+
+ /* Normalize Alpha */
+ j = norm_l(t0);
+ t0 = (t0 << j);
+ alp_h = t0 >> 16;
+ alp_l = (t0 & 0xffff)>>1;
+ alp_exp += j; /* Add normalization to alp_exp */
+
+ /* A[j] = An[j] */
+ for (j = 1; j <= i; j++)
+ {
+ Ah[j] = Anh[j];
+ Al[j] = Anl[j];
+ }
+ }
+ /* Truncate A[i] in Q27 to Q12 with rounding */
+ A[0] = 4096;
+ for (i = 1; i <= M; i++)
+ {
+ t0 = (Ah[i] << 16) + (Al[i] << 1);
+ old_A[i - 1] = A[i] = vo_round((t0 << 1));
+ }
+ old_rc[0] = rc[0];
+ old_rc[1] = rc[1];
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/log2.c b/media/codecs/amrwb/enc/src/log2.c
new file mode 100644
index 0000000..f14058e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/log2.c
@@ -0,0 +1,111 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* *
+* File : log2.c *
+* Purpose : Computes log2(L_x) *
+* *
+************************************************************************/
+
+#include "log2.h"
+/********************************************************************************
+* INCLUDE FILES
+*********************************************************************************/
+#include "typedef.h"
+#include "basic_op.h"
+
+/*********************************************************************************
+* LOCAL VARIABLES AND TABLES
+**********************************************************************************/
+#include "log2_tab.h" /* Table for Log2() */
+
+/*************************************************************************
+*
+* FUNCTION: Log2_norm()
+*
+* PURPOSE: Computes log2(L_x, exp), where L_x is positive and
+* normalized, and exp is the normalisation exponent
+* If L_x is negative or zero, the result is 0.
+*
+* DESCRIPTION:
+* The function Log2(L_x) is approximated by a table and linear
+* interpolation. The following steps are used to compute Log2(L_x)
+*
+* 1- exponent = 30-norm_exponent
+* 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization).
+* 3- a = bit10-b24
+* 4- i -=32
+* 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+*
+*************************************************************************/
+
+void Log2_norm (
+ Word32 L_x, /* (i) : input value (normalized) */
+ Word16 exp, /* (i) : norm_l (L_x) */
+ Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ )
+{
+ Word16 i, a, tmp;
+ Word32 L_y;
+ if (L_x <= (Word32) 0)
+ {
+ *exponent = 0;
+ *fraction = 0;
+ return;
+ }
+ *exponent = (30 - exp);
+ L_x = (L_x >> 9);
+ i = extract_h (L_x); /* Extract b25-b31 */
+ L_x = (L_x >> 1);
+ a = (Word16)(L_x); /* Extract b10-b24 of fraction */
+ a = (Word16)(a & (Word16)0x7fff);
+ i -= 32;
+ L_y = L_deposit_h (table[i]); /* table[i] << 16 */
+ tmp = vo_sub(table[i], table[i + 1]); /* table[i] - table[i+1] */
+ L_y = vo_L_msu (L_y, tmp, a); /* L_y -= tmp*a*2 */
+ *fraction = extract_h (L_y);
+
+ return;
+}
+
+/*************************************************************************
+*
+* FUNCTION: Log2()
+*
+* PURPOSE: Computes log2(L_x), where L_x is positive.
+* If L_x is negative or zero, the result is 0.
+*
+* DESCRIPTION:
+* normalizes L_x and then calls Log2_norm().
+*
+*************************************************************************/
+
+void Log2 (
+ Word32 L_x, /* (i) : input value */
+ Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+ Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ )
+{
+ Word16 exp;
+
+ exp = norm_l(L_x);
+ Log2_norm ((L_x << exp), exp, exponent, fraction);
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/lp_dec2.c b/media/codecs/amrwb/enc/src/lp_dec2.c
new file mode 100644
index 0000000..9a9dd34
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/lp_dec2.c
@@ -0,0 +1,70 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: lp_dec2.c *
+* *
+* Description:Decimate a vector by 2 with 2nd order fir filter *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+
+#define L_FIR 5
+#define L_MEM (L_FIR-2)
+
+/* static float h_fir[L_FIR] = {0.13, 0.23, 0.28, 0.23, 0.13}; */
+/* fixed-point: sum of coef = 32767 to avoid overflow on DC */
+static Word16 h_fir[L_FIR] = {4260, 7536, 9175, 7536, 4260};
+
+void LP_Decim2(
+ Word16 x[], /* in/out: signal to process */
+ Word16 l, /* input : size of filtering */
+ Word16 mem[] /* in/out: memory (size=3) */
+ )
+{
+ Word16 *p_x, x_buf[L_FRAME + L_MEM];
+ Word32 i, j;
+ Word32 L_tmp;
+ /* copy initial filter states into buffer */
+ p_x = x_buf;
+ for (i = 0; i < L_MEM; i++)
+ {
+ *p_x++ = mem[i];
+ mem[i] = x[l - L_MEM + i];
+ }
+ for (i = 0; i < l; i++)
+ {
+ *p_x++ = x[i];
+ }
+ for (i = 0, j = 0; i < l; i += 2, j++)
+ {
+ p_x = &x_buf[i];
+ L_tmp = ((*p_x++) * h_fir[0]);
+ L_tmp += ((*p_x++) * h_fir[1]);
+ L_tmp += ((*p_x++) * h_fir[2]);
+ L_tmp += ((*p_x++) * h_fir[3]);
+ L_tmp += ((*p_x++) * h_fir[4]);
+ x[j] = (L_tmp + 0x4000)>>15;
+ }
+ return;
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/math_op.c b/media/codecs/amrwb/enc/src/math_op.c
new file mode 100644
index 0000000..9d7c74e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/math_op.c
@@ -0,0 +1,224 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/*___________________________________________________________________________
+| |
+| This file contains mathematic operations in fixed point. |
+| |
+| Isqrt() : inverse square root (16 bits precision). |
+| Pow2() : 2^x (16 bits precision). |
+| Log2() : log2 (16 bits precision). |
+| Dot_product() : scalar product of <x[],y[]> |
+| |
+| These operations are not standard double precision operations. |
+| They are used where low complexity is important and the full 32 bits |
+| precision is not necessary. For example, the function Div_32() has a |
+| 24 bits precision which is enough for our purposes. |
+| |
+| In this file, the values use theses representations: |
+| |
+| Word32 L_32 : standard signed 32 bits format |
+| Word16 hi, lo : L_32 = hi<<16 + lo<<1 (DPF - Double Precision Format) |
+| Word32 frac, Word16 exp : L_32 = frac << exp-31 (normalised format) |
+| Word16 int, frac : L_32 = int.frac (fractional format) |
+|___________________________________________________________________________|
+*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+
+/*___________________________________________________________________________
+| |
+| Function Name : Isqrt |
+| |
+| Compute 1/sqrt(L_x). |
+| if L_x is negative or zero, result is 1 (7fffffff). |
+|---------------------------------------------------------------------------|
+| Algorithm: |
+| |
+| 1- Normalization of L_x. |
+| 2- call Isqrt_n(L_x, exponant) |
+| 3- L_y = L_x << exponant |
+|___________________________________________________________________________|
+*/
+Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */
+ Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */
+ )
+{
+ Word16 exp;
+ Word32 L_y;
+ exp = norm_l(L_x);
+ L_x = (L_x << exp); /* L_x is normalized */
+ exp = (31 - exp);
+ Isqrt_n(&L_x, &exp);
+ L_y = (L_x << exp); /* denormalization */
+ return (L_y);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : Isqrt_n |
+| |
+| Compute 1/sqrt(value). |
+| if value is negative or zero, result is 1 (frac=7fffffff, exp=0). |
+|---------------------------------------------------------------------------|
+| Algorithm: |
+| |
+| The function 1/sqrt(value) is approximated by a table and linear |
+| interpolation. |
+| |
+| 1- If exponant is odd then shift fraction right once. |
+| 2- exponant = -((exponant-1)>>1) |
+| 3- i = bit25-b30 of fraction, 16 <= i <= 63 ->because of normalization. |
+| 4- a = bit10-b24 |
+| 5- i -=16 |
+| 6- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 |
+|___________________________________________________________________________|
+*/
+static Word16 table_isqrt[49] =
+{
+ 32767, 31790, 30894, 30070, 29309, 28602, 27945, 27330, 26755, 26214,
+ 25705, 25225, 24770, 24339, 23930, 23541, 23170, 22817, 22479, 22155,
+ 21845, 21548, 21263, 20988, 20724, 20470, 20225, 19988, 19760, 19539,
+ 19326, 19119, 18919, 18725, 18536, 18354, 18176, 18004, 17837, 17674,
+ 17515, 17361, 17211, 17064, 16921, 16782, 16646, 16514, 16384
+};
+
+void Isqrt_n(
+ Word32 * frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */
+ Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */
+ )
+{
+ Word16 i, a, tmp;
+
+ if (*frac <= (Word32) 0)
+ {
+ *exp = 0;
+ *frac = 0x7fffffffL;
+ return;
+ }
+
+ if((*exp & 1) == 1) /*If exponant odd -> shift right */
+ *frac = (*frac) >> 1;
+
+ *exp = negate((*exp - 1) >> 1);
+
+ *frac = (*frac >> 9);
+ i = extract_h(*frac); /* Extract b25-b31 */
+ *frac = (*frac >> 1);
+ a = (Word16)(*frac); /* Extract b10-b24 */
+ a = (Word16) (a & (Word16) 0x7fff);
+ i -= 16;
+ *frac = L_deposit_h(table_isqrt[i]); /* table[i] << 16 */
+ tmp = vo_sub(table_isqrt[i], table_isqrt[i + 1]); /* table[i] - table[i+1]) */
+ *frac = vo_L_msu(*frac, tmp, a); /* frac -= tmp*a*2 */
+
+ return;
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : Pow2() |
+| |
+| L_x = pow(2.0, exponant.fraction) (exponant = interger part) |
+| = pow(2.0, 0.fraction) << exponant |
+|---------------------------------------------------------------------------|
+| Algorithm: |
+| |
+| The function Pow2(L_x) is approximated by a table and linear |
+| interpolation. |
+| |
+| 1- i = bit10-b15 of fraction, 0 <= i <= 31 |
+| 2- a = bit0-b9 of fraction |
+| 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2 |
+| 4- L_x = L_x >> (30-exponant) (with rounding) |
+|___________________________________________________________________________|
+*/
+static Word16 table_pow2[33] =
+{
+ 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911,
+ 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726,
+ 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706,
+ 31379, 32066, 32767
+};
+
+Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */
+ Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */
+ Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */
+ )
+{
+ Word16 exp, i, a, tmp;
+ Word32 L_x;
+
+ L_x = vo_L_mult(fraction, 32); /* L_x = fraction<<6 */
+ i = extract_h(L_x); /* Extract b10-b16 of fraction */
+ L_x =L_x >> 1;
+ a = (Word16)(L_x); /* Extract b0-b9 of fraction */
+ a = (Word16) (a & (Word16) 0x7fff);
+
+ L_x = L_deposit_h(table_pow2[i]); /* table[i] << 16 */
+ tmp = vo_sub(table_pow2[i], table_pow2[i + 1]); /* table[i] - table[i+1] */
+ L_x -= (tmp * a)<<1; /* L_x -= tmp*a*2 */
+
+ exp = vo_sub(30, exponant);
+ L_x = vo_L_shr_r(L_x, exp);
+
+ return (L_x);
+}
+
+/*___________________________________________________________________________
+| |
+| Function Name : Dot_product12() |
+| |
+| Compute scalar product of <x[],y[]> using accumulator. |
+| |
+| The result is normalized (in Q31) with exponent (0..30). |
+|---------------------------------------------------------------------------|
+| Algorithm: |
+| |
+| dot_product = sum(x[i]*y[i]) i=0..N-1 |
+|___________________________________________________________________________|
+*/
+
+Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */
+ Word16 x[], /* (i) 12bits: x vector */
+ Word16 y[], /* (i) 12bits: y vector */
+ Word16 lg, /* (i) : vector length */
+ Word16 * exp /* (o) : exponent of result (0..+30) */
+ )
+{
+ Word16 sft;
+ Word32 i, L_sum;
+ L_sum = 0;
+ for (i = 0; i < lg; i++)
+ {
+ Word32 tmp = (Word32) x[i] * (Word32) y[i];
+ if (tmp == (Word32) 0x40000000L) {
+ tmp = MAX_32;
+ }
+ L_sum = L_add(L_sum, tmp);
+ }
+ L_sum = L_shl2(L_sum, 1);
+ L_sum = L_add(L_sum, 1);
+ /* Normalize acc in Q31 */
+ sft = norm_l(L_sum);
+ L_sum = L_sum << sft;
+ *exp = 30 - sft; /* exponent = 0..30 */
+ return (L_sum);
+
+}
+
+
diff --git a/media/codecs/amrwb/enc/src/mem_align.c b/media/codecs/amrwb/enc/src/mem_align.c
new file mode 100644
index 0000000..04e5976
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/mem_align.c
@@ -0,0 +1,112 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/*******************************************************************************
+ File: mem_align.c
+
+ Content: Memory alloc alignments functions
+
+*******************************************************************************/
+
+
+#include "mem_align.h"
+#ifdef _MSC_VER
+#include <stddef.h>
+#else
+#include <stdint.h>
+#endif
+
+/*****************************************************************************
+*
+* function name: mem_malloc
+* description: malloc the alignments memory
+* returns: the point of the memory
+*
+**********************************************************************************/
+void *
+mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID)
+{
+ int ret;
+ unsigned char *mem_ptr;
+ VO_MEM_INFO MemInfo;
+
+ if (!alignment) {
+
+ MemInfo.Flag = 0;
+ MemInfo.Size = size + 1;
+ ret = pMemop->Alloc(CodecID, &MemInfo);
+ if(ret != 0)
+ return 0;
+ mem_ptr = (unsigned char *)MemInfo.VBuffer;
+
+ pMemop->Set(CodecID, mem_ptr, 0, size + 1);
+
+ *mem_ptr = (unsigned char)1;
+
+ return ((void *)(mem_ptr+1));
+ } else {
+ unsigned char *tmp;
+
+ MemInfo.Flag = 0;
+ MemInfo.Size = size + alignment;
+ ret = pMemop->Alloc(CodecID, &MemInfo);
+ if(ret != 0)
+ return 0;
+
+ tmp = (unsigned char *)MemInfo.VBuffer;
+
+ pMemop->Set(CodecID, tmp, 0, size + alignment);
+
+ mem_ptr =
+ (unsigned char *) ((intptr_t) (tmp + alignment - 1) &
+ (~((intptr_t) (alignment - 1))));
+
+ if (mem_ptr == tmp)
+ mem_ptr += alignment;
+
+ *(mem_ptr - 1) = (unsigned char) (mem_ptr - tmp);
+
+ return ((void *)mem_ptr);
+ }
+
+ return(0);
+}
+
+
+/*****************************************************************************
+*
+* function name: mem_free
+* description: free the memory
+*
+*******************************************************************************/
+void
+mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID)
+{
+
+ unsigned char *ptr;
+
+ if (mem_ptr == 0)
+ return;
+
+ ptr = mem_ptr;
+
+ ptr -= *(ptr - 1);
+
+ pMemop->Free(CodecID, ptr);
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/oper_32b.c b/media/codecs/amrwb/enc/src/oper_32b.c
new file mode 100644
index 0000000..e6f80d0
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/oper_32b.c
@@ -0,0 +1,223 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/*****************************************************************************
+ * This file contains operations in double precision. *
+ * These operations are not standard double precision operations. *
+ * They are used where single precision is not enough but the full 32 bits *
+ * precision is not necessary. For example, the function Div_32() has a *
+ * 24 bits precision which is enough for our purposes. *
+ * *
+ * The double precision numbers use a special representation: *
+ * *
+ * L_32 = hi<<16 + lo<<1 *
+ * *
+ * L_32 is a 32 bit integer. *
+ * hi and lo are 16 bit signed integers. *
+ * As the low part also contains the sign, this allows fast multiplication. *
+ * *
+ * 0x8000 0000 <= L_32 <= 0x7fff fffe. *
+ * *
+ * We will use DPF (Double Precision Format )in this file to specify *
+ * this special format. *
+ *****************************************************************************
+*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+
+/*****************************************************************************
+ * *
+ * Function L_Extract() *
+ * *
+ * Extract from a 32 bit integer two 16 bit DPF. *
+ * *
+ * Arguments: *
+ * *
+ * L_32 : 32 bit integer. *
+ * 0x8000 0000 <= L_32 <= 0x7fff ffff. *
+ * hi : b16 to b31 of L_32 *
+ * lo : (L_32 - hi<<16)>>1 *
+ *****************************************************************************
+*/
+
+__inline void VO_L_Extract (Word32 L_32, Word16 *hi, Word16 *lo)
+{
+ *hi = (Word16)(L_32 >> 16);
+ *lo = (Word16)((L_32 & 0xffff) >> 1);
+ return;
+}
+
+/*****************************************************************************
+ * *
+ * Function L_Comp() *
+ * *
+ * Compose from two 16 bit DPF a 32 bit integer. *
+ * *
+ * L_32 = hi<<16 + lo<<1 *
+ * *
+ * Arguments: *
+ * *
+ * hi msb *
+ * lo lsf (with sign) *
+ * *
+ * Return Value : *
+ * *
+ * 32 bit long signed integer (Word32) whose value falls in the *
+ * range : 0x8000 0000 <= L_32 <= 0x7fff fff0. *
+ * *
+ *****************************************************************************
+*/
+
+Word32 L_Comp (Word16 hi, Word16 lo)
+{
+ Word32 L_32;
+
+ L_32 = L_deposit_h (hi);
+
+ return (L_mac (L_32, lo, 1)); /* = hi<<16 + lo<<1 */
+}
+
+/*****************************************************************************
+ * Function Mpy_32() *
+ * *
+ * Multiply two 32 bit integers (DPF). The result is divided by 2**31 *
+ * *
+ * L_32 = (hi1*hi2)<<1 + ( (hi1*lo2)>>15 + (lo1*hi2)>>15 )<<1 *
+ * *
+ * This operation can also be viewed as the multiplication of two Q31 *
+ * number and the result is also in Q31. *
+ * *
+ * Arguments: *
+ * *
+ * hi1 hi part of first number *
+ * lo1 lo part of first number *
+ * hi2 hi part of second number *
+ * lo2 lo part of second number *
+ * *
+ *****************************************************************************
+*/
+
+__inline Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2)
+{
+ Word32 L_32;
+ L_32 = (hi1 * hi2);
+ L_32 += (hi1 * lo2) >> 15;
+ L_32 += (lo1 * hi2) >> 15;
+ L_32 <<= 1;
+
+ return (L_32);
+}
+
+/*****************************************************************************
+ * Function Mpy_32_16() *
+ * *
+ * Multiply a 16 bit integer by a 32 bit (DPF). The result is divided *
+ * by 2**15 *
+ * *
+ * *
+ * L_32 = (hi1*lo2)<<1 + ((lo1*lo2)>>15)<<1 *
+ * *
+ * Arguments: *
+ * *
+ * hi hi part of 32 bit number. *
+ * lo lo part of 32 bit number. *
+ * n 16 bit number. *
+ * *
+ *****************************************************************************
+*/
+
+__inline Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n)
+{
+ Word32 L_32;
+
+ L_32 = (hi * n)<<1;
+ L_32 += (((lo * n)>>15)<<1);
+
+ return (L_32);
+}
+
+/*****************************************************************************
+ * *
+ * Function Name : Div_32 *
+ * *
+ * Purpose : *
+ * Fractional integer division of two 32 bit numbers. *
+ * L_num / L_denom. *
+ * L_num and L_denom must be positive and L_num < L_denom. *
+ * L_denom = denom_hi<<16 + denom_lo<<1 *
+ * denom_hi is a normalize number. *
+ * *
+ * Inputs : *
+ * *
+ * L_num *
+ * 32 bit long signed integer (Word32) whose value falls in the *
+ * range : 0x0000 0000 < L_num < L_denom *
+ * *
+ * L_denom = denom_hi<<16 + denom_lo<<1 (DPF) *
+ * *
+ * denom_hi *
+ * 16 bit positive normalized integer whose value falls in the *
+ * range : 0x4000 < hi < 0x7fff *
+ * denom_lo *
+ * 16 bit positive integer whose value falls in the *
+ * range : 0 < lo < 0x7fff *
+ * *
+ * Return Value : *
+ * *
+ * L_div *
+ * 32 bit long signed integer (Word32) whose value falls in the *
+ * range : 0x0000 0000 <= L_div <= 0x7fff ffff. *
+ * *
+ * Algorithm: *
+ * *
+ * - find = 1/L_denom. *
+ * First approximation: approx = 1 / denom_hi *
+ * 1/L_denom = approx * (2.0 - L_denom * approx ) *
+ * *
+ * - result = L_num * (1/L_denom) *
+ *****************************************************************************
+*/
+
+Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo)
+{
+ Word16 approx, hi, lo, n_hi, n_lo;
+ Word32 L_32;
+
+ /* First approximation: 1 / L_denom = 1/denom_hi */
+
+ approx = div_s ((Word16) 0x3fff, denom_hi);
+
+ /* 1/L_denom = approx * (2.0 - L_denom * approx) */
+
+ L_32 = Mpy_32_16 (denom_hi, denom_lo, approx);
+
+ L_32 = L_sub ((Word32) 0x7fffffffL, L_32);
+ hi = L_32 >> 16;
+ lo = (L_32 & 0xffff) >> 1;
+
+ L_32 = Mpy_32_16 (hi, lo, approx);
+
+ /* L_num * (1/L_denom) */
+ hi = L_32 >> 16;
+ lo = (L_32 & 0xffff) >> 1;
+ VO_L_Extract (L_num, &n_hi, &n_lo);
+ L_32 = Mpy_32 (n_hi, n_lo, hi, lo);
+ L_32 = L_shl2(L_32, 2);
+
+ return (L_32);
+}
+
diff --git a/media/codecs/amrwb/enc/src/p_med_ol.c b/media/codecs/amrwb/enc/src/p_med_ol.c
new file mode 100644
index 0000000..5d2b4bd
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/p_med_ol.c
@@ -0,0 +1,256 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: p_med_ol.c *
+* *
+* Description: Compute the open loop pitch lag *
+* output: open loop pitch lag *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "acelp.h"
+#include "oper_32b.h"
+#include "math_op.h"
+#include "p_med_ol.tab"
+
+Word16 Pitch_med_ol(
+ Word16 wsp[], /* i: signal used to compute the open loop pitch*/
+ /* wsp[-pit_max] to wsp[-1] should be known */
+ Coder_State *st, /* i/o: codec global structure */
+ Word16 L_frame /* i: length of frame to compute pitch */
+ )
+{
+ Word16 Tm;
+ Word16 hi, lo;
+ Word16 *ww, *we, *hp_wsp;
+ Word16 exp_R0, exp_R1, exp_R2;
+ Word32 i, j, max, R0, R1, R2;
+ Word16 *p1, *p2;
+ Word16 L_min = 17; /* minimum pitch lag: PIT_MIN / OPL_DECIM */
+ Word16 L_max = 115; /* maximum pitch lag: PIT_MAX / OPL_DECIM */
+ Word16 L_0 = st->old_T0_med; /* old open-loop pitch */
+ Word16 *gain = &(st->ol_gain); /* normalize correlation of hp_wsp for the lag */
+ Word16 *hp_wsp_mem = st->hp_wsp_mem; /* memory of the hypass filter for hp_wsp[] (lg = 9)*/
+ Word16 *old_hp_wsp = st->old_hp_wsp; /* hypass wsp[] */
+ Word16 wght_flg = st->ol_wght_flg; /* is weighting function used */
+
+ ww = &corrweight[198];
+ we = &corrweight[98 + L_max - L_0];
+
+ max = MIN_32;
+ Tm = 0;
+ for (i = L_max; i > L_min; i--)
+ {
+ /* Compute the correlation */
+ R0 = 0;
+ p1 = wsp;
+ p2 = &wsp[-i];
+ for (j = 0; j < L_frame; j+=4)
+ {
+ R0 += vo_L_mult((*p1++), (*p2++));
+ R0 += vo_L_mult((*p1++), (*p2++));
+ R0 += vo_L_mult((*p1++), (*p2++));
+ R0 += vo_L_mult((*p1++), (*p2++));
+ }
+ /* Weighting of the correlation function. */
+ hi = R0>>16;
+ lo = (R0 & 0xffff)>>1;
+
+ R0 = Mpy_32_16(hi, lo, *ww);
+ ww--;
+
+ if ((L_0 > 0) && (wght_flg > 0))
+ {
+ /* Weight the neighbourhood of the old lag. */
+ hi = R0>>16;
+ lo = (R0 & 0xffff)>>1;
+ R0 = Mpy_32_16(hi, lo, *we);
+ we--;
+ }
+ if(R0 >= max)
+ {
+ max = R0;
+ Tm = i;
+ }
+ }
+
+ /* Hypass the wsp[] vector */
+ hp_wsp = old_hp_wsp + L_max;
+ Hp_wsp(wsp, hp_wsp, L_frame, hp_wsp_mem);
+
+ /* Compute normalize correlation at delay Tm */
+ R0 = 0;
+ R1 = 0;
+ R2 = 0;
+ p1 = hp_wsp;
+ p2 = hp_wsp - Tm;
+ for (j = 0; j < L_frame; j+=4)
+ {
+ R2 += vo_mult32(*p1, *p1);
+ R1 += vo_mult32(*p2, *p2);
+ R0 += vo_mult32(*p1++, *p2++);
+ R2 += vo_mult32(*p1, *p1);
+ R1 += vo_mult32(*p2, *p2);
+ R0 += vo_mult32(*p1++, *p2++);
+ R2 += vo_mult32(*p1, *p1);
+ R1 += vo_mult32(*p2, *p2);
+ R0 += vo_mult32(*p1++, *p2++);
+ R2 += vo_mult32(*p1, *p1);
+ R1 += vo_mult32(*p2, *p2);
+ R0 += vo_mult32(*p1++, *p2++);
+ }
+ R0 = R0 <<1;
+ R1 = (R1 <<1) + 1L;
+ R2 = (R2 <<1) + 1L;
+ /* gain = R0/ sqrt(R1*R2) */
+
+ exp_R0 = norm_l(R0);
+ R0 = (R0 << exp_R0);
+
+ exp_R1 = norm_l(R1);
+ R1 = (R1 << exp_R1);
+
+ exp_R2 = norm_l(R2);
+ R2 = (R2 << exp_R2);
+
+
+ R1 = vo_L_mult(voround(R1), voround(R2));
+
+ i = norm_l(R1);
+ R1 = (R1 << i);
+
+ exp_R1 += exp_R2;
+ exp_R1 += i;
+ exp_R1 = 62 - exp_R1;
+
+ Isqrt_n(&R1, &exp_R1);
+
+ R0 = vo_L_mult(voround(R0), voround(R1));
+ exp_R0 = 31 - exp_R0;
+ exp_R0 += exp_R1;
+
+ *gain = vo_round(L_shl(R0, exp_R0));
+
+ /* Shitf hp_wsp[] for next frame */
+
+ for (i = 0; i < L_max; i++)
+ {
+ old_hp_wsp[i] = old_hp_wsp[i + L_frame];
+ }
+
+ return (Tm);
+}
+
+/************************************************************************
+* Function: median5 *
+* *
+* Returns the median of the set {X[-2], X[-1],..., X[2]}, *
+* whose elements are 16-bit integers. *
+* *
+* Input: *
+* X[-2:2] 16-bit integers. *
+* *
+* Return: *
+* The median of {X[-2], X[-1],..., X[2]}. *
+************************************************************************/
+
+Word16 median5(Word16 x[])
+{
+ Word16 x1, x2, x3, x4, x5;
+ Word16 tmp;
+
+ x1 = x[-2];
+ x2 = x[-1];
+ x3 = x[0];
+ x4 = x[1];
+ x5 = x[2];
+
+ if (x2 < x1)
+ {
+ tmp = x1;
+ x1 = x2;
+ x2 = tmp;
+ }
+ if (x3 < x1)
+ {
+ tmp = x1;
+ x1 = x3;
+ x3 = tmp;
+ }
+ if (x4 < x1)
+ {
+ tmp = x1;
+ x1 = x4;
+ x4 = tmp;
+ }
+ if (x5 < x1)
+ {
+ x5 = x1;
+ }
+ if (x3 < x2)
+ {
+ tmp = x2;
+ x2 = x3;
+ x3 = tmp;
+ }
+ if (x4 < x2)
+ {
+ tmp = x2;
+ x2 = x4;
+ x4 = tmp;
+ }
+ if (x5 < x2)
+ {
+ x5 = x2;
+ }
+ if (x4 < x3)
+ {
+ x3 = x4;
+ }
+ if (x5 < x3)
+ {
+ x3 = x5;
+ }
+ return (x3);
+}
+
+
+Word16 Med_olag( /* output : median of 5 previous open-loop lags */
+ Word16 prev_ol_lag, /* input : previous open-loop lag */
+ Word16 old_ol_lag[5]
+ )
+{
+ Word32 i;
+
+ /* Use median of 5 previous open-loop lags as old lag */
+
+ for (i = 4; i > 0; i--)
+ {
+ old_ol_lag[i] = old_ol_lag[i - 1];
+ }
+
+ old_ol_lag[0] = prev_ol_lag;
+
+ i = median5(&old_ol_lag[2]);
+
+ return i;
+
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/pit_shrp.c b/media/codecs/amrwb/enc/src/pit_shrp.c
new file mode 100644
index 0000000..f100253
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/pit_shrp.c
@@ -0,0 +1,49 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: pit_shrp.c *
+* *
+* Description: Performs Pitch sharpening routine *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+void Pit_shrp(
+ Word16 * x, /* in/out: impulse response (or algebraic code) */
+ Word16 pit_lag, /* input : pitch lag */
+ Word16 sharp, /* input : pitch sharpening factor (Q15) */
+ Word16 L_subfr /* input : subframe size */
+ )
+{
+ Word32 i;
+ Word32 L_tmp;
+ Word16 *x_ptr = x + pit_lag;
+
+ for (i = pit_lag; i < L_subfr; i++)
+ {
+ L_tmp = (*x_ptr << 15);
+ L_tmp += *x++ * sharp;
+ *x_ptr++ = ((L_tmp + 0x4000)>>15);
+ }
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/pitch_f4.c b/media/codecs/amrwb/enc/src/pitch_f4.c
new file mode 100644
index 0000000..b453b25
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/pitch_f4.c
@@ -0,0 +1,327 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: pitch_f4.c *
+* *
+* Description: Find the closed loop pitch period with *
+* 1/4 subsample resolution. *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+#include "acelp.h"
+#include "cnst.h"
+
+#define UP_SAMP 4
+#define L_INTERPOL1 4
+
+#define UNUSED(x) (void)(x)
+
+/* Local functions */
+
+#ifdef ASM_OPT
+void Norm_corr_asm(
+ Word16 exc[], /* (i) : excitation buffer */
+ Word16 xn[], /* (i) : target vector */
+ Word16 h[], /* (i) Q15 : impulse response of synth/wgt filters */
+ Word16 L_subfr,
+ Word16 t_min, /* (i) : minimum value of pitch lag. */
+ Word16 t_max, /* (i) : maximum value of pitch lag. */
+ Word16 corr_norm[] /* (o) Q15 : normalized correlation */
+ );
+#else
+static void Norm_Corr(
+ Word16 exc[], /* (i) : excitation buffer */
+ Word16 xn[], /* (i) : target vector */
+ Word16 h[], /* (i) Q15 : impulse response of synth/wgt filters */
+ Word16 L_subfr,
+ Word16 t_min, /* (i) : minimum value of pitch lag. */
+ Word16 t_max, /* (i) : maximum value of pitch lag. */
+ Word16 corr_norm[] /* (o) Q15 : normalized correlation */
+ );
+#endif
+
+static Word16 Interpol_4( /* (o) : interpolated value */
+ Word16 * x, /* (i) : input vector */
+ Word32 frac /* (i) : fraction (-4..+3) */
+ );
+
+
+Word16 Pitch_fr4( /* (o) : pitch period. */
+ Word16 exc[], /* (i) : excitation buffer */
+ Word16 xn[], /* (i) : target vector */
+ Word16 h[], /* (i) Q15 : impulse response of synth/wgt filters */
+ Word16 t0_min, /* (i) : minimum value in the searched range. */
+ Word16 t0_max, /* (i) : maximum value in the searched range. */
+ Word16 * pit_frac, /* (o) : chosen fraction (0, 1, 2 or 3). */
+ Word16 i_subfr, /* (i) : indicator for first subframe. */
+ Word16 t0_fr2, /* (i) : minimum value for resolution 1/2 */
+ Word16 t0_fr1, /* (i) : minimum value for resolution 1 */
+ Word16 L_subfr /* (i) : Length of subframe */
+ )
+{
+ Word32 fraction, i;
+ Word16 t_min, t_max;
+ Word16 max, t0, step, temp;
+ Word16 *corr;
+ Word16 corr_v[40]; /* Total length = t0_max-t0_min+1+2*L_inter */
+
+ /* Find interval to compute normalized correlation */
+
+ t_min = L_sub(t0_min, L_INTERPOL1);
+ t_max = L_add(t0_max, L_INTERPOL1);
+ corr = &corr_v[-t_min];
+ /* Compute normalized correlation between target and filtered excitation */
+#ifdef ASM_OPT /* asm optimization branch */
+ Norm_corr_asm(exc, xn, h, L_subfr, t_min, t_max, corr);
+#else
+ Norm_Corr(exc, xn, h, L_subfr, t_min, t_max, corr);
+#endif
+
+ /* Find integer pitch */
+
+ max = corr[t0_min];
+ t0 = t0_min;
+ for (i = t0_min + 1; i <= t0_max; i++)
+ {
+ if (corr[i] >= max)
+ {
+ max = corr[i];
+ t0 = i;
+ }
+ }
+ /* If first subframe and t0 >= t0_fr1, do not search fractionnal pitch */
+ if ((i_subfr == 0) && (t0 >= t0_fr1))
+ {
+ *pit_frac = 0;
+ return (t0);
+ }
+ /*------------------------------------------------------------------*
+ * Search fractionnal pitch with 1/4 subsample resolution. *
+ * Test the fractions around t0 and choose the one which maximizes *
+ * the interpolated normalized correlation. *
+ *------------------------------------------------------------------*/
+
+ step = 1; /* 1/4 subsample resolution */
+ fraction = -3;
+ if ((t0_fr2 == PIT_MIN)||((i_subfr == 0) && (t0 >= t0_fr2)))
+ {
+ step = 2; /* 1/2 subsample resolution */
+ fraction = -2;
+ }
+ if(t0 == t0_min)
+ {
+ fraction = 0;
+ }
+ max = Interpol_4(&corr[t0], fraction);
+
+ for (i = fraction + step; i <= 3; i += step)
+ {
+ temp = Interpol_4(&corr[t0], i);
+ if(temp > max)
+ {
+ max = temp;
+ fraction = i;
+ }
+ }
+ /* limit the fraction value in the interval [0,1,2,3] */
+ if (fraction < 0)
+ {
+ fraction += UP_SAMP;
+ t0 -= 1;
+ }
+ *pit_frac = fraction;
+ return (t0);
+}
+
+
+/***********************************************************************************
+* Function: Norm_Corr() *
+* *
+* Description: Find the normalized correlation between the target vector and the *
+* filtered past excitation. *
+* (correlation between target and filtered excitation divided by the *
+* square root of energy of target and filtered excitation). *
+************************************************************************************/
+#ifndef ASM_OPT
+static void Norm_Corr(
+ Word16 exc[], /* (i) : excitation buffer */
+ Word16 xn[], /* (i) : target vector */
+ Word16 h[], /* (i) Q15 : impulse response of synth/wgt filters */
+ Word16 L_subfr,
+ Word16 t_min, /* (i) : minimum value of pitch lag. */
+ Word16 t_max, /* (i) : maximum value of pitch lag. */
+ Word16 corr_norm[]) /* (o) Q15 : normalized correlation */
+{
+ Word32 i, k, t;
+ Word32 corr, exp_corr, norm, exp, scale;
+ Word16 exp_norm, excf[L_SUBFR], tmp;
+ Word32 L_tmp, L_tmp1, L_tmp2;
+ UNUSED(L_subfr);
+
+ /* compute the filtered excitation for the first delay t_min */
+ k = -t_min;
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Convolve_asm(&exc[k], h, excf, 64);
+#else
+ Convolve(&exc[k], h, excf, 64);
+#endif
+
+ /* Compute rounded down 1/sqrt(energy of xn[]) */
+ L_tmp = 0;
+ for (i = 0; i < 64; i+=4)
+ {
+ L_tmp = L_add(L_tmp, (xn[i] * xn[i]));
+ L_tmp = L_add(L_tmp, (xn[i+1] * xn[i+1]));
+ L_tmp = L_add(L_tmp, (xn[i+2] * xn[i+2]));
+ L_tmp = L_add(L_tmp, (xn[i+3] * xn[i+3]));
+ }
+
+ L_tmp = L_add(L_shl(L_tmp, 1), 1);
+ exp = norm_l(L_tmp);
+ exp = L_sub(32, exp);
+ //exp = exp + 2; /* energy of xn[] x 2 + rounded up */
+ scale = -(exp >> 1); /* (1<<scale) < 1/sqrt(energy rounded) */
+
+ /* loop for every possible period */
+
+ for (t = t_min; t <= t_max; t++)
+ {
+ /* Compute correlation between xn[] and excf[] */
+ L_tmp = 0;
+ L_tmp1 = 0;
+ for (i = 0; i < 64; i+=4)
+ {
+ L_tmp = L_add(L_tmp, (xn[i] * excf[i]));
+ L_tmp1 = L_add(L_tmp1, (excf[i] * excf[i]));
+ L_tmp = L_add(L_tmp, (xn[i+1] * excf[i+1]));
+ L_tmp1 = L_add(L_tmp1, (excf[i+1] * excf[i+1]));
+ L_tmp = L_add(L_tmp, (xn[i+2] * excf[i+2]));
+ L_tmp1 = L_add(L_tmp1, (excf[i+2] * excf[i+2]));
+ L_tmp = L_add(L_tmp, (xn[i+3] * excf[i+3]));
+ L_tmp1 = L_add(L_tmp1, (excf[i+3] * excf[i+3]));
+ }
+
+ L_tmp = L_add(L_shl(L_tmp, 1), 1);
+ L_tmp1 = L_add(L_shl(L_tmp1, 1), 1);
+
+ exp = norm_l(L_tmp);
+ L_tmp = L_shl(L_tmp, exp);
+ exp_corr = L_sub(30, exp);
+ corr = extract_h(L_tmp);
+
+ exp = norm_l(L_tmp1);
+ L_tmp = L_shl(L_tmp1, exp);
+ exp_norm = L_sub(30, exp);
+
+ Isqrt_n(&L_tmp, &exp_norm);
+ norm = extract_h(L_tmp);
+
+ /* Normalize correlation = correlation * (1/sqrt(energy)) */
+
+ L_tmp = L_mult(corr, norm);
+
+ L_tmp2 = L_add(exp_corr, exp_norm + scale);
+ if(L_tmp2 < 0)
+ {
+ L_tmp2 = -L_tmp2;
+ L_tmp = L_tmp >> L_tmp2;
+ }
+ else
+ {
+ L_tmp = L_shl(L_tmp, L_tmp2);
+ }
+
+ corr_norm[t] = voround(L_tmp);
+ /* modify the filtered excitation excf[] for the next iteration */
+
+ if(t != t_max)
+ {
+ k = -(t + 1);
+ tmp = exc[k];
+ for (i = 63; i > 0; i--)
+ {
+ excf[i] = add1(vo_mult(tmp, h[i]), excf[i - 1]);
+ }
+ excf[0] = vo_mult(tmp, h[0]);
+ }
+ }
+ return;
+}
+
+#endif
+/************************************************************************************
+* Function: Interpol_4() *
+* *
+* Description: For interpolating the normalized correlation with 1/4 resolution. *
+**************************************************************************************/
+
+/* 1/4 resolution interpolation filter (-3 dB at 0.791*fs/2) in Q14 */
+static Word16 inter4_1[4][8] =
+{
+ {-12, 420, -1732, 5429, 13418, -1242, 73, 32},
+ {-26, 455, -2142, 9910, 9910, -2142, 455, -26},
+ {32, 73, -1242, 13418, 5429, -1732, 420, -12},
+ {206, -766, 1376, 14746, 1376, -766, 206, 0}
+};
+
+/*** Coefficients in floating point
+static float inter4_1[UP_SAMP*L_INTERPOL1+1] = {
+0.900000,
+0.818959, 0.604850, 0.331379, 0.083958,
+-0.075795, -0.130717, -0.105685, -0.046774,
+0.004467, 0.027789, 0.025642, 0.012571,
+0.001927, -0.001571, -0.000753, 0.000000};
+***/
+
+static Word16 Interpol_4( /* (o) : interpolated value */
+ Word16 * x, /* (i) : input vector */
+ Word32 frac /* (i) : fraction (-4..+3) */
+ )
+{
+ Word16 sum;
+ Word32 k, L_sum;
+ Word16 *ptr;
+
+ if (frac < 0)
+ {
+ frac += UP_SAMP;
+ x--;
+ }
+ x = x - L_INTERPOL1 + 1;
+ k = UP_SAMP - 1 - frac;
+ ptr = &(inter4_1[k][0]);
+
+ L_sum = vo_mult32(x[0], (*ptr++));
+ L_sum = L_add(L_sum, vo_mult32(x[1], (*ptr++)));
+ L_sum = L_add(L_sum, vo_mult32(x[2], (*ptr++)));
+ L_sum = L_add(L_sum, vo_mult32(x[3], (*ptr++)));
+ L_sum = L_add(L_sum, vo_mult32(x[4], (*ptr++)));
+ L_sum = L_add(L_sum, vo_mult32(x[5], (*ptr++)));
+ L_sum = L_add(L_sum, vo_mult32(x[6], (*ptr++)));
+ L_sum = L_add(L_sum, vo_mult32(x[7], (*ptr++)));
+
+ sum = extract_h(L_add(L_shl2(L_sum, 2), 0x8000));
+ return (sum);
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/pred_lt4.c b/media/codecs/amrwb/enc/src/pred_lt4.c
new file mode 100644
index 0000000..386cab3
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/pred_lt4.c
@@ -0,0 +1,120 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: pred_lt4.c *
+* *
+* Description: Compute the result of long term prediction with *
+* fractional interpolation of resolution 1/4 *
+* on return exc[0..L_subr-1] contains the interpolated signal *
+* (adaptive codebook excitation) *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+#define UP_SAMP 4
+#define L_INTERPOL2 16
+
+/* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) in Q14 */
+
+Word16 inter4_2[4][32] =
+{
+ {0,-2,4,-2,-10,38,-88,165,-275,424,-619,871,-1207,1699,-2598,5531,14031,-2147,780,-249,
+ -16,153,-213,226,-209,175,-133,91,-55,28,-10,2},
+
+ {1,-7,19,-33,47,-52,43,-9,-60,175,-355,626,-1044,1749,-3267,10359,10359,-3267,1749,-1044,
+ 626,-355,175,-60,-9,43,-52,47,-33,19, -7, 1},
+
+ {2,-10,28,-55,91,-133,175,-209,226,-213,153,-16,-249,780,-2147,14031,5531,-2598,1699,-1207,
+ 871,-619,424,-275,165,-88,38,-10,-2,4,-2,0},
+
+ {1,-7,22,-49,92,-153,231,-325,431,-544,656,-762,853,-923,968,15401,968,-923,853,-762,
+ 656,-544,431,-325,231,-153,92,-49,22,-7, 1, 0}
+
+};
+
+void Pred_lt4(
+ Word16 exc[], /* in/out: excitation buffer */
+ Word16 T0, /* input : integer pitch lag */
+ Word16 frac, /* input : fraction of lag */
+ Word16 L_subfr /* input : subframe size */
+ )
+{
+ Word16 j, k, *x;
+ Word32 L_sum;
+ Word16 *ptr, *ptr1;
+ Word16 *ptr2;
+
+ x = exc - T0;
+ frac = -frac;
+ if (frac < 0)
+ {
+ frac += UP_SAMP;
+ x--;
+ }
+ x -= 15; /* x = L_INTERPOL2 - 1 */
+ k = 3 - frac; /* k = UP_SAMP - 1 - frac */
+
+ ptr2 = &(inter4_2[k][0]);
+ for (j = 0; j < L_subfr; j++)
+ {
+ ptr = ptr2;
+ ptr1 = x;
+ L_sum = vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+ L_sum += vo_mult32((*ptr1++), (*ptr++));
+
+ L_sum = L_shl2(L_sum, 2);
+ exc[j] = extract_h(L_add(L_sum, 0x8000));
+ x++;
+ }
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/preemph.c b/media/codecs/amrwb/enc/src/preemph.c
new file mode 100644
index 0000000..a43841a
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/preemph.c
@@ -0,0 +1,101 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: preemph.c *
+* *
+* Description: Preemphasis: filtering through 1 - g z^-1 *
+* Preemph2 --> signal is multiplied by 2 *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include <stdint.h>
+
+void Preemph(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : preemphasis coefficient */
+ Word16 lg, /* (i) : lenght of filtering */
+ Word16 * mem /* (i/o) : memory (x[-1]) */
+ )
+{
+ Word16 temp;
+ Word32 i, L_tmp;
+
+ temp = x[lg - 1];
+
+ for (i = lg - 1; i > 0; i--)
+ {
+ L_tmp = L_deposit_h(x[i]);
+ L_tmp -= (x[i - 1] * mu)<<1;
+ x[i] = (L_tmp + 0x8000)>>16;
+ }
+
+ L_tmp = L_deposit_h(x[0]);
+ L_tmp -= ((*mem) * mu)<<1;
+ x[0] = (L_tmp + 0x8000)>>16;
+
+ *mem = temp;
+
+ return;
+}
+
+
+void Preemph2(
+ Word16 x[], /* (i/o) : input signal overwritten by the output */
+ Word16 mu, /* (i) Q15 : preemphasis coefficient */
+ Word16 lg, /* (i) : lenght of filtering */
+ Word16 * mem /* (i/o) : memory (x[-1]) */
+ )
+{
+ Word16 temp;
+ Word32 i, L_tmp;
+
+ temp = x[lg - 1];
+
+ for (i = (Word16) (lg - 1); i > 0; i--)
+ {
+ L_tmp = L_deposit_h(x[i]);
+ L_tmp -= (x[i - 1] * mu)<<1; // only called with mu == 22282, so this won't overflow
+ if (L_tmp > INT32_MAX / 2) {
+ L_tmp = INT32_MAX / 2;
+ }
+ L_tmp = (L_tmp << 1);
+ if (L_tmp > INT32_MAX - 0x8000) {
+ L_tmp = INT32_MAX - 0x8000;
+ }
+ x[i] = (L_tmp + 0x8000)>>16;
+ }
+
+ L_tmp = L_deposit_h(x[0]);
+ L_tmp -= ((*mem) * mu)<<1;
+ if (L_tmp > INT32_MAX / 2) {
+ L_tmp = INT32_MAX / 2;
+ }
+ L_tmp = (L_tmp << 1);
+ if (L_tmp > INT32_MAX - 0x8000) {
+ L_tmp = INT32_MAX - 0x8000;
+ }
+ x[0] = (L_tmp + 0x8000)>>16;
+
+ *mem = temp;
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/q_gain2.c b/media/codecs/amrwb/enc/src/q_gain2.c
new file mode 100644
index 0000000..bb797d8
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/q_gain2.c
@@ -0,0 +1,346 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/**************************************************************************
+* File: q_gain2.c *
+* *
+* Description: *
+* Quantization of pitch and codebook gains. *
+* MA prediction is performed on the innovation energy (in dB with mean *
+* removed). *
+* An initial predicted gain, g_0, is first determined and the correction *
+* factor alpha = gain / g_0 is quantized. *
+* The pitch gain and the correction factor are vector quantized and the *
+* mean-squared weighted error criterion is used in the quantizer search. *
+****************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "math_op.h"
+#include "log2.h"
+#include "acelp.h"
+#include "q_gain2.tab"
+
+#define MEAN_ENER 30
+#define RANGE 64
+#define PRED_ORDER 4
+
+
+/* MA prediction coeff ={0.5, 0.4, 0.3, 0.2} in Q13 */
+static Word16 pred[PRED_ORDER] = {4096, 3277, 2458, 1638};
+
+
+void Init_Q_gain2(
+ Word16 * mem /* output :static memory (2 words) */
+ )
+{
+ Word32 i;
+
+ /* 4nd order quantizer energy predictor (init to -14.0 in Q10) */
+ for (i = 0; i < PRED_ORDER; i++)
+ {
+ mem[i] = -14336; /* past_qua_en[i] */
+ }
+
+ return;
+}
+
+Word16 Q_gain2( /* Return index of quantization. */
+ Word16 xn[], /* (i) Q_xn: Target vector. */
+ Word16 y1[], /* (i) Q_xn: Adaptive codebook. */
+ Word16 Q_xn, /* (i) : xn and y1 format */
+ Word16 y2[], /* (i) Q9 : Filtered innovative vector. */
+ Word16 code[], /* (i) Q9 : Innovative vector. */
+ Word16 g_coeff[], /* (i) : Correlations <xn y1> <y1 y1> */
+ /* Compute in G_pitch(). */
+ Word16 L_subfr, /* (i) : Subframe lenght. */
+ Word16 nbits, /* (i) : number of bits (6 or 7) */
+ Word16 * gain_pit, /* (i/o)Q14: Pitch gain. */
+ Word32 * gain_cod, /* (o) Q16 : Code gain. */
+ Word16 gp_clip, /* (i) : Gp Clipping flag */
+ Word16 * mem /* (i/o) : static memory (2 words) */
+ )
+{
+ Word16 index, *p, min_ind, size;
+ Word16 exp, frac, gcode0, exp_gcode0, e_max, exp_code, qua_ener;
+ Word16 g_pitch, g2_pitch, g_code, g_pit_cod, g2_code, g2_code_lo;
+ Word16 coeff[5], coeff_lo[5], exp_coeff[5];
+ Word16 exp_max[5];
+ Word32 i, j, L_tmp, dist_min;
+ Word16 *past_qua_en, *t_qua_gain;
+
+ past_qua_en = mem;
+
+ /*-----------------------------------------------------------------*
+ * - Find the initial quantization pitch index *
+ * - Set gains search range *
+ *-----------------------------------------------------------------*/
+ if (nbits == 6)
+ {
+ t_qua_gain = t_qua_gain6b;
+ min_ind = 0;
+ size = RANGE;
+
+ if(gp_clip == 1)
+ {
+ size = size - 16; /* limit gain pitch to 1.0 */
+ }
+ } else
+ {
+ t_qua_gain = t_qua_gain7b;
+
+ p = t_qua_gain7b + RANGE; /* pt at 1/4th of table */
+
+ j = nb_qua_gain7b - RANGE;
+
+ if (gp_clip == 1)
+ {
+ j = j - 27; /* limit gain pitch to 1.0 */
+ }
+ min_ind = 0;
+ g_pitch = *gain_pit;
+
+ for (i = 0; i < j; i++, p += 2)
+ {
+ if (g_pitch > *p)
+ {
+ min_ind = min_ind + 1;
+ }
+ }
+ size = RANGE;
+ }
+
+ /*------------------------------------------------------------------*
+ * Compute coefficient need for the quantization. *
+ * *
+ * coeff[0] = y1 y1 *
+ * coeff[1] = -2 xn y1 *
+ * coeff[2] = y2 y2 *
+ * coeff[3] = -2 xn y2 *
+ * coeff[4] = 2 y1 y2 *
+ * *
+ * Product <y1 y1> and <xn y1> have been compute in G_pitch() and *
+ * are in vector g_coeff[]. *
+ *------------------------------------------------------------------*/
+
+ coeff[0] = g_coeff[0];
+ exp_coeff[0] = g_coeff[1];
+ coeff[1] = negate(g_coeff[2]); /* coeff[1] = -2 xn y1 */
+ exp_coeff[1] = g_coeff[3] + 1;
+
+ /* Compute scalar product <y2[],y2[]> */
+#ifdef ASM_OPT /* asm optimization branch */
+ coeff[2] = extract_h(Dot_product12_asm(y2, y2, L_subfr, &exp));
+#else
+ coeff[2] = extract_h(Dot_product12(y2, y2, L_subfr, &exp));
+#endif
+ exp_coeff[2] = (exp - 18) + (Q_xn << 1); /* -18 (y2 Q9) */
+
+ /* Compute scalar product -2*<xn[],y2[]> */
+#ifdef ASM_OPT /* asm optimization branch */
+ coeff[3] = extract_h(L_negate(Dot_product12_asm(xn, y2, L_subfr, &exp)));
+#else
+ coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_subfr, &exp)));
+#endif
+
+ exp_coeff[3] = (exp - 8) + Q_xn; /* -9 (y2 Q9), +1 (2 xn y2) */
+
+ /* Compute scalar product 2*<y1[],y2[]> */
+#ifdef ASM_OPT /* asm optimization branch */
+ coeff[4] = extract_h(Dot_product12_asm(y1, y2, L_subfr, &exp));
+#else
+ coeff[4] = extract_h(Dot_product12(y1, y2, L_subfr, &exp));
+#endif
+ exp_coeff[4] = (exp - 8) + Q_xn; /* -9 (y2 Q9), +1 (2 y1 y2) */
+
+ /*-----------------------------------------------------------------*
+ * Find energy of code and compute: *
+ * *
+ * L_tmp = MEAN_ENER - 10log10(energy of code/ L_subfr) *
+ * = MEAN_ENER - 3.0103*log2(energy of code/ L_subfr) *
+ *-----------------------------------------------------------------*/
+#ifdef ASM_OPT /* asm optimization branch */
+ L_tmp = Dot_product12_asm(code, code, L_subfr, &exp_code);
+#else
+ L_tmp = Dot_product12(code, code, L_subfr, &exp_code);
+#endif
+ /* exp_code: -18 (code in Q9), -6 (/L_subfr), -31 (L_tmp Q31->Q0) */
+ exp_code = (exp_code - (18 + 6 + 31));
+
+ Log2(L_tmp, &exp, &frac);
+ exp += exp_code;
+ L_tmp = Mpy_32_16(exp, frac, -24660); /* x -3.0103(Q13) -> Q14 */
+
+ L_tmp += (MEAN_ENER * 8192)<<1; /* + MEAN_ENER in Q14 */
+
+ /*-----------------------------------------------------------------*
+ * Compute gcode0. *
+ * = Sum(i=0,1) pred[i]*past_qua_en[i] + mean_ener - ener_code *
+ *-----------------------------------------------------------------*/
+ L_tmp = (L_tmp << 10); /* From Q14 to Q24 */
+ L_tmp += (pred[0] * past_qua_en[0])<<1; /* Q13*Q10 -> Q24 */
+ L_tmp += (pred[1] * past_qua_en[1])<<1; /* Q13*Q10 -> Q24 */
+ L_tmp += (pred[2] * past_qua_en[2])<<1; /* Q13*Q10 -> Q24 */
+ L_tmp += (pred[3] * past_qua_en[3])<<1; /* Q13*Q10 -> Q24 */
+
+ gcode0 = extract_h(L_tmp); /* From Q24 to Q8 */
+
+ /*-----------------------------------------------------------------*
+ * gcode0 = pow(10.0, gcode0/20) *
+ * = pow(2, 3.321928*gcode0/20) *
+ * = pow(2, 0.166096*gcode0) *
+ *-----------------------------------------------------------------*/
+
+ L_tmp = vo_L_mult(gcode0, 5443); /* *0.166096 in Q15 -> Q24 */
+ L_tmp = L_tmp >> 8; /* From Q24 to Q16 */
+ VO_L_Extract(L_tmp, &exp_gcode0, &frac); /* Extract exponent of gcode0 */
+
+ gcode0 = (Word16)(Pow2(14, frac)); /* Put 14 as exponent so that */
+ /* output of Pow2() will be: */
+ /* 16384 < Pow2() <= 32767 */
+ exp_gcode0 -= 14;
+
+ /*-------------------------------------------------------------------------*
+ * Find the best quantizer *
+ * ~~~~~~~~~~~~~~~~~~~~~~~ *
+ * Before doing the computation we need to aling exponents of coeff[] *
+ * to be sure to have the maximum precision. *
+ * *
+ * In the table the pitch gains are in Q14, the code gains are in Q11 and *
+ * are multiply by gcode0 which have been multiply by 2^exp_gcode0. *
+ * Also when we compute g_pitch*g_pitch, g_code*g_code and g_pitch*g_code *
+ * we divide by 2^15. *
+ * Considering all the scaling above we have: *
+ * *
+ * exp_code = exp_gcode0-11+15 = exp_gcode0+4 *
+ * *
+ * g_pitch*g_pitch = -14-14+15 *
+ * g_pitch = -14 *
+ * g_code*g_code = (2*exp_code)+15 *
+ * g_code = exp_code *
+ * g_pitch*g_code = -14 + exp_code +15 *
+ * *
+ * g_pitch*g_pitch * coeff[0] ;exp_max0 = exp_coeff[0] - 13 *
+ * g_pitch * coeff[1] ;exp_max1 = exp_coeff[1] - 14 *
+ * g_code*g_code * coeff[2] ;exp_max2 = exp_coeff[2] +15+(2*exp_code) *
+ * g_code * coeff[3] ;exp_max3 = exp_coeff[3] + exp_code *
+ * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code *
+ *-------------------------------------------------------------------------*/
+
+ exp_code = (exp_gcode0 + 4);
+ exp_max[0] = (exp_coeff[0] - 13);
+ exp_max[1] = (exp_coeff[1] - 14);
+ exp_max[2] = (exp_coeff[2] + (15 + (exp_code << 1)));
+ exp_max[3] = (exp_coeff[3] + exp_code);
+ exp_max[4] = (exp_coeff[4] + (1 + exp_code));
+
+ /* Find maximum exponant */
+
+ e_max = exp_max[0];
+ for (i = 1; i < 5; i++)
+ {
+ if(exp_max[i] > e_max)
+ {
+ e_max = exp_max[i];
+ }
+ }
+
+ /* align coeff[] and save in special 32 bit double precision */
+
+ for (i = 0; i < 5; i++)
+ {
+ j = add1(vo_sub(e_max, exp_max[i]), 2);/* /4 to avoid overflow */
+ L_tmp = L_deposit_h(coeff[i]);
+ L_tmp = L_shr(L_tmp, j);
+ VO_L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);
+ coeff_lo[i] = (coeff_lo[i] >> 3); /* lo >> 3 */
+ }
+
+ /* Codebook search */
+ dist_min = MAX_32;
+ p = &t_qua_gain[min_ind << 1];
+
+ index = 0;
+ for (i = 0; i < size; i++)
+ {
+ g_pitch = *p++;
+ g_code = *p++;
+
+ g_code = ((g_code * gcode0) + 0x4000)>>15;
+ g2_pitch = ((g_pitch * g_pitch) + 0x4000)>>15;
+ g_pit_cod = ((g_code * g_pitch) + 0x4000)>>15;
+ L_tmp = (g_code * g_code)<<1;
+ VO_L_Extract(L_tmp, &g2_code, &g2_code_lo);
+
+ L_tmp = (coeff[2] * g2_code_lo)<<1;
+ L_tmp = (L_tmp >> 3);
+ L_tmp += (coeff_lo[0] * g2_pitch)<<1;
+ L_tmp += (coeff_lo[1] * g_pitch)<<1;
+ L_tmp += (coeff_lo[2] * g2_code)<<1;
+ L_tmp += (coeff_lo[3] * g_code)<<1;
+ L_tmp += (coeff_lo[4] * g_pit_cod)<<1;
+ L_tmp = (L_tmp >> 12);
+ L_tmp += (coeff[0] * g2_pitch)<<1;
+ L_tmp += (coeff[1] * g_pitch)<<1;
+ L_tmp += (coeff[2] * g2_code)<<1;
+ L_tmp += (coeff[3] * g_code)<<1;
+ L_tmp += (coeff[4] * g_pit_cod)<<1;
+
+ if(L_tmp < dist_min)
+ {
+ dist_min = L_tmp;
+ index = i;
+ }
+ }
+
+ /* Read the quantized gains */
+ index = index + min_ind;
+ p = &t_qua_gain[(index + index)];
+ *gain_pit = *p++; /* selected pitch gain in Q14 */
+ g_code = *p++; /* selected code gain in Q11 */
+
+ L_tmp = vo_L_mult(g_code, gcode0); /* Q11*Q0 -> Q12 */
+ L_tmp = L_shl(L_tmp, (exp_gcode0 + 4)); /* Q12 -> Q16 */
+
+ *gain_cod = L_tmp; /* gain of code in Q16 */
+
+ /*---------------------------------------------------*
+ * qua_ener = 20*log10(g_code) *
+ * = 6.0206*log2(g_code) *
+ * = 6.0206*(log2(g_codeQ11) - 11) *
+ *---------------------------------------------------*/
+
+ L_tmp = L_deposit_l(g_code);
+ Log2(L_tmp, &exp, &frac);
+ exp -= 11;
+ L_tmp = Mpy_32_16(exp, frac, 24660); /* x 6.0206 in Q12 */
+
+ qua_ener = (Word16)(L_tmp >> 3); /* result in Q10 */
+
+ /* update table of past quantized energies */
+
+ past_qua_en[3] = past_qua_en[2];
+ past_qua_en[2] = past_qua_en[1];
+ past_qua_en[1] = past_qua_en[0];
+ past_qua_en[0] = qua_ener;
+
+ return (index);
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/q_pulse.c b/media/codecs/amrwb/enc/src/q_pulse.c
new file mode 100644
index 0000000..657b6fe
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/q_pulse.c
@@ -0,0 +1,401 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: q_pulse.c *
+* *
+* Description: Coding and decoding of algebraic codebook *
+* *
+************************************************************************/
+
+#include <stdio.h>
+#include "typedef.h"
+#include "basic_op.h"
+#include "q_pulse.h"
+
+#define NB_POS 16 /* pos in track, mask for sign bit */
+#define UNUSED_VAR __attribute__((unused))
+
+Word32 quant_1p_N1( /* (o) return N+1 bits */
+ Word16 pos, /* (i) position of the pulse */
+ Word16 N) /* (i) number of bits for position */
+{
+ Word16 mask;
+ Word32 index;
+
+ mask = (1 << N) - 1; /* mask = ((1<<N)-1); */
+ /*-------------------------------------------------------*
+ * Quantization of 1 pulse with N+1 bits: *
+ *-------------------------------------------------------*/
+ index = L_deposit_l((Word16) (pos & mask));
+ if ((pos & NB_POS) != 0)
+ {
+ index = vo_L_add(index, L_deposit_l(1 << N)); /* index += 1 << N; */
+ }
+ return (index);
+}
+
+
+Word32 quant_2p_2N1( /* (o) return (2*N)+1 bits */
+ Word16 pos1, /* (i) position of the pulse 1 */
+ Word16 pos2, /* (i) position of the pulse 2 */
+ Word16 N) /* (i) number of bits for position */
+{
+ Word16 mask, tmp;
+ Word32 index;
+ mask = (1 << N) - 1; /* mask = ((1<<N)-1); */
+ /*-------------------------------------------------------*
+ * Quantization of 2 pulses with 2*N+1 bits: *
+ *-------------------------------------------------------*/
+ if (((pos2 ^ pos1) & NB_POS) == 0)
+ {
+ /* sign of 1st pulse == sign of 2th pulse */
+ if(pos1 <= pos2) /* ((pos1 - pos2) <= 0) */
+ {
+ /* index = ((pos1 & mask) << N) + (pos2 & mask); */
+ index = L_deposit_l(add1((((Word16) (pos1 & mask)) << N), ((Word16) (pos2 & mask))));
+ } else
+ {
+ /* ((pos2 & mask) << N) + (pos1 & mask); */
+ index = L_deposit_l(add1((((Word16) (pos2 & mask)) << N), ((Word16) (pos1 & mask))));
+ }
+ if ((pos1 & NB_POS) != 0)
+ {
+ tmp = (N << 1);
+ index = vo_L_add(index, (1L << tmp)); /* index += 1 << (2*N); */
+ }
+ } else
+ {
+ /* sign of 1st pulse != sign of 2th pulse */
+ if (vo_sub((Word16) (pos1 & mask), (Word16) (pos2 & mask)) <= 0)
+ {
+ /* index = ((pos2 & mask) << N) + (pos1 & mask); */
+ index = L_deposit_l(add1((((Word16) (pos2 & mask)) << N), ((Word16) (pos1 & mask))));
+ if ((pos2 & NB_POS) != 0)
+ {
+ tmp = (N << 1); /* index += 1 << (2*N); */
+ index = vo_L_add(index, (1L << tmp));
+ }
+ } else
+ {
+ /* index = ((pos1 & mask) << N) + (pos2 & mask); */
+ index = L_deposit_l(add1((((Word16) (pos1 & mask)) << N), ((Word16) (pos2 & mask))));
+ if ((pos1 & NB_POS) != 0)
+ {
+ tmp = (N << 1);
+ index = vo_L_add(index, (1 << tmp)); /* index += 1 << (2*N); */
+ }
+ }
+ }
+ return (index);
+}
+
+
+Word32 quant_3p_3N1( /* (o) return (3*N)+1 bits */
+ Word16 pos1, /* (i) position of the pulse 1 */
+ Word16 pos2, /* (i) position of the pulse 2 */
+ Word16 pos3, /* (i) position of the pulse 3 */
+ Word16 N) /* (i) number of bits for position */
+{
+ Word16 nb_pos;
+ Word32 index;
+
+ nb_pos =(1 <<(N - 1)); /* nb_pos = (1<<(N-1)); */
+ /*-------------------------------------------------------*
+ * Quantization of 3 pulses with 3*N+1 bits: *
+ *-------------------------------------------------------*/
+ if (((pos1 ^ pos2) & nb_pos) == 0)
+ {
+ index = quant_2p_2N1(pos1, pos2, sub(N, 1)); /* index = quant_2p_2N1(pos1, pos2, (N-1)); */
+ /* index += (pos1 & nb_pos) << N; */
+ index = vo_L_add(index, (L_deposit_l((Word16) (pos1 & nb_pos)) << N));
+ /* index += quant_1p_N1(pos3, N) << (2*N); */
+ index = vo_L_add(index, (quant_1p_N1(pos3, N)<<(N << 1)));
+
+ } else if (((pos1 ^ pos3) & nb_pos) == 0)
+ {
+ index = quant_2p_2N1(pos1, pos3, sub(N, 1)); /* index = quant_2p_2N1(pos1, pos3, (N-1)); */
+ index = vo_L_add(index, (L_deposit_l((Word16) (pos1 & nb_pos)) << N));
+ /* index += (pos1 & nb_pos) << N; */
+ index = vo_L_add(index, (quant_1p_N1(pos2, N) << (N << 1)));
+ /* index += quant_1p_N1(pos2, N) <<
+ * (2*N); */
+ } else
+ {
+ index = quant_2p_2N1(pos2, pos3, (N - 1)); /* index = quant_2p_2N1(pos2, pos3, (N-1)); */
+ /* index += (pos2 & nb_pos) << N; */
+ index = vo_L_add(index, (L_deposit_l((Word16) (pos2 & nb_pos)) << N));
+ /* index += quant_1p_N1(pos1, N) << (2*N); */
+ index = vo_L_add(index, (quant_1p_N1(pos1, N) << (N << 1)));
+ }
+ return (index);
+}
+
+
+Word32 quant_4p_4N1( /* (o) return (4*N)+1 bits */
+ Word16 pos1, /* (i) position of the pulse 1 */
+ Word16 pos2, /* (i) position of the pulse 2 */
+ Word16 pos3, /* (i) position of the pulse 3 */
+ Word16 pos4, /* (i) position of the pulse 4 */
+ Word16 N) /* (i) number of bits for position */
+{
+ Word16 nb_pos;
+ Word32 index;
+
+ nb_pos = 1 << (N - 1); /* nb_pos = (1<<(N-1)); */
+ /*-------------------------------------------------------*
+ * Quantization of 4 pulses with 4*N+1 bits: *
+ *-------------------------------------------------------*/
+ if (((pos1 ^ pos2) & nb_pos) == 0)
+ {
+ index = quant_2p_2N1(pos1, pos2, sub(N, 1)); /* index = quant_2p_2N1(pos1, pos2, (N-1)); */
+ /* index += (pos1 & nb_pos) << N; */
+ index = vo_L_add(index, (L_deposit_l((Word16) (pos1 & nb_pos)) << N));
+ /* index += quant_2p_2N1(pos3, pos4, N) << (2*N); */
+ index = vo_L_add(index, (quant_2p_2N1(pos3, pos4, N) << (N << 1)));
+ } else if (((pos1 ^ pos3) & nb_pos) == 0)
+ {
+ index = quant_2p_2N1(pos1, pos3, (N - 1));
+ /* index += (pos1 & nb_pos) << N; */
+ index = vo_L_add(index, (L_deposit_l((Word16) (pos1 & nb_pos)) << N));
+ /* index += quant_2p_2N1(pos2, pos4, N) << (2*N); */
+ index = vo_L_add(index, (quant_2p_2N1(pos2, pos4, N) << (N << 1)));
+ } else
+ {
+ index = quant_2p_2N1(pos2, pos3, (N - 1));
+ /* index += (pos2 & nb_pos) << N; */
+ index = vo_L_add(index, (L_deposit_l((Word16) (pos2 & nb_pos)) << N));
+ /* index += quant_2p_2N1(pos1, pos4, N) << (2*N); */
+ index = vo_L_add(index, (quant_2p_2N1(pos1, pos4, N) << (N << 1)));
+ }
+ return (index);
+}
+
+
+Word32 quant_4p_4N( /* (o) return 4*N bits */
+ Word16 pos[], /* (i) position of the pulse 1..4 */
+ Word16 N) /* (i) number of bits for position */
+{
+ Word16 nb_pos, mask UNUSED_VAR, n_1, tmp;
+ Word16 posA[4], posB[4];
+ Word32 i, j, k, index;
+
+ n_1 = (Word16) (N - 1);
+ nb_pos = (1 << n_1); /* nb_pos = (1<<n_1); */
+ mask = vo_sub((1 << N), 1); /* mask = ((1<<N)-1); */
+
+ i = 0;
+ j = 0;
+ for (k = 0; k < 4; k++)
+ {
+ if ((pos[k] & nb_pos) == 0)
+ {
+ posA[i++] = pos[k];
+ } else
+ {
+ posB[j++] = pos[k];
+ }
+ }
+
+ switch (i)
+ {
+ case 0:
+ tmp = vo_sub((N << 2), 3); /* index = 1 << ((4*N)-3); */
+ index = (1L << tmp);
+ /* index += quant_4p_4N1(posB[0], posB[1], posB[2], posB[3], n_1); */
+ index = vo_L_add(index, quant_4p_4N1(posB[0], posB[1], posB[2], posB[3], n_1));
+ break;
+ case 1:
+ /* index = quant_1p_N1(posA[0], n_1) << ((3*n_1)+1); */
+ tmp = add1((Word16)((vo_L_mult(3, n_1) >> 1)), 1);
+ index = L_shl(quant_1p_N1(posA[0], n_1), tmp);
+ /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1); */
+ index = vo_L_add(index, quant_3p_3N1(posB[0], posB[1], posB[2], n_1));
+ break;
+ case 2:
+ tmp = ((n_1 << 1) + 1); /* index = quant_2p_2N1(posA[0], posA[1], n_1) << ((2*n_1)+1); */
+ index = L_shl(quant_2p_2N1(posA[0], posA[1], n_1), tmp);
+ /* index += quant_2p_2N1(posB[0], posB[1], n_1); */
+ index = vo_L_add(index, quant_2p_2N1(posB[0], posB[1], n_1));
+ break;
+ case 3:
+ /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << N; */
+ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), N);
+ index = vo_L_add(index, quant_1p_N1(posB[0], n_1)); /* index += quant_1p_N1(posB[0], n_1); */
+ break;
+ case 4:
+ index = quant_4p_4N1(posA[0], posA[1], posA[2], posA[3], n_1);
+ break;
+ default:
+ index = 0;
+ fprintf(stderr, "Error in function quant_4p_4N\n");
+ }
+ tmp = ((N << 2) - 2); /* index += (i & 3) << ((4*N)-2); */
+ index = vo_L_add(index, L_shl((L_deposit_l(i) & (3L)), tmp));
+
+ return (index);
+}
+
+
+
+Word32 quant_5p_5N( /* (o) return 5*N bits */
+ Word16 pos[], /* (i) position of the pulse 1..5 */
+ Word16 N) /* (i) number of bits for position */
+{
+ Word16 nb_pos, n_1, tmp;
+ Word16 posA[5], posB[5];
+ Word32 i, j, k, index, tmp2;
+
+ n_1 = (Word16) (N - 1);
+ nb_pos = (1 << n_1); /* nb_pos = (1<<n_1); */
+
+ i = 0;
+ j = 0;
+ for (k = 0; k < 5; k++)
+ {
+ if ((pos[k] & nb_pos) == 0)
+ {
+ posA[i++] = pos[k];
+ } else
+ {
+ posB[j++] = pos[k];
+ }
+ }
+
+ switch (i)
+ {
+ case 0:
+ tmp = vo_sub((Word16)((vo_L_mult(5, N) >> 1)), 1); /* ((5*N)-1)) */
+ index = L_shl(1L, tmp); /* index = 1 << ((5*N)-1); */
+ tmp = add1((N << 1), 1); /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1) << ((2*N)+1);*/
+ tmp2 = L_shl(quant_3p_3N1(posB[0], posB[1], posB[2], n_1), tmp);
+ index = vo_L_add(index, tmp2);
+ index = vo_L_add(index, quant_2p_2N1(posB[3], posB[4], N)); /* index += quant_2p_2N1(posB[3], posB[4], N); */
+ break;
+ case 1:
+ tmp = vo_sub((Word16)((vo_L_mult(5, N) >> 1)), 1); /* index = 1 << ((5*N)-1); */
+ index = L_shl(1L, tmp);
+ tmp = add1((N << 1), 1); /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1) <<((2*N)+1); */
+ tmp2 = L_shl(quant_3p_3N1(posB[0], posB[1], posB[2], n_1), tmp);
+ index = vo_L_add(index, tmp2);
+ index = vo_L_add(index, quant_2p_2N1(posB[3], posA[0], N)); /* index += quant_2p_2N1(posB[3], posA[0], N); */
+ break;
+ case 2:
+ tmp = vo_sub((Word16)((vo_L_mult(5, N) >> 1)), 1); /* ((5*N)-1)) */
+ index = L_shl(1L, tmp); /* index = 1 << ((5*N)-1); */
+ tmp = add1((N << 1), 1); /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1) << ((2*N)+1); */
+ tmp2 = L_shl(quant_3p_3N1(posB[0], posB[1], posB[2], n_1), tmp);
+ index = vo_L_add(index, tmp2);
+ index = vo_L_add(index, quant_2p_2N1(posA[0], posA[1], N)); /* index += quant_2p_2N1(posA[0], posA[1], N); */
+ break;
+ case 3:
+ tmp = add1((N << 1), 1); /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << ((2*N)+1); */
+ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), tmp);
+ index = vo_L_add(index, quant_2p_2N1(posB[0], posB[1], N)); /* index += quant_2p_2N1(posB[0], posB[1], N); */
+ break;
+ case 4:
+ tmp = add1((N << 1), 1); /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << ((2*N)+1); */
+ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), tmp);
+ index = vo_L_add(index, quant_2p_2N1(posA[3], posB[0], N)); /* index += quant_2p_2N1(posA[3], posB[0], N); */
+ break;
+ case 5:
+ tmp = add1((N << 1), 1); /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << ((2*N)+1); */
+ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), tmp);
+ index = vo_L_add(index, quant_2p_2N1(posA[3], posA[4], N)); /* index += quant_2p_2N1(posA[3], posA[4], N); */
+ break;
+ default:
+ index = 0;
+ fprintf(stderr, "Error in function quant_5p_5N\n");
+ }
+
+ return (index);
+}
+
+
+Word32 quant_6p_6N_2( /* (o) return (6*N)-2 bits */
+ Word16 pos[], /* (i) position of the pulse 1..6 */
+ Word16 N) /* (i) number of bits for position */
+{
+ Word16 nb_pos, n_1;
+ Word16 posA[6], posB[6];
+ Word32 i, j, k, index;
+
+ /* !! N and n_1 are constants -> it doesn't need to be operated by Basic Operators */
+ n_1 = (Word16) (N - 1);
+ nb_pos = (1 << n_1); /* nb_pos = (1<<n_1); */
+
+ i = 0;
+ j = 0;
+ for (k = 0; k < 6; k++)
+ {
+ if ((pos[k] & nb_pos) == 0)
+ {
+ posA[i++] = pos[k];
+ } else
+ {
+ posB[j++] = pos[k];
+ }
+ }
+
+ switch (i)
+ {
+ case 0:
+ index = (1 << (Word16) (6 * N - 5)); /* index = 1 << ((6*N)-5); */
+ index = vo_L_add(index, (quant_5p_5N(posB, n_1) << N)); /* index += quant_5p_5N(posB, n_1) << N; */
+ index = vo_L_add(index, quant_1p_N1(posB[5], n_1)); /* index += quant_1p_N1(posB[5], n_1); */
+ break;
+ case 1:
+ index = (1L << (Word16) (6 * N - 5)); /* index = 1 << ((6*N)-5); */
+ index = vo_L_add(index, (quant_5p_5N(posB, n_1) << N)); /* index += quant_5p_5N(posB, n_1) << N; */
+ index = vo_L_add(index, quant_1p_N1(posA[0], n_1)); /* index += quant_1p_N1(posA[0], n_1); */
+ break;
+ case 2:
+ index = (1L << (Word16) (6 * N - 5)); /* index = 1 << ((6*N)-5); */
+ /* index += quant_4p_4N(posB, n_1) << ((2*n_1)+1); */
+ index = vo_L_add(index, (quant_4p_4N(posB, n_1) << (Word16) (2 * n_1 + 1)));
+ index = vo_L_add(index, quant_2p_2N1(posA[0], posA[1], n_1)); /* index += quant_2p_2N1(posA[0], posA[1], n_1); */
+ break;
+ case 3:
+ index = (quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << (Word16) (3 * n_1 + 1));
+ /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << ((3*n_1)+1); */
+ index =vo_L_add(index, quant_3p_3N1(posB[0], posB[1], posB[2], n_1));
+ /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1); */
+ break;
+ case 4:
+ i = 2;
+ index = (quant_4p_4N(posA, n_1) << (Word16) (2 * n_1 + 1)); /* index = quant_4p_4N(posA, n_1) << ((2*n_1)+1); */
+ index = vo_L_add(index, quant_2p_2N1(posB[0], posB[1], n_1)); /* index += quant_2p_2N1(posB[0], posB[1], n_1); */
+ break;
+ case 5:
+ i = 1;
+ index = (quant_5p_5N(posA, n_1) << N); /* index = quant_5p_5N(posA, n_1) << N; */
+ index = vo_L_add(index, quant_1p_N1(posB[0], n_1)); /* index += quant_1p_N1(posB[0], n_1); */
+ break;
+ case 6:
+ i = 0;
+ index = (quant_5p_5N(posA, n_1) << N); /* index = quant_5p_5N(posA, n_1) << N; */
+ index = vo_L_add(index, quant_1p_N1(posA[5], n_1)); /* index += quant_1p_N1(posA[5], n_1); */
+ break;
+ default:
+ index = 0;
+ fprintf(stderr, "Error in function quant_6p_6N_2\n");
+ }
+ index = vo_L_add(index, ((L_deposit_l(i) & 3L) << (Word16) (6 * N - 4))); /* index += (i & 3) << ((6*N)-4); */
+
+ return (index);
+}
+
+
diff --git a/media/codecs/amrwb/enc/src/qisf_ns.c b/media/codecs/amrwb/enc/src/qisf_ns.c
new file mode 100644
index 0000000..eac98e2
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/qisf_ns.c
@@ -0,0 +1,111 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***************************************************************************
+* File: qisf_ns.c *
+* *
+* Description: Coding/Decoding of ISF parameters for background noise.*
+* The ISF vector is quantized using VQ with split-by-5 *
+* *
+****************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "acelp.h"
+#include "qisf_ns.tab" /* Codebooks of ISFs */
+
+/*------------------------------------------------------------------*
+* routine: Qisf_ns() *
+* ~~~~~~~~~ *
+*------------------------------------------------------------------*/
+
+void Qisf_ns(
+ Word16 * isf1, /* input : ISF in the frequency domain (0..0.5) */
+ Word16 * isf_q, /* output: quantized ISF */
+ Word16 * indice /* output: quantization indices */
+ )
+{
+ Word16 i;
+ Word32 tmp;
+
+ for (i = 0; i < ORDER; i++)
+ {
+ isf_q[i] = sub(isf1[i], mean_isf_noise[i]);
+ }
+
+ indice[0] = Sub_VQ(&isf_q[0], dico1_isf_noise, 2, SIZE_BK_NOISE1, &tmp);
+ indice[1] = Sub_VQ(&isf_q[2], dico2_isf_noise, 3, SIZE_BK_NOISE2, &tmp);
+ indice[2] = Sub_VQ(&isf_q[5], dico3_isf_noise, 3, SIZE_BK_NOISE3, &tmp);
+ indice[3] = Sub_VQ(&isf_q[8], dico4_isf_noise, 4, SIZE_BK_NOISE4, &tmp);
+ indice[4] = Sub_VQ(&isf_q[12], dico5_isf_noise, 4, SIZE_BK_NOISE5, &tmp);
+
+ /* decoding the ISFs */
+
+ Disf_ns(indice, isf_q);
+
+ return;
+}
+
+/********************************************************************
+* Function: Disf_ns() *
+* ~~~~~~~~~ *
+* Decoding of ISF parameters *
+*-------------------------------------------------------------------*
+* Arguments: *
+* indice[] : indices of the selected codebook entries *
+* isf[] : quantized ISFs (in frequency domain) *
+*********************************************************************/
+
+void Disf_ns(
+ Word16 * indice, /* input: quantization indices */
+ Word16 * isf_q /* input : ISF in the frequency domain (0..0.5) */
+ )
+{
+ Word16 i;
+
+ for (i = 0; i < 2; i++)
+ {
+ isf_q[i] = dico1_isf_noise[indice[0] * 2 + i];
+ }
+ for (i = 0; i < 3; i++)
+ {
+ isf_q[i + 2] = dico2_isf_noise[indice[1] * 3 + i];
+ }
+ for (i = 0; i < 3; i++)
+ {
+ isf_q[i + 5] = dico3_isf_noise[indice[2] * 3 + i];
+ }
+ for (i = 0; i < 4; i++)
+ {
+ isf_q[i + 8] = dico4_isf_noise[indice[3] * 4 + i];
+ }
+ for (i = 0; i < 4; i++)
+ {
+ isf_q[i + 12] = dico5_isf_noise[indice[4] * 4 + i];
+ }
+
+ for (i = 0; i < ORDER; i++)
+ {
+ isf_q[i] = add(isf_q[i], mean_isf_noise[i]);
+ }
+
+ Reorder_isf(isf_q, ISF_GAP, ORDER);
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/qpisf_2s.c b/media/codecs/amrwb/enc/src/qpisf_2s.c
new file mode 100644
index 0000000..bec334e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/qpisf_2s.c
@@ -0,0 +1,542 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: apisf_2s.c *
+* *
+* Description: Coding/Decodeing of ISF parameters with predication
+* The ISF vector is quantized using two-stage VQ with split-by-2 *
+* in 1st stage and split-by-5(or 3) in the second stage *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "cnst.h"
+#include "acelp.h"
+#include "qpisf_2s.tab" /* Codebooks of isfs */
+
+#define MU 10923 /* Prediction factor (1.0/3.0) in Q15 */
+#define N_SURV_MAX 4 /* 4 survivors max */
+#define ALPHA 29491 /* 0. 9 in Q15 */
+#define ONE_ALPHA (32768-ALPHA) /* (1.0 - ALPHA) in Q15 */
+
+/* private functions */
+static void VQ_stage1(
+ Word16 * x, /* input : ISF residual vector */
+ Word16 * dico, /* input : quantization codebook */
+ Word16 dim, /* input : dimention of vector */
+ Word16 dico_size, /* input : size of quantization codebook */
+ Word16 * index, /* output: indices of survivors */
+ Word16 surv /* input : number of survivor */
+ );
+
+/**************************************************************************
+* Function: Qpisf_2s_46B() *
+* *
+* Description: Quantization of isf parameters with prediction. (46 bits) *
+* *
+* The isf vector is quantized using two-stage VQ with split-by-2 in *
+* 1st stage and split-by-5 in the second stage. *
+***************************************************************************/
+
+void Qpisf_2s_46b(
+ Word16 * isf1, /* (i) Q15 : ISF in the frequency domain (0..0.5) */
+ Word16 * isf_q, /* (o) Q15 : quantized ISF (0..0.5) */
+ Word16 * past_isfq, /* (io)Q15 : past ISF quantizer */
+ Word16 * indice, /* (o) : quantization indices */
+ Word16 nb_surv /* (i) : number of survivor (1, 2, 3 or 4) */
+ )
+{
+ Word16 tmp_ind[5];
+ Word16 surv1[N_SURV_MAX]; /* indices of survivors from 1st stage */
+ Word32 i, k, temp, min_err, distance;
+ Word16 isf[ORDER];
+ Word16 isf_stage2[ORDER];
+
+ for (i = 0; i < ORDER; i++)
+ {
+ isf[i] = vo_sub(isf1[i], mean_isf[i]);
+ isf[i] = vo_sub(isf[i], vo_mult(MU, past_isfq[i]));
+ }
+
+ VQ_stage1(&isf[0], dico1_isf, 9, SIZE_BK1, surv1, nb_surv);
+
+ distance = MAX_32;
+
+ for (k = 0; k < nb_surv; k++)
+ {
+ for (i = 0; i < 9; i++)
+ {
+ isf_stage2[i] = vo_sub(isf[i], dico1_isf[i + surv1[k] * 9]);
+ }
+ tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico21_isf, 3, SIZE_BK21, &min_err);
+ temp = min_err;
+ tmp_ind[1] = Sub_VQ(&isf_stage2[3], dico22_isf, 3, SIZE_BK22, &min_err);
+ temp = vo_L_add(temp, min_err);
+ tmp_ind[2] = Sub_VQ(&isf_stage2[6], dico23_isf, 3, SIZE_BK23, &min_err);
+ temp = vo_L_add(temp, min_err);
+
+ if(temp < distance)
+ {
+ distance = temp;
+ indice[0] = surv1[k];
+ for (i = 0; i < 3; i++)
+ {
+ indice[i + 2] = tmp_ind[i];
+ }
+ }
+ }
+
+
+ VQ_stage1(&isf[9], dico2_isf, 7, SIZE_BK2, surv1, nb_surv);
+
+ distance = MAX_32;
+
+ for (k = 0; k < nb_surv; k++)
+ {
+ for (i = 0; i < 7; i++)
+ {
+ isf_stage2[i] = vo_sub(isf[9 + i], dico2_isf[i + surv1[k] * 7]);
+ }
+
+ tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico24_isf, 3, SIZE_BK24, &min_err);
+ temp = min_err;
+ tmp_ind[1] = Sub_VQ(&isf_stage2[3], dico25_isf, 4, SIZE_BK25, &min_err);
+ temp = vo_L_add(temp, min_err);
+
+ if(temp < distance)
+ {
+ distance = temp;
+ indice[1] = surv1[k];
+ for (i = 0; i < 2; i++)
+ {
+ indice[i + 5] = tmp_ind[i];
+ }
+ }
+ }
+
+ Dpisf_2s_46b(indice, isf_q, past_isfq, isf_q, isf_q, 0, 0);
+
+ return;
+}
+
+/*****************************************************************************
+* Function: Qpisf_2s_36B() *
+* *
+* Description: Quantization of isf parameters with prediction. (36 bits) *
+* *
+* The isf vector is quantized using two-stage VQ with split-by-2 in *
+* 1st stage and split-by-3 in the second stage. *
+******************************************************************************/
+
+void Qpisf_2s_36b(
+ Word16 * isf1, /* (i) Q15 : ISF in the frequency domain (0..0.5) */
+ Word16 * isf_q, /* (o) Q15 : quantized ISF (0..0.5) */
+ Word16 * past_isfq, /* (io)Q15 : past ISF quantizer */
+ Word16 * indice, /* (o) : quantization indices */
+ Word16 nb_surv /* (i) : number of survivor (1, 2, 3 or 4) */
+ )
+{
+ Word16 i, k, tmp_ind[5];
+ Word16 surv1[N_SURV_MAX]; /* indices of survivors from 1st stage */
+ Word32 temp, min_err, distance;
+ Word16 isf[ORDER];
+ Word16 isf_stage2[ORDER];
+
+ for (i = 0; i < ORDER; i++)
+ {
+ isf[i] = vo_sub(isf1[i], mean_isf[i]);
+ isf[i] = vo_sub(isf[i], vo_mult(MU, past_isfq[i]));
+ }
+
+ VQ_stage1(&isf[0], dico1_isf, 9, SIZE_BK1, surv1, nb_surv);
+
+ distance = MAX_32;
+
+ for (k = 0; k < nb_surv; k++)
+ {
+ for (i = 0; i < 9; i++)
+ {
+ isf_stage2[i] = vo_sub(isf[i], dico1_isf[i + surv1[k] * 9]);
+ }
+
+ tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico21_isf_36b, 5, SIZE_BK21_36b, &min_err);
+ temp = min_err;
+ tmp_ind[1] = Sub_VQ(&isf_stage2[5], dico22_isf_36b, 4, SIZE_BK22_36b, &min_err);
+ temp = vo_L_add(temp, min_err);
+
+ if(temp < distance)
+ {
+ distance = temp;
+ indice[0] = surv1[k];
+ for (i = 0; i < 2; i++)
+ {
+ indice[i + 2] = tmp_ind[i];
+ }
+ }
+ }
+
+ VQ_stage1(&isf[9], dico2_isf, 7, SIZE_BK2, surv1, nb_surv);
+ distance = MAX_32;
+
+ for (k = 0; k < nb_surv; k++)
+ {
+ for (i = 0; i < 7; i++)
+ {
+ isf_stage2[i] = vo_sub(isf[9 + i], dico2_isf[i + surv1[k] * 7]);
+ }
+
+ tmp_ind[0] = Sub_VQ(&isf_stage2[0], dico23_isf_36b, 7, SIZE_BK23_36b, &min_err);
+ temp = min_err;
+
+ if(temp < distance)
+ {
+ distance = temp;
+ indice[1] = surv1[k];
+ indice[4] = tmp_ind[0];
+ }
+ }
+
+ Dpisf_2s_36b(indice, isf_q, past_isfq, isf_q, isf_q, 0, 0);
+
+ return;
+}
+
+/*********************************************************************
+* Function: Dpisf_2s_46b() *
+* *
+* Description: Decoding of ISF parameters *
+**********************************************************************/
+
+void Dpisf_2s_46b(
+ Word16 * indice, /* input: quantization indices */
+ Word16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ Word16 * past_isfq, /* i/0 : past ISF quantizer */
+ Word16 * isfold, /* input : past quantized ISF */
+ Word16 * isf_buf, /* input : isf buffer */
+ Word16 bfi, /* input : Bad frame indicator */
+ Word16 enc_dec
+ )
+{
+ Word16 ref_isf[M], tmp;
+ Word32 i, j, L_tmp;
+
+ if (bfi == 0) /* Good frame */
+ {
+ for (i = 0; i < 9; i++)
+ {
+ isf_q[i] = dico1_isf[indice[0] * 9 + i];
+ }
+ for (i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ isf_q[i] = add1(isf_q[i], dico21_isf[indice[2] * 3 + i]);
+ isf_q[i + 3] = add1(isf_q[i + 3], dico22_isf[indice[3] * 3 + i]);
+ isf_q[i + 6] = add1(isf_q[i + 6], dico23_isf[indice[4] * 3 + i]);
+ isf_q[i + 9] = add1(isf_q[i + 9], dico24_isf[indice[5] * 3 + i]);
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ isf_q[i + 12] = add1(isf_q[i + 12], dico25_isf[indice[6] * 4 + i]);
+ }
+
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = isf_q[i];
+ isf_q[i] = add1(tmp, mean_isf[i]);
+ isf_q[i] = add1(isf_q[i], vo_mult(MU, past_isfq[i]));
+ past_isfq[i] = tmp;
+ }
+
+ if (enc_dec)
+ {
+ for (i = 0; i < M; i++)
+ {
+ for (j = (L_MEANBUF - 1); j > 0; j--)
+ {
+ isf_buf[j * M + i] = isf_buf[(j - 1) * M + i];
+ }
+ isf_buf[i] = isf_q[i];
+ }
+ }
+ } else
+ { /* bad frame */
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = mean_isf[i] << 14;
+ for (j = 0; j < L_MEANBUF; j++)
+ {
+ L_tmp += (isf_buf[j * M + i] << 14);
+ }
+ ref_isf[i] = vo_round(L_tmp);
+ }
+
+ /* use the past ISFs slightly shifted towards their mean */
+ for (i = 0; i < ORDER; i++)
+ {
+ isf_q[i] = add1(vo_mult(ALPHA, isfold[i]), vo_mult(ONE_ALPHA, ref_isf[i]));
+ }
+
+ /* estimate past quantized residual to be used in next frame */
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = add1(ref_isf[i], vo_mult(past_isfq[i], MU)); /* predicted ISF */
+ past_isfq[i] = vo_sub(isf_q[i], tmp);
+ past_isfq[i] = (past_isfq[i] >> 1); /* past_isfq[i] *= 0.5 */
+ }
+ }
+
+ Reorder_isf(isf_q, ISF_GAP, ORDER);
+ return;
+}
+
+/*********************************************************************
+* Function: Disf_2s_36b() *
+* *
+* Description: Decoding of ISF parameters *
+*********************************************************************/
+
+void Dpisf_2s_36b(
+ Word16 * indice, /* input: quantization indices */
+ Word16 * isf_q, /* output: quantized ISF in frequency domain (0..0.5) */
+ Word16 * past_isfq, /* i/0 : past ISF quantizer */
+ Word16 * isfold, /* input : past quantized ISF */
+ Word16 * isf_buf, /* input : isf buffer */
+ Word16 bfi, /* input : Bad frame indicator */
+ Word16 enc_dec
+ )
+{
+ Word16 ref_isf[M], tmp;
+ Word32 i, j, L_tmp;
+
+ if (bfi == 0) /* Good frame */
+ {
+ for (i = 0; i < 9; i++)
+ {
+ isf_q[i] = dico1_isf[indice[0] * 9 + i];
+ }
+ for (i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
+ }
+
+ for (i = 0; i < 5; i++)
+ {
+ isf_q[i] = add1(isf_q[i], dico21_isf_36b[indice[2] * 5 + i]);
+ }
+ for (i = 0; i < 4; i++)
+ {
+ isf_q[i + 5] = add1(isf_q[i + 5], dico22_isf_36b[indice[3] * 4 + i]);
+ }
+ for (i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = add1(isf_q[i + 9], dico23_isf_36b[indice[4] * 7 + i]);
+ }
+
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = isf_q[i];
+ isf_q[i] = add1(tmp, mean_isf[i]);
+ isf_q[i] = add1(isf_q[i], vo_mult(MU, past_isfq[i]));
+ past_isfq[i] = tmp;
+ }
+
+
+ if (enc_dec)
+ {
+ for (i = 0; i < M; i++)
+ {
+ for (j = (L_MEANBUF - 1); j > 0; j--)
+ {
+ isf_buf[j * M + i] = isf_buf[(j - 1) * M + i];
+ }
+ isf_buf[i] = isf_q[i];
+ }
+ }
+ } else
+ { /* bad frame */
+ for (i = 0; i < M; i++)
+ {
+ L_tmp = (mean_isf[i] << 14);
+ for (j = 0; j < L_MEANBUF; j++)
+ {
+ L_tmp += (isf_buf[j * M + i] << 14);
+ }
+ ref_isf[i] = vo_round(L_tmp);
+ }
+
+ /* use the past ISFs slightly shifted towards their mean */
+ for (i = 0; i < ORDER; i++)
+ {
+ isf_q[i] = add1(vo_mult(ALPHA, isfold[i]), vo_mult(ONE_ALPHA, ref_isf[i]));
+ }
+
+ /* estimate past quantized residual to be used in next frame */
+ for (i = 0; i < ORDER; i++)
+ {
+ tmp = add1(ref_isf[i], vo_mult(past_isfq[i], MU)); /* predicted ISF */
+ past_isfq[i] = vo_sub(isf_q[i], tmp);
+ past_isfq[i] = past_isfq[i] >> 1; /* past_isfq[i] *= 0.5 */
+ }
+ }
+
+ Reorder_isf(isf_q, ISF_GAP, ORDER);
+
+ return;
+}
+
+
+/***************************************************************************
+* Function: Reorder_isf() *
+* *
+* Description: To make sure that the isfs are properly order and to *
+* keep a certain minimum distance between consecutive isfs. *
+*--------------------------------------------------------------------------*
+* Argument description in/out *
+* *
+* isf[] vector of isfs i/o *
+* min_dist minimum required distance i *
+* n LPC order i *
+****************************************************************************/
+
+void Reorder_isf(
+ Word16 * isf, /* (i/o) Q15: ISF in the frequency domain (0..0.5) */
+ Word16 min_dist, /* (i) Q15 : minimum distance to keep */
+ Word16 n /* (i) : number of ISF */
+ )
+{
+ Word32 i;
+ Word16 isf_min;
+
+ isf_min = min_dist;
+ for (i = 0; i < n - 1; i++)
+ {
+ if(isf[i] < isf_min)
+ {
+ isf[i] = isf_min;
+ }
+ isf_min = (isf[i] + min_dist);
+ }
+ return;
+}
+
+
+Word16 Sub_VQ( /* output: return quantization index */
+ Word16 * x, /* input : ISF residual vector */
+ Word16 * dico, /* input : quantization codebook */
+ Word16 dim, /* input : dimention of vector */
+ Word16 dico_size, /* input : size of quantization codebook */
+ Word32 * distance /* output: error of quantization */
+ )
+{
+ Word16 temp, *p_dico;
+ Word32 i, j, index;
+ Word32 dist_min, dist;
+
+ dist_min = MAX_32;
+ p_dico = dico;
+
+ index = 0;
+ for (i = 0; i < dico_size; i++)
+ {
+ dist = 0;
+
+ for (j = 0; j < dim; j++)
+ {
+ temp = x[j] - (*p_dico++);
+ dist += (temp * temp)<<1;
+ }
+
+ if(dist < dist_min)
+ {
+ dist_min = dist;
+ index = i;
+ }
+ }
+
+ *distance = dist_min;
+
+ /* Reading the selected vector */
+ p_dico = &dico[index * dim];
+ for (j = 0; j < dim; j++)
+ {
+ x[j] = *p_dico++;
+ }
+
+ return index;
+}
+
+
+static void VQ_stage1(
+ Word16 * x, /* input : ISF residual vector */
+ Word16 * dico, /* input : quantization codebook */
+ Word16 dim, /* input : dimention of vector */
+ Word16 dico_size, /* input : size of quantization codebook */
+ Word16 * index, /* output: indices of survivors */
+ Word16 surv /* input : number of survivor */
+ )
+{
+ Word16 temp, *p_dico;
+ Word32 i, j, k, l;
+ Word32 dist_min[N_SURV_MAX], dist;
+
+ dist_min[0] = MAX_32;
+ dist_min[1] = MAX_32;
+ dist_min[2] = MAX_32;
+ dist_min[3] = MAX_32;
+ index[0] = 0;
+ index[1] = 1;
+ index[2] = 2;
+ index[3] = 3;
+
+ p_dico = dico;
+
+ for (i = 0; i < dico_size; i++)
+ {
+ dist = 0;
+ for (j = 0; j < dim; j++)
+ {
+ temp = x[j] - (*p_dico++);
+ dist += (temp * temp)<<1;
+ }
+
+ for (k = 0; k < surv; k++)
+ {
+ if(dist < dist_min[k])
+ {
+ for (l = surv - 1; l > k; l--)
+ {
+ dist_min[l] = dist_min[l - 1];
+ index[l] = index[l - 1];
+ }
+ dist_min[k] = dist;
+ index[k] = i;
+ break;
+ }
+ }
+ }
+ return;
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/random.c b/media/codecs/amrwb/enc/src/random.c
new file mode 100644
index 0000000..758343c
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/random.c
@@ -0,0 +1,33 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: random.c *
+* *
+* Description: Signed 16 bits random generator *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+Word16 Random(Word16 * seed)
+{
+ /* static Word16 seed = 21845; */
+ *seed = (Word16)(L_add((L_mult(*seed, 31821) >> 1), 13849L));
+ return (*seed);
+}
+
diff --git a/media/codecs/amrwb/enc/src/residu.c b/media/codecs/amrwb/enc/src/residu.c
new file mode 100644
index 0000000..76d0e41
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/residu.c
@@ -0,0 +1,67 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: residu.c *
+* *
+* Description: Compute the LPC residual by filtering *
+* the input speech through A(z) *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+void Residu(
+ Word16 a[], /* (i) Q12 : prediction coefficients */
+ Word16 x[], /* (i) : speech (values x[-m..-1] are needed */
+ Word16 y[], /* (o) x2 : residual signal */
+ Word16 lg /* (i) : size of filtering */
+ )
+{
+ Word16 i,*p1, *p2;
+ Word32 s;
+ for (i = 0; i < lg; i++)
+ {
+ p1 = a;
+ p2 = &x[i];
+ s = vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1++), (*p2--));
+ s += vo_mult32((*p1), (*p2));
+
+ s = L_shl2(s, 5);
+ y[i] = extract_h(L_add(s, 0x8000));
+ }
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/scale.c b/media/codecs/amrwb/enc/src/scale.c
new file mode 100644
index 0000000..21458c8
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/scale.c
@@ -0,0 +1,57 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: scale.c *
+* *
+* Description: Scale signal to get maximum of dynamic *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+void Scale_sig(
+ Word16 x[], /* (i/o) : signal to scale */
+ Word16 lg, /* (i) : size of x[] */
+ Word16 exp /* (i) : exponent: x = round(x << exp) */
+ )
+{
+ Word32 i;
+ Word32 L_tmp;
+ if(exp > 0)
+ {
+ for (i = lg - 1 ; i >= 0; i--)
+ {
+ L_tmp = L_shl2(x[i], 16 + exp);
+ x[i] = extract_h(L_add(L_tmp, 0x8000));
+ }
+ }
+ else
+ {
+ exp = -exp;
+ for (i = lg - 1; i >= 0; i--)
+ {
+ L_tmp = x[i] << 16;
+ L_tmp >>= exp;
+ x[i] = (L_tmp + 0x8000)>>16;
+ }
+ }
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/stream.c b/media/codecs/amrwb/enc/src/stream.c
new file mode 100644
index 0000000..a39149e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/stream.c
@@ -0,0 +1,58 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: stream.c *
+* *
+* Description: VOME API Buffer Operator Implement Code *
+* *
+************************************************************************/
+
+#include "stream.h"
+
+void voAWB_InitFrameBuffer(FrameStream *stream)
+{
+ stream->set_ptr = NULL;
+ stream->frame_ptr_bk = stream->frame_ptr;
+ stream->set_len = 0;
+ stream->framebuffer_len = 0;
+ stream->frame_storelen = 0;
+}
+
+void voAWB_UpdateFrameBuffer(
+ FrameStream *stream,
+ VO_MEM_OPERATOR *pMemOP
+ )
+{
+ int len;
+ len = MIN(Frame_Maxsize - stream->frame_storelen, stream->set_len);
+ pMemOP->Copy(VO_INDEX_ENC_AMRWB, stream->frame_ptr_bk + stream->frame_storelen , stream->set_ptr, len);
+ stream->set_len -= len;
+ stream->set_ptr += len;
+ stream->framebuffer_len = stream->frame_storelen + len;
+ stream->frame_ptr = stream->frame_ptr_bk;
+ stream->used_len += len;
+}
+
+void voAWB_FlushFrameBuffer(FrameStream *stream)
+{
+ stream->set_ptr = NULL;
+ stream->frame_ptr_bk = stream->frame_ptr;
+ stream->set_len = 0;
+ stream->framebuffer_len = 0;
+ stream->frame_storelen = 0;
+}
+
diff --git a/media/codecs/amrwb/enc/src/syn_filt.c b/media/codecs/amrwb/enc/src/syn_filt.c
new file mode 100644
index 0000000..7eba12f
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/syn_filt.c
@@ -0,0 +1,164 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: syn_filt.c *
+* *
+* Description: Do the synthesis filtering 1/A(z) *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+#include "cnst.h"
+
+#define UNUSED(x) (void)(x)
+
+void Syn_filt(
+ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ Word16 x[], /* (i) : input signal */
+ Word16 y[], /* (o) : output signal */
+ Word16 lg, /* (i) : size of filtering */
+ Word16 mem[], /* (i/o) : memory associated with this filtering. */
+ Word16 update /* (i) : 0=no update, 1=update of memory. */
+ )
+{
+ Word32 i, a0;
+ Word16 y_buf[L_SUBFR16k + M16k];
+ Word32 L_tmp;
+ Word16 *yy, *p1, *p2;
+ yy = &y_buf[0];
+ /* copy initial filter states into synthesis buffer */
+ for (i = 0; i < 16; i++)
+ {
+ *yy++ = mem[i];
+ }
+ a0 = (a[0] >> 1); /* input / 2 */
+ /* Do the filtering. */
+ for (i = 0; i < lg; i++)
+ {
+ p1 = &a[1];
+ p2 = &yy[i-1];
+ L_tmp = vo_mult32(a0, x[i]);
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1++), (*p2--));
+ L_tmp -= vo_mult32((*p1), (*p2));
+
+ L_tmp = L_shl2(L_tmp, 4);
+ y[i] = yy[i] = extract_h(L_add(L_tmp, 0x8000));
+ }
+ /* Update memory if required */
+ if (update)
+ for (i = 0; i < 16; i++)
+ {
+ mem[i] = yy[lg - 16 + i];
+ }
+ return;
+}
+
+
+void Syn_filt_32(
+ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
+ Word16 m, /* (i) : order of LP filter */
+ Word16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
+ Word16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
+ Word16 sig_hi[], /* (o) /16 : synthesis high */
+ Word16 sig_lo[], /* (o) /16 : synthesis low */
+ Word16 lg /* (i) : size of filtering */
+ )
+{
+ Word32 i,a0;
+ Word32 L_tmp, L_tmp1;
+ Word16 *p1, *p2, *p3;
+ UNUSED(m);
+
+ a0 = a[0] >> (4 + Qnew); /* input / 16 and >>Qnew */
+ /* Do the filtering. */
+ for (i = 0; i < lg; i++)
+ {
+ L_tmp = 0;
+ L_tmp1 = 0;
+ p1 = a;
+ p2 = &sig_lo[i - 1];
+ p3 = &sig_hi[i - 1];
+
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+ L_tmp -= vo_mult32((*p2--), (*p1));
+ L_tmp1 -= vo_mult32((*p3--), (*p1++));
+
+ L_tmp = L_tmp >> 11;
+ L_tmp += vo_L_mult(exc[i], a0);
+
+ /* sig_hi = bit16 to bit31 of synthesis */
+ L_tmp = L_tmp - (L_tmp1<<1);
+
+ L_tmp = L_tmp >> 3; /* ai in Q12 */
+ sig_hi[i] = extract_h(L_tmp);
+
+ /* sig_lo = bit4 to bit15 of synthesis */
+ L_tmp >>= 4; /* 4 : sig_lo[i] >> 4 */
+ sig_lo[i] = (Word16)((L_tmp - (sig_hi[i] << 13)));
+ }
+
+ return;
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/updt_tar.c b/media/codecs/amrwb/enc/src/updt_tar.c
new file mode 100644
index 0000000..ba7c2ff
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/updt_tar.c
@@ -0,0 +1,50 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: updt_tar.c *
+* *
+* Description: Update the target vector for codebook search *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+void Updt_tar(
+ Word16 * x, /* (i) Q0 : old target (for pitch search) */
+ Word16 * x2, /* (o) Q0 : new target (for codebook search) */
+ Word16 * y, /* (i) Q0 : filtered adaptive codebook vector */
+ Word16 gain, /* (i) Q14 : adaptive codebook gain */
+ Word16 L /* (i) : subframe size */
+ )
+{
+ Word32 i;
+ Word32 L_tmp, L_tmp2;
+
+ for (i = 0; i < L; i++)
+ {
+ L_tmp = x[i] << 15;
+ L_tmp2 = L_mult(y[i], gain);
+ L_tmp = L_sub(L_tmp, L_tmp2);
+ x2[i] = extract_h(L_shl2(L_tmp, 1));
+ }
+
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/util.c b/media/codecs/amrwb/enc/src/util.c
new file mode 100644
index 0000000..374245f
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/util.c
@@ -0,0 +1,77 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: util.c *
+* *
+* Description: Reset and Copy buffer *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+/***********************************************************************
+* Function: Set_zero() *
+* Description: Set vector x[] to zero *
+************************************************************************/
+
+void Set_zero(
+ Word16 x[], /* (o) : vector to clear */
+ Word16 L /* (i) : length of vector */
+ )
+{
+ Word32 num = (Word32)L;
+ while (num > 0) {
+ *x++ = 0;
+ --num;
+ }
+}
+
+
+/*********************************************************************
+* Function: Copy() *
+* *
+* Description: Copy vector x[] to y[] *
+*********************************************************************/
+
+void Copy(
+ Word16 x[], /* (i) : input vector */
+ Word16 y[], /* (o) : output vector */
+ Word16 L /* (i) : vector length */
+ )
+{
+ Word32 temp1,temp2,num;
+ if (L <= 0) {
+ return;
+ }
+ if(L&1)
+ {
+ temp1 = *x++;
+ *y++ = temp1;
+ }
+ num = (Word32)(L>>1);
+ while (num > 0) {
+ temp1 = *x++;
+ temp2 = *x++;
+ *y++ = temp1;
+ *y++ = temp2;
+ --num;
+ }
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/src/voAMRWBEnc.c b/media/codecs/amrwb/enc/src/voAMRWBEnc.c
new file mode 100644
index 0000000..b908ff8
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/voAMRWBEnc.c
@@ -0,0 +1,1949 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: voAMRWBEnc.c *
+* *
+* Description: Performs the main encoder routine *
+* Fixed-point C simulation of AMR WB ACELP coding *
+* algorithm with 20 msspeech frames for *
+* wideband speech signals. *
+* *
+************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "math_op.h"
+#include "cnst.h"
+#include "acelp.h"
+#include "cod_main.h"
+#include "bits.h"
+#include "main.h"
+#include "voAMRWB.h"
+#include "mem_align.h"
+#include "cmnMemory.h"
+
+#define UNUSED(x) (void)(x)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* LPC interpolation coef {0.45, 0.8, 0.96, 1.0}; in Q15 */
+static Word16 interpol_frac[NB_SUBFR] = {14746, 26214, 31457, 32767};
+
+/* isp tables for initialization */
+static Word16 isp_init[M] =
+{
+ 32138, 30274, 27246, 23170, 18205, 12540, 6393, 0,
+ -6393, -12540, -18205, -23170, -27246, -30274, -32138, 1475
+};
+
+static Word16 isf_init[M] =
+{
+ 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192,
+ 9216, 10240, 11264, 12288, 13312, 14336, 15360, 3840
+};
+
+/* High Band encoding */
+static const Word16 HP_gain[16] =
+{
+ 3624, 4673, 5597, 6479, 7425, 8378, 9324, 10264,
+ 11210, 12206, 13391, 14844, 16770, 19655, 24289, 32728
+};
+
+/* Private function declaration */
+static Word16 synthesis(
+ Word16 Aq[], /* A(z) : quantized Az */
+ Word16 exc[], /* (i) : excitation at 12kHz */
+ Word16 Q_new, /* (i) : scaling performed on exc */
+ Word16 synth16k[], /* (o) : 16kHz synthesis signal */
+ Coder_State * st /* (i/o) : State structure */
+ );
+
+/* Codec some parameters initialization */
+void Reset_encoder(void *st, Word16 reset_all)
+{
+ Word16 i;
+ Coder_State *cod_state;
+ cod_state = (Coder_State *) st;
+ Set_zero(cod_state->old_exc, PIT_MAX + L_INTERPOL);
+ Set_zero(cod_state->mem_syn, M);
+ Set_zero(cod_state->past_isfq, M);
+ cod_state->mem_w0 = 0;
+ cod_state->tilt_code = 0;
+ cod_state->first_frame = 1;
+ Init_gp_clip(cod_state->gp_clip);
+ cod_state->L_gc_thres = 0;
+ if (reset_all != 0)
+ {
+ /* Static vectors to zero */
+ Set_zero(cod_state->old_speech, L_TOTAL - L_FRAME);
+ Set_zero(cod_state->old_wsp, (PIT_MAX / OPL_DECIM));
+ Set_zero(cod_state->mem_decim2, 3);
+ /* routines initialization */
+ Init_Decim_12k8(cod_state->mem_decim);
+ Init_HP50_12k8(cod_state->mem_sig_in);
+ Init_Levinson(cod_state->mem_levinson);
+ Init_Q_gain2(cod_state->qua_gain);
+ Init_Hp_wsp(cod_state->hp_wsp_mem);
+ /* isp initialization */
+ Copy(isp_init, cod_state->ispold, M);
+ Copy(isp_init, cod_state->ispold_q, M);
+ /* variable initialization */
+ cod_state->mem_preemph = 0;
+ cod_state->mem_wsp = 0;
+ cod_state->Q_old = 15;
+ cod_state->Q_max[0] = 15;
+ cod_state->Q_max[1] = 15;
+ cod_state->old_wsp_max = 0;
+ cod_state->old_wsp_shift = 0;
+ /* pitch ol initialization */
+ cod_state->old_T0_med = 40;
+ cod_state->ol_gain = 0;
+ cod_state->ada_w = 0;
+ cod_state->ol_wght_flg = 0;
+ for (i = 0; i < 5; i++)
+ {
+ cod_state->old_ol_lag[i] = 40;
+ }
+ Set_zero(cod_state->old_hp_wsp, (L_FRAME / 2) / OPL_DECIM + (PIT_MAX / OPL_DECIM));
+ Set_zero(cod_state->mem_syn_hf, M);
+ Set_zero(cod_state->mem_syn_hi, M);
+ Set_zero(cod_state->mem_syn_lo, M);
+ Init_HP50_12k8(cod_state->mem_sig_out);
+ Init_Filt_6k_7k(cod_state->mem_hf);
+ Init_HP400_12k8(cod_state->mem_hp400);
+ Copy(isf_init, cod_state->isfold, M);
+ cod_state->mem_deemph = 0;
+ cod_state->seed2 = 21845;
+ Init_Filt_6k_7k(cod_state->mem_hf2);
+ cod_state->gain_alpha = 32767;
+ cod_state->vad_hist = 0;
+ wb_vad_reset(cod_state->vadSt);
+ dtx_enc_reset(cod_state->dtx_encSt, isf_init);
+ }
+ return;
+}
+
+/*-----------------------------------------------------------------*
+* Funtion coder *
+* ~~~~~ *
+* ->Main coder routine. *
+* *
+*-----------------------------------------------------------------*/
+void coder(
+ Word16 * mode, /* input : used mode */
+ Word16 speech16k[], /* input : 320 new speech samples (at 16 kHz) */
+ Word16 prms[], /* output: output parameters */
+ Word16 * ser_size, /* output: bit rate of the used mode */
+ void *spe_state, /* i/o : State structure */
+ Word16 allow_dtx /* input : DTX ON/OFF */
+ )
+{
+ /* Coder states */
+ Coder_State *st;
+ /* Speech vector */
+ Word16 old_speech[L_TOTAL];
+ Word16 *new_speech, *speech, *p_window;
+
+ /* Weighted speech vector */
+ Word16 old_wsp[L_FRAME + (PIT_MAX / OPL_DECIM)];
+ Word16 *wsp;
+
+ /* Excitation vector */
+ Word16 old_exc[(L_FRAME + 1) + PIT_MAX + L_INTERPOL];
+ Word16 *exc;
+
+ /* LPC coefficients */
+ Word16 r_h[M + 1], r_l[M + 1]; /* Autocorrelations of windowed speech */
+ Word16 rc[M]; /* Reflection coefficients. */
+ Word16 Ap[M + 1]; /* A(z) with spectral expansion */
+ Word16 ispnew[M]; /* immittance spectral pairs at 4nd sfr */
+ Word16 ispnew_q[M]; /* quantized ISPs at 4nd subframe */
+ Word16 isf[M]; /* ISF (frequency domain) at 4nd sfr */
+ Word16 *p_A, *p_Aq; /* ptr to A(z) for the 4 subframes */
+ Word16 A[NB_SUBFR * (M + 1)]; /* A(z) unquantized for the 4 subframes */
+ Word16 Aq[NB_SUBFR * (M + 1)]; /* A(z) quantized for the 4 subframes */
+
+ /* Other vectors */
+ Word16 xn[L_SUBFR]; /* Target vector for pitch search */
+ Word16 xn2[L_SUBFR]; /* Target vector for codebook search */
+ Word16 dn[L_SUBFR]; /* Correlation between xn2 and h1 */
+ Word16 cn[L_SUBFR]; /* Target vector in residual domain */
+ Word16 h1[L_SUBFR]; /* Impulse response vector */
+ Word16 h2[L_SUBFR]; /* Impulse response vector */
+ Word16 code[L_SUBFR]; /* Fixed codebook excitation */
+ Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */
+ Word16 y2[L_SUBFR]; /* Filtered adaptive excitation */
+ Word16 error[M + L_SUBFR]; /* error of quantization */
+ Word16 synth[L_SUBFR]; /* 12.8kHz synthesis vector */
+ Word16 exc2[L_FRAME]; /* excitation vector */
+ Word16 buf[L_FRAME]; /* VAD buffer */
+
+ /* Scalars */
+ Word32 i, j, i_subfr, select, pit_flag, clip_gain, vad_flag;
+ Word16 codec_mode;
+ Word16 T_op, T_op2, T0, T0_min, T0_max, T0_frac, index;
+ Word16 gain_pit, gain_code, g_coeff[4], g_coeff2[4];
+ Word16 tmp, gain1, gain2, exp, Q_new, mu, shift, max;
+ Word16 voice_fac;
+ Word16 indice[8];
+ Word32 L_tmp, L_gain_code, L_max, L_tmp1;
+ Word16 code2[L_SUBFR]; /* Fixed codebook excitation */
+ Word16 stab_fac, fac, gain_code_lo;
+
+ Word16 corr_gain;
+ Word16 *vo_p0, *vo_p1, *vo_p2, *vo_p3;
+
+ st = (Coder_State *) spe_state;
+
+ *ser_size = nb_of_bits[*mode];
+ codec_mode = *mode;
+
+ /*--------------------------------------------------------------------------*
+ * Initialize pointers to speech vector. *
+ * *
+ * *
+ * |-------|-------|-------|-------|-------|-------| *
+ * past sp sf1 sf2 sf3 sf4 L_NEXT *
+ * <------- Total speech buffer (L_TOTAL) ------> *
+ * old_speech *
+ * <------- LPC analysis window (L_WINDOW) ------> *
+ * | <-- present frame (L_FRAME) ----> *
+ * p_window | <----- new speech (L_FRAME) ----> *
+ * | | *
+ * speech | *
+ * new_speech *
+ *--------------------------------------------------------------------------*/
+
+ new_speech = old_speech + L_TOTAL - L_FRAME - L_FILT; /* New speech */
+ speech = old_speech + L_TOTAL - L_FRAME - L_NEXT; /* Present frame */
+ p_window = old_speech + L_TOTAL - L_WINDOW;
+
+ exc = old_exc + PIT_MAX + L_INTERPOL;
+ wsp = old_wsp + (PIT_MAX / OPL_DECIM);
+
+ /* copy coder memory state into working space */
+ Copy(st->old_speech, old_speech, L_TOTAL - L_FRAME);
+ Copy(st->old_wsp, old_wsp, PIT_MAX / OPL_DECIM);
+ Copy(st->old_exc, old_exc, PIT_MAX + L_INTERPOL);
+
+ /*---------------------------------------------------------------*
+ * Down sampling signal from 16kHz to 12.8kHz *
+ * -> The signal is extended by L_FILT samples (padded to zero) *
+ * to avoid additional delay (L_FILT samples) in the coder. *
+ * The last L_FILT samples are approximated after decimation and *
+ * are used (and windowed) only in autocorrelations. *
+ *---------------------------------------------------------------*/
+
+ Decim_12k8(speech16k, L_FRAME16k, new_speech, st->mem_decim);
+
+ /* last L_FILT samples for autocorrelation window */
+ Copy(st->mem_decim, code, 2 * L_FILT16k);
+ Set_zero(error, L_FILT16k); /* set next sample to zero */
+ Decim_12k8(error, L_FILT16k, new_speech + L_FRAME, code);
+
+ /*---------------------------------------------------------------*
+ * Perform 50Hz HP filtering of input signal. *
+ *---------------------------------------------------------------*/
+
+ HP50_12k8(new_speech, L_FRAME, st->mem_sig_in);
+
+ /* last L_FILT samples for autocorrelation window */
+ Copy(st->mem_sig_in, code, 6);
+ HP50_12k8(new_speech + L_FRAME, L_FILT, code);
+
+ /*---------------------------------------------------------------*
+ * Perform fixed preemphasis through 1 - g z^-1 *
+ * Scale signal to get maximum of precision in filtering *
+ *---------------------------------------------------------------*/
+
+ mu = PREEMPH_FAC >> 1; /* Q15 --> Q14 */
+
+ /* get max of new preemphased samples (L_FRAME+L_FILT) */
+ L_tmp = new_speech[0] << 15;
+ L_tmp -= (st->mem_preemph * mu)<<1;
+ L_max = L_abs(L_tmp);
+
+ for (i = 1; i < L_FRAME + L_FILT; i++)
+ {
+ L_tmp = new_speech[i] << 15;
+ L_tmp -= (new_speech[i - 1] * mu)<<1;
+ L_tmp = L_abs(L_tmp);
+ if(L_tmp > L_max)
+ {
+ L_max = L_tmp;
+ }
+ }
+
+ /* get scaling factor for new and previous samples */
+ /* limit scaling to Q_MAX to keep dynamic for ringing in low signal */
+ /* limit scaling to Q_MAX also to avoid a[0]<1 in syn_filt_32 */
+ tmp = extract_h(L_max);
+ if (tmp == 0)
+ {
+ shift = Q_MAX;
+ } else
+ {
+ shift = norm_s(tmp) - 1;
+ if (shift < 0)
+ {
+ shift = 0;
+ }
+ if (shift > Q_MAX)
+ {
+ shift = Q_MAX;
+ }
+ }
+ Q_new = shift;
+ if (Q_new > st->Q_max[0])
+ {
+ Q_new = st->Q_max[0];
+ }
+ if (Q_new > st->Q_max[1])
+ {
+ Q_new = st->Q_max[1];
+ }
+ exp = (Q_new - st->Q_old);
+ st->Q_old = Q_new;
+ st->Q_max[1] = st->Q_max[0];
+ st->Q_max[0] = shift;
+
+ /* preemphasis with scaling (L_FRAME+L_FILT) */
+ tmp = new_speech[L_FRAME - 1];
+
+ for (i = L_FRAME + L_FILT - 1; i > 0; i--)
+ {
+ L_tmp = new_speech[i] << 15;
+ L_tmp -= (new_speech[i - 1] * mu)<<1;
+ L_tmp = (L_tmp << Q_new);
+ new_speech[i] = vo_round(L_tmp);
+ }
+
+ L_tmp = new_speech[0] << 15;
+ L_tmp -= (st->mem_preemph * mu)<<1;
+ L_tmp = (L_tmp << Q_new);
+ new_speech[0] = vo_round(L_tmp);
+
+ st->mem_preemph = tmp;
+
+ /* scale previous samples and memory */
+
+ Scale_sig(old_speech, L_TOTAL - L_FRAME - L_FILT, exp);
+ Scale_sig(old_exc, PIT_MAX + L_INTERPOL, exp);
+ Scale_sig(st->mem_syn, M, exp);
+ Scale_sig(st->mem_decim2, 3, exp);
+ Scale_sig(&(st->mem_wsp), 1, exp);
+ Scale_sig(&(st->mem_w0), 1, exp);
+
+ /*------------------------------------------------------------------------*
+ * Call VAD *
+ * Preemphesis scale down signal in low frequency and keep dynamic in HF.*
+ * Vad work slightly in futur (new_speech = speech + L_NEXT - L_FILT). *
+ *------------------------------------------------------------------------*/
+ Copy(new_speech, buf, L_FRAME);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Scale_sig_opt(buf, L_FRAME, 1 - Q_new);
+#else
+ Scale_sig(buf, L_FRAME, 1 - Q_new);
+#endif
+
+ vad_flag = wb_vad(st->vadSt, buf); /* Voice Activity Detection */
+ if (vad_flag == 0)
+ {
+ st->vad_hist = (st->vad_hist + 1);
+ } else
+ {
+ st->vad_hist = 0;
+ }
+
+ /* DTX processing */
+ if (allow_dtx != 0)
+ {
+ /* Note that mode may change here */
+ tx_dtx_handler(st->dtx_encSt, vad_flag, mode);
+ *ser_size = nb_of_bits[*mode];
+ }
+
+ if(*mode != MRDTX)
+ {
+ Parm_serial(vad_flag, 1, &prms);
+ }
+ /*------------------------------------------------------------------------*
+ * Perform LPC analysis *
+ * ~~~~~~~~~~~~~~~~~~~~ *
+ * - autocorrelation + lag windowing *
+ * - Levinson-durbin algorithm to find a[] *
+ * - convert a[] to isp[] *
+ * - convert isp[] to isf[] for quantization *
+ * - quantize and code the isf[] *
+ * - convert isf[] to isp[] for interpolation *
+ * - find the interpolated ISPs and convert to a[] for the 4 subframes *
+ *------------------------------------------------------------------------*/
+
+ /* LP analysis centered at 4nd subframe */
+ Autocorr(p_window, M, r_h, r_l); /* Autocorrelations */
+ Lag_window(r_h, r_l); /* Lag windowing */
+ Levinson(r_h, r_l, A, rc, st->mem_levinson); /* Levinson Durbin */
+ Az_isp(A, ispnew, st->ispold); /* From A(z) to ISP */
+
+ /* Find the interpolated ISPs and convert to a[] for all subframes */
+ Int_isp(st->ispold, ispnew, interpol_frac, A);
+
+ /* update ispold[] for the next frame */
+ Copy(ispnew, st->ispold, M);
+
+ /* Convert ISPs to frequency domain 0..6400 */
+ Isp_isf(ispnew, isf, M);
+
+ /* check resonance for pitch clipping algorithm */
+ Gp_clip_test_isf(isf, st->gp_clip);
+
+ /*----------------------------------------------------------------------*
+ * Perform PITCH_OL analysis *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * - Find the residual res[] for the whole speech frame *
+ * - Find the weighted input speech wsp[] for the whole speech frame *
+ * - scale wsp[] to avoid overflow in pitch estimation *
+ * - Find open loop pitch lag for whole speech frame *
+ *----------------------------------------------------------------------*/
+ p_A = A;
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ /* Weighting of LPC coefficients */
+ Weight_a(p_A, Ap, GAMMA1, M);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Residu_opt(Ap, &speech[i_subfr], &wsp[i_subfr], L_SUBFR);
+#else
+ Residu(Ap, &speech[i_subfr], &wsp[i_subfr], L_SUBFR);
+#endif
+
+ p_A += (M + 1);
+ }
+
+ Deemph2(wsp, TILT_FAC, L_FRAME, &(st->mem_wsp));
+
+ /* find maximum value on wsp[] for 12 bits scaling */
+ max = 0;
+ for (i = 0; i < L_FRAME; i++)
+ {
+ tmp = abs_s(wsp[i]);
+ if(tmp > max)
+ {
+ max = tmp;
+ }
+ }
+ tmp = st->old_wsp_max;
+ if(max > tmp)
+ {
+ tmp = max; /* tmp = max(wsp_max, old_wsp_max) */
+ }
+ st->old_wsp_max = max;
+
+ shift = norm_s(tmp) - 3;
+ if (shift > 0)
+ {
+ shift = 0; /* shift = 0..-3 */
+ }
+ /* decimation of wsp[] to search pitch in LF and to reduce complexity */
+ LP_Decim2(wsp, L_FRAME, st->mem_decim2);
+
+ /* scale wsp[] in 12 bits to avoid overflow */
+#ifdef ASM_OPT /* asm optimization branch */
+ Scale_sig_opt(wsp, L_FRAME / OPL_DECIM, shift);
+#else
+ Scale_sig(wsp, L_FRAME / OPL_DECIM, shift);
+#endif
+ /* scale old_wsp (warning: exp must be Q_new-Q_old) */
+ exp = exp + (shift - st->old_wsp_shift);
+ st->old_wsp_shift = shift;
+
+ Scale_sig(old_wsp, PIT_MAX / OPL_DECIM, exp);
+ Scale_sig(st->old_hp_wsp, PIT_MAX / OPL_DECIM, exp);
+
+ scale_mem_Hp_wsp(st->hp_wsp_mem, exp);
+
+ /* Find open loop pitch lag for whole speech frame */
+
+ if(*ser_size == NBBITS_7k)
+ {
+ /* Find open loop pitch lag for whole speech frame */
+ T_op = Pitch_med_ol(wsp, st, L_FRAME / OPL_DECIM);
+ } else
+ {
+ /* Find open loop pitch lag for first 1/2 frame */
+ T_op = Pitch_med_ol(wsp, st, (L_FRAME/2) / OPL_DECIM);
+ }
+
+ if(st->ol_gain > 19661) /* 0.6 in Q15 */
+ {
+ st->old_T0_med = Med_olag(T_op, st->old_ol_lag);
+ st->ada_w = 32767;
+ } else
+ {
+ st->ada_w = vo_mult(st->ada_w, 29491);
+ }
+
+ if(st->ada_w < 26214)
+ st->ol_wght_flg = 0;
+ else
+ st->ol_wght_flg = 1;
+
+ wb_vad_tone_detection(st->vadSt, st->ol_gain);
+ T_op *= OPL_DECIM;
+
+ if(*ser_size != NBBITS_7k)
+ {
+ /* Find open loop pitch lag for second 1/2 frame */
+ T_op2 = Pitch_med_ol(wsp + ((L_FRAME / 2) / OPL_DECIM), st, (L_FRAME/2) / OPL_DECIM);
+
+ if(st->ol_gain > 19661) /* 0.6 in Q15 */
+ {
+ st->old_T0_med = Med_olag(T_op2, st->old_ol_lag);
+ st->ada_w = 32767;
+ } else
+ {
+ st->ada_w = mult(st->ada_w, 29491);
+ }
+
+ if(st->ada_w < 26214)
+ st->ol_wght_flg = 0;
+ else
+ st->ol_wght_flg = 1;
+
+ wb_vad_tone_detection(st->vadSt, st->ol_gain);
+
+ T_op2 *= OPL_DECIM;
+
+ } else
+ {
+ T_op2 = T_op;
+ }
+ /*----------------------------------------------------------------------*
+ * DTX-CNG *
+ *----------------------------------------------------------------------*/
+ if(*mode == MRDTX) /* CNG mode */
+ {
+ /* Buffer isf's and energy */
+#ifdef ASM_OPT /* asm optimization branch */
+ Residu_opt(&A[3 * (M + 1)], speech, exc, L_FRAME);
+#else
+ Residu(&A[3 * (M + 1)], speech, exc, L_FRAME);
+#endif
+
+ for (i = 0; i < L_FRAME; i++)
+ {
+ exc2[i] = shr(exc[i], Q_new);
+ }
+
+ L_tmp = 0;
+ for (i = 0; i < L_FRAME; i++)
+ L_tmp += (exc2[i] * exc2[i])<<1;
+
+ L_tmp >>= 1;
+
+ dtx_buffer(st->dtx_encSt, isf, L_tmp, codec_mode);
+
+ /* Quantize and code the ISFs */
+ dtx_enc(st->dtx_encSt, isf, exc2, &prms);
+
+ /* Convert ISFs to the cosine domain */
+ Isf_isp(isf, ispnew_q, M);
+ Isp_Az(ispnew_q, Aq, M, 0);
+
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ corr_gain = synthesis(Aq, &exc2[i_subfr], 0, &speech16k[i_subfr * 5 / 4], st);
+ }
+ Copy(isf, st->isfold, M);
+
+ /* reset speech coder memories */
+ Reset_encoder(st, 0);
+
+ /*--------------------------------------------------*
+ * Update signal for next frame. *
+ * -> save past of speech[] and wsp[]. *
+ *--------------------------------------------------*/
+
+ Copy(&old_speech[L_FRAME], st->old_speech, L_TOTAL - L_FRAME);
+ Copy(&old_wsp[L_FRAME / OPL_DECIM], st->old_wsp, PIT_MAX / OPL_DECIM);
+
+ return;
+ }
+ /*----------------------------------------------------------------------*
+ * ACELP *
+ *----------------------------------------------------------------------*/
+
+ /* Quantize and code the ISFs */
+
+ if (*ser_size <= NBBITS_7k)
+ {
+ Qpisf_2s_36b(isf, isf, st->past_isfq, indice, 4);
+
+ Parm_serial(indice[0], 8, &prms);
+ Parm_serial(indice[1], 8, &prms);
+ Parm_serial(indice[2], 7, &prms);
+ Parm_serial(indice[3], 7, &prms);
+ Parm_serial(indice[4], 6, &prms);
+ } else
+ {
+ Qpisf_2s_46b(isf, isf, st->past_isfq, indice, 4);
+
+ Parm_serial(indice[0], 8, &prms);
+ Parm_serial(indice[1], 8, &prms);
+ Parm_serial(indice[2], 6, &prms);
+ Parm_serial(indice[3], 7, &prms);
+ Parm_serial(indice[4], 7, &prms);
+ Parm_serial(indice[5], 5, &prms);
+ Parm_serial(indice[6], 5, &prms);
+ }
+
+ /* Check stability on isf : distance between old isf and current isf */
+
+ L_tmp = 0;
+ for (i = 0; i < M - 1; i++)
+ {
+ tmp = vo_sub(isf[i], st->isfold[i]);
+ L_tmp += (tmp * tmp)<<1;
+ }
+
+ tmp = extract_h(L_shl2(L_tmp, 8));
+
+ tmp = vo_mult(tmp, 26214); /* tmp = L_tmp*0.8/256 */
+ tmp = vo_sub(20480, tmp); /* 1.25 - tmp (in Q14) */
+
+ stab_fac = shl(tmp, 1);
+
+ if (stab_fac < 0)
+ {
+ stab_fac = 0;
+ }
+ Copy(isf, st->isfold, M);
+
+ /* Convert ISFs to the cosine domain */
+ Isf_isp(isf, ispnew_q, M);
+
+ if (st->first_frame != 0)
+ {
+ st->first_frame = 0;
+ Copy(ispnew_q, st->ispold_q, M);
+ }
+ /* Find the interpolated ISPs and convert to a[] for all subframes */
+
+ Int_isp(st->ispold_q, ispnew_q, interpol_frac, Aq);
+
+ /* update ispold[] for the next frame */
+ Copy(ispnew_q, st->ispold_q, M);
+
+ p_Aq = Aq;
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+#ifdef ASM_OPT /* asm optimization branch */
+ Residu_opt(p_Aq, &speech[i_subfr], &exc[i_subfr], L_SUBFR);
+#else
+ Residu(p_Aq, &speech[i_subfr], &exc[i_subfr], L_SUBFR);
+#endif
+ p_Aq += (M + 1);
+ }
+
+ /* Buffer isf's and energy for dtx on non-speech frame */
+ if (vad_flag == 0)
+ {
+ for (i = 0; i < L_FRAME; i++)
+ {
+ exc2[i] = exc[i] >> Q_new;
+ }
+ L_tmp = 0;
+ for (i = 0; i < L_FRAME; i++) {
+ Word32 tmp = L_mult(exc2[i], exc2[i]); // (exc2[i] * exc2[i])<<1;
+ L_tmp = L_add(L_tmp, tmp);
+ }
+ L_tmp >>= 1;
+
+ dtx_buffer(st->dtx_encSt, isf, L_tmp, codec_mode);
+ }
+ /* range for closed loop pitch search in 1st subframe */
+
+ T0_min = T_op - 8;
+ if (T0_min < PIT_MIN)
+ {
+ T0_min = PIT_MIN;
+ }
+ T0_max = (T0_min + 15);
+
+ if(T0_max > PIT_MAX)
+ {
+ T0_max = PIT_MAX;
+ T0_min = T0_max - 15;
+ }
+ /*------------------------------------------------------------------------*
+ * Loop for every subframe in the analysis frame *
+ *------------------------------------------------------------------------*
+ * To find the pitch and innovation parameters. The subframe size is *
+ * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. *
+ * - compute the target signal for pitch search *
+ * - compute impulse response of weighted synthesis filter (h1[]) *
+ * - find the closed-loop pitch parameters *
+ * - encode the pitch dealy *
+ * - find 2 lt prediction (with / without LP filter for lt pred) *
+ * - find 2 pitch gains and choose the best lt prediction. *
+ * - find target vector for codebook search *
+ * - update the impulse response h1[] for codebook search *
+ * - correlation between target vector and impulse response *
+ * - codebook search and encoding *
+ * - VQ of pitch and codebook gains *
+ * - find voicing factor and tilt of code for next subframe. *
+ * - update states of weighting filter *
+ * - find excitation and synthesis speech *
+ *------------------------------------------------------------------------*/
+ p_A = A;
+ p_Aq = Aq;
+ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
+ {
+ pit_flag = i_subfr;
+ if ((i_subfr == 2 * L_SUBFR) && (*ser_size > NBBITS_7k))
+ {
+ pit_flag = 0;
+ /* range for closed loop pitch search in 3rd subframe */
+ T0_min = (T_op2 - 8);
+
+ if (T0_min < PIT_MIN)
+ {
+ T0_min = PIT_MIN;
+ }
+ T0_max = (T0_min + 15);
+ if (T0_max > PIT_MAX)
+ {
+ T0_max = PIT_MAX;
+ T0_min = (T0_max - 15);
+ }
+ }
+ /*-----------------------------------------------------------------------*
+ * *
+ * Find the target vector for pitch search: *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+ * *
+ * |------| res[n] *
+ * speech[n]---| A(z) |-------- *
+ * |------| | |--------| error[n] |------| *
+ * zero -- (-)--| 1/A(z) |-----------| W(z) |-- target *
+ * exc |--------| |------| *
+ * *
+ * Instead of subtracting the zero-input response of filters from *
+ * the weighted input speech, the above configuration is used to *
+ * compute the target vector. *
+ * *
+ *-----------------------------------------------------------------------*/
+
+ for (i = 0; i < M; i++)
+ {
+ error[i] = vo_sub(speech[i + i_subfr - M], st->mem_syn[i]);
+ }
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Residu_opt(p_Aq, &speech[i_subfr], &exc[i_subfr], L_SUBFR);
+#else
+ Residu(p_Aq, &speech[i_subfr], &exc[i_subfr], L_SUBFR);
+#endif
+ Syn_filt(p_Aq, &exc[i_subfr], error + M, L_SUBFR, error, 0);
+ Weight_a(p_A, Ap, GAMMA1, M);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Residu_opt(Ap, error + M, xn, L_SUBFR);
+#else
+ Residu(Ap, error + M, xn, L_SUBFR);
+#endif
+ Deemph2(xn, TILT_FAC, L_SUBFR, &(st->mem_w0));
+
+ /*----------------------------------------------------------------------*
+ * Find approx. target in residual domain "cn[]" for inovation search. *
+ *----------------------------------------------------------------------*/
+ /* first half: xn[] --> cn[] */
+ Set_zero(code, M);
+ Copy(xn, code + M, L_SUBFR / 2);
+ tmp = 0;
+ Preemph2(code + M, TILT_FAC, L_SUBFR / 2, &tmp);
+ Weight_a(p_A, Ap, GAMMA1, M);
+ Syn_filt(Ap,code + M, code + M, L_SUBFR / 2, code, 0);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Residu_opt(p_Aq,code + M, cn, L_SUBFR / 2);
+#else
+ Residu(p_Aq,code + M, cn, L_SUBFR / 2);
+#endif
+
+ /* second half: res[] --> cn[] (approximated and faster) */
+ Copy(&exc[i_subfr + (L_SUBFR / 2)], cn + (L_SUBFR / 2), L_SUBFR / 2);
+
+ /*---------------------------------------------------------------*
+ * Compute impulse response, h1[], of weighted synthesis filter *
+ *---------------------------------------------------------------*/
+
+ Set_zero(error, M + L_SUBFR);
+ Weight_a(p_A, error + M, GAMMA1, M);
+
+ vo_p0 = error+M;
+ vo_p3 = h1;
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ L_tmp = *vo_p0 << 14; /* x4 (Q12 to Q14) */
+ vo_p1 = p_Aq + 1;
+ vo_p2 = vo_p0-1;
+ for (j = 1; j <= M/4; j++)
+ {
+ L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
+ L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
+ L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
+ L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
+ }
+ *vo_p3++ = *vo_p0++ = vo_round((L_tmp <<4));
+ }
+ /* deemph without division by 2 -> Q14 to Q15 */
+ tmp = 0;
+ Deemph2(h1, TILT_FAC, L_SUBFR, &tmp); /* h1 in Q14 */
+
+ /* h2 in Q12 for codebook search */
+ Copy(h1, h2, L_SUBFR);
+
+ /*---------------------------------------------------------------*
+ * scale xn[] and h1[] to avoid overflow in dot_product12() *
+ *---------------------------------------------------------------*/
+#ifdef ASM_OPT /* asm optimization branch */
+ Scale_sig_opt(h2, L_SUBFR, -2);
+ Scale_sig_opt(xn, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */
+ Scale_sig_opt(h1, L_SUBFR, 1 + shift); /* set h1[] in Q15 with scaling for convolution */
+#else
+ Scale_sig(h2, L_SUBFR, -2);
+ Scale_sig(xn, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */
+ Scale_sig(h1, L_SUBFR, 1 + shift); /* set h1[] in Q15 with scaling for convolution */
+#endif
+ /*----------------------------------------------------------------------*
+ * Closed-loop fractional pitch search *
+ *----------------------------------------------------------------------*/
+ /* find closed loop fractional pitch lag */
+ if(*ser_size <= NBBITS_9k)
+ {
+ T0 = Pitch_fr4(&exc[i_subfr], xn, h1, T0_min, T0_max, &T0_frac,
+ pit_flag, PIT_MIN, PIT_FR1_8b, L_SUBFR);
+
+ /* encode pitch lag */
+ if (pit_flag == 0) /* if 1st/3rd subframe */
+ {
+ /*--------------------------------------------------------------*
+ * The pitch range for the 1st/3rd subframe is encoded with *
+ * 8 bits and is divided as follows: *
+ * PIT_MIN to PIT_FR1-1 resolution 1/2 (frac = 0 or 2) *
+ * PIT_FR1 to PIT_MAX resolution 1 (frac = 0) *
+ *--------------------------------------------------------------*/
+ if (T0 < PIT_FR1_8b)
+ {
+ index = ((T0 << 1) + (T0_frac >> 1) - (PIT_MIN<<1));
+ } else
+ {
+ index = ((T0 - PIT_FR1_8b) + ((PIT_FR1_8b - PIT_MIN)*2));
+ }
+
+ Parm_serial(index, 8, &prms);
+
+ /* find T0_min and T0_max for subframe 2 and 4 */
+ T0_min = (T0 - 8);
+ if (T0_min < PIT_MIN)
+ {
+ T0_min = PIT_MIN;
+ }
+ T0_max = T0_min + 15;
+ if (T0_max > PIT_MAX)
+ {
+ T0_max = PIT_MAX;
+ T0_min = (T0_max - 15);
+ }
+ } else
+ { /* if subframe 2 or 4 */
+ /*--------------------------------------------------------------*
+ * The pitch range for subframe 2 or 4 is encoded with 5 bits: *
+ * T0_min to T0_max resolution 1/2 (frac = 0 or 2) *
+ *--------------------------------------------------------------*/
+ i = (T0 - T0_min);
+ index = (i << 1) + (T0_frac >> 1);
+
+ Parm_serial(index, 5, &prms);
+ }
+ } else
+ {
+ T0 = Pitch_fr4(&exc[i_subfr], xn, h1, T0_min, T0_max, &T0_frac,
+ pit_flag, PIT_FR2, PIT_FR1_9b, L_SUBFR);
+
+ /* encode pitch lag */
+ if (pit_flag == 0) /* if 1st/3rd subframe */
+ {
+ /*--------------------------------------------------------------*
+ * The pitch range for the 1st/3rd subframe is encoded with *
+ * 9 bits and is divided as follows: *
+ * PIT_MIN to PIT_FR2-1 resolution 1/4 (frac = 0,1,2 or 3) *
+ * PIT_FR2 to PIT_FR1-1 resolution 1/2 (frac = 0 or 1) *
+ * PIT_FR1 to PIT_MAX resolution 1 (frac = 0) *
+ *--------------------------------------------------------------*/
+
+ if (T0 < PIT_FR2)
+ {
+ index = ((T0 << 2) + T0_frac) - (PIT_MIN << 2);
+ } else if(T0 < PIT_FR1_9b)
+ {
+ index = ((((T0 << 1) + (T0_frac >> 1)) - (PIT_FR2<<1)) + ((PIT_FR2 - PIT_MIN)<<2));
+ } else
+ {
+ index = (((T0 - PIT_FR1_9b) + ((PIT_FR2 - PIT_MIN)<<2)) + ((PIT_FR1_9b - PIT_FR2)<<1));
+ }
+
+ Parm_serial(index, 9, &prms);
+
+ /* find T0_min and T0_max for subframe 2 and 4 */
+
+ T0_min = (T0 - 8);
+ if (T0_min < PIT_MIN)
+ {
+ T0_min = PIT_MIN;
+ }
+ T0_max = T0_min + 15;
+
+ if (T0_max > PIT_MAX)
+ {
+ T0_max = PIT_MAX;
+ T0_min = (T0_max - 15);
+ }
+ } else
+ { /* if subframe 2 or 4 */
+ /*--------------------------------------------------------------*
+ * The pitch range for subframe 2 or 4 is encoded with 6 bits: *
+ * T0_min to T0_max resolution 1/4 (frac = 0,1,2 or 3) *
+ *--------------------------------------------------------------*/
+ i = (T0 - T0_min);
+ index = (i << 2) + T0_frac;
+ Parm_serial(index, 6, &prms);
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Gain clipping test to avoid unstable synthesis on frame erasure *
+ *-----------------------------------------------------------------*/
+
+ clip_gain = 0;
+ if((st->gp_clip[0] < 154) && (st->gp_clip[1] > 14746))
+ clip_gain = 1;
+
+ /*-----------------------------------------------------------------*
+ * - find unity gain pitch excitation (adaptive codebook entry) *
+ * with fractional interpolation. *
+ * - find filtered pitch exc. y1[]=exc[] convolved with h1[]) *
+ * - compute pitch gain1 *
+ *-----------------------------------------------------------------*/
+ /* find pitch exitation */
+#ifdef ASM_OPT /* asm optimization branch */
+ pred_lt4_asm(&exc[i_subfr], T0, T0_frac, L_SUBFR + 1);
+#else
+ Pred_lt4(&exc[i_subfr], T0, T0_frac, L_SUBFR + 1);
+#endif
+ if (*ser_size > NBBITS_9k)
+ {
+#ifdef ASM_OPT /* asm optimization branch */
+ Convolve_asm(&exc[i_subfr], h1, y1, L_SUBFR);
+#else
+ Convolve(&exc[i_subfr], h1, y1, L_SUBFR);
+#endif
+ gain1 = G_pitch(xn, y1, g_coeff, L_SUBFR);
+ /* clip gain if necessary to avoid problem at decoder */
+ if ((clip_gain != 0) && (gain1 > GP_CLIP))
+ {
+ gain1 = GP_CLIP;
+ }
+ /* find energy of new target xn2[] */
+ Updt_tar(xn, dn, y1, gain1, L_SUBFR); /* dn used temporary */
+ } else
+ {
+ gain1 = 0;
+ }
+ /*-----------------------------------------------------------------*
+ * - find pitch excitation filtered by 1st order LP filter. *
+ * - find filtered pitch exc. y2[]=exc[] convolved with h1[]) *
+ * - compute pitch gain2 *
+ *-----------------------------------------------------------------*/
+ /* find pitch excitation with lp filter */
+ vo_p0 = exc + i_subfr-1;
+ vo_p1 = code;
+ /* find pitch excitation with lp filter */
+ for (i = 0; i < L_SUBFR/2; i++)
+ {
+ L_tmp = 5898 * *vo_p0++;
+ L_tmp1 = 5898 * *vo_p0;
+ L_tmp += 20972 * *vo_p0++;
+ L_tmp1 += 20972 * *vo_p0++;
+ L_tmp1 += 5898 * *vo_p0--;
+ L_tmp += 5898 * *vo_p0;
+ *vo_p1++ = (L_tmp + 0x4000)>>15;
+ *vo_p1++ = (L_tmp1 + 0x4000)>>15;
+ }
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Convolve_asm(code, h1, y2, L_SUBFR);
+#else
+ Convolve(code, h1, y2, L_SUBFR);
+#endif
+
+ gain2 = G_pitch(xn, y2, g_coeff2, L_SUBFR);
+
+ /* clip gain if necessary to avoid problem at decoder */
+ if ((clip_gain != 0) && (gain2 > GP_CLIP))
+ {
+ gain2 = GP_CLIP;
+ }
+ /* find energy of new target xn2[] */
+ Updt_tar(xn, xn2, y2, gain2, L_SUBFR);
+ /*-----------------------------------------------------------------*
+ * use the best prediction (minimise quadratic error). *
+ *-----------------------------------------------------------------*/
+ select = 0;
+ if(*ser_size > NBBITS_9k)
+ {
+ L_tmp = 0L;
+ vo_p0 = dn;
+ vo_p1 = xn2;
+ for (i = 0; i < L_SUBFR/2; i++)
+ {
+ L_tmp = L_add(L_tmp, *vo_p0 * *vo_p0);
+ vo_p0++;
+ L_tmp = L_sub(L_tmp, *vo_p1 * *vo_p1);
+ vo_p1++;
+ L_tmp = L_add(L_tmp, *vo_p0 * *vo_p0);
+ vo_p0++;
+ L_tmp = L_sub(L_tmp, *vo_p1 * *vo_p1);
+ vo_p1++;
+ }
+
+ if (L_tmp <= 0)
+ {
+ select = 1;
+ }
+ Parm_serial(select, 1, &prms);
+ }
+ if (select == 0)
+ {
+ /* use the lp filter for pitch excitation prediction */
+ gain_pit = gain2;
+ Copy(code, &exc[i_subfr], L_SUBFR);
+ Copy(y2, y1, L_SUBFR);
+ Copy(g_coeff2, g_coeff, 4);
+ } else
+ {
+ /* no filter used for pitch excitation prediction */
+ gain_pit = gain1;
+ Copy(dn, xn2, L_SUBFR); /* target vector for codebook search */
+ }
+ /*-----------------------------------------------------------------*
+ * - update cn[] for codebook search *
+ *-----------------------------------------------------------------*/
+ Updt_tar(cn, cn, &exc[i_subfr], gain_pit, L_SUBFR);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Scale_sig_opt(cn, L_SUBFR, shift); /* scaling of cn[] to limit dynamic at 12 bits */
+#else
+ Scale_sig(cn, L_SUBFR, shift); /* scaling of cn[] to limit dynamic at 12 bits */
+#endif
+ /*-----------------------------------------------------------------*
+ * - include fixed-gain pitch contribution into impulse resp. h1[] *
+ *-----------------------------------------------------------------*/
+ tmp = 0;
+ Preemph(h2, st->tilt_code, L_SUBFR, &tmp);
+
+ if (T0_frac > 2)
+ T0 = (T0 + 1);
+ Pit_shrp(h2, T0, PIT_SHARP, L_SUBFR);
+ /*-----------------------------------------------------------------*
+ * - Correlation between target xn2[] and impulse response h1[] *
+ * - Innovative codebook search *
+ *-----------------------------------------------------------------*/
+ cor_h_x(h2, xn2, dn);
+ if (*ser_size <= NBBITS_7k)
+ {
+ ACELP_2t64_fx(dn, cn, h2, code, y2, indice);
+
+ Parm_serial(indice[0], 12, &prms);
+ } else if(*ser_size <= NBBITS_9k)
+ {
+ ACELP_4t64_fx(dn, cn, h2, code, y2, 20, *ser_size, indice);
+
+ Parm_serial(indice[0], 5, &prms);
+ Parm_serial(indice[1], 5, &prms);
+ Parm_serial(indice[2], 5, &prms);
+ Parm_serial(indice[3], 5, &prms);
+ } else if(*ser_size <= NBBITS_12k)
+ {
+ ACELP_4t64_fx(dn, cn, h2, code, y2, 36, *ser_size, indice);
+
+ Parm_serial(indice[0], 9, &prms);
+ Parm_serial(indice[1], 9, &prms);
+ Parm_serial(indice[2], 9, &prms);
+ Parm_serial(indice[3], 9, &prms);
+ } else if(*ser_size <= NBBITS_14k)
+ {
+ ACELP_4t64_fx(dn, cn, h2, code, y2, 44, *ser_size, indice);
+
+ Parm_serial(indice[0], 13, &prms);
+ Parm_serial(indice[1], 13, &prms);
+ Parm_serial(indice[2], 9, &prms);
+ Parm_serial(indice[3], 9, &prms);
+ } else if(*ser_size <= NBBITS_16k)
+ {
+ ACELP_4t64_fx(dn, cn, h2, code, y2, 52, *ser_size, indice);
+
+ Parm_serial(indice[0], 13, &prms);
+ Parm_serial(indice[1], 13, &prms);
+ Parm_serial(indice[2], 13, &prms);
+ Parm_serial(indice[3], 13, &prms);
+ } else if(*ser_size <= NBBITS_18k)
+ {
+ ACELP_4t64_fx(dn, cn, h2, code, y2, 64, *ser_size, indice);
+
+ Parm_serial(indice[0], 2, &prms);
+ Parm_serial(indice[1], 2, &prms);
+ Parm_serial(indice[2], 2, &prms);
+ Parm_serial(indice[3], 2, &prms);
+ Parm_serial(indice[4], 14, &prms);
+ Parm_serial(indice[5], 14, &prms);
+ Parm_serial(indice[6], 14, &prms);
+ Parm_serial(indice[7], 14, &prms);
+ } else if(*ser_size <= NBBITS_20k)
+ {
+ ACELP_4t64_fx(dn, cn, h2, code, y2, 72, *ser_size, indice);
+
+ Parm_serial(indice[0], 10, &prms);
+ Parm_serial(indice[1], 10, &prms);
+ Parm_serial(indice[2], 2, &prms);
+ Parm_serial(indice[3], 2, &prms);
+ Parm_serial(indice[4], 10, &prms);
+ Parm_serial(indice[5], 10, &prms);
+ Parm_serial(indice[6], 14, &prms);
+ Parm_serial(indice[7], 14, &prms);
+ } else
+ {
+ ACELP_4t64_fx(dn, cn, h2, code, y2, 88, *ser_size, indice);
+
+ Parm_serial(indice[0], 11, &prms);
+ Parm_serial(indice[1], 11, &prms);
+ Parm_serial(indice[2], 11, &prms);
+ Parm_serial(indice[3], 11, &prms);
+ Parm_serial(indice[4], 11, &prms);
+ Parm_serial(indice[5], 11, &prms);
+ Parm_serial(indice[6], 11, &prms);
+ Parm_serial(indice[7], 11, &prms);
+ }
+ /*-------------------------------------------------------*
+ * - Add the fixed-gain pitch contribution to code[]. *
+ *-------------------------------------------------------*/
+ tmp = 0;
+ Preemph(code, st->tilt_code, L_SUBFR, &tmp);
+ Pit_shrp(code, T0, PIT_SHARP, L_SUBFR);
+ /*----------------------------------------------------------*
+ * - Compute the fixed codebook gain *
+ * - quantize fixed codebook gain *
+ *----------------------------------------------------------*/
+ if(*ser_size <= NBBITS_9k)
+ {
+ index = Q_gain2(xn, y1, Q_new + shift, y2, code, g_coeff, L_SUBFR, 6,
+ &gain_pit, &L_gain_code, clip_gain, st->qua_gain);
+ Parm_serial(index, 6, &prms);
+ } else
+ {
+ index = Q_gain2(xn, y1, Q_new + shift, y2, code, g_coeff, L_SUBFR, 7,
+ &gain_pit, &L_gain_code, clip_gain, st->qua_gain);
+ Parm_serial(index, 7, &prms);
+ }
+ /* test quantized gain of pitch for pitch clipping algorithm */
+ Gp_clip_test_gain_pit(gain_pit, st->gp_clip);
+
+ L_tmp = L_shl(L_gain_code, Q_new);
+ gain_code = extract_h(L_add(L_tmp, 0x8000));
+
+ /*----------------------------------------------------------*
+ * Update parameters for the next subframe. *
+ * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced) *
+ *----------------------------------------------------------*/
+ /* find voice factor in Q15 (1=voiced, -1=unvoiced) */
+ Copy(&exc[i_subfr], exc2, L_SUBFR);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Scale_sig_opt(exc2, L_SUBFR, shift);
+#else
+ Scale_sig(exc2, L_SUBFR, shift);
+#endif
+ voice_fac = voice_factor(exc2, shift, gain_pit, code, gain_code, L_SUBFR);
+ /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */
+ st->tilt_code = ((voice_fac >> 2) + 8192);
+ /*------------------------------------------------------*
+ * - Update filter's memory "mem_w0" for finding the *
+ * target vector in the next subframe. *
+ * - Find the total excitation *
+ * - Find synthesis speech to update mem_syn[]. *
+ *------------------------------------------------------*/
+
+ /* y2 in Q9, gain_pit in Q14 */
+ L_tmp = L_mult(gain_code, y2[L_SUBFR - 1]);
+ L_tmp = L_shl(L_tmp, (5 + shift));
+ L_tmp = L_negate(L_tmp);
+ L_tmp += (xn[L_SUBFR - 1] * 16384)<<1;
+ L_tmp -= (y1[L_SUBFR - 1] * gain_pit)<<1;
+ L_tmp = L_shl(L_tmp, (1 - shift));
+ st->mem_w0 = extract_h(L_add(L_tmp, 0x8000));
+
+ if (*ser_size >= NBBITS_24k)
+ Copy(&exc[i_subfr], exc2, L_SUBFR);
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ Word32 tmp;
+ /* code in Q9, gain_pit in Q14 */
+ L_tmp = L_mult(gain_code, code[i]);
+ L_tmp = L_shl(L_tmp, 5);
+ tmp = L_mult(exc[i + i_subfr], gain_pit); // (exc[i + i_subfr] * gain_pit)<<1
+ L_tmp = L_add(L_tmp, tmp);
+ L_tmp = L_shl2(L_tmp, 1);
+ exc[i + i_subfr] = extract_h(L_add(L_tmp, 0x8000));
+ }
+
+ Syn_filt(p_Aq,&exc[i_subfr], synth, L_SUBFR, st->mem_syn, 1);
+
+ if(*ser_size >= NBBITS_24k)
+ {
+ /*------------------------------------------------------------*
+ * phase dispersion to enhance noise in low bit rate *
+ *------------------------------------------------------------*/
+ /* L_gain_code in Q16 */
+ VO_L_Extract(L_gain_code, &gain_code, &gain_code_lo);
+
+ /*------------------------------------------------------------*
+ * noise enhancer *
+ * ~~~~~~~~~~~~~~ *
+ * - Enhance excitation on noise. (modify gain of code) *
+ * If signal is noisy and LPC filter is stable, move gain *
+ * of code 1.5 dB toward gain of code threshold. *
+ * This decrease by 3 dB noise energy variation. *
+ *------------------------------------------------------------*/
+ tmp = (16384 - (voice_fac >> 1)); /* 1=unvoiced, 0=voiced */
+ fac = vo_mult(stab_fac, tmp);
+ L_tmp = L_gain_code;
+ if(L_tmp < st->L_gc_thres)
+ {
+ L_tmp = vo_L_add(L_tmp, Mpy_32_16(gain_code, gain_code_lo, 6226));
+ if(L_tmp > st->L_gc_thres)
+ {
+ L_tmp = st->L_gc_thres;
+ }
+ } else
+ {
+ L_tmp = Mpy_32_16(gain_code, gain_code_lo, 27536);
+ if(L_tmp < st->L_gc_thres)
+ {
+ L_tmp = st->L_gc_thres;
+ }
+ }
+ st->L_gc_thres = L_tmp;
+
+ L_gain_code = Mpy_32_16(gain_code, gain_code_lo, (32767 - fac));
+ VO_L_Extract(L_tmp, &gain_code, &gain_code_lo);
+ L_gain_code = vo_L_add(L_gain_code, Mpy_32_16(gain_code, gain_code_lo, fac));
+
+ /*------------------------------------------------------------*
+ * pitch enhancer *
+ * ~~~~~~~~~~~~~~ *
+ * - Enhance excitation on voice. (HP filtering of code) *
+ * On voiced signal, filtering of code by a smooth fir HP *
+ * filter to decrease energy of code in low frequency. *
+ *------------------------------------------------------------*/
+
+ tmp = ((voice_fac >> 3) + 4096); /* 0.25=voiced, 0=unvoiced */
+
+ L_tmp = L_deposit_h(code[0]);
+ L_tmp -= (code[1] * tmp)<<1;
+ code2[0] = vo_round(L_tmp);
+
+ for (i = 1; i < L_SUBFR - 1; i++)
+ {
+ L_tmp = L_deposit_h(code[i]);
+ L_tmp -= (code[i + 1] * tmp)<<1;
+ L_tmp -= (code[i - 1] * tmp)<<1;
+ code2[i] = vo_round(L_tmp);
+ }
+
+ L_tmp = L_deposit_h(code[L_SUBFR - 1]);
+ L_tmp -= (code[L_SUBFR - 2] * tmp)<<1;
+ code2[L_SUBFR - 1] = vo_round(L_tmp);
+
+ /* build excitation */
+ gain_code = vo_round(L_shl(L_gain_code, Q_new));
+
+ for (i = 0; i < L_SUBFR; i++)
+ {
+ L_tmp = L_mult(code2[i], gain_code);
+ L_tmp = L_shl(L_tmp, 5);
+ L_tmp = L_add(L_tmp, L_mult(exc2[i], gain_pit));
+ L_tmp = L_shl(L_tmp, 1);
+ exc2[i] = voround(L_tmp);
+ }
+
+ corr_gain = synthesis(p_Aq, exc2, Q_new, &speech16k[i_subfr * 5 / 4], st);
+ Parm_serial(corr_gain, 4, &prms);
+ }
+ p_A += (M + 1);
+ p_Aq += (M + 1);
+ } /* end of subframe loop */
+
+ /*--------------------------------------------------*
+ * Update signal for next frame. *
+ * -> save past of speech[], wsp[] and exc[]. *
+ *--------------------------------------------------*/
+ Copy(&old_speech[L_FRAME], st->old_speech, L_TOTAL - L_FRAME);
+ Copy(&old_wsp[L_FRAME / OPL_DECIM], st->old_wsp, PIT_MAX / OPL_DECIM);
+ Copy(&old_exc[L_FRAME], st->old_exc, PIT_MAX + L_INTERPOL);
+ return;
+}
+
+/*-----------------------------------------------------*
+* Function synthesis() *
+* *
+* Synthesis of signal at 16kHz with HF extension. *
+* *
+*-----------------------------------------------------*/
+
+static Word16 synthesis(
+ Word16 Aq[], /* A(z) : quantized Az */
+ Word16 exc[], /* (i) : excitation at 12kHz */
+ Word16 Q_new, /* (i) : scaling performed on exc */
+ Word16 synth16k[], /* (o) : 16kHz synthesis signal */
+ Coder_State * st /* (i/o) : State structure */
+ )
+{
+ Word16 fac, tmp, exp;
+ Word16 ener, exp_ener;
+ Word32 L_tmp, i;
+
+ Word16 synth_hi[M + L_SUBFR], synth_lo[M + L_SUBFR];
+ Word16 synth[L_SUBFR];
+ Word16 HF[L_SUBFR16k]; /* High Frequency vector */
+ Word16 Ap[M + 1];
+
+ Word16 HF_SP[L_SUBFR16k]; /* High Frequency vector (from original signal) */
+
+ Word16 HP_est_gain, HP_calc_gain, HP_corr_gain;
+ Word16 dist_min, dist;
+ Word16 HP_gain_ind = 0;
+ Word16 gain1, gain2;
+ Word16 weight1, weight2;
+
+ /*------------------------------------------------------------*
+ * speech synthesis *
+ * ~~~~~~~~~~~~~~~~ *
+ * - Find synthesis speech corresponding to exc2[]. *
+ * - Perform fixed deemphasis and hp 50hz filtering. *
+ * - Oversampling from 12.8kHz to 16kHz. *
+ *------------------------------------------------------------*/
+ Copy(st->mem_syn_hi, synth_hi, M);
+ Copy(st->mem_syn_lo, synth_lo, M);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Syn_filt_32_asm(Aq, M, exc, Q_new, synth_hi + M, synth_lo + M, L_SUBFR);
+#else
+ Syn_filt_32(Aq, M, exc, Q_new, synth_hi + M, synth_lo + M, L_SUBFR);
+#endif
+
+ Copy(synth_hi + L_SUBFR, st->mem_syn_hi, M);
+ Copy(synth_lo + L_SUBFR, st->mem_syn_lo, M);
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Deemph_32_asm(synth_hi + M, synth_lo + M, synth, &(st->mem_deemph));
+#else
+ Deemph_32(synth_hi + M, synth_lo + M, synth, PREEMPH_FAC, L_SUBFR, &(st->mem_deemph));
+#endif
+
+ HP50_12k8(synth, L_SUBFR, st->mem_sig_out);
+
+ /* Original speech signal as reference for high band gain quantisation */
+ for (i = 0; i < L_SUBFR16k; i++)
+ {
+ HF_SP[i] = synth16k[i];
+ }
+
+ /*------------------------------------------------------*
+ * HF noise synthesis *
+ * ~~~~~~~~~~~~~~~~~~ *
+ * - Generate HF noise between 5.5 and 7.5 kHz. *
+ * - Set energy of noise according to synthesis tilt. *
+ * tilt > 0.8 ==> - 14 dB (voiced) *
+ * tilt 0.5 ==> - 6 dB (voiced or noise) *
+ * tilt < 0.0 ==> 0 dB (noise) *
+ *------------------------------------------------------*/
+ /* generate white noise vector */
+ for (i = 0; i < L_SUBFR16k; i++)
+ {
+ HF[i] = Random(&(st->seed2))>>3;
+ }
+ /* energy of excitation */
+#ifdef ASM_OPT /* asm optimization branch */
+ Scale_sig_opt(exc, L_SUBFR, -3);
+ Q_new = Q_new - 3;
+ ener = extract_h(Dot_product12_asm(exc, exc, L_SUBFR, &exp_ener));
+#else
+ Scale_sig(exc, L_SUBFR, -3);
+ Q_new = Q_new - 3;
+ ener = extract_h(Dot_product12(exc, exc, L_SUBFR, &exp_ener));
+#endif
+
+ exp_ener = exp_ener - (Q_new + Q_new);
+ /* set energy of white noise to energy of excitation */
+#ifdef ASM_OPT /* asm optimization branch */
+ tmp = extract_h(Dot_product12_asm(HF, HF, L_SUBFR16k, &exp));
+#else
+ tmp = extract_h(Dot_product12(HF, HF, L_SUBFR16k, &exp));
+#endif
+
+ if(tmp > ener)
+ {
+ tmp = (tmp >> 1); /* Be sure tmp < ener */
+ exp = (exp + 1);
+ }
+ L_tmp = L_deposit_h(div_s(tmp, ener)); /* result is normalized */
+ exp = (exp - exp_ener);
+ Isqrt_n(&L_tmp, &exp);
+ L_tmp = L_shl(L_tmp, (exp + 1)); /* L_tmp x 2, L_tmp in Q31 */
+ tmp = extract_h(L_tmp); /* tmp = 2 x sqrt(ener_exc/ener_hf) */
+
+ for (i = 0; i < L_SUBFR16k; i++)
+ {
+ HF[i] = vo_mult(HF[i], tmp);
+ }
+
+ /* find tilt of synthesis speech (tilt: 1=voiced, -1=unvoiced) */
+ HP400_12k8(synth, L_SUBFR, st->mem_hp400);
+
+ L_tmp = 1L;
+ for (i = 0; i < L_SUBFR; i++)
+ L_tmp += (synth[i] * synth[i])<<1;
+
+ exp = norm_l(L_tmp);
+ ener = extract_h(L_tmp << exp); /* ener = r[0] */
+
+ L_tmp = 1L;
+ for (i = 1; i < L_SUBFR; i++)
+ L_tmp +=(synth[i] * synth[i - 1])<<1;
+
+ tmp = extract_h(L_tmp << exp); /* tmp = r[1] */
+
+ if (tmp > 0)
+ {
+ fac = div_s(tmp, ener);
+ } else
+ {
+ fac = 0;
+ }
+
+ /* modify energy of white noise according to synthesis tilt */
+ gain1 = 32767 - fac;
+ gain2 = vo_mult(gain1, 20480);
+ gain2 = shl(gain2, 1);
+
+ if (st->vad_hist > 0)
+ {
+ weight1 = 0;
+ weight2 = 32767;
+ } else
+ {
+ weight1 = 32767;
+ weight2 = 0;
+ }
+ tmp = vo_mult(weight1, gain1);
+ tmp = add1(tmp, vo_mult(weight2, gain2));
+
+ if (tmp != 0)
+ {
+ tmp = (tmp + 1);
+ }
+ HP_est_gain = tmp;
+
+ if(HP_est_gain < 3277)
+ {
+ HP_est_gain = 3277; /* 0.1 in Q15 */
+ }
+ /* synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz */
+ Weight_a(Aq, Ap, 19661, M); /* fac=0.6 */
+
+#ifdef ASM_OPT /* asm optimization branch */
+ Syn_filt_asm(Ap, HF, HF, st->mem_syn_hf);
+ /* noise High Pass filtering (1ms of delay) */
+ Filt_6k_7k_asm(HF, L_SUBFR16k, st->mem_hf);
+ /* filtering of the original signal */
+ Filt_6k_7k_asm(HF_SP, L_SUBFR16k, st->mem_hf2);
+
+ /* check the gain difference */
+ Scale_sig_opt(HF_SP, L_SUBFR16k, -1);
+ ener = extract_h(Dot_product12_asm(HF_SP, HF_SP, L_SUBFR16k, &exp_ener));
+ /* set energy of white noise to energy of excitation */
+ tmp = extract_h(Dot_product12_asm(HF, HF, L_SUBFR16k, &exp));
+#else
+ Syn_filt(Ap, HF, HF, L_SUBFR16k, st->mem_syn_hf, 1);
+ /* noise High Pass filtering (1ms of delay) */
+ Filt_6k_7k(HF, L_SUBFR16k, st->mem_hf);
+ /* filtering of the original signal */
+ Filt_6k_7k(HF_SP, L_SUBFR16k, st->mem_hf2);
+ /* check the gain difference */
+ Scale_sig(HF_SP, L_SUBFR16k, -1);
+ ener = extract_h(Dot_product12(HF_SP, HF_SP, L_SUBFR16k, &exp_ener));
+ /* set energy of white noise to energy of excitation */
+ tmp = extract_h(Dot_product12(HF, HF, L_SUBFR16k, &exp));
+#endif
+
+ if (tmp > ener)
+ {
+ tmp = (tmp >> 1); /* Be sure tmp < ener */
+ exp = (exp + 1);
+ }
+ L_tmp = L_deposit_h(div_s(tmp, ener)); /* result is normalized */
+ exp = vo_sub(exp, exp_ener);
+ Isqrt_n(&L_tmp, &exp);
+ L_tmp = L_shl(L_tmp, exp); /* L_tmp, L_tmp in Q31 */
+ HP_calc_gain = extract_h(L_tmp); /* tmp = sqrt(ener_input/ener_hf) */
+
+ /* st->gain_alpha *= st->dtx_encSt->dtxHangoverCount/7 */
+ L_tmp = (vo_L_mult(st->dtx_encSt->dtxHangoverCount, 4681) << 15);
+ st->gain_alpha = vo_mult(st->gain_alpha, extract_h(L_tmp));
+
+ if(st->dtx_encSt->dtxHangoverCount > 6)
+ st->gain_alpha = 32767;
+ HP_est_gain = HP_est_gain >> 1; /* From Q15 to Q14 */
+ HP_corr_gain = add1(vo_mult(HP_calc_gain, st->gain_alpha), vo_mult((32767 - st->gain_alpha), HP_est_gain));
+
+ /* Quantise the correction gain */
+ dist_min = 32767;
+ for (i = 0; i < 16; i++)
+ {
+ dist = vo_mult((HP_corr_gain - HP_gain[i]), (HP_corr_gain - HP_gain[i]));
+ if (dist_min > dist)
+ {
+ dist_min = dist;
+ HP_gain_ind = i;
+ }
+ }
+ HP_corr_gain = HP_gain[HP_gain_ind];
+ /* return the quantised gain index when using the highest mode, otherwise zero */
+ return (HP_gain_ind);
+}
+
+/*************************************************
+*
+* Breif: Codec main function
+*
+**************************************************/
+
+int AMR_Enc_Encode(HAMRENC hCodec)
+{
+ Word32 i;
+ Coder_State *gData = (Coder_State*)hCodec;
+ Word16 *signal;
+ Word16 packed_size = 0;
+ Word16 prms[NB_BITS_MAX];
+ Word16 coding_mode = 0, nb_bits, allow_dtx, mode, reset_flag;
+ mode = gData->mode;
+ coding_mode = gData->mode;
+ nb_bits = nb_of_bits[mode];
+ signal = (Word16 *)gData->inputStream;
+ allow_dtx = gData->allow_dtx;
+
+ /* check for homing frame */
+ reset_flag = encoder_homing_frame_test(signal);
+
+ for (i = 0; i < L_FRAME16k; i++) /* Delete the 2 LSBs (14-bit input) */
+ {
+ *(signal + i) = (Word16) (*(signal + i) & 0xfffC);
+ }
+
+ coder(&coding_mode, signal, prms, &nb_bits, gData, allow_dtx);
+ packed_size = PackBits(prms, coding_mode, mode, gData);
+ if (reset_flag != 0)
+ {
+ Reset_encoder(gData, 1);
+ }
+ return packed_size;
+}
+
+/***************************************************************************
+*
+*Brief: Codec API function --- Initialize the codec and return a codec handle
+*
+***************************************************************************/
+
+VO_U32 VO_API voAMRWB_Init(VO_HANDLE * phCodec, /* o: the audio codec handle */
+ VO_AUDIO_CODINGTYPE vType, /* i: Codec Type ID */
+ VO_CODEC_INIT_USERDATA * pUserData /* i: init Parameters */
+ )
+{
+ Coder_State *st;
+ FrameStream *stream;
+#ifdef USE_DEAULT_MEM
+ VO_MEM_OPERATOR voMemoprator;
+#endif
+ VO_MEM_OPERATOR *pMemOP;
+ UNUSED(vType);
+
+ int interMem = 0;
+
+ if(pUserData == NULL || pUserData->memflag != VO_IMF_USERMEMOPERATOR || pUserData->memData == NULL )
+ {
+#ifdef USE_DEAULT_MEM
+ voMemoprator.Alloc = cmnMemAlloc;
+ voMemoprator.Copy = cmnMemCopy;
+ voMemoprator.Free = cmnMemFree;
+ voMemoprator.Set = cmnMemSet;
+ voMemoprator.Check = cmnMemCheck;
+ interMem = 1;
+ pMemOP = &voMemoprator;
+#else
+ *phCodec = NULL;
+ return VO_ERR_INVALID_ARG;
+#endif
+ }
+ else
+ {
+ pMemOP = (VO_MEM_OPERATOR *)pUserData->memData;
+ }
+ /*-------------------------------------------------------------------------*
+ * Memory allocation for coder state. *
+ *-------------------------------------------------------------------------*/
+ if ((st = (Coder_State *)mem_malloc(pMemOP, sizeof(Coder_State), 32, VO_INDEX_ENC_AMRWB)) == NULL)
+ {
+ return VO_ERR_OUTOF_MEMORY;
+ }
+
+ st->vadSt = NULL;
+ st->dtx_encSt = NULL;
+ st->sid_update_counter = 3;
+ st->sid_handover_debt = 0;
+ st->prev_ft = TX_SPEECH;
+ st->inputStream = NULL;
+ st->inputSize = 0;
+
+ /* Default setting */
+ st->mode = VOAMRWB_MD2385; /* bit rate 23.85kbps */
+ st->frameType = VOAMRWB_RFC3267; /* frame type: RFC3267 */
+ st->allow_dtx = 0; /* disable DTX mode */
+
+ st->outputStream = NULL;
+ st->outputSize = 0;
+
+ st->stream = (FrameStream *)mem_malloc(pMemOP, sizeof(FrameStream), 32, VO_INDEX_ENC_AMRWB);
+ if(st->stream == NULL)
+ return VO_ERR_OUTOF_MEMORY;
+
+ st->stream->frame_ptr = (unsigned char *)mem_malloc(pMemOP, Frame_Maxsize, 32, VO_INDEX_ENC_AMRWB);
+ if(st->stream->frame_ptr == NULL)
+ return VO_ERR_OUTOF_MEMORY;
+
+ stream = st->stream;
+ voAWB_InitFrameBuffer(stream);
+
+ wb_vad_init(&(st->vadSt), pMemOP);
+ dtx_enc_init(&(st->dtx_encSt), isf_init, pMemOP);
+
+ Reset_encoder((void *) st, 1);
+
+ if(interMem)
+ {
+ st->voMemoprator.Alloc = cmnMemAlloc;
+ st->voMemoprator.Copy = cmnMemCopy;
+ st->voMemoprator.Free = cmnMemFree;
+ st->voMemoprator.Set = cmnMemSet;
+ st->voMemoprator.Check = cmnMemCheck;
+ pMemOP = &st->voMemoprator;
+ }
+
+ st->pvoMemop = pMemOP;
+
+ *phCodec = (void *) st;
+
+ return VO_ERR_NONE;
+}
+
+/**********************************************************************************
+*
+* Brief: Codec API function: Input PCM data
+*
+***********************************************************************************/
+
+VO_U32 VO_API voAMRWB_SetInputData(
+ VO_HANDLE hCodec, /* i/o: The codec handle which was created by Init function */
+ VO_CODECBUFFER * pInput /* i: The input buffer parameter */
+ )
+{
+ Coder_State *gData;
+ FrameStream *stream;
+
+ if(NULL == hCodec)
+ {
+ return VO_ERR_INVALID_ARG;
+ }
+
+ gData = (Coder_State *)hCodec;
+ stream = gData->stream;
+
+ if(NULL == pInput || NULL == pInput->Buffer)
+ {
+ return VO_ERR_INVALID_ARG;
+ }
+
+ stream->set_ptr = pInput->Buffer;
+ stream->set_len = pInput->Length;
+ stream->frame_ptr = stream->frame_ptr_bk;
+ stream->used_len = 0;
+
+ return VO_ERR_NONE;
+}
+
+/**************************************************************************************
+*
+* Brief: Codec API function: Get the compression audio data frame by frame
+*
+***************************************************************************************/
+
+VO_U32 VO_API voAMRWB_GetOutputData(
+ VO_HANDLE hCodec, /* i: The Codec Handle which was created by Init function*/
+ VO_CODECBUFFER * pOutput, /* o: The output audio data */
+ VO_AUDIO_OUTPUTINFO * pAudioFormat /* o: The encoder module filled audio format and used the input size*/
+ )
+{
+ Coder_State* gData = (Coder_State*)hCodec;
+ VO_MEM_OPERATOR *pMemOP;
+ FrameStream *stream = (FrameStream *)gData->stream;
+ pMemOP = (VO_MEM_OPERATOR *)gData->pvoMemop;
+
+ if(stream->framebuffer_len < Frame_MaxByte) /* check the work buffer len */
+ {
+ stream->frame_storelen = stream->framebuffer_len;
+ if(stream->frame_storelen)
+ {
+ pMemOP->Copy(VO_INDEX_ENC_AMRWB, stream->frame_ptr_bk , stream->frame_ptr , stream->frame_storelen);
+ }
+ if(stream->set_len > 0)
+ {
+ voAWB_UpdateFrameBuffer(stream, pMemOP);
+ }
+ if(stream->framebuffer_len < Frame_MaxByte)
+ {
+ if(pAudioFormat)
+ pAudioFormat->InputUsed = stream->used_len;
+ return VO_ERR_INPUT_BUFFER_SMALL;
+ }
+ }
+
+ gData->inputStream = stream->frame_ptr;
+ gData->outputStream = (unsigned short*)pOutput->Buffer;
+
+ gData->outputSize = AMR_Enc_Encode(gData); /* encoder main function */
+
+ pOutput->Length = gData->outputSize; /* get the output buffer length */
+ stream->frame_ptr += 640; /* update the work buffer ptr */
+ stream->framebuffer_len -= 640;
+
+ if(pAudioFormat) /* return output audio information */
+ {
+ pAudioFormat->Format.Channels = 1;
+ pAudioFormat->Format.SampleRate = 8000;
+ pAudioFormat->Format.SampleBits = 16;
+ pAudioFormat->InputUsed = stream->used_len;
+ }
+ return VO_ERR_NONE;
+}
+
+/*************************************************************************
+*
+* Brief: Codec API function---set the data by specified parameter ID
+*
+*************************************************************************/
+
+
+VO_U32 VO_API voAMRWB_SetParam(
+ VO_HANDLE hCodec, /* i/o: The Codec Handle which was created by Init function */
+ VO_S32 uParamID, /* i: The param ID */
+ VO_PTR pData /* i: The param value depend on the ID */
+ )
+{
+ Coder_State* gData = (Coder_State*)hCodec;
+ FrameStream *stream = (FrameStream *)(gData->stream);
+ int *lValue = (int*)pData;
+
+ switch(uParamID)
+ {
+ /* setting AMR-WB frame type*/
+ case VO_PID_AMRWB_FRAMETYPE:
+ if(*lValue < VOAMRWB_DEFAULT || *lValue > VOAMRWB_RFC3267)
+ return VO_ERR_WRONG_PARAM_ID;
+ gData->frameType = *lValue;
+ break;
+ /* setting AMR-WB bit rate */
+ case VO_PID_AMRWB_MODE:
+ {
+ if(*lValue < VOAMRWB_MD66 || *lValue > VOAMRWB_MD2385)
+ return VO_ERR_WRONG_PARAM_ID;
+ gData->mode = *lValue;
+ }
+ break;
+ /* enable or disable DTX mode */
+ case VO_PID_AMRWB_DTX:
+ gData->allow_dtx = (Word16)(*lValue);
+ break;
+
+ case VO_PID_COMMON_HEADDATA:
+ break;
+ /* flush the work buffer */
+ case VO_PID_COMMON_FLUSH:
+ stream->set_ptr = NULL;
+ stream->frame_storelen = 0;
+ stream->framebuffer_len = 0;
+ stream->set_len = 0;
+ break;
+
+ default:
+ return VO_ERR_WRONG_PARAM_ID;
+ }
+ return VO_ERR_NONE;
+}
+
+/**************************************************************************
+*
+*Brief: Codec API function---Get the data by specified parameter ID
+*
+***************************************************************************/
+
+VO_U32 VO_API voAMRWB_GetParam(
+ VO_HANDLE hCodec, /* i: The Codec Handle which was created by Init function */
+ VO_S32 uParamID, /* i: The param ID */
+ VO_PTR pData /* o: The param value depend on the ID */
+ )
+{
+ int temp;
+ Coder_State* gData = (Coder_State*)hCodec;
+
+ if (gData==NULL)
+ return VO_ERR_INVALID_ARG;
+ switch(uParamID)
+ {
+ /* output audio format */
+ case VO_PID_AMRWB_FORMAT:
+ {
+ VO_AUDIO_FORMAT* fmt = (VO_AUDIO_FORMAT*)pData;
+ fmt->Channels = 1;
+ fmt->SampleRate = 16000;
+ fmt->SampleBits = 16;
+ break;
+ }
+ /* output audio channel number */
+ case VO_PID_AMRWB_CHANNELS:
+ temp = 1;
+ pData = (void *)(&temp);
+ break;
+ /* output audio sample rate */
+ case VO_PID_AMRWB_SAMPLERATE:
+ temp = 16000;
+ pData = (void *)(&temp);
+ break;
+ /* output audio frame type */
+ case VO_PID_AMRWB_FRAMETYPE:
+ temp = gData->frameType;
+ pData = (void *)(&temp);
+ break;
+ /* output audio bit rate */
+ case VO_PID_AMRWB_MODE:
+ temp = gData->mode;
+ pData = (void *)(&temp);
+ break;
+ default:
+ return VO_ERR_WRONG_PARAM_ID;
+ }
+
+ return VO_ERR_NONE;
+}
+
+/***********************************************************************************
+*
+* Brief: Codec API function---Release the codec after all encoder operations are done
+*
+*************************************************************************************/
+
+VO_U32 VO_API voAMRWB_Uninit(VO_HANDLE hCodec /* i/o: Codec handle pointer */
+ )
+{
+ Coder_State* gData = (Coder_State*)hCodec;
+ VO_MEM_OPERATOR *pMemOP;
+ pMemOP = gData->pvoMemop;
+
+ if(hCodec)
+ {
+ if(gData->stream)
+ {
+ if(gData->stream->frame_ptr_bk)
+ {
+ mem_free(pMemOP, gData->stream->frame_ptr_bk, VO_INDEX_ENC_AMRWB);
+ gData->stream->frame_ptr_bk = NULL;
+ }
+ mem_free(pMemOP, gData->stream, VO_INDEX_ENC_AMRWB);
+ gData->stream = NULL;
+ }
+ wb_vad_exit(&(((Coder_State *) gData)->vadSt), pMemOP);
+ dtx_enc_exit(&(((Coder_State *) gData)->dtx_encSt), pMemOP);
+
+ mem_free(pMemOP, hCodec, VO_INDEX_ENC_AMRWB);
+ hCodec = NULL;
+ }
+
+ return VO_ERR_NONE;
+}
+
+/********************************************************************************
+*
+* Brief: voGetAMRWBEncAPI gets the API handle of the codec
+*
+********************************************************************************/
+
+VO_S32 VO_API voGetAMRWBEncAPI(
+ VO_AUDIO_CODECAPI * pEncHandle /* i/o: Codec handle pointer */
+ )
+{
+ if(NULL == pEncHandle)
+ return VO_ERR_INVALID_ARG;
+ pEncHandle->Init = voAMRWB_Init;
+ pEncHandle->SetInputData = voAMRWB_SetInputData;
+ pEncHandle->GetOutputData = voAMRWB_GetOutputData;
+ pEncHandle->SetParam = voAMRWB_SetParam;
+ pEncHandle->GetParam = voAMRWB_GetParam;
+ pEncHandle->Uninit = voAMRWB_Uninit;
+
+ return VO_ERR_NONE;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/media/codecs/amrwb/enc/src/voicefac.c b/media/codecs/amrwb/enc/src/voicefac.c
new file mode 100644
index 0000000..c9f48c2
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/voicefac.c
@@ -0,0 +1,92 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: voicefac.c *
+* *
+* Description: Find the voicing factors (1 = voice to -1 = unvoiced) *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+
+Word16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
+ Word16 exc[], /* (i) Q_exc : pitch excitation */
+ Word16 Q_exc, /* (i) : exc format */
+ Word16 gain_pit, /* (i) Q14 : gain of pitch */
+ Word16 code[], /* (i) Q9 : Fixed codebook excitation */
+ Word16 gain_code, /* (i) Q0 : gain of code */
+ Word16 L_subfr /* (i) : subframe length */
+ )
+{
+ Word16 tmp, exp, ener1, exp1, ener2, exp2;
+ Word32 i, L_tmp;
+
+#ifdef ASM_OPT /* asm optimization branch */
+ ener1 = extract_h(Dot_product12_asm(exc, exc, L_subfr, &exp1));
+#else
+ ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1));
+#endif
+ exp1 = exp1 - (Q_exc + Q_exc);
+ L_tmp = vo_L_mult(gain_pit, gain_pit);
+ exp = norm_l(L_tmp);
+ tmp = extract_h(L_tmp << exp);
+ ener1 = vo_mult(ener1, tmp);
+ exp1 = exp1 - exp - 10; /* 10 -> gain_pit Q14 to Q9 */
+
+#ifdef ASM_OPT /* asm optimization branch */
+ ener2 = extract_h(Dot_product12_asm(code, code, L_subfr, &exp2));
+#else
+ ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2));
+#endif
+
+ exp = norm_s(gain_code);
+ tmp = gain_code << exp;
+ tmp = vo_mult(tmp, tmp);
+ ener2 = vo_mult(ener2, tmp);
+ exp2 = exp2 - (exp + exp);
+
+ i = exp1 - exp2;
+
+ if (i >= 0)
+ {
+ ener1 = ener1 >> 1;
+ ener2 = ener2 >> (i + 1);
+ } else
+ {
+ ener1 = ener1 >> (1 - i);
+ ener2 = ener2 >> 1;
+ }
+
+ tmp = vo_sub(ener1, ener2);
+ ener1 = add1(add1(ener1, ener2), 1);
+
+ if (tmp >= 0)
+ {
+ tmp = div_s(tmp, ener1);
+ } else
+ {
+ tmp = vo_negate(div_s(vo_negate(tmp), ener1));
+ }
+
+ return (tmp);
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/wb_vad.c b/media/codecs/amrwb/enc/src/wb_vad.c
new file mode 100644
index 0000000..866a69c
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/wb_vad.c
@@ -0,0 +1,808 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: wb_vad.c *
+* *
+* Description: Voice Activity Detection *
+* *
+************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "cnst.h"
+#include "wb_vad.h"
+#include "typedef.h"
+#include "basic_op.h"
+#include "math_op.h"
+#include "wb_vad_c.h"
+#include "mem_align.h"
+
+/******************************************************************************
+* Calculate Log2 and scale the signal:
+*
+* ilog2(Word32 in) = -1024*log10(in * 2^-31)/log10(2), where in = [1, 2^31-1]
+*
+* input output
+* 32768 16384
+* 1 31744
+*
+* When input is in the range of [1,2^16], max error is 0.0380%.
+*********************************************************************************/
+
+static Word16 ilog2( /* return: output value of the log2 */
+ Word16 mant /* i: value to be converted */
+ )
+{
+ Word16 ex, ex2, res;
+ Word32 i, l_temp;
+
+ if (mant <= 0)
+ {
+ mant = 1;
+ }
+ ex = norm_s(mant);
+ mant = mant << ex;
+
+ for (i = 0; i < 3; i++)
+ mant = vo_mult(mant, mant);
+ l_temp = vo_L_mult(mant, mant);
+
+ ex2 = norm_l(l_temp);
+ mant = extract_h(l_temp << ex2);
+
+ res = (ex + 16) << 10;
+ res = add1(res, (ex2 << 6));
+ res = vo_sub(add1(res, 127), (mant >> 8));
+ return (res);
+}
+
+/******************************************************************************
+*
+* Function : filter5
+* Purpose : Fifth-order half-band lowpass/highpass filter pair with
+* decimation.
+*
+*******************************************************************************/
+
+static void filter5(
+ Word16 * in0, /* i/o : input values; output low-pass part */
+ Word16 * in1, /* i/o : input values; output high-pass part */
+ Word16 data[] /* i/o : filter memory */
+ )
+{
+ Word16 temp0, temp1, temp2;
+
+ temp0 = vo_sub(*in0, vo_mult(COEFF5_1, data[0]));
+ temp1 = add1(data[0], vo_mult(COEFF5_1, temp0));
+ data[0] = temp0;
+
+ temp0 = vo_sub(*in1, vo_mult(COEFF5_2, data[1]));
+ temp2 = add1(data[1], vo_mult(COEFF5_2, temp0));
+ data[1] = temp0;
+
+ *in0 = extract_h((vo_L_add(temp1, temp2) << 15));
+ *in1 = extract_h((vo_L_sub(temp1, temp2) << 15));
+}
+
+/******************************************************************************
+*
+* Function : filter3
+* Purpose : Third-order half-band lowpass/highpass filter pair with
+* decimation.
+*
+*******************************************************************************/
+
+static void filter3(
+ Word16 * in0, /* i/o : input values; output low-pass part */
+ Word16 * in1, /* i/o : input values; output high-pass part */
+ Word16 * data /* i/o : filter memory */
+ )
+{
+ Word16 temp1, temp2;
+
+ temp1 = vo_sub(*in1, vo_mult(COEFF3, *data));
+ temp2 = add1(*data, vo_mult(COEFF3, temp1));
+ *data = temp1;
+
+ *in1 = extract_h((vo_L_sub(*in0, temp2) << 15));
+ *in0 = extract_h((vo_L_add(*in0, temp2) << 15));
+}
+
+/******************************************************************************
+*
+* Function : level_calculation
+* Purpose : Calculate signal level in a sub-band. Level is calculated
+* by summing absolute values of the input data.
+*
+* Signal level calculated from of the end of the frame
+* (data[count1 - count2]) is stored to (*sub_level)
+* and added to the level of the next frame.
+*
+******************************************************************************/
+
+static Word16 level_calculation( /* return: signal level */
+ Word16 data[], /* i : signal buffer */
+ Word16 * sub_level, /* i : level calculated at the end of the previous frame*/
+ /* o : level of signal calculated from the last */
+ /* (count2 - count1) samples */
+ Word16 count1, /* i : number of samples to be counted */
+ Word16 count2, /* i : number of samples to be counted */
+ Word16 ind_m, /* i : step size for the index of the data buffer */
+ Word16 ind_a, /* i : starting index of the data buffer */
+ Word16 scale /* i : scaling for the level calculation */
+ )
+{
+ Word32 i, l_temp1, l_temp2;
+ Word16 level;
+
+ l_temp1 = 0L;
+ for (i = count1; i < count2; i++)
+ {
+ l_temp1 += (abs_s(data[ind_m * i + ind_a])<<1);
+ }
+
+ l_temp2 = vo_L_add(l_temp1, L_shl(*sub_level, 16 - scale));
+ *sub_level = extract_h(L_shl(l_temp1, scale));
+
+ for (i = 0; i < count1; i++)
+ {
+ l_temp2 += (abs_s(data[ind_m * i + ind_a])<<1);
+ }
+ level = extract_h(L_shl2(l_temp2, scale));
+
+ return level;
+}
+
+/******************************************************************************
+*
+* Function : filter_bank
+* Purpose : Divide input signal into bands and calculate level of
+* the signal in each band
+*
+*******************************************************************************/
+
+static void filter_bank(
+ VadVars * st, /* i/o : State struct */
+ Word16 in[], /* i : input frame */
+ Word16 level[] /* o : signal levels at each band */
+ )
+{
+ Word32 i;
+ Word16 tmp_buf[FRAME_LEN];
+
+ /* shift input 1 bit down for safe scaling */
+ for (i = 0; i < FRAME_LEN; i++)
+ {
+ tmp_buf[i] = in[i] >> 1;
+ }
+
+ /* run the filter bank */
+ for (i = 0; i < 128; i++)
+ {
+ filter5(&tmp_buf[2 * i], &tmp_buf[2 * i + 1], st->a_data5[0]);
+ }
+ for (i = 0; i < 64; i++)
+ {
+ filter5(&tmp_buf[4 * i], &tmp_buf[4 * i + 2], st->a_data5[1]);
+ filter5(&tmp_buf[4 * i + 1], &tmp_buf[4 * i + 3], st->a_data5[2]);
+ }
+ for (i = 0; i < 32; i++)
+ {
+ filter5(&tmp_buf[8 * i], &tmp_buf[8 * i + 4], st->a_data5[3]);
+ filter5(&tmp_buf[8 * i + 2], &tmp_buf[8 * i + 6], st->a_data5[4]);
+ filter3(&tmp_buf[8 * i + 3], &tmp_buf[8 * i + 7], &st->a_data3[0]);
+ }
+ for (i = 0; i < 16; i++)
+ {
+ filter3(&tmp_buf[16 * i + 0], &tmp_buf[16 * i + 8], &st->a_data3[1]);
+ filter3(&tmp_buf[16 * i + 4], &tmp_buf[16 * i + 12], &st->a_data3[2]);
+ filter3(&tmp_buf[16 * i + 6], &tmp_buf[16 * i + 14], &st->a_data3[3]);
+ }
+
+ for (i = 0; i < 8; i++)
+ {
+ filter3(&tmp_buf[32 * i + 0], &tmp_buf[32 * i + 16], &st->a_data3[4]);
+ filter3(&tmp_buf[32 * i + 8], &tmp_buf[32 * i + 24], &st->a_data3[5]);
+ }
+
+ /* calculate levels in each frequency band */
+
+ /* 4800 - 6400 Hz */
+ level[11] = level_calculation(tmp_buf, &st->sub_level[11], 16, 64, 4, 1, 14);
+ /* 4000 - 4800 Hz */
+ level[10] = level_calculation(tmp_buf, &st->sub_level[10], 8, 32, 8, 7, 15);
+ /* 3200 - 4000 Hz */
+ level[9] = level_calculation(tmp_buf, &st->sub_level[9],8, 32, 8, 3, 15);
+ /* 2400 - 3200 Hz */
+ level[8] = level_calculation(tmp_buf, &st->sub_level[8],8, 32, 8, 2, 15);
+ /* 2000 - 2400 Hz */
+ level[7] = level_calculation(tmp_buf, &st->sub_level[7],4, 16, 16, 14, 16);
+ /* 1600 - 2000 Hz */
+ level[6] = level_calculation(tmp_buf, &st->sub_level[6],4, 16, 16, 6, 16);
+ /* 1200 - 1600 Hz */
+ level[5] = level_calculation(tmp_buf, &st->sub_level[5],4, 16, 16, 4, 16);
+ /* 800 - 1200 Hz */
+ level[4] = level_calculation(tmp_buf, &st->sub_level[4],4, 16, 16, 12, 16);
+ /* 600 - 800 Hz */
+ level[3] = level_calculation(tmp_buf, &st->sub_level[3],2, 8, 32, 8, 17);
+ /* 400 - 600 Hz */
+ level[2] = level_calculation(tmp_buf, &st->sub_level[2],2, 8, 32, 24, 17);
+ /* 200 - 400 Hz */
+ level[1] = level_calculation(tmp_buf, &st->sub_level[1],2, 8, 32, 16, 17);
+ /* 0 - 200 Hz */
+ level[0] = level_calculation(tmp_buf, &st->sub_level[0],2, 8, 32, 0, 17);
+}
+
+/******************************************************************************
+*
+* Function : update_cntrl
+* Purpose : Control update of the background noise estimate.
+*
+*******************************************************************************/
+
+static void update_cntrl(
+ VadVars * st, /* i/o : State structure */
+ Word16 level[] /* i : sub-band levels of the input frame */
+ )
+{
+ Word32 i;
+ Word16 num, temp, stat_rat, exp, denom;
+ Word16 alpha;
+
+ /* if a tone has been detected for a while, initialize stat_count */
+ if (sub((Word16) (st->tone_flag & 0x7c00), 0x7c00) == 0)
+ {
+ st->stat_count = STAT_COUNT;
+ } else
+ {
+ /* if 8 last vad-decisions have been "0", reinitialize stat_count */
+ if ((st->vadreg & 0x7f80) == 0)
+ {
+ st->stat_count = STAT_COUNT;
+ } else
+ {
+ stat_rat = 0;
+ for (i = 0; i < COMPLEN; i++)
+ {
+ if(level[i] > st->ave_level[i])
+ {
+ num = level[i];
+ denom = st->ave_level[i];
+ } else
+ {
+ num = st->ave_level[i];
+ denom = level[i];
+ }
+ /* Limit nimimum value of num and denom to STAT_THR_LEVEL */
+ if(num < STAT_THR_LEVEL)
+ {
+ num = STAT_THR_LEVEL;
+ }
+ if(denom < STAT_THR_LEVEL)
+ {
+ denom = STAT_THR_LEVEL;
+ }
+ exp = norm_s(denom);
+ denom = denom << exp;
+
+ /* stat_rat = num/denom * 64 */
+ temp = div_s(num >> 1, denom);
+ stat_rat = add1(stat_rat, shr(temp, (8 - exp)));
+ }
+
+ /* compare stat_rat with a threshold and update stat_count */
+ if(stat_rat > STAT_THR)
+ {
+ st->stat_count = STAT_COUNT;
+ } else
+ {
+ if ((st->vadreg & 0x4000) != 0)
+ {
+
+ if (st->stat_count != 0)
+ {
+ st->stat_count = st->stat_count - 1;
+ }
+ }
+ }
+ }
+ }
+
+ /* Update average amplitude estimate for stationarity estimation */
+ alpha = ALPHA4;
+ if(st->stat_count == STAT_COUNT)
+ {
+ alpha = 32767;
+ } else if ((st->vadreg & 0x4000) == 0)
+ {
+ alpha = ALPHA5;
+ }
+ for (i = 0; i < COMPLEN; i++)
+ {
+ st->ave_level[i] = add1(st->ave_level[i], vo_mult_r(alpha, vo_sub(level[i], st->ave_level[i])));
+ }
+}
+
+/******************************************************************************
+*
+* Function : hangover_addition
+* Purpose : Add hangover after speech bursts
+*
+*******************************************************************************/
+
+static Word16 hangover_addition( /* return: VAD_flag indicating final VAD decision */
+ VadVars * st, /* i/o : State structure */
+ Word16 low_power, /* i : flag power of the input frame */
+ Word16 hang_len, /* i : hangover length */
+ Word16 burst_len /* i : minimum burst length for hangover addition */
+ )
+{
+ /* if the input power (pow_sum) is lower than a threshold, clear counters and set VAD_flag to "0" */
+ if (low_power != 0)
+ {
+ st->burst_count = 0;
+ st->hang_count = 0;
+ return 0;
+ }
+ /* update the counters (hang_count, burst_count) */
+ if ((st->vadreg & 0x4000) != 0)
+ {
+ st->burst_count = st->burst_count + 1;
+ if(st->burst_count >= burst_len)
+ {
+ st->hang_count = hang_len;
+ }
+ return 1;
+ } else
+ {
+ st->burst_count = 0;
+ if (st->hang_count > 0)
+ {
+ st->hang_count = st->hang_count - 1;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************
+*
+* Function : noise_estimate_update
+* Purpose : Update of background noise estimate
+*
+*******************************************************************************/
+
+static void noise_estimate_update(
+ VadVars * st, /* i/o : State structure */
+ Word16 level[] /* i : sub-band levels of the input frame */
+ )
+{
+ Word32 i;
+ Word16 alpha_up, alpha_down, bckr_add = 2;
+
+ /* Control update of bckr_est[] */
+ update_cntrl(st, level);
+
+ /* Choose update speed */
+ if ((0x7800 & st->vadreg) == 0)
+ {
+ alpha_up = ALPHA_UP1;
+ alpha_down = ALPHA_DOWN1;
+ } else
+ {
+ if (st->stat_count == 0)
+ {
+ alpha_up = ALPHA_UP2;
+ alpha_down = ALPHA_DOWN2;
+ } else
+ {
+ alpha_up = 0;
+ alpha_down = ALPHA3;
+ bckr_add = 0;
+ }
+ }
+
+ /* Update noise estimate (bckr_est) */
+ for (i = 0; i < COMPLEN; i++)
+ {
+ Word16 temp;
+ temp = (st->old_level[i] - st->bckr_est[i]);
+
+ if (temp < 0)
+ { /* update downwards */
+ st->bckr_est[i] = add1(-2, add(st->bckr_est[i],vo_mult_r(alpha_down, temp)));
+ /* limit minimum value of the noise estimate to NOISE_MIN */
+ if(st->bckr_est[i] < NOISE_MIN)
+ {
+ st->bckr_est[i] = NOISE_MIN;
+ }
+ } else
+ { /* update upwards */
+ st->bckr_est[i] = add1(bckr_add, add1(st->bckr_est[i],vo_mult_r(alpha_up, temp)));
+
+ /* limit maximum value of the noise estimate to NOISE_MAX */
+ if(st->bckr_est[i] > NOISE_MAX)
+ {
+ st->bckr_est[i] = NOISE_MAX;
+ }
+ }
+ }
+
+ /* Update signal levels of the previous frame (old_level) */
+ for (i = 0; i < COMPLEN; i++)
+ {
+ st->old_level[i] = level[i];
+ }
+}
+
+/******************************************************************************
+*
+* Function : vad_decision
+* Purpose : Calculates VAD_flag
+*
+*******************************************************************************/
+
+static Word16 vad_decision( /* return value : VAD_flag */
+ VadVars * st, /* i/o : State structure */
+ Word16 level[COMPLEN], /* i : sub-band levels of the input frame */
+ Word32 pow_sum /* i : power of the input frame */
+ )
+{
+ Word32 i;
+ Word32 L_snr_sum;
+ Word32 L_temp;
+ Word16 vad_thr, temp, noise_level;
+ Word16 low_power_flag;
+ Word16 hang_len, burst_len;
+ Word16 ilog2_speech_level, ilog2_noise_level;
+ Word16 temp2;
+
+ /* Calculate squared sum of the input levels (level) divided by the background noise components
+ * (bckr_est). */
+ L_snr_sum = 0;
+ for (i = 0; i < COMPLEN; i++)
+ {
+ Word16 exp;
+
+ exp = norm_s(st->bckr_est[i]);
+ temp = (st->bckr_est[i] << exp);
+ temp = div_s((level[i] >> 1), temp);
+ temp = shl(temp, (exp - (UNIRSHFT - 1)));
+ L_snr_sum = L_mac(L_snr_sum, temp, temp);
+ }
+
+ /* Calculate average level of estimated background noise */
+ L_temp = 0;
+ for (i = 1; i < COMPLEN; i++) /* ignore lowest band */
+ {
+ L_temp = vo_L_add(L_temp, st->bckr_est[i]);
+ }
+
+ noise_level = extract_h((L_temp << 12));
+ /* if SNR is lower than a threshold (MIN_SPEECH_SNR), and increase speech_level */
+ temp = vo_mult(noise_level, MIN_SPEECH_SNR) << 3;
+
+ if(st->speech_level < temp)
+ {
+ st->speech_level = temp;
+ }
+ ilog2_noise_level = ilog2(noise_level);
+
+ /* If SNR is very poor, speech_level is probably corrupted by noise level. This is correctred by
+ * subtracting MIN_SPEECH_SNR*noise_level from speech level */
+ ilog2_speech_level = ilog2(st->speech_level - temp);
+
+ temp = add1(vo_mult(NO_SLOPE, (ilog2_noise_level - NO_P1)), THR_HIGH);
+
+ temp2 = add1(SP_CH_MIN, vo_mult(SP_SLOPE, (ilog2_speech_level - SP_P1)));
+ if (temp2 < SP_CH_MIN)
+ {
+ temp2 = SP_CH_MIN;
+ }
+ if (temp2 > SP_CH_MAX)
+ {
+ temp2 = SP_CH_MAX;
+ }
+ vad_thr = temp + temp2;
+
+ if(vad_thr < THR_MIN)
+ {
+ vad_thr = THR_MIN;
+ }
+ /* Shift VAD decision register */
+ st->vadreg = (st->vadreg >> 1);
+
+ /* Make intermediate VAD decision */
+ if(L_snr_sum > vo_L_mult(vad_thr, (512 * COMPLEN)))
+ {
+ st->vadreg = (Word16) (st->vadreg | 0x4000);
+ }
+ /* check if the input power (pow_sum) is lower than a threshold" */
+ if(pow_sum < VAD_POW_LOW)
+ {
+ low_power_flag = 1;
+ } else
+ {
+ low_power_flag = 0;
+ }
+ /* Update background noise estimates */
+ noise_estimate_update(st, level);
+
+ /* Calculate values for hang_len and burst_len based on vad_thr */
+ hang_len = add1(vo_mult(HANG_SLOPE, (vad_thr - HANG_P1)), HANG_HIGH);
+ if(hang_len < HANG_LOW)
+ {
+ hang_len = HANG_LOW;
+ }
+ burst_len = add1(vo_mult(BURST_SLOPE, (vad_thr - BURST_P1)), BURST_HIGH);
+
+ return (hangover_addition(st, low_power_flag, hang_len, burst_len));
+}
+
+/******************************************************************************
+*
+* Function : Estimate_Speech()
+* Purpose : Estimate speech level
+*
+* Maximum signal level is searched and stored to the variable sp_max.
+* The speech frames must locate within SP_EST_COUNT number of frames.
+* Thus, noisy frames having occasional VAD = "1" decisions will not
+* affect to the estimated speech_level.
+*
+*******************************************************************************/
+
+static void Estimate_Speech(
+ VadVars * st, /* i/o : State structure */
+ Word16 in_level /* level of the input frame */
+ )
+{
+ Word16 alpha;
+
+ /* if the required activity count cannot be achieved, reset counters */
+ if((st->sp_est_cnt - st->sp_max_cnt) > (SP_EST_COUNT - SP_ACTIVITY_COUNT))
+ {
+ st->sp_est_cnt = 0;
+ st->sp_max = 0;
+ st->sp_max_cnt = 0;
+ }
+ st->sp_est_cnt += 1;
+
+ if (((st->vadreg & 0x4000)||(in_level > st->speech_level)) && (in_level > MIN_SPEECH_LEVEL1))
+ {
+ /* update sp_max */
+ if(in_level > st->sp_max)
+ {
+ st->sp_max = in_level;
+ }
+ st->sp_max_cnt += 1;
+
+ if(st->sp_max_cnt >= SP_ACTIVITY_COUNT)
+ {
+ Word16 tmp;
+ /* update speech estimate */
+ tmp = (st->sp_max >> 1); /* scale to get "average" speech level */
+
+ /* select update speed */
+ if(tmp > st->speech_level)
+ {
+ alpha = ALPHA_SP_UP;
+ } else
+ {
+ alpha = ALPHA_SP_DOWN;
+ }
+ if(tmp > MIN_SPEECH_LEVEL2)
+ {
+ st->speech_level = add1(st->speech_level, vo_mult_r(alpha, vo_sub(tmp, st->speech_level)));
+ }
+ /* clear all counters used for speech estimation */
+ st->sp_max = 0;
+ st->sp_max_cnt = 0;
+ st->sp_est_cnt = 0;
+ }
+ }
+}
+
+/******************************************************************************
+*
+* Function: wb_vad_init
+* Purpose: Allocates state memory and initializes state memory
+*
+*******************************************************************************/
+
+Word16 wb_vad_init( /* return: non-zero with error, zero for ok. */
+ VadVars ** state, /* i/o : State structure */
+ VO_MEM_OPERATOR *pMemOP
+ )
+{
+ VadVars *s;
+
+ if (state == (VadVars **) NULL)
+ {
+ fprintf(stderr, "vad_init: invalid parameter\n");
+ return -1;
+ }
+ *state = NULL;
+
+ /* allocate memory */
+ if ((s = (VadVars *) mem_malloc(pMemOP, sizeof(VadVars), 32, VO_INDEX_ENC_AMRWB)) == NULL)
+ {
+ fprintf(stderr, "vad_init: can not malloc state structure\n");
+ return -1;
+ }
+ wb_vad_reset(s);
+
+ *state = s;
+
+ return 0;
+}
+
+/******************************************************************************
+*
+* Function: wb_vad_reset
+* Purpose: Initializes state memory
+*
+*******************************************************************************/
+
+Word16 wb_vad_reset( /* return: non-zero with error, zero for ok. */
+ VadVars * state /* i/o : State structure */
+ )
+{
+ Word32 i, j;
+
+ if (state == (VadVars *) NULL)
+ {
+ fprintf(stderr, "vad_reset: invalid parameter\n");
+ return -1;
+ }
+ state->tone_flag = 0;
+ state->vadreg = 0;
+ state->hang_count = 0;
+ state->burst_count = 0;
+ state->hang_count = 0;
+
+ /* initialize memory used by the filter bank */
+ for (i = 0; i < F_5TH_CNT; i++)
+ {
+ for (j = 0; j < 2; j++)
+ {
+ state->a_data5[i][j] = 0;
+ }
+ }
+
+ for (i = 0; i < F_3TH_CNT; i++)
+ {
+ state->a_data3[i] = 0;
+ }
+
+ /* initialize the rest of the memory */
+ for (i = 0; i < COMPLEN; i++)
+ {
+ state->bckr_est[i] = NOISE_INIT;
+ state->old_level[i] = NOISE_INIT;
+ state->ave_level[i] = NOISE_INIT;
+ state->sub_level[i] = 0;
+ }
+
+ state->sp_est_cnt = 0;
+ state->sp_max = 0;
+ state->sp_max_cnt = 0;
+ state->speech_level = SPEECH_LEVEL_INIT;
+ state->prev_pow_sum = 0;
+ return 0;
+}
+
+/******************************************************************************
+*
+* Function: wb_vad_exit
+* Purpose: The memory used for state memory is freed
+*
+*******************************************************************************/
+
+void wb_vad_exit(
+ VadVars ** state, /* i/o : State structure */
+ VO_MEM_OPERATOR *pMemOP
+ )
+{
+ if (state == NULL || *state == NULL)
+ return;
+ /* deallocate memory */
+ mem_free(pMemOP, *state, VO_INDEX_ENC_AMRWB);
+ *state = NULL;
+ return;
+}
+
+/******************************************************************************
+*
+* Function : wb_vad_tone_detection
+* Purpose : Search maximum pitch gain from a frame. Set tone flag if
+* pitch gain is high. This is used to detect
+* signaling tones and other signals with high pitch gain.
+*
+*******************************************************************************/
+
+void wb_vad_tone_detection(
+ VadVars * st, /* i/o : State struct */
+ Word16 p_gain /* pitch gain */
+ )
+{
+ /* update tone flag */
+ st->tone_flag = (st->tone_flag >> 1);
+
+ /* if (pitch_gain > TONE_THR) set tone flag */
+ if (p_gain > TONE_THR)
+ {
+ st->tone_flag = (Word16) (st->tone_flag | 0x4000);
+ }
+}
+
+/******************************************************************************
+*
+* Function : wb_vad
+* Purpose : Main program for Voice Activity Detection (VAD) for AMR
+*
+*******************************************************************************/
+
+Word16 wb_vad( /* Return value : VAD Decision, 1 = speech, 0 = noise */
+ VadVars * st, /* i/o : State structure */
+ Word16 in_buf[] /* i : samples of the input frame */
+ )
+{
+ Word16 level[COMPLEN];
+ Word32 i;
+ Word16 VAD_flag, temp;
+ Word32 L_temp, pow_sum;
+
+ /* Calculate power of the input frame. */
+ L_temp = 0L;
+ for (i = 0; i < FRAME_LEN; i++)
+ {
+ L_temp = L_mac(L_temp, in_buf[i], in_buf[i]);
+ }
+
+ /* pow_sum = power of current frame and previous frame */
+ pow_sum = L_add(L_temp, st->prev_pow_sum);
+
+ /* save power of current frame for next call */
+ st->prev_pow_sum = L_temp;
+
+ /* If input power is very low, clear tone flag */
+ if (pow_sum < POW_TONE_THR)
+ {
+ st->tone_flag = (Word16) (st->tone_flag & 0x1fff);
+ }
+ /* Run the filter bank and calculate signal levels at each band */
+ filter_bank(st, in_buf, level);
+
+ /* compute VAD decision */
+ VAD_flag = vad_decision(st, level, pow_sum);
+
+ /* Calculate input level */
+ L_temp = 0;
+ for (i = 1; i < COMPLEN; i++) /* ignore lowest band */
+ {
+ L_temp = vo_L_add(L_temp, level[i]);
+ }
+
+ temp = extract_h(L_temp << 12);
+
+ Estimate_Speech(st, temp); /* Estimate speech level */
+ return (VAD_flag);
+}
+
+
+
+
diff --git a/media/codecs/amrwb/enc/src/weight_a.c b/media/codecs/amrwb/enc/src/weight_a.c
new file mode 100644
index 0000000..23b774e
--- /dev/null
+++ b/media/codecs/amrwb/enc/src/weight_a.c
@@ -0,0 +1,48 @@
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+/***********************************************************************
+* File: weight_a.c *
+* *
+* Description:Weighting of LPC coefficients *
+* ap[i] = a[i] * (gamma ** i) *
+* *
+************************************************************************/
+
+#include "typedef.h"
+#include "basic_op.h"
+
+void Weight_a(
+ Word16 a[], /* (i) Q12 : a[m+1] LPC coefficients */
+ Word16 ap[], /* (o) Q12 : Spectral expanded LPC coefficients */
+ Word16 gamma, /* (i) Q15 : Spectral expansion factor. */
+ Word16 m /* (i) : LPC order. */
+ )
+{
+ Word32 num = m - 1, fac;
+ *ap++ = *a++;
+ fac = gamma;
+ do{
+ *ap++ =(Word16)(((vo_L_mult((*a++), fac)) + 0x8000) >> 16);
+ fac = (vo_L_mult(fac, gamma) + 0x8000) >> 16;
+ }while(--num != 0);
+
+ *ap++ = (Word16)(((vo_L_mult((*a++), fac)) + 0x8000) >> 16);
+ return;
+}
+
+
+
diff --git a/media/codecs/amrwb/enc/test/AmrwbEncTestEnvironment.h b/media/codecs/amrwb/enc/test/AmrwbEncTestEnvironment.h
new file mode 100644
index 0000000..08ada66
--- /dev/null
+++ b/media/codecs/amrwb/enc/test/AmrwbEncTestEnvironment.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AMRWBENC_TEST_ENVIRONMENT_H__
+#define __AMRWBENC_TEST_ENVIRONMENT_H__
+
+#include <gtest/gtest.h>
+
+#include <getopt.h>
+
+using namespace std;
+
+class AmrwbEncTestEnvironment : public ::testing::Environment {
+ public:
+ AmrwbEncTestEnvironment() : res("/data/local/tmp/") {}
+
+ // Parses the command line arguments
+ int initFromOptions(int argc, char **argv);
+
+ void setRes(const char *_res) { res = _res; }
+
+ const string getRes() const { return res; }
+
+ private:
+ string res;
+};
+
+int AmrwbEncTestEnvironment::initFromOptions(int argc, char **argv) {
+ static struct option options[] = {{"res", required_argument, 0, 'P'}, {0, 0, 0, 0}};
+
+ while (true) {
+ int index = 0;
+ int c = getopt_long(argc, argv, "P:", options, &index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'P':
+ setRes(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr,
+ "unrecognized option: %s\n\n"
+ "usage: %s <gtest options> <test options>\n\n"
+ "test options are:\n\n"
+ "-P, --path: Resource files directory location\n",
+ argv[optind ?: 1], argv[0]);
+ return 2;
+ }
+ return 0;
+}
+
+#endif // __AMRWBENC_TEST_ENVIRONMENT_H__
diff --git a/media/codecs/amrwb/enc/test/AmrwbEncoderTest.cpp b/media/codecs/amrwb/enc/test/AmrwbEncoderTest.cpp
new file mode 100644
index 0000000..1a6ee27
--- /dev/null
+++ b/media/codecs/amrwb/enc/test/AmrwbEncoderTest.cpp
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "AmrwbEncoderTest"
+
+#include <utils/Log.h>
+
+#include <stdio.h>
+
+#include "cmnMemory.h"
+#include "voAMRWB.h"
+
+#include "AmrwbEncTestEnvironment.h"
+
+#define OUTPUT_FILE "/data/local/tmp/amrwbEncode.out"
+#define VOAMRWB_RFC3267_HEADER_INFO "#!AMR-WB\n"
+
+constexpr int32_t kInputBufferSize = 640;
+constexpr int32_t kOutputBufferSize = 1024;
+
+static AmrwbEncTestEnvironment *gEnv = nullptr;
+
+class AmrwbEncoderTest : public ::testing::TestWithParam<tuple<string, int32_t, VOAMRWBFRAMETYPE>> {
+ public:
+ AmrwbEncoderTest() : mEncoderHandle(nullptr) {
+ tuple<string, int32_t, VOAMRWBFRAMETYPE> params = GetParam();
+ mInputFile = gEnv->getRes() + get<0>(params);
+ mMode = get<1>(params);
+ mFrameType = get<2>(params);
+ mMemOperator.Alloc = cmnMemAlloc;
+ mMemOperator.Copy = cmnMemCopy;
+ mMemOperator.Free = cmnMemFree;
+ mMemOperator.Set = cmnMemSet;
+ mMemOperator.Check = cmnMemCheck;
+
+ mUserData.memflag = VO_IMF_USERMEMOPERATOR;
+ mUserData.memData = (VO_PTR)(&mMemOperator);
+ }
+
+ ~AmrwbEncoderTest() {
+ if (mEncoderHandle) {
+ mEncoderHandle = nullptr;
+ }
+ }
+
+ string mInputFile;
+ unsigned char mOutputBuf[kOutputBufferSize];
+ unsigned char mInputBuf[kInputBufferSize];
+ VOAMRWBFRAMETYPE mFrameType;
+ VO_AUDIO_CODECAPI mApiHandle;
+ VO_MEM_OPERATOR mMemOperator;
+ VO_CODEC_INIT_USERDATA mUserData;
+ VO_HANDLE mEncoderHandle;
+ int32_t mMode;
+};
+
+TEST_P(AmrwbEncoderTest, CreateAmrwbEncoderTest) {
+ int32_t status = voGetAMRWBEncAPI(&mApiHandle);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to get api handle";
+
+ status = mApiHandle.Init(&mEncoderHandle, VO_AUDIO_CodingAMRWB, &mUserData);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to init AMRWB encoder";
+
+ status = mApiHandle.SetParam(mEncoderHandle, VO_PID_AMRWB_FRAMETYPE, &mFrameType);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to set AMRWB encoder frame type to " << mFrameType;
+
+ status = mApiHandle.SetParam(mEncoderHandle, VO_PID_AMRWB_MODE, &mMode);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to set AMRWB encoder mode to %d" << mMode;
+ ALOGV("AMR-WB encoder created successfully");
+
+ status = mApiHandle.Uninit(mEncoderHandle);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to delete AMRWB encoder";
+ ALOGV("AMR-WB encoder deleted successfully");
+}
+
+TEST_P(AmrwbEncoderTest, AmrwbEncodeTest) {
+ VO_CODECBUFFER inData;
+ VO_CODECBUFFER outData;
+ VO_AUDIO_OUTPUTINFO outFormat;
+
+ FILE *fpInput = fopen(mInputFile.c_str(), "rb");
+ ASSERT_NE(fpInput, nullptr) << "Error opening input file " << mInputFile;
+
+ FILE *fpOutput = fopen(OUTPUT_FILE, "wb");
+ ASSERT_NE(fpOutput, nullptr) << "Error opening output file " << OUTPUT_FILE;
+
+ uint32_t status = voGetAMRWBEncAPI(&mApiHandle);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to get api handle";
+
+ status = mApiHandle.Init(&mEncoderHandle, VO_AUDIO_CodingAMRWB, &mUserData);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to init AMRWB encoder";
+
+ status = mApiHandle.SetParam(mEncoderHandle, VO_PID_AMRWB_FRAMETYPE, &mFrameType);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to set AMRWB encoder frame type to " << mFrameType;
+
+ status = mApiHandle.SetParam(mEncoderHandle, VO_PID_AMRWB_MODE, &mMode);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to set AMRWB encoder mode to " << mMode;
+
+ if (mFrameType == VOAMRWB_RFC3267) {
+ /* write RFC3267 Header info to indicate single channel AMR file storage format */
+ int32_t size = strlen(VOAMRWB_RFC3267_HEADER_INFO);
+ memcpy(mOutputBuf, VOAMRWB_RFC3267_HEADER_INFO, size);
+ fwrite(mOutputBuf, 1, size, fpOutput);
+ }
+
+ int32_t frameNum = 0;
+ while (1) {
+ int32_t buffLength =
+ (int32_t)fread(mInputBuf, sizeof(signed char), kInputBufferSize, fpInput);
+
+ if (buffLength == 0 || feof(fpInput)) break;
+ ASSERT_EQ(buffLength, kInputBufferSize) << "Error in reading input file";
+
+ inData.Buffer = (unsigned char *)mInputBuf;
+ inData.Length = buffLength;
+ outData.Buffer = mOutputBuf;
+ status = mApiHandle.SetInputData(mEncoderHandle, &inData);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to setup Input data";
+
+ do {
+ status = mApiHandle.GetOutputData(mEncoderHandle, &outData, &outFormat);
+ ASSERT_NE(status, VO_ERR_LICENSE_ERROR) << "Failed to encode the file";
+ if (status == 0) {
+ frameNum++;
+ fwrite(outData.Buffer, 1, outData.Length, fpOutput);
+ fflush(fpOutput);
+ }
+ } while (status != VO_ERR_INPUT_BUFFER_SMALL);
+ }
+
+ ALOGV("Number of frames processed: %d", frameNum);
+ status = mApiHandle.Uninit(mEncoderHandle);
+ ASSERT_EQ(status, VO_ERR_NONE) << "Failed to delete AMRWB encoder";
+
+ if (fpInput) {
+ fclose(fpInput);
+ }
+ if (fpOutput) {
+ fclose(fpOutput);
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ AmrwbEncoderTestAll, AmrwbEncoderTest,
+ ::testing::Values(
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD66, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD885, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1265, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1425, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1585, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1825, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1985, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD2305, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD2385, VOAMRWB_DEFAULT),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD66, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD885, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1265, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1425, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1585, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1825, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1985, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD2305, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD2385, VOAMRWB_ITU),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD66, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD885, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1265, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1425, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1585, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1825, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD1985, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD2305, VOAMRWB_RFC3267),
+ make_tuple("bbb_raw_1ch_16khz_s16le.raw", VOAMRWB_MD2385, VOAMRWB_RFC3267)));
+
+int main(int argc, char **argv) {
+ gEnv = new AmrwbEncTestEnvironment();
+ ::testing::AddGlobalTestEnvironment(gEnv);
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = gEnv->initFromOptions(argc, argv);
+ if (status == 0) {
+ status = RUN_ALL_TESTS();
+ ALOGV("Test result = %d\n", status);
+ }
+ return status;
+}
diff --git a/media/codecs/amrwb/enc/test/Android.bp b/media/codecs/amrwb/enc/test/Android.bp
new file mode 100644
index 0000000..7042bc5
--- /dev/null
+++ b/media/codecs/amrwb/enc/test/Android.bp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_test {
+ name: "AmrwbEncoderTest",
+ gtest: true,
+
+ srcs: [
+ "AmrwbEncoderTest.cpp",
+ ],
+
+ static_libs: [
+ "libstagefright_enc_common",
+ "libstagefright_amrwbenc",
+ "libaudioutils",
+ "libsndfile",
+ ],
+
+ shared_libs: [
+ "liblog",
+ ],
+
+ cflags: [
+ "-Werror",
+ "-Wall",
+ ],
+
+ sanitize: {
+ cfi: true,
+ misc_undefined: [
+ "unsigned-integer-overflow",
+ "signed-integer-overflow",
+ ],
+ },
+}
diff --git a/media/codecs/amrwb/enc/test/AndroidTest.xml b/media/codecs/amrwb/enc/test/AndroidTest.xml
new file mode 100644
index 0000000..46f147c
--- /dev/null
+++ b/media/codecs/amrwb/enc/test/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for Amr-wb Encoder unit test">
+ <option name="test-suite-tag" value="AmrwbEncoderTest" />
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="AmrwbEncoderTest->/data/local/tmp/AmrwbEncoderTest" />
+ <option name="push-file"
+ key="https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrwbenc/test/AmrwbEncoderTest.zip?unzip=true"
+ value="/data/local/tmp/AmrwbEncoderTestRes/" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="AmrwbEncoderTest" />
+ <option name="native-test-flag" value="-P /data/local/tmp/AmrwbEncoderTestRes/" />
+ </test>
+</configuration>
diff --git a/media/codecs/amrwb/enc/test/README.md b/media/codecs/amrwb/enc/test/README.md
new file mode 100644
index 0000000..78762cb
--- /dev/null
+++ b/media/codecs/amrwb/enc/test/README.md
@@ -0,0 +1,39 @@
+## Media Testing ##
+---
+#### AMR-WB Encoder :
+The Amr-Wb Encoder Test Suite validates the amrwb encoder available in libstagefright.
+
+Run the following steps to build the test suite:
+```
+m AmrwbEncoderTest
+```
+
+The 32-bit binaries will be created in the following path : ${OUT}/data/nativetest/
+
+The 64-bit binaries will be created in the following path : ${OUT}/data/nativetest64/
+
+To test 64-bit binary push binaries from nativetest64.
+```
+adb push ${OUT}/data/nativetest64/AmrwbEncoderTest/AmrwbEncoderTest /data/local/tmp/
+```
+
+To test 32-bit binary push binaries from nativetest.
+```
+adb push ${OUT}/data/nativetest/AmrwbEncoderTest/AmrwbEncoderTest /data/local/tmp/
+```
+
+The resource file for the tests is taken from [here](https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/amrwbenc/test/AmrwbEncoderTest.zip). Download, unzip and push these files into device for testing.
+
+```
+adb push AmrwbEncoderTestRes/. /data/local/tmp/
+```
+
+usage: AmrwbEncoderTest -P \<path_to_folder\>
+```
+adb shell /data/local/tmp/AmrwbEncoderTest -P /data/local/tmp/AmrwbEncoderTestRes/
+```
+Alternatively, the test can also be run using atest command.
+
+```
+atest AmrwbEncoderTest -- --enable-module-dynamic-download=true
+```
diff --git a/media/codecs/m4v_h263/TEST_MAPPING b/media/codecs/m4v_h263/TEST_MAPPING
new file mode 100644
index 0000000..ba3ff1c
--- /dev/null
+++ b/media/codecs/m4v_h263/TEST_MAPPING
@@ -0,0 +1,18 @@
+// mappings for frameworks/av/media/libstagefright/codecs/m4v_h263
+{
+ // tests which require dynamic content
+ // invoke with: atest -- --enable-module-dynamic-download=true
+ // TODO(b/148094059): unit tests not allowed to download content
+ "dynamic-presubmit": [
+
+ // the decoder reports something bad about an unexpected newline in the *config file
+ // and the config file looks like the AndroidTest.xml file that we put in there.
+ // I don't get this from the Encoder -- and I don't see any substantive difference
+ // between decode and encode AndroidTest.xml files -- except that encode does NOT
+ // finish with a newline.
+ // strange.
+ { "name": "Mpeg4H263DecoderTest"},
+ { "name": "Mpeg4H263EncoderTest"}
+
+ ]
+}
diff --git a/media/codecs/m4v_h263/dec/Android.bp b/media/codecs/m4v_h263/dec/Android.bp
new file mode 100644
index 0000000..b40745a
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/Android.bp
@@ -0,0 +1,58 @@
+cc_library_static {
+ name: "libstagefright_m4vh263dec",
+ vendor_available: true,
+ apex_available: [
+ "//apex_available:platform",
+ "com.android.media.swcodec",
+ ],
+ min_sdk_version: "29",
+ host_supported: true,
+ shared_libs: ["liblog"],
+
+ srcs: [
+ "src/bitstream.cpp",
+ "src/block_idct.cpp",
+ "src/cal_dc_scaler.cpp",
+ "src/combined_decode.cpp",
+ "src/conceal.cpp",
+ "src/datapart_decode.cpp",
+ "src/dcac_prediction.cpp",
+ "src/dec_pred_intra_dc.cpp",
+ "src/get_pred_adv_b_add.cpp",
+ "src/get_pred_outside.cpp",
+ "src/idct.cpp",
+ "src/idct_vca.cpp",
+ "src/mb_motion_comp.cpp",
+ "src/mb_utils.cpp",
+ "src/packet_util.cpp",
+ "src/post_filter.cpp",
+ "src/pvdec_api.cpp",
+ "src/scaling_tab.cpp",
+ "src/vlc_decode.cpp",
+ "src/vlc_dequant.cpp",
+ "src/vlc_tab.cpp",
+ "src/vop.cpp",
+ "src/zigzag_tab.cpp",
+ ],
+
+ local_include_dirs: ["src"],
+ export_include_dirs: ["include"],
+
+ cflags: [
+ "-Werror",
+ ],
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ ],
+ cfi: true,
+ },
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
diff --git a/media/codecs/m4v_h263/dec/MODULE_LICENSE_APACHE2 b/media/codecs/m4v_h263/dec/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/m4v_h263/dec/NOTICE b/media/codecs/m4v_h263/dec/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/m4v_h263/dec/include/m4vh263_decoder_pv_types.h b/media/codecs/m4v_h263/dec/include/m4vh263_decoder_pv_types.h
new file mode 100644
index 0000000..711ec58
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/include/m4vh263_decoder_pv_types.h
@@ -0,0 +1,67 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------$
+ */
+
+#ifndef M4V_H263_DECODER_PV_TYPES_H_
+#define M4V_H263_DECODER_PV_TYPES_H_
+
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h> // for free, malloc, etc
+
+// Redefine the int types
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef int16_t int16;
+typedef uint32_t uint32;
+typedef int32_t int32;
+typedef unsigned int uint;
+
+// Redefine the oscl memory management routines
+#define oscl_memcpy memcpy
+#define oscl_memset memset
+#define oscl_malloc malloc
+#define oscl_free free
+#define oscl_memcmp memcmp
+#define OSCL_DELETE(ptr) { delete(ptr); }
+
+// Request status values. These are negative so that
+// they won't conflict with system error codes.
+const int32 OSCL_REQUEST_ERR_NONE = 0;
+const int32 OSCL_REQUEST_PENDING = (-0x7fffffff);
+const int32 OSCL_REQUEST_ERR_CANCEL = (-1);
+const int32 OSCL_REQUEST_ERR_GENERAL = (-2);
+
+// Request status type
+class OsclAOStatus
+{
+ public:
+ OsclAOStatus();
+ explicit OsclAOStatus(int32 aStatus);
+ int32 operator=(int32 aStatus);
+ int32 operator==(int32 aStatus) const;
+ int32 operator!=(int32 aStatus) const;
+ int32 operator>=(int32 aStatus) const;
+ int32 operator<=(int32 aStatus) const;
+ int32 operator>(int32 aStatus) const;
+ int32 operator<(int32 aStatus) const;
+ int32 Value() const;
+ private:
+ int32 iStatus;
+};
+
+#endif // M4V_H263_DECODER_PV_TYPES_H_
diff --git a/media/codecs/m4v_h263/dec/include/mp4dec_api.h b/media/codecs/m4v_h263/dec/include/mp4dec_api.h
new file mode 100644
index 0000000..06aee07
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/include/mp4dec_api.h
@@ -0,0 +1,181 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _MP4DEC_API_H_
+#define _MP4DEC_API_H_
+
+#include "m4vh263_decoder_pv_types.h"
+
+// #define PV_TOLERATE_VOL_ERRORS
+#define PV_MEMORY_POOL
+
+#ifndef _PV_TYPES_
+#define _PV_TYPES_
+
+typedef uint Bool;
+
+#define PV_CODEC_INIT 0
+#define PV_CODEC_STOP 1
+#endif
+
+#define PV_TRUE 1
+#define PV_FALSE 0
+
+#ifndef OSCL_IMPORT_REF
+#define OSCL_IMPORT_REF /* empty */
+#endif
+#ifndef OSCL_EXPORT_REF
+#define OSCL_EXPORT_REF /* empty */
+#endif
+
+
+#define PV_NO_POST_PROC 0
+#define PV_DEBLOCK 1
+#define PV_DERING 2
+
+
+
+#include "visual_header.h" // struct VolInfo is defined
+
+
+/**@name Structure and Data Types
+ * These type definitions specify the input / output from the PVMessage
+ * library.
+ */
+
+/*@{*/
+/* The application has to allocate space for this structure */
+typedef struct tagOutputFrame
+{
+ uint8 *data; /* pointer to output YUV buffer */
+ uint32 timeStamp; /* time stamp */
+} OutputFrame;
+
+typedef struct tagApplicationData
+{
+ int layer; /* current video layer */
+ void *object; /* some optional data field */
+} applicationData;
+
+/* Application controls, this structed shall be allocated */
+/* and initialized in the application. */
+typedef struct tagvideoDecControls
+{
+ /* The following fucntion pointer is copied to BitstreamDecVideo structure */
+ /* upon initialization and never used again. */
+ int (*readBitstreamData)(uint8 *buf, int nbytes_required, void *appData);
+ applicationData appData;
+
+ uint8 *outputFrame;
+ void *videoDecoderData; /* this is an internal pointer that is only used */
+ /* in the decoder library. */
+#ifdef PV_MEMORY_POOL
+ int32 size;
+#endif
+ int nLayers;
+ /* pointers to VOL data for frame-based decoding. */
+ uint8 *volbuf[2]; /* maximum of 2 layers for now */
+ int32 volbuf_size[2];
+
+} VideoDecControls;
+
+typedef enum
+{
+ H263_MODE = 0, MPEG4_MODE, UNKNOWN_MODE
+} MP4DecodingMode;
+
+typedef enum
+{
+ MP4_I_FRAME, MP4_P_FRAME, MP4_B_FRAME, MP4_BAD_FRAME
+} MP4FrameType;
+
+typedef struct tagVopHeaderInfo
+{
+ int currLayer;
+ uint32 timestamp;
+ MP4FrameType frameType;
+ int refSelCode;
+ int16 quantizer;
+} VopHeaderInfo;
+
+/*--------------------------------------------------------------------------*
+ * VideoRefCopyInfo:
+ * OMAP DSP specific typedef structure, to support the user (ARM) copying
+ * of a Reference Frame into the Video Decoder.
+ *--------------------------------------------------------------------------*/
+typedef struct tagVideoRefCopyInfoPtr
+{
+ uint8 *yChan; /* The Y component frame the user can copy a new reference to */
+ uint8 *uChan; /* The U component frame the user can copy a new reference to */
+ uint8 *vChan; /* The V component frame the user can copy a new reference to */
+ uint8 *currentVop; /* The Vop for video the user can copy a new reference to */
+} VideoRefCopyInfoPtr;
+
+typedef struct tagVideoRefCopyInfoData
+{
+ int16 width; /* Width */
+ int16 height; /* Height */
+ int16 realWidth; /* Non-padded width, not a multiple of 16. */
+ int16 realHeight; /* Non-padded height, not a multiple of 16. */
+} VideoRefCopyInfoData;
+
+typedef struct tagVideoRefCopyInfo
+{
+ VideoRefCopyInfoData data;
+ VideoRefCopyInfoPtr ptrs;
+} VideoRefCopyInfo;
+
+/*@}*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ OSCL_IMPORT_REF Bool PVInitVideoDecoder(VideoDecControls *decCtrl, uint8 *volbuf[], int32 *volbuf_size, int nLayers, int width, int height, MP4DecodingMode mode);
+ Bool PVAllocVideoData(VideoDecControls *decCtrl, int width, int height, int nLayers);
+ OSCL_IMPORT_REF Bool PVCleanUpVideoDecoder(VideoDecControls *decCtrl);
+ Bool PVResetVideoDecoder(VideoDecControls *decCtrl);
+ OSCL_IMPORT_REF void PVSetReferenceYUV(VideoDecControls *decCtrl, uint8 *refYUV);
+ Bool PVDecSetReference(VideoDecControls *decCtrl, uint8 *refYUV, uint32 timestamp);
+ Bool PVDecSetEnhReference(VideoDecControls *decCtrl, uint8 *refYUV, uint32 timestamp);
+ OSCL_IMPORT_REF Bool PVDecodeVideoFrame(VideoDecControls *decCtrl, uint8 *bitstream[], uint32 *timestamp, int32 *buffer_size, uint use_ext_timestamp[], uint8* currYUV);
+ Bool PVDecodeVopHeader(VideoDecControls *decCtrl, uint8 *buffer[], uint32 timestamp[], int32 buffer_size[], VopHeaderInfo *header_info, uint use_ext_timestamp[], uint8 *currYUV);
+ Bool PVDecodeVopBody(VideoDecControls *decCtrl, int32 buffer_size[]);
+ void PVDecPostProcess(VideoDecControls *decCtrl, uint8 *outputYUV);
+ OSCL_IMPORT_REF void PVGetVideoDimensions(VideoDecControls *decCtrl, int32 *display_width, int32 *display_height);
+ OSCL_IMPORT_REF void PVGetBufferDimensions(VideoDecControls *decCtrl, int32 *buf_width, int32 *buf_height);
+ OSCL_IMPORT_REF void PVSetPostProcType(VideoDecControls *decCtrl, int mode);
+ uint32 PVGetVideoTimeStamp(VideoDecControls *decoderControl);
+ int PVGetDecBitrate(VideoDecControls *decCtrl);
+ int PVGetDecFramerate(VideoDecControls *decCtrl);
+ uint8 *PVGetDecOutputFrame(VideoDecControls *decCtrl);
+ int PVGetLayerID(VideoDecControls *decCtrl);
+ int32 PVGetDecMemoryUsage(VideoDecControls *decCtrl);
+ OSCL_IMPORT_REF MP4DecodingMode PVGetDecBitstreamMode(VideoDecControls *decCtrl);
+ Bool PVExtractVolHeader(uint8 *video_buffer, uint8 *vol_header, int32 *vol_header_size);
+ int32 PVLocateFrameHeader(uint8 *video_buffer, int32 vop_size);
+ int32 PVLocateH263FrameHeader(uint8 *video_buffer, int32 vop_size);
+ Bool PVGetVolInfo(VideoDecControls *decCtrl, VolInfo *pVolInfo); // BX 6/24/04
+ Bool IsIntraFrame(VideoDecControls *decoderControl);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _MP4DEC_API_H_ */
+
diff --git a/media/codecs/m4v_h263/dec/include/visual_header.h b/media/codecs/m4v_h263/dec/include/visual_header.h
new file mode 100644
index 0000000..48da0dc
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/include/visual_header.h
@@ -0,0 +1,51 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _VISUAL_HEADER_H
+#define _VISUAL_HEADER_H
+
+#ifndef _PV_TYPES_ // In order to compile in MDF wrapper
+#define _PV_TYPES_
+
+#include "m4vh263_decoder_pv_types.h"
+
+typedef uint Bool;
+
+#endif // #ifndef _PV_TYPES_
+
+
+typedef struct tagVolInfo
+{
+ int32 shortVideoHeader; /* shortVideoHeader mode */
+
+ /* Error Resilience Flags */
+ int32 errorResDisable; /* VOL disable error resilence mode(Use Resynch markers) */
+ int32 useReverseVLC; /* VOL reversible VLCs */
+ int32 dataPartitioning; /* VOL data partitioning */
+
+ /* Parameters used for scalability */
+ int32 scalability; /* VOL scalability (flag) */
+
+ int32 nbitsTimeIncRes; /* number of bits for time increment () */
+
+ int32 profile_level_id; /* profile and level */
+
+
+} VolInfo;
+
+#endif // #ifndef _VISUAL_HEADER_H
+
diff --git a/media/codecs/m4v_h263/dec/src/bitstream.cpp b/media/codecs/m4v_h263/dec/src/bitstream.cpp
new file mode 100644
index 0000000..37250f3
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/bitstream.cpp
@@ -0,0 +1,1001 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "bitstream.h"
+#include "mp4dec_lib.h"
+
+
+#define OSCL_DISABLE_WARNING_CONDITIONAL_IS_CONSTANT
+/* to mask the n least significant bits of an integer */
+static const uint32 msk[33] =
+{
+ 0x00000000, 0x00000001, 0x00000003, 0x00000007,
+ 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
+ 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
+ 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
+ 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
+ 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
+ 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
+ 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
+ 0xffffffff
+};
+
+
+/* ======================================================================== */
+/* Function : BitstreamFillCache() */
+/* Date : 08/29/2000 */
+/* Purpose : Read more bitstream data into buffer & the 24-byte cache. */
+/* This function is different from BitstreamFillBuffer in */
+/* that the buffer is the frame-based buffer provided by */
+/* the application. */
+/* In/out : */
+/* Return : PV_SUCCESS if successed, PV_FAIL if failed. */
+/* Modified : 4/16/01 : removed return of PV_END_OF_BUFFER */
+/* ======================================================================== */
+PV_STATUS BitstreamFillCache(BitstreamDecVideo *stream)
+{
+ uint8 *bitstreamBuffer = stream->bitstreamBuffer;
+ uint8 *v;
+ int num_bits, i;
+
+ stream->curr_word |= (stream->next_word >> stream->incnt); // stream->incnt cannot be 32
+ stream->next_word <<= (31 - stream->incnt);
+ stream->next_word <<= 1;
+ num_bits = stream->incnt_next + stream->incnt;
+ if (num_bits >= 32)
+ {
+ stream->incnt_next -= (32 - stream->incnt);
+ stream->incnt = 32;
+ return PV_SUCCESS;
+ }
+ /* this check can be removed if there is additional extra 4 bytes at the end of the bitstream */
+ v = bitstreamBuffer + stream->read_point;
+
+ if (stream->read_point > stream->data_end_pos - 4)
+ {
+ if (stream->data_end_pos <= stream->read_point)
+ {
+ stream->incnt = num_bits;
+ stream->incnt_next = 0;
+ return PV_SUCCESS;
+ }
+
+ stream->next_word = 0;
+
+ for (i = 0; i < stream->data_end_pos - stream->read_point; i++)
+ {
+ stream->next_word |= (v[i] << ((3 - i) << 3));
+ }
+
+ stream->read_point = stream->data_end_pos;
+ stream->curr_word |= (stream->next_word >> num_bits); // this is safe
+
+ stream->next_word <<= (31 - num_bits);
+ stream->next_word <<= 1;
+ num_bits = i << 3;
+ stream->incnt += stream->incnt_next;
+ stream->incnt_next = num_bits - (32 - stream->incnt);
+ if (stream->incnt_next < 0)
+ {
+ stream->incnt += num_bits;
+ stream->incnt_next = 0;
+ }
+ else
+ {
+ stream->incnt = 32;
+ }
+ return PV_SUCCESS;
+ }
+
+ stream->next_word = ((uint32)v[0] << 24) | (v[1] << 16) | (v[2] << 8) | v[3];
+ stream->read_point += 4;
+
+ stream->curr_word |= (stream->next_word >> num_bits); // this is safe
+ stream->next_word <<= (31 - num_bits);
+ stream->next_word <<= 1;
+ stream->incnt_next += stream->incnt;
+ stream->incnt = 32;
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : BitstreamReset() */
+/* Date : 08/29/2000 */
+/* Purpose : Initialize the bitstream buffer for frame-based decoding. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+void BitstreamReset(BitstreamDecVideo *stream, uint8 *buffer, int32 buffer_size)
+{
+ /* set up frame-based bitstream buffer */
+ oscl_memset(stream, 0, sizeof(BitstreamDecVideo));
+ stream->data_end_pos = buffer_size;
+ stream->bitstreamBuffer = buffer;
+}
+
+
+/* ======================================================================== */
+/* Function : BitstreamOpen() */
+/* Purpose : Initialize the bitstream data structure. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+int BitstreamOpen(BitstreamDecVideo *stream, int)
+{
+ int buffer_size = 0;
+ /* set up linear bitstream buffer */
+// stream->currentBytePos = 0;
+ stream->data_end_pos = 0;
+
+ stream->incnt = 0;
+ stream->incnt_next = 0;
+ stream->bitcnt = 0;
+ stream->curr_word = stream->next_word = 0;
+ stream->read_point = stream->data_end_pos;
+ return buffer_size;
+}
+
+
+/* ======================================================================== */
+/* Function : BitstreamClose() */
+/* Purpose : Cleanup the bitstream data structure. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+void BitstreamClose(BitstreamDecVideo *)
+{
+ return;
+}
+
+
+/***********************************************************CommentBegin******
+*
+* -- BitstreamShowBits32HC
+* Shows 32 bits
+***********************************************************CommentEnd********/
+
+PV_STATUS BitstreamShowBits32HC(BitstreamDecVideo *stream, uint32 *code)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+ if (stream->incnt < 32)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ *code = stream->curr_word;
+ return status;
+}
+
+/***********************************************************CommentBegin******
+*
+* -- BitstreamShowBits32
+* Shows upto and including 31 bits
+***********************************************************CommentEnd********/
+PV_STATUS BitstreamShowBits32(BitstreamDecVideo *stream, int nbits, uint32 *code)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+ if (stream->incnt < nbits)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ *code = stream->curr_word >> (32 - nbits);
+ return status;
+}
+
+
+#ifndef PV_BS_INLINE
+/*========================================================================= */
+/* Function: BitstreamShowBits16() */
+/* Date: 12/18/2000 */
+/* Purpose: To see the next "nbits"(nbits<=16) bitstream bits */
+/* without advancing the read pointer */
+/* */
+/* =========================================================================*/
+PV_STATUS BitstreamShowBits16(BitstreamDecVideo *stream, int nbits, uint *code)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+
+ if (stream->incnt < nbits)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+
+ *code = stream->curr_word >> (32 - nbits);
+ return status;
+}
+
+
+/*========================================================================= */
+/* Function: BitstreamShow15Bits() */
+/* Date: 01/23/2001 */
+/* Purpose: To see the next 15 bitstream bits */
+/* without advancing the read pointer */
+/* */
+/* =========================================================================*/
+PV_STATUS BitstreamShow15Bits(BitstreamDecVideo *stream, uint *code)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+ if (stream->incnt < 15)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ *code = stream->curr_word >> 17;
+ return status;
+}
+/*========================================================================= */
+/* Function: BitstreamShow13Bits */
+/* Date: 050923 */
+/* Purpose: Faciliate and speed up showing 13 bit from bitstream */
+/* used in VlcTCOEFF decoding */
+/* Modified: */
+/* =========================================================================*/
+PV_STATUS BitstreamShow13Bits(BitstreamDecVideo *stream, uint *code)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+ if (stream->incnt < 13)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ *code = stream->curr_word >> 19;
+ return status;
+}
+
+uint BitstreamReadBits16_INLINE(BitstreamDecVideo *stream, int nbits)
+{
+ uint code;
+ PV_STATUS status;
+
+ if (stream->incnt < nbits)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ code = stream->curr_word >> (32 - nbits);
+ PV_BitstreamFlushBits(stream, nbits);
+ return code;
+}
+
+
+uint BitstreamRead1Bits_INLINE(BitstreamDecVideo *stream)
+{
+ PV_STATUS status = PV_SUCCESS;
+ uint code;
+
+
+ if (stream->incnt < 1)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ code = stream->curr_word >> 31;
+ PV_BitstreamFlushBits(stream, 1);
+
+ return code;
+}
+
+#endif
+
+/* ======================================================================== */
+/* Function : BitstreamReadBits16() */
+/* Purpose : Read bits (nbits <=16) from bitstream buffer. */
+/* In/out : */
+/* Return : */
+/* ======================================================================== */
+uint BitstreamReadBits16(BitstreamDecVideo *stream, int nbits)
+{
+ uint code;
+
+ if (stream->incnt < nbits)
+ {
+ /* frame-based decoding */
+ BitstreamFillCache(stream);
+ }
+ code = stream->curr_word >> (32 - nbits);
+ PV_BitstreamFlushBits(stream, nbits);
+ return code;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamRead1Bits() */
+/* Date : 10/23/2000 */
+/* Purpose : Faciliate and speed up reading 1 bit from bitstream. */
+/* In/out : */
+/* Return : */
+/* ======================================================================== */
+
+uint BitstreamRead1Bits(BitstreamDecVideo *stream)
+{
+ uint code;
+
+ if (stream->incnt < 1)
+ {
+ /* frame-based decoding */
+ BitstreamFillCache(stream);
+ }
+ code = stream->curr_word >> 31;
+ PV_BitstreamFlushBits(stream, 1);
+
+ return code;
+}
+
+/* ======================================================================== */
+/* Function : PV_BitstreamFlushBitsCheck() */
+/* Purpose : Flush nbits bits from bitstream buffer. Check for cache */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS PV_BitstreamFlushBitsCheck(BitstreamDecVideo *stream, int nbits)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+ stream->bitcnt += nbits;
+ stream->incnt -= nbits;
+ if (stream->incnt < 0)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+
+ if (stream->incnt < 0)
+ {
+ stream->bitcnt += stream->incnt;
+ stream->incnt = 0;
+ }
+ }
+ stream->curr_word <<= nbits;
+ return status;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamReadBits32() */
+/* Purpose : Read bits from bitstream buffer. */
+/* In/out : */
+/* Return : */
+/* ======================================================================== */
+uint32 BitstreamReadBits32(BitstreamDecVideo *stream, int nbits)
+{
+ uint32 code;
+
+ if (stream->incnt < nbits)
+ {
+ /* frame-based decoding */
+ BitstreamFillCache(stream);
+ }
+ code = stream->curr_word >> (32 - nbits);
+ PV_BitstreamFlushBits(stream, nbits);
+ return code;
+}
+
+uint32 BitstreamReadBits32HC(BitstreamDecVideo *stream)
+{
+ uint32 code;
+
+ BitstreamShowBits32HC(stream, &code);
+ stream->bitcnt += 32;
+ stream->incnt = 0;
+ stream->curr_word = 0;
+ return code;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamCheckEndBuffer() */
+/* Date : 03/30/2001 */
+/* Purpose : Check to see if we are at the end of buffer */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS BitstreamCheckEndBuffer(BitstreamDecVideo *stream)
+{
+ if (stream->read_point >= stream->data_end_pos && stream->incnt <= 0) return PV_END_OF_VOP;
+ return PV_SUCCESS;
+}
+
+
+PV_STATUS PV_BitstreamShowBitsByteAlign(BitstreamDecVideo *stream, int nbits, uint32 *code)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+ int n_stuffed;
+
+ n_stuffed = 8 - (stream->bitcnt & 0x7); /* 07/05/01 */
+
+ if (stream->incnt < (nbits + n_stuffed))
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+
+ *code = (stream->curr_word << n_stuffed) >> (32 - nbits);
+ return status;
+}
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+PV_STATUS PV_BitstreamShowBitsByteAlignNoForceStuffing(BitstreamDecVideo *stream, int nbits, uint32 *code)
+{
+ PV_STATUS status = PV_SUCCESS;
+
+ int n_stuffed;
+
+ n_stuffed = (8 - (stream->bitcnt & 0x7)) & 7;
+
+ if (stream->incnt < (nbits + n_stuffed))
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+
+ *code = (stream->curr_word << n_stuffed) >> (32 - nbits);
+ return status;
+}
+#endif
+
+PV_STATUS PV_BitstreamByteAlign(BitstreamDecVideo *stream)
+{
+ PV_STATUS status = PV_SUCCESS;
+ int n_stuffed;
+
+ n_stuffed = 8 - (stream->bitcnt & 0x7); /* 07/05/01 */
+
+ /* We have to make sure we have enough bits in the cache. 08/15/2000 */
+ if (stream->incnt < n_stuffed)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+
+
+ stream->bitcnt += n_stuffed;
+ stream->incnt -= n_stuffed;
+ stream->curr_word <<= n_stuffed;
+ if (stream->incnt < 0)
+ {
+ stream->bitcnt += stream->incnt;
+ stream->incnt = 0;
+ }
+ return status;
+}
+
+
+PV_STATUS BitstreamByteAlignNoForceStuffing(BitstreamDecVideo *stream)
+{
+ uint n_stuffed;
+
+ n_stuffed = (8 - (stream->bitcnt & 0x7)) & 0x7; /* 07/05/01 */
+
+ stream->bitcnt += n_stuffed;
+ stream->incnt -= n_stuffed;
+
+ if (stream->incnt < 0)
+ {
+ stream->bitcnt += stream->incnt;
+ stream->incnt = 0;
+ }
+ stream->curr_word <<= n_stuffed;
+ return PV_SUCCESS;
+}
+
+
+/* ==================================================================== */
+/* Function : getPointer() */
+/* Date : 10/98 */
+/* Purpose : get current position of file pointer */
+/* In/out : */
+/* Return : */
+/* ==================================================================== */
+int32 getPointer(BitstreamDecVideo *stream)
+{
+ return stream->bitcnt;
+}
+
+
+
+
+/* ====================================================================== /
+Function : movePointerTo()
+Date : 05/14/2004
+Purpose : move bitstream pointer to a desired position
+In/out :
+Return :
+Modified :
+/ ====================================================================== */
+PV_STATUS movePointerTo(BitstreamDecVideo *stream, int32 pos)
+{
+ int32 byte_pos;
+ if (pos < 0)
+ {
+ pos = 0;
+ }
+
+ byte_pos = pos >> 3;
+
+ if (byte_pos > stream->data_end_pos)
+ {
+ byte_pos = stream->data_end_pos;
+ }
+
+ stream->read_point = byte_pos & -4;
+ stream->bitcnt = stream->read_point << 3;;
+ stream->curr_word = 0;
+ stream->next_word = 0;
+ stream->incnt = 0;
+ stream->incnt_next = 0;
+ BitstreamFillCache(stream);
+ PV_BitstreamFlushBits(stream, ((pos & 0x7) + ((byte_pos & 0x3) << 3)));
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : validStuffing() */
+/* Date : 04/11/2000 */
+/* Purpose : Check whether we have valid stuffing at current position. */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : 12/18/2000 : changed the pattern type to uint */
+/* 04/01/2001 : removed PV_END_OF_BUFFER */
+/* ======================================================================== */
+Bool validStuffing(BitstreamDecVideo *stream)
+{
+ uint n_stuffed;
+ uint pattern;
+
+
+ n_stuffed = 8 - (stream->bitcnt & 0x7);
+ BitstreamShowBits16(stream, n_stuffed, &pattern);
+ if (pattern == msk[n_stuffed-1]) return PV_TRUE;
+ return PV_FALSE;
+}
+#ifdef PV_ANNEX_IJKT_SUPPORT
+Bool validStuffing_h263(BitstreamDecVideo *stream)
+{
+ uint n_stuffed;
+ uint pattern;
+
+
+ n_stuffed = (8 - (stream->bitcnt & 0x7)) & 7; // stream->incnt % 8
+ if (n_stuffed == 0)
+ {
+ return PV_TRUE;
+ }
+ BitstreamShowBits16(stream, n_stuffed, &pattern);
+ if (pattern == 0) return PV_TRUE;
+ return PV_FALSE;
+}
+#endif
+
+
+/* ======================================================================== */
+/* Function : PVSearchNextH263Frame() */
+/* Date : 04/08/2005 */
+/* Purpose : search for 0x00 0x00 0x80 */
+/* In/out : */
+/* Return : PV_SUCCESS if succeeded or PV_END_OF_VOP if failed */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS PVSearchNextH263Frame(BitstreamDecVideo *stream)
+{
+ PV_STATUS status = PV_SUCCESS;
+ uint8 *ptr;
+ int32 i;
+ int32 initial_byte_aligned_position = (stream->bitcnt + 7) >> 3;
+
+ ptr = stream->bitstreamBuffer + initial_byte_aligned_position;
+
+ i = PVLocateH263FrameHeader(ptr, stream->data_end_pos - initial_byte_aligned_position);
+ if (stream->data_end_pos <= initial_byte_aligned_position + i)
+ {
+ status = PV_END_OF_VOP;
+ }
+ (void)movePointerTo(stream, ((i + initial_byte_aligned_position) << 3)); /* ptr + i */
+ return status;
+}
+
+
+/* ======================================================================== */
+/* Function : PVSearchNextM4VFrame() */
+/* Date : 04/08/2005 */
+/* Purpose : search for 0x00 0x00 0x01 and move the pointer to the */
+/* beginning of the start code */
+/* In/out : */
+/* Return : PV_SUCCESS if succeeded or PV_END_OF_VOP if failed */
+/* Modified : */
+/* ======================================================================== */
+
+PV_STATUS PVSearchNextM4VFrame(BitstreamDecVideo *stream)
+{
+ PV_STATUS status = PV_SUCCESS;
+ uint8 *ptr;
+ int32 i;
+ int32 initial_byte_aligned_position = (stream->bitcnt + 7) >> 3;
+
+ ptr = stream->bitstreamBuffer + initial_byte_aligned_position;
+
+ i = PVLocateFrameHeader(ptr, stream->data_end_pos - initial_byte_aligned_position);
+ if (stream->data_end_pos <= initial_byte_aligned_position + i)
+ {
+ status = PV_END_OF_VOP;
+ }
+ (void)movePointerTo(stream, ((i + initial_byte_aligned_position) << 3)); /* ptr + i */
+ return status;
+}
+
+
+
+void PVLocateM4VFrameBoundary(BitstreamDecVideo *stream)
+{
+ uint8 *ptr;
+ int32 byte_pos = (stream->bitcnt >> 3);
+
+ stream->searched_frame_boundary = 1;
+ ptr = stream->bitstreamBuffer + byte_pos;
+
+ stream->data_end_pos = PVLocateFrameHeader(ptr, (int32)stream->data_end_pos - byte_pos) + byte_pos;
+}
+
+void PVLocateH263FrameBoundary(BitstreamDecVideo *stream)
+{
+ uint8 *ptr;
+ int32 byte_pos = (stream->bitcnt >> 3);
+
+ stream->searched_frame_boundary = 1;
+ ptr = stream->bitstreamBuffer + byte_pos;
+
+ stream->data_end_pos = PVLocateH263FrameHeader(ptr, (int32)stream->data_end_pos - byte_pos) + byte_pos;
+}
+
+/* ======================================================================== */
+/* Function : quickSearchVideoPacketHeader() */
+/* Date : 05/08/2000 */
+/* Purpose : Quick search for the next video packet header */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS quickSearchVideoPacketHeader(BitstreamDecVideo *stream, int marker_length)
+{
+ PV_STATUS status = PV_SUCCESS;
+ uint32 tmpvar;
+
+
+ if (stream->searched_frame_boundary == 0)
+ {
+ PVLocateM4VFrameBoundary(stream);
+ }
+
+ do
+ {
+ status = BitstreamCheckEndBuffer(stream);
+ if (status == PV_END_OF_VOP) break;
+ PV_BitstreamShowBitsByteAlign(stream, marker_length, &tmpvar);
+ if (tmpvar == RESYNC_MARKER) break;
+ PV_BitstreamFlushBits(stream, 8);
+ }
+ while (status == PV_SUCCESS);
+
+ return status;
+}
+#ifdef PV_ANNEX_IJKT_SUPPORT
+PV_STATUS quickSearchH263SliceHeader(BitstreamDecVideo *stream)
+{
+ PV_STATUS status = PV_SUCCESS;
+ uint32 tmpvar;
+
+
+ if (stream->searched_frame_boundary == 0)
+ {
+ PVLocateH263FrameBoundary(stream);
+ }
+
+ do
+ {
+ status = BitstreamCheckEndBuffer(stream);
+ if (status == PV_END_OF_VOP) break;
+ PV_BitstreamShowBitsByteAlignNoForceStuffing(stream, 17, &tmpvar);
+ if (tmpvar == RESYNC_MARKER) break;
+ PV_BitstreamFlushBits(stream, 8);
+ }
+ while (status == PV_SUCCESS);
+
+ return status;
+}
+#endif
+/* ======================================================================== */
+/* The following functions are for Error Concealment. */
+/* ======================================================================== */
+
+/****************************************************/
+// 01/22/99 Quick search of Resync Marker
+// (actually the first part of it, i.e. 16 0's and a 1.
+
+/* We are not using the fastest algorithm possible. What this function does is
+to locate 11 consecutive 0's and then check if the 5 bits before them and
+the 1 bit after them are all 1's.
+*/
+
+// Table used for quick search of markers. Gives the last `1' in
+// 4 bits. The MSB is bit #1, the LSB is bit #4.
+const int lastOne[] =
+{
+ 0, 4, 3, 4, 2, 4, 3, 4,
+ 1, 4, 3, 4, 2, 4, 3, 4
+};
+
+// Table used for quick search of markers. Gives the last `0' in
+// 4 bits. The MSB is bit #1, the LSB is bit #4.
+/*const int lastZero[]=
+{
+ 4, 3, 4, 2, 4, 3, 4, 1,
+ 4, 3, 4, 2, 4, 3, 4, 0
+};
+*/
+// Table used for quick search of markers. Gives the first `0' in
+// 4 bits. The MSB is bit #1, the LSB is bit #4.
+const int firstZero[] =
+{
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 3, 3, 4, 0
+};
+
+// Table used for quick search of markers. Gives the first `1' in
+// 4 bits. The MSB is bit #1, the LSB is bit #4.
+const int firstOne[] =
+{
+ 0, 4, 3, 3, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1
+};
+
+
+/* ======================================================================== */
+/* Function : quickSearchMarkers() */
+/* Date : 01/25/99 */
+/* Purpose : Quick search for Motion marker */
+/* In/out : */
+/* Return : Boolean true of false */
+/* Modified : 12/18/2000 : 32-bit version */
+/* ======================================================================== */
+PV_STATUS quickSearchMotionMarker(BitstreamDecVideo *stream)
+// MM: (11111000000000001)
+{
+ PV_STATUS status;
+ uint32 tmpvar, tmpvar2;
+
+ if (stream->searched_frame_boundary == 0)
+ {
+ PVLocateM4VFrameBoundary(stream);
+ }
+
+ while (TRUE)
+ {
+ status = BitstreamCheckEndBuffer(stream);
+ if (status == PV_END_OF_VOP) return PV_END_OF_VOP;
+
+ BitstreamShowBits32(stream, 17, &tmpvar);
+ if (!tmpvar) return PV_FAIL;
+
+ if (tmpvar & 1) // Check if the 17th bit from the curr bit pos is a '1'
+ {
+ if (tmpvar == MOTION_MARKER_COMB)
+ {
+ return PV_SUCCESS; // Found
+ }
+ else
+ {
+ tmpvar >>= 1;
+ tmpvar &= 0xF;
+ PV_BitstreamFlushBits(stream, (int)(12 + firstZero[tmpvar]));
+ }
+ }
+ else
+ {
+ // 01/25/99 Get the first 16 bits
+ tmpvar >>= 1;
+ tmpvar2 = tmpvar & 0xF;
+
+ // 01/26/99 Check bits #13 ~ #16
+ if (tmpvar2)
+ {
+ PV_BitstreamFlushBits(stream, (int)(7 + lastOne[tmpvar2]));
+ }
+ else
+ {
+ tmpvar >>= 4;
+ tmpvar2 = tmpvar & 0xF;
+
+ // 01/26/99 Check bits #9 ~ #12
+ if (tmpvar2)
+ {
+ PV_BitstreamFlushBits(stream, (int)(3 + lastOne[tmpvar2]));
+ }
+ else
+ {
+ tmpvar >>= 4;
+ tmpvar2 = tmpvar & 0xF;
+
+ // 01/26/99 Check bits #5 ~ #8
+ // We don't need to check further
+ // for the first 5 bits should be all 1's
+ if (lastOne[tmpvar2] < 2)
+ {
+ /* we already have too many consecutive 0's. */
+ /* Go directly pass the last of the 17 bits. */
+ PV_BitstreamFlushBits(stream, 17);
+ }
+ else
+ {
+ PV_BitstreamFlushBits(stream, (int)(lastOne[tmpvar2] - 1));
+ }
+ }
+ }
+ }
+
+ }
+}
+
+/* ======================================================================== */
+/* Function : quickSearchDCM() */
+/* Date : 01/22/99 */
+/* Purpose : Quick search for DC Marker */
+/* We are not using the fastest algorithm possible. What this */
+/* function does is to locate 11 consecutive 0's and then */
+/* check if the 7 bits before them and the 1 bit after them */
+/* are correct. (actually the first part of it, i.e. 16 0's */
+/* and a 1. */
+/* In/out : */
+/* Return : Boolean true of false */
+/* Modified : 12/18/2000 : 32-bit version */
+/* ======================================================================== */
+PV_STATUS quickSearchDCM(BitstreamDecVideo *stream)
+// DCM: (110 1011 0000 0000 0001)
+{
+ PV_STATUS status;
+ uint32 tmpvar, tmpvar2;
+
+ if (stream->searched_frame_boundary == 0)
+ {
+ PVLocateM4VFrameBoundary(stream);
+ }
+
+ while (TRUE)
+ {
+ status = BitstreamCheckEndBuffer(stream);
+ if (status == PV_END_OF_VOP) return PV_END_OF_VOP;
+ BitstreamShowBits32(stream, 19, &tmpvar);
+
+ if (tmpvar & 1) // Check if the 17th bit from the curr bit pos is a '1'
+ {
+ if (tmpvar == DC_MARKER)
+ {
+ return PV_SUCCESS; // Found
+ }
+ else
+ {
+ // 01/25/99 We treat the last of the 19 bits as its 7th bit (which is
+ // also a `1'
+ PV_BitstreamFlushBits(stream, 12);
+ }
+ }
+ else
+ {
+ tmpvar >>= 1;
+ tmpvar2 = tmpvar & 0xF;
+
+ if (tmpvar2)
+ {
+ PV_BitstreamFlushBits(stream, (int)(7 + lastOne[tmpvar2]));
+ }
+ else
+ {
+ tmpvar >>= 4;
+ tmpvar2 = tmpvar & 0xF;
+ if (tmpvar2)
+ {
+ PV_BitstreamFlushBits(stream, (int)(3 + lastOne[tmpvar2]));
+ }
+ else
+ {
+ tmpvar >>= 4;
+ tmpvar2 = tmpvar & 0xF;
+ if (lastOne[tmpvar2] < 2)
+ {
+ /* we already have too many consecutive 0's. */
+ /* Go directly pass the last of the 17 bits. */
+ PV_BitstreamFlushBits(stream, 19);
+ }
+ else
+ {
+ PV_BitstreamFlushBits(stream, (int)(lastOne[tmpvar2] - 1));
+ }
+ }
+ }
+ }
+ }
+}
+
+/* ======================================================================== */
+/* Function : quickSearchGOBHeader() 0000 0000 0000 0000 1 */
+/* Date : 07/06/01 */
+/* Purpose : Quick search of GOBHeader (not byte aligned) */
+/* In/out : */
+/* Return : Integer value indicates type of marker found */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS quickSearchGOBHeader(BitstreamDecVideo *stream)
+{
+ PV_STATUS status;
+ int byte0, byte1, byte2, shift, tmpvar;
+
+ BitstreamByteAlignNoForceStuffing(stream);
+
+ if (stream->searched_frame_boundary == 0)
+ {
+ PVLocateH263FrameBoundary(stream);
+ }
+
+ while (TRUE)
+ {
+ status = BitstreamCheckEndBuffer(stream);
+ if (status == PV_END_OF_VOP) return PV_END_OF_VOP;
+
+ if (stream->incnt < 24)
+ {
+ status = BitstreamFillCache(stream);
+ }
+
+
+ byte1 = (stream->curr_word << 8) >> 24;
+ if (byte1 == 0)
+ {
+ byte2 = (stream->curr_word << 16) >> 24;
+ if (byte2)
+ {
+ tmpvar = byte2 >> 4;
+
+ if (tmpvar)
+ {
+ shift = 9 - firstOne[tmpvar];
+ }
+ else
+ {
+ shift = 5 - firstOne[byte2];
+ }
+ byte0 = stream->curr_word >> 24;
+ if ((byte0 & msk[shift]) == 0)
+ {
+ PV_BitstreamFlushBits(stream, 8 - shift);
+ return PV_SUCCESS;
+ }
+ PV_BitstreamFlushBits(stream, 8); /* third_byte is not zero */
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, 8);
+ }
+}
diff --git a/media/codecs/m4v_h263/dec/src/bitstream.h b/media/codecs/m4v_h263/dec/src/bitstream.h
new file mode 100644
index 0000000..d52fa87
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/bitstream.h
@@ -0,0 +1,174 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#ifndef _BITSTREAM_D_H_
+#define _BITSTREAM_D_H_
+
+#include "mp4dec_lib.h" /* video decoder function prototypes */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#define PV_BS_INLINE /* support inline bitstream functions */
+
+#define PV_BitstreamFlushBits(A,B) {(A)->bitcnt += (B); (A)->incnt -= (B); (A)->curr_word <<= (B);}
+
+ PV_STATUS BitstreamFillBuffer(BitstreamDecVideo *stream);
+ PV_STATUS BitstreamFillCache(BitstreamDecVideo *stream);
+ void BitstreamReset(BitstreamDecVideo *stream, uint8 *buffer, int32 buffer_size);
+ int BitstreamOpen(BitstreamDecVideo *stream, int layer);
+ void BitstreamClose(BitstreamDecVideo *stream);
+
+ PV_STATUS BitstreamShowBits32(BitstreamDecVideo *stream, int nbits, uint32 *code);
+ uint32 BitstreamReadBits32(BitstreamDecVideo *stream, int nbits);
+
+ uint BitstreamReadBits16(BitstreamDecVideo *stream, int nbits);
+ uint BitstreamRead1Bits(BitstreamDecVideo *stream);
+#ifndef PV_BS_INLINE
+ PV_STATUS BitstreamShowBits16(BitstreamDecVideo *stream, int nbits, uint *code);
+ PV_STATUS BitstreamShow15Bits(BitstreamDecVideo *stream, uint *code);
+ PV_STATUS BitstreamShow13Bits(BitstreamDecVideo *stream, uint *code);
+ uint BitstreamReadBits16_INLINE(BitstreamDecVideo *stream, int nbits);
+ uint BitstreamRead1Bits_INLINE(BitstreamDecVideo *stream);
+#else
+ __inline PV_STATUS BitstreamShowBits16(BitstreamDecVideo *stream, int nbits, uint *code)
+ {
+ PV_STATUS status = PV_SUCCESS;
+
+
+ if (stream->incnt < nbits)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+
+ *code = stream->curr_word >> (32 - nbits);
+ return status;
+ }
+
+
+
+ /* =========================================================================*/
+ __inline PV_STATUS BitstreamShow15Bits(BitstreamDecVideo *stream, uint *code)
+ {
+ PV_STATUS status = PV_SUCCESS;
+
+ if (stream->incnt < 15)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ *code = stream->curr_word >> 17;
+ return status;
+ }
+
+
+ __inline PV_STATUS BitstreamShow13Bits(BitstreamDecVideo *stream, uint *code)
+ {
+ PV_STATUS status = PV_SUCCESS;
+
+ if (stream->incnt < 13)
+ {
+ /* frame-based decoding */
+ status = BitstreamFillCache(stream);
+ }
+ *code = stream->curr_word >> 19;
+ return status;
+ }
+ __inline uint BitstreamReadBits16_INLINE(BitstreamDecVideo *stream, int nbits)
+ {
+ uint code;
+
+ if (stream->incnt < nbits)
+ {
+ /* frame-based decoding */
+ BitstreamFillCache(stream);
+ }
+ code = stream->curr_word >> (32 - nbits);
+ PV_BitstreamFlushBits(stream, nbits);
+ return code;
+ }
+
+
+ __inline uint BitstreamRead1Bits_INLINE(BitstreamDecVideo *stream)
+ {
+ uint code;
+
+ if (stream->incnt < 1)
+ {
+ /* frame-based decoding */
+ BitstreamFillCache(stream);
+ }
+ code = stream->curr_word >> 31;
+ PV_BitstreamFlushBits(stream, 1);
+
+ return code;
+ }
+
+#endif
+
+
+
+
+
+
+
+ PV_STATUS PV_BitstreamFlushBitsCheck(BitstreamDecVideo *stream, int nbits);
+
+ uint32 BitstreamReadBits32HC(BitstreamDecVideo *stream);
+ PV_STATUS BitstreamShowBits32HC(BitstreamDecVideo *stream, uint32 *code);
+
+
+
+ PV_STATUS BitstreamCheckEndBuffer(BitstreamDecVideo *stream);
+
+ PV_STATUS PV_BitstreamShowBitsByteAlign(BitstreamDecVideo *stream, int nbits, uint32 *code);
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ PV_STATUS PV_BitstreamShowBitsByteAlignNoForceStuffing(BitstreamDecVideo *stream, int nbits, uint32 *code);
+ Bool validStuffing_h263(BitstreamDecVideo *stream);
+ PV_STATUS quickSearchH263SliceHeader(BitstreamDecVideo *stream);
+#endif
+ PV_STATUS PV_BitstreamByteAlign(BitstreamDecVideo *stream);
+ PV_STATUS BitstreamByteAlignNoForceStuffing(BitstreamDecVideo *stream);
+ Bool validStuffing(BitstreamDecVideo *stream);
+
+ PV_STATUS movePointerTo(BitstreamDecVideo *stream, int32 pos);
+ PV_STATUS PVSearchNextM4VFrame(BitstreamDecVideo *stream);
+ PV_STATUS PVSearchNextH263Frame(BitstreamDecVideo *stream);
+ PV_STATUS quickSearchVideoPacketHeader(BitstreamDecVideo *stream, int marker_length);
+
+
+ /* for error concealment & soft-decoding */
+ void PVLocateM4VFrameBoundary(BitstreamDecVideo *stream);
+ void PVSearchH263FrameBoundary(BitstreamDecVideo *stream);
+
+ PV_STATUS quickSearchMotionMarker(BitstreamDecVideo *stream);
+ PV_STATUS quickSearchDCM(BitstreamDecVideo *stream);
+ PV_STATUS quickSearchGOBHeader(BitstreamDecVideo *stream);
+ void BitstreamShowBuffer(BitstreamDecVideo *stream, int32 startbit, int32 endbit, uint8 *bitBfr);
+
+ /* 10/8/98 New prototyps. */
+ int32 getPointer(BitstreamDecVideo *stream);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _BITSTREAM_D_H_ */
diff --git a/media/codecs/m4v_h263/dec/src/block_idct.cpp b/media/codecs/m4v_h263/dec/src/block_idct.cpp
new file mode 100644
index 0000000..bc708e2
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/block_idct.cpp
@@ -0,0 +1,914 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ [input_variable_name] = [description of the input to module, its type
+ definition, and length (when applicable)]
+
+ Local Stores/Buffers/Pointers Needed:
+ [local_store_name] = [description of the local store, its type
+ definition, and length (when applicable)]
+ [local_buffer_name] = [description of the local buffer, its type
+ definition, and length (when applicable)]
+ [local_ptr_name] = [description of the local pointer, its type
+ definition, and length (when applicable)]
+
+ Global Stores/Buffers/Pointers Needed:
+ [global_store_name] = [description of the global store, its type
+ definition, and length (when applicable)]
+ [global_buffer_name] = [description of the global buffer, its type
+ definition, and length (when applicable)]
+ [global_ptr_name] = [description of the global pointer, its type
+ definition, and length (when applicable)]
+
+ Outputs:
+ [return_variable_name] = [description of data/pointer returned
+ by module, its type definition, and length
+ (when applicable)]
+
+ Pointers and Buffers Modified:
+ [variable_bfr_ptr] points to the [describe where the
+ variable_bfr_ptr points to, its type definition, and length
+ (when applicable)]
+ [variable_bfr] contents are [describe the new contents of
+ variable_bfr]
+
+ Local Stores Modified:
+ [local_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+ Global Stores Modified:
+ [global_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+#include "idct.h"
+#include "motion_comp.h"
+
+#define OSCL_DISABLE_WARNING_CONV_POSSIBLE_LOSS_OF_DATA
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+/* private prototypes */
+static void idctrow(int16 *blk, uint8 *pred, uint8 *dst, int width);
+static void idctrow_intra(int16 *blk, PIXEL *, int width);
+static void idctcol(int16 *blk);
+
+#ifdef FAST_IDCT
+// mapping from nz_coefs to functions to be used
+
+
+// ARM4 does not allow global data when they are not constant hence
+// an array of function pointers cannot be considered as array of constants
+// (actual addresses are only known when the dll is loaded).
+// So instead of arrays of function pointers, we'll store here
+// arrays of rows or columns and then call the idct function
+// corresponding to such the row/column number:
+
+
+static void (*const idctcolVCA[10][4])(int16*) =
+{
+ {&idctcol1, &idctcol0, &idctcol0, &idctcol0},
+ {&idctcol1, &idctcol1, &idctcol0, &idctcol0},
+ {&idctcol2, &idctcol1, &idctcol0, &idctcol0},
+ {&idctcol3, &idctcol1, &idctcol0, &idctcol0},
+ {&idctcol3, &idctcol2, &idctcol0, &idctcol0},
+ {&idctcol3, &idctcol2, &idctcol1, &idctcol0},
+ {&idctcol3, &idctcol2, &idctcol1, &idctcol1},
+ {&idctcol3, &idctcol2, &idctcol2, &idctcol1},
+ {&idctcol3, &idctcol3, &idctcol2, &idctcol1},
+ {&idctcol4, &idctcol3, &idctcol2, &idctcol1}
+};
+
+
+static void (*const idctrowVCA[10])(int16*, uint8*, uint8*, int) =
+{
+ &idctrow1,
+ &idctrow2,
+ &idctrow2,
+ &idctrow2,
+ &idctrow2,
+ &idctrow3,
+ &idctrow4,
+ &idctrow4,
+ &idctrow4,
+ &idctrow4
+};
+
+
+static void (*const idctcolVCA2[16])(int16*) =
+{
+ &idctcol0, &idctcol4, &idctcol3, &idctcol4,
+ &idctcol2, &idctcol4, &idctcol3, &idctcol4,
+ &idctcol1, &idctcol4, &idctcol3, &idctcol4,
+ &idctcol2, &idctcol4, &idctcol3, &idctcol4
+};
+
+static void (*const idctrowVCA2[8])(int16*, uint8*, uint8*, int) =
+{
+ &idctrow1, &idctrow4, &idctrow3, &idctrow4,
+ &idctrow2, &idctrow4, &idctrow3, &idctrow4
+};
+
+static void (*const idctrowVCA_intra[10])(int16*, PIXEL *, int) =
+{
+ &idctrow1_intra,
+ &idctrow2_intra,
+ &idctrow2_intra,
+ &idctrow2_intra,
+ &idctrow2_intra,
+ &idctrow3_intra,
+ &idctrow4_intra,
+ &idctrow4_intra,
+ &idctrow4_intra,
+ &idctrow4_intra
+};
+
+static void (*const idctrowVCA2_intra[8])(int16*, PIXEL *, int) =
+{
+ &idctrow1_intra, &idctrow4_intra, &idctrow3_intra, &idctrow4_intra,
+ &idctrow2_intra, &idctrow4_intra, &idctrow3_intra, &idctrow4_intra
+};
+#endif
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void MBlockIDCT(VideoDecData *video)
+{
+ Vop *currVop = video->currVop;
+ MacroBlock *mblock = video->mblock;
+ PIXEL *c_comp;
+ PIXEL *cu_comp;
+ PIXEL *cv_comp;
+ int x_pos = video->mbnum_col;
+ int y_pos = video->mbnum_row;
+ int width, width_uv;
+ int32 offset;
+ width = video->width;
+ width_uv = width >> 1;
+ offset = (int32)(y_pos << 4) * width + (x_pos << 4);
+
+ c_comp = currVop->yChan + offset;
+ cu_comp = currVop->uChan + (offset >> 2) + (x_pos << 2);
+ cv_comp = currVop->vChan + (offset >> 2) + (x_pos << 2);
+
+ BlockIDCT_intra(mblock, c_comp, 0, width);
+ BlockIDCT_intra(mblock, c_comp + 8, 1, width);
+ BlockIDCT_intra(mblock, c_comp + (width << 3), 2, width);
+ BlockIDCT_intra(mblock, c_comp + (width << 3) + 8, 3, width);
+ BlockIDCT_intra(mblock, cu_comp, 4, width_uv);
+ BlockIDCT_intra(mblock, cv_comp, 5, width_uv);
+}
+
+
+void BlockIDCT_intra(
+ MacroBlock *mblock, PIXEL *c_comp, int comp, int width)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int16 *coeff_in = mblock->block[comp];
+#ifdef INTEGER_IDCT
+#ifdef FAST_IDCT /* VCA IDCT using nzcoefs and bitmaps*/
+ int i, bmapr;
+ int nz_coefs = mblock->no_coeff[comp];
+ uint8 *bitmapcol = mblock->bitmapcol[comp];
+ uint8 bitmaprow = mblock->bitmaprow[comp];
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ if (nz_coefs <= 10)
+ {
+ bmapr = (nz_coefs - 1);
+
+ (*(idctcolVCA[bmapr]))(coeff_in);
+ (*(idctcolVCA[bmapr][1]))(coeff_in + 1);
+ (*(idctcolVCA[bmapr][2]))(coeff_in + 2);
+ (*(idctcolVCA[bmapr][3]))(coeff_in + 3);
+
+ (*idctrowVCA_intra[nz_coefs-1])(coeff_in, c_comp, width);
+ }
+ else
+ {
+ i = 8;
+ while (i--)
+ {
+ bmapr = (int)bitmapcol[i];
+ if (bmapr)
+ {
+ if ((bmapr&0xf) == 0) /* 07/18/01 */
+ {
+ (*(idctcolVCA2[bmapr>>4]))(coeff_in + i);
+ }
+ else
+ {
+ idctcol(coeff_in + i);
+ }
+ }
+ }
+ if ((bitmapcol[4] | bitmapcol[5] | bitmapcol[6] | bitmapcol[7]) == 0)
+ {
+ bitmaprow >>= 4;
+ (*(idctrowVCA2_intra[(int)bitmaprow]))(coeff_in, c_comp, width);
+ }
+ else
+ {
+ idctrow_intra(coeff_in, c_comp, width);
+ }
+ }
+#else
+ void idct_intra(int *block, uint8 *comp, int width);
+ idct_intra(coeff_in, c_comp, width);
+#endif
+#else
+ void idctref_intra(int *block, uint8 *comp, int width);
+ idctref_intra(coeff_in, c_comp, width);
+#endif
+
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+
+/* 08/04/05, no residue, just copy from pred to output */
+void Copy_Blk_to_Vop(uint8 *dst, uint8 *pred, int width)
+{
+ /* copy 4 bytes at a time */
+ width -= 4;
+ *((uint32*)dst) = *((uint32*)pred);
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+ *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+ *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+ *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+ *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+ *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+ *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+ *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
+ *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
+
+ return ;
+}
+
+/* 08/04/05 compute IDCT and add prediction at the end */
+void BlockIDCT(
+ uint8 *dst, /* destination */
+ uint8 *pred, /* prediction block, pitch 16 */
+ int16 *coeff_in, /* DCT data, size 64 */
+ int width, /* width of dst */
+ int nz_coefs,
+ uint8 *bitmapcol,
+ uint8 bitmaprow
+)
+{
+#ifdef INTEGER_IDCT
+#ifdef FAST_IDCT /* VCA IDCT using nzcoefs and bitmaps*/
+ int i, bmapr;
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ if (nz_coefs <= 10)
+ {
+ bmapr = (nz_coefs - 1);
+ (*(idctcolVCA[bmapr]))(coeff_in);
+ (*(idctcolVCA[bmapr][1]))(coeff_in + 1);
+ (*(idctcolVCA[bmapr][2]))(coeff_in + 2);
+ (*(idctcolVCA[bmapr][3]))(coeff_in + 3);
+
+ (*idctrowVCA[nz_coefs-1])(coeff_in, pred, dst, width);
+ return ;
+ }
+ else
+ {
+ i = 8;
+
+ while (i--)
+ {
+ bmapr = (int)bitmapcol[i];
+ if (bmapr)
+ {
+ if ((bmapr&0xf) == 0) /* 07/18/01 */
+ {
+ (*(idctcolVCA2[bmapr>>4]))(coeff_in + i);
+ }
+ else
+ {
+ idctcol(coeff_in + i);
+ }
+ }
+ }
+ if ((bitmapcol[4] | bitmapcol[5] | bitmapcol[6] | bitmapcol[7]) == 0)
+ {
+ (*(idctrowVCA2[bitmaprow>>4]))(coeff_in, pred, dst, width);
+ }
+ else
+ {
+ idctrow(coeff_in, pred, dst, width);
+ }
+ return ;
+ }
+#else // FAST_IDCT
+ void idct(int *block, uint8 *pred, uint8 *dst, int width);
+ idct(coeff_in, pred, dst, width);
+ return;
+#endif // FAST_IDCT
+#else // INTEGER_IDCT
+ void idctref(int *block, uint8 *pred, uint8 *dst, int width);
+ idctref(coeff_in, pred, dst, width);
+ return;
+#endif // INTEGER_IDCT
+
+}
+/*----------------------------------------------------------------------------
+; End Function: block_idct
+----------------------------------------------------------------------------*/
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: idctrow
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS FOR idctrow
+
+ Inputs:
+ [input_variable_name] = [description of the input to module, its type
+ definition, and length (when applicable)]
+
+ Local Stores/Buffers/Pointers Needed:
+ [local_store_name] = [description of the local store, its type
+ definition, and length (when applicable)]
+ [local_buffer_name] = [description of the local buffer, its type
+ definition, and length (when applicable)]
+ [local_ptr_name] = [description of the local pointer, its type
+ definition, and length (when applicable)]
+
+ Global Stores/Buffers/Pointers Needed:
+ [global_store_name] = [description of the global store, its type
+ definition, and length (when applicable)]
+ [global_buffer_name] = [description of the global buffer, its type
+ definition, and length (when applicable)]
+ [global_ptr_name] = [description of the global pointer, its type
+ definition, and length (when applicable)]
+
+ Outputs:
+ [return_variable_name] = [description of data/pointer returned
+ by module, its type definition, and length
+ (when applicable)]
+
+ Pointers and Buffers Modified:
+ [variable_bfr_ptr] points to the [describe where the
+ variable_bfr_ptr points to, its type definition, and length
+ (when applicable)]
+ [variable_bfr] contents are [describe the new contents of
+ variable_bfr]
+
+ Local Stores Modified:
+ [local_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+ Global Stores Modified:
+ [global_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION FOR idctrow
+
+------------------------------------------------------------------------------
+ REQUIREMENTS FOR idctrow
+
+------------------------------------------------------------------------------
+ REFERENCES FOR idctrow
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE FOR idctrow
+
+------------------------------------------------------------------------------
+ RESOURCES USED FOR idctrow
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; Function Code FOR idctrow
+----------------------------------------------------------------------------*/
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow(
+ int16 *blk, uint8 *pred, uint8 *dst, int width
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* row (horizontal) IDCT
+ *
+ * 7 pi 1 dst[k] = sum c[l] * src[l] * cos( -- *
+ * ( k + - ) * l ) l=0 8 2
+ *
+ * where: c[0] = 128 c[1..7] = 128*sqrt(2) */
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ width -= 4;
+ dst -= width;
+ pred -= 12;
+ blk -= 8;
+
+ while (i--)
+ {
+ x1 = (int32)blk[12] << 8;
+ blk[12] = 0;
+ x2 = blk[14];
+ blk[14] = 0;
+ x3 = blk[10];
+ blk[10] = 0;
+ x4 = blk[9];
+ blk[9] = 0;
+ x5 = blk[15];
+ blk[15] = 0;
+ x6 = blk[13];
+ blk[13] = 0;
+ x7 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ blk[0] = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x8 = W7 * (x4 + x5) + 4;
+ x4 = (x8 + (W1 - W7) * x4) >> 3;
+ x5 = (x8 - (W1 + W7) * x5) >> 3;
+ x8 = W3 * (x6 + x7) + 4;
+ x6 = (x8 - (W3 - W5) * x6) >> 3;
+ x7 = (x8 - (W3 + W5) * x7) >> 3;
+
+ /* second stage */
+ x8 = x0 + x1;
+ x0 -= x1;
+ x1 = W6 * (x3 + x2) + 4;
+ x2 = (x1 - (W2 + W6) * x2) >> 3;
+ x3 = (x1 + (W2 - W6) * x3) >> 3;
+ x1 = x4 + x6;
+ x4 -= x6;
+ x6 = x5 + x7;
+ x5 -= x7;
+
+ /* third stage */
+ x7 = x8 + x3;
+ x8 -= x3;
+ x3 = x0 + x2;
+ x0 -= x2;
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x4 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(pred += 12)); /* read 4 bytes from pred */
+
+ res = (x7 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x3 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 + x4) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x8 + x6) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += width)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred += 4)); /* read 4 bytes from pred */
+
+ res = (x8 - x6) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 - x4) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x3 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x7 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow_intra(
+ int16 *blk, PIXEL *comp, int width
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8, temp;
+ int i = 8;
+ int offset = width;
+ int32 word;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* row (horizontal) IDCT
+ *
+ * 7 pi 1 dst[k] = sum c[l] * src[l] * cos( -- *
+ * ( k + - ) * l ) l=0 8 2
+ *
+ * where: c[0] = 128 c[1..7] = 128*sqrt(2) */
+ while (i--)
+ {
+ x1 = (int32)blk[4] << 8;
+ blk[4] = 0;
+ x2 = blk[6];
+ blk[6] = 0;
+ x3 = blk[2];
+ blk[2] = 0;
+ x4 = blk[1];
+ blk[1] = 0;
+ x5 = blk[7];
+ blk[7] = 0;
+ x6 = blk[5];
+ blk[5] = 0;
+ x7 = blk[3];
+ blk[3] = 0;
+#ifndef FAST_IDCT
+ /* shortcut */ /* covered by idctrow1 01/9/2001 */
+ if (!(x1 | x2 | x3 | x4 | x5 | x6 | x7))
+ {
+ blk[0] = blk[1] = blk[2] = blk[3] = blk[4] = blk[5] = blk[6] = blk[7] = (blk[0] + 32) >> 6;
+ return;
+ }
+#endif
+ x0 = ((int32)blk[0] << 8) + 8192;
+ blk[0] = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x8 = W7 * (x4 + x5) + 4;
+ x4 = (x8 + (W1 - W7) * x4) >> 3;
+ x5 = (x8 - (W1 + W7) * x5) >> 3;
+ x8 = W3 * (x6 + x7) + 4;
+ x6 = (x8 - (W3 - W5) * x6) >> 3;
+ x7 = (x8 - (W3 + W5) * x7) >> 3;
+
+ /* second stage */
+ x8 = x0 + x1;
+ x0 -= x1;
+ x1 = W6 * (x3 + x2) + 4;
+ x2 = (x1 - (W2 + W6) * x2) >> 3;
+ x3 = (x1 + (W2 - W6) * x3) >> 3;
+ x1 = x4 + x6;
+ x4 -= x6;
+ x6 = x5 + x7;
+ x5 -= x7;
+
+ /* third stage */
+ x7 = x8 + x3;
+ x8 -= x3;
+ x3 = x0 + x2;
+ x0 -= x2;
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x4 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ word = ((x7 + x1) >> 14);
+ CLIP_RESULT(word)
+
+ temp = ((x3 + x2) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+
+ temp = ((x0 + x4) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+
+ temp = ((x8 + x6) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp)) = word;
+
+ word = ((x8 - x6) >> 14);
+ CLIP_RESULT(word)
+
+ temp = ((x0 - x4) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+
+ temp = ((x3 - x2) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+
+ temp = ((x7 - x1) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp + 4)) = word;
+ comp += offset;
+
+ blk += B_SIZE;
+ }
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+
+/*----------------------------------------------------------------------------
+; End Function: idctrow
+----------------------------------------------------------------------------*/
+
+
+/****************************************************************************/
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: idctcol
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS FOR idctcol
+
+ Inputs:
+ [input_variable_name] = [description of the input to module, its type
+ definition, and length (when applicable)]
+
+ Local Stores/Buffers/Pointers Needed:
+ [local_store_name] = [description of the local store, its type
+ definition, and length (when applicable)]
+ [local_buffer_name] = [description of the local buffer, its type
+ definition, and length (when applicable)]
+ [local_ptr_name] = [description of the local pointer, its type
+ definition, and length (when applicable)]
+
+ Global Stores/Buffers/Pointers Needed:
+ [global_store_name] = [description of the global store, its type
+ definition, and length (when applicable)]
+ [global_buffer_name] = [description of the global buffer, its type
+ definition, and length (when applicable)]
+ [global_ptr_name] = [description of the global pointer, its type
+ definition, and length (when applicable)]
+
+ Outputs:
+ [return_variable_name] = [description of data/pointer returned
+ by module, its type definition, and length
+ (when applicable)]
+
+ Pointers and Buffers Modified:
+ [variable_bfr_ptr] points to the [describe where the
+ variable_bfr_ptr points to, its type definition, and length
+ (when applicable)]
+ [variable_bfr] contents are [describe the new contents of
+ variable_bfr]
+
+ Local Stores Modified:
+ [local_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+ Global Stores Modified:
+ [global_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION FOR idctcol
+
+------------------------------------------------------------------------------
+ REQUIREMENTS FOR idctcol
+
+------------------------------------------------------------------------------
+ REFERENCES FOR idctcol
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE FOR idctcol
+
+------------------------------------------------------------------------------
+ RESOURCES USED FOR idctcol
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; Function Code FOR idctcol
+----------------------------------------------------------------------------*/
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctcol(
+ int16 *blk
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* column (vertical) IDCT
+ *
+ * 7 pi 1 dst[8*k] = sum c[l] * src[8*l] *
+ * cos( -- * ( k + - ) * l ) l=0 8 2
+ *
+ * where: c[0] = 1/1024 c[1..7] = (1/1024)*sqrt(2) */
+ x1 = (int32)blk[32] << 11;
+ x2 = blk[48];
+ x3 = blk[16];
+ x4 = blk[8];
+ x5 = blk[56];
+ x6 = blk[40];
+ x7 = blk[24];
+#ifndef FAST_IDCT
+ /* shortcut */ /* covered by idctcolumn1 01/9/2001 */
+ if (!(x1 | x2 | x3 | x4 | x5 | x6 | x7))
+ {
+ blk[0] = blk[8] = blk[16] = blk[24] = blk[32] = blk[40] = blk[48] = blk[56]
+ = blk[0] << 3;
+ return;
+ }
+#endif
+
+ x0 = ((int32)blk[0] << 11) + 128;
+
+ /* first stage */
+ x8 = W7 * (x4 + x5);
+ x4 = x8 + (W1 - W7) * x4;
+ x5 = x8 - (W1 + W7) * x5;
+ x8 = W3 * (x6 + x7);
+ x6 = x8 - (W3 - W5) * x6;
+ x7 = x8 - (W3 + W5) * x7;
+
+ /* second stage */
+ x8 = x0 + x1;
+ x0 -= x1;
+ x1 = W6 * (x3 + x2);
+ x2 = x1 - (W2 + W6) * x2;
+ x3 = x1 + (W2 - W6) * x3;
+ x1 = x4 + x6;
+ x4 -= x6;
+ x6 = x5 + x7;
+ x5 -= x7;
+
+ /* third stage */
+ x7 = x8 + x3;
+ x8 -= x3;
+ x3 = x0 + x2;
+ x0 -= x2;
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x4 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ blk[0] = (x7 + x1) >> 8;
+ blk[8] = (x3 + x2) >> 8;
+ blk[16] = (x0 + x4) >> 8;
+ blk[24] = (x8 + x6) >> 8;
+ blk[32] = (x8 - x6) >> 8;
+ blk[40] = (x0 - x4) >> 8;
+ blk[48] = (x3 - x2) >> 8;
+ blk[56] = (x7 - x1) >> 8;
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+/*----------------------------------------------------------------------------
+; End Function: idctcol
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/m4v_h263/dec/src/cal_dc_scaler.cpp b/media/codecs/m4v_h263/dec/src/cal_dc_scaler.cpp
new file mode 100644
index 0000000..85889d3
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/cal_dc_scaler.cpp
@@ -0,0 +1,182 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ [input_variable_name] = [description of the input to module, its type
+ definition, and length (when applicable)]
+
+ Local Stores/Buffers/Pointers Needed:
+ [local_store_name] = [description of the local store, its type
+ definition, and length (when applicable)]
+ [local_buffer_name] = [description of the local buffer, its type
+ definition, and length (when applicable)]
+ [local_ptr_name] = [description of the local pointer, its type
+ definition, and length (when applicable)]
+
+ Global Stores/Buffers/Pointers Needed:
+ [global_store_name] = [description of the global store, its type
+ definition, and length (when applicable)]
+ [global_buffer_name] = [description of the global buffer, its type
+ definition, and length (when applicable)]
+ [global_ptr_name] = [description of the global pointer, its type
+ definition, and length (when applicable)]
+
+ Outputs:
+ [return_variable_name] = [description of data/pointer returned
+ by module, its type definition, and length
+ (when applicable)]
+
+ Pointers and Buffers Modified:
+ [variable_bfr_ptr] points to the [describe where the
+ variable_bfr_ptr points to, its type definition, and length
+ (when applicable)]
+ [variable_bfr] contents are [describe the new contents of
+ variable_bfr]
+
+ Local Stores Modified:
+ [local_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+ Global Stores Modified:
+ [global_store_name] = [describe new contents, its type
+ definition, and length (when applicable)]
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This module calculates the DC quantization scale according
+ to the incoming Q and type.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+ [List requirements to be satisfied by this module.]
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [List all references used in designing this module.]
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+ RESOURCES USED
+ When the code is written for a specific target processor the
+ the resources used should be documented below.
+
+ STACK USAGE: [stack count for this module] + [variable to represent
+ stack usage for each subroutine called]
+
+ where: [stack usage variable] = stack usage for [subroutine
+ name] (see [filename].ext)
+
+ DATA MEMORY USED: x words
+
+ PROGRAM MEMORY USED: x words
+
+ CLOCK CYCLES: [cycle count equation for this module] + [variable
+ used to represent cycle count for each subroutine
+ called]
+
+ where: [cycle count variable] = cycle count for [subroutine
+ name] (see [filename].ext)
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+#include "vlc_decode.h"
+#include "bitstream.h"
+#include "zigzag.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+int cal_dc_scaler(
+ int QP,
+ int type)
+{
+
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int dc_scaler;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ if (type == LUMINANCE_DC_TYPE)
+ {
+ if (QP > 0 && QP < 5) dc_scaler = 8;
+ else if (QP > 4 && QP < 9) dc_scaler = 2 * QP;
+ else if (QP > 8 && QP < 25) dc_scaler = QP + 8;
+ else dc_scaler = 2 * QP - 16;
+ }
+ else /* if (type == CHROMINANCE_DC_TYPE), there is no other types. */
+ {
+ if (QP > 0 && QP < 5) dc_scaler = 8;
+ else if (QP > 4 && QP < 25) dc_scaler = (QP + 13) >> 1;
+ else dc_scaler = QP - 6;
+ }
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return dc_scaler;
+}
+
diff --git a/media/codecs/m4v_h263/dec/src/combined_decode.cpp b/media/codecs/m4v_h263/dec/src/combined_decode.cpp
new file mode 100644
index 0000000..72cbe83
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/combined_decode.cpp
@@ -0,0 +1,744 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4dec_lib.h" /* video decoder function prototypes */
+#include "vlc_decode.h"
+#include "bitstream.h"
+#include "scaling.h"
+#include "mbtype_mode.h"
+
+#define OSCL_DISABLE_WARNING_CONDITIONAL_IS_CONSTANT
+/* ======================================================================== */
+/* Function : DecodeFrameCombinedMode() */
+/* Purpose : Decode a frame of MPEG4 bitstream in combined mode. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* */
+/* 03/30/2000 : Cleaned up and optimized the code. */
+/* 03/31/2000 : Added proper handling of MB stuffing. */
+/* 04/13/2000 : Rewrote this combined mode path completely */
+/* so that it handles "Combined Mode With Error */
+/* Resilience." Now the code resembles the */
+/* pseudo codes in MPEG-4 standard better. */
+/* 10/13/2000 : Add fast VLC+dequant */
+/* 04/13/2001 : fix MB_stuffing */
+/* 08/07/2001 : remove MBzero */
+/* ======================================================================== */
+PV_STATUS DecodeFrameCombinedMode(VideoDecData *video)
+{
+ PV_STATUS status;
+ int mbnum;
+ Vop *currVop = video->currVop;
+ BitstreamDecVideo *stream = video->bitstream;
+ int shortVideoHeader = video->shortVideoHeader;
+ int16 QP, *QPMB = video->QPMB;
+ uint8 *Mode = video->headerInfo.Mode;
+ int nTotalMB = video->nTotalMB;
+ int nMBPerRow = video->nMBPerRow;
+ int slice_counter;
+ uint32 tmpvar, long_zero_bits;
+ uint code;
+ int valid_stuffing;
+ int resync_marker_length;
+ int stuffing_length;
+
+ /* add this for error resilient, 05/18/2000 */
+ int32 startPacket;
+ int mb_start;
+ /* copy and pad to prev_Vop for INTER coding */
+ switch (currVop->predictionType)
+ {
+ case I_VOP :
+// oscl_memset(Mode, MODE_INTRA, sizeof(uint8)*nTotalMB);
+ resync_marker_length = 17;
+ stuffing_length = 9;
+ break;
+ case P_VOP :
+ oscl_memset(video->motX, 0, sizeof(MOT)*4*nTotalMB);
+ oscl_memset(video->motY, 0, sizeof(MOT)*4*nTotalMB);
+// oscl_memset(Mode, MODE_INTER, sizeof(uint8)*nTotalMB);
+ resync_marker_length = 16 + currVop->fcodeForward;
+ stuffing_length = 10;
+ break;
+ default :
+ mp4dec_log("DecodeFrameCombinedMode(): Vop type not supported.\n");
+ return PV_FAIL;
+ }
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (video->shortVideoHeader)
+ {
+ if (video->advanced_INTRA)
+ {
+ if (video->modified_quant)
+ {
+ video->vlcDecCoeffIntra = &VlcDecTCOEFShortHeader_AnnexIT;
+ video->vlcDecCoeffInter = &VlcDecTCOEFShortHeader_AnnexT;
+ }
+ else
+ {
+ video->vlcDecCoeffIntra = &VlcDecTCOEFShortHeader_AnnexI;
+ video->vlcDecCoeffInter = &VlcDecTCOEFShortHeader;
+ }
+ }
+ else
+ {
+ if (video->modified_quant)
+ {
+ video->vlcDecCoeffInter = video->vlcDecCoeffIntra = &VlcDecTCOEFShortHeader_AnnexT;
+ }
+ else
+ {
+ video->vlcDecCoeffInter = video->vlcDecCoeffIntra = &VlcDecTCOEFShortHeader;
+ }
+ }
+ }
+
+#endif
+
+ /** Initialize sliceNo ***/
+ mbnum = slice_counter = 0;
+// oscl_memset(video->sliceNo, 0, sizeof(uint8)*nTotalMB);
+ QP = video->currVop->quantizer;
+
+ do
+ {
+ /* This section is equivalent to motion_shape_texture() */
+ /* in the MPEG-4 standard. 04/13/2000 */
+ mb_start = mbnum;
+ video->usePrevQP = 0; /* 04/27/01 */
+ startPacket = getPointer(stream);
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (video->modified_quant)
+ {
+ video->QP_CHR = MQ_chroma_QP_table[QP];
+ }
+ else
+ {
+ video->QP_CHR = QP; /* ANNEX_T */
+ }
+#endif
+ /* remove any stuffing bits */
+ BitstreamShowBits16(stream, stuffing_length, &code);
+ while (code == 1)
+ {
+ PV_BitstreamFlushBits(stream, stuffing_length);
+ BitstreamShowBits16(stream, stuffing_length, &code);
+ }
+
+ do
+ {
+ /* we need video->mbnum in lower level functions */
+ video->mbnum = mbnum;
+ video->mbnum_row = PV_GET_ROW(mbnum, nMBPerRow);
+ video->mbnum_col = mbnum - video->mbnum_row * nMBPerRow;
+ /* assign slice number for each macroblocks */
+ video->sliceNo[mbnum] = (uint8) slice_counter;
+
+ /* decode COD, MCBPC, ACpred_flag, CPBY and DQUANT */
+ /* We have to discard stuffed MB header */
+ status = GetMBheader(video, &QP);
+
+ if (status != PV_SUCCESS)
+ {
+ VideoDecoderErrorDetected(video);
+ video->mbnum = mb_start;
+ movePointerTo(stream, (startPacket & -8));
+ break;
+ }
+
+ /* Store the QP value for later use in AC prediction */
+ QPMB[mbnum] = QP;
+
+ if (Mode[mbnum] != MODE_SKIPPED)
+ {
+ /* decode the DCT coeficients for the MB */
+ status = GetMBData(video);
+ if (status != PV_SUCCESS)
+ {
+ VideoDecoderErrorDetected(video);
+ video->mbnum = mb_start;
+ movePointerTo(stream, (startPacket & -8));
+ break;
+ }
+ }
+ else /* MODE_SKIPPED */
+ {
+ SkippedMBMotionComp(video); /* 08/04/05 */
+ }
+ // Motion compensation and put video->mblock->pred_block
+ mbnum++;
+
+ /* remove any stuffing bits */
+ BitstreamShowBits16(stream, stuffing_length, &code);
+ while (code == 1)
+ {
+ PV_BitstreamFlushBits(stream, stuffing_length);
+ BitstreamShowBits16(stream, stuffing_length, &code);
+ }
+
+ /* have we reached the end of the video packet or vop? */
+ if (shortVideoHeader)
+ {
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (!video->slice_structure)
+ {
+#endif
+ if (mbnum >= (int)(video->mbnum_row + 1)*video->nMBinGOB) /* 10/11/01 */
+ {
+ if (mbnum >= nTotalMB) return PV_SUCCESS;
+ status = BitstreamShowBits32(stream, GOB_RESYNC_MARKER_LENGTH, &tmpvar);
+
+ if (tmpvar == GOB_RESYNC_MARKER)
+ {
+ break;
+ }
+ else
+ {
+ status = PV_BitstreamShowBitsByteAlign(stream, GOB_RESYNC_MARKER_LENGTH, &tmpvar);
+ if (tmpvar == GOB_RESYNC_MARKER) break;
+ }
+ }
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ }
+ else
+ {
+
+ if (mbnum >= nTotalMB) /* in case no valid stuffing 06/23/01 */
+ {
+ valid_stuffing = validStuffing_h263(stream);
+ if (valid_stuffing == 0)
+ {
+ VideoDecoderErrorDetected(video);
+ ConcealPacket(video, mb_start, nTotalMB, slice_counter);
+ }
+ return PV_SUCCESS;
+ }
+ /* ANNEX_K */
+ PV_BitstreamShowBitsByteAlignNoForceStuffing(stream, 17, &tmpvar);
+ if (tmpvar == RESYNC_MARKER)
+ {
+ valid_stuffing = validStuffing_h263(stream);
+ if (valid_stuffing)
+ break; /* 06/21/01 */
+ }
+
+ }
+#endif
+ }
+ else
+ {
+ if (mbnum >= nTotalMB) /* in case no valid stuffing 06/23/01 */
+ {
+ /* 11/01/2002 if we are at the end of the frame and there is some garbage data
+ at the end of the frame (i.e. no next startcode) break if the stuffing is valid */
+ valid_stuffing = validStuffing(stream);
+ if (valid_stuffing == 0)
+ {
+ /* end 11/01/2002 */
+ VideoDecoderErrorDetected(video);
+ ConcealPacket(video, mb_start, nTotalMB, slice_counter);
+ }
+ PV_BitstreamByteAlign(stream);
+ return PV_SUCCESS;
+ }
+
+ status = PV_BitstreamShowBitsByteAlign(stream, 23, &tmpvar); /* this call is valid for f_code < 8 */
+ long_zero_bits = !tmpvar;
+
+ if ((tmpvar >> (23 - resync_marker_length)) == RESYNC_MARKER || long_zero_bits)
+ {
+ valid_stuffing = validStuffing(stream);
+ if (valid_stuffing)
+ break; /* 06/21/01 */
+ }
+
+ }
+ }
+ while (TRUE);
+
+ if (shortVideoHeader)
+ { /* We need to check newgob to refresh quantizer */
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (!video->slice_structure)
+ {
+#endif
+ while ((status = PV_GobHeader(video)) == PV_FAIL)
+ {
+ if ((status = quickSearchGOBHeader(stream)) != PV_SUCCESS)
+ {
+ break;
+ }
+ }
+
+ mbnum = currVop->gobNumber * video->nMBinGOB;
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ }
+ else
+ {
+ while ((status = PV_H263SliceHeader(video, &mbnum)) == PV_FAIL)
+ {
+ if ((status = quickSearchH263SliceHeader(stream)) != PV_SUCCESS)
+ {
+ break;
+ }
+ }
+ }
+
+#endif
+ }
+ else
+ {
+ while ((status = PV_ReadVideoPacketHeader(video, &mbnum)) == PV_FAIL)
+ {
+ if ((status = quickSearchVideoPacketHeader(stream, resync_marker_length)) != PV_SUCCESS)
+ {
+ break;
+ }
+ }
+ }
+
+ if (status == PV_END_OF_VOP)
+ {
+ mbnum = nTotalMB;
+ }
+
+ if (mbnum > video->mbnum + 1)
+ {
+ ConcealPacket(video, video->mbnum, mbnum, slice_counter);
+ }
+ QP = video->currVop->quantizer;
+ slice_counter++;
+ if (mbnum >= nTotalMB) break;
+
+ }
+ while (TRUE);
+ return PV_SUCCESS;
+}
+
+
+/* ============================================================================ */
+/* Function : GetMBHeader() */
+/* Purpose : Decode MB header, not_coded, mcbpc, ac_pred_flag, cbpy, dquant. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* */
+/* 3/29/00 : Changed the returned value and optimized the code. */
+/* 4/01/01 : new ACDC prediction structure */
+/* ============================================================================ */
+PV_STATUS GetMBheader(VideoDecData *video, int16 *QP)
+{
+ BitstreamDecVideo *stream = video->bitstream;
+ int mbnum = video->mbnum;
+ uint8 *Mode = video->headerInfo.Mode;
+ int x_pos = video->mbnum_col;
+ typeDCStore *DC = video->predDC + mbnum;
+ typeDCACStore *DCAC_row = video->predDCAC_row + x_pos;
+ typeDCACStore *DCAC_col = video->predDCAC_col;
+ const static int16 DQ_tab[4] = { -1, -2, 1, 2};
+
+ int CBPY, CBPC;
+ int MBtype, VopType;
+ int MCBPC;
+ uint DQUANT;
+ int comp;
+ Bool mb_coded;
+
+ VopType = video->currVop->predictionType;
+ mb_coded = ((VopType == I_VOP) ? TRUE : !BitstreamRead1Bits_INLINE(stream));
+
+ if (!mb_coded)
+ {
+ /* skipped macroblock */
+ Mode[mbnum] = MODE_SKIPPED;
+ //oscl_memset(DCAC_row, 0, sizeof(typeDCACStore)); /* SKIPPED_ACDC */
+ //oscl_memset(DCAC_col, 0, sizeof(typeDCACStore));
+ ZERO_OUT_64BYTES(DCAC_row);
+ ZERO_OUT_64BYTES(DCAC_col); /* 08/12/05 */
+
+ for (comp = 0; comp < 6; comp++)
+ {
+ (*DC)[comp] = mid_gray;
+ }
+ }
+ else
+ {
+ /* coded macroblock */
+ if (VopType == I_VOP)
+ {
+ MCBPC = PV_VlcDecMCBPC_com_intra(stream);
+ }
+ else
+ {
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (!video->deblocking)
+ {
+ MCBPC = PV_VlcDecMCBPC_com_inter(stream);
+ }
+ else
+ {
+ MCBPC = PV_VlcDecMCBPC_com_inter_H263(stream);
+ }
+#else
+ MCBPC = PV_VlcDecMCBPC_com_inter(stream);
+#endif
+ }
+
+ if (VLC_ERROR_DETECTED(MCBPC))
+ {
+ return PV_FAIL;
+ }
+
+ Mode[mbnum] = (uint8)(MBtype = MBtype_mode[MCBPC & 7]);
+ CBPC = (MCBPC >> 4) & 3;
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (MBtype & INTRA_MASK)
+ {
+ if (!video->shortVideoHeader)
+ {
+ video->acPredFlag[mbnum] = (uint8) BitstreamRead1Bits(stream);
+ }
+ else
+ {
+ if (video->advanced_INTRA)
+ {
+ if (!BitstreamRead1Bits(stream))
+ {
+ video->acPredFlag[mbnum] = 0;
+ }
+ else
+ {
+ video->acPredFlag[mbnum] = 1;
+ if (BitstreamRead1Bits(stream))
+ {
+ video->mblock->direction = 0;
+ }
+ else
+ {
+ video->mblock->direction = 1;
+ }
+ }
+ }
+ else
+ {
+ video->acPredFlag[mbnum] = 0;
+ }
+ }
+ }
+#else
+ if ((MBtype & INTRA_MASK) && !video->shortVideoHeader)
+ {
+ video->acPredFlag[mbnum] = (uint8) BitstreamRead1Bits_INLINE(stream);
+ }
+ else
+ {
+ video->acPredFlag[mbnum] = 0;
+ }
+#endif
+ CBPY = PV_VlcDecCBPY(stream, MBtype & INTRA_MASK); /* INTRA || INTRA_Q */
+ if (CBPY < 0)
+ {
+ return PV_FAIL;
+ }
+
+ // GW 04/23/99
+ video->headerInfo.CBP[mbnum] = (uint8)(CBPY << 2 | (CBPC & 3));
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (MBtype & Q_MASK)
+ {
+ if (!video->modified_quant)
+ {
+ DQUANT = BitstreamReadBits16(stream, 2);
+ *QP += DQ_tab[DQUANT];
+
+ if (*QP < 1) *QP = 1;
+ else if (*QP > 31) *QP = 31;
+ video->QP_CHR = *QP; /* ANNEX_T */
+ }
+ else
+ {
+ if (BitstreamRead1Bits(stream))
+ {
+ if (BitstreamRead1Bits(stream))
+ {
+ *QP += DQ_tab_Annex_T_11[*QP];
+ }
+ else
+ {
+ *QP += DQ_tab_Annex_T_10[*QP];
+ }
+ if (*QP < 1) *QP = 1;
+ else if (*QP > 31) *QP = 31;
+ }
+ else
+ {
+ *QP = (int16)BitstreamReadBits16(stream, 5);
+ }
+ video->QP_CHR = MQ_chroma_QP_table[*QP];
+ }
+ }
+#else
+ if (MBtype & Q_MASK)
+ {
+ DQUANT = BitstreamReadBits16(stream, 2);
+ *QP += DQ_tab[DQUANT];
+
+ if (*QP < 1) *QP = 1;
+ else if (*QP > 31) *QP = 31;
+ }
+#endif
+ }
+ return PV_SUCCESS;
+}
+
+
+
+
+
+/***********************************************************CommentBegin******
+* 3/10/00 : initial modification to the
+* new PV-Decoder Lib format.
+* 4/2/2000 : Cleanup and error-handling modification. This
+* function has been divided into several sub-functions for
+* better coding style and maintainance reason. I also
+* greatly shrunk the code size here.
+* 9/18/2000 : VlcDecode+Dequant optimization *
+* 4/01/2001 : new ACDC prediction structure
+* 3/29/2002 : removed GetIntraMB and GetInterMB
+***********************************************************CommentEnd********/
+PV_STATUS GetMBData(VideoDecData *video)
+{
+ BitstreamDecVideo *stream = video->bitstream;
+ int mbnum = video->mbnum;
+ MacroBlock *mblock = video->mblock;
+ int16 *dataBlock;
+ PIXEL *c_comp;
+ uint mode = video->headerInfo.Mode[mbnum];
+ uint CBP = video->headerInfo.CBP[mbnum];
+ typeDCStore *DC = video->predDC + mbnum;
+ int intra_dc_vlc_thr = video->currVop->intraDCVlcThr;
+ int16 QP = video->QPMB[mbnum];
+ int16 QP_tmp = QP;
+ int width = video->width;
+ int comp;
+ int switched;
+ int ncoeffs[6] = {0, 0, 0, 0, 0, 0};
+ int *no_coeff = mblock->no_coeff;
+ int16 DC_coeff;
+ PV_STATUS status;
+
+ int y_pos = video->mbnum_row;
+ int x_pos = video->mbnum_col;
+ int32 offset = (int32)(y_pos << 4) * width + (x_pos << 4);
+
+ /* Decode each 8-by-8 blocks. comp 0 ~ 3 are luminance blocks, 4 ~ 5 */
+ /* are chrominance blocks. 04/03/2000. */
+
+ /* oscl_memset(mblock->block, 0, sizeof(typeMBStore)); Aug 9,2005 */
+
+ if (mode & INTRA_MASK) /* MODE_INTRA || MODE_INTRA_Q */
+ {
+ switched = 0;
+ if (intra_dc_vlc_thr)
+ {
+ if (video->usePrevQP)
+ QP_tmp = video->QPMB[mbnum-1]; /* running QP 04/26/01 */
+
+ switched = (intra_dc_vlc_thr == 7 || QP_tmp >= intra_dc_vlc_thr * 2 + 11);
+ }
+
+ mblock->DCScalarLum = cal_dc_scaler(QP, LUMINANCE_DC_TYPE); /* 3/01/01 */
+ mblock->DCScalarChr = cal_dc_scaler(QP, CHROMINANCE_DC_TYPE);
+
+ for (comp = 0; comp < 6; comp++)
+ {
+ dataBlock = mblock->block[comp]; /* 10/20/2000 */
+
+ if (video->shortVideoHeader)
+ {
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (!video->advanced_INTRA)
+ {
+#endif
+ DC_coeff = (int16) BitstreamReadBits16_INLINE(stream, 8);
+
+ if ((DC_coeff & 0x7f) == 0) /* 128 & 0 */
+ {
+ /* currently we will only signal FAIL for 128. We will ignore the 0 case */
+ if (DC_coeff == 128)
+ {
+ return PV_FAIL;
+ }
+ else
+ {
+ VideoDecoderErrorDetected(video);
+ }
+ }
+ if (DC_coeff == 255)
+ {
+ DC_coeff = 128;
+ }
+ dataBlock[0] = (int16) DC_coeff;
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ }
+#endif
+ ncoeffs[comp] = VlcDequantH263IntraBlock_SH(video, comp, mblock->bitmapcol[comp], &mblock->bitmaprow[comp]);
+
+ }
+ else
+ {
+ if (switched == 0)
+ {
+ status = PV_DecodePredictedIntraDC(comp, stream, &DC_coeff);
+ if (status != PV_SUCCESS) return PV_FAIL;
+
+ dataBlock[0] = (int16) DC_coeff;
+ }
+ ncoeffs[comp] = VlcDequantH263IntraBlock(video, comp,
+ switched, mblock->bitmapcol[comp], &mblock->bitmaprow[comp]);
+ }
+
+ if (VLC_ERROR_DETECTED(ncoeffs[comp]))
+ {
+ if (switched)
+ return PV_FAIL;
+ else
+ {
+ ncoeffs[comp] = 1;
+ oscl_memset((dataBlock + 1), 0, sizeof(int16)*63);
+ }
+ }
+ no_coeff[comp] = ncoeffs[comp];
+
+ }
+ MBlockIDCT(video);
+ }
+ else /* INTER modes */
+ { /* moved it here Aug 15, 2005 */
+ /* decode the motion vector (if there are any) */
+ status = PV_GetMBvectors(video, mode);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+
+ MBMotionComp(video, CBP);
+ c_comp = video->currVop->yChan + offset;
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ for (comp = 0; comp < 4; comp++)
+ {
+ (*DC)[comp] = mid_gray;
+ if (CBP & (1 << (5 - comp)))
+ {
+ ncoeffs[comp] = VlcDequantH263InterBlock(video, comp, mblock->bitmapcol[comp], &mblock->bitmaprow[comp]);
+ if (VLC_ERROR_DETECTED(ncoeffs[comp])) return PV_FAIL;
+
+ BlockIDCT(c_comp + (comp&2)*(width << 2) + 8*(comp&1), mblock->pred_block + (comp&2)*64 + 8*(comp&1), mblock->block[comp], width, ncoeffs[comp],
+ mblock->bitmapcol[comp], mblock->bitmaprow[comp]);
+
+ }
+ }
+
+ video->QPMB[mbnum] = video->QP_CHR; /* ANNEX_T */
+
+
+
+ (*DC)[4] = mid_gray;
+ if (CBP & 2)
+ {
+ ncoeffs[4] = VlcDequantH263InterBlock(video, 4, mblock->bitmapcol[4], &mblock->bitmaprow[4]);
+ if (VLC_ERROR_DETECTED(ncoeffs[4])) return PV_FAIL;
+
+ BlockIDCT(video->currVop->uChan + (offset >> 2) + (x_pos << 2), mblock->pred_block + 256, mblock->block[4], width >> 1, ncoeffs[4],
+ mblock->bitmapcol[4], mblock->bitmaprow[4]);
+
+ }
+ (*DC)[5] = mid_gray;
+ if (CBP & 1)
+ {
+ ncoeffs[5] = VlcDequantH263InterBlock(video, 5, mblock->bitmapcol[5], &mblock->bitmaprow[5]);
+ if (VLC_ERROR_DETECTED(ncoeffs[5])) return PV_FAIL;
+
+ BlockIDCT(video->currVop->vChan + (offset >> 2) + (x_pos << 2), mblock->pred_block + 264, mblock->block[5], width >> 1, ncoeffs[5],
+ mblock->bitmapcol[5], mblock->bitmaprow[5]);
+
+ }
+ video->QPMB[mbnum] = QP; /* restore the QP values ANNEX_T*/
+#else
+ for (comp = 0; comp < 4; comp++)
+ {
+ (*DC)[comp] = mid_gray;
+ if (CBP & (1 << (5 - comp)))
+ {
+ ncoeffs[comp] = VlcDequantH263InterBlock(video, comp, mblock->bitmapcol[comp], &mblock->bitmaprow[comp]);
+ if (VLC_ERROR_DETECTED(ncoeffs[comp])) return PV_FAIL;
+
+ BlockIDCT(c_comp + (comp&2)*(width << 2) + 8*(comp&1), mblock->pred_block + (comp&2)*64 + 8*(comp&1), mblock->block[comp], width, ncoeffs[comp],
+ mblock->bitmapcol[comp], mblock->bitmaprow[comp]);
+
+ }
+ }
+
+ (*DC)[4] = mid_gray;
+ if (CBP & 2)
+ {
+ ncoeffs[4] = VlcDequantH263InterBlock(video, 4, mblock->bitmapcol[4], &mblock->bitmaprow[4]);
+ if (VLC_ERROR_DETECTED(ncoeffs[4])) return PV_FAIL;
+
+ BlockIDCT(video->currVop->uChan + (offset >> 2) + (x_pos << 2), mblock->pred_block + 256, mblock->block[4], width >> 1, ncoeffs[4],
+ mblock->bitmapcol[4], mblock->bitmaprow[4]);
+
+ }
+ else
+ {
+ /* no IDCT for all zeros blocks 03/28/2002 */
+ /* BlockIDCT(); */
+ }
+ (*DC)[5] = mid_gray;
+ if (CBP & 1)
+ {
+ ncoeffs[5] = VlcDequantH263InterBlock(video, 5, mblock->bitmapcol[5], &mblock->bitmaprow[5]);
+ if (VLC_ERROR_DETECTED(ncoeffs[5])) return PV_FAIL;
+
+ BlockIDCT(video->currVop->vChan + (offset >> 2) + (x_pos << 2), mblock->pred_block + 264, mblock->block[5], width >> 1, ncoeffs[5],
+ mblock->bitmapcol[5], mblock->bitmaprow[5]);
+
+ }
+ else
+ {
+ /* no IDCT for all zeros blocks 03/28/2002 */
+ /* BlockIDCT(); */
+#endif // PV_ANNEX_IJKT_SUPPORT
+
+
+
+
+
+
+ }
+
+ video->usePrevQP = 1; /* should be set after decoding the first Coded 04/27/01 */
+ return PV_SUCCESS;
+}
+
+
+
diff --git a/media/codecs/m4v_h263/dec/src/conceal.cpp b/media/codecs/m4v_h263/dec/src/conceal.cpp
new file mode 100644
index 0000000..8393d79
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/conceal.cpp
@@ -0,0 +1,202 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#define LOG_TAG "conceal"
+
+#include "log/log.h"
+
+#include "mp4dec_lib.h" /* video decoder function prototypes */
+#include "vlc_decode.h"
+#include "bitstream.h"
+#include "scaling.h"
+
+/* ====================================================================== /
+Function : ConcealTexture_I()
+Date : 06/12/2001
+Purpose : Conceal texture for I-partition
+In/out :
+Return :
+Modified :
+/ ====================================================================== */
+void ConcealTexture_I(VideoDecData *video, int32 startFirstPartition, int mb_start, int mb_stop, int slice_counter)
+{
+ int mbnum;
+ BitstreamDecVideo *stream = video->bitstream;
+ int16 QP;
+ int intra_dc_vlc_thr = video->currVop->intraDCVlcThr;
+
+ movePointerTo(stream, startFirstPartition);
+
+ video->usePrevQP = 0;
+ for (mbnum = mb_start; mbnum < mb_stop; mbnum++)
+ {
+ video->mbnum = mbnum;
+ video->mbnum_row = PV_GET_ROW(mbnum, video->nMBPerRow);
+ video->mbnum_col = mbnum - video->mbnum_row * video->nMBPerRow;
+ video->sliceNo[mbnum] = (uint8) slice_counter;
+ QP = video->QPMB[mbnum];
+ PV_VlcDecMCBPC_com_intra(stream);
+ GetMBheaderDataPart_DQUANT_DC(video, &QP);
+
+ if (intra_dc_vlc_thr)
+ {
+ if (video->usePrevQP)
+ QP = video->QPMB[mbnum-1];
+ if (intra_dc_vlc_thr == 7 || QP >= intra_dc_vlc_thr*2 + 11) /* if switched then conceal from previous frame */
+ {
+ ConcealPacket(video, mbnum, mb_stop, slice_counter);
+ video->mbnum = mb_stop - 1;
+ video->mbnum_row = PV_GET_ROW(video->mbnum, video->nMBPerRow);
+ video->mbnum_col = video->mbnum - video->mbnum_row * video->nMBPerRow;
+ break;
+ }
+ }
+
+ video->headerInfo.CBP[mbnum] = 0;
+ video->acPredFlag[mbnum] = 0;
+ GetMBData_DataPart(video);
+ video->usePrevQP = 1;
+ }
+ return;
+}
+
+/* ====================================================================== /
+Function : ConcealTexture_P()
+Date : 05/16/2000
+Purpose : Conceal texture for P-partition
+In/out :
+Return :
+/ ====================================================================== */
+
+void ConcealTexture_P(VideoDecData *video, int mb_start, int mb_stop, int slice_counter)
+{
+ int mbnum;
+
+ for (mbnum = mb_start; mbnum < mb_stop; mbnum++)
+ {
+ video->mbnum = mbnum;
+ video->mbnum_row = PV_GET_ROW(mbnum, video->nMBPerRow);
+ video->mbnum_col = mbnum - video->mbnum_row * video->nMBPerRow;
+ video->sliceNo[mbnum] = (uint8) slice_counter;
+ oscl_memset(video->mblock->block, 0, sizeof(typeMBStore));
+ /* to get rid of dark region caused by INTRA blocks */
+ /* 05/19/2000 */
+ if (video->headerInfo.Mode[mbnum] & INTER_MASK)
+ {
+ MBMotionComp(video, 0);
+ }
+ else
+ {
+ video->headerInfo.Mode[mbnum] = MODE_SKIPPED;
+ SkippedMBMotionComp(video);
+ }
+ }
+
+ return;
+}
+
+/***************************************************************
+Function: ConcealPacket
+Purpose : Conceal motion and texture of a packet by direct
+copying from previous frame.
+Returned: void
+Modified:
+*************************************************************/
+void ConcealPacket(VideoDecData *video,
+ int mb_start,
+ int mb_stop,
+ int slice_counter)
+{
+ int i;
+ for (i = mb_start; i < mb_stop; i++)
+ {
+ CopyVopMB(video->currVop, video->concealFrame, i, video->width, video->height);
+ video->sliceNo[i] = (uint8) slice_counter;
+ video->headerInfo.Mode[i] = MODE_SKIPPED;
+ }
+
+ return;
+}
+
+/****************************************************************************
+Function: CopyVopMB
+Purpose : Fill a macroblock with previous Vop.
+Returned : void
+Modified: 6/04/2001 rewrote the function
+ copies from concealFrame
+****************************************************************************/
+void CopyVopMB(Vop *curr, uint8 *prevFrame, int mbnum, int width_Y, int height)
+{
+ if (curr == NULL || prevFrame == NULL) {
+ ALOGE("b/24630158");
+ return;
+ }
+ int width_C = width_Y >> 1;
+ int row = MB_SIZE;
+ uint8 *y1, *y2, *u1, *u2, *v1, *v2;
+ int xpos, ypos, MB_in_width;
+ int32 lumstart, chrstart, size;
+
+ MB_in_width = (width_Y + 15) >> 4;
+ ypos = PV_GET_ROW(mbnum, MB_in_width);
+ xpos = mbnum - ypos * MB_in_width;
+ lumstart = (ypos << 4) * (int32)width_Y + (xpos << 4);
+ chrstart = (ypos << 3) * (int32)width_C + (xpos << 3);
+
+ size = (int32)height * width_Y;
+
+ y1 = curr->yChan + lumstart;
+ u1 = curr->uChan + chrstart;
+ v1 = curr->vChan + chrstart;
+ y2 = prevFrame + lumstart;
+ u2 = prevFrame + size + chrstart;
+ v2 = prevFrame + size + (size >> 2) + chrstart;
+ while (row)
+ {
+ oscl_memcpy(y1, y2, MB_SIZE);
+ y1 += width_Y;
+ y2 += width_Y;
+ oscl_memcpy(y1, y2, MB_SIZE);
+ y1 += width_Y;
+ y2 += width_Y;
+ oscl_memcpy(y1, y2, MB_SIZE);
+ y1 += width_Y;
+ y2 += width_Y;
+ oscl_memcpy(y1, y2, MB_SIZE);
+ y1 += width_Y;
+ y2 += width_Y;
+
+ oscl_memcpy(u1, u2, B_SIZE);
+ u1 += width_C;
+ u2 += width_C;
+ oscl_memcpy(u1, u2, B_SIZE);
+ u1 += width_C;
+ u2 += width_C;
+
+ oscl_memcpy(v1, v2, B_SIZE);
+ v1 += width_C;
+ v2 += width_C;
+ oscl_memcpy(v1, v2, B_SIZE);
+ v1 += width_C;
+ v2 += width_C;
+
+ row -= 4;
+ }
+ return;
+} /* CopyVopMB */
+
diff --git a/media/codecs/m4v_h263/dec/src/datapart_decode.cpp b/media/codecs/m4v_h263/dec/src/datapart_decode.cpp
new file mode 100644
index 0000000..6071f40
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/datapart_decode.cpp
@@ -0,0 +1,758 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4dec_lib.h"
+#include "vlc_decode.h"
+#include "bitstream.h"
+#include "scaling.h"
+#include "mbtype_mode.h"
+#include "idct.h"
+
+#define OSCL_DISABLE_WARNING_CONDITIONAL_IS_CONSTANT
+/* ======================================================================== */
+/* Function : DecodeFrameDataPartMode() */
+/* Purpose : Decode a frame of MPEG4 bitstream in datapartitioning mode. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* */
+/* 04/25/2000 : Rewrite the data partitioning path completely */
+/* according to the pseudo codes in MPEG-4 */
+/* standard. */
+/* Modified : 09/18/2000 add fast VlcDecode+Dequant */
+/* 04/17/2001 cleanup */
+/* ======================================================================== */
+PV_STATUS DecodeFrameDataPartMode(VideoDecData *video)
+{
+ PV_STATUS status;
+ Vop *currVop = video->currVop;
+ BitstreamDecVideo *stream = video->bitstream;
+
+ int nMBPerRow = video->nMBPerRow;
+
+ int vopType = currVop->predictionType;
+ int mbnum;
+ int nTotalMB = video->nTotalMB;
+ int slice_counter;
+ int resync_marker_length;
+
+ /* copy and pad to prev_Vop for INTER coding */
+ switch (vopType)
+ {
+ case I_VOP :
+// oscl_memset(Mode, MODE_INTRA, sizeof(uint8)*nTotalMB);
+ resync_marker_length = 17;
+ break;
+ case P_VOP :
+ oscl_memset(video->motX, 0, sizeof(MOT)*4*nTotalMB);
+ oscl_memset(video->motY, 0, sizeof(MOT)*4*nTotalMB);
+// oscl_memset(Mode, MODE_INTER, sizeof(uint8)*nTotalMB);
+ resync_marker_length = 16 + currVop->fcodeForward;
+ break;
+ default :
+ mp4dec_log("DecodeFrameDataPartMode(): Vop type not supported.\n");
+ return PV_FAIL;
+ }
+
+ /** Initialize sliceNo ***/
+ mbnum = slice_counter = 0;
+// oscl_memset(video->sliceNo, 0, sizeof(uint8)*nTotalMB);
+
+ do
+ {
+ /* This section is equivalent to motion_shape_texture() */
+ /* in the MPEG-4 standard. 04/13/2000 */
+ video->mbnum = mbnum;
+ video->mbnum_row = PV_GET_ROW(mbnum, nMBPerRow); /* This is needed if nbnum is read from the packet header */
+ video->mbnum_col = mbnum - video->mbnum_row * nMBPerRow;
+
+ switch (vopType)
+ {
+ case I_VOP :
+ status = DecodeDataPart_I_VideoPacket(video, slice_counter);
+ break;
+
+ case P_VOP :
+ status = DecodeDataPart_P_VideoPacket(video, slice_counter);
+ break;
+
+ default :
+ mp4dec_log("DecodeFrameDataPartMode(): Vop type not supported.\n");
+ return PV_FAIL;
+ }
+
+ while ((status = PV_ReadVideoPacketHeader(video, &mbnum)) == PV_FAIL)
+ {
+ if ((status = quickSearchVideoPacketHeader(stream, resync_marker_length)) != PV_SUCCESS)
+ {
+ break;
+ }
+ }
+
+ if (status == PV_END_OF_VOP)
+ {
+ mbnum = nTotalMB;
+ }
+
+ if (mbnum > video->mbnum + 1)
+ {
+ ConcealPacket(video, video->mbnum, mbnum, slice_counter);
+ }
+ slice_counter++;
+ if (mbnum >= nTotalMB)
+ {
+ break;
+ }
+
+
+ }
+ while (TRUE);
+
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : DecodeDataPart_I_VideoPacket() */
+/* Date : 04/25/2000 */
+/* Purpose : Decode Data Partitioned Mode Video Packet in I-VOP */
+/* In/out : */
+/* Return : PV_SUCCESS if successed, PV_FAIL if failed. */
+/* Modified : 09/18/2000 add fast VlcDecode+Dequant */
+/* 04/01/2001 fixed MB_stuffing, removed unnecessary code */
+/* ======================================================================== */
+PV_STATUS DecodeDataPart_I_VideoPacket(VideoDecData *video, int slice_counter)
+{
+ PV_STATUS status;
+ uint8 *Mode = video->headerInfo.Mode;
+ BitstreamDecVideo *stream = video->bitstream;
+ int nTotalMB = video->nTotalMB;
+ int mbnum, mb_start, mb_end;
+ int16 QP, *QPMB = video->QPMB;
+ int MBtype, MCBPC, CBPY;
+ uint32 tmpvar;
+ uint code;
+ int nMBPerRow = video->nMBPerRow;
+ Bool valid_stuffing;
+ int32 startSecondPart, startFirstPart = getPointer(stream);
+
+ /* decode the first partition */
+ QP = video->currVop->quantizer;
+ mb_start = mbnum = video->mbnum;
+ video->usePrevQP = 0; /* 04/27/01 */
+
+
+ BitstreamShowBits16(stream, 9, &code);
+ while (code == 1)
+ {
+ PV_BitstreamFlushBits(stream, 9);
+ BitstreamShowBits16(stream, 9, &code);
+ }
+
+ do
+ {
+ /* decode COD, MCBPC, ACpred_flag, CPBY and DQUANT */
+ MCBPC = PV_VlcDecMCBPC_com_intra(stream);
+
+ if (!VLC_ERROR_DETECTED(MCBPC))
+ {
+ Mode[mbnum] = (uint8)(MBtype = MBtype_mode[MCBPC & 7]);
+ video->headerInfo.CBP[mbnum] = (uint8)((MCBPC >> 4) & 3);
+ status = GetMBheaderDataPart_DQUANT_DC(video, &QP);
+ video->usePrevQP = 1; /* set it after the first coded MB 04/27/01 */
+ }
+ else
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ video->mbnum = mb_start;
+ movePointerTo(stream, startFirstPart);
+ return PV_FAIL;
+ }
+
+ video->sliceNo[mbnum] = (uint8) slice_counter;
+ QPMB[mbnum] = QP;
+ video->mbnum = ++mbnum;
+
+ BitstreamShowBits16(stream, 9, &code);
+ while (code == 1)
+ {
+ PV_BitstreamFlushBits(stream, 9);
+ BitstreamShowBits16(stream, 9, &code);
+ }
+ /* have we reached the end of the video packet or vop? */
+ status = BitstreamShowBits32(stream, DC_MARKER_LENGTH, &tmpvar);
+
+ }
+ while (tmpvar != DC_MARKER && video->mbnum < nTotalMB);
+
+ if (tmpvar == DC_MARKER)
+ {
+ PV_BitstreamFlushBits(stream, DC_MARKER_LENGTH);
+ }
+ else
+ {
+ status = quickSearchDCM(stream);
+ if (status == PV_SUCCESS)
+ {
+ /* only way you can end up being here is in the last packet,and there is stuffing at
+ the end of the first partition */
+ PV_BitstreamFlushBits(stream, DC_MARKER_LENGTH);
+ }
+ else
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startFirstPart);
+ video->mbnum = mb_start;
+ /* concealment will be taken care of in the upper layer */
+ return PV_FAIL;
+ }
+ }
+
+ /* decode the second partition */
+ startSecondPart = getPointer(stream);
+
+ mb_end = video->mbnum;
+
+ for (mbnum = mb_start; mbnum < mb_end; mbnum++)
+ {
+ MBtype = Mode[mbnum];
+ /* No skipped mode in I-packets 3/1/2001 */
+ video->mbnum = mbnum;
+
+ video->mbnum_row = PV_GET_ROW(mbnum, nMBPerRow); /* This is needed if nbnum is read from the packet header */
+ video->mbnum_col = mbnum - video->mbnum_row * nMBPerRow;
+ /* there is always acdcpred in DataPart mode 04/10/01 */
+ video->acPredFlag[mbnum] = (uint8) BitstreamRead1Bits(stream);
+
+ CBPY = PV_VlcDecCBPY(stream, MBtype & INTRA_MASK); /* MODE_INTRA || MODE_INTRA_Q */
+ if (CBPY < 0)
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startSecondPart); /* */
+ /* Conceal packet, 05/15/2000 */
+ ConcealTexture_I(video, startFirstPart, mb_start, mb_end, slice_counter);
+ return PV_FAIL;
+ }
+
+ video->headerInfo.CBP[mbnum] |= (uint8)(CBPY << 2);
+ }
+
+ video->usePrevQP = 0;
+
+ for (mbnum = mb_start; mbnum < mb_end; mbnum++)
+ {
+ video->mbnum = mbnum;
+
+ video->mbnum_row = PV_GET_ROW(mbnum , nMBPerRow); /* This is needed if nbnum is read from the packet header */
+ video->mbnum_col = mbnum - video->mbnum_row * nMBPerRow;
+ /* No skipped mode in I-packets 3/1/2001 */
+ /* decode the DCT coeficients for the MB */
+ status = GetMBData_DataPart(video);
+ if (status != PV_SUCCESS)
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startSecondPart); /* */
+ /* Conceal packet, 05/15/2000 */
+ ConcealTexture_I(video, startFirstPart, mb_start, mb_end, slice_counter);
+ return status;
+ }
+ video->usePrevQP = 1; /* 04/27/01 should be set after decoding first MB */
+ }
+
+ valid_stuffing = validStuffing(stream);
+ if (!valid_stuffing)
+ {
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startSecondPart);
+ ConcealTexture_I(video, startFirstPart, mb_start, mb_end, slice_counter);
+ return PV_FAIL;
+ }
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : DecodeDataPart_P_VideoPacket() */
+/* Date : 04/25/2000 */
+/* Purpose : Decode Data Partitioned Mode Video Packet in P-VOP */
+/* In/out : */
+/* Return : PV_SUCCESS if successed, PV_FAIL if failed. */
+/* Modified : 09/18/2000, fast VlcDecode+Dequant */
+/* 04/13/2001, fixed MB_stuffing, new ACDC pred structure, */
+/* cleanup */
+/* 08/07/2001, remove MBzero */
+/* ======================================================================== */
+PV_STATUS DecodeDataPart_P_VideoPacket(VideoDecData *video, int slice_counter)
+{
+ PV_STATUS status;
+ uint8 *Mode = video->headerInfo.Mode;
+ BitstreamDecVideo *stream = video->bitstream;
+ int nTotalMB = video->nTotalMB;
+ int mbnum, mb_start, mb_end;
+ int16 QP, *QPMB = video->QPMB;
+ int MBtype, CBPY;
+ Bool valid_stuffing;
+ int intra_MB;
+ uint32 tmpvar;
+ uint code;
+ int32 startFirstPart, startSecondPart;
+ int nMBPerRow = video->nMBPerRow;
+ uint8 *pbyte;
+ /* decode the first partition */
+ startFirstPart = getPointer(stream);
+ mb_start = video->mbnum;
+ video->usePrevQP = 0; /* 04/27/01 */
+
+ BitstreamShowBits16(stream, 10, &code);
+ while (code == 1)
+ {
+ PV_BitstreamFlushBits(stream, 10);
+ BitstreamShowBits16(stream, 10, &code);
+ }
+
+ do
+ {
+ /* decode COD, MCBPC, ACpred_flag, CPBY and DQUANT */
+ /* We have to discard stuffed MB header */
+
+ status = GetMBheaderDataPart_P(video);
+
+ if (status != PV_SUCCESS)
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startFirstPart);
+ video->mbnum = mb_start;
+ return PV_FAIL;
+ }
+
+ /* we must update slice_counter before motion vector decoding. */
+ video->sliceNo[video->mbnum] = (uint8) slice_counter;
+
+ if (Mode[video->mbnum] & INTER_MASK) /* INTER || INTER_Q || INTER_4V */
+ {
+ /* decode the motion vector (if there are any) */
+ status = PV_GetMBvectors(video, Mode[video->mbnum]);
+ if (status != PV_SUCCESS)
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startFirstPart);
+ video->mbnum = mb_start;
+ return PV_FAIL;
+ }
+ }
+ video->mbnum++;
+
+ video->mbnum_row = PV_GET_ROW(video->mbnum, nMBPerRow); /* This is needed if mbnum is read from the packet header */
+ video->mbnum_col = video->mbnum - video->mbnum_row * nMBPerRow;
+
+ BitstreamShowBits16(stream, 10, &code);
+ while (code == 1)
+ {
+ PV_BitstreamFlushBits(stream, 10);
+ BitstreamShowBits16(stream, 10, &code);
+ }
+ /* have we reached the end of the video packet or vop? */
+ status = BitstreamShowBits32(stream, MOTION_MARKER_COMB_LENGTH, &tmpvar);
+ /* if (status != PV_SUCCESS && status != PV_END_OF_BUFFER) return status; */
+ }
+ while (tmpvar != MOTION_MARKER_COMB && video->mbnum < nTotalMB);
+
+ if (tmpvar == MOTION_MARKER_COMB)
+ {
+ PV_BitstreamFlushBits(stream, MOTION_MARKER_COMB_LENGTH);
+ }
+ else
+ {
+ status = quickSearchMotionMarker(stream);
+ if (status == PV_SUCCESS)
+ {
+ /* only way you can end up being here is in the last packet,and there is stuffing at
+ the end of the first partition */
+ PV_BitstreamFlushBits(stream, MOTION_MARKER_COMB_LENGTH);
+ }
+ else
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startFirstPart);
+ video->mbnum = mb_start;
+ /* concealment will be taken care of in the upper layer */
+ return PV_FAIL;
+ }
+ }
+
+ /* decode the second partition */
+ startSecondPart = getPointer(stream);
+ QP = video->currVop->quantizer;
+
+ mb_end = video->mbnum;
+
+ for (mbnum = mb_start; mbnum < mb_end; mbnum++)
+ {
+ MBtype = Mode[mbnum];
+
+ if (MBtype == MODE_SKIPPED)
+ {
+ QPMB[mbnum] = QP; /* 03/01/01 */
+ continue;
+ }
+ intra_MB = (MBtype & INTRA_MASK); /* (MBtype == MODE_INTRA || MBtype == MODE_INTRA_Q) */
+ video->mbnum = mbnum;
+ video->mbnum_row = PV_GET_ROW(mbnum, nMBPerRow); /* This is needed if nbnum is read from the packet header */
+ video->mbnum_col = mbnum - video->mbnum_row * nMBPerRow;
+
+ /* there is always acdcprediction in DataPart mode 04/10/01 */
+ if (intra_MB)
+ {
+ video->acPredFlag[mbnum] = (uint8) BitstreamRead1Bits_INLINE(stream);
+ }
+
+ CBPY = PV_VlcDecCBPY(stream, intra_MB);
+ if (CBPY < 0)
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+ /* Conceal second partition, 5/15/2000 */
+ movePointerTo(stream, startSecondPart);
+ ConcealTexture_P(video, mb_start, mb_end, slice_counter);
+ return PV_FAIL;
+ }
+
+ video->headerInfo.CBP[mbnum] |= (uint8)(CBPY << 2);
+ if (intra_MB || MBtype == MODE_INTER_Q) /* 04/26/01 */
+ {
+ status = GetMBheaderDataPart_DQUANT_DC(video, &QP);
+ if (status != PV_SUCCESS) return status;
+ }
+ video->usePrevQP = 1; /* 04/27/01 */
+ QPMB[mbnum] = QP;
+ }
+
+ video->usePrevQP = 0; /* 04/27/01 */
+
+ for (mbnum = mb_start; mbnum < mb_end; mbnum++)
+ {
+ video->mbnum = mbnum;
+ video->mbnum_row = PV_GET_ROW(mbnum, nMBPerRow); /* This is needed if nbnum is read from the packet header */
+ video->mbnum_col = mbnum - video->mbnum_row * nMBPerRow;
+
+
+ if (Mode[mbnum] != MODE_SKIPPED)
+ {
+ /* decode the DCT coeficients for the MB */
+ status = GetMBData_DataPart(video);
+ if (status != PV_SUCCESS)
+ {
+ /* Report the error to the application. 06/20/2000 */
+ VideoDecoderErrorDetected(video);
+
+ /* Conceal second partition, 5/15/2000 */
+ movePointerTo(stream, startSecondPart);
+ ConcealTexture_P(video, mb_start, mb_end, slice_counter);
+ return status;
+ }
+ video->usePrevQP = 1; /* 04/27/01 */
+ }
+ else
+ { // SKIPPED
+
+ /* Motion compensation and put it to video->mblock->pred_block */
+ SkippedMBMotionComp(video);
+
+ //oscl_memset(video->predDCAC_row + video->mbnum_col, 0, sizeof(typeDCACStore)); /* SKIPPED_ACDC */
+ //oscl_memset(video->predDCAC_col, 0, sizeof(typeDCACStore));
+ /* 08/08/2005 */
+ pbyte = (uint8*)(video->predDCAC_row + video->mbnum_col);
+ ZERO_OUT_64BYTES(pbyte);
+ pbyte = (uint8*)(video->predDCAC_col);
+ ZERO_OUT_64BYTES(pbyte);
+
+ }
+ }
+
+ valid_stuffing = validStuffing(stream); /* */
+ if (!valid_stuffing)
+ {
+ VideoDecoderErrorDetected(video);
+ movePointerTo(stream, startSecondPart); /* */
+ ConcealTexture_P(video, mb_start, mb_end, slice_counter);
+
+ return PV_FAIL;
+ }
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : GetMBheaderDataPart_DQUANT_DC() */
+/* Date : 04/26/2000 */
+/* Purpose : Decode DQUANT and DC in Data Partitioned Mode for both */
+/* I-VOP and P-VOP. */
+/* In/out : */
+/* Return : PV_SUCCESS if successed, PV_FAIL if failed. */
+/* Modified : 02/13/2001 new ACDC prediction structure, */
+/* cleanup */
+/* ======================================================================== */
+PV_STATUS GetMBheaderDataPart_DQUANT_DC(VideoDecData *video, int16 *QP)
+{
+ PV_STATUS status = PV_SUCCESS;
+ BitstreamDecVideo *stream = video->bitstream;
+ int mbnum = video->mbnum;
+ int intra_dc_vlc_thr = video->currVop->intraDCVlcThr;
+ uint8 *Mode = video->headerInfo.Mode;
+ int MBtype = Mode[mbnum];
+ typeDCStore *DC = video->predDC + mbnum;
+ int comp;
+ Bool switched;
+ uint DQUANT;
+ int16 QP_tmp;
+
+ const static int DQ_tab[4] = { -1, -2, 1, 2};
+
+ if (MBtype & Q_MASK) /* INTRA_Q || INTER_Q */
+ {
+ DQUANT = BitstreamReadBits16(stream, 2);
+ *QP += DQ_tab[DQUANT];
+
+ if (*QP < 1) *QP = 1;
+ else if (*QP > 31) *QP = 31;
+ }
+ if (MBtype & INTRA_MASK) /* INTRA || INTRA_Q */ /* no switch, code DC separately */
+ {
+ QP_tmp = *QP; /* running QP 04/26/01*/
+ switched = 0;
+ if (intra_dc_vlc_thr) /* 04/27/01 */
+ {
+ if (video->usePrevQP)
+ QP_tmp = video->QPMB[mbnum-1];
+ switched = (intra_dc_vlc_thr == 7 || QP_tmp >= intra_dc_vlc_thr * 2 + 11);
+ }
+ if (!switched)
+ {
+ for (comp = 0; comp < 6; comp++)
+ {
+ status = PV_DecodePredictedIntraDC(comp, stream, (*DC + comp)); /* 03/01/01 */
+ if (status != PV_SUCCESS) return PV_FAIL;
+ }
+ }
+ else
+ {
+ for (comp = 0; comp < 6; comp++)
+ {
+ (*DC)[comp] = 0; /* 04/26/01 needed for switched case*/
+ }
+ }
+ }
+ return status;
+}
+
+
+/***********************************************************CommentBegin******
+* 04/25/2000 : Initial modification to the new PV Lib format.
+* 04/17/2001 : new ACDC pred structure
+***********************************************************CommentEnd********/
+PV_STATUS GetMBheaderDataPart_P(VideoDecData *video)
+{
+ BitstreamDecVideo *stream = video->bitstream;
+ int mbnum = video->mbnum;
+ uint8 *Mode = video->headerInfo.Mode;
+ typeDCStore *DC = video->predDC + mbnum;
+ uint no_dct_flag;
+ int comp;
+ int MCBPC;
+
+ no_dct_flag = BitstreamRead1Bits_INLINE(stream);
+
+ if (no_dct_flag)
+ {
+ /* skipped macroblock */
+ Mode[mbnum] = MODE_SKIPPED;
+
+ for (comp = 0; comp < 6; comp++)
+ {
+ (*DC)[comp] = mid_gray;
+ /* ACDC REMOVE AC coefs are set in DecodeDataPart_P */
+ }
+ }
+ else
+ {
+ /* coded macroblock */
+ MCBPC = PV_VlcDecMCBPC_com_inter(stream);
+
+ if (VLC_ERROR_DETECTED(MCBPC))
+ {
+ return PV_FAIL;
+ }
+
+ Mode[mbnum] = (uint8)MBtype_mode[MCBPC & 7];
+ video->headerInfo.CBP[mbnum] = (uint8)((MCBPC >> 4) & 3);
+ }
+
+ return PV_SUCCESS;
+}
+
+
+/***********************************************************CommentBegin******
+* 04/17/01 new ACDC pred structure, reorganized code, cleanup
+***********************************************************CommentEnd********/
+PV_STATUS GetMBData_DataPart(VideoDecData *video)
+{
+ int mbnum = video->mbnum;
+ int16 *dataBlock;
+ MacroBlock *mblock = video->mblock;
+ int QP = video->QPMB[mbnum];
+ int32 offset;
+ PIXEL *c_comp;
+ int width = video->width;
+ int intra_dc_vlc_thr = video->currVop->intraDCVlcThr;
+ uint CBP = video->headerInfo.CBP[mbnum];
+ uint8 mode = video->headerInfo.Mode[mbnum];
+ int x_pos = video->mbnum_col;
+ typeDCStore *DC = video->predDC + mbnum;
+ int ncoeffs[6], *no_coeff = mblock->no_coeff;
+ int comp;
+ Bool switched;
+ int QP_tmp = QP;
+
+ int y_pos = video->mbnum_row;
+
+
+
+
+ /* oscl_memset(mblock->block, 0, sizeof(typeMBStore)); Aug 9,2005 */
+
+ if (mode & INTRA_MASK) /* MODE_INTRA || mode == MODE_INTRA_Q */
+ {
+ switched = 0;
+ if (intra_dc_vlc_thr)
+ {
+ if (video->usePrevQP)
+ QP_tmp = video->QPMB[mbnum-1]; /* running QP 04/26/01 */
+
+ switched = (intra_dc_vlc_thr == 7 || QP_tmp >= intra_dc_vlc_thr * 2 + 11);
+ }
+
+ mblock->DCScalarLum = cal_dc_scaler(QP, LUMINANCE_DC_TYPE); /* ACDC 03/01/01 */
+ mblock->DCScalarChr = cal_dc_scaler(QP, CHROMINANCE_DC_TYPE);
+
+ for (comp = 0; comp < 6; comp++)
+ {
+ dataBlock = mblock->block[comp]; /*, 10/20/2000 */
+
+ dataBlock[0] = (*DC)[comp];
+
+ ncoeffs[comp] = VlcDequantH263IntraBlock(video, comp,
+ switched, mblock->bitmapcol[comp], &mblock->bitmaprow[comp]);
+
+ if (VLC_ERROR_DETECTED(ncoeffs[comp])) /* */
+ {
+ if (switched)
+ return PV_FAIL;
+ else
+ {
+ ncoeffs[comp] = 1;
+ oscl_memset((dataBlock + 1), 0, sizeof(int16)*63);
+ }
+ }
+ no_coeff[comp] = ncoeffs[comp];
+ /* modified to new semaphore for post-proc */
+ // Future work:: can be combined in the dequant function
+ // @todo Deblocking Semaphore for INTRA block
+ }
+ MBlockIDCT(video);
+ }
+ else /* MODE INTER*/
+ {
+
+
+
+
+ MBMotionComp(video, CBP);
+ offset = (int32)(y_pos << 4) * width + (x_pos << 4);
+ c_comp = video->currVop->yChan + offset;
+
+
+ for (comp = 0; comp < 4; comp++)
+ {
+ (*DC)[comp] = mid_gray;
+
+ if (CBP & (1 << (5 - comp)))
+ {
+ ncoeffs[comp] = VlcDequantH263InterBlock(video, comp,
+ mblock->bitmapcol[comp], &mblock->bitmaprow[comp]);
+ if (VLC_ERROR_DETECTED(ncoeffs[comp]))
+ return PV_FAIL;
+
+
+ BlockIDCT(c_comp + (comp&2)*(width << 2) + 8*(comp&1), mblock->pred_block + (comp&2)*64 + 8*(comp&1), mblock->block[comp], width, ncoeffs[comp],
+ mblock->bitmapcol[comp], mblock->bitmaprow[comp]);
+
+ }
+ else
+ {
+ ncoeffs[comp] = 0;
+ }
+
+ /* @todo Deblocking Semaphore for INTRA block, for inter just test for ringing */
+ }
+
+ (*DC)[4] = mid_gray;
+ if (CBP & 2)
+ {
+ ncoeffs[4] = VlcDequantH263InterBlock(video, 4,
+ mblock->bitmapcol[4], &mblock->bitmaprow[4]);
+ if (VLC_ERROR_DETECTED(ncoeffs[4]))
+ return PV_FAIL;
+
+ BlockIDCT(video->currVop->uChan + (offset >> 2) + (x_pos << 2), mblock->pred_block + 256, mblock->block[4], width >> 1, ncoeffs[4],
+ mblock->bitmapcol[4], mblock->bitmaprow[4]);
+
+ }
+ else
+ {
+ ncoeffs[4] = 0;
+ }
+ (*DC)[5] = mid_gray;
+ if (CBP & 1)
+ {
+ ncoeffs[5] = VlcDequantH263InterBlock(video, 5,
+ mblock->bitmapcol[5], &mblock->bitmaprow[5]);
+ if (VLC_ERROR_DETECTED(ncoeffs[5]))
+ return PV_FAIL;
+
+ BlockIDCT(video->currVop->vChan + (offset >> 2) + (x_pos << 2), mblock->pred_block + 264, mblock->block[5], width >> 1, ncoeffs[5],
+ mblock->bitmapcol[5], mblock->bitmaprow[5]);
+
+ }
+ else
+ {
+ ncoeffs[5] = 0;
+ }
+
+
+
+
+ /* Motion compensation and put it to video->mblock->pred_block */
+ }
+ return PV_SUCCESS;
+}
diff --git a/media/codecs/m4v_h263/dec/src/dcac_prediction.cpp b/media/codecs/m4v_h263/dec/src/dcac_prediction.cpp
new file mode 100644
index 0000000..2a8bf1e
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/dcac_prediction.cpp
@@ -0,0 +1,368 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+#include "vlc_decode.h"
+#include "bitstream.h"
+#include "zigzag.h"
+#include "scaling.h"
+
+void doDCACPrediction(
+ VideoDecData *video,
+ int comp,
+ int16 *q_block,
+ int *direction
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int i;
+ int mbnum = video->mbnum;
+ int nMBPerRow = video->nMBPerRow;
+ int x_pos = video->mbnum_col;
+ int y_pos = video->mbnum_row;
+ int16 *AC_tmp;
+ int QP_tmp;
+ int16 *QP_store = video->QPMB + mbnum;
+ int QP = video->QPMB[mbnum];
+ int QP_half = QP >> 1;
+ int32 val;
+ int flag_0 = FALSE, flag_1 = FALSE;
+ uint8 *slice_nb = video->sliceNo;
+ typeDCStore *DC_store = video->predDC + mbnum;
+ typeDCACStore *DCAC_row = video->predDCAC_row + x_pos;
+ typeDCACStore *DCAC_col = video->predDCAC_col;
+
+ uint ACpred_flag = (uint) video->acPredFlag[mbnum];
+
+ int left_bnd, up_bnd;
+
+ static const int Xpos[6] = { -1, 0, -1, 0, -1, -1};
+ static const int Ypos[6] = { -1, -1, 0, 0, -1, -1};
+
+ static const int Xtab[6] = {1, 0, 3, 2, 4, 5};
+ static const int Ytab[6] = {2, 3, 0, 1, 4, 5};
+ static const int Ztab[6] = {3, 2, 1, 0, 4, 5};
+
+ /* I added these to speed up comparisons */
+ static const int Pos0[6] = { 1, 1, 0, 0, 1, 1};
+ static const int Pos1[6] = { 1, 0, 1, 0, 1, 1};
+
+ static const int B_Xtab[6] = {0, 1, 0, 1, 2, 3};
+ static const int B_Ytab[6] = {0, 0, 1, 1, 2, 3};
+
+// int *direction; /* 0: HORIZONTAL, 1: VERTICAL */
+ int block_A, block_B, block_C;
+ int DC_pred;
+ int y_offset, x_offset, x_tab, y_tab, z_tab; /* speedup coefficients */
+ int b_xtab, b_ytab;
+
+ if (!comp && x_pos && !(video->headerInfo.Mode[mbnum-1]&INTRA_MASK)) /* not intra */
+ {
+ oscl_memset(DCAC_col, 0, sizeof(typeDCACStore));
+ }
+ if (!comp && y_pos && !(video->headerInfo.Mode[mbnum-nMBPerRow]&INTRA_MASK)) /* not intra */
+ {
+ oscl_memset(DCAC_row, 0, sizeof(typeDCACStore));
+ }
+
+ y_offset = Ypos[comp] * nMBPerRow;
+ x_offset = Xpos[comp];
+ x_tab = Xtab[comp];
+ y_tab = Ytab[comp];
+ z_tab = Ztab[comp];
+
+ b_xtab = B_Xtab[comp];
+ b_ytab = B_Ytab[comp];
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* Find the direction of prediction and the DC prediction */
+
+ if (x_pos == 0 && y_pos == 0)
+ { /* top left corner */
+ block_A = (comp == 1 || comp == 3) ? flag_0 = TRUE, DC_store[0][x_tab] : mid_gray;
+ block_B = (comp == 3) ? DC_store[x_offset][z_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3) ? flag_1 = TRUE, DC_store[0][y_tab] : mid_gray;
+ }
+ else if (x_pos == 0)
+ { /* left edge */
+ up_bnd = Pos0[comp] && slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow];
+
+ block_A = (comp == 1 || comp == 3) ? flag_0 = TRUE, DC_store[0][x_tab] : mid_gray;
+ block_B = ((comp == 1 && up_bnd) || comp == 3) ? DC_store[y_offset+x_offset][z_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3 || up_bnd) ? flag_1 = TRUE, DC_store[y_offset][y_tab] : mid_gray;
+ }
+ else if (y_pos == 0)
+ { /* top row */
+ left_bnd = Pos1[comp] && slice_nb[mbnum] == slice_nb[mbnum-1];
+
+ block_A = (comp == 1 || comp == 3 || left_bnd) ? flag_0 = TRUE, DC_store[x_offset][x_tab] : mid_gray;
+ block_B = ((comp == 2 && left_bnd) || comp == 3) ? DC_store[y_offset + x_offset][z_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3) ? flag_1 = TRUE, DC_store[y_offset][y_tab] : mid_gray;
+ }
+ else
+ {
+ up_bnd = Pos0[comp] && slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow];
+ left_bnd = Pos1[comp] && slice_nb[mbnum] == slice_nb[mbnum-1];
+
+ block_A = (comp == 1 || comp == 3 || left_bnd) ? flag_0 = TRUE, DC_store[x_offset][x_tab] : mid_gray;
+ block_B = (((comp == 0 || comp == 4 || comp == 5) && slice_nb[mbnum] == slice_nb[mbnum-1-nMBPerRow]) ||
+ (comp == 1 && up_bnd) || (comp == 2 && left_bnd) || (comp == 3)) ? DC_store[y_offset+x_offset][z_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3 || up_bnd) ? flag_1 = TRUE, DC_store[y_offset][y_tab] : mid_gray;
+ }
+
+
+ if ((PV_ABS((block_A - block_B))) < (PV_ABS((block_B - block_C))))
+ {
+ DC_pred = block_C;
+ *direction = 1;
+ if (ACpred_flag == 1)
+ {
+ if (flag_1)
+ {
+ AC_tmp = DCAC_row[0][b_xtab];
+ QP_tmp = QP_store[y_offset];
+ if (QP_tmp == QP)
+ {
+ for (i = 1; i < 8; i++)
+ {
+ q_block[i] = *AC_tmp++;
+ }
+ }
+ else
+ {
+ for (i = 1; i < 8; i++)
+ {
+ val = (int32)(*AC_tmp++) * QP_tmp;
+ q_block[i] = (val < 0) ? (int16)((val - QP_half) / QP) : (int16)((val + QP_half) / QP);
+ /* Vertical, top ROW of block C */
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ DC_pred = block_A;
+ *direction = 0;
+ if (ACpred_flag == 1)
+ {
+ if (flag_0)
+ {
+ AC_tmp = DCAC_col[0][b_ytab];
+ QP_tmp = QP_store[x_offset];
+ if (QP_tmp == QP)
+ {
+ for (i = 1; i < 8; i++)
+ {
+ q_block[i<<3] = *AC_tmp++;
+ }
+ }
+ else
+ {
+ for (i = 1; i < 8; i++)
+ {
+ val = (int32)(*AC_tmp++) * QP_tmp;
+ q_block[i<<3] = (val < 0) ? (int16)((val - QP_half) / QP) : (int16)((val + QP_half) / QP);
+ /* Vertical, top ROW of block C */
+ }
+ }
+ }
+ }
+ }
+
+ /* Now predict the DC coefficient */
+ QP_tmp = (comp < 4) ? video->mblock->DCScalarLum : video->mblock->DCScalarChr;
+ q_block[0] += (int16)((DC_pred + (QP_tmp >> 1)) * scale[QP_tmp] >> 18);
+// q_block[0] += (DC_pred+(QP_tmp>>1))/QP_tmp;
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+#ifdef PV_ANNEX_IJKT_SUPPORT
+void doDCACPrediction_I(
+ VideoDecData *video,
+ int comp,
+ int16 *q_block
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int mbnum = video->mbnum;
+ int nMBPerRow = video->nMBPerRow;
+ int x_pos = video->mbnum_col;
+ int y_pos = video->mbnum_row;
+ int16 *AC_tmp;
+ int flag_0 = FALSE, flag_1 = FALSE;
+ uint8 *slice_nb = video->sliceNo;
+ typeDCStore *DC_store = video->predDC + mbnum;
+ typeDCACStore *DCAC_row = video->predDCAC_row + x_pos;
+ typeDCACStore *DCAC_col = video->predDCAC_col;
+ int left_bnd, up_bnd;
+ uint8 *mode = video->headerInfo.Mode;
+ uint ACpred_flag = (uint) video->acPredFlag[mbnum];
+
+
+
+ static const int Xpos[6] = { -1, 0, -1, 0, -1, -1};
+ static const int Ypos[6] = { -1, -1, 0, 0, -1, -1};
+
+ static const int Xtab[6] = {1, 0, 3, 2, 4, 5};
+ static const int Ytab[6] = {2, 3, 0, 1, 4, 5};
+
+ /* I added these to speed up comparisons */
+ static const int Pos0[6] = { 1, 1, 0, 0, 1, 1};
+ static const int Pos1[6] = { 1, 0, 1, 0, 1, 1};
+
+ static const int B_Xtab[6] = {0, 1, 0, 1, 2, 3};
+ static const int B_Ytab[6] = {0, 0, 1, 1, 2, 3};
+
+// int *direction; /* 0: HORIZONTAL, 1: VERTICAL */
+ int block_A, block_C;
+ int y_offset, x_offset, x_tab, y_tab; /* speedup coefficients */
+ int b_xtab, b_ytab;
+ y_offset = Ypos[comp] * nMBPerRow;
+ x_offset = Xpos[comp];
+ x_tab = Xtab[comp];
+ y_tab = Ytab[comp];
+
+ b_xtab = B_Xtab[comp];
+ b_ytab = B_Ytab[comp];
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* Find the direction of prediction and the DC prediction */
+
+ if (x_pos == 0 && y_pos == 0)
+ { /* top left corner */
+ block_A = (comp == 1 || comp == 3) ? flag_0 = TRUE, DC_store[0][x_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3) ? flag_1 = TRUE, DC_store[0][y_tab] : mid_gray;
+ }
+ else if (x_pos == 0)
+ { /* left edge */
+ up_bnd = (Pos0[comp] && slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow])
+ && (mode[mbnum-nMBPerRow] == MODE_INTRA || mode[mbnum-nMBPerRow] == MODE_INTRA_Q);;
+
+ block_A = (comp == 1 || comp == 3) ? flag_0 = TRUE, DC_store[0][x_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3 || up_bnd) ? flag_1 = TRUE, DC_store[y_offset][y_tab] : mid_gray;
+ }
+ else if (y_pos == 0)
+ { /* top row */
+ left_bnd = (Pos1[comp] && slice_nb[mbnum] == slice_nb[mbnum-1])
+ && (mode[mbnum-1] == MODE_INTRA || mode[mbnum-1] == MODE_INTRA_Q);
+
+ block_A = (comp == 1 || comp == 3 || left_bnd) ? flag_0 = TRUE, DC_store[x_offset][x_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3) ? flag_1 = TRUE, DC_store[y_offset][y_tab] : mid_gray;
+ }
+ else
+ {
+ up_bnd = (Pos0[comp] && slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow])
+ && (mode[mbnum-nMBPerRow] == MODE_INTRA || mode[mbnum-nMBPerRow] == MODE_INTRA_Q);
+ left_bnd = (Pos1[comp] && slice_nb[mbnum] == slice_nb[mbnum-1])
+ && (mode[mbnum-1] == MODE_INTRA || mode[mbnum-1] == MODE_INTRA_Q);
+
+ block_A = (comp == 1 || comp == 3 || left_bnd) ? flag_0 = TRUE, DC_store[x_offset][x_tab] : mid_gray;
+ block_C = (comp == 2 || comp == 3 || up_bnd) ? flag_1 = TRUE, DC_store[y_offset][y_tab] : mid_gray;
+ }
+
+ if (ACpred_flag == 0)
+ {
+ if (flag_0 == TRUE)
+ {
+ if (flag_1 == TRUE)
+ {
+ q_block[0] = (int16)((block_A + block_C) >> 1);
+ }
+ else
+ {
+ q_block[0] = (int16)block_A;
+ }
+ }
+ else
+ {
+ if (flag_1 == TRUE)
+ {
+ q_block[0] = (int16)block_C;
+ }
+ else
+ {
+ q_block[0] = mid_gray;
+ }
+ }
+
+ }
+ else
+ {
+ if (video->mblock->direction == 1)
+ {
+ if (flag_1 == TRUE)
+ {
+ q_block[0] = (int16)block_C;
+
+ AC_tmp = DCAC_row[0][b_xtab];
+ q_block[1] = AC_tmp[0];
+ q_block[2] = AC_tmp[1];
+ q_block[3] = AC_tmp[2];
+ q_block[4] = AC_tmp[3];
+ q_block[5] = AC_tmp[4];
+ q_block[6] = AC_tmp[5];
+ q_block[7] = AC_tmp[6];
+ }
+ else
+ {
+ q_block[0] = mid_gray;
+ }
+ }
+ else
+ {
+ if (flag_0 == TRUE)
+ {
+ q_block[0] = (int16)block_A;
+
+ AC_tmp = DCAC_col[0][b_ytab];
+ q_block[8] = AC_tmp[0];
+ q_block[16] = AC_tmp[1];
+ q_block[24] = AC_tmp[2];
+ q_block[32] = AC_tmp[3];
+ q_block[40] = AC_tmp[4];
+ q_block[48] = AC_tmp[5];
+ q_block[56] = AC_tmp[6];
+ }
+ else
+ {
+ q_block[0] = mid_gray;
+ }
+ }
+ }
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+#endif
+
diff --git a/media/codecs/m4v_h263/dec/src/dec_pred_intra_dc.cpp b/media/codecs/m4v_h263/dec/src/dec_pred_intra_dc.cpp
new file mode 100644
index 0000000..c19c23a
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/dec_pred_intra_dc.cpp
@@ -0,0 +1,75 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4dec_lib.h"
+#include "vlc_decode.h"
+#include "bitstream.h"
+#include "zigzag.h"
+
+PV_STATUS PV_DecodePredictedIntraDC(
+ int compnum,
+ BitstreamDecVideo *stream,
+ int16 *INTRADC_delta)
+{
+
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ PV_STATUS status = PV_SUCCESS;
+ uint DC_size;
+ uint code;
+ int first_bit;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* read DC size 2 - 8 bits */
+ status = PV_VlcDecIntraDCPredSize(stream, compnum, &DC_size);
+
+ if (status == PV_SUCCESS)
+ {
+ if (DC_size == 0)
+ {
+ *INTRADC_delta = 0;
+ }
+ else
+ {
+ /* read delta DC 0 - 8 bits */
+ code = (int) BitstreamReadBits16_INLINE(stream, DC_size);
+
+ first_bit = code >> (DC_size - 1);
+
+ if (first_bit == 0)
+ {
+ /* negative delta INTRA DC */
+ *INTRADC_delta = code ^((1 << DC_size) - 1);
+ *INTRADC_delta = -(*INTRADC_delta);
+ }
+ else
+ { /* positive delta INTRA DC */
+ *INTRADC_delta = code;
+ }
+ if (DC_size > 8) BitstreamRead1Bits_INLINE(stream);
+ }
+ }
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return status;
+}
+
diff --git a/media/codecs/m4v_h263/dec/src/get_pred_adv_b_add.cpp b/media/codecs/m4v_h263/dec/src/get_pred_adv_b_add.cpp
new file mode 100644
index 0000000..fe9e7dc
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/get_pred_adv_b_add.cpp
@@ -0,0 +1,1190 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ xpos = x half-pixel of (x,y) coordinates within a VOP; motion
+ compensated coordinates; native type
+ ypos = y half-pixel of (x,y) coordinates within a VOP; motion
+ compensated coordinates; native type
+ comp = pointer to 8-bit compensated prediction values within a VOP;
+ computed by this module (i/o); full-pel resolution
+ c_prev = pointer to previous 8-bit prediction values within a VOP;
+ values range from (0-255); full-pel resolution
+ sh_d = pointer to residual values used to compensate the predicted
+ value; values range from (-512 to 511); full-pel resolution
+ width = width of the VOP in pixels (x axis); full-pel resolution
+ rnd1 = rounding value for case when one dimension uses half-pel
+ resolution
+ rnd2 = rounding value for case when two dimensions uses half-pel
+ resolution
+ CBP = flag indicating whether residual is all zeros
+ (0 -> all zeros, 1 -> not all zeros)
+ outside_flag = flag indicating whether motion vector is outside the
+ VOP (0 -> inside, 1 -> outside)
+
+ Outputs:
+ returns 1
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Pointers and Buffers Modified:
+ comp = buffer contains newly computed compensated prediction values
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Compute pixel values for a block in the current VOP. The prediction
+ values are generated by averaging pixel values in the previous VOP; the
+ block position in the previous frame is computed from the current block's
+ motion vector. The computed pixel values are then computed by adding the
+ prediction values to the block residual values.
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+#include "motion_comp.h"
+
+#define OSCL_DISABLE_WARNING_CONV_POSSIBLE_LOSS_OF_DATA
+
+int GetPredAdvancedBy0x0(
+ uint8 *prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+)
+{
+ uint i; /* loop variable */
+ int offset, offset2;
+ uint32 pred_word, word1, word2;
+ int tmp;
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+ offset = width - B_SIZE; /* offset for prev */
+ offset2 = (pred_width_rnd >> 1) - 4; /* offset for pred_block */
+
+ tmp = (uintptr_t)prev & 0x3;
+ pred_block -= offset2; /* preset */
+
+ if (tmp == 0) /* word-aligned */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ *((uint32*)(pred_block += offset2)) = *((uint32*)prev);
+ *((uint32*)(pred_block += 4)) = *((uint32*)(prev + 4));
+ prev += width;
+ }
+ return 1;
+ }
+ else if (tmp == 1) /* first position */
+ {
+ prev--; /* word-aligned */
+
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* read 4 bytes, b4 b3 b2 b1 */
+ word2 = *((uint32*)(prev += 4)); /* read 4 bytes, b8 b7 b6 b5 */
+ word1 >>= 8; /* 0 b4 b3 b2 */
+ pred_word = word1 | (word2 << 24); /* b5 b4 b3 b2 */
+ *((uint32*)(pred_block += offset2)) = pred_word;
+
+ word1 = *((uint32*)(prev += 4)); /* b12 b11 b10 b9 */
+ word2 >>= 8; /* 0 b8 b7 b6 */
+ pred_word = word2 | (word1 << 24); /* b9 b8 b7 b6 */
+ *((uint32*)(pred_block += 4)) = pred_word;
+
+ prev += offset;
+ }
+
+ return 1;
+ }
+ else if (tmp == 2) /* second position */
+ {
+ prev -= 2; /* word1-aligned */
+
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* read 4 bytes, b4 b3 b2 b1 */
+ word2 = *((uint32*)(prev += 4)); /* read 4 bytes, b8 b7 b6 b5 */
+ word1 >>= 16; /* 0 0 b4 b3 */
+ pred_word = word1 | (word2 << 16); /* b6 b5 b4 b3 */
+ *((uint32*)(pred_block += offset2)) = pred_word;
+
+ word1 = *((uint32*)(prev += 4)); /* b12 b11 b10 b9 */
+ word2 >>= 16; /* 0 0 b8 b7 */
+ pred_word = word2 | (word1 << 16); /* b10 b9 b8 b7 */
+ *((uint32*)(pred_block += 4)) = pred_word;
+
+
+ prev += offset;
+ }
+
+ return 1;
+ }
+ else /* third position */
+ {
+ prev -= 3; /* word1-aligned */
+
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* read 4 bytes, b4 b3 b2 b1 */
+ word2 = *((uint32*)(prev += 4)); /* read 4 bytes, b8 b7 b6 b5 */
+ word1 >>= 24; /* 0 0 0 b4 */
+ pred_word = word1 | (word2 << 8); /* b7 b6 b5 b4 */
+ *((uint32*)(pred_block += offset2)) = pred_word;
+
+ word1 = *((uint32*)(prev += 4)); /* b12 b11 b10 b9 */
+ word2 >>= 24; /* 0 0 0 b8 */
+ pred_word = word2 | (word1 << 8); /* b11 b10 b9 b8 */
+ *((uint32*)(pred_block += 4)) = pred_word;
+
+ prev += offset;
+ }
+
+ return 1;
+ }
+}
+
+/**************************************************************************/
+int GetPredAdvancedBy0x1(
+ uint8 *prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+)
+{
+ uint i; /* loop variable */
+ int offset, offset2;
+ uint32 word1, word2, word3, word12;
+ int tmp;
+ int rnd1;
+ uint32 mask;
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+ offset = width - B_SIZE; /* offset for prev */
+ offset2 = (pred_width_rnd >> 1) - 4; /* offset of pred_block */
+
+ rnd1 = pred_width_rnd & 1;
+
+ /* Branch based on pixel location (half-pel or full-pel) for x and y */
+ pred_block -= offset2; /* preset */
+
+ tmp = (uintptr_t)prev & 3;
+ mask = 254;
+ mask |= (mask << 8);
+ mask |= (mask << 16); /* 0xFEFEFEFE */
+
+ if (tmp == 0) /* word-aligned */
+ {
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b4 b3 b2 b1 */
+ word2 = *((uint32*)(prev += 4)); /* b8 b7 b6 b5 */
+ word12 = (word1 >> 8); /* 0 b4 b3 b2 */
+ word12 |= (word2 << 24); /* b5 b4 b3 b2 */
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b12 b11 b10 b9 */
+ word12 = (word2 >> 8); /* 0 b8 b7 b6 */
+ word12 |= (word1 << 24); /* b9 b8 b7 b6 */
+ word3 = word2 | word12;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 == 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b4 b3 b2 b1 */
+
+ word2 = *((uint32*)(prev += 4)); /* b8 b7 b6 b5 */
+ word12 = (word1 >> 8); /* 0 b4 b3 b2 */
+ word12 |= (word2 << 24); /* b5 b4 b3 b2 */
+ word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b12 b11 b10 b9 */
+ word12 = (word2 >> 8); /* 0 b8 b7 b6 */
+ word12 |= (word1 << 24); /* b9 b8 b7 b6 */
+ word3 = word2 & word12;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ } /* rnd1 */
+ }
+ else if (tmp == 1)
+ {
+ prev--; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b3 b2 b1 b0 */
+ word2 = *((uint32*)(prev += 4)); /* b7 b6 b5 b4 */
+ word12 = (word1 >> 8); /* 0 b3 b2 b1 */
+ word1 >>= 16; /* 0 0 b3 b2 */
+ word12 |= (word2 << 24); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 16); /* b5 b4 b3 b2 */
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b11 b10 b9 b8 */
+ word12 = (word2 >> 8); /* 0 b7 b6 b5 */
+ word2 >>= 16; /* 0 0 b7 b6 */
+ word12 |= (word1 << 24); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 16); /* b9 b8 b7 b6 */
+ word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word2&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b3 b2 b1 b0 */
+
+ word2 = *((uint32*)(prev += 4)); /* b7 b6 b5 b4 */
+ word12 = (word1 >> 8); /* 0 b3 b2 b1 */
+ word1 >>= 16; /* 0 0 b3 b2 */
+ word12 |= (word2 << 24); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 16); /* b5 b4 b3 b2 */
+ word3 = word1 & word12;
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b11 b10 b9 b8 */
+ word12 = (word2 >> 8); /* 0 b7 b6 b5 */
+ word2 >>= 16; /* 0 0 b7 b6 */
+ word12 |= (word1 << 24); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 16); /* b9 b8 b7 b6 */
+ word3 = word2 & word12;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ } /* rnd1 */
+ }
+ else if (tmp == 2)
+ {
+ prev -= 2; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b2 b1 b0 bN1 */
+ word2 = *((uint32*)(prev += 4)); /* b6 b5 b4 b3 */
+ word12 = (word1 >> 16); /* 0 0 b2 b1 */
+ word1 >>= 24; /* 0 0 0 b2 */
+ word12 |= (word2 << 16); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 8); /* b5 b4 b3 b2 */
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b10 b9 b8 b7 */
+ word12 = (word2 >> 16); /* 0 0 b6 b5 */
+ word2 >>= 24; /* 0 0 0 b6 */
+ word12 |= (word1 << 16); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 8); /* b9 b8 b7 b6 */
+ word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 == 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b2 b1 b0 bN1 */
+ word2 = *((uint32*)(prev += 4)); /* b6 b5 b4 b3 */
+ word12 = (word1 >> 16); /* 0 0 b2 b1 */
+ word1 >>= 24; /* 0 0 0 b2 */
+ word12 |= (word2 << 16); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 8); /* b5 b4 b3 b2 */
+ word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b10 b9 b8 b7 */
+ word12 = (word2 >> 16); /* 0 0 b6 b5 */
+ word2 >>= 24; /* 0 0 0 b6 */
+ word12 |= (word1 << 16); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 8); /* b9 b8 b7 b6 */
+ word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+ else /* tmp = 3 */
+ {
+ prev -= 3; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b1 b0 bN1 bN2 */
+ word2 = *((uint32*)(prev += 4)); /* b5 b4 b3 b2 */
+ word12 = (word1 >> 24); /* 0 0 0 b1 */
+ word12 |= (word2 << 8); /* b4 b3 b2 b1 */
+ word1 = word2;
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b9 b8 b7 b6 */
+ word12 = (word2 >> 24); /* 0 0 0 b5 */
+ word12 |= (word1 << 8); /* b8 b7 b6 b5 */
+ word2 = word1; /* b9 b8 b7 b6 */
+ word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ else
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)prev); /* b1 b0 bN1 bN2 */
+ word2 = *((uint32*)(prev += 4)); /* b5 b4 b3 b2 */
+ word12 = (word1 >> 24); /* 0 0 0 b1 */
+ word12 |= (word2 << 8); /* b4 b3 b2 b1 */
+ word1 = word2;
+ word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1; /* write 4 pixels */
+
+ word1 = *((uint32*)(prev += 4)); /* b9 b8 b7 b6 */
+ word12 = (word2 >> 24); /* 0 0 0 b5 */
+ word12 |= (word1 << 8); /* b8 b7 b6 b5 */
+ word2 = word1; /* b9 b8 b7 b6 */
+ word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((uint32*)(pred_block += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+}
+
+/**************************************************************************/
+int GetPredAdvancedBy1x0(
+ uint8 *prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+)
+{
+ uint i; /* loop variable */
+ int offset, offset2;
+ uint32 word1, word2, word3, word12, word22;
+ int tmp;
+ int rnd1;
+ uint32 mask;
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+ offset = width - B_SIZE; /* offset for prev */
+ offset2 = (pred_width_rnd >> 1) - 4; /* offset for pred_block */
+
+ rnd1 = pred_width_rnd & 1;
+
+ /* Branch based on pixel location (half-pel or full-pel) for x and y */
+ pred_block -= offset2; /* preset */
+
+ tmp = (uintptr_t)prev & 3;
+ mask = 254;
+ mask |= (mask << 8);
+ mask |= (mask << 16); /* 0xFEFEFEFE */
+
+ if (tmp == 0) /* word-aligned */
+ {
+ prev -= 4;
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)(prev += 4));
+ word2 = *((uint32*)(prev + width));
+ word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1;
+ word1 = *((uint32*)(prev += 4));
+ word2 = *((uint32*)(prev + width));
+ word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((uint32*)(prev += 4));
+ word2 = *((uint32*)(prev + width));
+ word3 = word1 & word2; /* rnd1 = 0; */
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += offset2)) = word1;
+ word1 = *((uint32*)(prev += 4));
+ word2 = *((uint32*)(prev + width));
+ word3 = word1 & word2; /* rnd1 = 0; */
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+ else if (tmp == 1)
+ {
+ prev--; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((uint32*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((uint32*)(prev + width));
+
+ word1 = *((uint32*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((uint32*)(prev + width));
+ word12 >>= 8; /* 0 b4 b3 b2 */
+ word22 >>= 8;
+ word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
+ word22 = word22 | (word2 << 24);
+ word3 = word12 | word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((uint32*)(pred_block += offset2)) = word12;
+
+ word12 = *((uint32*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((uint32*)(prev + width));
+ word1 >>= 8; /* 0 b8 b7 b6 */
+ word2 >>= 8;
+ word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
+ word2 = word2 | (word22 << 24);
+ word3 = word1 | word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((uint32*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((uint32*)(prev + width));
+
+ word1 = *((uint32*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((uint32*)(prev + width));
+ word12 >>= 8; /* 0 b4 b3 b2 */
+ word22 >>= 8;
+ word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
+ word22 = word22 | (word2 << 24);
+ word3 = word12 & word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((uint32*)(pred_block += offset2)) = word12;
+
+ word12 = *((uint32*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((uint32*)(prev + width));
+ word1 >>= 8; /* 0 b8 b7 b6 */
+ word2 >>= 8;
+ word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
+ word2 = word2 | (word22 << 24);
+ word3 = word1 & word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+ else if (tmp == 2)
+ {
+ prev -= 2; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((uint32*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((uint32*)(prev + width));
+
+ word1 = *((uint32*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((uint32*)(prev + width));
+ word12 >>= 16; /* 0 0 b4 b3 */
+ word22 >>= 16;
+ word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
+ word22 = word22 | (word2 << 16);
+ word3 = word12 | word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((uint32*)(pred_block += offset2)) = word12;
+
+ word12 = *((uint32*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((uint32*)(prev + width));
+ word1 >>= 16; /* 0 0 b8 b7 */
+ word2 >>= 16;
+ word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
+ word2 = word2 | (word22 << 16);
+ word3 = word1 | word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((uint32*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((uint32*)(prev + width));
+
+ word1 = *((uint32*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((uint32*)(prev + width));
+ word12 >>= 16; /* 0 0 b4 b3 */
+ word22 >>= 16;
+ word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
+ word22 = word22 | (word2 << 16);
+ word3 = word12 & word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((uint32*)(pred_block += offset2)) = word12;
+
+ word12 = *((uint32*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((uint32*)(prev + width));
+ word1 >>= 16; /* 0 0 b8 b7 */
+ word2 >>= 16;
+ word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
+ word2 = word2 | (word22 << 16);
+ word3 = word1 & word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+ prev += offset;
+ }
+
+ return 1;
+ }
+ }
+ else /* tmp == 3 */
+ {
+ prev -= 3; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((uint32*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((uint32*)(prev + width));
+
+ word1 = *((uint32*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((uint32*)(prev + width));
+ word12 >>= 24; /* 0 0 0 b4 */
+ word22 >>= 24;
+ word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
+ word22 = word22 | (word2 << 8);
+ word3 = word12 | word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((uint32*)(pred_block += offset2)) = word12;
+
+ word12 = *((uint32*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((uint32*)(prev + width));
+ word1 >>= 24; /* 0 0 0 b8 */
+ word2 >>= 24;
+ word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
+ word2 = word2 | (word22 << 8);
+ word3 = word1 | word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((uint32*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((uint32*)(prev + width));
+
+ word1 = *((uint32*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((uint32*)(prev + width));
+ word12 >>= 24; /* 0 0 0 b4 */
+ word22 >>= 24;
+ word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
+ word22 = word22 | (word2 << 8);
+ word3 = word12 & word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((uint32*)(pred_block += offset2)) = word12;
+
+ word12 = *((uint32*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((uint32*)(prev + width));
+ word1 >>= 24; /* 0 0 0 b8 */
+ word2 >>= 24;
+ word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
+ word2 = word2 | (word22 << 8);
+ word3 = word1 & word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((uint32*)(pred_block += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ } /* rnd */
+ } /* tmp */
+}
+
+/**********************************************************************************/
+int GetPredAdvancedBy1x1(
+ uint8 *prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+)
+{
+ uint i; /* loop variable */
+ int offset, offset2;
+ uint32 x1, x2, x1m, x2m, y1, y2, y1m, y2m; /* new way */
+ int tmp;
+ int rnd1, rnd2;
+ uint32 mask;
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+ offset = width - B_SIZE; /* offset for prev */
+ offset2 = (pred_width_rnd >> 1) - 8; /* offset for pred_block */
+
+ rnd1 = pred_width_rnd & 1;
+
+ rnd2 = rnd1 + 1;
+ rnd2 |= (rnd2 << 8);
+ rnd2 |= (rnd2 << 16);
+
+ mask = 0x3F;
+ mask |= (mask << 8);
+ mask |= (mask << 16); /* 0x3f3f3f3f */
+
+ tmp = (uintptr_t)prev & 3;
+
+ pred_block -= 4; /* preset */
+
+ if (tmp == 0) /* word-aligned */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((uint32*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((uint32*)(prev + width)); /* load b3 b2 b1 b0, another line */
+ y1 = *((uint32*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((uint32*)(prev + width)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((uint32*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((uint32*)(prev + width)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ y2m = x1m >> 8;
+ y2 = x1 >> 8;
+ y2m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */
+ y2 |= (y1 << 24);
+ x1m += y2m; /* a3+b3+a4+b4, ....., a0+b0+a1+b1 */
+ x1 += y2;
+ x1 += rnd2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((uint32*)(pred_block += 4)) = x1m; /* save x1m */
+
+ y2m = y1m >> 8;
+ y2 = y1 >> 8;
+ y2m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */
+ y2 |= (x2 << 24);
+ y1m += y2m; /* a7+b7+a8+b8, ....., a4+b4+a5+b5 */
+ y1 += y2;
+ y1 += rnd2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((uint32*)(pred_block += 4)) = y1m; /* save y1m */
+
+ pred_block += offset2;
+ prev += offset;
+ }
+
+ return 1;
+ }
+ else if (tmp == 1)
+ {
+ prev--; /* to word-aligned */
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((uint32*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((uint32*)(prev + width)); /* load b3 b2 b1 b0, another line */
+ y1 = *((uint32*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((uint32*)(prev + width)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((uint32*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((uint32*)(prev + width)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ x1m >>= 8 ;
+ x1 >>= 8;
+ x1m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */
+ x1 |= (y1 << 24);
+ y2m = (y1m << 16);
+ y2 = (y1 << 16);
+ y2m |= (x1m >> 8); /* a5+b5, a4+b4, a3+b3, a2+b2 */
+ y2 |= (x1 >> 8);
+ x1 += rnd2;
+ x1m += y2m; /* a4+b4+a5+b5, ....., a1+b1+a2+b2 */
+ x1 += y2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((uint32*)(pred_block += 4)) = x1m; /* save x1m */
+
+ y1m >>= 8;
+ y1 >>= 8;
+ y1m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */
+ y1 |= (x2 << 24);
+ y2m = (x2m << 16);
+ y2 = (x2 << 16);
+ y2m |= (y1m >> 8); /* a9+b9, a8+b8, a7+b7, a6+b6,*/
+ y2 |= (y1 >> 8);
+ y1 += rnd2;
+ y1m += y2m; /* a8+b8+a9+b9, ....., a5+b5+a6+b6 */
+ y1 += y2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((uint32*)(pred_block += 4)) = y1m; /* save y1m */
+
+ pred_block += offset2;
+ prev += offset;
+ }
+ return 1;
+ }
+ else if (tmp == 2)
+ {
+ prev -= 2; /* to word-aligned */
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((uint32*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((uint32*)(prev + width)); /* load b3 b2 b1 b0, another line */
+ y1 = *((uint32*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((uint32*)(prev + width)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((uint32*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((uint32*)(prev + width)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ x1m >>= 16 ;
+ x1 >>= 16;
+ x1m |= (y1m << 16); /* a5+b5, a4+b4, a3+b3, a2+b2 */
+ x1 |= (y1 << 16);
+ y2m = (y1m << 8);
+ y2 = (y1 << 8);
+ y2m |= (x1m >> 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */
+ y2 |= (x1 >> 8);
+ x1 += rnd2;
+ x1m += y2m; /* a5+b5+a6+b6, ....., a2+b2+a3+b3 */
+ x1 += y2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((uint32*)(pred_block += 4)) = x1m; /* save x1m */
+
+ y1m >>= 16;
+ y1 >>= 16;
+ y1m |= (x2m << 16); /* a9+b9, a8+b8, a7+b7, a6+b6 */
+ y1 |= (x2 << 16);
+ y2m = (x2m << 8);
+ y2 = (x2 << 8);
+ y2m |= (y1m >> 8); /* a10+b10, a9+b9, a8+b8, a7+b7,*/
+ y2 |= (y1 >> 8);
+ y1 += rnd2;
+ y1m += y2m; /* a9+b9+a10+b10, ....., a6+b6+a7+b7 */
+ y1 += y2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((uint32*)(pred_block += 4)) = y1m; /* save y1m */
+
+ pred_block += offset2;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* tmp == 3 */
+ {
+ prev -= 3; /* to word-aligned */
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((uint32*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((uint32*)(prev + width)); /* load b3 b2 b1 b0, another line */
+ y1 = *((uint32*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((uint32*)(prev + width)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((uint32*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((uint32*)(prev + width)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ x1m >>= 24 ;
+ x1 >>= 24;
+ x1m |= (y1m << 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */
+ x1 |= (y1 << 8);
+
+ x1m += y1m; /* a6+b6+a7+b7, ....., a3+b3+a4+b4 */
+ x1 += y1;
+ x1 += rnd2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((uint32*)(pred_block += 4)) = x1m; /* save x1m */
+
+ y1m >>= 24;
+ y1 >>= 24;
+ y1m |= (x2m << 8); /* a10+b10, a9+b9, a8+b8, a7+b7 */
+ y1 |= (x2 << 8);
+ y1m += x2m; /* a10+b10+a11+b11, ....., a7+b7+a8+b8 */
+ y1 += x2;
+ y1 += rnd2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((uint32*)(pred_block += 4)) = y1m; /* save y1m */
+
+ pred_block += offset2;
+ prev += offset;
+ }
+ return 1;
+ }
+}
+
+
diff --git a/media/codecs/m4v_h263/dec/src/get_pred_outside.cpp b/media/codecs/m4v_h263/dec/src/get_pred_outside.cpp
new file mode 100644
index 0000000..9cd9022
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/get_pred_outside.cpp
@@ -0,0 +1,514 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ xpos = x half-pixel of (x,y) coordinates within a VOP; motion
+ compensated coordinates; native data type
+ ypos = y half-pixel of (x,y) coordinates within a VOP; motion
+ compensated coordinates; native data type
+ comp = pointer to 8-bit compensated prediction values within a VOP;
+ computed by this module (i/o); full-pel resolution; 8-bit data
+ c_prev = pointer to previous 8-bit prediction values within a VOP;
+ values range from (0-255); full-pel resolution; 8-bit data
+ sh_d = pointer to residual values used to compensate the predicted
+ value; values range from (-512 to 511); full-pel resolution;
+ native data type
+ width = width of the VOP in pixels (x axis); full-pel resolution;
+ native data type
+ height = height of the VOP in pixels (y axis); full-pel resolution;
+ native data type
+ rnd1 = rounding value for case when one dimension uses half-pel
+ resolution; native data type
+ rnd2 = rounding value for case when two dimensions uses half-pel
+ resolution; native data type
+
+ Outputs:
+ returns 1
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Pointers and Buffers Modified:
+ comp = buffer contains newly computed compensated prediction values
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Summary:
+
+ This function performs motion compensated prediction for the case where
+ the motion vector points to a block outside the VOP. The function interpolates
+ the pixels that are outside the VOP using the boundary pixels for the block.
+ Once the values are interpolated, the pixel values are computed for a block
+ in the current VOP. The prediction values are generated by averaging pixel
+ values in the previous VOP; the block position in the previous frame is
+ computed from the current block's motion vector. The computed pixel values
+ are calculated by adding the prediction values to the block residual values.
+
+ Details:
+
+ First, this functions determines which VOP boundary(ies) the motion vector
+ is outside, i.e., left, right, top, bottom. xpos is compared to the left and
+ right boundaries; ypos is compared to the top and bottom boundaries. The number
+ of block pixels inside the the boundary in the x and y directions are stored
+ in endx and endy, respectively. If the entire block is inside the x or y
+ boundary, the respectively end is set to 0.
+
+ After the boundaries are tested, any pixels lying outside a boundary are
+ interpolated from the boundary pixels. For example, if the block is outside the
+ bottom boundary, boundary pixels alone the bottom of the VOP as used to
+ interpolated those pixels lying outside the bottom boundary. The interpolation
+ used is a simple column-wise or row-wise copy of the boundary pixels (inside the
+ block) depending on which boundary the block is outside. In our example, each
+ boundary pixel would be copied column-wise to the pixel beneath it. If the
+ block was outside right boundary, the boundary pixels would be copied row-wise
+ to the pixel to the right of it. If the block was outside both an x and y
+ boundary, the boundary pixels would be copied row-wise for the portion of the
+ block outside the x boundary, and column-wise for the portion of the block
+ outside the y boundary. And so on.
+
+ Once the pixel interpolation is complete, the motion compensated output values
+ (comp[]) are calculed from the motion compensated prediction (pred[])values and
+ the residual values (sh_d[]) of the current frame. The prediction values are
+ generated by averaging pixel values in the previous VOP; the block position in
+ the previous frame is computed from the current block's motion vector. The
+ computed pixel values are calculated by adding the prediction values to the
+ block residual values.
+
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+#include "motion_comp.h"
+
+#define PAD_CORNER { temp = *prev; \
+ temp |= (temp<<8); \
+ temp |= (temp<<16); \
+ *((uint32*)ptr) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; }
+
+#define PAD_ROW { temp = *((uint32*)prev); \
+ temp2 = *((uint32*)(prev+4)); \
+ *((uint32*)ptr) = temp;\
+ *((uint32*)(ptr+4)) = temp2; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp2;\
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp2;\
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp2;\
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp2;\
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp2;\
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp2;\
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp2;}
+
+#define PAD_EXTRA_4x8 { temp = *((uint32*)(prev+8)); \
+ *((uint32*)ptr) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+=16)) = temp; }
+
+#define PAD_COL { temp = *prev; \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)ptr) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ temp = *(prev+=16); \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ temp = *(prev+=16); \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ temp = *(prev+=16); \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ temp = *(prev+=16); \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ temp = *(prev+=16); \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ temp = *(prev+=16); \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp; \
+ temp = *(prev+=16); \
+ temp|=(temp<<8); temp|=(temp<<16); \
+ *((uint32*)(ptr+=16)) = temp; \
+ *((uint32*)(ptr+4)) = temp;}
+
+/* copy 8x8 block */
+#define COPY_BLOCK { *((uint32*)ptr) = *((uint32*)prev); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); }
+
+#define COPY_12x8 { *((uint32*)ptr) = *((uint32*)prev); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); \
+ *((uint32*)(ptr+=16)) = *((uint32*)(prev+=width)); \
+ *((uint32*)(ptr+4)) = *((uint32*)(prev+4)); \
+ *((uint32*)(ptr+8)) = *((uint32*)(prev+8)); }
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+int GetPredOutside(
+ int xpos, /* i */
+ int ypos, /* i */
+ uint8 *c_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int height, /* i */
+ int rnd1, /* i */
+ int pred_width
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ uint8 *prev; /* pointers to adjacent pixels in the */
+ uint8 pred[256]; /* storage for padded pixel values, 16x16 */
+ uint8 *ptr;
+ int xoffset;
+ uint32 temp, temp2;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* saturate xpos and ypos */
+ if (xpos < -16) xpos = -16;
+ if (xpos > ((width - 1) << 1)) xpos = (width - 1) << 1;
+ if (ypos < -16) ypos = -16;
+ if (ypos > ((height - 1) << 1)) ypos = (height - 1) << 1;
+
+ if (xpos < 0)
+ {
+ if (ypos < 0) /* pad top left of frame */
+ {
+ /* copy the block */
+ ptr = pred + (8 << 4) + 8;
+ prev = c_prev;
+ COPY_BLOCK
+
+ /* pad the corner */
+ ptr = pred;
+ prev = pred + (8 << 4) + 8;
+ PAD_CORNER
+
+ /* pad top */
+ ptr = pred + 8;
+ prev = pred + (8 << 4) + 8;
+ PAD_ROW
+
+ /* pad left */
+ ptr = pred + (8 << 4);
+ prev = pred + (8 << 4) + 8;
+ PAD_COL
+
+
+ ptr = pred + (((ypos >> 1) + 8) << 4) + (xpos >> 1) + 8;
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+ }
+ else if ((ypos >> 1) < (height - B_SIZE)) /* pad left of frame */
+ {
+ /* copy block */
+ ptr = pred + 8;
+ prev = c_prev + (ypos >> 1) * width;
+ COPY_BLOCK
+ /* copy extra line */
+ *((uint32*)(ptr += 16)) = *((uint32*)(prev += width));
+ *((uint32*)(ptr + 4)) = *((uint32*)(prev + 4));
+
+ /* pad left */
+ ptr = pred;
+ prev = pred + 8;
+ PAD_COL
+ /* pad extra line */
+ temp = *(prev += 16);
+ temp |= (temp << 8);
+ temp |= (temp << 16);
+ *((uint32*)(ptr += 16)) = temp;
+ *((uint32*)(ptr + 4)) = temp;
+
+ ptr = pred + 8 + (xpos >> 1);
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+ }
+ else /* pad bottom left of frame */
+ {
+ /* copy the block */
+ ptr = pred + 8; /* point to the center */
+ prev = c_prev + width * (height - 8);
+ COPY_BLOCK
+
+ /* pad the corner */
+ ptr = pred + (8 << 4);
+ prev = ptr - 8;
+ PAD_CORNER
+
+ /* pad bottom */
+ ptr = pred + (8 << 4) + 8;
+ prev = ptr - 16;
+ PAD_ROW
+
+ /* pad left */
+ ptr = pred ;
+ prev = ptr + 8;
+ PAD_COL
+
+ ptr = pred + 8 + (((ypos >> 1) - (height - 8)) << 4) + (xpos >> 1);
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+ }
+ }
+ else if ((xpos >> 1) < (width - B_SIZE))
+ {
+ if (ypos < 0) /* pad top of frame */
+ {
+ xoffset = xpos >> 1;
+ xoffset = xoffset & 0x3; /* word align ptr */
+
+ /* copy block */
+ ptr = pred + (8 << 4);
+ prev = c_prev + (xpos >> 1) - xoffset;
+
+ if (xoffset || (xpos&1)) /* copy extra 4x8 */
+ {
+ COPY_12x8
+ }
+ else
+ {
+ COPY_BLOCK
+ }
+
+ /* pad top */
+ ptr = pred;
+ prev = pred + (8 << 4);
+ PAD_ROW
+ if (xoffset || (xpos&1)) /* pad extra 4x8 */
+ {
+ ptr = pred + 8;
+ PAD_EXTRA_4x8
+ }
+
+ ptr = pred + (((ypos >> 1) + 8) << 4) + xoffset;
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+ }
+ else /* pad bottom of frame */
+ {
+ xoffset = xpos >> 1;
+ xoffset = xoffset & 0x3; /* word align ptr */
+ /* copy block */
+ ptr = pred ;
+ prev = c_prev + width * (height - 8) + (xpos >> 1) - xoffset;
+ if (xoffset || (xpos&1))
+ {
+ COPY_12x8
+ }
+ else
+ {
+ COPY_BLOCK
+ }
+
+ /* pad bottom */
+ ptr = pred + (8 << 4);
+ prev = ptr - 16;
+ PAD_ROW
+ if (xoffset || (xpos&1))
+ {
+ ptr = pred + (8 << 4) + 8;
+ PAD_EXTRA_4x8
+ }
+
+ ptr = pred + (((ypos >> 1) - (height - 8)) << 4) + xoffset;
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+ }
+ }
+ else
+ {
+ if (ypos < 0) /* pad top right of frame */
+ {
+ /* copy block */
+ ptr = pred + (8 << 4);
+ prev = c_prev + width - 8;
+ COPY_BLOCK
+
+ /* pad top-right */
+ ptr = pred + 8;
+ prev = pred + (8 << 4) + 7;
+ PAD_CORNER
+
+ /* pad top */
+ ptr = pred ;
+ prev = pred + (8 << 4);
+ PAD_ROW;
+
+ /* pad right */
+ ptr = pred + (8 << 4) + 8;
+ prev = ptr - 1;
+ PAD_COL;
+
+ ptr = pred + ((8 + (ypos >> 1)) << 4) + (8 - (width - (xpos >> 1)));
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+ }
+ else if ((ypos >> 1) < (height - B_SIZE)) /* pad right of frame */
+ {
+ /* copy block */
+ ptr = pred;
+ prev = c_prev + (ypos >> 1) * width + width - 8;
+ COPY_BLOCK
+ /* copy extra line */
+ *((uint32*)(ptr += 16)) = *((uint32*)(prev += width));
+ *((uint32*)(ptr + 4)) = *((uint32*)(prev + 4));
+
+ /* pad right */
+ ptr = pred + 8;
+ prev = ptr - 1;
+ PAD_COL;
+ /* pad extra line */
+ temp = *(prev += 16);
+ temp |= (temp << 8);
+ temp |= (temp << 16);
+ *((uint32*)(ptr += 16)) = temp;
+ *((uint32*)(ptr + 4)) = temp;
+
+
+ ptr = pred + 8 - (width - (xpos >> 1));
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+
+ }
+ else /* pad bottom right of frame */
+ {
+ /* copy block */
+ ptr = pred;
+ prev = c_prev + width * (height - 8) + width - 8;
+ COPY_BLOCK
+
+ /* pad bottom-right */
+ ptr = pred + (8 << 4) + 8;
+ prev = ptr - 17;
+ PAD_CORNER
+
+ /* pad right */
+ ptr = pred + 8;
+ prev = ptr - 1;
+ PAD_COL
+
+ /* pad bottom */
+ ptr = pred + (8 << 4);
+ prev = ptr - 16;
+ PAD_ROW
+
+ ptr = pred + 8 - (width - (xpos >> 1)) + ((8 - (height - (ypos >> 1))) << 4);
+
+ GetPredAdvBTable[ypos&1][xpos&1](ptr, pred_block, 16, (pred_width << 1) | rnd1);
+
+ return 1;
+ }
+ }
+}
diff --git a/media/codecs/m4v_h263/dec/src/idct.cpp b/media/codecs/m4v_h263/dec/src/idct.cpp
new file mode 100644
index 0000000..2e932a4
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/idct.cpp
@@ -0,0 +1,579 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ MODULE DESCRIPTION
+
+ This file contains the functions that transform an 8r8 image block from
+ dequantized DCT coefficients to spatial domain pirel values by calculating
+ inverse discrete cosine transform (IDCT).
+
+------------------------------------------------------------------------------
+*/
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+#include "idct.h"
+#include "motion_comp.h"
+#ifndef FAST_IDCT
+
+/*
+------------------------------------------------------------------------------
+ FUNCTION NAME: idct
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS FOR idct
+
+ Inputs:
+ blk = pointer to the buffer containing the dequantized DCT
+ coefficients of type int for an 8r8 image block;
+ values range from (-2048, 2047) which defined as standard.
+
+ Local Stores/Buffers/Pointers Needed:
+ None
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ blk points to the found IDCT values for an 8r8 image block.
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION FOR idct
+
+ This function transforms an 8r8 image block from dequantized DCT coefficients
+ (F(u,v)) to spatial domain pirel values (f(r,y)) by performing the two
+ dimensional inverse discrete cosine transform (IDCT).
+
+ _7_ _7_ C(u) C(v)
+ f(r,y) = \ \ F(u,v)---- ----cos[(2r+1)*u*pi/16]cos[(2y+1)*v*pi/16]
+ /__ /__ 2 2
+ u=0 v=0
+
+ where C(i) = 1/sqrt(2) if i=0
+ C(i) = 1 otherwise
+
+ 2-D IDCT can be separated as horizontal(row-wise) and vertical(column-wise)
+ 1-D IDCTs. Therefore, 2-D IDCT values are found by the following two steps:
+ 1. Find horizontal 1-D IDCT values for each row from 8r8 dequantized DCT
+ coefficients by row IDCT operation.
+
+ _7_ C(u)
+ g(r,v) = \ F(u,v) ---- cos[(2r+1)*u*pi/16]
+ /__ 2
+ u=0
+
+ 2. Find vertical 1-D IDCT values for each column from the results of 1
+ by column IDCT operation.
+
+ _7_ C(v)
+ f(r,y) = \ g(r,v) ---- cos[(2y+1)*v*pi/16]
+ /__ 2
+ v=0
+
+------------------------------------------------------------------------------
+ REQUIREMENTS FOR idct
+
+ None
+
+------------------------------------------------------------------------------
+*/
+/* REFERENCES FOR idct */
+/* idct.c, inverse fast discrete cosine transform
+ inverse two dimensional DCT, Chen-Wang algorithm
+ (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984)
+ 32-bit integer arithmetic (8 bit coefficients)
+ 11 mults, 29 adds per DCT
+ sE, 18.8.91
+
+ coefficients ertended to 12 bit for IEEE1180-1990
+ compliance sE, 2.1.94
+*/
+
+
+/*----------------------------------------------------------------------------
+; Function Code FOR idct
+----------------------------------------------------------------------------*/
+void idct_intra(
+ int *blk, uint8 *comp, int width
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int i;
+ int32 tmpBLK[64];
+ int32 *tmpBLK32 = &tmpBLK[0];
+ int32 r0, r1, r2, r3, r4, r5, r6, r7, r8; /* butterfly nodes */
+ int32 a;
+ int offset = width - 8;
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* two dimensional inverse discrete cosine transform */
+
+
+ /* column (vertical) IDCT */
+ for (i = B_SIZE - 1; i >= 0; i--)
+ {
+ /* initialize butterfly nodes at first stage */
+
+ r1 = blk[B_SIZE * 4 + i] << 11;
+ /* since row IDCT results have net left shift by 3 */
+ /* this left shift by 8 gives net left shift by 11 */
+ /* in order to maintain the same scale as that of */
+ /* coefficients Wi */
+
+ r2 = blk[B_SIZE * 6 + i];
+ r3 = blk[B_SIZE * 2 + i];
+ r4 = blk[B_SIZE * 1 + i];
+ r5 = blk[B_SIZE * 7 + i];
+ r6 = blk[B_SIZE * 5 + i];
+ r7 = blk[B_SIZE * 3 + i];
+
+ if (!(r1 | r2 | r3 | r4 | r5 | r6 | r7))
+ {
+ /* shortcut */
+ /* execute if values of g(r,1) to g(r,7) in a column*/
+ /* are all zeros */
+
+ /* make output of IDCT >>3 or scaled by 1/8 and */
+ /* with the proper rounding */
+ a = (blk[B_SIZE * 0 + i]) << 3;
+ tmpBLK32[B_SIZE * 0 + i] = a;
+ tmpBLK32[B_SIZE * 1 + i] = a;
+ tmpBLK32[B_SIZE * 2 + i] = a;
+ tmpBLK32[B_SIZE * 3 + i] = a;
+ tmpBLK32[B_SIZE * 4 + i] = a;
+ tmpBLK32[B_SIZE * 5 + i] = a;
+ tmpBLK32[B_SIZE * 6 + i] = a;
+ tmpBLK32[B_SIZE * 7 + i] = a;
+ }
+ else
+ {
+ r0 = (blk[8 * 0 + i] << 11) + 128;
+
+ /* first stage */
+
+ r8 = W7 * (r4 + r5);
+ r4 = (r8 + (W1 - W7) * r4);
+ /* Multiplication with Wi increases the net left */
+ /* shift from 11 to 14,we have to shift back by 3*/
+ r5 = (r8 - (W1 + W7) * r5);
+ r8 = W3 * (r6 + r7);
+ r6 = (r8 - (W3 - W5) * r6);
+ r7 = (r8 - (W3 + W5) * r7);
+
+ /* second stage */
+ r8 = r0 + r1;
+ r0 -= r1;
+
+ r1 = W6 * (r3 + r2);
+ r2 = (r1 - (W2 + W6) * r2);
+ r3 = (r1 + (W2 - W6) * r3);
+
+ r1 = r4 + r6;
+ r4 -= r6;
+ r6 = r5 + r7;
+ r5 -= r7;
+
+ /* third stage */
+ r7 = r8 + r3;
+ r8 -= r3;
+ r3 = r0 + r2;
+ r0 -= r2;
+ r2 = (181 * (r4 + r5) + 128) >> 8; /* rounding */
+ r4 = (181 * (r4 - r5) + 128) >> 8;
+
+ /* fourth stage */
+ /* net shift of IDCT is >>3 after the following */
+ /* shift operation, it makes output of 2-D IDCT */
+ /* scaled by 1/8, that is scaled twice by */
+ /* 1/(2*sqrt(2)) for row IDCT and column IDCT. */
+ /* see detail analysis in design doc. */
+ tmpBLK32[0 + i] = (r7 + r1) >> 8;
+ tmpBLK32[(1<<3) + i] = (r3 + r2) >> 8;
+ tmpBLK32[(2<<3) + i] = (r0 + r4) >> 8;
+ tmpBLK32[(3<<3) + i] = (r8 + r6) >> 8;
+ tmpBLK32[(4<<3) + i] = (r8 - r6) >> 8;
+ tmpBLK32[(5<<3) + i] = (r0 - r4) >> 8;
+ tmpBLK32[(6<<3) + i] = (r3 - r2) >> 8;
+ tmpBLK32[(7<<3) + i] = (r7 - r1) >> 8;
+ }
+ }
+ /* row (horizontal) IDCT */
+ for (i = 0 ; i < B_SIZE; i++)
+ {
+ /* initialize butterfly nodes at the first stage */
+
+ r1 = ((int32)tmpBLK32[4+(i<<3)]) << 8;
+ /* r1 left shift by 11 is to maintain the same */
+ /* scale as that of coefficients (W1,...W7) */
+ /* since blk[4] won't multiply with Wi. */
+ /* see detail diagram in design document. */
+
+ r2 = tmpBLK32[6+(i<<3)];
+ r3 = tmpBLK32[2+(i<<3)];
+ r4 = tmpBLK32[1+(i<<3)];
+ r5 = tmpBLK32[7+(i<<3)];
+ r6 = tmpBLK32[5+(i<<3)];
+ r7 = tmpBLK32[3+(i<<3)];
+
+ if (!(r1 | r2 | r3 | r4 | r5 | r6 | r7))
+ {
+ /* shortcut */
+ /* execute if values of F(1,v) to F(7,v) in a row*/
+ /* are all zeros */
+
+ /* output of row IDCT scaled by 8 */
+ a = (((int32)tmpBLK32[0+(i<<3)] + 32) >> 6);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ *comp++ = a;
+ *comp++ = a;
+ *comp++ = a;
+ *comp++ = a;
+ *comp++ = a;
+ *comp++ = a;
+ *comp++ = a;
+
+ comp += offset;
+ }
+
+ else
+ {
+ /* for proper rounding in the fourth stage */
+ r0 = (((int32)tmpBLK32[0+(i<<3)]) << 8) + 8192;
+
+ /* first stage */
+
+ r8 = W7 * (r4 + r5) + 4;
+ r4 = (r8 + (W1 - W7) * r4) >> 3;
+ r5 = (r8 - (W1 + W7) * r5) >> 3;
+
+ r8 = W3 * (r6 + r7) + 4;
+ r6 = (r8 - (W3 - W5) * r6) >> 3;
+ r7 = (r8 - (W3 + W5) * r7) >> 3;
+
+ /* second stage */
+ r8 = r0 + r1;
+ r0 -= r1;
+
+ r1 = W6 * (r3 + r2) + 4;
+ r2 = (r1 - (W2 + W6) * r2) >> 3;
+ r3 = (r1 + (W2 - W6) * r3) >> 3;
+
+ r1 = r4 + r6;
+ r4 -= r6;
+ r6 = r5 + r7;
+ r5 -= r7;
+
+ /* third stage */
+ r7 = r8 + r3;
+ r8 -= r3;
+ r3 = r0 + r2;
+ r0 -= r2;
+ r2 = (181 * (r4 + r5) + 128) >> 8; /* rounding */
+ r4 = (181 * (r4 - r5) + 128) >> 8;
+
+ /* fourth stage */
+ /* net shift of this function is <<3 after the */
+ /* following shift operation, it makes output of */
+ /* row IDCT scaled by 8 to retain 3 bits precision*/
+ a = ((r7 + r1) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ a = ((r3 + r2) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ a = ((r0 + r4) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ a = ((r8 + r6) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ a = ((r8 - r6) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ a = ((r0 - r4) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ a = ((r3 - r2) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+ a = ((r7 - r1) >> 14);
+ CLIP_RESULT(a)
+ *comp++ = a;
+
+ comp += offset;
+ }
+ }
+
+
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+
+void idct(
+ int *blk, uint8 *pred, uint8 *dst, int width)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int i;
+ int32 tmpBLK[64];
+ int32 *tmpBLK32 = &tmpBLK[0];
+ int32 r0, r1, r2, r3, r4, r5, r6, r7, r8; /* butterfly nodes */
+ int32 a;
+ int res;
+
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* two dimensional inverse discrete cosine transform */
+
+
+ /* column (vertical) IDCT */
+ for (i = B_SIZE - 1; i >= 0; i--)
+ {
+ /* initialize butterfly nodes at first stage */
+
+ r1 = blk[B_SIZE * 4 + i] << 11;
+ /* since row IDCT results have net left shift by 3 */
+ /* this left shift by 8 gives net left shift by 11 */
+ /* in order to maintain the same scale as that of */
+ /* coefficients Wi */
+
+ r2 = blk[B_SIZE * 6 + i];
+ r3 = blk[B_SIZE * 2 + i];
+ r4 = blk[B_SIZE * 1 + i];
+ r5 = blk[B_SIZE * 7 + i];
+ r6 = blk[B_SIZE * 5 + i];
+ r7 = blk[B_SIZE * 3 + i];
+
+ if (!(r1 | r2 | r3 | r4 | r5 | r6 | r7))
+ {
+ /* shortcut */
+ /* execute if values of g(r,1) to g(r,7) in a column*/
+ /* are all zeros */
+
+ /* make output of IDCT >>3 or scaled by 1/8 and */
+ /* with the proper rounding */
+ a = (blk[B_SIZE * 0 + i]) << 3;
+ tmpBLK32[B_SIZE * 0 + i] = a;
+ tmpBLK32[B_SIZE * 1 + i] = a;
+ tmpBLK32[B_SIZE * 2 + i] = a;
+ tmpBLK32[B_SIZE * 3 + i] = a;
+ tmpBLK32[B_SIZE * 4 + i] = a;
+ tmpBLK32[B_SIZE * 5 + i] = a;
+ tmpBLK32[B_SIZE * 6 + i] = a;
+ tmpBLK32[B_SIZE * 7 + i] = a;
+ }
+ else
+ {
+ r0 = (blk[8 * 0 + i] << 11) + 128;
+
+ /* first stage */
+
+ r8 = W7 * (r4 + r5);
+ r4 = (r8 + (W1 - W7) * r4);
+ /* Multiplication with Wi increases the net left */
+ /* shift from 11 to 14,we have to shift back by 3*/
+ r5 = (r8 - (W1 + W7) * r5);
+ r8 = W3 * (r6 + r7);
+ r6 = (r8 - (W3 - W5) * r6);
+ r7 = (r8 - (W3 + W5) * r7);
+
+ /* second stage */
+ r8 = r0 + r1;
+ r0 -= r1;
+
+ r1 = W6 * (r3 + r2);
+ r2 = (r1 - (W2 + W6) * r2);
+ r3 = (r1 + (W2 - W6) * r3);
+
+ r1 = r4 + r6;
+ r4 -= r6;
+ r6 = r5 + r7;
+ r5 -= r7;
+
+ /* third stage */
+ r7 = r8 + r3;
+ r8 -= r3;
+ r3 = r0 + r2;
+ r0 -= r2;
+ r2 = (181 * (r4 + r5) + 128) >> 8; /* rounding */
+ r4 = (181 * (r4 - r5) + 128) >> 8;
+
+ /* fourth stage */
+ /* net shift of IDCT is >>3 after the following */
+ /* shift operation, it makes output of 2-D IDCT */
+ /* scaled by 1/8, that is scaled twice by */
+ /* 1/(2*sqrt(2)) for row IDCT and column IDCT. */
+ /* see detail analysis in design doc. */
+ tmpBLK32[0 + i] = (r7 + r1) >> 8;
+ tmpBLK32[(1<<3) + i] = (r3 + r2) >> 8;
+ tmpBLK32[(2<<3) + i] = (r0 + r4) >> 8;
+ tmpBLK32[(3<<3) + i] = (r8 + r6) >> 8;
+ tmpBLK32[(4<<3) + i] = (r8 - r6) >> 8;
+ tmpBLK32[(5<<3) + i] = (r0 - r4) >> 8;
+ tmpBLK32[(6<<3) + i] = (r3 - r2) >> 8;
+ tmpBLK32[(7<<3) + i] = (r7 - r1) >> 8;
+ }
+ }
+ /* row (horizontal) IDCT */
+ for (i = B_SIZE - 1; i >= 0; i--)
+ {
+ /* initialize butterfly nodes at the first stage */
+
+ r1 = ((int32)tmpBLK32[4+(i<<3)]) << 8;
+ /* r1 left shift by 11 is to maintain the same */
+ /* scale as that of coefficients (W1,...W7) */
+ /* since blk[4] won't multiply with Wi. */
+ /* see detail diagram in design document. */
+
+ r2 = tmpBLK32[6+(i<<3)];
+ r3 = tmpBLK32[2+(i<<3)];
+ r4 = tmpBLK32[1+(i<<3)];
+ r5 = tmpBLK32[7+(i<<3)];
+ r6 = tmpBLK32[5+(i<<3)];
+ r7 = tmpBLK32[3+(i<<3)];
+
+ if (!(r1 | r2 | r3 | r4 | r5 | r6 | r7))
+ {
+ /* shortcut */
+ /* execute if values of F(1,v) to F(7,v) in a row*/
+ /* are all zeros */
+
+ /* output of row IDCT scaled by 8 */
+ a = (tmpBLK32[0+(i<<3)] + 32) >> 6;
+ blk[0+(i<<3)] = a;
+ blk[1+(i<<3)] = a;
+ blk[2+(i<<3)] = a;
+ blk[3+(i<<3)] = a;
+ blk[4+(i<<3)] = a;
+ blk[5+(i<<3)] = a;
+ blk[6+(i<<3)] = a;
+ blk[7+(i<<3)] = a;
+
+ }
+
+ else
+ {
+ /* for proper rounding in the fourth stage */
+ r0 = (((int32)tmpBLK32[0+(i<<3)]) << 8) + 8192;
+
+ /* first stage */
+
+ r8 = W7 * (r4 + r5) + 4;
+ r4 = (r8 + (W1 - W7) * r4) >> 3;
+ r5 = (r8 - (W1 + W7) * r5) >> 3;
+
+ r8 = W3 * (r6 + r7) + 4;
+ r6 = (r8 - (W3 - W5) * r6) >> 3;
+ r7 = (r8 - (W3 + W5) * r7) >> 3;
+
+ /* second stage */
+ r8 = r0 + r1;
+ r0 -= r1;
+
+ r1 = W6 * (r3 + r2) + 4;
+ r2 = (r1 - (W2 + W6) * r2) >> 3;
+ r3 = (r1 + (W2 - W6) * r3) >> 3;
+
+ r1 = r4 + r6;
+ r4 -= r6;
+ r6 = r5 + r7;
+ r5 -= r7;
+
+ /* third stage */
+ r7 = r8 + r3;
+ r8 -= r3;
+ r3 = r0 + r2;
+ r0 -= r2;
+ r2 = (181 * (r4 + r5) + 128) >> 8; /* rounding */
+ r4 = (181 * (r4 - r5) + 128) >> 8;
+
+ /* fourth stage */
+ /* net shift of this function is <<3 after the */
+ /* following shift operation, it makes output of */
+ /* row IDCT scaled by 8 to retain 3 bits precision*/
+ blk[0+(i<<3)] = (r7 + r1) >> 14;
+ blk[1+(i<<3)] = (r3 + r2) >> 14;
+ blk[2+(i<<3)] = (r0 + r4) >> 14;
+ blk[3+(i<<3)] = (r8 + r6) >> 14;
+ blk[4+(i<<3)] = (r8 - r6) >> 14;
+ blk[5+(i<<3)] = (r0 - r4) >> 14;
+ blk[6+(i<<3)] = (r3 - r2) >> 14;
+ blk[7+(i<<3)] = (r7 - r1) >> 14;
+ }
+ /* add with prediction , 08/03/05 */
+ res = (*pred++ + block[0+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+ res = (*pred++ + block[1+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+ res = (*pred++ + block[2+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+ res = (*pred++ + block[3+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+ res = (*pred++ + block[4+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+ res = (*pred++ + block[5+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+ res = (*pred++ + block[6+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+ res = (*pred++ + block[7+(i<<3)]);
+ CLIP_RESULT(res);
+ *dst++ = res;
+
+ pred += 8;
+ dst += (width - 8);
+ }
+
+
+
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+
+#endif
+/*----------------------------------------------------------------------------
+; End Function: idct
+----------------------------------------------------------------------------*/
+
diff --git a/media/codecs/m4v_h263/dec/src/idct.h b/media/codecs/m4v_h263/dec/src/idct.h
new file mode 100644
index 0000000..484631b
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/idct.h
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef idct_h
+#define idct_h
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define INTEGER_IDCT
+
+#ifdef FAST_IDCT
+#ifndef INTEGER_IDCT
+#define INTEGER_IDCT
+#endif
+#endif
+
+#ifdef FAST_IDCT
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ void idctrow0(int16 *blk, uint8 *pred, uint8 *dst, int width);
+ void idctrow1(int16 *blk, uint8 *pred, uint8 *dst, int width);
+ void idctrow2(int16 *blk, uint8 *pred, uint8 *dst, int width);
+ void idctrow3(int16 *blk, uint8 *pred, uint8 *dst, int width);
+ void idctrow4(int16 *blk, uint8 *pred, uint8 *dst, int width);
+ void idctcol0(int16 *blk);
+ void idctcol1(int16 *blk);
+ void idctcol2(int16 *blk);
+ void idctcol3(int16 *blk);
+ void idctcol4(int16 *blk);
+
+ void idctrow0_intra(int16 *blk, PIXEL *comp, int width);
+ void idctrow1_intra(int16 *blk, PIXEL *comp, int width);
+ void idctrow2_intra(int16 *blk, PIXEL *comp, int width);
+ void idctrow3_intra(int16 *blk, PIXEL *comp, int width);
+ void idctrow4_intra(int16 *blk, PIXEL *comp, int width);
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+/* this code assumes ">>" to be a two's-complement arithmetic */
+/* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */
+
+/* a positive real constant is converted to an integer scaled by 2048 */
+/* or equivalent to left shift by 11 */
+
+#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */
+#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */
+#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */
+#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */
+#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */
+#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */
+#define W1mW7 2276
+#define W1pW7 3406
+#define W5mW3 (-799)
+#define mW3mW5 (-4017)
+#define mW2mW6 (-3784)
+#define W2mW6 1568
+
+/* left shift by 11 is to maintain the accuracy of the decimal point */
+/* for the transform coefficients (W1,...W7) */
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/m4v_h263/dec/src/idct_vca.cpp b/media/codecs/m4v_h263/dec/src/idct_vca.cpp
new file mode 100644
index 0000000..dbaf5d1
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/idct_vca.cpp
@@ -0,0 +1,670 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "idct.h"
+#include "motion_comp.h"
+
+#ifdef FAST_IDCT
+
+/****************************************************************
+* vca_idct.c : created 6/1/99 for several options
+* of hard-coded reduced idct function (using nz_coefs)
+******************************************************************/
+
+/*****************************************************/
+//pretested version
+void idctrow0(int16 *, uint8 *, uint8 *, int)
+{
+ return ;
+}
+void idctcol0(int16 *)
+{
+ return ;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow1(int16 *blk, uint8 *pred, uint8 *dst, int width)
+{
+ /* shortcut */
+ int tmp;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ width -= 4;
+ dst -= width;
+ pred -= 12;
+ blk -= 8;
+
+ while (i--)
+ {
+ tmp = (*(blk += 8) + 32) >> 6;
+ *blk = 0;
+
+ pred_word = *((uint32*)(pred += 12)); /* read 4 bytes from pred */
+ res = tmp + (pred_word & 0xFF);
+ CLIP_RESULT(res);
+ res2 = tmp + ((pred_word >> 8) & 0xFF);
+ CLIP_RESULT(res2);
+ dst_word = (res2 << 8) | res;
+ res = tmp + ((pred_word >> 16) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 16);
+ res = tmp + ((pred_word >> 24) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += width)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred += 4)); /* read 4 bytes from pred */
+ res = tmp + (pred_word & 0xFF);
+ CLIP_RESULT(res);
+ res2 = tmp + ((pred_word >> 8) & 0xFF);
+ CLIP_RESULT(res2);
+ dst_word = (res2 << 8) | res;
+ res = tmp + ((pred_word >> 16) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 16);
+ res = tmp + ((pred_word >> 24) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return;
+}
+
+void idctcol1(int16 *blk)
+{ /* shortcut */
+ blk[0] = blk[8] = blk[16] = blk[24] = blk[32] = blk[40] = blk[48] = blk[56] =
+ blk[0] << 3;
+ return;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow2(int16 *blk, uint8 *pred, uint8 *dst, int width)
+{
+ int32 x0, x1, x2, x4, x5;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ width -= 4;
+ dst -= width;
+ pred -= 12;
+ blk -= 8;
+
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(pred += 12)); /* read 4 bytes from pred */
+ res = (x0 + x4) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 + x5) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += width)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred += 4)); /* read 4 bytes from pred */
+ res = (x0 - x5) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 - x1) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x4) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctcol2(int16 *blk)
+{
+ int32 x0, x1, x3, x5, x7;//, x8;
+
+ x1 = blk[8];
+ x0 = ((int32)blk[0] << 11) + 128;
+ /* both upper and lower*/
+
+ x7 = W7 * x1;
+ x1 = W1 * x1;
+
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ blk[0] = (x0 + x1) >> 8;
+ blk[8] = (x0 + x7) >> 8;
+ blk[16] = (x0 + x5) >> 8;
+ blk[24] = (x0 + x3) >> 8;
+ blk[56] = (x0 - x1) >> 8;
+ blk[48] = (x0 - x7) >> 8;
+ blk[40] = (x0 - x5) >> 8;
+ blk[32] = (x0 - x3) >> 8;
+
+ return ;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow3(int16 *blk, uint8 *pred, uint8 *dst, int width)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ width -= 4;
+ dst -= width;
+ pred -= 12;
+ blk -= 8;
+
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ pred_word = *((uint32*)(pred += 12)); /* read 4 bytes from pred */
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += width)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred += 4)); /* read 4 bytes from pred */
+ res = (x2 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += 4)) = dst_word; /* save 4 bytes to dst */
+ }
+
+ return ;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctcol3(int16 *blk)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+
+ x2 = blk[16];
+ x1 = blk[8];
+ x0 = ((int32)blk[0] << 11) + 128;
+
+ x4 = x0;
+ x6 = W6 * x2;
+ x2 = W2 * x2;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = W7 * x1;
+ x1 = W1 * x1;
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ blk[0] = (x0 + x1) >> 8;
+ blk[8] = (x4 + x7) >> 8;
+ blk[16] = (x6 + x5) >> 8;
+ blk[24] = (x2 + x3) >> 8;
+ blk[56] = (x0 - x1) >> 8;
+ blk[48] = (x4 - x7) >> 8;
+ blk[40] = (x6 - x5) >> 8;
+ blk[32] = (x2 - x3) >> 8;
+
+ return;
+}
+
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow4(int16 *blk, uint8 *pred, uint8 *dst, int width)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ width -= 4;
+ dst -= width;
+ pred -= 12;
+ blk -= 8;
+
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x3 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x5 = (W3 * x3 + 4) >> 3;
+ x3 = (- W5 * x3 + 4) >> 3;
+ x8 = x1 - x5;
+ x1 += x5;
+ x5 = x8;
+ x8 = x7 - x3;
+ x3 += x7;
+ x7 = (181 * (x5 + x8) + 128) >> 8;
+ x5 = (181 * (x5 - x8) + 128) >> 8;
+
+ pred_word = *((uint32*)(pred += 12)); /* read 4 bytes from pred */
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += width)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred += 4)); /* read 4 bytes from pred */
+ res = (x2 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(dst += 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctcol4(int16 *blk)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ x2 = blk[16];
+ x1 = blk[8];
+ x3 = blk[24];
+ x0 = ((int32)blk[0] << 11) + 128;
+
+ x4 = x0;
+ x6 = W6 * x2;
+ x2 = W2 * x2;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = W7 * x1;
+ x1 = W1 * x1;
+ x5 = W3 * x3;
+ x3 = -W5 * x3;
+ x8 = x1 - x5;
+ x1 += x5;
+ x5 = x8;
+ x8 = x7 - x3;
+ x3 += x7;
+ x7 = (181 * (x5 + x8) + 128) >> 8;
+ x5 = (181 * (x5 - x8) + 128) >> 8;
+
+
+ blk[0] = (x0 + x1) >> 8;
+ blk[8] = (x4 + x7) >> 8;
+ blk[16] = (x6 + x5) >> 8;
+ blk[24] = (x2 + x3) >> 8;
+ blk[56] = (x0 - x1) >> 8;
+ blk[48] = (x4 - x7) >> 8;
+ blk[40] = (x6 - x5) >> 8;
+ blk[32] = (x2 - x3) >> 8;
+
+ return ;
+}
+
+void idctrow0_intra(int16 *, PIXEL *, int)
+{
+ return ;
+}
+
+void idctrow1_intra(int16 *blk, PIXEL *comp, int width)
+{
+ /* shortcut */
+ int32 tmp;
+ int i = 8;
+ int offset = width;
+ uint32 word;
+
+ comp -= offset;
+ while (i--)
+ {
+ tmp = ((blk[0] + 32) >> 6);
+ blk[0] = 0;
+ CLIP_RESULT(tmp)
+
+ word = (tmp << 8) | tmp;
+ word = (word << 16) | word;
+
+ *((uint32*)(comp += offset)) = word;
+ *((uint32*)(comp + 4)) = word;
+
+
+
+
+ blk += B_SIZE;
+ }
+ return;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow2_intra(int16 *blk, PIXEL *comp, int width)
+{
+ int32 x0, x1, x2, x4, x5, temp;
+ int i = 8;
+ int offset = width;
+ int32 word;
+
+ comp -= offset;
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[1];
+ blk[1] = 0;
+ x0 = ((int32)blk[0] << 8) + 8192;
+ blk[0] = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ word = ((x0 + x4) >> 14);
+ CLIP_RESULT(word)
+
+ temp = ((x0 + x2) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+ temp = ((x0 + x1) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+ temp = ((x0 + x5) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp += offset)) = word;
+
+ word = ((x0 - x5) >> 14);
+ CLIP_RESULT(word)
+ temp = ((x0 - x1) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+ temp = ((x0 - x2) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+ temp = ((x0 - x4) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp + 4)) = word;
+
+ blk += B_SIZE;
+ }
+ return ;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow3_intra(int16 *blk, PIXEL *comp, int width)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8, temp;
+ int i = 8;
+ int offset = width;
+ int32 word;
+
+ comp -= offset;
+
+ while (i--)
+ {
+ x2 = blk[2];
+ blk[2] = 0;
+ x1 = blk[1];
+ blk[1] = 0;
+ x0 = ((int32)blk[0] << 8) + 8192;
+ blk[0] = 0;/* for proper rounding in the fourth stage */
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ word = ((x0 + x1) >> 14);
+ CLIP_RESULT(word)
+ temp = ((x4 + x7) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+
+
+ temp = ((x6 + x5) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+
+ temp = ((x2 + x3) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp += offset)) = word;
+
+ word = ((x2 - x3) >> 14);
+ CLIP_RESULT(word)
+
+ temp = ((x6 - x5) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+
+ temp = ((x4 - x7) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+
+ temp = ((x0 - x1) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp + 4)) = word;
+
+ blk += B_SIZE;
+ }
+ return ;
+}
+
+__attribute__((no_sanitize("signed-integer-overflow")))
+void idctrow4_intra(int16 *blk, PIXEL *comp, int width)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8, temp;
+ int i = 8;
+ int offset = width;
+ int32 word;
+
+ comp -= offset;
+
+ while (i--)
+ {
+ x2 = blk[2];
+ blk[2] = 0;
+ x1 = blk[1];
+ blk[1] = 0;
+ x3 = blk[3];
+ blk[3] = 0;
+ x0 = ((int32)blk[0] << 8) + 8192;
+ blk[0] = 0;/* for proper rounding in the fourth stage */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x5 = (W3 * x3 + 4) >> 3;
+ x3 = (- W5 * x3 + 4) >> 3;
+ x8 = x1 - x5;
+ x1 += x5;
+ x5 = x8;
+ x8 = x7 - x3;
+ x3 += x7;
+ x7 = (181 * (x5 + x8) + 128) >> 8;
+ x5 = (181 * (x5 - x8) + 128) >> 8;
+
+ word = ((x0 + x1) >> 14);
+ CLIP_RESULT(word)
+
+ temp = ((x4 + x7) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+
+
+ temp = ((x6 + x5) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+
+ temp = ((x2 + x3) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp += offset)) = word;
+
+ word = ((x2 - x3) >> 14);
+ CLIP_RESULT(word)
+
+ temp = ((x6 - x5) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 8);
+
+ temp = ((x4 - x7) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 16);
+
+ temp = ((x0 - x1) >> 14);
+ CLIP_RESULT(temp)
+ word = word | (temp << 24);
+ *((int32*)(comp + 4)) = word;
+
+ blk += B_SIZE;
+ }
+
+ return ;
+}
+
+#endif
+
diff --git a/media/codecs/m4v_h263/dec/src/max_level.h b/media/codecs/m4v_h263/dec/src/max_level.h
new file mode 100644
index 0000000..2d59c73
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/max_level.h
@@ -0,0 +1,149 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+* ------------------------------------------------------------------- *
+* MPEG-4 Simple Profile Video Decoder *
+* ------------------------------------------------------------------- *
+*
+* This software module was originally developed by
+*
+* Michael Wollborn (TUH / ACTS-MoMuSyS)
+*
+* in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
+* This software module is an implementation of a part of one or more MPEG-4
+* Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
+* license to this software module or modifications thereof for use in hardware
+* or software products claiming conformance to the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* Those intending to use this software module in hardware or software products
+* are advised that its use may infringe existing patents. The original
+* developer of this software module and his/her company, the subsequent
+* editors and their companies, and ISO/IEC have no liability for use of this
+* software module or modifications thereof in an implementation. Copyright is
+* not released for non MPEG-4 Video (ISO/IEC 14496-2) Standard conforming
+* products.
+*
+* ACTS-MoMuSys partners retain full right to use the code for his/her own
+* purpose, assign or donate the code to a third party and to inhibit third
+* parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) Standard
+* conforming products. This copyright notice must be included in all copies or
+* derivative works.
+*
+* Copyright (c) 1997
+*
+*****************************************************************************
+
+This is a header file for "vlc_decode.c". The table data actually resides
+in "vlc_tab.c".
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+
+#ifndef max_level_H
+#define max_level_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4def.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ extern const int intra_max_level[2][NCOEFF_BLOCK];
+
+ extern const int inter_max_level[2][NCOEFF_BLOCK];
+
+ extern const int intra_max_run0[28];
+
+
+ extern const int intra_max_run1[9];
+
+ extern const int inter_max_run0[13];
+
+
+ extern const int inter_max_run1[4];
+
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/media/codecs/m4v_h263/dec/src/mb_motion_comp.cpp b/media/codecs/m4v_h263/dec/src/mb_motion_comp.cpp
new file mode 100644
index 0000000..79760f5
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/mb_motion_comp.cpp
@@ -0,0 +1,565 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#define LOG_TAG "m4v_h263"
+#include <log/log.h>
+
+/*
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ video = pointer to structure of type VideoDecData
+
+ Local Stores/Buffers/Pointers Needed:
+ roundtab16 = rounding table
+
+ Global Stores/Buffers/Pointers Needed:
+ None
+
+ Outputs:
+ None
+
+ Pointers and Buffers Modified:
+ video->currVop->yChan contents are the newly calculated luminance
+ data
+ video->currVop->uChan contents are the newly calculated chrominance
+ b data
+ video->currVop->vChan contents are the newly calculated chrominance
+ r data
+ video->pstprcTypCur contents are the updated semaphore propagation
+ values
+
+ Local Stores Modified:
+ None
+
+ Global Stores Modified:
+ None
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ This function performs high level motion compensation on the luminance and
+ chrominance data. It sets up all the parameters required by the functions
+ that perform luminance and chrominance prediction and it initializes the
+ pointer to the post processing semaphores of a given block. It also checks
+ the motion compensation mode in order to determine which luminance or
+ chrominance prediction functions to call and determines how the post
+ processing semaphores are updated.
+
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+#include "motion_comp.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+/* 09/29/2000 bring this from mp4def.h */
+// const static int roundtab4[] = {0,1,1,1};
+// const static int roundtab8[] = {0,0,1,1,1,1,1,2};
+/*** 10/30 for TPS */
+// const static int roundtab12[] = {0,0,0,1,1,1,1,1,1,1,2,2};
+/* 10/30 for TPS ***/
+const static int roundtab16[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+/** modified 3 August 2005 to do prediction and put the results in
+video->mblock->pred_block, no adding with residue */
+
+void MBMotionComp(
+ VideoDecData *video,
+ int CBP
+)
+{
+
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ /* Previous Video Object Plane */
+ Vop *prev = video->prevVop;
+
+ /* Current Macroblock (MB) in the VOP */
+ int mbnum = video->mbnum;
+
+ /* Number of MB per data row */
+ int MB_in_width = video->nMBPerRow;
+ int ypos, xpos;
+ PIXEL *c_comp, *c_prev;
+ PIXEL *cu_comp, *cu_prev;
+ PIXEL *cv_comp, *cv_prev;
+ int height, width, pred_width;
+ int imv, mvwidth;
+ int32 offset;
+ uint8 mode;
+ uint8 *pred_block, *pred;
+
+ /* Motion vector (dx,dy) in half-pel resolution */
+ int dx, dy;
+
+ MOT px[4], py[4];
+ int xpred, ypred;
+ int xsum;
+ int round1;
+ /*----------------------------------------------------------------------------
+ ; Function body here
+ ----------------------------------------------------------------------------*/
+ /* Set rounding type */
+ /* change from array to single 09/29/2000 */
+ round1 = (int)(1 - video->currVop->roundingType);
+
+ /* width of luminance data in pixels (y axis) */
+ width = video->width;
+
+ /* heigth of luminance data in pixels (x axis) */
+ height = video->height;
+
+ /* number of blocks per row */
+ mvwidth = MB_in_width << 1;
+
+ /* starting y position in current MB; origin of MB */
+ ypos = video->mbnum_row << 4 ;
+ /* starting x position in current MB; origin of MB */
+ xpos = video->mbnum_col << 4 ;
+
+ /* offset to (x,y) position in current luminance MB */
+ /* in pixel resolution */
+ /* ypos*width -> row, +x -> column */
+ offset = (int32)ypos * width + xpos;
+
+ /* get mode for current MB */
+ mode = video->headerInfo.Mode[mbnum];
+
+ /* block index */
+ /* imv = (xpos/8) + ((ypos/8) * mvwidth) */
+ imv = (offset >> 6) - (xpos >> 6) + (xpos >> 3);
+ if (mode & INTER_1VMASK)
+ {
+ dx = px[0] = px[1] = px[2] = px[3] = video->motX[imv];
+ dy = py[0] = py[1] = py[2] = py[3] = video->motY[imv];
+ if ((dx & 3) == 0)
+ {
+ dx = dx >> 1;
+ }
+ else
+ {
+ /* x component of MV is or'ed for rounding (?) */
+ dx = (dx >> 1) | 1;
+ }
+
+ /* y component of motion vector; divide by 2 for to */
+ /* convert to full-pel resolution. */
+ if ((dy & 3) == 0)
+ {
+ dy = dy >> 1;
+ }
+ else
+ {
+ /* y component of MV is or'ed for rounding (?) */
+ dy = (dy >> 1) | 1;
+ }
+ }
+ else
+ {
+ px[0] = video->motX[imv];
+ px[1] = video->motX[imv+1];
+ px[2] = video->motX[imv+mvwidth];
+ px[3] = video->motX[imv+mvwidth+1];
+ xsum = px[0] + px[1] + px[2] + px[3];
+ dx = PV_SIGN(xsum) * (roundtab16[(PV_ABS(xsum)) & 0xF] +
+ (((PV_ABS(xsum)) >> 4) << 1));
+ py[0] = video->motY[imv];
+ py[1] = video->motY[imv+1];
+ py[2] = video->motY[imv+mvwidth];
+ py[3] = video->motY[imv+mvwidth+1];
+ xsum = py[0] + py[1] + py[2] + py[3];
+ dy = PV_SIGN(xsum) * (roundtab16[(PV_ABS(xsum)) & 0xF] +
+ (((PV_ABS(xsum)) >> 4) << 1));
+ }
+
+ /* Pointer to previous luminance frame */
+ c_prev = prev->yChan;
+ if (!c_prev) {
+ ALOGE("b/35269635");
+ android_errorWriteLog(0x534e4554, "35269635");
+ return;
+ }
+
+ pred_block = video->mblock->pred_block;
+
+ /* some blocks have no residue or INTER4V */
+ /*if (mode == MODE_INTER4V) 05/08/15 */
+ /* Motion Compensation for an 8x8 block within a MB */
+ /* (4 MV per MB) */
+
+
+
+ /* Call function that performs luminance prediction */
+ /* luminance_pred_mode_inter4v(xpos, ypos, px, py, c_prev,
+ video->mblock->pred_block, width, height,
+ round1, mvwidth, &xsum, &ysum);*/
+ c_comp = video->currVop->yChan + offset;
+
+
+ xpred = (int)((xpos << 1) + px[0]);
+ ypred = (int)((ypos << 1) + py[0]);
+
+ if ((CBP >> 5)&1)
+ {
+ pred = pred_block;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = c_comp;
+ pred_width = width;
+ }
+
+ /* check whether the MV points outside the frame */
+ if (xpred >= 0 && xpred <= ((width << 1) - (2*B_SIZE)) &&
+ ypred >= 0 && ypred <= ((height << 1) - (2*B_SIZE)))
+ { /*****************************/
+ /* (x,y) is inside the frame */
+ /*****************************/
+ ;
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*width),
+ pred, width, (pred_width << 1) | round1);
+ }
+ else
+ { /******************************/
+ /* (x,y) is outside the frame */
+ /******************************/
+ GetPredOutside(xpred, ypred, c_prev,
+ pred, width, height, round1, pred_width);
+ }
+
+
+ /* Compute prediction values over current luminance MB */
+ /* (blocks 1); add motion vector prior to input; */
+ /* add 8 to x_pos to advance to next block */
+ xpred = (int)(((xpos + B_SIZE) << 1) + px[1]);
+ ypred = (int)((ypos << 1) + py[1]);
+
+ if ((CBP >> 4)&1)
+ {
+ pred = pred_block + 8;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = c_comp + 8;
+ pred_width = width;
+ }
+
+ /* check whether the MV points outside the frame */
+ if (xpred >= 0 && xpred <= ((width << 1) - (2*B_SIZE)) &&
+ ypred >= 0 && ypred <= ((height << 1) - (2*B_SIZE)))
+ { /*****************************/
+ /* (x,y) is inside the frame */
+ /*****************************/
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*width),
+ pred, width, (pred_width << 1) | round1);
+ }
+ else
+ { /******************************/
+ /* (x,y) is outside the frame */
+ /******************************/
+ GetPredOutside(xpred, ypred, c_prev,
+ pred, width, height, round1, pred_width);
+ }
+
+
+
+ /* Compute prediction values over current luminance MB */
+ /* (blocks 2); add motion vector prior to input */
+ /* add 8 to y_pos to advance to block on next row */
+ xpred = (int)((xpos << 1) + px[2]);
+ ypred = (int)(((ypos + B_SIZE) << 1) + py[2]);
+
+ if ((CBP >> 3)&1)
+ {
+ pred = pred_block + 128;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = c_comp + (width << 3);
+ pred_width = width;
+ }
+
+ /* check whether the MV points outside the frame */
+ if (xpred >= 0 && xpred <= ((width << 1) - (2*B_SIZE)) &&
+ ypred >= 0 && ypred <= ((height << 1) - (2*B_SIZE)))
+ { /*****************************/
+ /* (x,y) is inside the frame */
+ /*****************************/
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*width),
+ pred, width, (pred_width << 1) | round1);
+ }
+ else
+ { /******************************/
+ /* (x,y) is outside the frame */
+ /******************************/
+ GetPredOutside(xpred, ypred, c_prev,
+ pred, width, height, round1, pred_width);
+ }
+
+
+
+ /* Compute prediction values over current luminance MB */
+ /* (blocks 3); add motion vector prior to input; */
+ /* add 8 to x_pos and y_pos to advance to next block */
+ /* on next row */
+ xpred = (int)(((xpos + B_SIZE) << 1) + px[3]);
+ ypred = (int)(((ypos + B_SIZE) << 1) + py[3]);
+
+ if ((CBP >> 2)&1)
+ {
+ pred = pred_block + 136;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = c_comp + (width << 3) + 8;
+ pred_width = width;
+ }
+
+ /* check whether the MV points outside the frame */
+ if (xpred >= 0 && xpred <= ((width << 1) - (2*B_SIZE)) &&
+ ypred >= 0 && ypred <= ((height << 1) - (2*B_SIZE)))
+ { /*****************************/
+ /* (x,y) is inside the frame */
+ /*****************************/
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*width),
+ pred, width, (pred_width << 1) | round1);
+ }
+ else
+ { /******************************/
+ /* (x,y) is outside the frame */
+ /******************************/
+ GetPredOutside(xpred, ypred, c_prev,
+ pred, width, height, round1, pred_width);
+ }
+ /* Call function to set de-blocking and de-ringing */
+ /* semaphores for luminance */
+
+
+
+ /* xpred and ypred calculation for Chrominance is */
+ /* in full-pel resolution. */
+
+ /* Chrominance */
+ /* width of chrominance data in pixels (y axis) */
+ width >>= 1;
+
+ /* heigth of chrominance data in pixels (x axis) */
+ height >>= 1;
+
+ /* Pointer to previous chrominance b frame */
+ cu_prev = prev->uChan;
+
+ /* Pointer to previous chrominance r frame */
+ cv_prev = prev->vChan;
+
+ /* x position in prediction data offset by motion vector */
+ /* xpred calculation for Chrominance is in full-pel */
+ /* resolution. */
+ xpred = xpos + dx;
+
+ /* y position in prediction data offset by motion vector */
+ /* ypred calculation for Chrominance is in full-pel */
+ /* resolution. */
+ ypred = ypos + dy;
+
+ cu_comp = video->currVop->uChan + (offset >> 2) + (xpos >> 2);
+ cv_comp = video->currVop->vChan + (offset >> 2) + (xpos >> 2);
+
+ /* Call function that performs chrominance prediction */
+ /* chrominance_pred(xpred, ypred, cu_prev, cv_prev,
+ pred_block, width_uv, height_uv,
+ round1);*/
+ if (xpred >= 0 && xpred <= ((width << 1) - (2*B_SIZE)) && ypred >= 0 &&
+ ypred <= ((height << 1) - (2*B_SIZE)))
+ {
+ /*****************************/
+ /* (x,y) is inside the frame */
+ /*****************************/
+ if ((CBP >> 1)&1)
+ {
+ pred = pred_block + 256;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = cu_comp;
+ pred_width = width;
+ }
+
+ /* Compute prediction for Chrominance b (block[4]) */
+ GetPredAdvBTable[ypred&1][xpred&1](cu_prev + (xpred >> 1) + ((ypred >> 1)*width),
+ pred, width, (pred_width << 1) | round1);
+
+ if (CBP&1)
+ {
+ pred = pred_block + 264;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = cv_comp;
+ pred_width = width;
+ }
+ /* Compute prediction for Chrominance r (block[5]) */
+ GetPredAdvBTable[ypred&1][xpred&1](cv_prev + (xpred >> 1) + ((ypred >> 1)*width),
+ pred, width, (pred_width << 1) | round1);
+
+ return ;
+ }
+ else
+ {
+ /******************************/
+ /* (x,y) is outside the frame */
+ /******************************/
+ if ((CBP >> 1)&1)
+ {
+ pred = pred_block + 256;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = cu_comp;
+ pred_width = width;
+ }
+
+ /* Compute prediction for Chrominance b (block[4]) */
+ GetPredOutside(xpred, ypred, cu_prev,
+ pred, width, height, round1, pred_width);
+
+ if (CBP&1)
+ {
+ pred = pred_block + 264;
+ pred_width = 16;
+ }
+ else
+ {
+ pred = cv_comp;
+ pred_width = width;
+ }
+
+ /* Compute prediction for Chrominance r (block[5]) */
+ GetPredOutside(xpred, ypred, cv_prev,
+ pred, width, height, round1, pred_width);
+
+ return ;
+ }
+
+}
+
+/*** special function for skipped macroblock, Aug 15, 2005 */
+void SkippedMBMotionComp(
+ VideoDecData *video
+)
+{
+ Vop *prev = video->prevVop;
+ Vop *comp;
+ int ypos, xpos;
+ PIXEL *c_comp, *c_prev;
+ PIXEL *cu_comp, *cu_prev;
+ PIXEL *cv_comp, *cv_prev;
+ int width, width_uv;
+ int32 offset;
+
+ width = video->width;
+ width_uv = width >> 1;
+ ypos = video->mbnum_row << 4 ;
+ xpos = video->mbnum_col << 4 ;
+ offset = (int32)ypos * width + xpos;
+
+
+ /* zero motion compensation for previous frame */
+ /*mby*width + mbx;*/
+ c_prev = prev->yChan;
+ if (!c_prev) {
+ ALOGE("b/35269635");
+ android_errorWriteLog(0x534e4554, "35269635");
+ return;
+ }
+ c_prev += offset;
+
+ /*by*width_uv + bx;*/
+ cu_prev = prev->uChan + (offset >> 2) + (xpos >> 2);
+ /*by*width_uv + bx;*/
+ cv_prev = prev->vChan + (offset >> 2) + (xpos >> 2);
+
+ comp = video->currVop;
+
+ c_comp = comp->yChan + offset;
+ cu_comp = comp->uChan + (offset >> 2) + (xpos >> 2);
+ cv_comp = comp->vChan + (offset >> 2) + (xpos >> 2);
+
+
+ /* Copy previous reconstructed frame into the current frame */
+ PutSKIPPED_MB(c_comp, c_prev, width);
+ PutSKIPPED_B(cu_comp, cu_prev, width_uv);
+ PutSKIPPED_B(cv_comp, cv_prev, width_uv);
+
+ /* 10/24/2000 post_processing semaphore generation */
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+
+ return;
+}
diff --git a/media/codecs/m4v_h263/dec/src/mb_utils.cpp b/media/codecs/m4v_h263/dec/src/mb_utils.cpp
new file mode 100644
index 0000000..25a31b7
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/mb_utils.cpp
@@ -0,0 +1,133 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4dec_lib.h"
+
+/* ====================================================================== /
+ Function : PutSKIPPED_MB()
+ Date : 04/03/2000
+/ ====================================================================== */
+
+void PutSKIPPED_MB(uint8 *comp, uint8 *prev, int width)
+{
+ int32 *temp0, *temp1;
+ int row;
+ row = MB_SIZE;
+
+
+ while (row)
+ {
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+ temp1[2] = temp0[2];
+ temp1[3] = temp0[3];
+
+ comp += width;
+ prev += width;
+
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+ temp1[2] = temp0[2];
+ temp1[3] = temp0[3];
+
+ comp += width;
+ prev += width;
+
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+ temp1[2] = temp0[2];
+ temp1[3] = temp0[3];
+
+
+ comp += width;
+ prev += width;
+
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+ temp1[2] = temp0[2];
+ temp1[3] = temp0[3];
+
+ comp += width;
+ prev += width;
+ row -= 4;
+ }
+}
+
+
+/* ====================================================================== /
+ Function : PutSKIPPED_B()
+ Date : 04/03/2000
+/ ====================================================================== */
+
+void PutSKIPPED_B(uint8 *comp, uint8 *prev, int width)
+{
+ int32 *temp0, *temp1;
+ int row;
+
+ row = B_SIZE;
+ while (row)
+ {
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+
+ comp += width;
+ prev += width;
+
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+
+ comp += width;
+ prev += width;
+
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+
+ comp += width;
+ prev += width;
+
+ temp0 = (int32 *)prev;
+ temp1 = (int32 *)comp;
+
+ temp1[0] = temp0[0];
+ temp1[1] = temp0[1];
+
+ comp += width;
+ prev += width;
+ row -= 4;
+ }
+}
+
+
diff --git a/media/codecs/m4v_h263/dec/src/mbtype_mode.h b/media/codecs/m4v_h263/dec/src/mbtype_mode.h
new file mode 100644
index 0000000..c45bb5f
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/mbtype_mode.h
@@ -0,0 +1,37 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+const static int MBtype_mode[] =
+{
+ MODE_INTER,
+ MODE_INTER_Q,
+ MODE_INTER4V,
+ MODE_INTRA,
+ MODE_INTRA_Q,
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ MODE_INTER4V_Q,
+#endif
+ MODE_SKIPPED
+};
+#ifdef PV_ANNEX_IJKT_SUPPORT
+const static int16 DQ_tab_Annex_T_10[32] = {0, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3};
+const static int16 DQ_tab_Annex_T_11[32] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, -5};
+const static int16 MQ_chroma_QP_table[32] = {0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13,
+ 14, 14, 14, 14, 14, 15, 15, 15, 15, 15
+ };
+#endif
+
diff --git a/media/codecs/m4v_h263/dec/src/motion_comp.h b/media/codecs/m4v_h263/dec/src/motion_comp.h
new file mode 100644
index 0000000..68281ba
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/motion_comp.h
@@ -0,0 +1,108 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef motion_comp_h
+#define motion_comp_h
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+/* CBP Mask defines used in chrominance prediction */
+#define CBP_MASK_CHROMA_BLK4 0x2
+#define CBP_MASK_CHROMA_BLK5 0x1
+
+/* CBP Mask defines used in luminance prediction (MODE_INTER4V) */
+#define CBP_MASK_BLK0_MODE_INTER4V 0x20
+#define CBP_MASK_BLK1_MODE_INTER4V 0x10
+#define CBP_MASK_BLK2_MODE_INTER4V 0x08
+#define CBP_MASK_BLK3_MODE_INTER4V 0x04
+
+/* CBP Mask defines used in luminance prediction (MODE_INTER or MODE_INTER_Q) */
+#define CBP_MASK_MB_MODE_INTER 0x3c
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define CLIP_RESULT(x) if((x) & -256){(x) = 0xFF & (~((x)>>31));}
+#define ADD_AND_CLIP1(x) x += (pred_word&0xFF); CLIP_RESULT(x);
+#define ADD_AND_CLIP2(x) x += ((pred_word>>8)&0xFF); CLIP_RESULT(x);
+#define ADD_AND_CLIP3(x) x += ((pred_word>>16)&0xFF); CLIP_RESULT(x);
+#define ADD_AND_CLIP4(x) x += ((pred_word>>24)&0xFF); CLIP_RESULT(x);
+
+#define ADD_AND_CLIP(x,y) { x9 = ~((x)>>8); \
+ if(x9!=-1){ \
+ x9 = ((uint32)x9)>>24; \
+ (y) = x9|((y)<<8); \
+ } \
+ else \
+ { \
+ (y) = (x)|((y)<<8); \
+ } \
+ }
+
+
+ static int (*const GetPredAdvBTable[2][2])(uint8*, uint8*, int, int) =
+ {
+ {&GetPredAdvancedBy0x0, &GetPredAdvancedBy0x1},
+ {&GetPredAdvancedBy1x0, &GetPredAdvancedBy1x1}
+ };
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
diff --git a/media/codecs/m4v_h263/dec/src/mp4dec_lib.h b/media/codecs/m4v_h263/dec/src/mp4dec_lib.h
new file mode 100644
index 0000000..ce6f9c3
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/mp4dec_lib.h
@@ -0,0 +1,303 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _MP4DECLIB_H_
+#define _MP4DECLIB_H_
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4def.h" /* typedef */
+#include "mp4lib_int.h" /* main video structure */
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+ /* defined in pvdec_api.c, these function are not supposed to be */
+ /* exposed to programmers outside PacketVideo. 08/15/2000. */
+ uint VideoDecoderErrorDetected(VideoDecData *video);
+
+#ifdef ENABLE_LOG
+ void m4vdec_dprintf(char *format, ...);
+#define mp4dec_log(message) m4vdec_dprintf(message)
+#else
+#define mp4dec_log(message)
+#endif
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in frame_buffer.c */
+ PV_STATUS FillFrameBufferNew(BitstreamDecVideo *stream);
+ PV_STATUS FillFrameBuffer(BitstreamDecVideo *stream, int short_header);
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in dc_ac_pred.c */
+ int cal_dc_scaler(int QP, int type);
+ PV_STATUS PV_DecodePredictedIntraDC(int compnum, BitstreamDecVideo *stream,
+ int16 *IntraDC_delta);
+
+ void doDCACPrediction(VideoDecData *video, int comp, int16 *q_block,
+ int *direction);
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ void doDCACPrediction_I(VideoDecData *video, int comp, int16 *q_block);
+#endif
+ /*--------------------------------------------------------------------------*/
+ /* defined in block_idct.c */
+ void MBlockIDCTAdd(VideoDecData *video, int nz_coefs[]);
+
+ void BlockIDCT(uint8 *dst, uint8 *pred, int16 *blk, int width, int nzcoefs,
+ uint8 *bitmapcol, uint8 bitmaprow);
+
+ void MBlockIDCT(VideoDecData *video);
+ void BlockIDCT_intra(MacroBlock *mblock, PIXEL *c_comp, int comp, int width_offset);
+ /*--------------------------------------------------------------------------*/
+ /* defined in combined_decode.c */
+ PV_STATUS DecodeFrameCombinedMode(VideoDecData *video);
+ PV_STATUS GetMBheader(VideoDecData *video, int16 *QP);
+ PV_STATUS GetMBData(VideoDecData *video);
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in datapart_decode.c */
+ PV_STATUS DecodeFrameDataPartMode(VideoDecData *video);
+ PV_STATUS GetMBheaderDataPart_DQUANT_DC(VideoDecData *video, int16 *QP);
+ PV_STATUS GetMBheaderDataPart_P(VideoDecData *video);
+ PV_STATUS DecodeDataPart_I_VideoPacket(VideoDecData *video, int slice_counter);
+ PV_STATUS DecodeDataPart_P_VideoPacket(VideoDecData *video, int slice_counter);
+ PV_STATUS GetMBData_DataPart(VideoDecData *video);
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in packet_util.c */
+ PV_STATUS PV_ReadVideoPacketHeader(VideoDecData *video, int *next_MB);
+ PV_STATUS RecoverPacketError(BitstreamDecVideo *stream, int marker_length, int32 *nextVop);
+ PV_STATUS RecoverGOBError(BitstreamDecVideo *stream, int marker_length, int32 *vopPos);
+ PV_STATUS PV_GobHeader(VideoDecData *video);
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ PV_STATUS PV_H263SliceHeader(VideoDecData *videoInt, int *next_MB);
+#endif
+ /*--------------------------------------------------------------------------*/
+ /* defined in motion_comp.c */
+ void MBMotionComp(VideoDecData *video, int CBP);
+ void SkippedMBMotionComp(VideoDecData *video);
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in chrominance_pred.c */
+ void chrominance_pred(
+ int xpred, /* i */
+ int ypred, /* i */
+ uint8 *cu_prev, /* i */
+ uint8 *cv_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width_uv, /* i */
+ int height_uv, /* i */
+ int round1
+ );
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in luminance_pred_mode_inter.c */
+ void luminance_pred_mode_inter(
+ int xpred, /* i */
+ int ypred, /* i */
+ uint8 *c_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int height, /* i */
+ int round1
+ );
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in luminance_pred_mode_inter4v.c */
+ void luminance_pred_mode_inter4v(
+ int xpos, /* i */
+ int ypos, /* i */
+ MOT *px, /* i */
+ MOT *py, /* i */
+ uint8 *c_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int height, /* i */
+ int round1, /* i */
+ int mvwidth, /* i */
+ int *xsum_ptr, /* i/o */
+ int *ysum_ptr /* i/o */
+ );
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in pp_semaphore_chroma_inter.c */
+ /*--------------------------------------------------------------------------*/
+ /* defined in get_pred_adv_mb_add.c */
+ int GetPredAdvancedMB(
+ int xpos,
+ int ypos,
+ uint8 *c_prev,
+ uint8 *pred_block,
+ int width,
+ int rnd1
+ );
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in get_pred_adv_b_add.c */
+ int GetPredAdvancedBy0x0(
+ uint8 *c_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+ );
+
+ int GetPredAdvancedBy0x1(
+ uint8 *c_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+ );
+
+ int GetPredAdvancedBy1x0(
+ uint8 *c_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+ );
+
+ int GetPredAdvancedBy1x1(
+ uint8 *c_prev, /* i */
+ uint8 *pred_block, /* i */
+ int width, /* i */
+ int pred_width_rnd /* i */
+ );
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in get_pred_outside.c */
+ int GetPredOutside(
+ int xpos,
+ int ypos,
+ uint8 *c_prev,
+ uint8 *pred_block,
+ int width,
+ int height,
+ int rnd1,
+ int pred_width
+ );
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in find_pmvsErrRes.c */
+ void mv_prediction(VideoDecData *video, int block, MOT *mvx, MOT *mvy);
+
+ /*--------------------------------------------------------------------------*/
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in mb_utils.c */
+ void Copy_MB_into_Vop(uint8 *comp, int yChan[][NCOEFF_BLOCK], int width);
+ void Copy_B_into_Vop(uint8 *comp, int cChan[], int width);
+ void PutSKIPPED_MB(uint8 *comp, uint8 *c_prev, int width);
+ void PutSKIPPED_B(uint8 *comp, uint8 *c_prev, int width);
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in vop.c */
+ PV_STATUS DecodeGOVHeader(BitstreamDecVideo *stream, uint32 *time_base);
+ PV_STATUS DecodeVOLHeader(VideoDecData *video, int layer);
+ PV_STATUS DecodeVOPHeader(VideoDecData *video, Vop *currVop, Bool use_ext_tiemstamp);
+ PV_STATUS DecodeShortHeader(VideoDecData *video, Vop *currVop);
+ PV_STATUS PV_DecodeVop(VideoDecData *video);
+ uint32 CalcVopDisplayTime(Vol *currVol, Vop *currVop, int shortVideoHeader);
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in post_proc.c */
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ void H263_Deblock(uint8 *rec, int width, int height, int16 *QP_store, uint8 *mode, int chr, int T);
+#endif
+ int PostProcSemaphore(int16 *q_block);
+ void PostFilter(VideoDecData *video, int filer_type, uint8 *output);
+ void FindMaxMin(uint8 *ptr, int *min, int *max, int incr);
+ void DeringAdaptiveSmoothMMX(uint8 *img, int incr, int thres, int mxdf);
+ void AdaptiveSmooth_NoMMX(uint8 *Rec_Y, int v0, int h0, int v_blk, int h_blk,
+ int thr, int width, int max_diff);
+ void Deringing_Luma(uint8 *Rec_Y, int width, int height, int16 *QP_store,
+ int Combined, uint8 *pp_mod);
+ void Deringing_Chroma(uint8 *Rec_C, int width, int height, int16 *QP_store,
+ int Combined, uint8 *pp_mod);
+ void CombinedHorzVertFilter(uint8 *rec, int width, int height, int16 *QP_store,
+ int chr, uint8 *pp_mod);
+ void CombinedHorzVertFilter_NoSoftDeblocking(uint8 *rec, int width, int height, int16 *QP_store,
+ int chr, uint8 *pp_mod);
+ void CombinedHorzVertRingFilter(uint8 *rec, int width, int height,
+ int16 *QP_store, int chr, uint8 *pp_mod);
+
+ /*--------------------------------------------------------------------------*/
+ /* defined in conceal.c */
+ void ConcealTexture_I(VideoDecData *video, int32 startFirstPartition, int mb_start, int mb_stop,
+ int slice_counter);
+ void ConcealTexture_P(VideoDecData *video, int mb_start, int mb_stop,
+ int slice_counter);
+ void ConcealPacket(VideoDecData *video, int mb_start, int mb_stop,
+ int slice_counter);
+ void CopyVopMB(Vop *curr, uint8 *prev, int mbnum, int width, int height);
+
+ /* define in vlc_dequant.c , 09/18/2000*/
+#ifdef PV_SUPPORT_MAIN_PROFILE
+ int VlcDequantMpegIntraBlock(void *video, int comp, int switched,
+ uint8 *bitmapcol, uint8 *bitmaprow);
+ int VlcDequantMpegInterBlock(void *video, int comp,
+ uint8 *bitmapcol, uint8 *bitmaprow);
+#endif
+ int VlcDequantH263IntraBlock(VideoDecData *video, int comp, int switched,
+ uint8 *bitmapcol, uint8 *bitmaprow);
+ int VlcDequantH263IntraBlock_SH(VideoDecData *video, int comp,
+ uint8 *bitmapcol, uint8 *bitmaprow);
+ int VlcDequantH263InterBlock(VideoDecData *video, int comp,
+ uint8 *bitmapcol, uint8 *bitmaprow);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/m4v_h263/dec/src/mp4def.h b/media/codecs/m4v_h263/dec/src/mp4def.h
new file mode 100644
index 0000000..20f458d
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/mp4def.h
@@ -0,0 +1,167 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _PVDECDEF_H_
+#define _PVDECDEF_H_
+
+#include "mp4dec_api.h"
+
+typedef enum
+{
+ PV_SUCCESS,
+ PV_FAIL,
+ PV_MB_STUFFING, /* hit Macroblock_Stuffing */
+ PV_END_OF_VOP, /* hit End_of_Video_Object_Plane */
+ PV_END_OF_MB /* hit End_of_Macroblock */
+#ifdef PV_TOLERATE_VOL_ERRORS
+ , PV_BAD_VOLHEADER
+#endif
+} PV_STATUS;
+
+typedef uint8 PIXEL;
+typedef int16 MOT; /* : "int" type runs faster on RISC machine */
+
+#define TRUE 1
+#define FALSE 0
+
+#define PV_ABS(x) (((x)<0)? -(x) : (x))
+#define PV_SIGN(x) (((x)<0)? -1 : 1)
+#define PV_SIGN0(a) (((a)<0)? -1 : (((a)>0) ? 1 : 0))
+#define PV_MAX(a,b) ((a)>(b)? (a):(b))
+#define PV_MIN(a,b) ((a)<(b)? (a):(b))
+#define PV_MEDIAN(A,B,C) ((A) > (B) ? ((A) < (C) ? (A) : (B) > (C) ? (B) : (C)): (B) < (C) ? (B) : (C) > (A) ? (C) : (A))
+/* You don't want to use ((x>UB)?UB:(x<LB)?LB:x) for the clipping */
+/* because it will use one extra comparison if the compiler is */
+/* not well-optimized. 04/19/2000. */
+#define CLIP_THE_RANGE(x,LB,UB) if ((x)<(LB)) (x) = (LB); else if ((x)>(UB)) (x) = (UB)
+
+#define MODE_INTRA 0x08 //01000
+#define MODE_INTRA_Q 0x09 //01001
+#define MODE_SKIPPED 0x10 //10000
+#define MODE_INTER4V 0x14 //10100
+#define MODE_INTER 0x16 //10110
+#define MODE_INTER_Q 0x17 //10111
+#define MODE_INTER4V_Q 0x15 //10101
+#define INTER_1VMASK 0x2
+#define Q_MASK 0x1
+#define INTRA_MASK 0x8
+#define INTER_MASK 0x4
+
+
+#define I_VOP 0
+#define P_VOP 1
+#define B_VOP 2
+
+#define LUMINANCE_DC_TYPE 1
+#define CHROMINANCE_DC_TYPE 2
+
+#define START_CODE_LENGTH 32
+
+/* 11/30/98 */
+#define NoMarkerFound (-1)
+#define FoundRM 1 /* Resync Marker */
+#define FoundVSC 2 /* VOP_START_CODE. */
+#define FoundGSC 3 /* GROUP_START_CODE */
+#define FoundEOB 4 /* EOB_CODE */
+
+/* PacketVideo "absolution timestamp" object. 06/13/2000 */
+#define PVTS_START_CODE 0x01C4
+#define PVTS_START_CODE_LENGTH 32
+
+/* session layer and vop layer start codes */
+
+#define VISUAL_OBJECT_SEQUENCE_START_CODE 0x01B0
+#define VISUAL_OBJECT_SEQUENCE_END_CODE 0x01B1
+
+#define VISUAL_OBJECT_START_CODE 0x01B5
+#define VO_START_CODE 0x8
+#define VO_HEADER_LENGTH 32 /* lengtho of VO header: VO_START_CODE + VO_ID */
+
+#define SOL_START_CODE 0x01BE
+#define SOL_START_CODE_LENGTH 32
+
+#define VOL_START_CODE 0x12
+#define VOL_START_CODE_LENGTH 28
+
+#define VOP_START_CODE 0x1B6
+#define VOP_START_CODE_LENGTH 32
+
+#define GROUP_START_CODE 0x01B3
+#define GROUP_START_CODE_LENGTH 32
+
+#define VOP_ID_CODE_LENGTH 5
+#define VOP_TEMP_REF_CODE_LENGTH 16
+
+#define USER_DATA_START_CODE 0x01B2
+#define USER_DATA_START_CODE_LENGTH 32
+
+#define START_CODE_PREFIX 0x01
+#define START_CODE_PREFIX_LENGTH 24
+
+#define SHORT_VIDEO_START_MARKER 0x20
+#define SHORT_VIDEO_START_MARKER_LENGTH 22
+#define SHORT_VIDEO_END_MARKER 0x3F
+#define GOB_RESYNC_MARKER 0x01
+#define GOB_RESYNC_MARKER_LENGTH 17
+
+/* motion and resync markers used in error resilient mode */
+
+#define DC_MARKER 438273
+#define DC_MARKER_LENGTH 19
+
+#define MOTION_MARKER_COMB 126977
+#define MOTION_MARKER_COMB_LENGTH 17
+
+#define MOTION_MARKER_SEP 81921
+#define MOTION_MARKER_SEP_LENGTH 17
+
+#define RESYNC_MARKER 1
+#define RESYNC_MARKER_LENGTH 17
+
+#define SPRITE_NOT_USED 0
+#define STATIC_SPRITE 1
+#define ONLINE_SPRITE 2
+#define GMC_SPRITE 3
+
+/* macroblock and block size */
+#define MB_SIZE 16
+#define NCOEFF_MB (MB_SIZE*MB_SIZE)
+#define B_SIZE 8
+#define NCOEFF_BLOCK (B_SIZE*B_SIZE)
+#define NCOEFF_Y NCOEFF_MB
+#define NCOEFF_U NCOEFF_BLOCK
+#define NCOEFF_V NCOEFF_BLOCK
+#define BLK_PER_MB 4 /* Number of blocks per MB */
+
+/* VLC decoding related definitions */
+#define VLC_ERROR (-1)
+#define VLC_ESCAPE 7167
+
+
+/* macro utility */
+#define ZERO_OUT_64BYTES(x) { *((uint32*)(x)) = *(((uint32*)(x))+1) = \
+ *(((uint32*)(x))+2) = *(((uint32*)(x))+3) = \
+ *(((uint32*)(x))+4) = *(((uint32*)(x))+5) = \
+ *(((uint32*)(x))+6) = *(((uint32*)(x))+7) = \
+ *(((uint32*)(x))+8) = *(((uint32*)(x))+9) = \
+ *(((uint32*)(x))+10) = *(((uint32*)(x))+11) = \
+ *(((uint32*)(x))+12) = *(((uint32*)(x))+13) = \
+ *(((uint32*)(x))+14) = *(((uint32*)(x))+15) = 0; }
+
+
+
+#endif /* _PVDECDEF_H_ */
diff --git a/media/codecs/m4v_h263/dec/src/mp4lib_int.h b/media/codecs/m4v_h263/dec/src/mp4lib_int.h
new file mode 100644
index 0000000..d6754a7
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/mp4lib_int.h
@@ -0,0 +1,296 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _MP4LIB_INT_H_
+#define _MP4LIB_INT_H_
+
+#include "mp4def.h"
+#include "mp4dec_api.h" // extra structure
+
+#undef ENABLE_LOG
+#define BITRATE_AVERAGE_WINDOW 4
+#define FRAMERATE_SCALE ((BITRATE_AVERAGE_WINDOW-1)*10000L)
+#define FAST_IDCT /* , for fast Variable complexity IDCT */
+//#define PV_DEC_EXTERNAL_IDCT /* for separate IDCT (i.e. no direct access to output frame) */
+#define PV_ANNEX_IJKT_SUPPORT
+#define mid_gray 1024
+
+typedef struct tagBitstream
+{
+ /* function that reteive data from outside the library. 04/11/2000 */
+ /* In frame-based decoding mode, this shall be NULL. 08/29/2000 */
+ uint32 curr_word;
+ uint32 next_word;
+ uint8 *bitstreamBuffer; /* pointer to buffer memory */
+ int32 read_point; /* starting point in the buffer to be read to cache */
+ int incnt; /* bit left in cached */
+ int incnt_next;
+ uint32 bitcnt; /* total bit read so-far (from inbfr)*/
+ int32 data_end_pos; /*should be added , 06/07/2000 */
+ int searched_frame_boundary;
+} BitstreamDecVideo, *LPBitstreamDecVideo;
+
+/* complexity estimation parameters */
+typedef struct tagComplexity_Est
+{
+ uint8 text_1; /* texture_complexity_estimation_set_1 */
+ uint8 text_2; /* texture_complexity_estimation_set_2 */
+ uint8 mc; /* motion_compensation_complexity */
+} Complexity_Est;
+
+
+typedef struct tagVop
+{
+ PIXEL *yChan; /* The Y component */
+ PIXEL *uChan; /* The U component */
+ PIXEL *vChan; /* The V component */
+
+ uint32 timeStamp; /* Vop TimeStamp in msec */
+
+ /* Actual syntax elements for VOP (standard) */
+ int predictionType; /* VOP prediction type */
+ uint timeInc; /* VOP time increment (relative to last mtb) */
+ int vopCoded;
+ int roundingType;
+ int intraDCVlcThr;
+ int16 quantizer; /* VOP quantizer */
+ int fcodeForward; /* VOP dynamic range of motion vectors */
+ int fcodeBackward; /* VOP dynamic range of motion vectors */
+ int refSelectCode; /* enhancement layer reference select code */
+
+ /* H.263 parameters */
+ int gobNumber;
+ int gobFrameID;
+ int temporalRef; /* temporal reference, roll over at 256 */
+ int ETR;
+} Vop;
+
+typedef struct tagVol
+{
+ int volID; /* VOL identifier (for tracking) */
+ uint timeIncrementResolution;/* VOL time increment */
+ int nbitsTimeIncRes; /* number of bits for time increment */
+ uint timeInc_offset; /* timeInc offset for multiple VOP in a packet */
+ uint32 moduloTimeBase; /* internal decoder clock */
+ int fixedVopRate;
+ BitstreamDecVideo *bitstream; /* library bitstream buffer (input buffer) */
+
+ int complexity_estDisable; /* VOL disable complexity estimation */
+ int complexity_estMethod; /* VOL complexity estimation method */
+ Complexity_Est complexity; /* complexity estimation flags */
+
+ /* Error Resilience Flags */
+ int errorResDisable; /* VOL disable error resilence mode */
+ /* (Use Resynch markers) */
+ int useReverseVLC; /* VOL reversible VLCs */
+ int dataPartitioning; /* VOL data partitioning */
+
+ /* Bit depth */
+ uint bitsPerPixel;
+// int mid_gray; /* 2^(bits_per_pixel+2) */
+
+ /* Quantization related parameters */
+ int quantPrecision; /* Quantizer precision */
+ uint quantType; /* MPEG-4 or H.263 Quantization Type */
+ /* Added loaded quant mat, 05/22/2000 */
+ int loadIntraQuantMat; /* Load intra quantization matrix */
+ int loadNonIntraQuantMat; /* Load nonintra quantization matrix */
+ int iqmat[64]; /* Intra quant.matrix */
+ int niqmat[64]; /* Non-intra quant.matrix */
+
+ /* Parameters used for scalability */
+ int scalability; /* VOL scalability (flag) */
+ int scalType; /* temporal = 0, spatial = 1, both = 2 */
+
+ int refVolID; /* VOL id of reference VOL */
+ int refSampDir; /* VOL resol. of ref. VOL */
+ int horSamp_n; /* VOL hor. resampling of ref. VOL given by */
+ int horSamp_m; /* sampfac = hor_samp_n/hor_samp_m */
+ int verSamp_n; /* VOL ver. resampling of ref. VOL given by */
+ int verSamp_m; /* sampfac = ver_samp_n/ver_samp_m */
+ int enhancementType; /* VOL type of enhancement layer */
+ /* profile and level */
+ int32 profile_level_id; /* 8-bit profile and level */ // 6/17/04
+
+} Vol;
+
+
+typedef int16 typeMBStore[6][NCOEFF_BLOCK];
+
+typedef struct tagMacroBlock
+{
+ typeMBStore block; /* blocks */ /* ACDC */
+ uint8 pred_block[384]; /* prediction block, Aug 3,2005 */
+ uint8 bitmapcol[6][8];
+ uint8 bitmaprow[6];
+ int no_coeff[6];
+ int DCScalarLum; /* Luminance DC Scalar */
+ int DCScalarChr; /* Chrominance DC Scalar */
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ int direction;
+#endif
+} MacroBlock;
+
+typedef struct tagHeaderInfoDecVideo
+{
+ uint8 *Mode; /* Modes INTRA/INTER/etc. */
+ uint8 *CBP; /* MCBPC/CBPY stuff */
+} HeaderInfoDecVideo;
+
+
+/************************************************************/
+/* VLC structures */
+/************************************************************/
+typedef struct tagTcoef
+{
+ uint last;
+ uint run;
+ int level;
+ uint sign;
+} Tcoef, *LPTcoef;
+
+
+
+typedef struct tagVLCtab
+{
+ int32 val;
+ int32 len;
+} VLCtab, *LPVLCtab;
+
+typedef struct tagVLCshorttab
+{
+ int16 val;
+ int16 len;
+} VLCshorttab, *LPVLCshorttab ; /* for space saving, Antoine Nguyen*/
+
+typedef struct tagVLCtab2
+{
+ uint8 run;
+ uint8 level;
+ uint8 last;
+ uint8 len;
+} VLCtab2, *LPVLCtab2; /* 10/24/2000 */
+
+/* This type is designed for fast access of DC/AC */
+/* prediction data. If the compiler is smart */
+/* enough, it will use shifting for indexing. */
+/* 04/14/2000. */
+
+typedef int16 typeDCStore[6]; /* ACDC */
+typedef int16 typeDCACStore[4][8];
+
+
+
+/* Global structure that can be passed around */
+typedef struct tagVideoDecData
+{
+ BitstreamDecVideo *bitstream; /* library bitstream buffer (input buffer) */
+ /* Data For Layers (Scalability) */
+ Vol **vol; /* Data stored for each VOL */
+
+ /* Data used for reconstructing frames */
+ Vop *currVop; /* Current VOP (frame) */
+ Vop *prevVop; /* Previous VOP (frame) */
+ /* Data used to facilitate multiple layer decoding. 05/04/2000 */
+ Vop *prevEnhcVop; /* New change to rid of memcpy(). 04/24/2001 */
+ Vop **vopHeader; /* one for each layer. 08/29/2000 */
+
+ /* I/O structures */
+ MacroBlock *mblock; /* Macroblock data structure */
+ uint8 *acPredFlag; /* */
+
+ /* scratch memory used in data partitioned mode */
+ typeDCStore *predDC; /* The DC coeffs for each MB */
+ typeDCACStore *predDCAC_row;
+ typeDCACStore *predDCAC_col;
+
+ int usePrevQP; /* running QP decision switch */
+ uint8 *sliceNo; /* Slice indicator for each MB */
+ /* changed this to a 1D */
+ /* array for optimization */
+ MOT *motX; /* Motion vector in X direction */
+ MOT *motY; /* Motion vector in Y direction */
+ HeaderInfoDecVideo headerInfo; /* MB Header information */
+ int16 *QPMB; /* Quantizer value for each MB */
+
+ uint8 *pstprcTypCur; /* Postprocessing type for current frame */
+ uint8 *pstprcTypPrv; /* Postprocessing type for previous frame */
+ /* scratch memory used in all modes */
+ int mbnum; /* Macroblock number */
+ uint mbnum_row;
+ int mbnum_col;
+ /* I added these variables since they are used a lot. 04/13/2000 */
+ int nMBPerRow, nMBPerCol; /* number of MBs in each row & column */
+ int nTotalMB;
+ /* for short video header */
+ int nMBinGOB; /* number of MBs in GOB, 05/22/00 */
+ int nGOBinVop; /* number of GOB in Vop 05/22/00 */
+ /* VOL Dimensions */
+ int width; /* Width */
+ int height; /* Height */
+ int displayWidth; /* Handle image whose size is not a multiple of 16. */
+ int displayHeight; /* This is the actual size. 08/09/2000 */
+ int32 size;
+ /* Miscellaneous data points to be passed */
+ int frame_idx; /* Current frame ID */
+ int frameRate; /* Output frame Rate (over 10 seconds) */
+ int32 duration;
+ uint32 currTimestamp;
+ int currLayer; /* Current frame layer */
+ int shortVideoHeader; /* shortVideoHeader mode */
+ int intra_acdcPredDisable; /* VOL disable INTRA DC prediction */
+ int numberOfLayers; /* Number of Layers */
+ /* Frame to be used for concealment 07/07/2001 */
+ uint8 *concealFrame;
+ int vop_coding_type;
+ /* framerate and bitrate statistics counters. 08/23/2000 */
+ int32 nBitsPerVop[BITRATE_AVERAGE_WINDOW];
+ uint32 prevTimestamp[BITRATE_AVERAGE_WINDOW];
+ int nBitsForMBID; /* how many bits required for MB number? */
+ /* total data memory used by the docder library. 08/23/2000 */
+ int32 memoryUsage;
+
+ /* flag to turn on/off error concealment or soft decoding */
+ int errorConcealment;
+
+ /* Application controls */
+ VideoDecControls *videoDecControls;
+ int postFilterType; /* Postfilter mode 04/25/00 */
+
+
+
+ PV_STATUS(*vlcDecCoeffIntra)(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra_luma*/);
+ PV_STATUS(*vlcDecCoeffInter)(BitstreamDecVideo *stream, Tcoef *pTcoef);
+ int initialized;
+
+ /* Annex IJKT */
+ int deblocking;
+ int slice_structure;
+ int modified_quant;
+ int advanced_INTRA;
+ int16 QP_CHR; /* ANNEX_T */
+} VideoDecData;
+
+/* for fast VLC+Dequant 10/12/2000*/
+typedef int (*VlcDequantBlockFuncP)(void *video, int comp, int switched,
+ uint8 *bitmaprow, uint8 *bitmapcol);
+
+//////////////////////////////////////////////////////////////
+// Decoder structures //
+//////////////////////////////////////////////////////////////
+#endif /* _MP4LIB_INT_H_ */
+
diff --git a/media/codecs/m4v_h263/dec/src/packet_util.cpp b/media/codecs/m4v_h263/dec/src/packet_util.cpp
new file mode 100644
index 0000000..5880e32
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/packet_util.cpp
@@ -0,0 +1,256 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4dec_lib.h"
+#include "vlc_decode.h"
+#include "bitstream.h"
+
+
+/***********************************************************CommentBegin******
+* 04/13/2000 : initial modification to the new PV-Decoder
+* Lib format.
+* 04/16/2001 : Removed PV_END_OF_BUFFER case, error resilience
+***********************************************************CommentEnd********/
+PV_STATUS PV_ReadVideoPacketHeader(VideoDecData *video, int *next_MB)
+{
+ PV_STATUS status;
+ Vol *currVol = video->vol[video->currLayer];
+ Vop *currVop = video->currVop;
+ BitstreamDecVideo *stream = video->bitstream;
+ int fcode_forward;
+ int resync_marker_length;
+ int nbits = video->nBitsForMBID;
+ uint32 tmpvar32;
+ uint tmpvar16;
+ int16 quantizer;
+ int nTotalMB = video->nTotalMB;
+
+ fcode_forward = currVop->fcodeForward;
+ resync_marker_length = 17;
+
+ if (currVop->predictionType != I_VOP) resync_marker_length = 16 + fcode_forward;
+
+ status = PV_BitstreamShowBitsByteAlign(stream, resync_marker_length, &tmpvar32);
+ /* if (status != PV_SUCCESS && status != PV_END_OF_BUFFER) return status; */
+ if (tmpvar32 == RESYNC_MARKER)
+ {
+// DecNextStartCode(stream);
+ PV_BitstreamByteAlign(stream);
+ BitstreamReadBits32(stream, resync_marker_length);
+
+ int mbnum = (int) BitstreamReadBits16(stream, nbits);
+ if (mbnum < 0) {
+ return PV_FAIL;
+ }
+ *next_MB = mbnum;
+// if (*next_MB <= video->mbnum) /* needs more investigation */
+// *next_MB = video->mbnum+1;
+
+ if (*next_MB >= nTotalMB) /* fix 04/05/01 */
+ {
+ *next_MB = video->mbnum + 1;
+ if (*next_MB >= nTotalMB) /* this check is needed */
+ *next_MB = nTotalMB - 1;
+ }
+ quantizer = (int16) BitstreamReadBits16(stream, currVol->quantPrecision);
+ if (quantizer == 0) return PV_FAIL; /* 04/03/01 */
+
+ currVop->quantizer = quantizer;
+
+ /* if we have HEC, read some redundant VOP header information */
+ /* this part needs improvement 04/05/01 */
+ if (BitstreamRead1Bits(stream))
+ {
+ int time_base = -1;
+
+ /* modulo_time_base (? bits) */
+ do
+ {
+ time_base++;
+ tmpvar16 = BitstreamRead1Bits(stream);
+ }
+ while (tmpvar16 == 1);
+
+ /* marker bit */
+ BitstreamRead1Bits(stream);
+
+ /* vop_time_increment (1-15 bits) */
+ BitstreamReadBits16(stream, currVol->nbitsTimeIncRes);
+
+ /* marker bit */
+ BitstreamRead1Bits(stream);
+
+ /* vop_prediction_type (2 bits) */
+ BitstreamReadBits16(stream, 2);
+
+ /* Added intra_dc_vlc_thr reading */
+ BitstreamReadBits16(stream, 3);
+
+ /* fcodes */
+ if (currVop->predictionType != I_VOP)
+ {
+ fcode_forward = (int) BitstreamReadBits16(stream, 3);
+
+ if (currVop->predictionType == B_VOP)
+ {
+ BitstreamReadBits16(stream, 3);
+ }
+ }
+
+ }
+ }
+ else
+ {
+ PV_BitstreamByteAlign(stream); /* */
+ status = BitstreamCheckEndBuffer(stream); /* return end_of_VOP 03/30/01 */
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+ status = BitstreamShowBits32HC(stream, &tmpvar32); /* 07/07/01 */
+ /* -16 = 0xFFFFFFF0*/
+ if ((tmpvar32 & 0xFFFFFFF0) == VISUAL_OBJECT_SEQUENCE_START_CODE) /* start code mask 00 00 01 */
+
+ {
+ /* we don't have to check for legl stuffing here. 05/08/2000 */
+ return PV_END_OF_VOP;
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+
+ return PV_SUCCESS;
+}
+
+
+
+/***********************************************************CommentBegin******
+* 3/10/00 : initial modification to the
+* new PV-Decoder Lib format.
+* 04/17/01 : remove PV_END_OF_BUFFER, error checking
+***********************************************************CommentEnd********/
+PV_STATUS PV_GobHeader(VideoDecData *video)
+{
+ uint32 tmpvar;
+ Vop *currVop = video->currVop;
+ BitstreamDecVideo *stream = video->bitstream;
+ int quantPrecision = 5;
+ int16 quantizer;
+
+ BitstreamShowBits32(stream, GOB_RESYNC_MARKER_LENGTH, &tmpvar);
+
+ if (tmpvar != GOB_RESYNC_MARKER)
+ {
+ PV_BitstreamShowBitsByteAlign(stream, GOB_RESYNC_MARKER_LENGTH, &tmpvar);
+
+ if (tmpvar != GOB_RESYNC_MARKER)
+ {
+ return PV_FAIL;
+ }
+ else
+ PV_BitstreamByteAlign(stream); /* if bytealigned GOBHEADER search is performed */
+ /* then no more noforcestuffing */
+ }
+
+ /* we've got a GOB header info here */
+ BitstreamShowBits32(stream, GOB_RESYNC_MARKER_LENGTH + 5, &tmpvar);
+ tmpvar &= 0x1F;
+
+ if (tmpvar == 0)
+ {
+ return PV_END_OF_VOP;
+ }
+
+ if (tmpvar == 31)
+ {
+ PV_BitstreamFlushBits(stream, GOB_RESYNC_MARKER_LENGTH + 5);
+ BitstreamByteAlignNoForceStuffing(stream);
+ return PV_END_OF_VOP;
+ }
+
+ PV_BitstreamFlushBits(stream, GOB_RESYNC_MARKER_LENGTH + 5);
+ currVop->gobNumber = (int) tmpvar;
+ if (currVop->gobNumber >= video->nGOBinVop) return PV_FAIL;
+ currVop->gobFrameID = (int) BitstreamReadBits16(stream, 2);
+ quantizer = (int16) BitstreamReadBits16(stream, quantPrecision);
+ if (quantizer == 0) return PV_FAIL; /* 04/03/01 */
+
+ currVop->quantizer = quantizer;
+ return PV_SUCCESS;
+}
+#ifdef PV_ANNEX_IJKT_SUPPORT
+PV_STATUS PV_H263SliceHeader(VideoDecData *video, int *next_MB)
+{
+ PV_STATUS status;
+ uint32 tmpvar;
+ Vop *currVop = video->currVop;
+ BitstreamDecVideo *stream = video->bitstream;
+ int nTotalMB = video->nTotalMB;
+ int16 quantizer;
+
+ PV_BitstreamShowBitsByteAlignNoForceStuffing(stream, 17, &tmpvar);
+ if (tmpvar == RESYNC_MARKER)
+ {
+ BitstreamByteAlignNoForceStuffing(stream);
+ PV_BitstreamFlushBits(stream, 17);
+ if (!BitstreamRead1Bits(stream))
+ {
+ return PV_FAIL;
+ }
+ *next_MB = BitstreamReadBits16(stream, video->nBitsForMBID);
+ if (*next_MB >= nTotalMB) /* fix 04/05/01 */
+ {
+ *next_MB = video->mbnum + 1;
+ if (*next_MB >= nTotalMB) /* this check is needed */
+ *next_MB = nTotalMB - 1;
+ }
+ /* we will not parse sebp2 for large pictures 3GPP */
+ quantizer = (int16) BitstreamReadBits16(stream, 5);
+ if (quantizer == 0) return PV_FAIL;
+
+ currVop->quantizer = quantizer;
+ if (!BitstreamRead1Bits(stream))
+ {
+ return PV_FAIL;
+ }
+ currVop->gobFrameID = (int) BitstreamReadBits16(stream, 2);
+ }
+ else
+ {
+ status = BitstreamCheckEndBuffer(stream); /* return end_of_VOP 03/30/01 */
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+ PV_BitstreamShowBitsByteAlign(stream, SHORT_VIDEO_START_MARKER_LENGTH, &tmpvar);
+
+ if (tmpvar == SHORT_VIDEO_START_MARKER)
+ {
+ /* we don't have to check for legal stuffing here. 05/08/2000 */
+ return PV_END_OF_VOP;
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+ return PV_SUCCESS;
+}
+#endif
+
diff --git a/media/codecs/m4v_h263/dec/src/post_filter.cpp b/media/codecs/m4v_h263/dec/src/post_filter.cpp
new file mode 100644
index 0000000..37a03a0
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/post_filter.cpp
@@ -0,0 +1,439 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#include "mp4dec_lib.h"
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+#include "motion_comp.h"
+#include "mbtype_mode.h"
+const static int STRENGTH_tab[] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12};
+#endif
+
+
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+void H263_Deblock(uint8 *rec,
+ int width,
+ int height,
+ int16 *QP_store,
+ uint8 *mode,
+ int chr, int annex_T)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int i, j, k;
+ uint8 *rec_y;
+ int tmpvar;
+ int mbnum, strength, A_D, d1_2, d1, d2, A, B, C, D, b_size;
+ int d, offset, nMBPerRow, nMBPerCol, width2 = (width << 1);
+ /* MAKE SURE I-VOP INTRA MACROBLOCKS ARE SET TO NON-SKIPPED MODE*/
+ mbnum = 0;
+
+ if (chr)
+ {
+ nMBPerRow = width >> 3;
+ nMBPerCol = height >> 3;
+ b_size = 8;
+ }
+ else
+ {
+ nMBPerRow = width >> 4;
+ nMBPerCol = height >> 4;
+ b_size = 16;
+ }
+
+
+ /********************************* VERTICAL FILTERING ****************************/
+ /* vertical filtering of mid sections no need to check neighboring QP's etc */
+ if (!chr)
+ {
+ rec_y = rec + (width << 3);
+ for (i = 0; i < (height >> 4); i++)
+ {
+ for (j = 0; j < (width >> 4); j++)
+ {
+ if (mode[mbnum] != MODE_SKIPPED)
+ {
+ k = 16;
+ strength = STRENGTH_tab[QP_store[mbnum]];
+ while (k--)
+ {
+ A = *(rec_y - width2);
+ D = *(rec_y + width);
+ A_D = A - D;
+ C = *rec_y;
+ B = *(rec_y - width);
+ d = (((C - B) << 2) + A_D);
+
+ if (d < 0)
+ {
+ d1 = -(-d >> 3);
+ if (d1 < -(strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 < -strength)
+ {
+ d1 = -d1 - (strength << 1);
+ }
+ d1_2 = -d1 >> 1;
+ }
+ else
+ {
+ d1 = d >> 3;
+ if (d1 > (strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 > strength)
+ {
+ d1 = (strength << 1) - d1;
+ }
+ d1_2 = d1 >> 1;
+ }
+
+ if (A_D < 0)
+ {
+ d2 = -(-A_D >> 2);
+ if (d2 < -d1_2)
+ {
+ d2 = -d1_2;
+ }
+ }
+ else
+ {
+ d2 = A_D >> 2;
+ if (d2 > d1_2)
+ {
+ d2 = d1_2;
+ }
+ }
+
+ *(rec_y - width2) = A - d2;
+ tmpvar = B + d1;
+ CLIP_RESULT(tmpvar)
+ *(rec_y - width) = tmpvar;
+ tmpvar = C - d1;
+ CLIP_RESULT(tmpvar)
+ *rec_y = tmpvar;
+ *(rec_y + width) = D + d2;
+ rec_y++;
+ }
+ }
+ else
+ {
+ rec_y += b_size;
+ }
+ mbnum++;
+ }
+ rec_y += (15 * width);
+
+ }
+ }
+
+ /* VERTICAL boundary blocks */
+
+
+ rec_y = rec + width * b_size;
+
+ mbnum = nMBPerRow;
+ for (i = 0; i < nMBPerCol - 1; i++)
+ {
+ for (j = 0; j < nMBPerRow; j++)
+ {
+ if (mode[mbnum] != MODE_SKIPPED || mode[mbnum - nMBPerRow] != MODE_SKIPPED)
+ {
+ k = b_size;
+ if (mode[mbnum] != MODE_SKIPPED)
+ {
+ strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum]] : QP_store[mbnum])];
+ }
+ else
+ {
+ strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum - nMBPerRow]] : QP_store[mbnum - nMBPerRow])];
+ }
+
+ while (k--)
+ {
+ A = *(rec_y - width2);
+ D = *(rec_y + width);
+ A_D = A - D;
+ C = *rec_y;
+ B = *(rec_y - width);
+ d = (((C - B) << 2) + A_D);
+
+ if (d < 0)
+ {
+ d1 = -(-d >> 3);
+ if (d1 < -(strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 < -strength)
+ {
+ d1 = -d1 - (strength << 1);
+ }
+ d1_2 = -d1 >> 1;
+ }
+ else
+ {
+ d1 = d >> 3;
+ if (d1 > (strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 > strength)
+ {
+ d1 = (strength << 1) - d1;
+ }
+ d1_2 = d1 >> 1;
+ }
+
+ if (A_D < 0)
+ {
+ d2 = -(-A_D >> 2);
+ if (d2 < -d1_2)
+ {
+ d2 = -d1_2;
+ }
+ }
+ else
+ {
+ d2 = A_D >> 2;
+ if (d2 > d1_2)
+ {
+ d2 = d1_2;
+ }
+ }
+
+ *(rec_y - width2) = A - d2;
+ tmpvar = B + d1;
+ CLIP_RESULT(tmpvar)
+ *(rec_y - width) = tmpvar;
+ tmpvar = C - d1;
+ CLIP_RESULT(tmpvar)
+ *rec_y = tmpvar;
+ *(rec_y + width) = D + d2;
+ rec_y++;
+ }
+ }
+ else
+ {
+ rec_y += b_size;
+ }
+ mbnum++;
+ }
+ rec_y += ((b_size - 1) * width);
+
+ }
+
+
+ /***************************HORIZONTAL FILTERING ********************************************/
+ mbnum = 0;
+ /* HORIZONTAL INNER */
+ if (!chr)
+ {
+ rec_y = rec + 8;
+ offset = width * b_size - b_size;
+
+ for (i = 0; i < nMBPerCol; i++)
+ {
+ for (j = 0; j < nMBPerRow; j++)
+ {
+ if (mode[mbnum] != MODE_SKIPPED)
+ {
+ k = 16;
+ strength = STRENGTH_tab[QP_store[mbnum]];
+ while (k--)
+ {
+ A = *(rec_y - 2);
+ D = *(rec_y + 1);
+ A_D = A - D;
+ C = *rec_y;
+ B = *(rec_y - 1);
+ d = (((C - B) << 2) + A_D);
+
+ if (d < 0)
+ {
+ d1 = -(-d >> 3);
+ if (d1 < -(strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 < -strength)
+ {
+ d1 = -d1 - (strength << 1);
+ }
+ d1_2 = -d1 >> 1;
+ }
+ else
+ {
+ d1 = d >> 3;
+ if (d1 > (strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 > strength)
+ {
+ d1 = (strength << 1) - d1;
+ }
+ d1_2 = d1 >> 1;
+ }
+
+ if (A_D < 0)
+ {
+ d2 = -(-A_D >> 2);
+ if (d2 < -d1_2)
+ {
+ d2 = -d1_2;
+ }
+ }
+ else
+ {
+ d2 = A_D >> 2;
+ if (d2 > d1_2)
+ {
+ d2 = d1_2;
+ }
+ }
+
+ *(rec_y - 2) = A - d2;
+ tmpvar = B + d1;
+ CLIP_RESULT(tmpvar)
+ *(rec_y - 1) = tmpvar;
+ tmpvar = C - d1;
+ CLIP_RESULT(tmpvar)
+ *rec_y = tmpvar;
+ *(rec_y + 1) = D + d2;
+ rec_y += width;
+ }
+ rec_y -= offset;
+ }
+ else
+ {
+ rec_y += b_size;
+ }
+ mbnum++;
+ }
+ rec_y += (15 * width);
+
+ }
+ }
+
+
+
+ /* HORIZONTAL EDGE */
+ rec_y = rec + b_size;
+ offset = width * b_size - b_size;
+ mbnum = 1;
+ for (i = 0; i < nMBPerCol; i++)
+ {
+ for (j = 0; j < nMBPerRow - 1; j++)
+ {
+ if (mode[mbnum] != MODE_SKIPPED || mode[mbnum-1] != MODE_SKIPPED)
+ {
+ k = b_size;
+ if (mode[mbnum] != MODE_SKIPPED)
+ {
+ strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum]] : QP_store[mbnum])];
+ }
+ else
+ {
+ strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum - 1]] : QP_store[mbnum - 1])];
+ }
+
+ while (k--)
+ {
+ A = *(rec_y - 2);
+ D = *(rec_y + 1);
+ A_D = A - D;
+ C = *rec_y;
+ B = *(rec_y - 1);
+ d = (((C - B) << 2) + A_D);
+
+ if (d < 0)
+ {
+ d1 = -(-d >> 3);
+ if (d1 < -(strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 < -strength)
+ {
+ d1 = -d1 - (strength << 1);
+ }
+ d1_2 = -d1 >> 1;
+ }
+ else
+ {
+ d1 = d >> 3;
+ if (d1 > (strength << 1))
+ {
+ d1 = 0;
+ }
+ else if (d1 > strength)
+ {
+ d1 = (strength << 1) - d1;
+ }
+ d1_2 = d1 >> 1;
+ }
+
+ if (A_D < 0)
+ {
+ d2 = -(-A_D >> 2);
+ if (d2 < -d1_2)
+ {
+ d2 = -d1_2;
+ }
+ }
+ else
+ {
+ d2 = A_D >> 2;
+ if (d2 > d1_2)
+ {
+ d2 = d1_2;
+ }
+ }
+
+ *(rec_y - 2) = A - d2;
+ tmpvar = B + d1;
+ CLIP_RESULT(tmpvar)
+ *(rec_y - 1) = tmpvar;
+ tmpvar = C - d1;
+ CLIP_RESULT(tmpvar)
+ *rec_y = tmpvar;
+ *(rec_y + 1) = D + d2;
+ rec_y += width;
+ }
+ rec_y -= offset;
+ }
+ else
+ {
+ rec_y += b_size;
+ }
+ mbnum++;
+ }
+ rec_y += ((width * (b_size - 1)) + b_size);
+ mbnum++;
+ }
+
+ return;
+}
+#endif
+
diff --git a/media/codecs/m4v_h263/dec/src/post_proc.h b/media/codecs/m4v_h263/dec/src/post_proc.h
new file mode 100644
index 0000000..a8ab37f
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/post_proc.h
@@ -0,0 +1,75 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef post_proc_H
+#define post_proc_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4dec_lib.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define UPDATE_PV_MAXPV_MIN(p,max,min) if ((p) > (max)) (max)=(p); else if ((p) < (min)) (min) = (p);
+
+#define INDEX(x,thr) (((x)>=(thr))?1:0)
+#define BLKSIZE 8
+#define MBSIZE 16
+#define DERING_THR 16
+
+/* version for fast Deblock filtering*/
+#define KTh 4 /*threshold for soft filtering*/
+#define KThH 4 /*threshold for hard filtering */
+
+#define NoMMX
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/m4v_h263/dec/src/pvdec_api.cpp b/media/codecs/m4v_h263/dec/src/pvdec_api.cpp
new file mode 100644
index 0000000..b0828e4
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/pvdec_api.cpp
@@ -0,0 +1,1687 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#define LOG_TAG "pvdec_api"
+#include <log/log.h>
+#include "mp4dec_lib.h"
+#include "vlc_decode.h"
+#include "bitstream.h"
+
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffff
+#endif
+
+#ifndef SIZE_MAX
+#define SIZE_MAX ((size_t) -1)
+#endif
+
+#define OSCL_DISABLE_WARNING_CONDITIONAL_IS_CONSTANT
+
+#ifdef DEC_INTERNAL_MEMORY_OPT
+#define QCIF_MBS 99
+#define QCIF_BS (4*QCIF_MBS)
+#define QCIF_MB_ROWS 11
+extern uint8 IMEM_sliceNo[QCIF_MBS];
+extern uint8 IMEM_acPredFlag[QCIF_MBS];
+extern uint8 IMEM_headerInfo_Mode[QCIF_MBS];
+extern uint8 IMEM_headerInfo_CBP[QCIF_MBS];
+extern int IMEM_headerInfo_QPMB[QCIF_MBS];
+extern MacroBlock IMEM_mblock;
+extern MOT IMEM_motX[QCIF_BS];
+extern MOT IMEM_motY[QCIF_BS];
+extern BitstreamDecVideo IMEM_BitstreamDecVideo[4];
+extern typeDCStore IMEM_predDC[QCIF_MBS];
+extern typeDCACStore IMEM_predDCAC_col[QCIF_MB_ROWS+1];
+
+extern VideoDecData IMEM_VideoDecData[1];
+extern Vop IMEM_currVop[1];
+extern Vop IMEM_prevVop[1];
+extern PIXEL IMEM_currVop_yChan[QCIF_MBS*128*3];
+extern PIXEL IMEM_prevVop_yChan[QCIF_MBS*128*3];
+extern uint8 IMEM_pstprcTypCur[6*QCIF_MBS];
+extern uint8 IMEM_pstprcTypPrv[6*QCIF_MBS];
+
+
+extern Vop IMEM_vopHEADER[2];
+extern Vol IMEM_VOL[2];
+extern Vop IMEM_vopHeader[2][1];
+extern Vol IMEM_vol[2][1];
+
+#endif
+
+/* ======================================================================== */
+/* Function : PVInitVideoDecoder() */
+/* Date : 04/11/2000, 08/29/2000 */
+/* Purpose : Initialization of the MPEG-4 video decoder library. */
+/* The return type is Bool instead of PV_STATUS because */
+/* we don't want to expose PV_STATUS to (outside) programmers */
+/* that use our decoder library SDK. */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVInitVideoDecoder(VideoDecControls *decCtrl, uint8 *volbuf[],
+ int32 *volbuf_size, int nLayers, int width, int height, MP4DecodingMode mode)
+{
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+ Bool status = PV_TRUE;
+ int idx;
+ BitstreamDecVideo *stream;
+
+
+ oscl_memset(decCtrl, 0, sizeof(VideoDecControls)); /* fix a size bug. 03/28/2001 */
+ decCtrl->nLayers = nLayers;
+ for (idx = 0; idx < nLayers; idx++)
+ {
+ decCtrl->volbuf[idx] = volbuf[idx];
+ decCtrl->volbuf_size[idx] = volbuf_size[idx];
+ }
+
+ /* memory allocation & initialization */
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ video = IMEM_VideoDecData;
+#else
+ video = (VideoDecData *) oscl_malloc(sizeof(VideoDecData));
+#endif
+ if (video != NULL)
+ {
+ oscl_memset(video, 0, sizeof(VideoDecData));
+ video->memoryUsage = sizeof(VideoDecData);
+ video->numberOfLayers = nLayers;
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ video->vol = (Vol **) IMEM_VOL;
+#else
+ if ((size_t)nLayers > SIZE_MAX / sizeof(Vol *)) {
+ status = PV_FALSE;
+ oscl_free(video);
+ goto fail;
+ }
+
+ video->vol = (Vol **) oscl_malloc(nLayers * sizeof(Vol *));
+#endif
+ if (video->vol == NULL) status = PV_FALSE;
+ video->memoryUsage += nLayers * sizeof(Vol *);
+
+ /* be sure not to leak any previous state */
+ PVCleanUpVideoDecoder(decCtrl);
+ /* we need to setup this pointer for the application to */
+ /* pass it around. */
+ decCtrl->videoDecoderData = (void *) video;
+ video->videoDecControls = decCtrl; /* yes. we have a cyclic */
+ /* references here :) */
+
+ /* Allocating Vop space, this has to change when we add */
+ /* spatial scalability to the decoder */
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ video->currVop = IMEM_currVop;
+ if (video->currVop == NULL) status = PV_FALSE;
+ else oscl_memset(video->currVop, 0, sizeof(Vop));
+ video->prevVop = IMEM_prevVop;
+ if (video->prevVop == NULL) status = PV_FALSE;
+ else oscl_memset(video->prevVop, 0, sizeof(Vop));
+ video->memoryUsage += (sizeof(Vop) * 2);
+ video->vopHeader = (Vop **) IMEM_vopHEADER;
+#else
+
+ video->currVop = (Vop *) oscl_malloc(sizeof(Vop));
+ if (video->currVop == NULL) status = PV_FALSE;
+ else oscl_memset(video->currVop, 0, sizeof(Vop));
+ video->prevVop = (Vop *) oscl_malloc(sizeof(Vop));
+ if (video->prevVop == NULL) status = PV_FALSE;
+ else oscl_memset(video->prevVop, 0, sizeof(Vop));
+ video->memoryUsage += (sizeof(Vop) * 2);
+
+ if ((size_t)nLayers > SIZE_MAX / sizeof(Vop *)) {
+ status = PV_FALSE;
+ goto fail;
+ }
+
+ video->vopHeader = (Vop **) oscl_malloc(sizeof(Vop *) * nLayers);
+#endif
+ if (video->vopHeader == NULL) status = PV_FALSE;
+ else oscl_memset(video->vopHeader, 0, sizeof(Vop *)*nLayers);
+ video->memoryUsage += (sizeof(Vop *) * nLayers);
+
+ video->initialized = PV_FALSE;
+ /* Decode the header to get all information to allocate data */
+ if (status == PV_TRUE)
+ {
+ /* initialize decoded frame counter. 04/24/2001 */
+ video->frame_idx = -1;
+
+
+ for (idx = 0; idx < nLayers; idx++)
+ {
+
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ video->vopHeader[idx] = IMEM_vopHeader[idx];
+#else
+ video->vopHeader[idx] = (Vop *) oscl_malloc(sizeof(Vop));
+#endif
+ if (video->vopHeader[idx] == NULL)
+ {
+ status = PV_FALSE;
+ break;
+ }
+ else
+ {
+ oscl_memset(video->vopHeader[idx], 0, sizeof(Vop));
+ video->vopHeader[idx]->timeStamp = 0;
+ video->memoryUsage += (sizeof(Vop));
+ }
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ video->vol[idx] = IMEM_vol[idx];
+ video->memoryUsage += sizeof(Vol);
+ if (video->vol[idx] == NULL) status = PV_FALSE;
+ else oscl_memset(video->vol[idx], 0, sizeof(Vol));
+ stream = IMEM_BitstreamDecVideo;
+#else
+ video->vol[idx] = (Vol *) oscl_malloc(sizeof(Vol));
+ if (video->vol[idx] == NULL)
+ {
+ status = PV_FALSE;
+ break;
+ }
+ else
+ {
+ video->memoryUsage += sizeof(Vol);
+ oscl_memset(video->vol[idx], 0, sizeof(Vol));
+ }
+
+ stream = (BitstreamDecVideo *) oscl_malloc(sizeof(BitstreamDecVideo));
+#endif
+ video->memoryUsage += sizeof(BitstreamDecVideo);
+ if (stream == NULL)
+ {
+ status = PV_FALSE;
+ break;
+ }
+ else
+ {
+ int32 buffer_size;
+ oscl_memset(stream, 0, sizeof(BitstreamDecVideo));
+ if ((buffer_size = BitstreamOpen(stream, idx)) < 0)
+ {
+ mp4dec_log("InitVideoDecoder(): Can't allocate bitstream buffer.\n");
+ status = PV_FALSE;
+ break;
+ }
+ video->memoryUsage += buffer_size;
+ video->vol[idx]->bitstream = stream;
+ video->vol[idx]->volID = idx;
+ video->vol[idx]->timeInc_offset = 0; /* 11/12/01 */
+ video->vlcDecCoeffIntra = &VlcDecTCOEFShortHeader;
+ video->vlcDecCoeffInter = &VlcDecTCOEFShortHeader;
+ if (mode == MPEG4_MODE)
+ {
+ /* Set up VOL header bitstream for frame-based decoding. 08/30/2000 */
+ BitstreamReset(stream, decCtrl->volbuf[idx], decCtrl->volbuf_size[idx]);
+
+ switch (DecodeVOLHeader(video, idx))
+ {
+ case PV_SUCCESS :
+ if (status == PV_TRUE)
+ status = PV_TRUE; /* we want to make sure that if first layer is bad, second layer is good return PV_FAIL */
+ else
+ status = PV_FALSE;
+ break;
+#ifdef PV_TOLERATE_VOL_ERRORS
+ case PV_BAD_VOLHEADER:
+ status = PV_TRUE;
+ break;
+#endif
+ default :
+ status = PV_FALSE;
+ break;
+ }
+
+ }
+ else
+ {
+ video->shortVideoHeader = PV_TRUE;
+ }
+
+ if (video->shortVideoHeader == PV_TRUE)
+ {
+ mode = H263_MODE;
+ /* Set max width and height. In H.263 mode, we use */
+ /* volbuf_size[0] to pass in width and volbuf_size[1] */
+ /* to pass in height. 04/23/2001 */
+ video->prevVop->temporalRef = 0; /* 11/12/01 */
+ /* Compute some convenience variables: 04/23/2001 */
+ video->vol[idx]->quantType = 0;
+ video->vol[idx]->quantPrecision = 5;
+ video->vol[idx]->errorResDisable = 1;
+ video->vol[idx]->dataPartitioning = 0;
+ video->vol[idx]->useReverseVLC = 0;
+ video->intra_acdcPredDisable = 1;
+ video->vol[idx]->scalability = 0;
+
+ video->displayWidth = width;
+ video->displayHeight = height;
+ video->width = (width + 15) & -16;
+ video->height = (height + 15) & -16;
+ video->size = (int32)video->width * video->height;
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ video->modified_quant = 0;
+ video->advanced_INTRA = 0;
+ video->deblocking = 0;
+ video->slice_structure = 0;
+#endif
+ }
+
+ }
+ }
+
+ }
+ if (status != PV_FALSE)
+ {
+ status = PVAllocVideoData(decCtrl, width, height, nLayers);
+ video->initialized = PV_TRUE;
+ }
+ }
+ else
+ {
+ status = PV_FALSE;
+ }
+
+fail:
+ if (status == PV_FALSE) PVCleanUpVideoDecoder(decCtrl);
+
+ return status;
+}
+
+Bool PVAllocVideoData(VideoDecControls *decCtrl, int width, int height, int nLayers)
+{
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+ Bool status = PV_TRUE;
+ int nTotalMB;
+ int nMBPerRow;
+ int32 size;
+
+ if (video->shortVideoHeader == PV_TRUE)
+ {
+ video->displayWidth = width;
+ video->displayHeight = height;
+ video->width = (width + 15) & -16;
+ video->height = (height + 15) & -16;
+
+ video->nMBPerRow =
+ video->nMBinGOB = video->width / MB_SIZE;
+ video->nMBPerCol =
+ video->nGOBinVop = video->height / MB_SIZE;
+ video->nTotalMB =
+ video->nMBPerRow * video->nMBPerCol;
+ }
+
+ if (((uint64_t)video->width * video->height) > (uint64_t)INT32_MAX / sizeof(PIXEL)) {
+ return PV_FALSE;
+ }
+
+ size = (int32)sizeof(PIXEL) * video->width * video->height;
+#ifdef PV_MEMORY_POOL
+ decCtrl->size = size;
+#else
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ video->currVop->yChan = IMEM_currVop_yChan; /* Allocate memory for all VOP OKA 3/2/1*/
+ if (video->currVop->yChan == NULL) status = PV_FALSE;
+ else {
+ video->currVop->uChan = video->currVop->yChan + size;
+ video->currVop->vChan = video->currVop->uChan + (size >> 2);
+ }
+
+ video->prevVop->yChan = IMEM_prevVop_yChan; /* Allocate memory for all VOP OKA 3/2/1*/
+ if (video->prevVop->yChan == NULL) status = PV_FALSE;
+ else {
+ video->prevVop->uChan = video->prevVop->yChan + size;
+ video->prevVop->vChan = video->prevVop->uChan + (size >> 2);
+ }
+#else
+ if (size > INT32_MAX / 3) {
+ return PV_FALSE;
+ }
+ video->currVop->yChan = (PIXEL *) oscl_malloc(size * 3 / 2); /* Allocate memory for all VOP OKA 3/2/1*/
+ if (video->currVop->yChan == NULL) status = PV_FALSE;
+ else {
+ video->currVop->uChan = video->currVop->yChan + size;
+ video->currVop->vChan = video->currVop->uChan + (size >> 2);
+ }
+ video->prevVop->yChan = (PIXEL *) oscl_malloc(size * 3 / 2); /* Allocate memory for all VOP OKA 3/2/1*/
+ if (video->prevVop->yChan == NULL) status = PV_FALSE;
+ else {
+ video->prevVop->uChan = video->prevVop->yChan + size;
+ video->prevVop->vChan = video->prevVop->uChan + (size >> 2);
+ }
+#endif
+ video->memoryUsage += (size * 3);
+#endif // MEMORY_POOL
+ /* Note that baseVop, enhcVop is only used to hold enhancement */
+ /* layer header information. 05/04/2000 */
+ if (nLayers > 1)
+ {
+ video->prevEnhcVop = (Vop *) oscl_malloc(sizeof(Vop));
+ video->memoryUsage += (sizeof(Vop));
+ if (video->prevEnhcVop == NULL)
+ {
+ status = PV_FALSE;
+ }
+ else
+ {
+ oscl_memset(video->prevEnhcVop, 0, sizeof(Vop));
+#ifndef PV_MEMORY_POOL
+ if (size > INT32_MAX / 3) {
+ return PV_FALSE;
+ }
+
+ video->prevEnhcVop->yChan = (PIXEL *) oscl_malloc(size * 3 / 2); /* Allocate memory for all VOP OKA 3/2/1*/
+ if (video->prevEnhcVop->yChan == NULL) status = PV_FALSE;
+ else {
+ video->prevEnhcVop->uChan = video->prevEnhcVop->yChan + size;
+ video->prevEnhcVop->vChan = video->prevEnhcVop->uChan + (size >> 2);
+ }
+ video->memoryUsage += (3 * size / 2);
+#endif
+ }
+ }
+
+ /* Allocating space for slices, AC prediction flag, and */
+ /* AC/DC prediction storage */
+ nTotalMB = video->nTotalMB;
+ nMBPerRow = video->nMBPerRow;
+
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ video->sliceNo = (uint8 *)(IMEM_sliceNo);
+ if (video->sliceNo == NULL) status = PV_FALSE;
+ video->memoryUsage += nTotalMB;
+ video->acPredFlag = (uint8 *)(IMEM_acPredFlag);
+ if (video->acPredFlag == NULL) status = PV_FALSE;
+ video->memoryUsage += (nTotalMB);
+ video->predDC = (typeDCStore *)(IMEM_predDC);
+ if (video->predDC == NULL) status = PV_FALSE;
+ video->memoryUsage += (nTotalMB * sizeof(typeDCStore));
+ video->predDCAC_col = (typeDCACStore *)(IMEM_predDCAC_col);
+ if (video->predDCAC_col == NULL) status = PV_FALSE;
+ video->memoryUsage += ((nMBPerRow + 1) * sizeof(typeDCACStore));
+ video->predDCAC_row = video->predDCAC_col + 1;
+ video->headerInfo.Mode = (uint8 *)(IMEM_headerInfo_Mode);
+ if (video->headerInfo.Mode == NULL) status = PV_FALSE;
+ video->memoryUsage += nTotalMB;
+ video->headerInfo.CBP = (uint8 *)(IMEM_headerInfo_CBP);
+ if (video->headerInfo.CBP == NULL) status = PV_FALSE;
+ video->memoryUsage += nTotalMB;
+ video->QPMB = (int *)(IMEM_headerInfo_QPMB);
+ if (video->QPMB == NULL) status = PV_FALSE;
+ video->memoryUsage += (nTotalMB * sizeof(int));
+ video->mblock = &IMEM_mblock;
+ if (video->mblock == NULL) status = PV_FALSE;
+ oscl_memset(video->mblock->block, 0, sizeof(int16)*6*NCOEFF_BLOCK); // Aug 23,2005
+
+ video->memoryUsage += sizeof(MacroBlock);
+ video->motX = (MOT *)(IMEM_motX);
+ if (video->motX == NULL) status = PV_FALSE;
+ video->motY = (MOT *)(IMEM_motY);
+ if (video->motY == NULL) status = PV_FALSE;
+ video->memoryUsage += (sizeof(MOT) * 8 * nTotalMB);
+#else
+ video->sliceNo = (uint8 *) oscl_malloc(nTotalMB);
+ if (video->sliceNo == NULL) status = PV_FALSE;
+ else oscl_memset(video->sliceNo, 0, nTotalMB);
+ video->memoryUsage += nTotalMB;
+
+ video->acPredFlag = (uint8 *) oscl_malloc(nTotalMB * sizeof(uint8));
+ if (video->acPredFlag == NULL) status = PV_FALSE;
+ else oscl_memset(video->acPredFlag, 0, nTotalMB * sizeof(uint8));
+ video->memoryUsage += (nTotalMB);
+
+ if ((size_t)nTotalMB > SIZE_MAX / sizeof(typeDCStore)) {
+ return PV_FALSE;
+ }
+ video->predDC = (typeDCStore *) oscl_malloc(nTotalMB * sizeof(typeDCStore));
+ if (video->predDC == NULL) status = PV_FALSE;
+ else oscl_memset(video->predDC, 0, nTotalMB * sizeof(typeDCStore));
+ video->memoryUsage += (nTotalMB * sizeof(typeDCStore));
+
+ if (nMBPerRow > INT32_MAX - 1
+ || (size_t)(nMBPerRow + 1) > SIZE_MAX / sizeof(typeDCACStore)) {
+ return PV_FALSE;
+ }
+ video->predDCAC_col = (typeDCACStore *) oscl_malloc((nMBPerRow + 1) * sizeof(typeDCACStore));
+ if (video->predDCAC_col == NULL) status = PV_FALSE;
+ else oscl_memset(video->predDCAC_col, 0, (nMBPerRow + 1) * sizeof(typeDCACStore));
+ video->memoryUsage += ((nMBPerRow + 1) * sizeof(typeDCACStore));
+
+ /* element zero will be used for storing vertical (col) AC coefficients */
+ /* the rest will be used for storing horizontal (row) AC coefficients */
+ video->predDCAC_row = video->predDCAC_col + 1; /* ACDC */
+
+ /* Allocating HeaderInfo structure & Quantizer array */
+ video->headerInfo.Mode = (uint8 *) oscl_malloc(nTotalMB);
+ if (video->headerInfo.Mode == NULL) status = PV_FALSE;
+ else oscl_memset(video->headerInfo.Mode, 0, nTotalMB);
+ video->memoryUsage += nTotalMB;
+ video->headerInfo.CBP = (uint8 *) oscl_malloc(nTotalMB);
+ if (video->headerInfo.CBP == NULL) status = PV_FALSE;
+ else oscl_memset (video->headerInfo.CBP, 0, nTotalMB);
+ video->memoryUsage += nTotalMB;
+
+ if ((size_t)nTotalMB > SIZE_MAX / sizeof(int16)) {
+ return PV_FALSE;
+ }
+ video->QPMB = (int16 *) oscl_malloc(nTotalMB * sizeof(int16));
+ if (video->QPMB == NULL) status = PV_FALSE;
+ else memset(video->QPMB, 0x0, nTotalMB * sizeof(int16));
+ video->memoryUsage += (nTotalMB * sizeof(int));
+
+ /* Allocating macroblock space */
+ video->mblock = (MacroBlock *) oscl_malloc(sizeof(MacroBlock));
+ if (video->mblock == NULL)
+ {
+ status = PV_FALSE;
+ }
+ else
+ {
+ oscl_memset(video->mblock->block, 0, sizeof(int16)*6*NCOEFF_BLOCK); // Aug 23,2005
+
+ video->memoryUsage += sizeof(MacroBlock);
+ }
+ /* Allocating motion vector space */
+ if ((size_t)nTotalMB > SIZE_MAX / (sizeof(MOT) * 4)) {
+ return PV_FALSE;
+ }
+ video->motX = (MOT *) oscl_malloc(sizeof(MOT) * 4 * nTotalMB);
+ if (video->motX == NULL) status = PV_FALSE;
+ else memset(video->motX, 0, sizeof(MOT) * 4 * nTotalMB);
+ video->motY = (MOT *) oscl_malloc(sizeof(MOT) * 4 * nTotalMB);
+ if (video->motY == NULL) status = PV_FALSE;
+ else memset(video->motY, 0, sizeof(MOT) * 4 * nTotalMB);
+ video->memoryUsage += (sizeof(MOT) * 8 * nTotalMB);
+#endif
+
+
+ /* initialize the decoder library */
+ video->prevVop->predictionType = I_VOP;
+ video->prevVop->timeStamp = 0;
+#ifndef PV_MEMORY_POOL
+ oscl_memset(video->prevVop->yChan, 16, sizeof(uint8)*size); /* 10/31/01 */
+ oscl_memset(video->prevVop->uChan, 128, sizeof(uint8)*size / 2);
+
+ oscl_memset(video->currVop->yChan, 0, sizeof(uint8)*size*3 / 2);
+ if (nLayers > 1)
+ {
+ oscl_memset(video->prevEnhcVop->yChan, 0, sizeof(uint8)*size*3 / 2);
+ video->prevEnhcVop->timeStamp = 0;
+ }
+ video->concealFrame = video->prevVop->yChan; /* 07/07/2001 */
+ decCtrl->outputFrame = video->prevVop->yChan; /* 06/19/2002 */
+#endif
+
+ /* always start from base layer */
+ video->currLayer = 0;
+ return status;
+}
+
+/* ======================================================================== */
+/* Function : PVResetVideoDecoder() */
+/* Date : 01/14/2002 */
+/* Purpose : Reset video timestamps */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* ======================================================================== */
+Bool PVResetVideoDecoder(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+ int idx;
+
+ for (idx = 0; idx < decCtrl->nLayers; idx++)
+ {
+ video->vopHeader[idx]->timeStamp = 0;
+ }
+ video->prevVop->timeStamp = 0;
+ if (decCtrl->nLayers > 1)
+ video->prevEnhcVop->timeStamp = 0;
+
+ oscl_memset(video->mblock->block, 0, sizeof(int16)*6*NCOEFF_BLOCK); // Aug 23,2005
+
+ return PV_TRUE;
+}
+
+
+/* ======================================================================== */
+/* Function : PVCleanUpVideoDecoder() */
+/* Date : 04/11/2000, 08/29/2000 */
+/* Purpose : Cleanup of the MPEG-4 video decoder library. */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVCleanUpVideoDecoder(VideoDecControls *decCtrl)
+{
+ int idx;
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+#ifdef DEC_INTERNAL_MEMORY_OPT
+ if (video)
+ {
+
+ video->acPredFlag = NULL;
+ video->sliceNo = NULL;
+ video->motX = NULL;
+ video->motY = NULL;
+ video->mblock = NULL;
+ video->QPMB = NULL;
+ video->predDC = NULL;
+ video->predDCAC_row = NULL;
+ video->predDCAC_col = NULL;
+ video->headerInfo.Mode = NULL;
+ video->headerInfo.CBP = NULL;
+ if (video->numberOfLayers > 1)
+ {
+ if (video->prevEnhcVop)
+ {
+ video->prevEnhcVop->uChan = NULL;
+ video->prevEnhcVop->vChan = NULL;
+ if (video->prevEnhcVop->yChan) oscl_free(video->prevEnhcVop->yChan);
+ oscl_free(video->prevEnhcVop);
+ }
+ }
+ if (video->currVop)
+ {
+ video->currVop->uChan = NULL;
+ video->currVop->vChan = NULL;
+ if (video->currVop->yChan)
+ video->currVop->yChan = NULL;
+ video->currVop = NULL;
+ }
+ if (video->prevVop)
+ {
+ video->prevVop->uChan = NULL;
+ video->prevVop->vChan = NULL;
+ if (video->prevVop->yChan)
+ video->prevVop->yChan = NULL;
+ video->prevVop = NULL;
+ }
+
+ if (video->vol)
+ {
+ for (idx = 0; idx < video->numberOfLayers; idx++)
+ {
+ if (video->vol[idx])
+ {
+ BitstreamClose(video->vol[idx]->bitstream);
+ video->vol[idx]->bitstream = NULL;
+ video->vol[idx] = NULL;
+ }
+ video->vopHeader[idx] = NULL;
+
+ }
+ video->vol = NULL;
+ video->vopHeader = NULL;
+ }
+
+ video = NULL;
+ decCtrl->videoDecoderData = NULL;
+ }
+
+#else
+
+ if (video)
+ {
+ if (video->predDC) oscl_free(video->predDC);
+ video->predDCAC_row = NULL;
+ if (video->predDCAC_col) oscl_free(video->predDCAC_col);
+ if (video->motX) oscl_free(video->motX);
+ if (video->motY) oscl_free(video->motY);
+ if (video->mblock) oscl_free(video->mblock);
+ if (video->QPMB) oscl_free(video->QPMB);
+ if (video->headerInfo.Mode) oscl_free(video->headerInfo.Mode);
+ if (video->headerInfo.CBP) oscl_free(video->headerInfo.CBP);
+ if (video->sliceNo) oscl_free(video->sliceNo);
+ if (video->acPredFlag) oscl_free(video->acPredFlag);
+
+ if (video->numberOfLayers > 1)
+ {
+ if (video->prevEnhcVop)
+ {
+ video->prevEnhcVop->uChan = NULL;
+ video->prevEnhcVop->vChan = NULL;
+ if (video->prevEnhcVop->yChan) oscl_free(video->prevEnhcVop->yChan);
+ oscl_free(video->prevEnhcVop);
+ }
+ }
+ if (video->currVop)
+ {
+
+#ifndef PV_MEMORY_POOL
+ video->currVop->uChan = NULL;
+ video->currVop->vChan = NULL;
+ if (video->currVop->yChan)
+ oscl_free(video->currVop->yChan);
+#endif
+ oscl_free(video->currVop);
+ }
+ if (video->prevVop)
+ {
+#ifndef PV_MEMORY_POOL
+ video->prevVop->uChan = NULL;
+ video->prevVop->vChan = NULL;
+ if (video->prevVop->yChan)
+ oscl_free(video->prevVop->yChan);
+#endif
+ oscl_free(video->prevVop);
+ }
+
+ if (video->vol)
+ {
+ for (idx = 0; idx < video->numberOfLayers; idx++)
+ {
+ if (video->vol[idx])
+ {
+ if (video->vol[idx]->bitstream)
+ {
+ BitstreamClose(video->vol[idx]->bitstream);
+ oscl_free(video->vol[idx]->bitstream);
+ }
+ oscl_free(video->vol[idx]);
+ }
+
+ }
+ oscl_free(video->vol);
+ }
+
+ for (idx = 0; idx < video->numberOfLayers; idx++)
+ {
+ if (video->vopHeader[idx]) oscl_free(video->vopHeader[idx]);
+ }
+
+ if (video->vopHeader) oscl_free(video->vopHeader);
+
+ oscl_free(video);
+ decCtrl->videoDecoderData = NULL;
+ }
+#endif
+ return PV_TRUE;
+}
+/* ======================================================================== */
+/* Function : PVGetVideoDimensions() */
+/* Date : 040505 */
+/* Purpose : */
+/* In/out : */
+/* Return : the display_width and display_height of */
+/* the frame in the current layer. */
+/* Note : This is not a macro or inline function because we do */
+/* not want to expose our internal data structure. */
+/* Modified : */
+/* ======================================================================== */
+OSCL_EXPORT_REF void PVGetVideoDimensions(VideoDecControls *decCtrl, int32 *display_width, int32 *display_height)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ *display_width = video->displayWidth;
+ *display_height = video->displayHeight;
+}
+
+OSCL_EXPORT_REF void PVGetBufferDimensions(VideoDecControls *decCtrl, int32 *width, int32 *height) {
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ *width = video->width;
+ *height = video->height;
+}
+
+/* ======================================================================== */
+/* Function : PVGetVideoTimeStamp() */
+/* Date : 04/27/2000, 08/29/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : current time stamp in millisecond. */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+uint32 PVGetVideoTimeStamp(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ return video->currTimestamp;
+}
+
+
+/* ======================================================================== */
+/* Function : PVSetPostProcType() */
+/* Date : 07/07/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : Set post-processing filter type. */
+/* Note : */
+/* Modified : . 08/29/2000 changes the name for consistency. */
+/* ======================================================================== */
+OSCL_EXPORT_REF void PVSetPostProcType(VideoDecControls *decCtrl, int mode)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ if (mode != 0) {
+ ALOGE("Post processing filters are not supported");
+ }
+ video->postFilterType = 0;
+}
+
+
+/* ======================================================================== */
+/* Function : PVGetDecBitrate() */
+/* Date : 08/23/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : This function returns the average bits per second. */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+int PVGetDecBitrate(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ int idx;
+ int32 sum = 0;
+
+ for (idx = 0; idx < BITRATE_AVERAGE_WINDOW; idx++)
+ {
+ sum += video->nBitsPerVop[idx];
+ }
+ sum = (sum * video->frameRate) / (10 * BITRATE_AVERAGE_WINDOW);
+ return (int) sum;
+}
+
+
+/* ======================================================================== */
+/* Function : PVGetDecFramerate() */
+/* Date : 08/23/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : This function returns the average frame per 10 second. */
+/* Note : The fps can be calculated by PVGetDecFramerate()/10 */
+/* Modified : */
+/* ======================================================================== */
+int PVGetDecFramerate(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+
+ return video->frameRate;
+}
+
+/* ======================================================================== */
+/* Function : PVGetOutputFrame() */
+/* Date : 05/07/2001 */
+/* Purpose : */
+/* In/out : */
+/* Return : This function returns the pointer to the output frame */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+uint8 *PVGetDecOutputFrame(VideoDecControls *decCtrl)
+{
+ return decCtrl->outputFrame;
+}
+
+/* ======================================================================== */
+/* Function : PVGetLayerID() */
+/* Date : 07/09/2001 */
+/* Purpose : */
+/* In/out : */
+/* Return : This function returns decoded frame layer id (BASE/ENHANCE) */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+int PVGetLayerID(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ return video->currLayer;
+}
+/* ======================================================================== */
+/* Function : PVGetDecMemoryUsage() */
+/* Date : 08/23/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : This function returns the amount of memory used. */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+int32 PVGetDecMemoryUsage(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ return video->memoryUsage;
+}
+
+
+/* ======================================================================== */
+/* Function : PVGetDecBitstreamMode() */
+/* Date : 08/23/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : This function returns the decoding mode of the baselayer */
+/* bitstream. */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+OSCL_EXPORT_REF MP4DecodingMode PVGetDecBitstreamMode(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ if (video->shortVideoHeader)
+ {
+ return H263_MODE;
+ }
+ else
+ {
+ return MPEG4_MODE;
+ }
+}
+
+
+/* ======================================================================== */
+/* Function : PVExtractVolHeader() */
+/* Date : 08/29/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : Extract vol header of the bitstream from buffer[]. */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+Bool PVExtractVolHeader(uint8 *video_buffer, uint8 *vol_header, int32 *vol_header_size)
+{
+ int idx = -1;
+ uint8 start_code_prefix[] = { 0x00, 0x00, 0x01 };
+ uint8 h263_prefix[] = { 0x00, 0x00, 0x80 };
+
+ if (oscl_memcmp(h263_prefix, video_buffer, 3) == 0) /* we have short header stream */
+ {
+ oscl_memcpy(vol_header, video_buffer, 32);
+ *vol_header_size = 32;
+ return TRUE;
+ }
+ else
+ {
+ if (oscl_memcmp(start_code_prefix, video_buffer, 3) ||
+ (video_buffer[3] != 0xb0 && video_buffer[3] >= 0x20)) return FALSE;
+
+ do
+ {
+ idx++;
+ while (oscl_memcmp(start_code_prefix, video_buffer + idx, 3))
+ {
+ idx++;
+ if (idx + 3 >= *vol_header_size) goto quit;
+ }
+ }
+ while (video_buffer[idx+3] != 0xb3 && video_buffer[idx+3] != 0xb6);
+
+ oscl_memcpy(vol_header, video_buffer, idx);
+ *vol_header_size = idx;
+ return TRUE;
+ }
+
+quit:
+ oscl_memcpy(vol_header, video_buffer, *vol_header_size);
+ return FALSE;
+}
+
+
+/* ======================================================================== */
+/* Function : PVLocateFrameHeader() */
+/* Date : 04/8/2005 */
+/* Purpose : */
+/* In/out : */
+/* Return : Return the offset to the first SC in the buffer */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+int32 PVLocateFrameHeader(uint8 *ptr, int32 size)
+{
+ int count = 0;
+ int32 i = size;
+
+ if (size < 1)
+ {
+ return 0;
+ }
+ while (i--)
+ {
+ if ((count > 1) && (*ptr == 0x01))
+ {
+ i += 2;
+ break;
+ }
+
+ if (*ptr++)
+ count = 0;
+ else
+ count++;
+ }
+ return (size - (i + 1));
+}
+
+
+/* ======================================================================== */
+/* Function : PVLocateH263FrameHeader() */
+/* Date : 04/8/2005 */
+/* Purpose : */
+/* In/out : */
+/* Return : Return the offset to the first SC in the buffer */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+int32 PVLocateH263FrameHeader(uint8 *ptr, int32 size)
+{
+ int count = 0;
+ int32 i = size;
+
+ if (size < 1)
+ {
+ return 0;
+ }
+
+ while (i--)
+ {
+ if ((count > 1) && ((*ptr & 0xFC) == 0x80))
+ {
+ i += 2;
+ break;
+ }
+
+ if (*ptr++)
+ count = 0;
+ else
+ count++;
+ }
+ return (size - (i + 1));
+}
+
+
+/* ======================================================================== */
+/* Function : PVDecodeVideoFrame() */
+/* Date : 08/29/2000 */
+/* Purpose : Decode one video frame and return a YUV-12 image. */
+/* In/out : */
+/* Return : */
+/* Note : */
+/* Modified : 04/17/2001 removed PV_EOS, PV_END_OF_BUFFER */
+/* : 08/22/2002 break up into 2 functions PVDecodeVopHeader and */
+/* PVDecodeVopBody */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVDecodeVideoFrame(VideoDecControls *decCtrl, uint8 *buffer[],
+ uint32 timestamp[], int32 buffer_size[], uint use_ext_timestamp[], uint8 *currYUV)
+{
+ PV_STATUS status = PV_FAIL;
+ VopHeaderInfo header_info;
+
+ status = (PV_STATUS)PVDecodeVopHeader(decCtrl, buffer, timestamp, buffer_size, &header_info, use_ext_timestamp, currYUV);
+ if (status != PV_TRUE)
+ return PV_FALSE;
+
+ if (PVDecodeVopBody(decCtrl, buffer_size) != PV_TRUE)
+ {
+ return PV_FALSE;
+ }
+
+ return PV_TRUE;
+}
+
+/* ======================================================================== */
+/* Function : PVDecodeVopHeader() */
+/* Date : 08/22/2002 */
+/* Purpose : Determine target layer and decode vop header, modified from */
+/* original PVDecodeVideoFrame. */
+/* In/out : */
+/* Return : */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+Bool PVDecodeVopHeader(VideoDecControls *decCtrl, uint8 *buffer[],
+ uint32 timestamp[], int32 buffer_size[], VopHeaderInfo *header_info, uint use_ext_timestamp [], uint8 *currYUV)
+{
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+ Vol *currVol;
+ Vop *currVop = video->currVop;
+ Vop **vopHeader = video->vopHeader;
+ BitstreamDecVideo *stream;
+
+ int target_layer;
+
+#ifdef PV_SUPPORT_TEMPORAL_SCALABILITY
+ PV_STATUS status = PV_FAIL;
+ int idx;
+ int32 display_time;
+
+ /* decide which frame to decode next */
+ if (decCtrl->nLayers > 1)
+ {
+ display_time = target_layer = -1;
+ for (idx = 0; idx < decCtrl->nLayers; idx++)
+ {
+ /* do we have data for this layer? */
+ if (buffer_size[idx] <= 0)
+ {
+ timestamp[idx] = -1;
+ continue;
+ }
+
+ /* did the application provide a timestamp for this vop? */
+ if (timestamp[idx] < 0)
+ {
+ if (vopHeader[idx]->timeStamp < 0)
+ {
+ /* decode the timestamp in the bitstream */
+ video->currLayer = idx;
+ stream = video->vol[idx]->bitstream;
+ BitstreamReset(stream, buffer[idx], buffer_size[idx]);
+
+ while ((status = DecodeVOPHeader(video, vopHeader[idx], FALSE)) != PV_SUCCESS)
+ {
+ /* Try to find a VOP header in the buffer. 08/30/2000. */
+ if (PVSearchNextM4VFrame(stream) != PV_SUCCESS)
+ {
+ /* if we don't have data for enhancement layer, */
+ /* don't just stop. 09/07/2000. */
+ buffer_size[idx] = 0;
+ break;
+ }
+ }
+ if (status == PV_SUCCESS)
+ {
+ vopHeader[idx]->timeStamp =
+ timestamp[idx] = CalcVopDisplayTime(video->vol[idx], vopHeader[idx], video->shortVideoHeader);
+ if (idx == 0) vopHeader[idx]->refSelectCode = 1;
+ }
+ }
+ else
+ {
+ /* We've decoded this vop header in the previous run already. */
+ timestamp[idx] = vopHeader[idx]->timeStamp;
+ }
+ }
+
+ /* Use timestamps to select the next VOP to be decoded */
+ if (timestamp[idx] >= 0 && (display_time < 0 || display_time > timestamp[idx]))
+ {
+ display_time = timestamp[idx];
+ target_layer = idx;
+ }
+ else if (display_time == timestamp[idx])
+ {
+ /* we have to handle either SNR or spatial scalability here. */
+ }
+ }
+ if (target_layer < 0) return PV_FALSE;
+
+ /* set up for decoding the target layer */
+ video->currLayer = target_layer;
+ currVol = video->vol[target_layer];
+ video->bitstream = stream = currVol->bitstream;
+
+ /* We need to decode the vop header if external timestamp */
+ /* is provided. 10/04/2000 */
+ if (vopHeader[target_layer]->timeStamp < 0)
+ {
+ stream = video->vol[target_layer]->bitstream;
+ BitstreamReset(stream, buffer[target_layer], buffer_size[target_layer]);
+
+ while (DecodeVOPHeader(video, vopHeader[target_layer], TRUE) != PV_SUCCESS)
+ {
+ /* Try to find a VOP header in the buffer. 08/30/2000. */
+ if (PVSearchNextM4VFrame(stream) != PV_SUCCESS)
+ {
+ /* if we don't have data for enhancement layer, */
+ /* don't just stop. 09/07/2000. */
+ buffer_size[target_layer] = 0;
+ break;
+ }
+ }
+ video->vol[target_layer]->timeInc_offset = vopHeader[target_layer]->timeInc;
+ video->vol[target_layer]->moduloTimeBase = timestamp[target_layer];
+ vopHeader[target_layer]->timeStamp = timestamp[target_layer];
+ if (target_layer == 0) vopHeader[target_layer]->refSelectCode = 1;
+ }
+ }
+ else /* base layer only decoding */
+ {
+#endif
+ video->currLayer = target_layer = 0;
+ currVol = video->vol[0];
+ video->bitstream = stream = currVol->bitstream;
+ if (buffer_size[0] <= 0) return PV_FALSE;
+ BitstreamReset(stream, buffer[0], buffer_size[0]);
+
+ if (video->shortVideoHeader)
+ {
+ while (DecodeShortHeader(video, vopHeader[0]) != PV_SUCCESS)
+ {
+ if (PVSearchNextH263Frame(stream) != PV_SUCCESS)
+ {
+ /* There is no vop header in the buffer, */
+ /* clean bitstream buffer. 2/5/2001 */
+ buffer_size[0] = 0;
+ if (video->initialized == PV_FALSE)
+ {
+ video->displayWidth = video->width = 0;
+ video->displayHeight = video->height = 0;
+ }
+ return PV_FALSE;
+ }
+ }
+
+ if (use_ext_timestamp[0])
+ {
+ /* MTB for H263 is absolute TR */
+ /* following line is equivalent to round((timestamp[0]*30)/1001); 11/13/2001 */
+ video->vol[0]->moduloTimeBase = 30 * ((timestamp[0] + 17) / 1001) + (30 * ((timestamp[0] + 17) % 1001) / 1001);
+ vopHeader[0]->timeStamp = timestamp[0];
+ }
+ else
+ vopHeader[0]->timeStamp = CalcVopDisplayTime(currVol, vopHeader[0], video->shortVideoHeader);
+ }
+ else
+ {
+ while (DecodeVOPHeader(video, vopHeader[0], FALSE) != PV_SUCCESS)
+ {
+ /* Try to find a VOP header in the buffer. 08/30/2000. */
+ if (PVSearchNextM4VFrame(stream) != PV_SUCCESS)
+ {
+ /* There is no vop header in the buffer, */
+ /* clean bitstream buffer. 2/5/2001 */
+ buffer_size[0] = 0;
+ return PV_FALSE;
+ }
+ }
+
+ if (use_ext_timestamp[0])
+ {
+ video->vol[0]->timeInc_offset = vopHeader[0]->timeInc;
+ video->vol[0]->moduloTimeBase = timestamp[0]; /* 11/12/2001 */
+ vopHeader[0]->timeStamp = timestamp[0];
+ }
+ else
+ {
+ vopHeader[0]->timeStamp = CalcVopDisplayTime(currVol, vopHeader[0], video->shortVideoHeader);
+ }
+ }
+
+ /* set up some base-layer only parameters */
+ vopHeader[0]->refSelectCode = 1;
+#ifdef PV_SUPPORT_TEMPORAL_SCALABILITY
+ }
+#endif
+ timestamp[target_layer] = video->currTimestamp = vopHeader[target_layer]->timeStamp;
+#ifdef PV_MEMORY_POOL
+ vopHeader[target_layer]->yChan = (PIXEL *)currYUV;
+ vopHeader[target_layer]->uChan = (PIXEL *)currYUV + decCtrl->size;
+ vopHeader[target_layer]->vChan = (PIXEL *)(vopHeader[target_layer]->uChan) + (decCtrl->size >> 2);
+#else
+ vopHeader[target_layer]->yChan = currVop->yChan;
+ vopHeader[target_layer]->uChan = currVop->uChan;
+ vopHeader[target_layer]->vChan = currVop->vChan;
+#endif
+ oscl_memcpy(currVop, vopHeader[target_layer], sizeof(Vop));
+
+#ifdef PV_SUPPORT_TEMPORAL_SCALABILITY
+ vopHeader[target_layer]->timeStamp = -1;
+#endif
+ /* put header info into the structure */
+ header_info->currLayer = target_layer;
+ header_info->timestamp = video->currTimestamp;
+ header_info->frameType = (MP4FrameType)currVop->predictionType;
+ header_info->refSelCode = vopHeader[target_layer]->refSelectCode;
+ header_info->quantizer = currVop->quantizer;
+ /***************************************/
+
+ return PV_TRUE;
+}
+
+
+/* ======================================================================== */
+/* Function : PVDecodeVopBody() */
+/* Date : 08/22/2002 */
+/* Purpose : Decode vop body after the header is decoded, modified from */
+/* original PVDecodeVideoFrame. */
+/* In/out : */
+/* Return : */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+Bool PVDecodeVopBody(VideoDecControls *decCtrl, int32 buffer_size[])
+{
+ PV_STATUS status = PV_FAIL;
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+ int target_layer = video->currLayer;
+ Vol *currVol = video->vol[target_layer];
+ Vop *currVop = video->currVop;
+ Vop *prevVop = video->prevVop;
+ Vop *tempVopPtr;
+ int bytes_consumed = 0; /* Record how many bits we used in the buffer. 04/24/2001 */
+
+ int idx;
+
+ if (currVop->vopCoded == 0) /* 07/03/2001 */
+ {
+ PV_BitstreamByteAlign(currVol->bitstream);
+ /* We should always clear up bitstream buffer. 10/10/2000 */
+ bytes_consumed = (getPointer(currVol->bitstream) + 7) >> 3;
+
+ if (bytes_consumed > currVol->bitstream->data_end_pos)
+ {
+ bytes_consumed = currVol->bitstream->data_end_pos;
+ }
+
+ if (bytes_consumed < buffer_size[target_layer])
+ {
+ /* If we only consume part of the bits in the buffer, take those */
+ /* out. 04/24/2001 */
+ /* oscl_memcpy(buffer[target_layer], buffer[target_layer]+bytes_consumed,
+ (buffer_size[target_layer]-=bytes_consumed)); */
+ buffer_size[target_layer] -= bytes_consumed;
+ }
+ else
+ {
+ buffer_size[target_layer] = 0;
+ }
+#ifdef PV_MEMORY_POOL
+
+ if (target_layer)
+ {
+ if (video->prevEnhcVop->timeStamp > video->prevVop->timeStamp)
+ {
+ video->prevVop = video->prevEnhcVop;
+ }
+ }
+
+ if (!video->prevVop->yChan) {
+ ALOGE("b/35269635");
+ android_errorWriteLog(0x534e4554, "35269635");
+ return PV_FALSE;
+ }
+ oscl_memcpy(currVop->yChan, video->prevVop->yChan, (decCtrl->size*3) / 2);
+
+ video->prevVop = prevVop;
+
+ video->concealFrame = currVop->yChan; /* 07/07/2001 */
+
+ video->vop_coding_type = currVop->predictionType; /* 07/09/01 */
+
+ decCtrl->outputFrame = currVop->yChan;
+
+ /* Swap VOP pointers. No enhc. frame oscl_memcpy() anymore! 04/24/2001 */
+ if (target_layer)
+ {
+ tempVopPtr = video->prevEnhcVop;
+ video->prevEnhcVop = video->currVop;
+ video->currVop = tempVopPtr;
+ }
+ else
+ {
+ tempVopPtr = video->prevVop;
+ video->prevVop = video->currVop;
+ video->currVop = tempVopPtr;
+ }
+#else
+ if (target_layer) /* this is necessary to avoid flashback problems 06/21/2002*/
+ {
+ video->prevEnhcVop->timeStamp = currVop->timeStamp;
+ }
+ else
+ {
+ video->prevVop->timeStamp = currVop->timeStamp;
+ }
+#endif
+ video->vop_coding_type = currVop->predictionType; /* 07/09/01 */
+ /* the following is necessary to avoid displaying an notCoded I-VOP at the beginning of a session
+ or after random positioning 07/03/02*/
+ if (currVop->predictionType == I_VOP)
+ {
+ video->vop_coding_type = P_VOP;
+ }
+
+
+ return PV_TRUE;
+ }
+ /* ======================================================= */
+ /* Decode vop body (if there is no error in the header!) */
+ /* ======================================================= */
+
+ /* first, we need to select a reference frame */
+ if (decCtrl->nLayers > 1)
+ {
+ if (currVop->predictionType == I_VOP)
+ {
+ /* do nothing here */
+ }
+ else if (currVop->predictionType == P_VOP)
+ {
+ switch (currVop->refSelectCode)
+ {
+ case 0 : /* most recently decoded enhancement vop */
+ /* Setup video->prevVop before we call PV_DecodeVop(). 04/24/2001 */
+ if (video->prevEnhcVop->timeStamp >= video->prevVop->timeStamp)
+ video->prevVop = video->prevEnhcVop;
+ break;
+
+ case 1 : /* most recently displayed base-layer vop */
+ if (target_layer)
+ {
+ if (video->prevEnhcVop->timeStamp > video->prevVop->timeStamp)
+ video->prevVop = video->prevEnhcVop;
+ }
+ break;
+
+ case 2 : /* next base-layer vop in display order */
+ break;
+
+ case 3 : /* temporally coincident base-layer vop (no MV's) */
+ break;
+ }
+ }
+ else /* we have a B-Vop */
+ {
+ mp4dec_log("DecodeVideoFrame(): B-VOP not supported.\n");
+ }
+ }
+
+ /* This is for the calculation of the frame rate and bitrate. */
+ idx = ++video->frame_idx % BITRATE_AVERAGE_WINDOW;
+
+ /* Calculate bitrate for this layer. 08/23/2000 */
+ status = PV_DecodeVop(video);
+ video->nBitsPerVop[idx] = getPointer(currVol->bitstream);
+ video->prevTimestamp[idx] = currVop->timeStamp;
+
+ /* restore video->prevVop after PV_DecodeVop(). 04/24/2001 */
+// if (currVop->refSelectCode == 0) video->prevVop = prevVop;
+ video->prevVop = prevVop;
+
+ /* Estimate the frame rate. 08/23/2000 */
+ video->duration = video->prevTimestamp[idx];
+ video->duration -= video->prevTimestamp[(++idx)%BITRATE_AVERAGE_WINDOW];
+ if (video->duration > 0)
+ { /* Only update framerate when the timestamp is right */
+ video->frameRate = (int)(FRAMERATE_SCALE) / video->duration;
+ }
+
+ /* We should always clear up bitstream buffer. 10/10/2000 */
+ bytes_consumed = (getPointer(currVol->bitstream) + 7) >> 3; /* 11/4/03 */
+
+ if (bytes_consumed > currVol->bitstream->data_end_pos)
+ {
+ bytes_consumed = currVol->bitstream->data_end_pos;
+ }
+
+ if (bytes_consumed < buffer_size[target_layer])
+ {
+ /* If we only consume part of the bits in the buffer, take those */
+ /* out. 04/24/2001 */
+ /* oscl_memcpy(buffer[target_layer], buffer[target_layer]+bytes_consumed,
+ (buffer_size[target_layer]-=bytes_consumed)); */
+ buffer_size[target_layer] -= bytes_consumed;
+ }
+ else
+ {
+ buffer_size[target_layer] = 0;
+ }
+ switch (status)
+ {
+ case PV_FAIL :
+ return PV_FALSE; /* this will take care of concealment if we lose whole frame */
+
+ case PV_END_OF_VOP :
+ /* we may want to differenciate PV_END_OF_VOP and PV_SUCCESS */
+ /* in the future. 05/10/2000 */
+
+ case PV_SUCCESS :
+ /* Nohting is wrong :). */
+
+
+ video->concealFrame = video->currVop->yChan; /* 07/07/2001 */
+
+ video->vop_coding_type = video->currVop->predictionType; /* 07/09/01 */
+
+ decCtrl->outputFrame = video->currVop->yChan;
+
+ /* Swap VOP pointers. No enhc. frame oscl_memcpy() anymore! 04/24/2001 */
+ if (target_layer)
+ {
+ tempVopPtr = video->prevEnhcVop;
+ video->prevEnhcVop = video->currVop;
+ video->currVop = tempVopPtr;
+ }
+ else
+ {
+ tempVopPtr = video->prevVop;
+ video->prevVop = video->currVop;
+ video->currVop = tempVopPtr;
+ }
+ break;
+
+ default :
+ /* This will never happen */
+ break;
+ }
+
+ return PV_TRUE;
+}
+
+#ifdef PV_MEMORY_POOL
+OSCL_EXPORT_REF void PVSetReferenceYUV(VideoDecControls *decCtrl, uint8 *YUV)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ video->prevVop->yChan = (PIXEL *)YUV;
+ video->prevVop->uChan = (PIXEL *)YUV + video->size;
+ video->prevVop->vChan = (PIXEL *)video->prevVop->uChan + (decCtrl->size >> 2);
+ oscl_memset(video->prevVop->yChan, 16, sizeof(uint8)*decCtrl->size); /* 10/31/01 */
+ oscl_memset(video->prevVop->uChan, 128, sizeof(uint8)*decCtrl->size / 2);
+ video->concealFrame = video->prevVop->yChan; /* 07/07/2001 */
+ decCtrl->outputFrame = video->prevVop->yChan; /* 06/19/2002 */
+}
+#endif
+
+
+/* ======================================================================== */
+/* Function : VideoDecoderErrorDetected() */
+/* Date : 06/20/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : This function will be called everytime an error int the */
+/* bitstream is detected. */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+uint VideoDecoderErrorDetected(VideoDecData *)
+{
+ /* This is only used for trapping bitstream error for debuging */
+ return 0;
+}
+
+#ifdef ENABLE_LOG
+#include <stdio.h>
+#include <stdarg.h>
+/* ======================================================================== */
+/* Function : m4vdec_dprintf() */
+/* Date : 08/15/2000 */
+/* Purpose : This is a function that logs messages in the mpeg4 video */
+/* decoder. We can call the standard PacketVideo PVMessage */
+/* from inside this function if necessary. */
+/* In/out : */
+/* Return : */
+/* Note : To turn on the logging, LOG_MP4DEC_MESSAGE must be defined */
+/* when compiling this file (only this file). */
+/* Modified : */
+/* ======================================================================== */
+void m4vdec_dprintf(char *format, ...)
+{
+ FILE *log_fp;
+ va_list args;
+ va_start(args, format);
+
+ /* open the log file */
+ log_fp = fopen("\\mp4dec_log.txt", "a+");
+ if (log_fp == NULL) return;
+ /* output the message */
+ vfprintf(log_fp, format, args);
+ fclose(log_fp);
+
+ va_end(args);
+}
+#endif
+
+
+/* ======================================================================== */
+/* Function : IsIntraFrame() */
+/* Date : 05/29/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : The most recently decoded frame is an Intra frame. */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+Bool IsIntraFrame(VideoDecControls *decCtrl)
+{
+ VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
+ return (video->vop_coding_type == I_VOP);
+}
+
+/* ======================================================================== */
+/* Function : PVDecPostProcess() */
+/* Date : 01/09/2002 */
+/* Purpose : PostProcess one video frame and return a YUV-12 image. */
+/* In/out : */
+/* Return : */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+void PVDecPostProcess(VideoDecControls *decCtrl, uint8 *outputYUV)
+{
+ uint8 *outputBuffer;
+ outputBuffer = decCtrl->outputFrame;
+ outputYUV;
+ decCtrl->outputFrame = outputBuffer;
+ return;
+}
+
+
+/* ======================================================================== */
+/* Function : PVDecSetReference(VideoDecControls *decCtrl, uint8 *refYUV, */
+/* int32 timestamp) */
+/* Date : 07/22/2003 */
+/* Purpose : Get YUV reference frame from external source. */
+/* In/out : YUV 4-2-0 frame containing new reference frame in the same */
+/* : dimension as original, i.e., doesn't have to be multiple of 16 !!!. */
+/* Return : */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+Bool PVDecSetReference(VideoDecControls *decCtrl, uint8 *refYUV, uint32 timestamp)
+{
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+ Vop *prevVop = video->prevVop;
+ int width = video->width;
+ uint8 *dstPtr, *orgPtr, *dstPtr2, *orgPtr2;
+ int32 size = (int32)width * video->height;
+
+
+ /* set new parameters */
+ prevVop->timeStamp = timestamp;
+ prevVop->predictionType = I_VOP;
+
+ dstPtr = prevVop->yChan;
+ orgPtr = refYUV;
+ oscl_memcpy(dstPtr, orgPtr, size);
+ dstPtr = prevVop->uChan;
+ dstPtr2 = prevVop->vChan;
+ orgPtr = refYUV + size;
+ orgPtr2 = orgPtr + (size >> 2);
+ oscl_memcpy(dstPtr, orgPtr, (size >> 2));
+ oscl_memcpy(dstPtr2, orgPtr2, (size >> 2));
+
+ video->concealFrame = video->prevVop->yChan;
+ video->vop_coding_type = I_VOP;
+ decCtrl->outputFrame = video->prevVop->yChan;
+
+ return PV_TRUE;
+}
+
+/* ======================================================================== */
+/* Function : PVDecSetEnhReference(VideoDecControls *decCtrl, uint8 *refYUV, */
+/* int32 timestamp) */
+/* Date : 07/23/2003 */
+/* Purpose : Get YUV enhance reference frame from external source. */
+/* In/out : YUV 4-2-0 frame containing new reference frame in the same */
+/* : dimension as original, i.e., doesn't have to be multiple of 16 !!!. */
+/* Return : */
+/* Note : */
+/* Modified : */
+/* ======================================================================== */
+Bool PVDecSetEnhReference(VideoDecControls *decCtrl, uint8 *refYUV, uint32 timestamp)
+{
+ VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
+ Vop *prevEnhcVop = video->prevEnhcVop;
+ uint8 *dstPtr, *orgPtr, *dstPtr2, *orgPtr2;
+ int32 size = (int32) video->width * video->height;
+
+ if (video->numberOfLayers <= 1)
+ return PV_FALSE;
+
+
+ /* set new parameters */
+ prevEnhcVop->timeStamp = timestamp;
+ prevEnhcVop->predictionType = I_VOP;
+
+ dstPtr = prevEnhcVop->yChan;
+ orgPtr = refYUV;
+ oscl_memcpy(dstPtr, orgPtr, size);
+ dstPtr = prevEnhcVop->uChan;
+ dstPtr2 = prevEnhcVop->vChan;
+ orgPtr = refYUV + size;
+ orgPtr2 = orgPtr + (size >> 2);
+ oscl_memcpy(dstPtr, orgPtr, (size >> 2));
+ oscl_memcpy(dstPtr2, orgPtr2, (size >> 2));
+ video->concealFrame = video->prevEnhcVop->yChan;
+ video->vop_coding_type = I_VOP;
+ decCtrl->outputFrame = video->prevEnhcVop->yChan;
+
+ return PV_TRUE;
+}
+
+
+/* ======================================================================== */
+/* Function : PVGetVolInfo() */
+/* Date : 08/06/2003 */
+/* Purpose : Get the vol info(only base-layer). */
+/* In/out : */
+/* Return : */
+/* Note : */
+/* Modified : 06/24/2004 */
+/* ======================================================================== */
+Bool PVGetVolInfo(VideoDecControls *decCtrl, VolInfo *pVolInfo)
+{
+ Vol *currVol;
+
+ if (pVolInfo == NULL || decCtrl == NULL || decCtrl->videoDecoderData == NULL ||
+ ((VideoDecData *)decCtrl->videoDecoderData)->vol[0] == NULL) return PV_FALSE;
+
+ currVol = ((VideoDecData *)(decCtrl->videoDecoderData))->vol[0];
+
+ // get the VOL info
+ pVolInfo->shortVideoHeader = (int32)((VideoDecData *)(decCtrl->videoDecoderData))->shortVideoHeader;
+ pVolInfo->dataPartitioning = (int32)currVol->dataPartitioning;
+ pVolInfo->errorResDisable = (int32)currVol->errorResDisable;
+ pVolInfo->useReverseVLC = (int32)currVol->useReverseVLC;
+ pVolInfo->scalability = (int32)currVol->scalability;
+ pVolInfo->nbitsTimeIncRes = (int32)currVol->nbitsTimeIncRes;
+ pVolInfo->profile_level_id = (int32)currVol->profile_level_id;
+
+ return PV_TRUE;
+}
+
+
+
diff --git a/media/codecs/m4v_h263/dec/src/scaling.h b/media/codecs/m4v_h263/dec/src/scaling.h
new file mode 100644
index 0000000..26abbae
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/scaling.h
@@ -0,0 +1,52 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ extern const int32 scale[63];
+
+#define PV_GET_ROW(a,b) ((a) / (b))
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+
+
diff --git a/media/codecs/m4v_h263/dec/src/scaling_tab.cpp b/media/codecs/m4v_h263/dec/src/scaling_tab.cpp
new file mode 100644
index 0000000..a1f95aa
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/scaling_tab.cpp
@@ -0,0 +1,88 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "mp4dec_api.h"
+#include "mp4def.h"
+#include "scaling.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/* this scaling can be used for dividing values up to 3292 07/10/01 */
+const int32 scale[63] = {0, 262145, 131073, 87382, 65537, 52430, 43692, 37450, 32769, 29128,
+ 26215, 23832, 21846, 20166, 18726, 17477, 16385, 15421, 14565, 13798,
+ 13108, 12484, 11917, 11399, 10924, 10487, 10083, 9710, 9363, 9040,
+ 8739, 8457, 8193, 7945, 7711, 7491, 7283, 7086, 6900, 6723, 6555, 6395,
+ 6243, 6097, 5959, 5826, 5700, 5579, 5462, 5351, 5244, 5141, 5042, 4947, 4856,
+ 4767, 4682, 4600, 4521, 4444, 4370, 4298, 4229
+ };
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
diff --git a/media/codecs/m4v_h263/dec/src/vlc_dec_tab.h b/media/codecs/m4v_h263/dec/src/vlc_dec_tab.h
new file mode 100644
index 0000000..404cc8b
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/vlc_dec_tab.h
@@ -0,0 +1,215 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+* ------------------------------------------------------------------- *
+* MPEG-4 Simple Profile Video Decoder *
+* ------------------------------------------------------------------- *
+*
+* This software module was originally developed by
+*
+* Paulo Nunes (IST / ACTS-MoMuSyS)
+*
+* and edited by
+*
+* Robert Danielsen (Telenor / ACTS-MoMuSyS)
+*
+* in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
+* This software module is an implementation of a part of one or more MPEG-4
+* Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
+* license to this software module or modifications thereof for use in hardware
+* or software products claiming conformance to the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* Those intending to use this software module in hardware or software products
+* are advised that its use may infringe existing patents. The original
+* developer of this software module and his/her company, the subsequent
+* editors and their companies, and ISO/IEC have no liability for use of this
+* software module or modifications thereof in an implementation. Copyright is
+* not released for non MPEG-4 Video (ISO/IEC 14496-2) Standard conforming
+* products.
+*
+* ACTS-MoMuSys partners retain full right to use the code for his/her own
+* purpose, assign or donate the code to a third party and to inhibit third
+* parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) Standard
+* conforming products. This copyright notice must be included in all copies or
+* derivative works.
+*
+* Copyright (c) 1996
+*
+*****************************************************************************
+***********************************************************HeaderBegin*******
+*
+* File: vlc_dec_tab.h
+*
+* Author: Paulo Nunes (IST) - Paulo.Nunes@it.ist.utl.pt
+* Created: 1-Mar-96
+*
+* Description: This file contains the VLC tables for module which deals
+* with VLC decoding.
+*
+* Notes: This file was created based on tmndecode
+* Written by Karl Olav Lillevold <kol@nta.no>,
+* 1995 Telenor R&D.
+* Donated to the Momusys-project as background code by
+* Telenor.
+*
+* based on mpeg2decode, (C) 1994, MPEG Software Simulation Group
+* and mpeg2play, (C) 1994 Stefan Eckart
+* <stefan@lis.e-technik.tu-muenchen.de>
+*
+*
+* Modified: 9-May-96 Paulo Nunes: Reformatted. New headers.
+* 14-May-96 Paulo Nunes: Changed TMNMVtabs according to VM2.1.
+* 04.11.96 Robert Danielsen: Added three new tables for coding
+* of Intra luminance coefficients (VM 4.0)
+* 01.05.97 Luis Ducla-Soares: added VM7.0 Reversible VLC tables (RVLC).
+* 13.05.97 Minhua Zhou: added VlC tables for CBPYtab2 CBPYtab3,
+* revised CBPYtab
+*
+***********************************************************HeaderEnd*********
+
+This module is a header file for "vlc_decode.c". The table data actually
+resides in "vlc_tab.c".
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef vlc_dec_tab_H
+#define vlc_dec_tab_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "mp4def.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ extern const VLCshorttab PV_TMNMVtab0[];
+
+ extern const VLCshorttab PV_TMNMVtab1[];
+
+ extern const VLCshorttab PV_TMNMVtab2[];
+
+ extern const VLCshorttab PV_MCBPCtab[];
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ extern const VLCshorttab PV_MCBPCtab1[];
+#endif
+ extern const VLCshorttab PV_MCBPCtabintra[];
+
+ /* Table for separate mode MCBPC, for coding DQUANT-flag and CBPC */
+
+ extern const VLCshorttab MCBPCtab_sep[32];
+
+ extern const VLCshorttab PV_CBPYtab[48];
+
+ extern const VLCshorttab CBPYtab2[16];
+
+ extern const VLCshorttab CBPYtab3[64];
+
+ extern const VLCtab2 PV_DCT3Dtab0[];
+
+
+ extern const VLCtab2 PV_DCT3Dtab1[];
+
+
+ extern const VLCtab2 PV_DCT3Dtab2[];
+
+ /* New tables for Intra luminance blocks */
+
+ extern const VLCtab2 PV_DCT3Dtab3[];
+
+ extern const VLCtab2 PV_DCT3Dtab4[];
+
+ extern const VLCtab2 PV_DCT3Dtab5[];
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ /* Annex I tables */
+ extern const VLCtab2 PV_DCT3Dtab6[];
+
+ extern const VLCtab2 PV_DCT3Dtab7[];
+
+ extern const VLCtab2 PV_DCT3Dtab8[];
+#endif
+ /* RVLC tables */
+ extern const int ptrRvlcTab[];
+
+ extern const VLCtab2 RvlcDCTtabIntra[];
+
+ extern const VLCtab2 RvlcDCTtabInter[];
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+
+
+
+
diff --git a/media/codecs/m4v_h263/dec/src/vlc_decode.cpp b/media/codecs/m4v_h263/dec/src/vlc_decode.cpp
new file mode 100644
index 0000000..7202f98
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/vlc_decode.cpp
@@ -0,0 +1,1636 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+* ------------------------------------------------------------------- *
+* MPEG-4 Simple Profile Video Decoder *
+* ------------------------------------------------------------------- *
+*
+* This software module was originally developed by
+*
+* Paulo Nunes (IST / ACTS-MoMuSyS)
+* Robert Danielsen (Telenor / ACTS-MoMuSyS)
+*
+* in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
+* This software module is an implementation of a part of one or more MPEG-4
+* Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
+* license to this software module or modifications thereof for use in hardware
+* or software products claiming conformance to the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* Those intending to use this software module in hardware or software products
+* are advised that its use may infringe existing patents. The original
+* developer of this software module and his/her company, the subsequent
+* editors and their companies, and ISO/IEC have no liability for use of this
+* software module or modifications thereof in an implementation. Copyright is
+* not released for non MPEG-4 Video (ISO/IEC 14496-2) Standard conforming
+* products.
+*
+* ACTS-MoMuSys partners retain full right to use the code for his/her own
+* purpose, assign or donate the code to a third party and to inhibit third
+* parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) Standard
+* conforming products. This copyright notice must be included in all copies or
+* derivative works.
+*
+* Copyright (c) 1996
+*
+*****************************************************************************/
+
+/***********************************************************HeaderBegin*******
+*
+* File: vlc_dec.c
+*
+* Author: Paulo Nunes (IST) - Paulo.Nunes@lx.it.pt
+* Created: 1-Mar-96
+*
+* Description: This file contains the VLC functions needed to decode a
+* bitstream.
+*
+* Notes:
+* The functions contained in this file were adapted from
+* tmndecode
+* Written by Karl Olav Lillevold <kol@nta.no>,
+* 1995 Telenor R&D.
+* Donated to the Momusys-project as background code by
+* Telenor.
+*
+* based on mpeg2decode, (C) 1994, MPEG Software Simulation Group
+* and mpeg2play, (C) 1994 Stefan Eckart
+* <stefan@lis.e-technik.tu-muenchen.de>
+*
+*
+* Modified: 9-May-96 Paulo Nunes: Reformatted. New headers.
+* 17-Jan-97 Jan De Lameillieure (HHI) : corrected in
+* 01.05.97 Luis Ducla-Soares: added RvlcDecTCOEF() to allow decoding
+* of Reversible VLCs.
+* 09.03.98 Paulo Nunes: Cleaning.
+*
+***********************************************************HeaderEnd*********/
+
+#include "mp4dec_lib.h"
+#include "vlc_dec_tab.h"
+#include "vlc_decode.h"
+#include "bitstream.h"
+#include "max_level.h"
+
+
+/* ====================================================================== /
+ Function : DecodeUserData()
+ Date : 04/10/2000
+ History :
+ Modified : 04/16/2001 : removed status checking of PV_BitstreamFlushBits
+
+ This is simply a realization of the user_data() function
+ in the ISO/IEC 14496-2 manual.
+/ ====================================================================== */
+PV_STATUS DecodeUserData(BitstreamDecVideo *stream)
+{
+ PV_STATUS status;
+ uint32 code;
+
+ BitstreamReadBits32HC(stream);
+ BitstreamShowBits32(stream, 24, &code);
+
+ while (code != 1)
+ {
+ /* Discard user data for now. 04/05/2000 */
+ BitstreamReadBits16(stream, 8);
+ BitstreamShowBits32(stream, 24, &code);
+ status = BitstreamCheckEndBuffer(stream);
+ if (status == PV_END_OF_VOP) return status; /* 03/19/2002 */
+ }
+ return PV_SUCCESS;
+}
+
+
+
+/***********************************************************CommentBegin******
+*
+* 3/10/00 : initial modification to the
+* new PV-Decoder Lib format.
+* 3/29/00 : added return code check to some functions and
+* optimize the code.
+*
+***********************************************************CommentEnd********/
+PV_STATUS PV_GetMBvectors(VideoDecData *video, uint mode)
+{
+ PV_STATUS status;
+ BitstreamDecVideo *stream = video->bitstream;
+ int f_code_f = video->currVop->fcodeForward;
+ int vlc_code_mag;
+
+
+ MOT *mot_x = video->motX;
+ MOT *mot_y = video->motY;
+
+ int k, offset;
+ int x_pos = video->mbnum_col;
+ int y_pos = video->mbnum_row;
+ int doubleWidth = video->nMBPerRow << 1;
+ int pos = (x_pos + y_pos * doubleWidth) << 1;
+ MOT mvx = 0, mvy = 0;
+
+
+ if (f_code_f == 1)
+ {
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (mode == MODE_INTER4V || mode == MODE_INTER4V_Q)
+#else
+ if (mode == MODE_INTER4V)
+#endif
+ {
+ for (k = 0; k < 4; k++)
+ {
+ offset = (k & 1) + (k >> 1) * doubleWidth;
+ mv_prediction(video, k, &mvx, &mvy);
+ /* decode component x */
+ status = PV_VlcDecMV(stream, &vlc_code_mag);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ mvx += (MOT)vlc_code_mag;
+ mvx = (MOT)(((mvx + 32) & 0x3F) - 32);
+
+
+ status = PV_VlcDecMV(stream, &vlc_code_mag);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ mvy += (MOT)vlc_code_mag;
+ mvy = (MOT)(((mvy + 32) & 0x3F) - 32);
+
+ mot_x[pos+offset] = (MOT) mvx;
+ mot_y[pos+offset] = (MOT) mvy;
+ }
+ }
+ else
+ {
+ mv_prediction(video, 0, &mvx, &mvy);
+ /* For PVOPs, field appears only in MODE_INTER & MODE_INTER_Q */
+ status = PV_VlcDecMV(stream, &vlc_code_mag);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ mvx += (MOT)vlc_code_mag;
+ mvx = (MOT)(((mvx + 32) & 0x3F) - 32);
+
+
+ status = PV_VlcDecMV(stream, &vlc_code_mag);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+
+ mvy += (MOT)vlc_code_mag;
+ mvy = (MOT)(((mvy + 32) & 0x3F) - 32);
+
+
+ mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
+ mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
+ pos += doubleWidth;
+ mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
+ mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
+ }
+ }
+ else
+ {
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (mode == MODE_INTER4V || mode == MODE_INTER4V_Q)
+#else
+ if (mode == MODE_INTER4V)
+#endif
+ {
+ for (k = 0; k < 4; k++)
+ {
+ offset = (k & 1) + (k >> 1) * doubleWidth;
+ mv_prediction(video, k, &mvx, &mvy);
+ status = PV_DecodeMBVec(stream, &mvx, &mvy, f_code_f);
+ mot_x[pos+offset] = (MOT) mvx;
+ mot_y[pos+offset] = (MOT) mvy;
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+ }
+ }
+ else
+ {
+ mv_prediction(video, 0, &mvx, &mvy);
+ /* For PVOPs, field appears only in MODE_INTER & MODE_INTER_Q */
+ status = PV_DecodeMBVec(stream, &mvx, &mvy, f_code_f);
+ mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
+ mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
+ pos += doubleWidth;
+ mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
+ mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+ }
+ }
+ return PV_SUCCESS;
+}
+
+
+/***********************************************************CommentBegin******
+* 3/10/00 : initial modification to the
+* new PV-Decoder Lib format.
+* 3/29/00 : added return code check to some functions
+* 5/10/00 : check whether the decoded vector is legal.
+* 4/17/01 : use MOT type
+***********************************************************CommentEnd********/
+PV_STATUS PV_DecodeMBVec(BitstreamDecVideo *stream, MOT *mv_x, MOT *mv_y, int f_code_f)
+{
+ PV_STATUS status;
+ int vlc_code_magx, vlc_code_magy;
+ int residualx = 0, residualy = 0;
+
+ /* decode component x */
+ status = PV_VlcDecMV(stream, &vlc_code_magx);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ if (vlc_code_magx)
+ {
+ residualx = (int) BitstreamReadBits16_INLINE(stream, (int)(f_code_f - 1));
+ }
+
+
+ /* decode component y */
+ status = PV_VlcDecMV(stream, &vlc_code_magy);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ if (vlc_code_magy)
+ {
+ residualy = (int) BitstreamReadBits16_INLINE(stream, (int)(f_code_f - 1));
+ }
+
+
+ if (PV_DeScaleMVD(f_code_f, residualx, vlc_code_magx, mv_x) != PV_SUCCESS)
+ {
+ return PV_FAIL;
+ }
+
+ if (PV_DeScaleMVD(f_code_f, residualy, vlc_code_magy, mv_y) != PV_SUCCESS)
+ {
+ return PV_FAIL;
+ }
+
+ return PV_SUCCESS;
+}
+
+
+/***********************************************************CommentBegin******
+* 3/31/2000 : initial modification to the new PV-Decoder Lib format.
+* 5/10/2000 : check to see if the decoded vector falls within
+* the legal fcode range.
+*
+***********************************************************CommentEnd********/
+PV_STATUS PV_DeScaleMVD(
+ int f_code, /* <-- MV range in 1/2 units: 1=32,2=64,...,7=2048 */
+ int residual, /* <-- part of the MV Diff. FLC coded */
+ int vlc_code_mag, /* <-- part of the MV Diff. VLC coded */
+ MOT *vector /* --> Obtained MV component in 1/2 units */
+)
+{
+ int half_range = (1 << (f_code + 4));
+ int mask = (half_range << 1) - 1;
+ int diff_vector;
+
+
+ if (vlc_code_mag == 0)
+ {
+ diff_vector = vlc_code_mag;
+ }
+ else
+ {
+ diff_vector = ((PV_ABS(vlc_code_mag) - 1) << (f_code - 1)) + residual + 1;
+ if (vlc_code_mag < 0)
+ {
+ diff_vector = -diff_vector;
+ }
+ }
+
+ *vector += (MOT)(diff_vector);
+
+ *vector = (MOT)((*vector + half_range) & mask) - half_range;
+
+ return PV_SUCCESS;
+}
+
+
+
+void mv_prediction(
+ VideoDecData *video,
+ int block,
+ MOT *mvx,
+ MOT *mvy
+)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ MOT *motxdata = video->motX;
+ MOT *motydata = video->motY;
+ int mbnum_col = video->mbnum_col;
+ int mbnum_row = video->mbnum_row;
+ uint8 *slice_nb = video->sliceNo;
+ int nMBPerRow = video->nMBPerRow;
+ int nMVPerRow = nMBPerRow << 1;
+ int mbnum = video->mbnum;
+ int p1x = 0, p2x = 0, p3x = 0;
+ int p1y = 0, p2y = 0, p3y = 0;
+ int rule1 = 0, rule2 = 0, rule3 = 0;
+ int indx;
+
+ indx = ((mbnum_col << 1) + (block & 1)) + ((mbnum_row << 1) + (block >> 1)) * nMVPerRow - 1; /* left block */
+
+ if (block & 1) /* block 1, 3 */
+ {
+ p1x = motxdata[indx];
+ p1y = motydata[indx];
+ rule1 = 1;
+ }
+ else /* block 0, 2 */
+ {
+ if (mbnum_col > 0 && slice_nb[mbnum] == slice_nb[mbnum-1])
+ {
+ p1x = motxdata[indx];
+ p1y = motydata[indx];
+ rule1 = 1;
+ }
+ }
+
+ indx = indx + 1 - nMVPerRow; /* upper_block */
+ if (block >> 1)
+ {
+ indx -= (block & 1);
+ p2x = motxdata[indx];
+ p2y = motydata[indx];
+ p3x = motxdata[indx + 1];
+ p3y = motydata[indx + 1];
+ rule2 = rule3 = 1;
+ }
+ else
+ { /* block 0,1 */
+ if (mbnum_row)
+ {
+ if (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow])
+ {
+ p2x = motxdata[indx];
+ p2y = motydata[indx];
+ rule2 = 1;
+ }
+ if (mbnum_col < nMBPerRow - 1 && slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow+1])
+ {
+ indx = indx + 2 - (block & 1);
+ p3x = motxdata[indx];
+ p3y = motydata[indx];
+ rule3 = 1;
+ }
+ }
+ }
+
+ if (rule1 + rule2 + rule3 > 1)
+ {
+ *mvx = (MOT)PV_MEDIAN(p1x, p2x, p3x);
+ *mvy = (MOT)PV_MEDIAN(p1y, p2y, p3y);
+ }
+ else if (rule1 + rule2 + rule3 == 1)
+ {
+ /* two of three are zero */
+ *mvx = (MOT)(p1x + p2x + p3x);
+ *mvy = (MOT)(p1y + p2y + p3y);
+ }
+ else
+ {
+ /* all MBs are outside the VOP */
+ *mvx = *mvy = 0;
+ }
+ /*----------------------------------------------------------------------------
+ ; Return nothing or data or data pointer
+ ----------------------------------------------------------------------------*/
+ return;
+}
+
+/***********************************************************CommentBegin******
+*
+* 3/30/2000 : initial modification to the new PV-Decoder Lib format.
+* 4/16/2001 : removed checking of status for PV_BitstreamFlushBits
+***********************************************************CommentEnd********/
+
+PV_STATUS PV_VlcDecMV(BitstreamDecVideo *stream, int *mv)
+{
+ PV_STATUS status = PV_SUCCESS;
+ uint code;
+
+ BitstreamShow13Bits(stream, &code);
+
+ if (code >> 12)
+ {
+ *mv = 0; /* Vector difference = 0 */
+ PV_BitstreamFlushBits(stream, 1);
+ return PV_SUCCESS;
+ }
+
+ if (code >= 512)
+ {
+ code = (code >> 8) - 2;
+ PV_BitstreamFlushBits(stream, PV_TMNMVtab0[code].len + 1);
+ *mv = PV_TMNMVtab0[code].val;
+ return status;
+ }
+
+ if (code >= 128)
+ {
+ code = (code >> 2) - 32;
+ PV_BitstreamFlushBits(stream, PV_TMNMVtab1[code].len + 1);
+ *mv = PV_TMNMVtab1[code].val;
+ return status;
+ }
+
+ if (code < 4)
+ {
+ *mv = -1;
+ return PV_FAIL;
+ }
+
+ code -= 4;
+
+ PV_BitstreamFlushBits(stream, PV_TMNMVtab2[code].len + 1);
+
+ *mv = PV_TMNMVtab2[code].val;
+ return status;
+}
+
+
+/***********************************************************CommentBegin******
+* 3/30/2000 : initial modification to the new PV-Decoder Lib
+* format and the change of error-handling method.
+* 4/16/01 : removed status checking of PV_BitstreamFlushBits
+***********************************************************CommentEnd********/
+
+int PV_VlcDecMCBPC_com_intra(BitstreamDecVideo *stream)
+{
+ uint code;
+
+ BitstreamShowBits16(stream, 9, &code);
+
+
+ if (code < 8)
+ {
+ return VLC_CODE_ERROR;
+ }
+
+ code >>= 3;
+
+ if (code >= 32)
+ {
+ PV_BitstreamFlushBits(stream, 1);
+ return 3;
+ }
+
+ PV_BitstreamFlushBits(stream, PV_MCBPCtabintra[code].len);
+
+ return PV_MCBPCtabintra[code].val;
+}
+
+
+/***********************************************************CommentBegin******
+*
+* 3/30/2000 : initial modification to the new PV-Decoder Lib
+* format and the change of error-handling method.
+* 4/16/2001 : removed checking of return status of PV_BitstreamFlushBits
+***********************************************************CommentEnd********/
+
+int PV_VlcDecMCBPC_com_inter(BitstreamDecVideo *stream)
+{
+ uint code;
+
+ BitstreamShowBits16(stream, 9, &code);
+
+ if (code == 0)
+ {
+ return VLC_CODE_ERROR;
+ }
+ else if (code >= 256)
+ {
+ PV_BitstreamFlushBits(stream, 1);
+ return 0;
+ }
+
+ PV_BitstreamFlushBits(stream, PV_MCBPCtab[code].len);
+ return PV_MCBPCtab[code].val;
+}
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+int PV_VlcDecMCBPC_com_inter_H263(BitstreamDecVideo *stream)
+{
+ uint code;
+
+ BitstreamShow13Bits(stream, &code);
+
+ if (code < 8)
+ {
+ return VLC_CODE_ERROR;
+ }
+ else if (code >= 4096)
+ {
+ PV_BitstreamFlushBits(stream, 1);
+ return 0;
+ }
+ if (code >= 16)
+ {
+ PV_BitstreamFlushBits(stream, PV_MCBPCtab[code >> 4].len);
+ return PV_MCBPCtab[code >> 4].val;
+ }
+ else
+ {
+ PV_BitstreamFlushBits(stream, PV_MCBPCtab1[code - 8].len);
+ return PV_MCBPCtab1[code - 8].val;
+ }
+}
+#endif
+/***********************************************************CommentBegin******
+* 3/30/2000 : initial modification to the new PV-Decoder Lib
+* format and the change of error-handling method.
+* 4/16/2001 : removed status checking for PV_BitstreamFlushBits
+***********************************************************CommentEnd********/
+
+int PV_VlcDecCBPY(BitstreamDecVideo *stream, int intra)
+{
+ int CBPY = 0;
+ uint code;
+
+ BitstreamShowBits16(stream, 6, &code);
+
+
+ if (code < 2)
+ {
+ return -1;
+ }
+ else if (code >= 48)
+ {
+ PV_BitstreamFlushBits(stream, 2);
+ CBPY = 15;
+ }
+ else
+ {
+ PV_BitstreamFlushBits(stream, PV_CBPYtab[code].len);
+ CBPY = PV_CBPYtab[code].val;
+ }
+
+ if (intra == 0) CBPY = 15 - CBPY;
+ CBPY = CBPY & 15;
+ return CBPY;
+}
+
+
+/***********************************************************CommentBegin******
+* 3/31/2000 : initial modification to the new PV-Decoder Lib format.
+*
+* 8/23/2000 : optimize the function by removing unnecessary BitstreamShowBits()
+* function calls.
+*
+* 9/6/2000 : change the API to check for end-of-buffer for proper
+* termination of decoding process.
+***********************************************************CommentEnd********/
+PV_STATUS PV_VlcDecIntraDCPredSize(BitstreamDecVideo *stream, int compnum, uint *DC_size)
+{
+ PV_STATUS status = PV_FAIL; /* 07/09/01 */
+ uint code;
+
+ *DC_size = 0;
+ if (compnum < 4) /* luminance block */
+ {
+
+ BitstreamShowBits16(stream, 11, &code);
+
+ if (code == 1)
+ {
+ *DC_size = 12;
+ PV_BitstreamFlushBits(stream, 11);
+ return PV_SUCCESS;
+ }
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 11;
+ PV_BitstreamFlushBits(stream, 10);
+ return PV_SUCCESS;
+ }
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 10;
+ PV_BitstreamFlushBits(stream, 9);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 9;
+ PV_BitstreamFlushBits(stream, 8);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 8;
+ PV_BitstreamFlushBits(stream, 7);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 7;
+ PV_BitstreamFlushBits(stream, 6);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 6;
+ PV_BitstreamFlushBits(stream, 5);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 5;
+ PV_BitstreamFlushBits(stream, 4);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 4;
+ PV_BitstreamFlushBits(stream, 3);
+ return PV_SUCCESS;
+ }
+ else if (code == 2)
+ {
+ *DC_size = 3;
+ PV_BitstreamFlushBits(stream, 3);
+ return PV_SUCCESS;
+ }
+ else if (code == 3)
+ {
+ *DC_size = 0;
+ PV_BitstreamFlushBits(stream, 3);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 2)
+ {
+ *DC_size = 2;
+ PV_BitstreamFlushBits(stream, 2);
+ return PV_SUCCESS;
+ }
+ else if (code == 3)
+ {
+ *DC_size = 1;
+ PV_BitstreamFlushBits(stream, 2);
+ return PV_SUCCESS;
+ }
+ }
+ else /* chrominance block */
+ {
+
+ BitstreamShow13Bits(stream, &code);
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 12;
+ PV_BitstreamFlushBits(stream, 12);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 11;
+ PV_BitstreamFlushBits(stream, 11);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 10;
+ PV_BitstreamFlushBits(stream, 10);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 9;
+ PV_BitstreamFlushBits(stream, 9);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 8;
+ PV_BitstreamFlushBits(stream, 8);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 7;
+ PV_BitstreamFlushBits(stream, 7);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 6;
+ PV_BitstreamFlushBits(stream, 6);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 5;
+ PV_BitstreamFlushBits(stream, 5);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 4;
+ PV_BitstreamFlushBits(stream, 4);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ if (code == 1)
+ {
+ *DC_size = 3;
+ PV_BitstreamFlushBits(stream, 3);
+ return PV_SUCCESS;
+ }
+
+ code >>= 1;
+ {
+ *DC_size = (int)(3 - code);
+ PV_BitstreamFlushBits(stream, 2);
+ return PV_SUCCESS;
+ }
+ }
+
+ return status;
+}
+
+/***********************************************************CommentBegin******
+*
+*
+* 3/30/2000 : initial modification to the new PV-Decoder Lib
+* format and the change of error-handling method.
+*
+***********************************************************CommentEnd********/
+
+
+
+PV_STATUS VlcDecTCOEFIntra(BitstreamDecVideo *stream, Tcoef *pTcoef)
+{
+ uint code;
+ const VLCtab2 *tab;
+
+ BitstreamShow13Bits(stream, &code);
+
+ /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFIntra */
+ /* if(GetTcoeffIntra(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
+ if (code >= 1024)
+ {
+ tab = &PV_DCT3Dtab3[(code >> 6) - 16];
+ }
+ else
+ {
+ if (code >= 256)
+ {
+ tab = &PV_DCT3Dtab4[(code >> 3) - 32];
+ }
+ else
+ {
+ if (code >= 16)
+ {
+ tab = &PV_DCT3Dtab5[(code>>1) - 8];
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint) tab->run; //(tab->val >> 8) & 255;
+ pTcoef->level = (int) tab->level; //tab->val & 255;
+ pTcoef->last = (uint) tab->last; //(tab->val >> 16) & 1;
+
+
+ /* the following is modified for 3-mode escape -- boon */
+ if (tab->level != 0xFF)
+ {
+ return PV_SUCCESS;
+ }
+
+ //if (((tab->run<<8)|(tab->level)|(tab->last<<16)) == VLC_ESCAPE_CODE)
+
+ if (!pTcoef->sign)
+ {
+ /* first escape mode. level is offset */
+ BitstreamShow13Bits(stream, &code);
+
+ /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFIntra */
+ /* if(GetTcoeffIntra(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
+ if (code >= 1024)
+ {
+ tab = &PV_DCT3Dtab3[(code >> 6) - 16];
+ }
+ else
+ {
+ if (code >= 256)
+ {
+ tab = &PV_DCT3Dtab4[(code >> 3) - 32];
+ }
+ else
+ {
+ if (code >= 16)
+ {
+ tab = &PV_DCT3Dtab5[(code>>1) - 8];
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+
+ /* sign bit */
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run; //(tab->val >> 8) & 255;
+ pTcoef->level = (int)tab->level; //tab->val & 255;
+ pTcoef->last = (uint)tab->last; //(tab->val >> 16) & 1;
+
+
+ /* need to add back the max level */
+ if ((pTcoef->last == 0 && pTcoef->run > 14) || (pTcoef->last == 1 && pTcoef->run > 20))
+ {
+ return PV_FAIL;
+ }
+ pTcoef->level = pTcoef->level + intra_max_level[pTcoef->last][pTcoef->run];
+
+
+ }
+ else
+ {
+ uint run_offset;
+ run_offset = BitstreamRead1Bits_INLINE(stream);
+
+ if (!run_offset)
+ {
+ /* second escape mode. run is offset */
+ BitstreamShow13Bits(stream, &code);
+
+ /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFIntra */
+ /* if(GetTcoeffIntra(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
+ if (code >= 1024)
+ {
+ tab = &PV_DCT3Dtab3[(code >> 6) - 16];
+ }
+ else
+ {
+ if (code >= 256)
+ {
+ tab = &PV_DCT3Dtab4[(code >> 3) - 32];
+ }
+ else
+ {
+ if (code >= 16)
+ {
+ tab = &PV_DCT3Dtab5[(code>>1) - 8];
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ /* sign bit */
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run; //(tab->val >> 8) & 255;
+ pTcoef->level = (int)tab->level; //tab->val & 255;
+ pTcoef->last = (uint)tab->last; //(tab->val >> 16) & 1;
+
+
+
+ /* need to add back the max run */
+ if (pTcoef->last)
+ {
+ if (pTcoef->level > 8)
+ {
+ return PV_FAIL;
+ }
+ pTcoef->run = pTcoef->run + intra_max_run1[pTcoef->level] + 1;
+ }
+ else
+ {
+ if (pTcoef->level > 27)
+ {
+ return PV_FAIL;
+ }
+ pTcoef->run = pTcoef->run + intra_max_run0[pTcoef->level] + 1;
+ }
+
+
+ }
+ else
+ {
+
+ code = BitstreamReadBits16_INLINE(stream, 8);
+ pTcoef->last = code >> 7;
+ pTcoef->run = (code >> 1) & 0x3F;
+ pTcoef->level = (int)(BitstreamReadBits16_INLINE(stream, 13) >> 1);
+
+ if (pTcoef->level >= 2048)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = 4096 - pTcoef->level;
+ }
+ else
+ {
+ pTcoef->sign = 0;
+ }
+ } /* flc */
+ }
+
+ return PV_SUCCESS;
+
+} /* VlcDecTCOEFIntra */
+
+PV_STATUS VlcDecTCOEFInter(BitstreamDecVideo *stream, Tcoef *pTcoef)
+{
+ uint code;
+ const VLCtab2 *tab;
+
+ BitstreamShow13Bits(stream, &code);
+
+ /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFInter */
+ /* if(GetTcoeffInter(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
+ if (code >= 1024)
+ {
+ tab = &PV_DCT3Dtab0[(code >> 6) - 16];
+ }
+ else
+ {
+ if (code >= 256)
+ {
+ tab = &PV_DCT3Dtab1[(code >> 3) - 32];
+ }
+ else
+ {
+ if (code >= 16)
+ {
+ tab = &PV_DCT3Dtab2[(code>>1) - 8];
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+ }
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run; //(tab->val >> 4) & 255;
+ pTcoef->level = (int)tab->level; //tab->val & 15;
+ pTcoef->last = (uint)tab->last; //(tab->val >> 12) & 1;
+
+ /* the following is modified for 3-mode escape -- boon */
+ if (tab->run != 0xBF)
+ {
+ return PV_SUCCESS;
+ }
+ //if (((tab->run<<4)|(tab->level)|(tab->last<<12)) == VLC_ESCAPE_CODE)
+
+
+ if (!pTcoef->sign)
+ {
+ /* first escape mode. level is offset */
+ BitstreamShow13Bits(stream, &code);
+
+ /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFInter */
+ /* if(GetTcoeffInter(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
+ if (code >= 1024)
+ {
+ tab = &PV_DCT3Dtab0[(code >> 6) - 16];
+ }
+ else
+ {
+ if (code >= 256)
+ {
+ tab = &PV_DCT3Dtab1[(code >> 3) - 32];
+ }
+ else
+ {
+ if (code >= 16)
+ {
+ tab = &PV_DCT3Dtab2[(code>>1) - 8];
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+ }
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run; //(tab->val >> 4) & 255;
+ pTcoef->level = (int)tab->level; //tab->val & 15;
+ pTcoef->last = (uint)tab->last; //(tab->val >> 12) & 1;
+
+ /* need to add back the max level */
+ if ((pTcoef->last == 0 && pTcoef->run > 26) || (pTcoef->last == 1 && pTcoef->run > 40))
+ {
+ return PV_FAIL;
+ }
+ pTcoef->level = pTcoef->level + inter_max_level[pTcoef->last][pTcoef->run];
+ }
+ else
+ {
+ uint run_offset;
+ run_offset = BitstreamRead1Bits_INLINE(stream);
+
+ if (!run_offset)
+ {
+ /* second escape mode. run is offset */
+ BitstreamShow13Bits(stream, &code);
+
+ /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFInter */
+ /*if(GetTcoeffInter(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
+ if (code >= 1024)
+ {
+ tab = &PV_DCT3Dtab0[(code >> 6) - 16];
+ }
+ else
+ {
+ if (code >= 256)
+ {
+ tab = &PV_DCT3Dtab1[(code >> 3) - 32];
+ }
+ else
+ {
+ if (code >= 16)
+ {
+ tab = &PV_DCT3Dtab2[(code>>1) - 8];
+ }
+ else
+ {
+ return PV_FAIL;
+ }
+ }
+ }
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run; //(tab->val >> 4) & 255;
+ pTcoef->level = (int)tab->level; //tab->val & 15;
+ pTcoef->last = (uint)tab->last; //(tab->val >> 12) & 1;
+
+ /* need to add back the max run */
+ if (pTcoef->last)
+ {
+ if (pTcoef->level > 3)
+ {
+ return PV_FAIL;
+ }
+ pTcoef->run = pTcoef->run + inter_max_run1[pTcoef->level] + 1;
+ }
+ else
+ {
+ if (pTcoef->level > 12)
+ {
+ return PV_FAIL;
+ }
+ pTcoef->run = pTcoef->run + inter_max_run0[pTcoef->level] + 1;
+ }
+ }
+ else
+ {
+
+ code = BitstreamReadBits16_INLINE(stream, 8);
+ pTcoef->last = code >> 7;
+ pTcoef->run = (code >> 1) & 0x3F;
+ pTcoef->level = (int)(BitstreamReadBits16_INLINE(stream, 13) >> 1);
+
+
+
+ if (pTcoef->level >= 2048)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = 4096 - pTcoef->level;
+ }
+ else
+ {
+ pTcoef->sign = 0;
+ }
+ } /* flc */
+ }
+
+ return PV_SUCCESS;
+
+} /* VlcDecTCOEFInter */
+
+/*=======================================================
+ Function: VlcDecTCOEFShortHeader()
+ Date : 04/27/99
+ Purpose : New function used in decoding of video planes
+ with short header
+ Modified: 05/23/2000
+ for new decoder structure.
+=========================================================*/
+PV_STATUS VlcDecTCOEFShortHeader(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra*/)
+{
+ uint code;
+ const VLCtab2 *tab;
+
+ BitstreamShow13Bits(stream, &code);
+
+ /*intra = 0;*/
+
+ if (code >= 1024) tab = &PV_DCT3Dtab0[(code >> 6) - 16];
+ else
+ {
+ if (code >= 256) tab = &PV_DCT3Dtab1[(code >> 3) - 32];
+ else
+ {
+ if (code >= 16) tab = &PV_DCT3Dtab2[(code>>1) - 8];
+ else return PV_FAIL;
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run;//(tab->val >> 4) & 255;
+ pTcoef->level = (int)tab->level;//tab->val & 15;
+ pTcoef->last = (uint)tab->last;//(tab->val >> 12) & 1;
+
+ /* the following is modified for 3-mode escape -- boon */
+ if (((tab->run << 4) | (tab->level) | (tab->last << 12)) != VLC_ESCAPE_CODE) /* ESCAPE */
+ {
+ return PV_SUCCESS;
+ }
+
+
+ /* escape mode 4 - H.263 type */
+ pTcoef->last = pTcoef->sign; /* Last */
+ pTcoef->run = BitstreamReadBits16_INLINE(stream, 6); /* Run */
+ pTcoef->level = (int) BitstreamReadBits16_INLINE(stream, 8); /* Level */
+
+ if (pTcoef->level == 0 || pTcoef->level == 128)
+ {
+ return PV_FAIL;
+ }
+
+ if (pTcoef->level > 128)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = 256 - pTcoef->level;
+ }
+ else
+ {
+ pTcoef->sign = 0;
+ }
+
+
+
+ return PV_SUCCESS;
+
+} /* VlcDecTCOEFShortHeader */
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+PV_STATUS VlcDecTCOEFShortHeader_AnnexI(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra*/)
+{
+ uint code;
+ const VLCtab2 *tab;
+
+ BitstreamShow13Bits(stream, &code);
+
+ /*intra = 0;*/
+
+ if (code >= 1024) tab = &PV_DCT3Dtab6[(code >> 6) - 16];
+ else
+ {
+ if (code >= 256) tab = &PV_DCT3Dtab7[(code >> 3) - 32];
+ else
+ {
+ if (code >= 16) tab = &PV_DCT3Dtab8[(code>>1) - 8];
+ else return PV_FAIL;
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run;//(tab->val >> 4) & 255;
+ pTcoef->level = (int)tab->level;//tab->val & 15;
+ pTcoef->last = (uint)tab->last;//(tab->val >> 12) & 1;
+
+ /* the following is modified for 3-mode escape -- boon */
+ if (((tab->run << 6) | (tab->level) | (tab->last << 12)) != VLC_ESCAPE_CODE) /* ESCAPE */
+ {
+ return PV_SUCCESS;
+ }
+ /* escape mode 4 - H.263 type */
+ pTcoef->last = pTcoef->sign; /* Last */
+ pTcoef->run = BitstreamReadBits16(stream, 6); /* Run */
+ pTcoef->level = (int) BitstreamReadBits16(stream, 8); /* Level */
+
+ if (pTcoef->level == 0 || pTcoef->level == 128)
+ {
+ return PV_FAIL;
+ }
+
+
+ if (pTcoef->level > 128)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = 256 - pTcoef->level;
+ }
+ else pTcoef->sign = 0;
+
+
+
+ return PV_SUCCESS;
+
+} /* VlcDecTCOEFShortHeader_AnnexI */
+
+PV_STATUS VlcDecTCOEFShortHeader_AnnexT(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra*/)
+{
+ uint code;
+ const VLCtab2 *tab;
+
+ BitstreamShow13Bits(stream, &code);
+
+ /*intra = 0;*/
+
+ if (code >= 1024) tab = &PV_DCT3Dtab0[(code >> 6) - 16];
+ else
+ {
+ if (code >= 256) tab = &PV_DCT3Dtab1[(code >> 3) - 32];
+ else
+ {
+ if (code >= 16) tab = &PV_DCT3Dtab2[(code>>1) - 8];
+ else return PV_FAIL;
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run;//(tab->val >> 4) & 255;
+ pTcoef->level = (int)tab->level;//tab->val & 15;
+ pTcoef->last = (uint)tab->last;//(tab->val >> 12) & 1;
+
+ /* the following is modified for 3-mode escape -- */
+ if (((tab->run << 4) | (tab->level) | (tab->last << 12)) != VLC_ESCAPE_CODE) /* ESCAPE */
+ {
+ return PV_SUCCESS;
+ }
+ /* escape mode 4 - H.263 type */
+ pTcoef->last = pTcoef->sign; /* Last */
+ pTcoef->run = BitstreamReadBits16(stream, 6); /* Run */
+ pTcoef->level = (int) BitstreamReadBits16(stream, 8); /* Level */
+
+ if (pTcoef->level == 0)
+ {
+ return PV_FAIL;
+ }
+
+ if (pTcoef->level >= 128)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = 256 - pTcoef->level;
+ }
+ else
+ {
+ pTcoef->sign = 0;
+ }
+
+ if (pTcoef->level == 128)
+ {
+ code = BitstreamReadBits16(stream, 11); /* ANNEX_T */
+
+ code = (code >> 6 & 0x1F) | (code << 5 & 0x7ff);
+ if (code > 1024)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = (2048 - code);
+ }
+ else
+ {
+ pTcoef->sign = 0;
+ pTcoef->level = code;
+ }
+ }
+
+ return PV_SUCCESS;
+
+} /* VlcDecTCOEFShortHeader */
+
+
+PV_STATUS VlcDecTCOEFShortHeader_AnnexIT(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra*/)
+{
+ uint code;
+ const VLCtab2 *tab;
+
+ BitstreamShow13Bits(stream, &code);
+
+ /*intra = 0;*/
+
+ if (code >= 1024) tab = &PV_DCT3Dtab6[(code >> 6) - 16];
+ else
+ {
+ if (code >= 256) tab = &PV_DCT3Dtab7[(code >> 3) - 32];
+ else
+ {
+ if (code >= 16) tab = &PV_DCT3Dtab8[(code>>1) - 8];
+ else return PV_FAIL;
+ }
+ }
+
+ PV_BitstreamFlushBits(stream, tab->len + 1);
+ pTcoef->sign = (code >> (12 - tab->len)) & 1;
+ pTcoef->run = (uint)tab->run;//(tab->val >> 4) & 255;
+ pTcoef->level = (int)tab->level;//tab->val & 15;
+ pTcoef->last = (uint)tab->last;//(tab->val >> 12) & 1;
+
+ /* the following is modified for 3-mode escape -- */
+ if (((tab->run << 6) | (tab->level) | (tab->last << 12)) != VLC_ESCAPE_CODE) /* ESCAPE */
+ {
+ return PV_SUCCESS;
+ }
+ /* escape mode 4 - H.263 type */
+ pTcoef->last = pTcoef->sign; /* Last */
+ pTcoef->run = BitstreamReadBits16(stream, 6); /* Run */
+ pTcoef->level = (int) BitstreamReadBits16(stream, 8); /* Level */
+
+ if (pTcoef->level == 0)
+ {
+ return PV_FAIL;
+ }
+
+ if (pTcoef->level >= 128)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = 256 - pTcoef->level;
+ }
+ else
+ {
+ pTcoef->sign = 0;
+ }
+
+ if (pTcoef->level == 128)
+ {
+ code = BitstreamReadBits16(stream, 11); /* ANNEX_T */
+
+ code = (code >> 6 & 0x1F) | (code << 5 & 0x7ff);
+ if (code > 1024)
+ {
+ pTcoef->sign = 1;
+ pTcoef->level = (2048 - code);
+ }
+ else
+ {
+ pTcoef->sign = 0;
+ pTcoef->level = code;
+ }
+ }
+
+
+ return PV_SUCCESS;
+
+} /* VlcDecTCOEFShortHeader_AnnexI */
+#endif
+/***********************************************************CommentBegin******
+* 3/30/2000 : initial modification to the new PV-Decoder Lib
+* format and the change of error-handling method.
+* The coefficient is now returned thru a pre-
+* initialized parameters for speedup.
+*
+***********************************************************CommentEnd********/
+
+
+PV_STATUS RvlcDecTCOEFInter(BitstreamDecVideo *stream, Tcoef *pTcoef)
+{
+ uint code, mask;
+ const VLCtab2 *tab2;
+ int count, len, num[2] = {0, 0} /* 01/30/01 */;
+
+ mask = 0x4000; /* mask 100000000000000 */
+ BitstreamShow15Bits(stream, &code); /* 03/07/01 */
+
+ len = 1;
+
+ // 09/20/99 Escape mode
+ /// Bitstream Exchange
+ if (code < 2048)
+ {
+ PV_BitstreamFlushBits(stream, 5);
+ pTcoef->last = BitstreamRead1Bits_INLINE(stream);
+ pTcoef->run = BitstreamReadBits16_INLINE(stream, 6);
+ // 09/20/99 New marker bit
+ PV_BitstreamFlushBits(stream, 1);
+ // 09/20/99 The length for LEVEL used to be 7 in the old version
+ pTcoef->level = (int)(BitstreamReadBits16_INLINE(stream, 12) >> 1);
+ // 09/20/99 Another new marker bit
+// PV_BitstreamFlushBitsCheck(stream, 1);
+ pTcoef->sign = BitstreamReadBits16_INLINE(stream, 5) & 0x1; /* fix 3/13/01 */
+ return PV_SUCCESS;
+ }
+
+ if (code & mask)
+ {
+ count = 1;
+ while (mask && count > 0) /* fix 3/28/01 */
+ {
+ mask = mask >> 1;
+ if (code & mask)
+ count--;
+ else
+ num[0]++; /* number of zeros in the middle */
+ len++;
+ }
+ }
+ else
+ {
+ count = 2;
+ while (mask && count > 0) /* fix 3/28/01 */
+ {
+ mask = mask >> 1;
+ if (!(code & mask))
+ count--;
+ else
+ num[count-1]++; /* number of ones in the middle */
+ len++;
+ }
+ }
+
+ code = code & 0x7fff;
+ code = code >> (15 - (len + 1));
+
+ /* 1/30/01, add fast decoding algorithm here */
+ /* code is in two forms : 0xxxx0xxx00 or 0xxx0xxx01
+ num[1] and num[0] x
+ or : 1xxxxx10 or 1xxxxx11
+ num[0] x */
+
+ /* len+1 is the length of the above */
+
+ if (num[1] > 10 || num[0] > 11) /* invalid RVLC code */
+ return PV_FAIL;
+
+ if (code&(1 << len))
+ tab2 = RvlcDCTtabInter + 146 + (num[0] << 1) + (code & 1);
+ else
+ tab2 = RvlcDCTtabInter + ptrRvlcTab[num[1]] + (num[0] << 1) + (code & 1);
+
+ PV_BitstreamFlushBits(stream, (int) tab2->len);
+ pTcoef->run = (uint)tab2->run;//(tab->val >> 8) & 255;
+ pTcoef->level = (int)tab2->level;//tab->val & 255;
+ pTcoef->last = (uint)tab2->last;//(tab->val >> 16) & 1;
+
+ pTcoef->sign = BitstreamRead1Bits_INLINE(stream);
+ return PV_SUCCESS;
+} /* RvlcDecTCOEFInter */
+
+PV_STATUS RvlcDecTCOEFIntra(BitstreamDecVideo *stream, Tcoef *pTcoef)
+{
+ uint code, mask;
+ const VLCtab2 *tab2;
+ int count, len, num[2] = {0, 0} /* 01/30/01 */;
+
+ mask = 0x4000; /* mask 100000000000000 */
+ BitstreamShow15Bits(stream, &code);
+
+ len = 1;
+
+ // 09/20/99 Escape mode
+ /// Bitstream Exchange
+ if (code < 2048)
+ {
+ PV_BitstreamFlushBits(stream, 5);
+ pTcoef->last = BitstreamRead1Bits_INLINE(stream);
+ pTcoef->run = BitstreamReadBits16_INLINE(stream, 6);
+ // 09/20/99 New marker bit
+ PV_BitstreamFlushBits(stream, 1);
+ // 09/20/99 The length for LEVEL used to be 7 in the old version
+ pTcoef->level = (int)(BitstreamReadBits16_INLINE(stream, 12) >> 1);
+ // 09/20/99 Another new marker bit
+// PV_BitstreamFlushBitsCheck(stream, 1);
+ pTcoef->sign = BitstreamReadBits16_INLINE(stream, 5) & 0x1; /* fix 03/13/01 */
+ return PV_SUCCESS;
+ }
+
+ if (code & mask)
+ {
+ count = 1;
+ while (mask && count > 0) /* fix 03/28/01 */
+ {
+ mask = mask >> 1;
+ if (code & mask)
+ count--;
+ else
+ num[0]++; /* number of zeros in the middle */
+ len++;
+ }
+ }
+ else
+ {
+ count = 2;
+ while (mask && count > 0) /* fix 03/28/01 */
+ {
+ mask = mask >> 1;
+ if (!(code & mask))
+ count--;
+ else
+ num[count-1]++; /* number of ones in the middle */
+ len++;
+ }
+ }
+
+ code = code & 0x7fff;
+ code = code >> (15 - (len + 1));
+
+ /* 1/30/01, add fast decoding algorithm here */
+ /* code is in two forms : 0xxxx0xxx00 or 0xxx0xxx01
+ num[1] and num[0] x
+ or : 1xxxxx10 or 1xxxxx11
+ num[0] x */
+
+ /* len+1 is the length of the above */
+
+ if (num[1] > 10 || num[0] > 11) /* invalid RVLC code */
+ return PV_FAIL;
+
+ if (code & (1 << len))
+ tab2 = RvlcDCTtabIntra + 146 + (num[0] << 1) + (code & 1);
+ else
+ tab2 = RvlcDCTtabIntra + ptrRvlcTab[num[1]] + (num[0] << 1) + (code & 1);
+
+ PV_BitstreamFlushBits(stream, (int) tab2->len);
+ pTcoef->run = (uint)tab2->run;//(tab->val >> 8) & 255;
+ pTcoef->level = (int)tab2->level;//tab->val & 255;
+ pTcoef->last = (uint)tab2->last;//(tab->val >> 16) & 1;
+
+ pTcoef->sign = BitstreamRead1Bits_INLINE(stream);
+ return PV_SUCCESS;
+} /* RvlcDecTCOEFIntra */
+
diff --git a/media/codecs/m4v_h263/dec/src/vlc_decode.h b/media/codecs/m4v_h263/dec/src/vlc_decode.h
new file mode 100644
index 0000000..e242820
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/vlc_decode.h
@@ -0,0 +1,122 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+-------------------------------------------------------------------
+ MPEG-4 Simple Profile Video Decoder
+-------------------------------------------------------------------
+*
+* This software module was originally developed by
+*
+* Paulo Nunes (IST / ACTS-MoMuSyS)
+*
+* in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
+* This software module is an implementation of a part of one or more MPEG-4
+* Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
+* license to this software module or modifications thereof for use in hardware
+* or software products claiming conformance to the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* Those intending to use this software module in hardware or software products
+* are advised that its use may infringe existing patents. The original
+* developer of this software module and his/her company, the subsequent
+* editors and their companies, and ISO/IEC have no liability for use of this
+* software module or modifications thereof in an implementation. Copyright is
+* not released for non MPEG-4 Video (ISO/IEC 14496-2) Standard conforming
+* products.
+*
+* ACTS-MoMuSys partners retain full right to use the code for his/her own
+* purpose, assign or donate the code to a third party and to inhibit third
+* parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) Standard
+* conforming products. This copyright notice must be included in all copies or
+* derivative works.
+*
+* Copyright (c) 1996
+*
+*****************************************************************************/
+
+/***********************************************************HeaderBegin*******
+*
+* File: vlc_dec.h
+*
+* Author: Paulo Nunes (IST) - Paulo.Nunes@lx.it.pt
+* Created:
+*
+* Description: This is the header file for the "vlcdec" module.
+*
+* Notes:
+*
+* Modified: 9-May-96 Paulo Nunes: Reformatted. New headers.
+*
+* ================= PacketVideo Modification ================================
+*
+* 3/30/00 : initial modification to the
+* new PV-Decoder Lib format.
+*
+***********************************************************CommentEnd********/
+
+
+#ifndef _VLCDECODE_H_
+#define _VLCDECODE_H_
+
+#include "mp4lib_int.h"
+
+#define VLC_ERROR_DETECTED(x) ((x) < 0)
+#define VLC_IO_ERROR (-1)
+#define VLC_CODE_ERROR (-2)
+#define VLC_MB_STUFFING (-4)
+#define VLC_NO_LAST_BIT (-5)
+
+#define VLC_ESCAPE_CODE 7167
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+ PV_STATUS DecodeUserData(BitstreamDecVideo *stream);
+ PV_STATUS PV_GetMBvectors(VideoDecData *, uint mode);
+ PV_STATUS PV_DecodeMBVec(BitstreamDecVideo *stream, MOT *mv_x, MOT *mv_y, int f_code_f);
+ PV_STATUS PV_DeScaleMVD(int f_code, int residual, int vlc_code_mag, MOT *vector);
+
+ PV_STATUS PV_VlcDecMV(BitstreamDecVideo *stream, int *mv);
+ int PV_VlcDecMCBPC_com_intra(BitstreamDecVideo *stream);
+ int PV_VlcDecMCBPC_com_inter(BitstreamDecVideo *stream);
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ int PV_VlcDecMCBPC_com_inter_H263(BitstreamDecVideo *stream);
+ PV_STATUS VlcDecTCOEFShortHeader_AnnexI(BitstreamDecVideo *stream, Tcoef *pTcoef);
+ PV_STATUS VlcDecTCOEFShortHeader_AnnexT(BitstreamDecVideo *stream, Tcoef *pTcoef); /* ANNEX_T */
+ PV_STATUS VlcDecTCOEFShortHeader_AnnexIT(BitstreamDecVideo *stream, Tcoef *pTcoef);
+#endif
+ int PV_VlcDecCBPY(BitstreamDecVideo *stream, int intra);
+
+ PV_STATUS VlcDecTCOEFIntra(BitstreamDecVideo *stream, Tcoef *pTcoef);
+ PV_STATUS VlcDecTCOEFInter(BitstreamDecVideo *stream, Tcoef *pTcoef);
+ PV_STATUS VlcDecTCOEFShortHeader(BitstreamDecVideo *stream, Tcoef *pTcoef);
+ PV_STATUS RvlcDecTCOEFIntra(BitstreamDecVideo *stream, Tcoef *pTcoef);
+ PV_STATUS RvlcDecTCOEFInter(BitstreamDecVideo *stream, Tcoef *pTcoef);
+ PV_STATUS PV_VlcDecIntraDCPredSize(BitstreamDecVideo *stream, int compnum, uint *DC_size);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
diff --git a/media/codecs/m4v_h263/dec/src/vlc_dequant.cpp b/media/codecs/m4v_h263/dec/src/vlc_dequant.cpp
new file mode 100644
index 0000000..db13a48
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/vlc_dequant.cpp
@@ -0,0 +1,1152 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4dec_lib.h"
+#include "vlc_decode.h"
+#include "zigzag.h"
+
+
+typedef PV_STATUS(*VlcDecFuncP)(BitstreamDecVideo *stream, Tcoef *pTcoef);
+static const uint8 AC_rowcol[64] = { 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ };
+static const uint8 mask[8] = /* for fast bitmap */
+ {128, 64, 32, 16, 8, 4, 2, 1};
+
+
+
+/***********************************************************CommentBegin******
+*
+* -- VlcDequantMpegBlock -- Decodes the DCT coefficients of one 8x8 block and perform
+ dequantization using Mpeg mode.
+ Date: 08/08/2000
+
+ Modified: 3/21/01
+ Added pre IDCT clipping, new ACDC prediction structure, ACDC prediction clipping,
+ 16-bit int case, removed multiple zigzaging
+******************************************************************************/
+
+#ifdef PV_SUPPORT_MAIN_PROFILE
+int VlcDequantMpegIntraBlock(void *vid, int comp, int switched,
+ uint8 *bitmapcol, uint8 *bitmaprow)
+{
+ VideoDecData *video = (VideoDecData*) vid;
+ Vol *currVol = video->vol[video->currLayer];
+ BitstreamDecVideo *stream = video->bitstream;
+ int16 *datablock = video->mblock->block[comp]; /* 10/20/2000, assume it has been reset of all-zero !!!*/
+ int mbnum = video->mbnum;
+ uint CBP = video->headerInfo.CBP[mbnum];
+ int QP = video->QPMB[mbnum];
+ typeDCStore *DC = video->predDC + mbnum;
+ int x_pos = video->mbnum_col;
+ typeDCACStore *DCAC_row = video->predDCAC_row + x_pos;
+ typeDCACStore *DCAC_col = video->predDCAC_col;
+ uint ACpred_flag = (uint) video->acPredFlag[mbnum];
+
+ /*** VLC *****/
+ int i, j, k;
+ Tcoef run_level;
+ int last, return_status;
+ VlcDecFuncP vlcDecCoeff;
+ int direction;
+ const int *inv_zigzag;
+ /*** Quantizer ****/
+ int dc_scaler;
+ int sum;
+ int *qmat;
+ int32 temp;
+
+ const int B_Xtab[6] = {0, 1, 0, 1, 2, 3};
+ const int B_Ytab[6] = {0, 0, 1, 1, 2, 3};
+
+ int16 *dcac_row, *dcac_col;
+
+ dcac_row = (*DCAC_row)[B_Xtab[comp]];
+ dcac_col = (*DCAC_col)[B_Ytab[comp]];
+
+
+ i = 1 - switched;
+
+#ifdef FAST_IDCT
+ *((uint32*)bitmapcol) = *((uint32*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+#endif
+
+
+ /* select which Huffman table to be used */
+ vlcDecCoeff = video->vlcDecCoeffIntra;
+
+ dc_scaler = (comp < 4) ? video->mblock->DCScalarLum : video->mblock->DCScalarChr;
+
+ /* enter the zero run decoding loop */
+ sum = 0;
+ qmat = currVol->iqmat;
+
+ /* perform only VLC decoding */
+ /* We cannot do DCACrecon before VLC decoding. 10/17/2000 */
+ doDCACPrediction(video, comp, datablock, &direction);
+ if (!ACpred_flag) direction = 0;
+ inv_zigzag = zigzag_inv + (ACpred_flag << 6) + (direction << 6);
+ if (CBP & (1 << (5 - comp)))
+ {
+ do
+ {
+ return_status = (*vlcDecCoeff)(stream, &run_level);
+ if (return_status != PV_SUCCESS)
+ {
+ last = 1;/* 11/1/2000 let it slips undetected, just like
+ in original version */
+ i = VLC_ERROR;
+ ACpred_flag = 0; /* no of coefficients should not get reset 03/07/2002 */
+ break;
+ }
+
+ i += run_level.run;
+ last = run_level.last;
+ if (i >= 64)
+ {
+ /* i = NCOEFF_BLOCK; */ /* 11/1/00 */
+ ACpred_flag = 0; /* no of coefficients should not get reset 03/07/2002 */
+ i = VLC_NO_LAST_BIT;
+ last = 1;
+ break;
+ }
+
+ k = inv_zigzag[i];
+
+ if (run_level.sign == 1)
+ {
+ datablock[k] -= run_level.level;
+ }
+ else
+ {
+ datablock[k] += run_level.level;
+ }
+
+ if (AC_rowcol[k])
+ {
+ temp = (int32)datablock[k] * qmat[k] * QP;
+ temp = (temp + (0x7 & (temp >> 31))) >> 3;
+ if (temp > 2047) temp = 2047;
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int) temp;
+
+#ifdef FAST_IDCT
+ bitmapcol[k&0x7] |= mask[k>>3];
+#endif
+ sum ^= temp;
+ }
+
+ i++;
+ }
+ while (!last);
+
+ }
+ else
+ {
+ i = 1; /* 04/26/01 needed for switched case */
+ }
+ ///// NEED TO DEQUANT THOSE PREDICTED AC COEFF
+ /* dequantize the rest of AC predicted coeff that haven't been dequant */
+ if (ACpred_flag)
+ {
+
+ i = NCOEFF_BLOCK; /* otherwise, FAST IDCT won't work correctly, 10/18/2000 */
+
+ if (!direction) /* check vertical */
+ {
+ dcac_row[0] = datablock[1];
+ dcac_row[1] = datablock[2];
+ dcac_row[2] = datablock[3];
+ dcac_row[3] = datablock[4];
+ dcac_row[4] = datablock[5];
+ dcac_row[5] = datablock[6];
+ dcac_row[6] = datablock[7];
+
+ for (j = 0, k = 8; k < 64; k += 8, j++)
+ {
+ if (dcac_col[j] = datablock[k])
+ { /* ACDC clipping 03/26/01 */
+ if (datablock[k] > 2047) dcac_col[j] = 2047;
+ else if (datablock[k] < -2048) dcac_col[j] = -2048;
+
+ temp = (int32)dcac_col[j] * qmat[k] * QP;
+ temp = (temp + (0x7 & (temp >> 31))) >> 3; /* 03/26/01*/
+ if (temp > 2047) temp = 2047;
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int)temp;
+ sum ^= temp; /* 7/5/01 */
+#ifdef FAST_IDCT
+ bitmapcol[0] |= mask[k>>3];
+#endif
+
+ }
+ }
+ for (k = 1; k < 8; k++)
+ {
+ if (datablock[k])
+ {
+ temp = (int32)datablock[k] * qmat[k] * QP;
+ temp = (temp + (0x7 & (temp >> 31))) >> 3; /* 03/26/01*/
+ if (temp > 2047) temp = 2047;
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int)temp;
+ sum ^= temp; /* 7/5/01 */
+#ifdef FAST_IDCT
+ bitmapcol[k] |= 128;
+#endif
+
+ }
+ }
+
+ }
+ else
+ {
+
+ dcac_col[0] = datablock[8];
+ dcac_col[1] = datablock[16];
+ dcac_col[2] = datablock[24];
+ dcac_col[3] = datablock[32];
+ dcac_col[4] = datablock[40];
+ dcac_col[5] = datablock[48];
+ dcac_col[6] = datablock[56];
+
+
+ for (j = 0, k = 1; k < 8; k++, j++)
+ {
+ if (dcac_row[j] = datablock[k])
+ { /* ACDC clipping 03/26/01 */
+ if (datablock[k] > 2047) dcac_row[j] = 2047;
+ else if (datablock[k] < -2048) dcac_row[j] = -2048;
+
+ temp = (int32)dcac_row[j] * qmat[k] * QP;
+ temp = (temp + (0x7 & (temp >> 31))) >> 3; /* 03/26/01 */
+ if (temp > 2047) temp = 2047;
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int)temp;
+ sum ^= temp;
+#ifdef FAST_IDCT
+ bitmapcol[k] |= 128;
+#endif
+
+ }
+ }
+
+ for (k = 8; k < 64; k += 8)
+ {
+ if (datablock[k])
+ {
+ temp = (int32)datablock[k] * qmat[k] * QP;
+ temp = (temp + (0x7 & (temp >> 31))) >> 3; /* 03/26/01 */
+ if (temp > 2047) temp = 2047;
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int)temp;
+ sum ^= temp;
+#ifdef FAST_IDCT
+ bitmapcol[0] |= mask[k>>3];
+#endif
+ }
+ }
+
+ }
+ }
+ else
+ {
+
+ /* Store the qcoeff-values needed later for prediction */
+
+ dcac_row[0] = datablock[1]; /* ACDC, no need for clipping */
+ dcac_row[1] = datablock[2];
+ dcac_row[2] = datablock[3];
+ dcac_row[3] = datablock[4];
+ dcac_row[4] = datablock[5];
+ dcac_row[5] = datablock[6];
+ dcac_row[6] = datablock[7];
+
+ dcac_col[0] = datablock[8];
+ dcac_col[1] = datablock[16];
+ dcac_col[2] = datablock[24];
+ dcac_col[3] = datablock[32];
+ dcac_col[4] = datablock[40];
+ dcac_col[5] = datablock[48];
+ dcac_col[6] = datablock[56];
+
+ for (k = 1; k < 8; k++)
+ {
+ if (datablock[k])
+ {
+ temp = (int32)datablock[k] * qmat[k] * QP;
+ temp = (temp + (0x7 & (temp >> 31))) >> 3; /* 03/26/01*/
+ if (temp > 2047) temp = 2047;
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int)temp;
+ sum ^= temp; /* 7/5/01 */
+#ifdef FAST_IDCT
+ bitmapcol[k] |= 128;
+#endif
+
+ }
+ }
+ for (k = 8; k < 64; k += 8)
+ {
+ if (datablock[k])
+ {
+ temp = (int32)datablock[k] * qmat[k] * QP;
+ temp = (temp + (0x7 & (temp >> 31))) >> 3; /* 03/26/01 */
+ if (temp > 2047) temp = 2047;
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int)temp;
+ sum ^= temp;
+#ifdef FAST_IDCT
+ bitmapcol[0] |= mask[k>>3];
+#endif
+ }
+ }
+
+ }
+
+
+
+ if (datablock[0])
+ {
+ temp = (int32)datablock[0] * dc_scaler;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[0] = (int)temp;
+ sum ^= temp;
+#ifdef FAST_IDCT
+ bitmapcol[0] |= 128;
+#endif
+ }
+
+ if ((sum & 1) == 0)
+ {
+ datablock[63] = datablock[63] ^ 0x1;
+#ifdef FAST_IDCT /* 7/5/01, need to update bitmap */
+ if (datablock[63])
+ bitmapcol[7] |= 1;
+#endif
+ i = (-64 & i) | NCOEFF_BLOCK; /* if i > -1 then i is set to NCOEFF_BLOCK */
+ }
+
+
+#ifdef FAST_IDCT
+ if (i > 10)
+ {
+ for (k = 1; k < 4; k++)
+ {
+ if (bitmapcol[k] != 0)
+ {
+ (*bitmaprow) |= mask[k];
+ }
+ }
+ }
+#endif
+
+ /* Store the qcoeff-values needed later for prediction */
+ (*DC)[comp] = datablock[0];
+ return i;
+
+}
+
+
+/***********************************************************CommentBegin******
+*
+* -- VlcDequantMpegInterBlock -- Decodes the DCT coefficients of one 8x8 block and perform
+ dequantization using Mpeg mode for INTER block.
+ Date: 08/08/2000
+ Modified: 3/21/01
+ clean up, added clipping, 16-bit int case, new ACDC prediction
+******************************************************************************/
+
+
+int VlcDequantMpegInterBlock(void *vid, int comp,
+ uint8 *bitmapcol, uint8 *bitmaprow)
+{
+ VideoDecData *video = (VideoDecData*) vid;
+ BitstreamDecVideo *stream = video->bitstream;
+ Vol *currVol = video->vol[video->currLayer];
+ int16 *datablock = video->mblock->block[comp]; /* 10/20/2000, assume it has been reset of all-zero !!!*/
+ int mbnum = video->mbnum;
+ int QP = video->QPMB[mbnum];
+ /*** VLC *****/
+ int i, k;
+ Tcoef run_level;
+ int last, return_status;
+ VlcDecFuncP vlcDecCoeff;
+
+ /*** Quantizer ****/
+ int sum;
+ int *qmat;
+
+ int32 temp;
+
+ i = 0 ;
+
+#ifdef FAST_IDCT
+ *((uint32*)bitmapcol) = *((uint32*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+#endif
+
+ /* select which Huffman table to be used */
+ vlcDecCoeff = video->vlcDecCoeffInter;
+
+ /* enter the zero run decoding loop */
+ sum = 0;
+ qmat = currVol->niqmat;
+ do
+ {
+ return_status = (*vlcDecCoeff)(stream, &run_level);
+ if (return_status != PV_SUCCESS)
+ {
+ last = 1;/* 11/1/2000 let it slips undetected, just like
+ in original version */
+ i = VLC_ERROR;
+ sum = 1; /* no of coefficients should not get reset 03/07/2002 */
+ break;
+ }
+
+ i += run_level.run;
+ last = run_level.last;
+ if (i >= 64)
+ {
+ /* i = NCOEFF_BLOCK; */ /* 11/1/00 */
+ //return VLC_NO_LAST_BIT;
+ i = VLC_NO_LAST_BIT;
+ last = 1;
+ sum = 1; /* no of coefficients should not get reset 03/07/2002 */
+ break;
+ }
+
+ k = zigzag_inv[i];
+
+ if (run_level.sign == 1)
+ {
+ temp = (-(int32)(2 * run_level.level + 1) * qmat[k] * QP + 15) >> 4; /* 03/23/01 */
+ if (temp < -2048) temp = - 2048;
+ }
+ else
+ {
+ temp = ((int32)(2 * run_level.level + 1) * qmat[k] * QP) >> 4; /* 03/23/01 */
+ if (temp > 2047) temp = 2047;
+ }
+
+ datablock[k] = (int)temp;
+
+#ifdef FAST_IDCT
+ bitmapcol[k&0x7] |= mask[k>>3];
+#endif
+ sum ^= temp;
+
+ i++;
+ }
+ while (!last);
+
+ if ((sum & 1) == 0)
+ {
+ datablock[63] = datablock[63] ^ 0x1;
+#ifdef FAST_IDCT /* 7/5/01, need to update bitmap */
+ if (datablock[63])
+ bitmapcol[7] |= 1;
+#endif
+ i = NCOEFF_BLOCK;
+ }
+
+
+#ifdef FAST_IDCT
+ if (i > 10)
+ {
+ for (k = 1; k < 4; k++) /* 07/19/01 */
+ {
+ if (bitmapcol[k] != 0)
+ {
+ (*bitmaprow) |= mask[k];
+ }
+ }
+ }
+#endif
+
+ return i;
+}
+#endif
+/***********************************************************CommentBegin******
+*
+* -- VlcDequantIntraH263Block -- Decodes the DCT coefficients of one 8x8 block and perform
+ dequantization in H.263 mode for INTRA block.
+ Date: 08/08/2000
+ Modified: 3/21/01
+ clean up, added clipping, 16-bit int case, removed multiple zigzaging
+******************************************************************************/
+
+
+int VlcDequantH263IntraBlock(VideoDecData *video, int comp, int switched,
+ uint8 *bitmapcol, uint8 *bitmaprow)
+{
+ BitstreamDecVideo *stream = video->bitstream;
+ int16 *datablock = video->mblock->block[comp]; /* 10/20/2000, assume it has been reset of all-zero !!!*/
+ int32 temp;
+ int mbnum = video->mbnum;
+ uint CBP = video->headerInfo.CBP[mbnum];
+ int QP = video->QPMB[mbnum];
+ typeDCStore *DC = video->predDC + mbnum;
+ int x_pos = video->mbnum_col;
+ typeDCACStore *DCAC_row = video->predDCAC_row + x_pos;
+ typeDCACStore *DCAC_col = video->predDCAC_col;
+ uint ACpred_flag = (uint) video->acPredFlag[mbnum];
+
+ /*** VLC *****/
+ int i, j, k;
+ Tcoef run_level;
+ int last, return_status;
+ VlcDecFuncP vlcDecCoeff;
+ int direction;
+ const int *inv_zigzag;
+
+ /*** Quantizer ****/
+ int dc_scaler;
+ int sgn_coeff;
+
+
+
+ const int B_Xtab[6] = {0, 1, 0, 1, 2, 3};
+ const int B_Ytab[6] = {0, 0, 1, 1, 2, 3};
+
+ int16 *dcac_row, *dcac_col;
+
+ dcac_row = (*DCAC_row)[B_Xtab[comp]];
+ dcac_col = (*DCAC_col)[B_Ytab[comp]];
+
+#ifdef FAST_IDCT
+ *((uint32*)bitmapcol) = *((uint32*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+#endif
+ /* select which Huffman table to be used */
+ vlcDecCoeff = video->vlcDecCoeffIntra;
+
+ dc_scaler = (comp < 4) ? video->mblock->DCScalarLum : video->mblock->DCScalarChr;
+
+ /* perform only VLC decoding */
+ doDCACPrediction(video, comp, datablock, &direction);
+ if (!ACpred_flag) direction = 0;
+
+ inv_zigzag = zigzag_inv + (ACpred_flag << 6) + (direction << 6); /* 04/17/01 */
+
+ i = 1;
+ if (CBP & (1 << (5 - comp)))
+ {
+ i = 1 - switched;
+ do
+ {
+ return_status = (*vlcDecCoeff)(stream, &run_level);
+ if (return_status != PV_SUCCESS)
+ {
+ last = 1;/* 11/1/2000 let it slips undetected, just like
+ in original version */
+ i = VLC_ERROR;
+ ACpred_flag = 0; /* no of coefficients should not get reset 03/07/2002 */
+ break;
+ }
+
+ i += run_level.run;
+ last = run_level.last;
+ if (i >= 64)
+ {
+ ACpred_flag = 0; /* no of coefficients should not get reset 03/07/2002 */
+ i = VLC_NO_LAST_BIT;
+ last = 1;
+ break;
+ }
+
+ k = inv_zigzag[i];
+
+ if (run_level.sign == 1)
+ {
+ datablock[k] -= run_level.level;
+ sgn_coeff = -1;
+ }
+ else
+ {
+ datablock[k] += run_level.level;
+ sgn_coeff = 1;
+ }
+
+
+ if (AC_rowcol[k]) /* 10/25/2000 */
+ {
+ temp = (int32)QP * (2 * datablock[k] + sgn_coeff) - sgn_coeff + (QP & 1) * sgn_coeff;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int16) temp;
+
+#ifdef FAST_IDCT
+ bitmapcol[k&0x7] |= mask[k>>3];
+#endif
+ }
+
+ i++;
+ }
+ while (!last);
+
+ }
+
+ ///// NEED TO DEQUANT THOSE PREDICTED AC COEFF
+ /* dequantize the rest of AC predicted coeff that haven't been dequant */
+ if (ACpred_flag)
+ {
+
+ i = NCOEFF_BLOCK; /* otherwise, FAST IDCT won't work correctly, 10/18/2000 */
+
+ if (!direction) /* check vertical */
+ {
+
+ dcac_row[0] = datablock[1];
+ dcac_row[1] = datablock[2];
+ dcac_row[2] = datablock[3];
+ dcac_row[3] = datablock[4];
+ dcac_row[4] = datablock[5];
+ dcac_row[5] = datablock[6];
+ dcac_row[6] = datablock[7];
+
+ for (j = 0, k = 8; k < 64; k += 8, j++)
+ {
+ dcac_col[j] = datablock[k];
+ if (dcac_col[j])
+ {
+ if (datablock[k] > 0)
+ {
+ if (datablock[k] > 2047) dcac_col[j] = 2047;
+ sgn_coeff = 1;
+ }
+ else
+ {
+ if (datablock[k] < -2048) dcac_col[j] = -2048;
+ sgn_coeff = -1;
+ }
+ temp = (int32)QP * (2 * datablock[k] + sgn_coeff) - sgn_coeff + (QP & 1) * sgn_coeff;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int16) temp;
+#ifdef FAST_IDCT
+ bitmapcol[0] |= mask[k>>3];
+#endif
+
+ }
+ }
+
+ for (k = 1; k < 8; k++)
+ {
+ if (datablock[k])
+ {
+ sgn_coeff = (datablock[k] > 0) ? 1 : -1;
+ temp = (int32)QP * (2 * datablock[k] + sgn_coeff) - sgn_coeff + (QP & 1) * sgn_coeff;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int16) temp;
+#ifdef FAST_IDCT
+ bitmapcol[k] |= 128;
+#endif
+
+ }
+ }
+ }
+ else
+ {
+
+ dcac_col[0] = datablock[8];
+ dcac_col[1] = datablock[16];
+ dcac_col[2] = datablock[24];
+ dcac_col[3] = datablock[32];
+ dcac_col[4] = datablock[40];
+ dcac_col[5] = datablock[48];
+ dcac_col[6] = datablock[56];
+
+
+ for (j = 0, k = 1; k < 8; k++, j++)
+ {
+ dcac_row[j] = datablock[k];
+ if (dcac_row[j])
+ {
+ if (datablock[k] > 0)
+ {
+ if (datablock[k] > 2047) dcac_row[j] = 2047;
+ sgn_coeff = 1;
+ }
+ else
+ {
+ if (datablock[k] < -2048) dcac_row[j] = -2048;
+ sgn_coeff = -1;
+ }
+
+ temp = (int32)QP * (2 * datablock[k] + sgn_coeff) - sgn_coeff + (QP & 1) * sgn_coeff;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int) temp;
+#ifdef FAST_IDCT
+ bitmapcol[k] |= 128;
+#endif
+
+ }
+ }
+ for (k = 8; k < 64; k += 8)
+ {
+ if (datablock[k])
+ {
+ sgn_coeff = (datablock[k] > 0) ? 1 : -1;
+ temp = (int32)QP * (2 * datablock[k] + sgn_coeff) - sgn_coeff + (QP & 1) * sgn_coeff;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int16) temp;
+#ifdef FAST_IDCT
+ bitmapcol[0] |= mask[k>>3];
+#endif
+ }
+ }
+
+ }
+ }
+ else
+ {
+ dcac_row[0] = datablock[1];
+ dcac_row[1] = datablock[2];
+ dcac_row[2] = datablock[3];
+ dcac_row[3] = datablock[4];
+ dcac_row[4] = datablock[5];
+ dcac_row[5] = datablock[6];
+ dcac_row[6] = datablock[7];
+
+ dcac_col[0] = datablock[8];
+ dcac_col[1] = datablock[16];
+ dcac_col[2] = datablock[24];
+ dcac_col[3] = datablock[32];
+ dcac_col[4] = datablock[40];
+ dcac_col[5] = datablock[48];
+ dcac_col[6] = datablock[56];
+
+ for (k = 1; k < 8; k++)
+ {
+ if (datablock[k])
+ {
+ sgn_coeff = (datablock[k] > 0) ? 1 : -1;
+ temp = (int32)QP * (2 * datablock[k] + sgn_coeff) - sgn_coeff + (QP & 1) * sgn_coeff;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int16) temp;
+#ifdef FAST_IDCT
+ bitmapcol[k] |= 128;
+#endif
+ }
+ }
+ for (k = 8; k < 64; k += 8)
+ {
+ if (datablock[k])
+ {
+ sgn_coeff = (datablock[k] > 0) ? 1 : -1;
+ temp = (int32)QP * (2 * datablock[k] + sgn_coeff) - sgn_coeff + (QP & 1) * sgn_coeff;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[k] = (int16) temp;
+#ifdef FAST_IDCT
+ bitmapcol[0] |= mask[k>>3];
+#endif
+ }
+ }
+ }
+ if (datablock[0])
+ {
+#ifdef FAST_IDCT
+ bitmapcol[0] |= 128;
+#endif
+
+ temp = (int32)datablock[0] * dc_scaler;
+ if (temp > 2047) temp = 2047; /* 03/14/01 */
+ else if (temp < -2048) temp = -2048;
+ datablock[0] = (int16)temp;
+ }
+
+
+#ifdef FAST_IDCT
+ if (i > 10)
+ {
+ for (k = 1; k < 4; k++) /* if i > 10 then k = 0 does not matter */
+ {
+ if (bitmapcol[k] != 0)
+ {
+ (*bitmaprow) |= mask[k]; /* (1<<(7-i)); */
+ }
+ }
+ }
+#endif
+
+ /* Store the qcoeff-values needed later for prediction */
+ (*DC)[comp] = datablock[0];
+ return i;
+}
+
+int VlcDequantH263IntraBlock_SH(VideoDecData *video, int comp, uint8 *bitmapcol, uint8 *bitmaprow)
+{
+ BitstreamDecVideo *stream = video->bitstream;
+ int16 *datablock = video->mblock->block[comp]; /*, 10/20/2000, assume it has been reset of all-zero !!!*/
+ int32 temp;
+ int mbnum = video->mbnum;
+ uint CBP = video->headerInfo.CBP[mbnum];
+ int16 QP = video->QPMB[mbnum];
+ typeDCStore *DC = video->predDC + mbnum;
+ int x_pos = video->mbnum_col;
+ typeDCACStore *DCAC_row = video->predDCAC_row + x_pos;
+ typeDCACStore *DCAC_col = video->predDCAC_col;
+ uint ACpred_flag = (uint) video->acPredFlag[mbnum];
+
+ /*** VLC *****/
+ int i, k;
+ Tcoef run_level;
+ int last, return_status;
+ VlcDecFuncP vlcDecCoeff;
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ int direction;
+ const int *inv_zigzag;
+#endif
+ /*** Quantizer ****/
+
+
+
+ const int B_Xtab[6] = {0, 1, 0, 1, 2, 3};
+ const int B_Ytab[6] = {0, 0, 1, 1, 2, 3};
+
+ int16 *dcac_row, *dcac_col;
+
+ dcac_row = (*DCAC_row)[B_Xtab[comp]];
+ dcac_col = (*DCAC_col)[B_Ytab[comp]];
+ i = 1;
+
+#ifdef FAST_IDCT
+ *((uint32*)bitmapcol) = *((uint32*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+#endif
+
+ /* select which Huffman table to be used */
+ vlcDecCoeff = video->vlcDecCoeffIntra;
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (comp > 3) /* ANNEX_T */
+ {
+ QP = video->QP_CHR;
+ }
+ if (!video->advanced_INTRA)
+ {
+#endif
+
+ if ((CBP & (1 << (5 - comp))) == 0)
+ {
+#ifdef FAST_IDCT
+ bitmapcol[0] = 128;
+ bitmapcol[1] = bitmapcol[2] = bitmapcol[3] = bitmapcol[4] = bitmapcol[5] = bitmapcol[6] = bitmapcol[7] = 0;
+#endif
+ datablock[0] <<= 3; /* no need to clip */
+ return 1;//ncoeffs;
+ }
+ else
+ {
+ /* enter the zero run decoding loop */
+ do
+ {
+ return_status = (*vlcDecCoeff)(stream, &run_level);
+ if (return_status != PV_SUCCESS)
+ {
+ last = 1;/* 11/1/2000 let it slips undetected, just like
+ in original version */
+ i = VLC_ERROR;
+ break;
+ }
+
+ i += run_level.run;
+ last = run_level.last;
+ if (i >= 64)
+ {
+ /* i = NCOEFF_BLOCK; */ /* 11/1/00 */
+ i = VLC_NO_LAST_BIT;
+ last = 1;
+ break;
+ }
+ k = zigzag_inv[i];
+
+ if (run_level.sign == 0)
+ {
+ temp = (int32)QP * (2 * run_level.level + 1) - 1 + (QP & 1);
+ if (temp > 2047) temp = 2047;
+ }
+ else
+ {
+ temp = -(int32)QP * (2 * run_level.level + 1) + 1 - (QP & 1);
+ if (temp < -2048) temp = -2048;
+ }
+
+
+ datablock[k] = (int16) temp;
+
+#ifdef FAST_IDCT
+ bitmapcol[k&0x7] |= mask[k>>3];
+#endif
+ i++;
+ }
+ while (!last);
+
+ }
+ /* no ACDC prediction when ACDC disable */
+ if (datablock[0])
+ {
+#ifdef FAST_IDCT
+ bitmapcol[0] |= 128;
+#endif
+ datablock[0] <<= 3; /* no need to clip 09/18/2001 */
+ }
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ }
+ else /* advanced_INTRA mode */
+ {
+ i = 1;
+ doDCACPrediction_I(video, comp, datablock);
+ /* perform only VLC decoding */
+ if (!ACpred_flag)
+ {
+ direction = 0;
+ }
+ else
+ {
+ direction = video->mblock->direction;
+ }
+
+ inv_zigzag = zigzag_inv + (ACpred_flag << 6) + (direction << 6); /* 04/17/01 */
+
+ if (CBP & (1 << (5 - comp)))
+ {
+ i = 0;
+ do
+ {
+ return_status = (*vlcDecCoeff)(stream, &run_level);
+ if (return_status != PV_SUCCESS)
+ {
+ last = 1;/* 11/1/2000 let it slips undetected, just like
+ in original version */
+ i = VLC_ERROR;
+ ACpred_flag = 0; /* no of coefficients should not get reset 03/07/2002 */
+ break;
+ }
+
+ i += run_level.run;
+ last = run_level.last;
+ if (i >= 64)
+ {
+ /* i = NCOEFF_BLOCK; */ /* 11/1/00 */
+ ACpred_flag = 0; /* no of coefficients should not get reset 03/07/2002 */
+ i = VLC_NO_LAST_BIT;
+ last = 1;
+ break;
+ }
+
+ k = inv_zigzag[i];
+
+ if (run_level.sign == 0)
+ {
+ datablock[k] += (int16)QP * 2 * run_level.level;
+ if (datablock[k] > 2047) datablock[k] = 2047;
+ }
+ else
+ {
+ datablock[k] -= (int16)QP * 2 * run_level.level;
+ if (datablock[k] < -2048) datablock[k] = -2048;
+ }
+#ifdef FAST_IDCT
+ bitmapcol[k&0x7] |= mask[k>>3];
+#endif
+
+ i++;
+ }
+ while (!last);
+
+ }
+ ///// NEED TO DEQUANT THOSE PREDICTED AC COEFF
+ /* dequantize the rest of AC predicted coeff that haven't been dequant */
+
+ if (ACpred_flag)
+ {
+ i = NCOEFF_BLOCK;
+ for (k = 1; k < 8; k++)
+ {
+ if (datablock[k])
+ {
+ bitmapcol[k] |= 128;
+ }
+
+ if (datablock[k<<3])
+ {
+ bitmapcol[0] |= mask[k];
+ }
+ }
+ }
+
+ dcac_row[0] = datablock[1];
+ dcac_row[1] = datablock[2];
+ dcac_row[2] = datablock[3];
+ dcac_row[3] = datablock[4];
+ dcac_row[4] = datablock[5];
+ dcac_row[5] = datablock[6];
+ dcac_row[6] = datablock[7];
+
+ dcac_col[0] = datablock[8];
+ dcac_col[1] = datablock[16];
+ dcac_col[2] = datablock[24];
+ dcac_col[3] = datablock[32];
+ dcac_col[4] = datablock[40];
+ dcac_col[5] = datablock[48];
+ dcac_col[6] = datablock[56];
+
+ if (datablock[0])
+ {
+#ifdef FAST_IDCT
+ bitmapcol[0] |= 128;
+#endif
+
+ datablock[0] |= 1;
+ if (datablock[0] < 0)
+ {
+ datablock[0] = 0;
+ }
+ }
+ }
+#endif
+
+#ifdef FAST_IDCT
+ if (i > 10)
+ {
+ for (k = 1; k < 4; k++) /* if i > 10 then k = 0 does not matter */
+ {
+ if (bitmapcol[k] != 0)
+ {
+ (*bitmaprow) |= mask[k]; /* (1<<(7-i)); */
+ }
+ }
+ }
+#endif
+
+ /* Store the qcoeff-values needed later for prediction */
+ (*DC)[comp] = datablock[0];
+ return i;
+}
+
+/***********************************************************CommentBegin******
+*
+* -- VlcDequantInterH263Block -- Decodes the DCT coefficients of one 8x8 block and perform
+ dequantization in H.263 mode for INTER block.
+ Date: 08/08/2000
+ Modified: 3/21/01
+ clean up, added clipping, 16-bit int case
+******************************************************************************/
+
+
+int VlcDequantH263InterBlock(VideoDecData *video, int comp,
+ uint8 *bitmapcol, uint8 *bitmaprow)
+{
+ BitstreamDecVideo *stream = video->bitstream;
+ int16 *datablock = video->mblock->block[comp]; /* 10/20/2000, assume it has been reset of all-zero !!!*/
+ int32 temp;
+ int mbnum = video->mbnum;
+ int QP = video->QPMB[mbnum];
+
+ /*** VLC *****/
+ int i, k;
+ Tcoef run_level;
+ int last, return_status;
+ VlcDecFuncP vlcDecCoeff;
+
+ /*** Quantizer ****/
+
+
+ i = 0;
+
+#ifdef FAST_IDCT
+ *((uint32*)bitmapcol) = *((uint32*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+#endif
+
+ /* select which Huffman table to be used */
+ vlcDecCoeff = video->vlcDecCoeffInter;
+
+ /* enter the zero run decoding loop */
+ do
+ {
+ return_status = (*vlcDecCoeff)(stream, &run_level);
+ if (return_status != PV_SUCCESS)
+ {
+
+
+ last = 1;/* 11/1/2000 let it slips undetected, just like
+ in original version */
+ i = -1;
+ break;
+ }
+
+ i += run_level.run;
+ last = run_level.last;
+ if (i >= 64)
+ {
+ i = -1;
+ last = 1;
+ break;
+ }
+
+ if (run_level.sign == 0)
+ {
+ temp = (int32)QP * (2 * run_level.level + 1) - 1 + (QP & 1);
+ if (temp > 2047) temp = 2047;
+
+ }
+ else
+ {
+ temp = -(int32)QP * (2 * run_level.level + 1) + 1 - (QP & 1);
+ if (temp < -2048) temp = -2048;
+ }
+
+ k = zigzag_inv[i];
+ datablock[k] = (int16)temp;
+#ifdef FAST_IDCT
+ bitmapcol[k&0x7] |= mask[k>>3];
+#endif
+ i++;
+ }
+ while (!last);
+
+#ifdef FAST_IDCT
+ if (i > 10) /* 07/19/01 */
+ {
+ for (k = 1; k < 4; k++) /* if (i > 10 ) k = 0 does not matter */
+ {
+ if (bitmapcol[k] != 0)
+ {
+ (*bitmaprow) |= mask[k]; /* (1<<(7-i)); */
+ }
+ }
+ }
+#endif
+ return i;
+}
+
diff --git a/media/codecs/m4v_h263/dec/src/vlc_tab.cpp b/media/codecs/m4v_h263/dec/src/vlc_tab.cpp
new file mode 100644
index 0000000..704992f
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/vlc_tab.cpp
@@ -0,0 +1,835 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4dec_api.h"
+#include "mp4def.h"
+#include "mp4lib_int.h"
+#include "vlc_dec_tab.h"
+#include "max_level.h"
+
+
+const int intra_max_level[2][NCOEFF_BLOCK] =
+{
+ {27, 10, 5, 4, 3, 3, 3, 3,
+ 2, 2, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ },
+
+ {8, 3, 2, 2, 2, 2, 2, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0
+ }
+};
+
+
+const int inter_max_level[2][NCOEFF_BLOCK] =
+{
+ {12, 6, 4, 3, 3, 3, 3, 2,
+ 2, 2, 2, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0},
+
+ {3, 2, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0}
+};
+
+
+const int intra_max_run0[28] = { 999, 14, 9, 7, 3, 2, 1,
+ 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0
+ };
+
+
+const int intra_max_run1[9] = { 999, 20, 6,
+ 1, 0, 0,
+ 0, 0, 0
+ };
+
+const int inter_max_run0[13] = { 999,
+ 26, 10, 6, 2, 1, 1,
+ 0, 0, 0, 0, 0, 0
+ };
+
+
+const int inter_max_run1[4] = { 999, 40, 1, 0 };
+
+const VLCshorttab PV_TMNMVtab0[] =
+{
+ {3, 4}, { -3, 4}, {2, 3}, {2, 3}, { -2, 3}, { -2, 3}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
+ { -1, 2}, { -1, 2}, { -1, 2}, { -1, 2}
+};
+
+const VLCshorttab PV_TMNMVtab1[] =
+{
+ {12, 10}, { -12, 10}, {11, 10}, { -11, 10}, {10, 9}, {10, 9}, { -10, 9}, { -10, 9},
+ {9, 9}, {9, 9}, { -9, 9}, { -9, 9}, {8, 9}, {8, 9}, { -8, 9}, { -8, 9}, {7, 7}, {7, 7},
+ {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, { -7, 7}, { -7, 7}, { -7, 7}, { -7, 7},
+ { -7, 7}, { -7, 7}, { -7, 7}, { -7, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7},
+ {6, 7}, {6, 7}, { -6, 7}, { -6, 7}, { -6, 7}, { -6, 7}, { -6, 7}, { -6, 7}, { -6, 7},
+ { -6, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, { -5, 7},
+ { -5, 7}, { -5, 7}, { -5, 7}, { -5, 7}, { -5, 7}, { -5, 7}, { -5, 7}, {4, 6}, {4, 6}, {4, 6},
+ {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6},
+ {4, 6}, {4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6},
+ { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}, { -4, 6}
+};
+
+const VLCshorttab PV_TMNMVtab2[] =
+{
+ {32, 12}, { -32, 12}, {31, 12}, { -31, 12}, {30, 11}, {30, 11}, { -30, 11}, { -30, 11},
+ {29, 11}, {29, 11}, { -29, 11}, { -29, 11}, {28, 11}, {28, 11}, { -28, 11}, { -28, 11},
+ {27, 11}, {27, 11}, { -27, 11}, { -27, 11}, {26, 11}, {26, 11}, { -26, 11}, { -26, 11},
+ {25, 11}, {25, 11}, { -25, 11}, { -25, 11}, {24, 10}, {24, 10}, {24, 10}, {24, 10},
+ { -24, 10}, { -24, 10}, { -24, 10}, { -24, 10}, {23, 10}, {23, 10}, {23, 10}, {23, 10},
+ { -23, 10}, { -23, 10}, { -23, 10}, { -23, 10}, {22, 10}, {22, 10}, {22, 10}, {22, 10},
+ { -22, 10}, { -22, 10}, { -22, 10}, { -22, 10}, {21, 10}, {21, 10}, {21, 10}, {21, 10},
+ { -21, 10}, { -21, 10}, { -21, 10}, { -21, 10}, {20, 10}, {20, 10}, {20, 10}, {20, 10},
+ { -20, 10}, { -20, 10}, { -20, 10}, { -20, 10}, {19, 10}, {19, 10}, {19, 10}, {19, 10},
+ { -19, 10}, { -19, 10}, { -19, 10}, { -19, 10}, {18, 10}, {18, 10}, {18, 10}, {18, 10},
+ { -18, 10}, { -18, 10}, { -18, 10}, { -18, 10}, {17, 10}, {17, 10}, {17, 10}, {17, 10},
+ { -17, 10}, { -17, 10}, { -17, 10}, { -17, 10}, {16, 10}, {16, 10}, {16, 10}, {16, 10},
+ { -16, 10}, { -16, 10}, { -16, 10}, { -16, 10}, {15, 10}, {15, 10}, {15, 10}, {15, 10},
+ { -15, 10}, { -15, 10}, { -15, 10}, { -15, 10}, {14, 10}, {14, 10}, {14, 10}, {14, 10},
+ { -14, 10}, { -14, 10}, { -14, 10}, { -14, 10}, {13, 10}, {13, 10}, {13, 10}, {13, 10},
+ { -13, 10}, { -13, 10}, { -13, 10}, { -13, 10}
+};
+
+const VLCshorttab PV_MCBPCtab[] =
+{
+ {VLC_ERROR, 0},
+ {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8}, {19, 8}, {19, 8},
+ {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7}, {34, 7}, {34, 7}, {34, 7},
+ {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7}, {33, 7}, {33, 7}, {33, 7}, {33, 7},
+ {17, 7}, {17, 7}, {17, 7}, {17, 7}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6},
+ {4, 6}, {4, 6}, {4, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6},
+ {48, 6}, {48, 6}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
+ {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
+ {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
+ {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
+ {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
+ {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+ {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+ {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+ {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+ {16, 4}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
+ {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
+ {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
+ {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
+ {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
+ {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
+ {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
+ {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+ {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+ {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+ {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+ {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+ {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+ {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+ {1, 3}, {1, 3}, {1, 3}
+};
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+const VLCshorttab PV_MCBPCtab1[] =
+{
+ {5, 11}, {5, 11}, {5, 11}, {5, 11}, {21, 13}, {21, 13}, {37, 13}, {53, 13},
+};
+#endif
+const VLCshorttab PV_MCBPCtabintra[] =
+{
+ {VLC_ERROR, 0},
+ {20, 6}, {36, 6}, {52, 6}, {4, 4}, {4, 4}, {4, 4},
+ {4, 4}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3},
+ {19, 3}, {19, 3}, {19, 3}, {35, 3}, {35, 3}, {35, 3},
+ {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {51, 3},
+ {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3},
+ {51, 3}
+};
+
+
+
+const VLCshorttab PV_CBPYtab[48] =
+{
+ {VLC_ERROR, 0}, {VLC_ERROR, 0}, {6, 6}, {9, 6}, {8, 5}, {8, 5}, {4, 5}, {4, 5},
+ {2, 5}, {2, 5}, {1, 5}, {1, 5}, {0, 4}, {0, 4}, {0, 4}, {0, 4},
+ {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
+ {14, 4}, {14, 4}, {14, 4}, {14, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4},
+ {13, 4}, {13, 4}, {13, 4}, {13, 4}, {3, 4}, {3, 4}, {3, 4}, {3, 4},
+ {11, 4}, {11, 4}, {11, 4}, {11, 4}, {7, 4}, {7, 4}, {7, 4}, {7, 4}
+};
+
+
+
+const VLCtab2 PV_DCT3Dtab0[] =
+{
+ {0x8, 1, 1, 7}, {0x7, 1, 1, 7}, {0x6, 1, 1, 7}, {0x5, 1, 1, 7}, {0xc, 1, 0, 7}, {0xb, 1, 0, 7},
+ {0xa, 1, 0, 7}, {0x0, 4, 0, 7}, {0x4, 1, 1, 6}, {0x4, 1, 1, 6}, {0x3, 1, 1, 6}, {0x3, 1, 1, 6},
+ {0x2, 1, 1, 6}, {0x2, 1, 1, 6}, {0x1, 1, 1, 6}, {0x1, 1, 1, 6}, {0x9, 1, 0, 6}, {0x9, 1, 0, 6},
+ {0x8, 1, 0, 6}, {0x8, 1, 0, 6}, {0x7, 1, 0, 6}, {0x7, 1, 0, 6}, {0x6, 1, 0, 6}, {0x6, 1, 0, 6},
+ {0x1, 2, 0, 6}, {0x1, 2, 0, 6}, {0x0, 3, 0, 6}, {0x0, 3, 0, 6}, {0x5, 1, 0, 5}, {0x5, 1, 0, 5},
+ {0x5, 1, 0, 5}, {0x5, 1, 0, 5}, {0x4, 1, 0, 5}, {0x4, 1, 0, 5}, {0x4, 1, 0, 5}, {0x4, 1, 0, 5},
+ {0x3, 1, 0, 5}, {0x3, 1, 0, 5}, {0x3, 1, 0, 5}, {0x3, 1, 0, 5}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4},
+ {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3},
+ {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3},
+ {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3}, {0x1, 1, 0, 3},
+ {0x2, 1, 0, 4}, {0x2, 1, 0, 4}, {0x2, 1, 0, 4}, {0x2, 1, 0, 4}, {0x2, 1, 0, 4}, {0x2, 1, 0, 4},
+ {0x2, 1, 0, 4}, {0x2, 1, 0, 4}, {0x0, 2, 0, 4}, {0x0, 2, 0, 4}, {0x0, 2, 0, 4}, {0x0, 2, 0, 4},
+ {0x0, 2, 0, 4}, {0x0, 2, 0, 4}, {0x0, 2, 0, 4}, {0x0, 2, 0, 4}
+};
+
+
+const VLCtab2 PV_DCT3Dtab1[] =
+{
+ {0x0, 9, 0, 10}, {0x0, 8, 0, 10}, {0x18, 1, 1, 9}, {0x18, 1, 1, 9}, {0x17, 1, 1, 9}, {0x17, 1, 1, 9},
+ {0x16, 1, 1, 9}, {0x16, 1, 1, 9}, {0x15, 1, 1, 9}, {0x15, 1, 1, 9}, {0x14, 1, 1, 9}, {0x14, 1, 1, 9},
+ {0x13, 1, 1, 9}, {0x13, 1, 1, 9}, {0x12, 1, 1, 9}, {0x12, 1, 1, 9}, {0x11, 1, 1, 9}, {0x11, 1, 1, 9},
+ {0x0, 2, 1, 9}, {0x0, 2, 1, 9}, {0x16, 1, 0, 9}, {0x16, 1, 0, 9}, {0x15, 1, 0, 9}, {0x15, 1, 0, 9},
+ {0x14, 1, 0, 9}, {0x14, 1, 0, 9}, {0x13, 1, 0, 9}, {0x13, 1, 0, 9}, {0x12, 1, 0, 9}, {0x12, 1, 0, 9},
+ {0x11, 1, 0, 9}, {0x11, 1, 0, 9}, {0x10, 1, 0, 9}, {0x10, 1, 0, 9}, {0xf, 1, 0, 9}, {0xf, 1, 0, 9},
+ {0x4, 2, 0, 9}, {0x4, 2, 0, 9}, {0x3, 2, 0, 9}, {0x3, 2, 0, 9}, {0x0, 7, 0, 9}, {0x0, 7, 0, 9},
+ {0x0, 6, 0, 9}, {0x0, 6, 0, 9}, {0x10, 1, 1, 8}, {0x10, 1, 1, 8}, {0x10, 1, 1, 8}, {0x10, 1, 1, 8},
+ {0xf, 1, 1, 8}, {0xf, 1, 1, 8}, {0xf, 1, 1, 8}, {0xf, 1, 1, 8}, {0xe, 1, 1, 8}, {0xe, 1, 1, 8},
+ {0xe, 1, 1, 8}, {0xe, 1, 1, 8}, {0xd, 1, 1, 8}, {0xd, 1, 1, 8}, {0xd, 1, 1, 8}, {0xd, 1, 1, 8},
+ {0xc, 1, 1, 8}, {0xc, 1, 1, 8}, {0xc, 1, 1, 8}, {0xc, 1, 1, 8}, {0xb, 1, 1, 8}, {0xb, 1, 1, 8},
+ {0xb, 1, 1, 8}, {0xb, 1, 1, 8}, {0xa, 1, 1, 8}, {0xa, 1, 1, 8}, {0xa, 1, 1, 8}, {0xa, 1, 1, 8},
+ {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0xe, 1, 0, 8}, {0xe, 1, 0, 8},
+ {0xe, 1, 0, 8}, {0xe, 1, 0, 8}, {0xd, 1, 0, 8}, {0xd, 1, 0, 8}, {0xd, 1, 0, 8}, {0xd, 1, 0, 8},
+ {0x2, 2, 0, 8}, {0x2, 2, 0, 8}, {0x2, 2, 0, 8}, {0x2, 2, 0, 8}, {0x1, 3, 0, 8}, {0x1, 3, 0, 8},
+ {0x1, 3, 0, 8}, {0x1, 3, 0, 8}, {0x0, 5, 0, 8}, {0x0, 5, 0, 8}, {0x0, 5, 0, 8}, {0x0, 5, 0, 8}
+};
+
+
+const VLCtab2 PV_DCT3Dtab2[] =
+{
+ {0x1, 2, 1, 11}, {0x1, 2, 1, 11}, {0x0, 3, 1, 11}, {0x0, 3, 1, 11}, {0x0, 0xb, 0, 11}, {0x0, 0xb, 0, 11},
+ {0x0, 0xa, 0, 11}, {0x0, 0xa, 0, 11}, {0x1c, 1, 1, 10}, {0x1c, 1, 1, 10}, {0x1c, 1, 1, 10}, {0x1c, 1, 1, 10},
+ {0x1b, 1, 1, 10}, {0x1b, 1, 1, 10}, {0x1b, 1, 1, 10}, {0x1b, 1, 1, 10}, {0x1a, 1, 1, 10}, {0x1a, 1, 1, 10},
+ {0x1a, 1, 1, 10}, {0x1a, 1, 1, 10}, {0x19, 1, 1, 10}, {0x19, 1, 1, 10}, {0x19, 1, 1, 10}, {0x19, 1, 1, 10},
+ {0x9, 2, 0, 10}, {0x9, 2, 0, 10}, {0x9, 2, 0, 10}, {0x9, 2, 0, 10}, {0x8, 2, 0, 10}, {0x8, 2, 0, 10},
+ {0x8, 2, 0, 10}, {0x8, 2, 0, 10}, {0x7, 2, 0, 10}, {0x7, 2, 0, 10}, {0x7, 2, 0, 10}, {0x7, 2, 0, 10},
+ {0x6, 2, 0, 10}, {0x6, 2, 0, 10}, {0x6, 2, 0, 10}, {0x6, 2, 0, 10}, {0x5, 2, 0, 10}, {0x5, 2, 0, 10},
+ {0x5, 2, 0, 10}, {0x5, 2, 0, 10}, {0x3, 3, 0, 10}, {0x3, 3, 0, 10}, {0x3, 3, 0, 10}, {0x3, 3, 0, 10},
+ {0x2, 3, 0, 10}, {0x2, 3, 0, 10}, {0x2, 3, 0, 10}, {0x2, 3, 0, 10}, {0x1, 4, 0, 10}, {0x1, 4, 0, 10},
+ {0x1, 4, 0, 10}, {0x1, 4, 0, 10}, {0x0, 0xc, 0, 11}, {0x0, 0xc, 0, 11}, {0x1, 5, 0, 11}, {0x1, 5, 0, 11},
+ {0x17, 1, 0, 11}, {0x17, 1, 0, 11}, {0x18, 1, 0, 11}, {0x18, 1, 0, 11}, {0x1d, 1, 1, 11}, {0x1d, 1, 1, 11},
+ {0x1e, 1, 1, 11}, {0x1e, 1, 1, 11}, {0x1f, 1, 1, 11}, {0x1f, 1, 1, 11}, {0x20, 1, 1, 11}, {0x20, 1, 1, 11},
+ {0x1, 6, 0, 12}, {0x2, 4, 0, 12}, {0x4, 3, 0, 12}, {0x5, 3, 0, 12}, {0x6, 3, 0, 12}, {0xa, 2, 0, 12},
+ {0x19, 1, 0, 12}, {0x1a, 1, 0, 12}, {0x21, 1, 1, 12}, {0x22, 1, 1, 12}, {0x23, 1, 1, 12}, {0x24, 1, 1, 12},
+ {0x25, 1, 1, 12}, {0x26, 1, 1, 12}, {0x27, 1, 1, 12}, {0x28, 1, 1, 12}, {0xbf, 0xf, 1, 7},
+ {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7},
+ {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7},
+ {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7},
+ {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7},
+ {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7}, {0xbf, 0xf, 1, 7},
+ {0xbf, 0xf, 1, 7}
+};
+
+/* New tables for Intra luminance blocks */
+
+const VLCtab2 PV_DCT3Dtab3[] =
+{
+ {0x4, 1, 1, 7}, {0x3, 1, 1, 7}, {0x6, 1, 0, 7}, {0x5, 1, 1, 7},
+ {0x7, 1, 0, 7}, {0x2, 2, 0, 7}, {0x1, 3, 0, 7}, {0x0, 9, 0, 7},
+ {0x0, 2, 1, 6}, {0x0, 2, 1, 6}, {0x5, 1, 0, 6}, {0x5, 1, 0, 6},
+ {0x2, 1, 1, 6}, {0x2, 1, 1, 6}, {0x1, 1, 1, 6}, {0x1, 1, 1, 6},
+ {0x4, 1, 0, 6}, {0x4, 1, 0, 6}, {0x3, 1, 0, 6}, {0x3, 1, 0, 6},
+ {0x0, 8, 0, 6}, {0x0, 8, 0, 6}, {0x0, 7, 0, 6}, {0x0, 7, 0, 6},
+ {0x1, 2, 0, 6}, {0x1, 2, 0, 6}, {0x0, 6, 0, 6}, {0x0, 6, 0, 6},
+ {0x2, 1, 0, 5}, {0x2, 1, 0, 5}, {0x2, 1, 0, 5}, {0x2, 1, 0, 5},
+ {0x0, 5, 0, 5}, {0x0, 5, 0, 5}, {0x0, 5, 0, 5}, {0x0, 5, 0, 5},
+ {0x0, 4, 0, 5}, {0x0, 4, 0, 5}, {0x0, 4, 0, 5}, {0x0, 4, 0, 5},
+ {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4},
+ {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3},
+ {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3},
+ {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3},
+ {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3},
+ {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4},
+ {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4},
+ {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4},
+ {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4}
+};
+
+const VLCtab2 PV_DCT3Dtab4[] =
+{
+ {0x0, 0x12, 0, 10}, {0x0, 0x11, 0, 10}, {0xe, 1, 1, 9}, {0xe, 1, 1, 9},
+ {0xd, 1, 1, 9}, {0xd, 1, 1, 9}, {0xc, 1, 1, 9}, {0xc, 1, 1, 9},
+ {0xb, 1, 1, 9}, {0xb, 1, 1, 9}, {0xa, 1, 1, 9}, {0xa, 1, 1, 9},
+ {0x1, 2, 1, 9}, {0x1, 2, 1, 9}, {0x0, 4, 1, 9}, {0x0, 4, 1, 9},
+ {0xc, 1, 0, 9}, {0xc, 1, 0, 9}, {0xb, 1, 0, 9}, {0xb, 1, 0, 9},
+ {0x7, 2, 0, 9}, {0x7, 2, 0, 9}, {0x6, 2, 0, 9}, {0x6, 2, 0, 9},
+ {0x5, 2, 0, 9}, {0x5, 2, 0, 9}, {0x3, 3, 0, 9}, {0x3, 3, 0, 9},
+ {0x2, 3, 0, 9}, {0x2, 3, 0, 9}, {0x1, 6, 0, 9}, {0x1, 6, 0, 9},
+ {0x1, 5, 0, 9}, {0x1, 5, 0, 9}, {0x0, 0x10, 0, 9}, {0x0, 0x10, 0, 9},
+ {0x4, 2, 0, 9}, {0x4, 2, 0, 9}, {0x0, 0xf, 0, 9}, {0x0, 0xf, 0, 9},
+ {0x0, 0xe, 0, 9}, {0x0, 0xe, 0, 9}, {0x0, 0xd, 0, 9}, {0x0, 0xd, 0, 9},
+ {0x8, 1, 1, 8}, {0x8, 1, 1, 8}, {0x8, 1, 1, 8}, {0x8, 1, 1, 8},
+ {0x7, 1, 1, 8}, {0x7, 1, 1, 8}, {0x7, 1, 1, 8}, {0x7, 1, 1, 8},
+ {0x6, 1, 1, 8}, {0x6, 1, 1, 8}, {0x6, 1, 1, 8}, {0x6, 1, 1, 8},
+ {0x0, 3, 1, 8}, {0x0, 3, 1, 8}, {0x0, 3, 1, 8}, {0x0, 3, 1, 8},
+ {0xa, 1, 0, 8}, {0xa, 1, 0, 8}, {0xa, 1, 0, 8}, {0xa, 1, 0, 8},
+ {0x9, 1, 0, 8}, {0x9, 1, 0, 8}, {0x9, 1, 0, 8}, {0x9, 1, 0, 8},
+ {0x8, 1, 0, 8}, {0x8, 1, 0, 8}, {0x8, 1, 0, 8}, {0x8, 1, 0, 8},
+ {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0x9, 1, 1, 8},
+ {0x3, 2, 0, 8}, {0x3, 2, 0, 8}, {0x3, 2, 0, 8}, {0x3, 2, 0, 8},
+ {0x1, 4, 0, 8}, {0x1, 4, 0, 8}, {0x1, 4, 0, 8}, {0x1, 4, 0, 8},
+ {0x0, 0xc, 0, 8}, {0x0, 0xc, 0, 8}, {0x0, 0xc, 0, 8}, {0x0, 0xc, 0, 8},
+ {0x0, 0xb, 0, 8}, {0x0, 0xb, 0, 8}, {0x0, 0xb, 0, 8}, {0x0, 0xb, 0, 8},
+ {0x0, 0xa, 0, 8}, {0x0, 0xa, 0, 8}, {0x0, 0xa, 0, 8}, {0x0, 0xa, 0, 8}
+};
+
+const VLCtab2 PV_DCT3Dtab5[] =
+{
+ {0x0, 7, 1, 11}, {0x0, 7, 1, 11}, {0x0, 6, 1, 11}, {0x0, 6, 1, 11},
+ {0x0, 0x16, 0, 11}, {0x0, 0x16, 0, 11}, {0x0, 0x15, 0, 11}, {0x0, 0x15, 0, 11},
+ {0x2, 2, 1, 10}, {0x2, 2, 1, 10}, {0x2, 2, 1, 10}, {0x2, 2, 1, 10},
+ {0x1, 3, 1, 10}, {0x1, 3, 1, 10}, {0x1, 3, 1, 10}, {0x1, 3, 1, 10},
+ {0x0, 5, 1, 10}, {0x0, 5, 1, 10}, {0x0, 5, 1, 10}, {0x0, 5, 1, 10},
+ {0xd, 1, 0, 10}, {0xd, 1, 0, 10}, {0xd, 1, 0, 10}, {0xd, 1, 0, 10},
+ {0x5, 3, 0, 10}, {0x5, 3, 0, 10}, {0x5, 3, 0, 10}, {0x5, 3, 0, 10},
+ {0x8, 2, 0, 10}, {0x8, 2, 0, 10}, {0x8, 2, 0, 10}, {0x8, 2, 0, 10},
+ {0x4, 3, 0, 10}, {0x4, 3, 0, 10}, {0x4, 3, 0, 10}, {0x4, 3, 0, 10},
+ {0x3, 4, 0, 10}, {0x3, 4, 0, 10}, {0x3, 4, 0, 10}, {0x3, 4, 0, 10},
+ {0x2, 4, 0, 10}, {0x2, 4, 0, 10}, {0x2, 4, 0, 10}, {0x2, 4, 0, 10},
+ {0x1, 7, 0, 10}, {0x1, 7, 0, 10}, {0x1, 7, 0, 10}, {0x1, 7, 0, 10},
+ {0x0, 0x14, 0, 10}, {0x0, 0x14, 0, 10}, {0x0, 0x14, 0, 10}, {0x0, 0x14, 0, 10},
+ {0x0, 0x13, 0, 10}, {0x0, 0x13, 0, 10}, {0x0, 0x13, 0, 10}, {0x0, 0x13, 0, 10},
+ {0x0, 0x17, 0, 11}, {0x0, 0x17, 0, 11}, {0x0, 0x18, 0, 11}, {0x0, 0x18, 0, 11},
+ {0x1, 8, 0, 11}, {0x1, 8, 0, 11}, {0x9, 2, 0, 11}, {0x9, 2, 0, 11},
+ {0x3, 2, 1, 11}, {0x3, 2, 1, 11}, {0x4, 2, 1, 11}, {0x4, 2, 1, 11},
+ {0xf, 1, 1, 11}, {0xf, 1, 1, 11}, {0x10, 1, 1, 11}, {0x10, 1, 1, 11},
+ {0, 0x19, 0, 12}, {0, 0x1a, 0, 12}, {0, 0x1b, 0, 12}, {1, 9, 0, 12},
+ {0x6, 3, 0, 12}, {0x1, 0xa, 0, 12}, {0x2, 5, 0, 12}, {0x7, 3, 0, 12},
+ {0xe, 1, 0, 12}, {0x0, 8, 1, 12}, {0x5, 2, 1, 12}, {0x6, 2, 1, 12},
+ {0x11, 1, 1, 12}, {0x12, 1, 1, 12}, {0x13, 1, 1, 12}, {0x14, 1, 1, 12},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7},
+ {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}, {0x1b, 0xff, 0, 7}
+};
+
+#ifdef PV_ANNEX_IJKT_SUPPORT
+const VLCtab2 PV_DCT3Dtab6[] =
+{
+ {0x0, 3, 1, 7}, {0x4, 1, 1, 7}, {0x6, 1, 1, 7}, {0x5, 1, 1, 7}, {0x1, 3, 0, 7}, {0x2, 2, 0, 7},
+ {0x0, 9, 0, 7}, {0x5, 1, 0, 7}, {0x0, 2, 1, 6}, {0x0, 2, 1, 6}, {0x3, 1, 1, 6}, {0x3, 1, 1, 6},
+ {0x2, 1, 1, 6}, {0x2, 1, 1, 6}, {0x1, 1, 1, 6}, {0x1, 1, 1, 6}, {0x0, 6, 0, 6}, {0x0, 6, 0, 6},
+ {0x0, 7, 0, 6}, {0x0, 7, 0, 6}, {0x0, 8, 0, 6}, {0x0, 8, 0, 6}, {0x4, 1, 0, 6}, {0x4, 1, 0, 6},
+ {0x1, 2, 0, 6}, {0x1, 2, 0, 6}, {0x3, 1, 0, 6}, {0x3, 1, 0, 6}, {0x2, 1, 0, 5}, {0x2, 1, 0, 5},
+ {0x2, 1, 0, 5}, {0x2, 1, 0, 5}, {0x0, 4, 0, 5}, {0x0, 4, 0, 5}, {0x0, 4, 0, 5}, {0x0, 4, 0, 5},
+ {0x0, 5, 0, 5}, {0x0, 5, 0, 5}, {0x0, 5, 0, 5}, {0x0, 5, 0, 5}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4},
+ {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4}, {0x0, 1, 1, 4},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 1, 0, 2},
+ {0x0, 1, 0, 2}, {0x0, 1, 0, 2}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3},
+ {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3},
+ {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3}, {0x0, 2, 0, 3},
+ {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x0, 3, 0, 4},
+ {0x0, 3, 0, 4}, {0x0, 3, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4},
+ {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4}, {0x1, 1, 0, 4}
+};
+
+const VLCtab2 PV_DCT3Dtab7[] =
+{
+ {0xb, 1, 0, 10}, {0xa, 1, 0, 10}, {0x0, 5, 1, 9}, {0x0, 5, 1, 9}, {0x0, 6, 1, 9}, {0x0, 6, 1, 9},
+ {0x1, 2, 1, 9}, {0x1, 2, 1, 9}, {0x2, 2, 1, 9}, {0x2, 2, 1, 9}, {0xf, 1, 1, 9}, {0xf, 1, 1, 9},
+ {0x10, 1, 1, 9}, {0x10, 1, 1, 9}, {0x12, 1, 1, 9}, {0x12, 1, 1, 9}, {0x11, 1, 1, 9}, {0x11, 1, 1, 9},
+ {0xe, 1, 1, 9}, {0xe, 1, 1, 9}, {0x0, 13, 0, 9}, {0x0, 13, 0, 9}, {0x0, 14, 0, 9}, {0x0, 14, 0, 9},
+ {0x0, 15, 0, 9}, {0x0, 15, 0, 9}, {0x0, 16, 0, 9}, {0x0, 16, 0, 9}, {0x0, 17, 0, 9}, {0x0, 17, 0, 9},
+ {0x0, 18, 0, 9}, {0x0, 18, 0, 9}, {0x0, 11, 0, 9}, {0x0, 11, 0, 9}, {0x0, 12, 0, 9}, {0x0, 12, 0, 9},
+ {0x5, 2, 0, 9}, {0x5, 2, 0, 9}, {0x4, 2, 0, 9}, {0x4, 2, 0, 9}, {0x9, 1, 0, 9}, {0x9, 1, 0, 9},
+ {0x8, 1, 0, 9}, {0x8, 1, 0, 9}, {0x0, 4, 1, 8}, {0x0, 4, 1, 8}, {0x0, 4, 1, 8}, {0x0, 4, 1, 8},
+ {0x7, 1, 1, 8}, {0x7, 1, 1, 8}, {0x7, 1, 1, 8}, {0x7, 1, 1, 8}, {0x8, 1, 1, 8}, {0x8, 1, 1, 8},
+ {0x8, 1, 1, 8}, {0x8, 1, 1, 8}, {0xd, 1, 1, 8}, {0xd, 1, 1, 8}, {0xd, 1, 1, 8}, {0xd, 1, 1, 8},
+ {0xc, 1, 1, 8}, {0xc, 1, 1, 8}, {0xc, 1, 1, 8}, {0xc, 1, 1, 8}, {0xb, 1, 1, 8}, {0xb, 1, 1, 8},
+ {0xb, 1, 1, 8}, {0xb, 1, 1, 8}, {0xa, 1, 1, 8}, {0xa, 1, 1, 8}, {0xa, 1, 1, 8}, {0xa, 1, 1, 8},
+ {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0x9, 1, 1, 8}, {0x0, 10, 0, 8}, {0x0, 10, 0, 8},
+ {0x0, 10, 0, 8}, {0x0, 10, 0, 8}, {0x6, 1, 0, 8}, {0x6, 1, 0, 8}, {0x6, 1, 0, 8}, {0x6, 1, 0, 8},
+ {0x3, 2, 0, 8}, {0x3, 2, 0, 8}, {0x3, 2, 0, 8}, {0x3, 2, 0, 8}, {0x1, 4, 0, 8}, {0x1, 4, 0, 8},
+ {0x1, 4, 0, 8}, {0x1, 4, 0, 8}, {0x7, 1, 0, 8}, {0x7, 1, 0, 8}, {0x7, 1, 0, 8}, {0x7, 1, 0, 8}
+};
+
+
+const VLCtab2 PV_DCT3Dtab8[] =
+{
+ {0x13, 0x1, 1, 11}, {0x13, 0x1, 1, 11}, {0x14, 0x1, 1, 11}, {0x14, 0x1, 1, 11}, {0x9, 0x2, 0, 11}, {0x9, 0x2, 0, 11},
+ {0x4, 0x3, 0, 11}, {0x4, 0x3, 0, 11}, {0x0, 0x7, 1, 10}, {0x0, 0x7, 1, 10}, {0x0, 0x7, 1, 10}, {0x0, 0x7, 1, 10},
+ {0x1, 0x3, 1, 10}, {0x1, 0x3, 1, 10}, {0x1, 0x3, 1, 10}, {0x1, 0x3, 1, 10}, {0x3, 0x2, 1, 10}, {0x3, 0x2, 1, 10},
+ {0x3, 0x2, 1, 10}, {0x3, 0x2, 1, 10}, {0x4, 0x2, 1, 10}, {0x4, 0x2, 1, 10}, {0x4, 0x2, 1, 10}, {0x4, 0x2, 1, 10},
+ {0xc, 0x1, 0, 10}, {0xc, 0x1, 0, 10}, {0xc, 0x1, 0, 10}, {0xc, 0x1, 0, 10}, {0x2, 0x4, 0, 10}, {0x2, 0x4, 0, 10},
+ {0x2, 0x4, 0, 10}, {0x2, 0x4, 0, 10}, {0x8, 0x2, 0, 10}, {0x8, 0x2, 0, 10}, {0x8, 0x2, 0, 10}, {0x8, 0x2, 0, 10},
+ {0x7, 0x2, 0, 10}, {0x7, 0x2, 0, 10}, {0x7, 0x2, 0, 10}, {0x7, 0x2, 0, 10}, {0x6, 0x2, 0, 10}, {0x6, 0x2, 0, 10},
+ {0x6, 0x2, 0, 10}, {0x6, 0x2, 0, 10}, {0x3, 0x3, 0, 10}, {0x3, 0x3, 0, 10}, {0x3, 0x3, 0, 10}, {0x3, 0x3, 0, 10},
+ {0x2, 0x3, 0, 10}, {0x2, 0x3, 0, 10}, {0x2, 0x3, 0, 10}, {0x2, 0x3, 0, 10}, {0x1, 0x5, 0, 10}, {0x1, 0x5, 0, 10},
+ {0x1, 0x5, 0, 10}, {0x1, 0x5, 0, 10}, {0xd, 0x1, 0, 11}, {0xd, 0x1, 0, 11}, {0x1, 0x6, 0, 11}, {0x1, 0x6, 0, 11},
+ {0x0, 0x14, 0, 11}, {0x0, 0x14, 0, 11}, {0x0, 0x13, 0, 11}, {0x0, 0x13, 0, 11}, {0x2, 0x3, 1, 11}, {0x2, 0x3, 1, 11},
+ {0x1, 0x4, 1, 11}, {0x1, 0x4, 1, 11}, {0x0, 0x9, 1, 11}, {0x0, 0x9, 1, 11}, {0x0, 0x8, 1, 11}, {0x0, 0x8, 1, 11},
+ {0x1, 0x7, 0, 12}, {0x3, 0x4, 0, 12}, {0x5, 0x3, 0, 12}, {0x0, 0x19, 0, 12}, {0x0, 0x18, 0, 12}, {0x0, 0x17, 0, 12},
+ {0x0, 0x16, 0, 12}, {0x0, 0x15, 0, 12}, {0x15, 0x1, 1, 12}, {0x16, 0x1, 1, 12}, {0x17, 0x1, 1, 12}, {0x7, 0x2, 1, 12},
+ {0x6, 0x2, 1, 12}, {0x5, 0x2, 1, 12}, {0x3, 0x3, 1, 12}, {0x0, 0xa, 1, 12}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7},
+ {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7},
+ {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7},
+ {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7},
+ {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7},
+ {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}, {0x2f, 0x3f, 1, 7}
+};
+#endif
+/* RVLC tables */
+const int ptrRvlcTab[11] = {0, 24, 46, 66, 84, 100, 114, 126, 134, 140, 144};
+
+const VLCtab2 RvlcDCTtabIntra[170] = /* 00xxxx00 or 00xxxx01 */
+{
+ {27, 255, 0, 5}, /* 0000 is escape code */
+ {1, 1, 0, 4},
+ {2, 1, 0, 5},
+ {3, 1, 0, 5},
+ {4, 1, 0, 6},
+ {5, 1, 0, 6},
+ {6, 1, 0, 7},
+ {7, 1, 0, 7},
+ {8, 1, 0, 8},
+ {9, 1, 0, 8},
+ {10, 1, 0, 9},
+ {5, 2, 0, 9},
+ {11, 1, 0, 10},
+ {12, 1, 0, 10},
+ {13, 1, 0, 11},
+ {9, 2, 0, 11},
+ {10, 2, 0, 12},
+ {4, 4, 0, 12},
+ {14, 1, 0, 13},
+ {15, 1, 0, 13},
+ {16, 1, 0, 14},
+ {17, 1, 0, 14},
+ {0, 27, 0, 15},
+ {3, 9, 0, 15},
+ /* 010xxxx00 or 010xxxx01 */
+ {1, 2, 0, 5},
+ {0, 4, 0, 5},
+ {0, 5, 0, 6},
+ {0, 6, 0, 6},
+ {2, 2, 0, 7},
+ {1, 3, 0, 7},
+ {3, 2, 0, 8},
+ {4, 2, 0, 8},
+ {2, 3, 0, 9},
+ {3, 3, 0, 9},
+ {6, 2, 0, 10},
+ {7, 2, 0, 10},
+ {5, 3, 0, 11},
+ {6, 3, 0, 11},
+ {5, 4, 0, 12},
+ {6, 4, 0, 12},
+ {11, 2, 0, 13},
+ {8, 3, 0, 13},
+ {18, 1, 0, 14},
+ {8, 4, 0, 14},
+ {6, 5, 0, 15},
+ {7, 5, 0, 15},
+ /* 0110xxxx00 or 0110xxxx01 */
+ {3, 1, 1, 6},
+ {4, 1, 1, 6},
+ {0, 7, 0, 7},
+ {7, 1, 1, 7},
+ {1, 4, 0, 8},
+ {1, 5, 0, 8},
+ {1, 6, 0, 9},
+ {0, 10, 0, 9},
+ {8, 2, 0, 10},
+ {4, 3, 0, 10},
+ {7, 3, 0, 11},
+ {3, 4, 0, 11},
+ {3, 5, 0, 12},
+ {4, 5, 0, 12},
+ {9, 3, 0, 13},
+ {7, 4, 0, 13},
+ {5, 5, 0, 14},
+ {4, 6, 0, 14},
+ {9, 4, 0, 15},
+ {12, 2, 0, 15},
+ /* 01110xxxx00 or 01110xxxx01 */
+ {8, 1, 1, 7},
+ {9, 1, 1, 7},
+ {0, 8, 0, 8},
+ {0, 9, 0, 8},
+ {0, 11, 0, 9},
+ {1, 2, 1, 9},
+ {2, 4, 0, 10},
+ {1, 7, 0, 10},
+ {2, 5, 0, 11},
+ {2, 6, 0, 11},
+ {1, 10, 0, 12},
+ {0, 18, 0, 12},
+ {3, 6, 0, 13},
+ {2, 7, 0, 13},
+ {5, 6, 0, 14},
+ {3, 7, 0, 14},
+ {19, 1, 0, 15},
+ {1, 5, 1, 15},
+ /* 011110xxxx00 or 011110xxxx01 */
+ {0, 2, 1, 8},
+ {12, 1, 1, 8},
+ {15, 1, 1, 9},
+ {16, 1, 1, 9},
+ {0, 12, 0, 10},
+ {0, 13, 0, 10},
+ {1, 8, 0, 11},
+ {1, 9, 0, 11},
+ {0, 19, 0, 12},
+ {0, 22, 0, 12},
+ {2, 8, 0, 13},
+ {2, 9, 0, 13},
+ {3, 8, 0, 14},
+ {2, 10, 0, 14},
+ {2, 3, 1, 15},
+ {13, 2, 1, 15},
+ /* 0111110xxxx00 or 0111110xxxx01 */
+ {17, 1, 1, 9},
+ {18, 1, 1, 9},
+ {0, 14, 0, 10},
+ {21, 1, 1, 10},
+ {0, 15, 0, 11},
+ {0, 16, 0, 11},
+ {1, 3, 1, 12},
+ {3, 2, 1, 12},
+ {1, 11, 0, 13},
+ {0, 20, 0, 13},
+ {2, 11, 0, 14},
+ {1, 12, 0, 14},
+ {41, 1, 1, 15},
+ {42, 1, 1, 15},
+ /* 01111110xxxx00 or 01111110xxxx01 */
+ {22, 1, 1, 10},
+ {23, 1, 1, 10},
+ {0, 17, 0, 11},
+ {0, 3, 1, 11},
+ {4, 2, 1, 12},
+ {29, 1, 1, 12},
+ {0, 21, 0, 13},
+ {0, 23, 0, 13},
+ {1, 13, 0, 14},
+ {0, 24, 0, 14},
+ {43, 1, 1, 15},
+ {44, 1, 1, 15},
+ /* 011111110xxxx00 or 011111110xxxx01 */
+ {2, 2, 1, 11},
+ {26, 1, 1, 11},
+ {30, 1, 1, 12},
+ {31, 1, 1, 12},
+ {0, 4, 1, 13},
+ {5, 2, 1, 13},
+ {0, 25, 0, 14},
+ {0, 26, 0, 14},
+ /* 0111111110xxxx00 or 0111111110xxxx01 */
+ {32, 1, 1, 12},
+ {33, 1, 1, 12},
+ {6, 2, 1, 13},
+ {7, 2, 1, 13},
+ {0, 5, 1, 14},
+ {1, 4, 1, 14},
+ /* 01111111110xxxx00 or 01111111110xxxx01 */
+ {8, 2, 1, 13},
+ {9, 2, 1, 13},
+ {10, 2, 1, 14},
+ {11, 2, 1, 14},
+ /* 011111111110xxxx00 or 011111111110xxxx01 */
+ {12, 2, 1, 14},
+ {38, 1, 1, 14},
+ /* 1xxxx10 or 1xxxx11 from 11 zeros to 0 zeros*/
+ {0, 1, 0, 3},
+ {0, 2, 0, 3},
+ {0, 3, 0, 4},
+ {0, 1, 1, 4},
+ {1, 1, 1, 5},
+ {2, 1, 1, 5},
+ {5, 1, 1, 6},
+ {6, 1, 1, 6},
+ {10, 1, 1, 7},
+ {11, 1, 1, 7},
+ {13, 1, 1, 8},
+ {14, 1, 1, 8},
+ {19, 1, 1, 9},
+ {20, 1, 1, 9},
+ {24, 1, 1, 10},
+ {25, 1, 1, 10},
+ {27, 1, 1, 11},
+ {28, 1, 1, 11},
+ {34, 1, 1, 12},
+ {35, 1, 1, 12},
+ {36, 1, 1, 13},
+ {37, 1, 1, 13},
+ {39, 1, 1, 14},
+ {40, 1, 1, 14}
+};
+
+const VLCtab2 RvlcDCTtabInter[170] = /* 00xxxx00 or 00xxxx01 */
+{
+ {27, 255, 0, 5}, /* 0000 is escape code */
+ {0, 2, 0, 4},
+ {0, 3, 0, 5},
+ {3, 1, 0, 5},
+ {1, 2, 0, 6},
+ {6, 1, 0, 6},
+ {0, 4, 0, 7},
+ {2, 2, 0, 7},
+ {0, 5, 0, 8},
+ {0, 6, 0, 8},
+ {0, 7, 0, 9},
+ {1, 4, 0, 9},
+ {0, 8, 0, 10},
+ {0, 9, 0, 10},
+ {0, 10, 0, 11},
+ {0, 11, 0, 11},
+ {0, 12, 0, 12},
+ {1, 7, 0, 12},
+ {0, 13, 0, 13},
+ {0, 14, 0, 13},
+ {0, 17, 0, 14},
+ {0, 18, 0, 14},
+ {0, 19, 0, 15},
+ {3, 7, 0, 15},
+ /* 010xxxx00 or 010xxxx01 */
+ {4, 1, 0, 5},
+ {5, 1, 0, 5},
+ {7, 1, 0, 6},
+ {8, 1, 0, 6},
+ {9, 1, 0, 7},
+ {10, 1, 0, 7},
+ {1, 3, 0, 8},
+ {3, 2, 0, 8},
+ {2, 3, 0, 9},
+ {5, 2, 0, 9},
+ {1, 5, 0, 10},
+ {3, 3, 0, 10},
+ {1, 6, 0, 11},
+ {2, 4, 0, 11},
+ {2, 5, 0, 12},
+ {3, 4, 0, 12},
+ {0, 15, 0, 13},
+ {0, 16, 0, 13},
+ {1, 9, 0, 14},
+ {1, 10, 0, 14},
+ {4, 5, 0, 15},
+ {7, 4, 0, 15},
+ /* 0110xxxx00 or 0110xxxx01 */
+ {3, 1, 1, 6},
+ {4, 1, 1, 6},
+ {11, 1, 0, 7},
+ {7, 1, 1, 7},
+ {4, 2, 0, 8},
+ {12, 1, 0, 8},
+ {15, 1, 0, 9},
+ {16, 1, 0, 9},
+ {6, 2, 0, 10},
+ {7, 2, 0, 10},
+ {4, 3, 0, 11},
+ {5, 3, 0, 11},
+ {6, 3, 0, 12},
+ {7, 3, 0, 12},
+ {1, 8, 0, 13},
+ {3, 5, 0, 13},
+ {2, 6, 0, 14},
+ {2, 7, 0, 14},
+ {17, 2, 0, 15},
+ {37, 1, 0, 15},
+ /* 01110xxxx00 or 01110xxxx01 */
+ {8, 1, 1, 7},
+ {9, 1, 1, 7},
+ {13, 1, 0, 8},
+ {14, 1, 0, 8},
+ {17, 1, 0, 9},
+ {1, 2, 1, 9},
+ {8, 2, 0, 10},
+ {9, 2, 0, 10},
+ {10, 2, 0, 11},
+ {21, 1, 0, 11},
+ {11, 2, 0, 12},
+ {27, 1, 0, 12},
+ {4, 4, 0, 13},
+ {5, 4, 0, 13},
+ {3, 6, 0, 14},
+ {6, 4, 0, 14},
+ {38, 1, 0, 15},
+ {1, 5, 1, 15},
+ /* 011110xxxx00 or 011110xxxx01 */
+ {0, 2, 1, 8},
+ {12, 1, 1, 8},
+ {15, 1, 1, 9},
+ {16, 1, 1, 9},
+ {18, 1, 0, 10},
+ {19, 1, 0, 10},
+ {22, 1, 0, 11},
+ {23, 1, 0, 11},
+ {28, 1, 0, 12},
+ {29, 1, 0, 12},
+ {8, 3, 0, 13},
+ {12, 2, 0, 13},
+ {9, 3, 0, 14},
+ {13, 2, 0, 14},
+ {2, 3, 1, 15},
+ {13, 2, 1, 15},
+ /* 0111110xxxx00 or 0111110xxxx01 */
+ {17, 1, 1, 9},
+ {18, 1, 1, 9},
+ {20, 1, 0, 10},
+ {21, 1, 1, 10},
+ {24, 1, 0, 11},
+ {25, 1, 0, 11},
+ {1, 3, 1, 12},
+ {3, 2, 1, 12},
+ {30, 1, 0, 13},
+ {31, 1, 0, 13},
+ {14, 2, 0, 14},
+ {15, 2, 0, 14},
+ {41, 1, 1, 15},
+ {42, 1, 1, 15},
+ /* 01111110xxxx00 or 01111110xxxx01 */
+ {22, 1, 1, 10},
+ {23, 1, 1, 10},
+ {26, 1, 0, 11},
+ {0, 3, 1, 11},
+ {4, 2, 1, 12},
+ {29, 1, 1, 12},
+ {32, 1, 0, 13},
+ {33, 1, 0, 13},
+ {16, 2, 0, 14},
+ {34, 1, 0, 14},
+ {43, 1, 1, 15},
+ {44, 1, 1, 15},
+ /* 011111110xxxx00 or 011111110xxxx01 */
+ {2, 2, 1, 11},
+ {26, 1, 1, 11},
+ {30, 1, 1, 12},
+ {31, 1, 1, 12},
+ {0, 4, 1, 13},
+ {5, 2, 1, 13},
+ {35, 1, 0, 14},
+ {36, 1, 0, 14},
+ /* 0111111110xxxx00 or 0111111110xxxx01 */
+ {32, 1, 1, 12},
+ {33, 1, 1, 12},
+ {6, 2, 1, 13},
+ {7, 2, 1, 13},
+ {0, 5, 1, 14},
+ {1, 4, 1, 14},
+ /* 01111111110xxxx00 or 01111111110xxxx01 */
+ {8, 2, 1, 13},
+ {9, 2, 1, 13},
+ {10, 2, 1, 14},
+ {11, 2, 1, 14},
+ /* 011111111110xxxx00 or 011111111110xxxx01 */
+ {12, 2, 1, 14},
+ {38, 1, 1, 14},
+ /* 1xxxx10 or 1xxxx11 from 11 zeros to 0 zeros*/
+ {0, 1, 0, 3},
+ {1, 1, 0, 3},
+ {2, 1, 0, 4},
+ {0, 1, 1, 4},
+ {1, 1, 1, 5},
+ {2, 1, 1, 5},
+ {5, 1, 1, 6},
+ {6, 1, 1, 6},
+ {10, 1, 1, 7},
+ {11, 1, 1, 7},
+ {13, 1, 1, 8},
+ {14, 1, 1, 8},
+ {19, 1, 1, 9},
+ {20, 1, 1, 9},
+ {24, 1, 1, 10},
+ {25, 1, 1, 10},
+ {27, 1, 1, 11},
+ {28, 1, 1, 11},
+ {34, 1, 1, 12},
+ {35, 1, 1, 12},
+ {36, 1, 1, 13},
+ {37, 1, 1, 13},
+ {39, 1, 1, 14},
+ {40, 1, 1, 14}
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
diff --git a/media/codecs/m4v_h263/dec/src/vop.cpp b/media/codecs/m4v_h263/dec/src/vop.cpp
new file mode 100644
index 0000000..335846c
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/vop.cpp
@@ -0,0 +1,1660 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "log/log.h"
+
+#include "mp4dec_lib.h"
+#include "bitstream.h"
+#include "vlc_decode.h"
+#include "zigzag.h"
+
+#define OSCL_DISABLE_WARNING_CONV_POSSIBLE_LOSS_OF_DATA
+
+/* INTRA */
+const static int mpeg_iqmat_def[NCOEFF_BLOCK] =
+{
+ 8, 17, 18, 19, 21, 23, 25, 27,
+ 17, 18, 19, 21, 23, 25, 27, 28,
+ 20, 21, 22, 23, 24, 26, 28, 30,
+ 21, 22, 23, 24, 26, 28, 30, 32,
+ 22, 23, 24, 26, 28, 30, 32, 35,
+ 23, 24, 26, 28, 30, 32, 35, 38,
+ 25, 26, 28, 30, 32, 35, 38, 41,
+ 27, 28, 30, 32, 35, 38, 41, 45
+};
+
+/* INTER */
+const static int mpeg_nqmat_def[64] =
+{
+ 16, 17, 18, 19, 20, 21, 22, 23,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 18, 19, 20, 21, 22, 23, 24, 25,
+ 19, 20, 21, 22, 23, 24, 26, 27,
+ 20, 21, 22, 23, 25, 26, 27, 28,
+ 21, 22, 23, 24, 26, 27, 28, 30,
+ 22, 23, 24, 26, 27, 28, 30, 31,
+ 23, 24, 25, 27, 28, 30, 31, 33
+};
+
+/* ======================================================================== */
+/* Function : CalcNumBits() */
+/* Purpose : */
+/* In/out : */
+/* Return : Calculate the minimum number of bits required to */
+/* represent x. */
+/* Note : This is an equivalent implementation of */
+/* (long)ceil(log((double)x)/log(2.0)) */
+/* Modified : */
+/* ======================================================================== */
+int CalcNumBits(uint x)
+{
+ int i = 1;
+ while (x >>= 1) i++;
+ return i;
+}
+
+
+
+/***********************************************************CommentBegin******
+*
+* -- DecodeVolHeader -- Decode the header of a VOL
+*
+* 04/10/2000 : initial modification to the new PV-Decoder Lib format.
+* 10/12/2001 : reject non compliant bitstreams
+*
+***********************************************************CommentEnd********/
+PV_STATUS DecodeVOLHeader(VideoDecData *video, int layer)
+{
+ PV_STATUS status;
+ Vol *currVol;
+ BitstreamDecVideo *stream;
+ uint32 tmpvar, vol_shape;
+ uint32 startCode;
+ int *qmat, i, j;
+ int version_id = 1;
+#ifdef PV_TOLERATE_VOL_ERRORS
+ uint32 profile = 0x01;
+#endif
+ /* There's a "currLayer" variable inside videoDecData. */
+ /* However, we don't maintain it until we decode frame data. 04/05/2000 */
+ currVol = video->vol[layer];
+ stream = currVol->bitstream;
+ currVol->moduloTimeBase = 0;
+
+ /* Determine which start code for the decoder to begin with */
+ status = BitstreamShowBits32HC(stream, &startCode);
+
+ if (startCode == VISUAL_OBJECT_SEQUENCE_START_CODE)
+ { /* Bitstream Exhchange Fix 9/99 */
+ /* Bitstream Exchange requires we allow start with Video Object Sequence */
+ /* visual_object_sequence_start_code */
+ (void) BitstreamReadBits32HC(stream);
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8); /* profile */
+#ifndef PV_TOLERATE_VOL_ERRORS
+ if (layer) /* */
+ {
+ /* support SSPL0-2 */
+ if (tmpvar != 0x10 && tmpvar != 0x11 && tmpvar != 0x12 &&
+ tmpvar != 0xA1 && tmpvar != 0xA2 && tmpvar != 0xA3/* Core SP@L1-L3 */)
+ return PV_FAIL;
+ }
+ else
+ {
+ /* support SPL0-3 & SSPL0-2 */
+ if (tmpvar != 0x01 && tmpvar != 0x02 && tmpvar != 0x03 && tmpvar != 0x08 &&
+ /* While not technically supported, try to decode SPL4&SPL5 files as well. */
+ /* We'll fail later if the size is too large. This is to allow playback of */
+ /* some <=CIF files generated by other encoders. */
+ tmpvar != 0x04 && tmpvar != 0x05 &&
+ tmpvar != 0x10 && tmpvar != 0x11 && tmpvar != 0x12 &&
+ tmpvar != 0x21 && tmpvar != 0x22 && /* Core Profile Levels */
+ tmpvar != 0xA1 && tmpvar != 0xA2 && tmpvar != 0xA3 &&
+ tmpvar != 0xF0 && tmpvar != 0xF1 && /* Advanced Simple Profile Levels*/
+ tmpvar != 0xF2 && tmpvar != 0xF3 &&
+ tmpvar != 0xF4 && tmpvar != 0xF5)
+ return PV_FAIL;
+ }
+#else
+ profile = tmpvar;
+#endif
+
+ // save the profile and level for the query
+ currVol->profile_level_id = (uint)tmpvar; // 6/10/04
+
+
+
+ status = BitstreamShowBits32HC(stream, &tmpvar);
+ if (tmpvar == USER_DATA_START_CODE)
+ {
+ /* Something has to be done with user data 11/11/99 */
+ status = DecodeUserData(stream);
+ if (status != PV_SUCCESS) return PV_FAIL;
+ }
+ /* visual_object_start_code */
+ BitstreamShowBits32HC(stream, &tmpvar);
+ if (tmpvar != VISUAL_OBJECT_START_CODE)
+ {
+ do
+ {
+ /* Search for VOL_HEADER */
+ status = PVSearchNextM4VFrame(stream); /* search 0x00 0x00 0x01 */
+ if (status != PV_SUCCESS) return PV_FAIL; /* breaks the loop */
+ BitstreamShowBits32(stream, VOL_START_CODE_LENGTH, &tmpvar);
+ PV_BitstreamFlushBits(stream, 8);
+ }
+ while (tmpvar != VOL_START_CODE);
+ goto decode_vol;
+ }
+ else
+ {
+ BitstreamReadBits32HC(stream);
+ }
+
+ /* is_visual_object_identifier */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar)
+ {
+ /* visual_object_verid */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 4);
+ /* visual_object_priority */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 3);
+ }
+ /* visual_object_type */
+ BitstreamShowBits32(stream, 4, &tmpvar);
+ if (tmpvar == 1)
+ { /* video_signal_type */
+ PV_BitstreamFlushBits(stream, 4);
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar == 1)
+ {
+ /* video_format */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 3);
+ /* video_range */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ /* color_description */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar == 1)
+ {
+ /* color_primaries */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8);
+ /* transfer_characteristics */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8);
+ /* matrix_coefficients */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8);
+ }
+ }
+ }
+ else
+ {
+ do
+ {
+ /* Search for VOL_HEADER */
+ status = PVSearchNextM4VFrame(stream); /* search 0x00 0x00 0x01 */
+ if (status != PV_SUCCESS) return PV_FAIL; /* breaks the loop */
+ BitstreamShowBits32(stream, VOL_START_CODE_LENGTH, &tmpvar);
+ PV_BitstreamFlushBits(stream, 8);
+ }
+ while (tmpvar != VOL_START_CODE);
+ goto decode_vol;
+ }
+
+ /* next_start_code() */
+ status = PV_BitstreamByteAlign(stream); /* 10/12/01 */
+ status = BitstreamShowBits32HC(stream, &tmpvar);
+
+ if (tmpvar == USER_DATA_START_CODE)
+ {
+ /* Something has to be done to deal with user data (parse it) 11/11/99 */
+ status = DecodeUserData(stream);
+ if (status != PV_SUCCESS) return PV_FAIL;
+ }
+ status = BitstreamShowBits32(stream, 27, &tmpvar); /* 10/12/01 */
+ }
+ else
+ {
+ /* tmpvar = 0; */ /* 10/12/01 */
+ status = BitstreamShowBits32(stream, 27, &tmpvar); /* uncomment this line if you want
+ to start decoding with a
+ video_object_start_code */
+ }
+
+ if (tmpvar == VO_START_CODE)
+ {
+ /*****
+ *
+ * Read the VOL header entries from the bitstream
+ *
+ *****/
+ /* video_object_start_code */
+ tmpvar = BitstreamReadBits32(stream, 27);
+ tmpvar = (uint32) BitstreamReadBits16(stream, 5);
+
+
+ /* video_object_layer_start_code */
+ BitstreamShowBits32(stream, VOL_START_CODE_LENGTH, &tmpvar);
+ if (tmpvar != VOL_START_CODE)
+ {
+ status = BitstreamCheckEndBuffer(stream);
+ if (status == PV_END_OF_VOP)
+ {
+ video->shortVideoHeader = TRUE;
+ return PV_SUCCESS;
+ }
+ else
+ {
+ do
+ {
+ /* Search for VOL_HEADER */
+ status = PVSearchNextM4VFrame(stream);/* search 0x00 0x00 0x01 */
+ if (status != PV_SUCCESS) return PV_FAIL; /* breaks the loop */
+ BitstreamShowBits32(stream, VOL_START_CODE_LENGTH, &tmpvar);
+ PV_BitstreamFlushBits(stream, 8); /* advance the byte ptr */
+ }
+ while (tmpvar != VOL_START_CODE);
+ }
+ }
+ else
+ {
+ PV_BitstreamFlushBits(stream, 8);
+ }
+
+decode_vol:
+ PV_BitstreamFlushBits(stream, VOL_START_CODE_LENGTH - 8);
+ video->shortVideoHeader = 0;
+
+ /* vol_id (4 bits) */
+ currVol->volID = (int) BitstreamReadBits16(stream, 4);
+
+ /* RandomAccessible flag */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+
+ /* object type */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8); /* */
+
+#ifdef PV_TOLERATE_VOL_ERRORS
+ if (tmpvar == 0)
+ {
+ if (layer) /* */
+ {
+ /* support SSPL0-2 */
+ if (profile != 0x10 && profile != 0x11 && profile != 0x12)
+ return PV_FAIL;
+ tmpvar = 0x02;
+ }
+ else
+ {
+ /* support SPL0-3 & SSPL0-2 */
+ if (profile != 0x01 && profile != 0x02 && profile != 0x03 && profile != 0x08 &&
+ profile != 0x10 && profile != 0x11 && profile != 0x12)
+ return PV_FAIL;
+ tmpvar = 0x01;
+ }
+ profile |= 0x0100;
+ }
+#endif
+
+ if (layer)
+ {
+ if (tmpvar != 0x02) return PV_FAIL;
+ }
+ else
+ {
+ // Simple and advanced simple (for quant-type 1)
+ if (tmpvar != 0x01 && tmpvar != 0x11) return PV_FAIL;
+ }
+
+ /* version id specified? */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar == 1)
+ {
+ /* version ID */
+ version_id = (uint32) BitstreamReadBits16(stream, 4);
+ /* priority */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 3);
+
+ }
+
+ /* aspect ratio info */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 4);
+ if (tmpvar == 0) return PV_FAIL;
+ if (tmpvar == 0xf /* extended_par */)
+ {
+ /* width */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8);
+ /* height */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8);
+ }
+
+
+ /* control parameters present? */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+
+ /* Get the parameters (skipped) */
+ /* 03/10/99 */
+ if (tmpvar)
+ {
+ /* chroma_format */
+ tmpvar = BitstreamReadBits16(stream, 2);
+ if (tmpvar != 1) return PV_FAIL;
+ /* low_delay */
+ tmpvar = BitstreamRead1Bits(stream);
+
+ /* vbv_parameters present? */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar)
+ {
+ /* first_half_bit_rate */
+ BitstreamReadBits16(stream, 15);
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+ /* latter_half_bit_rate */
+ BitstreamReadBits16(stream, 15);
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+ /* first_half_vbv_buffer_size */
+ BitstreamReadBits16(stream, 15);
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+ /* latter_half_vbv_buffer_size */
+ BitstreamReadBits16(stream, 3);
+ /* first_half_vbv_occupancy */
+ BitstreamReadBits16(stream, 11);
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+ /* latter_half_vbv_occupancy */
+ BitstreamReadBits16(stream, 15);
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+ }
+ }
+
+ /* video_object_layer_shape (2 bits), only 00 (rect) is supported for now */
+ vol_shape = (uint32) BitstreamReadBits16(stream, 2);
+ if (vol_shape) return PV_FAIL;
+
+ /* marker bit, 03/10/99 */
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+
+ /* vop_time_increment_resolution */
+ currVol->timeIncrementResolution = BitstreamReadBits16(stream, 16);
+ if (currVol->timeIncrementResolution == 0) return PV_FAIL;
+
+ /* . since nbitsTimeIncRes will be used over and over again, */
+ /* we should put it in Vol structure. 04/12/2000. */
+ currVol->nbitsTimeIncRes = CalcNumBits((uint)currVol->timeIncrementResolution - 1);
+
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+
+ /* fixed_vop_rate */
+ currVol->fixedVopRate = (int) BitstreamRead1Bits(stream);
+ if (currVol->fixedVopRate)
+ {
+ /* fixed_vop_time_increment */
+ tmpvar = BitstreamReadBits16(stream, currVol->nbitsTimeIncRes);
+ }
+
+ /* marker bit */
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+
+ /* video_object_layer_width (13 bits) */
+ tmpvar = BitstreamReadBits16(stream, 13);
+ if (!tmpvar) return PV_FAIL;
+ video->displayWidth = video->width = tmpvar;
+
+ /* round up to a multiple of MB_SIZE. 08/09/2000 */
+ video->width = (video->width + 15) & -16;
+// video->displayWidth += (video->displayWidth & 0x1); /* displayed image should be even size */
+
+ /* marker bit */
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+
+ /* video_object_layer_height (13 bits) */
+ tmpvar = BitstreamReadBits16(stream, 13);
+ if (!tmpvar) return PV_FAIL;
+ video->displayHeight = video->height = tmpvar;
+
+ /* round up to a multiple of MB_SIZE. 08/09/2000 */
+ video->height = (video->height + 15) & -16;
+// video->displayHeight += (video->displayHeight & 0x1); /* displayed image should be even size */
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+
+ /* 03/10/99 */
+ /* interlaced */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar != 0)
+ {
+ mp4dec_log("DecodeVOLHeader(): Interlaced video is not supported.\n");
+ return PV_FAIL;
+ }
+
+ /* obmc_disable */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar == 0) return PV_FAIL;
+
+ if (version_id == 1)
+ {
+ /* sprite_enable (1 bits) */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ if (tmpvar)
+ {
+ mp4dec_log("DecodeVOLHeader(): Sprite is not supported.\n");
+ return PV_FAIL;
+ }
+ }
+ else
+ {
+ /* For version 2, vol_sprite_usage has two bits. */
+ /* sprite_enable */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 2);
+ if (tmpvar)
+ {
+ mp4dec_log("DecodeVOLHeader(): Sprite is not supported.\n");
+ return PV_FAIL;
+ }
+ }
+
+ /* not_8_bit */
+ if (BitstreamRead1Bits(stream))
+ {
+ /* quant_precision */
+ currVol->quantPrecision = BitstreamReadBits16(stream, 4);
+ /* bits_per_pixel */
+ currVol->bitsPerPixel = BitstreamReadBits16(stream, 4);
+ mp4dec_log("DecodeVOLHeader(): not an 8-bit stream.\n"); // For the time being we do not support != 8 bits
+
+ return PV_FAIL;
+ }
+ else
+ {
+ currVol->quantPrecision = 5;
+ currVol->bitsPerPixel = 8;
+ }
+
+ /* quant_type (1 bit) */
+ currVol->quantType = BitstreamRead1Bits(stream);
+ if (currVol->quantType)
+ {
+ /* load quantization matrices. 5/22/2000 */
+ /* load_intra_quant_mat (1 bit) */
+ qmat = currVol->iqmat;
+ currVol->loadIntraQuantMat = BitstreamRead1Bits(stream);
+ if (currVol->loadIntraQuantMat)
+ {
+ /* intra_quant_mat (8*64 bits) */
+ i = 0;
+ do
+ {
+ qmat[*(zigzag_inv+i)] = (int) BitstreamReadBits16(stream, 8);
+ }
+ while ((qmat[*(zigzag_inv+i)] != 0) && (++i < 64));
+
+ for (j = i; j < 64; j++)
+ qmat[*(zigzag_inv+j)] = qmat[*(zigzag_inv+i-1)];
+ }
+ else
+ {
+ oscl_memcpy(qmat, mpeg_iqmat_def, 64*sizeof(int));
+ }
+
+ qmat[0] = 0; /* necessary for switched && MPEG quant 07/09/01 */
+
+ /* load_nonintra_quant_mat (1 bit) */
+ qmat = currVol->niqmat;
+ currVol->loadNonIntraQuantMat = BitstreamRead1Bits(stream);
+ if (currVol->loadNonIntraQuantMat)
+ {
+ /* nonintra_quant_mat (8*64 bits) */
+ i = 0;
+ do
+ {
+ qmat[*(zigzag_inv+i)] = (int) BitstreamReadBits16(stream, 8);
+ }
+ while ((qmat[*(zigzag_inv+i)] != 0) && (++i < 64));
+
+ for (j = i; j < 64; j++)
+ qmat[*(zigzag_inv+j)] = qmat[*(zigzag_inv+i-1)];
+ }
+ else
+ {
+ oscl_memcpy(qmat, mpeg_nqmat_def, 64*sizeof(int));
+ }
+ }
+
+ if (version_id != 1)
+ {
+ /* quarter_sample enabled */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar) return PV_FAIL;
+ }
+
+ /* complexity_estimation_disable */
+ currVol->complexity_estDisable = BitstreamRead1Bits(stream);
+ if (currVol->complexity_estDisable == 0)
+ {
+ currVol->complexity_estMethod = BitstreamReadBits16(stream, 2);
+
+ if (currVol->complexity_estMethod < 2)
+ {
+ /* shape_complexity_estimation_disable */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar == 0)
+ {
+ mp4dec_log("DecodeVOLHeader(): Shape Complexity estimation is not supported.\n");
+ return PV_FAIL;
+ }
+ /* texture_complexity_estimation_set_1_disable */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar == 0)
+ {
+ currVol->complexity.text_1 = BitstreamReadBits16(stream, 4);
+ }
+ /* marker bit */
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+ /* texture_complexity_estimation_set_2_disable */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar == 0)
+ {
+ currVol->complexity.text_2 = BitstreamReadBits16(stream, 4);
+ }
+ /* motion_compensation_complexity_disable */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar == 0)
+ {
+ currVol->complexity.mc = BitstreamReadBits16(stream, 6);
+ }
+ /* marker bit */
+ if (!BitstreamRead1Bits(stream)) return PV_FAIL;
+
+ if (currVol->complexity_estMethod == 1)
+ { /* version2_complexity_estimation_disable */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar == 0)
+ {
+ mp4dec_log("DecodeVOLHeader(): sadct, quarter pel not supported.\n");
+ return PV_FAIL;
+ }
+ }
+ }
+ }
+
+ /* 03/10/99 */
+ /* resync_marker_disable */
+ currVol->errorResDisable = (int) BitstreamRead1Bits(stream);
+ /* data_partititioned */
+ currVol->dataPartitioning = (int) BitstreamRead1Bits(stream);
+
+ video->vlcDecCoeffIntra = &VlcDecTCOEFIntra;
+ video->vlcDecCoeffInter = &VlcDecTCOEFInter;
+
+ if (currVol->dataPartitioning)
+ {
+ if (layer) return PV_FAIL; /* */
+ /* reversible_vlc */
+ currVol->useReverseVLC = (int)BitstreamRead1Bits(stream);
+ if (currVol->useReverseVLC)
+ {
+ video->vlcDecCoeffIntra = &RvlcDecTCOEFIntra;
+ video->vlcDecCoeffInter = &RvlcDecTCOEFInter;
+ }
+ currVol->errorResDisable = 0;
+ }
+ else
+ {
+ currVol->useReverseVLC = 0;
+ }
+
+ if (version_id != 1)
+ {
+ /* newpred_enable */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar) return PV_FAIL;
+
+ /* reduced_resolution_vop */
+ tmpvar = BitstreamRead1Bits(stream);
+ if (tmpvar) return PV_FAIL;
+
+ }
+
+ /* Intra AC/DC prediction is always true */
+ video->intra_acdcPredDisable = 0;
+ /* scalability */
+ currVol->scalability = (int) BitstreamRead1Bits(stream);
+
+ if (currVol->scalability)
+ {
+ if (layer == 0) return PV_FAIL; /* */
+ /* hierarchy_type: 1 : temporal, 0 : spatial */
+ /* 03/10/99 */
+ currVol->scalType = (int) BitstreamRead1Bits(stream); /* */
+ if (!currVol->scalType) return PV_FAIL;
+
+ /* ref_layer_id (4 bits) */
+ currVol->refVolID = (int) BitstreamReadBits16(stream, 4);
+ if (layer) /* */
+ {
+ if (currVol->refVolID != video->vol[0]->volID) return PV_FAIL;
+ }
+ /* ref_layer_sampling_direc (1 bits) */
+ /* 1 : ref. layer has higher resolution */
+ /* 0 : ref. layer has equal or lower resolution */
+ currVol->refSampDir = (int) BitstreamRead1Bits(stream);
+ if (currVol->refSampDir) return PV_FAIL;
+
+ /* hor_sampling_factor_n (5 bits) */
+ currVol->horSamp_n = (int) BitstreamReadBits16(stream, 5);
+
+ /* hor_sampling_factor_m (5 bits) */
+ currVol->horSamp_m = (int) BitstreamReadBits16(stream, 5);
+
+ if (currVol->horSamp_m == 0) return PV_FAIL;
+ if (currVol->horSamp_n != currVol->horSamp_m) return PV_FAIL;
+
+ /* ver_sampling_factor_n (5 bits) */
+ currVol->verSamp_n = (int) BitstreamReadBits16(stream, 5);
+
+ /* ver_sampling_factor_m (5 bits) */
+ currVol->verSamp_m = (int) BitstreamReadBits16(stream, 5);
+
+ if (currVol->verSamp_m == 0) return PV_FAIL;
+ if (currVol->verSamp_n != currVol->verSamp_m) return PV_FAIL;
+
+
+ /* enhancement_type: 1 : partial region, 0 : full region */
+ /* 04/10/2000: we only support full region enhancement layer. */
+ if (BitstreamRead1Bits(stream)) return PV_FAIL;
+ }
+
+ PV_BitstreamByteAlign(stream);
+
+ status = BitstreamShowBits32HC(stream, &tmpvar);
+
+ /* if we hit the end of buffer, tmpvar == 0. 08/30/2000 */
+ if (tmpvar == USER_DATA_START_CODE)
+ {
+ status = DecodeUserData(stream);
+ /* you should not check for status here 03/19/2002 */
+ status = PV_SUCCESS;
+ }
+
+ /* Compute some convenience variables: 04/13/2000 */
+ video->nMBPerRow = video->width / MB_SIZE;
+ video->nMBPerCol = video->height / MB_SIZE;
+ video->nTotalMB = video->nMBPerRow * video->nMBPerCol;
+ video->nBitsForMBID = CalcNumBits((uint)video->nTotalMB - 1);
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ video->modified_quant = 0;
+ video->advanced_INTRA = 0;
+ video->deblocking = 0;
+ video->slice_structure = 0;
+#endif
+ }
+ else
+ {
+ /* SHORT_HEADER */
+ status = BitstreamShowBits32(stream, SHORT_VIDEO_START_MARKER_LENGTH, &tmpvar);
+
+ if (tmpvar == SHORT_VIDEO_START_MARKER)
+ {
+ video->shortVideoHeader = TRUE;
+ }
+ else
+ {
+ do
+ {
+ /* Search for VOL_HEADER */
+ status = PVSearchNextM4VFrame(stream); /* search 0x00 0x00 0x01 */
+ if (status != PV_SUCCESS) return PV_FAIL; /* breaks the loop */
+ BitstreamShowBits32(stream, VOL_START_CODE_LENGTH, &tmpvar);
+ PV_BitstreamFlushBits(stream, 8);
+ }
+ while (tmpvar != VOL_START_CODE);
+ goto decode_vol;
+ }
+ }
+#ifdef PV_TOLERATE_VOL_ERRORS
+ if (profile > 0xFF || profile == 0)
+ {
+ return PV_BAD_VOLHEADER;
+ }
+#endif
+
+ return status;
+}
+
+
+/***********************************************************CommentBegin******
+*
+* -- DecodeGOV -- Decodes the Group of VOPs from bitstream
+*
+* 04/20/2000 initial modification to the new PV-Decoder Lib format.
+*
+***********************************************************CommentEnd********/
+PV_STATUS DecodeGOVHeader(BitstreamDecVideo *stream, uint32 *time_base)
+{
+ uint32 tmpvar, time_s;
+ int closed_gov, broken_link;
+
+ /* group_start_code (32 bits) */
+// tmpvar = BitstreamReadBits32(stream, 32);
+
+ /* hours */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 5);
+ time_s = tmpvar * 3600;
+
+ /* minutes */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 6);
+ time_s += tmpvar * 60;
+
+ /* marker bit */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+
+ /* seconds */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 6);
+ time_s += tmpvar;
+
+ /* We have to check the timestamp here. If the sync timestamp is */
+ /* earlier than the previous timestamp or longer than 60 sec. */
+ /* after the previous timestamp, assume the GOV header is */
+ /* corrupted. 05/12/2000 */
+ *time_base = time_s; /* 02/27/2002 */
+// *time_base = *time_base/1000;
+// tmpvar = time_s - *time_base;
+// if (tmpvar <= 60) *time_base = time_s;
+// else return PV_FAIL;
+
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ closed_gov = tmpvar;
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ broken_link = tmpvar;
+
+ if ((closed_gov == 0) && (broken_link == 1))
+ {
+ return PV_SUCCESS; /* 03/15/2002 you can also return PV_FAIL */
+ }
+
+ PV_BitstreamByteAlign(stream);
+
+ BitstreamShowBits32HC(stream, &tmpvar);
+
+ while (tmpvar == USER_DATA_START_CODE) /* 03/15/2002 */
+ {
+ DecodeUserData(stream);
+ BitstreamShowBits32HC(stream, &tmpvar);
+ }
+
+ return PV_SUCCESS;
+}
+
+/***********************************************************CommentBegin******
+*
+* -- DecodeVopHeader -- Decodes the VOPheader information from the bitstream
+*
+* 04/12/2000 Initial port to the new PV decoder library format.
+* 05/10/2000 Error resilient decoding of vop header.
+*
+***********************************************************CommentEnd********/
+PV_STATUS DecodeVOPHeader(VideoDecData *video, Vop *currVop, Bool use_ext_timestamp)
+{
+ PV_STATUS status = PV_SUCCESS;
+ Vol *currVol = video->vol[video->currLayer];
+ BitstreamDecVideo *stream = currVol->bitstream;
+ uint32 tmpvar;
+ int time_base;
+
+ /*****
+ * Read the VOP header from the bitstream (No shortVideoHeader Mode here!)
+ *****/
+ BitstreamShowBits32HC(stream, &tmpvar);
+
+ /* check if we have a GOV header here. 08/30/2000 */
+ if (tmpvar == GROUP_START_CODE)
+ {
+ tmpvar = BitstreamReadBits32HC(stream);
+// rewindBitstream(stream, START_CODE_LENGTH); /* for backward compatibility */
+ status = DecodeGOVHeader(stream, &tmpvar);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+// use_ext_timestamp = TRUE; /* 02/08/2002 */
+ /* We should have a VOP header following the GOV header. 03/15/2001 */
+ BitstreamShowBits32HC(stream, &tmpvar);
+ }
+#ifdef PV_SUPPORT_TEMPORAL_SCALABILITY
+ currVop->timeStamp = -1;
+#endif
+ if (tmpvar == VOP_START_CODE)
+ {
+ tmpvar = BitstreamReadBits32HC(stream);
+ }
+ else
+ {
+ PV_BitstreamFlushBits(stream, 8); // advance by a byte
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+
+
+ /* vop_prediction_type (2 bits) */
+ currVop->predictionType = (int) BitstreamReadBits16(stream, 2);
+
+ /* modulo_time_base (? bits) */
+ time_base = -1;
+ do
+ {
+ time_base++;
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+ }
+ while (tmpvar == 1);
+
+
+
+ if (!use_ext_timestamp)
+ {
+ currVol->moduloTimeBase += 1000 * time_base; /* milliseconds based MTB 11/12/01 */
+ }
+
+ /* marker_bit (1 bit) */
+ if (!BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ /* vop_time_increment (1-15 bits) in Nov_Compliant (1-16 bits) */
+ /* we always assumes fixed vop rate here */
+ currVop->timeInc = BitstreamReadBits16(stream, currVol->nbitsTimeIncRes);
+
+
+ /* marker_bit (1 bit) */
+ if (!BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ /* vop_coded */
+ currVop->vopCoded = (int) BitstreamRead1Bits(stream);
+
+
+ if (currVop->vopCoded == 0)
+ {
+ status = PV_SUCCESS;
+ goto return_point;
+ }
+
+
+ /* read vop_rounding_type */
+ if (currVop->predictionType == P_VOP)
+ {
+ currVop->roundingType = (int) BitstreamRead1Bits(stream);
+ }
+ else
+ {
+ currVop->roundingType = 0;
+ }
+
+ if (currVol->complexity_estDisable == 0)
+ {
+ if (currVol->complexity_estMethod < 2) /* OCT 2002 */
+ {
+ if ((currVol->complexity.text_1 >> 3) & 0x1) /* intra */
+ BitstreamReadBits16(stream, 8);
+ if (currVol->complexity.text_1 & 0x1) /* not_coded */
+ BitstreamReadBits16(stream, 8);
+ if ((currVol->complexity.text_2 >> 3) & 0x1) /* dct_coefs */
+ BitstreamReadBits16(stream, 8);
+ if ((currVol->complexity.text_2 >> 2) & 0x1) /* dct_lines */
+ BitstreamReadBits16(stream, 8);
+ if ((currVol->complexity.text_2 >> 1) & 0x1) /* vlc_symbols */
+ BitstreamReadBits16(stream, 8);
+ if (currVol->complexity.text_2 & 0x1) /* vlc_bits */
+ BitstreamReadBits16(stream, 4);
+
+ if (currVop->predictionType != I_VOP)
+ {
+ if ((currVol->complexity.text_1 >> 2) & 0x1) /* inter */
+ BitstreamReadBits16(stream, 8);
+ if ((currVol->complexity.text_1 >> 1) & 0x1) /* inter_4v */
+ BitstreamReadBits16(stream, 8);
+ if ((currVol->complexity.mc >> 5) & 0x1) /* apm */
+ BitstreamReadBits16(stream, 8);
+ if ((currVol->complexity.mc >> 4) & 0x1) /* npm */
+ BitstreamReadBits16(stream, 8);
+ /* interpolate_mc_q */
+ if ((currVol->complexity.mc >> 2) & 0x1) /* forw_back_mc_q */
+ BitstreamReadBits16(stream, 8);
+ if ((currVol->complexity.mc >> 1) & 0x1) /* halfpel2 */
+ BitstreamReadBits16(stream, 8);
+ if (currVol->complexity.mc & 0x1) /* halfpel4 */
+ BitstreamReadBits16(stream, 8);
+ }
+ if (currVop->predictionType == B_VOP)
+ {
+ if ((currVol->complexity.mc >> 3) & 0x1) /* interpolate_mc_q */
+ BitstreamReadBits16(stream, 8);
+ }
+ }
+ }
+
+ /* read intra_dc_vlc_thr */
+ currVop->intraDCVlcThr = (int) BitstreamReadBits16(stream, 3);
+
+ /* read vop_quant (currVol->quantPrecision bits) */
+ currVop->quantizer = (int16) BitstreamReadBits16(stream, currVol->quantPrecision);
+ if (currVop->quantizer == 0)
+ {
+ currVop->quantizer = video->prevVop->quantizer;
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+
+ /* read vop_fcode_forward */
+ if (currVop->predictionType != I_VOP)
+ {
+ tmpvar = (uint32) BitstreamReadBits16(stream, 3);
+ if (tmpvar < 1)
+ {
+ currVop->fcodeForward = 1;
+ status = PV_FAIL;
+ goto return_point;
+ }
+ currVop->fcodeForward = tmpvar;
+ }
+ else
+ {
+ currVop->fcodeForward = 0;
+ }
+
+ /* read vop_fcode_backward */
+ if (currVop->predictionType == B_VOP)
+ {
+ tmpvar = (uint32) BitstreamReadBits16(stream, 3);
+ if (tmpvar < 1)
+ {
+ currVop->fcodeBackward = 1;
+ status = PV_FAIL;
+ goto return_point;
+ }
+ currVop->fcodeBackward = tmpvar;
+ }
+ else
+ {
+ currVop->fcodeBackward = 0;
+ }
+
+ if (currVol->scalability)
+ {
+ currVop->refSelectCode = (int) BitstreamReadBits16(stream, 2);
+ }
+
+return_point:
+ return status;
+}
+
+
+/***********************************************************CommentBegin******
+*
+* -- VideoPlaneWithShortHeader -- Decodes the short_video_header information from the bitstream
+* Modified :
+ 04/23/2001. Remove the codes related to the
+ "first pass" decoding. We use a different function
+ to set up the decoder now.
+***********************************************************CommentEnd********/
+PV_STATUS DecodeShortHeader(VideoDecData *video, Vop *currVop)
+{
+ PV_STATUS status = PV_SUCCESS;
+ Vol *currVol = video->vol[0];
+ BitstreamDecVideo *stream = currVol->bitstream;
+ uint32 tmpvar;
+ int32 size;
+
+ int extended_PTYPE = FALSE;
+ int UFEP = 0, custom_PFMT = 0, custom_PCF = 0;
+
+ status = BitstreamShowBits32(stream, SHORT_VIDEO_START_MARKER_LENGTH, &tmpvar);
+
+ if (tmpvar != SHORT_VIDEO_START_MARKER)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+
+ PV_BitstreamFlushBits(stream, SHORT_VIDEO_START_MARKER_LENGTH);
+
+ /* Temporal reference. Using vop_time_increment_resolution = 30000 */
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8);
+ currVop->temporalRef = (int) tmpvar;
+
+
+ currVop->timeInc = 0xff & (256 + currVop->temporalRef - video->prevVop->temporalRef);
+ currVol->moduloTimeBase += currVop->timeInc; /* mseconds 11/12/01 */
+ /* Marker Bit */
+ if (!BitstreamRead1Bits(stream))
+ {
+ mp4dec_log("DecodeShortHeader(): Marker bit wrong.\n");
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ /* Zero Bit */
+ if (BitstreamRead1Bits(stream))
+ {
+ mp4dec_log("DecodeShortHeader(): Zero bit wrong.\n");
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ /*split_screen_indicator*/
+ if (BitstreamRead1Bits(stream))
+ {
+ mp4dec_log("DecodeShortHeader(): Split Screen not supported.\n");
+ VideoDecoderErrorDetected(video);
+ }
+
+ /*document_freeze_camera*/
+ if (BitstreamRead1Bits(stream))
+ {
+ mp4dec_log("DecodeShortHeader(): Freeze Camera not supported.\n");
+ VideoDecoderErrorDetected(video);
+ }
+
+ /*freeze_picture_release*/
+ if (BitstreamRead1Bits(stream))
+ {
+ mp4dec_log("DecodeShortHeader(): Freeze Release not supported.\n");
+ VideoDecoderErrorDetected(video);
+ }
+ /* source format */
+ switch (BitstreamReadBits16(stream, 3))
+ {
+ case 1:
+ if (video->size < 128*96)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 128;
+ video->displayHeight = video->height = 96;
+ break;
+
+ case 2:
+ if (video->size < 176*144)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 176;
+ video->displayHeight = video->height = 144;
+ break;
+
+ case 3:
+ if (video->size < 352*288)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 352;
+ video->displayHeight = video->height = 288;
+ break;
+
+ case 4:
+ if (video->size < 704*576)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 704;
+ video->displayHeight = video->height = 576;
+ break;
+
+ case 5:
+ if (video->size < 1408*1152)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 1408;
+ video->displayHeight = video->height = 1152;
+ break;
+
+ case 7:
+ extended_PTYPE = TRUE;
+ break;
+
+ default:
+ /* Msg("H.263 source format not legal\n"); */
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+
+ currVop->roundingType = 0;
+
+ if (extended_PTYPE == FALSE)
+ {
+ currVop->predictionType = (int) BitstreamRead1Bits(stream);
+
+ /* four_reserved_zero_bits */
+ if (BitstreamReadBits16(stream, 4))
+ {
+ mp4dec_log("DecodeShortHeader(): Reserved bits wrong.\n");
+ status = PV_FAIL;
+ goto return_point;
+ }
+ }
+ else
+ {
+ UFEP = BitstreamReadBits16(stream, 3);
+ if (UFEP == 1)
+ {
+ /* source format */
+ switch (BitstreamReadBits16(stream, 3))
+ {
+ case 1:
+ if (video->size < 128*96)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 128;
+ video->displayHeight = video->height = 96;
+ break;
+
+ case 2:
+ if (video->size < 176*144)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 176;
+ video->displayHeight = video->height = 144;
+ break;
+
+ case 3:
+ if (video->size < 352*288)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 352;
+ video->displayHeight = video->height = 288;
+ break;
+
+ case 4:
+ if (video->size < 704*576)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 704;
+ video->displayHeight = video->height = 576;
+ break;
+
+ case 5:
+ if (video->size < 1408*1152)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = video->width = 1408;
+ video->displayHeight = video->height = 1152;
+ break;
+
+ case 6:
+ custom_PFMT = TRUE;
+ break;
+
+ default:
+ /* Msg("H.263 source format not legal\n"); */
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ custom_PCF = BitstreamRead1Bits(stream);
+ /* unrestricted MV */
+ if (BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ /* SAC */
+ if (BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ /* AP */
+ if (BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ video->advanced_INTRA = BitstreamRead1Bits(stream);
+
+ video->deblocking = BitstreamRead1Bits(stream);
+
+ video->slice_structure = BitstreamRead1Bits(stream);
+
+ /* RPS, ISD, AIV */
+ if (BitstreamReadBits16(stream, 3))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->modified_quant = BitstreamRead1Bits(stream);
+
+ /* Marker Bit and reserved*/
+ if (BitstreamReadBits16(stream, 4) != 8)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ }
+#ifndef PV_ANNEX_IJKT_SUPPORT
+ if (video->advanced_INTRA | video->deblocking | video->modified_quant | video->modified_quant)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+#endif
+
+ if (UFEP == 0 || UFEP == 1)
+ {
+ tmpvar = BitstreamReadBits16(stream, 3);
+ if (tmpvar > 1)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ currVop->predictionType = tmpvar;
+ /* RPR */
+ if (BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ /* RRU */
+ if (BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ currVop->roundingType = (int) BitstreamRead1Bits(stream);
+ if (BitstreamReadBits16(stream, 3) != 1)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ }
+ else
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ /* CPM */
+ if (BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ /* CPFMT */
+ if (custom_PFMT == 1 && UFEP == 1)
+ {
+ /* aspect ratio */
+ tmpvar = BitstreamReadBits16(stream, 4);
+ if (tmpvar == 0)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ /* Extended PAR */
+ if (tmpvar == 0xF)
+ {
+ /* Read par_width and par_height but do nothing */
+ /* par_width */
+ tmpvar = BitstreamReadBits16(stream, 8);
+
+ /* par_height */
+ tmpvar = BitstreamReadBits16(stream, 8);
+ }
+ tmpvar = BitstreamReadBits16(stream, 9);
+
+ int tmpDisplayWidth = (tmpvar + 1) << 2;
+ /* marker bit */
+ if (!BitstreamRead1Bits(stream))
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ tmpvar = BitstreamReadBits16(stream, 9);
+ if (tmpvar == 0)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ int tmpDisplayHeight = tmpvar << 2;
+ int tmpHeight = (tmpDisplayHeight + 15) & -16;
+ int tmpWidth = (tmpDisplayWidth + 15) & -16;
+
+ if (tmpWidth > video->width)
+ {
+ // while allowed by the spec, this decoder does not actually
+ // support an increase in size.
+ ALOGE("width increase not supported");
+ status = PV_FAIL;
+ goto return_point;
+ }
+ if (tmpHeight * tmpWidth > video->size)
+ {
+ // This is just possibly "b/37079296".
+ ALOGE("b/37079296");
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->displayWidth = tmpDisplayWidth;
+ video->width = tmpWidth;
+ video->displayHeight = tmpDisplayHeight;
+ video->height = tmpHeight;
+
+ video->nTotalMB = video->width / MB_SIZE * video->height / MB_SIZE;
+
+ if (video->nTotalMB <= 48)
+ {
+ video->nBitsForMBID = 6;
+ }
+ else if (video->nTotalMB <= 99)
+ {
+ video->nBitsForMBID = 7;
+ }
+ else if (video->nTotalMB <= 396)
+ {
+ video->nBitsForMBID = 9;
+ }
+ else if (video->nTotalMB <= 1584)
+ {
+ video->nBitsForMBID = 11;
+ }
+ else if (video->nTotalMB <= 6336)
+ {
+ video->nBitsForMBID = 13 ;
+ }
+ else if (video->nTotalMB <= 9216)
+ {
+ video->nBitsForMBID = 14 ;
+ }
+ else
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ }
+ if (UFEP == 1 && custom_PCF == 1)
+ {
+ BitstreamRead1Bits(stream);
+
+ tmpvar = BitstreamReadBits16(stream, 7);
+ if (tmpvar == 0)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ }
+
+ if (custom_PCF == 1)
+ {
+ currVop->ETR = BitstreamReadBits16(stream, 2);
+ }
+
+ if (UFEP == 1 && video->slice_structure == 1)
+ {
+ /* SSS */
+ tmpvar = BitstreamReadBits16(stream, 2);
+ if (tmpvar != 0)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ }
+ }
+
+ /* Recalculate number of macroblocks per row & col since */
+ /* the frame size can change. 04/23/2001. */
+ video->nMBinGOB = video->nMBPerRow = video->width / MB_SIZE;
+ video->nGOBinVop = video->nMBPerCol = video->height / MB_SIZE;
+ video->nTotalMB = video->nMBPerRow * video->nMBPerCol;
+ if (custom_PFMT == 0 || UFEP == 0)
+ {
+ video->nBitsForMBID = CalcNumBits((uint)video->nTotalMB - 1); /* otherwise calculate above */
+ }
+ size = (int32)video->width * video->height;
+ if (currVop->predictionType == P_VOP && size > video->videoDecControls->size)
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+ video->videoDecControls->size = size;
+ video->currVop->uChan = video->currVop->yChan + size;
+ video->currVop->vChan = video->currVop->uChan + (size >> 2);
+ video->prevVop->uChan = video->prevVop->yChan + size;
+ video->prevVop->vChan = video->prevVop->uChan + (size >> 2);
+
+
+ currVop->quantizer = (int16) BitstreamReadBits16(stream, 5);
+
+ if (currVop->quantizer == 0) /* 04/03/01 */
+ {
+ currVop->quantizer = video->prevVop->quantizer;
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+
+ /* Zero bit */
+ if (extended_PTYPE == FALSE)
+ {
+ if (BitstreamRead1Bits(stream))
+ {
+ mp4dec_log("DecodeShortHeader(): Zero bit wrong.\n");
+ status = PV_FAIL;
+ goto return_point;
+ }
+ }
+ /* pei */
+ tmpvar = (uint32) BitstreamRead1Bits(stream);
+
+ while (tmpvar)
+ {
+ tmpvar = (uint32) BitstreamReadBits16(stream, 8); /* "PSPARE" */
+ tmpvar = (uint32) BitstreamRead1Bits(stream); /* "PEI" */
+ }
+
+ if (video->slice_structure) /* ANNEX_K */
+ {
+ if (!BitstreamRead1Bits(stream)) /* SEPB1 */
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ // if (currVol->nBitsForMBID //
+ if (BitstreamReadBits16(stream, video->nBitsForMBID))
+ {
+ status = PV_FAIL; /* no ASO, RS support for Annex K */
+ goto return_point;
+ }
+
+ if (!BitstreamRead1Bits(stream)) /*SEPB3 */
+ {
+ status = PV_FAIL;
+ goto return_point;
+ }
+
+ }
+ /* Setting of other VOP-header parameters */
+ currVop->gobNumber = 0;
+ currVop->vopCoded = 1;
+
+ currVop->intraDCVlcThr = 0;
+ currVop->gobFrameID = 0; /* initial value, 05/22/00 */
+ currVol->errorResDisable = 0;
+ /*PutVopInterlaced(0,curr_vop); no implemented yet */
+ if (currVop->predictionType != I_VOP)
+ currVop->fcodeForward = 1;
+ else
+ currVop->fcodeForward = 0;
+
+return_point:
+
+ return status;
+}
+/***********************************************************CommentBegin******
+*
+* -- PV_DecodeVop -- Decodes the VOP information from the bitstream
+*
+* 04/12/2000
+* Initial port to the new PV decoder library format.
+* This function is different from the one in MoMuSys MPEG-4
+* visual decoder. We handle combined mode with or withput
+* error resilience and H.263 mode through the sam path now.
+*
+* 05/04/2000
+* Added temporal scalability to the decoder.
+*
+***********************************************************CommentEnd********/
+PV_STATUS PV_DecodeVop(VideoDecData *video)
+{
+ Vol *currVol = video->vol[video->currLayer];
+ PV_STATUS status;
+ uint32 tmpvar;
+
+ /*****
+ * Do scalable or non-scalable decoding of the current VOP
+ *****/
+
+ if (!currVol->scalability)
+ {
+ if (currVol->dataPartitioning)
+ {
+ /* Data partitioning mode comes here */
+ status = DecodeFrameDataPartMode(video);
+ }
+ else
+ {
+ /* Combined mode with or without error resilience */
+ /* and short video header comes here. */
+ status = DecodeFrameCombinedMode(video);
+ }
+ }
+ else
+ {
+#ifdef DO_NOT_FOLLOW_STANDARD
+ /* according to the standard, only combined mode is allowed */
+ /* in the enhancement layer. 06/01/2000. */
+ if (currVol->dataPartitioning)
+ {
+ /* Data partitioning mode comes here */
+ status = DecodeFrameDataPartMode(video);
+ }
+ else
+ {
+ /* Combined mode with or without error resilience */
+ /* and short video header comes here. */
+ status = DecodeFrameCombinedMode(video);
+ }
+#else
+ status = DecodeFrameCombinedMode(video);
+#endif
+ }
+
+ /* This part is for consuming Visual_object_sequence_end_code and EOS Code */ /* 10/15/01 */
+ if (!video->shortVideoHeader)
+ {
+ /* at this point bitstream is expected to be byte aligned */
+ BitstreamByteAlignNoForceStuffing(currVol->bitstream);
+
+ status = BitstreamShowBits32HC(currVol->bitstream, &tmpvar); /* 07/07/01 */
+ if (tmpvar == VISUAL_OBJECT_SEQUENCE_END_CODE)/* VOS_END_CODE */
+ {
+ PV_BitstreamFlushBits(currVol->bitstream, 16);
+ PV_BitstreamFlushBits(currVol->bitstream, 16);
+ }
+
+ }
+ else
+ {
+#ifdef PV_ANNEX_IJKT_SUPPORT
+ if (video->deblocking)
+ {
+ H263_Deblock(video->currVop->yChan, video->width, video->height, video->QPMB, video->headerInfo.Mode, 0, 0);
+ H263_Deblock(video->currVop->uChan, video->width >> 1, video->height >> 1, video->QPMB, video->headerInfo.Mode, 1, video->modified_quant);
+ H263_Deblock(video->currVop->vChan, video->width >> 1, video->height >> 1, video->QPMB, video->headerInfo.Mode, 1, video->modified_quant);
+ }
+#endif
+ /* Read EOS code for shortheader bitstreams */
+ status = BitstreamShowBits32(currVol->bitstream, 22, &tmpvar);
+ if (tmpvar == SHORT_VIDEO_END_MARKER)
+ {
+ PV_BitstreamFlushBits(currVol->bitstream, 22);
+ }
+ else
+ {
+ status = PV_BitstreamShowBitsByteAlign(currVol->bitstream, 22, &tmpvar);
+ if (tmpvar == SHORT_VIDEO_END_MARKER)
+ {
+ PV_BitstreamByteAlign(currVol->bitstream);
+ PV_BitstreamFlushBits(currVol->bitstream, 22);
+ }
+ }
+ }
+ return status;
+}
+
+
+/***********************************************************CommentBegin******
+*
+* -- CalcVopDisplayTime -- calculate absolute time when VOP is to be displayed
+*
+* 04/12/2000 Initial port to the new PV decoder library format.
+*
+***********************************************************CommentEnd********/
+uint32 CalcVopDisplayTime(Vol *currVol, Vop *currVop, int shortVideoHeader)
+{
+ uint32 display_time;
+
+
+ /*****
+ * Calculate the time when the VOP is to be displayed next
+ *****/
+
+ if (!shortVideoHeader)
+ {
+ display_time = (uint32)(currVol->moduloTimeBase + (((int32)currVop->timeInc - (int32)currVol->timeInc_offset) * 1000) / ((int32)currVol->timeIncrementResolution)); /* 11/12/2001 */
+ if (currVop->timeStamp >= display_time)
+ {
+ display_time += 1000; /* this case is valid if GOVHeader timestamp is ignored */
+ }
+ }
+ else
+ {
+ display_time = (uint32)(currVol->moduloTimeBase * 33 + (currVol->moduloTimeBase * 11) / 30); /* 11/12/2001 */
+ }
+
+ return(display_time);
+}
+
diff --git a/media/codecs/m4v_h263/dec/src/zigzag.h b/media/codecs/m4v_h263/dec/src/zigzag.h
new file mode 100644
index 0000000..4690a18
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/zigzag.h
@@ -0,0 +1,72 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#ifndef zigzag_H
+#define zigzag_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ extern const int zigzag_inv[3*NCOEFF_BLOCK];
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; GLOBAL FUNCTION DEFINITIONS
+ ; Function Prototype declaration
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; END
+ ----------------------------------------------------------------------------*/
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
diff --git a/media/codecs/m4v_h263/dec/src/zigzag_tab.cpp b/media/codecs/m4v_h263/dec/src/zigzag_tab.cpp
new file mode 100644
index 0000000..33dbb14
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/src/zigzag_tab.cpp
@@ -0,0 +1,110 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#include "mp4dec_api.h"
+#include "mp4def.h"
+#include "zigzag.h"
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int zigzag_inv[3*NCOEFF_BLOCK] =
+{
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63,
+//};
+
+ /* Vertical inverse zigzag */
+//const static Int zigzag_v_inv[NCOEFF_BLOCK] = {
+ 0, 8, 16, 24, 1, 9, 2, 10,
+ 17, 25, 32, 40, 48, 56, 57, 49,
+ 41, 33, 26, 18, 3, 11, 4, 12,
+ 19, 27, 34, 42, 50, 58, 35, 43,
+ 51, 59, 20, 28, 5, 13, 6, 14,
+ 21, 29, 36, 44, 52, 60, 37, 45,
+ 53, 61, 22, 30, 7, 15, 23, 31,
+ 38, 46, 54, 62, 39, 47, 55, 63,
+//};
+ /* Horizontal inverse zigzag*/
+//const static Int zizag_h_inv[NCOEFF_BLOCK] = {
+ 0, 1, 2, 3, 8, 9, 16, 17,
+ 10, 11, 4, 5, 6, 7, 15, 14,
+ 13, 12, 19, 18, 24, 25, 32, 33,
+ 26, 27, 20, 21, 22, 23, 28, 29,
+ 30, 31, 34, 35, 40, 41, 48, 49,
+ 42, 43, 36, 37, 38, 39, 44, 45,
+ 46, 47, 50, 51, 56, 57, 58, 59,
+ 52, 53, 54, 55, 60, 61, 62, 63
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Define all local variables
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Function body here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; Return nothing or data or data pointer
+----------------------------------------------------------------------------*/
+
+
diff --git a/media/codecs/m4v_h263/dec/test/Android.bp b/media/codecs/m4v_h263/dec/test/Android.bp
new file mode 100644
index 0000000..655491a
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/test/Android.bp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_test {
+ name: "Mpeg4H263DecoderTest",
+ gtest: true,
+
+ srcs: [
+ "Mpeg4H263DecoderTest.cpp",
+ ],
+
+ shared_libs: [
+ "liblog",
+ ],
+
+ static_libs: [
+ "libstagefright_m4vh263dec",
+ "libstagefright_foundation",
+ ],
+
+ cflags: [
+ "-Werror",
+ "-Wall",
+ ],
+
+ sanitize: {
+ misc_undefined: [
+ "unsigned-integer-overflow",
+ "signed-integer-overflow",
+ ],
+ cfi: true,
+ },
+}
diff --git a/media/codecs/m4v_h263/dec/test/AndroidTest.xml b/media/codecs/m4v_h263/dec/test/AndroidTest.xml
new file mode 100755
index 0000000..f572b0c
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/test/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for Mpeg4H263 Decoder unit tests">
+ <option name="test-suite-tag" value="Mpeg4H263DecoderTest" />
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="Mpeg4H263DecoderTest->/data/local/tmp/Mpeg4H263DecoderTest" />
+ <option name="push-file"
+ key="https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/m4v_h263/dec/test/Mpeg4H263Decoder-1.1.zip?unzip=true"
+ value="/data/local/tmp/Mpeg4H263DecoderTestRes/" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="Mpeg4H263DecoderTest" />
+ <option name="native-test-flag" value="-P /data/local/tmp/Mpeg4H263DecoderTestRes/" />
+ </test>
+</configuration>
diff --git a/media/codecs/m4v_h263/dec/test/Mpeg4H263DecoderTest.cpp b/media/codecs/m4v_h263/dec/test/Mpeg4H263DecoderTest.cpp
new file mode 100644
index 0000000..53d66ea
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/test/Mpeg4H263DecoderTest.cpp
@@ -0,0 +1,426 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "Mpeg4H263DecoderTest"
+#include <utils/Log.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <utils/String8.h>
+#include <fstream>
+
+#include <media/stagefright/foundation/AUtils.h>
+#include "mp4dec_api.h"
+
+#include "Mpeg4H263DecoderTestEnvironment.h"
+
+using namespace android;
+
+#define OUTPUT_FILE_NAME "/data/local/tmp/Output.yuv"
+#define CODEC_CONFIG_FLAG 32
+#define SYNC_FRAME 1
+#define MPEG4_MAX_WIDTH 1920
+#define MPEG4_MAX_HEIGHT 1080
+#define H263_MAX_WIDTH 352
+#define H263_MAX_HEIGHT 288
+
+constexpr uint32_t kNumOutputBuffers = 2;
+
+struct FrameInfo {
+ int32_t bytesCount;
+ uint32_t flags;
+ int64_t timestamp;
+};
+
+struct tagvideoDecControls;
+
+static Mpeg4H263DecoderTestEnvironment *gEnv = nullptr;
+
+class Mpeg4H263DecoderTest : public ::testing::TestWithParam<tuple<string, string, bool>> {
+ public:
+ Mpeg4H263DecoderTest()
+ : mDecHandle(nullptr),
+ mInputBuffer(nullptr),
+ mInitialized(false),
+ mFramesConfigured(false),
+ mNumSamplesOutput(0),
+ mWidth(352),
+ mHeight(288) {
+ memset(mOutputBuffer, 0x0, sizeof(mOutputBuffer));
+ }
+
+ ~Mpeg4H263DecoderTest() {
+ if (mEleStream.is_open()) mEleStream.close();
+ if (mDecHandle) {
+ delete mDecHandle;
+ mDecHandle = nullptr;
+ }
+ if (mInputBuffer) {
+ free(mInputBuffer);
+ mInputBuffer = nullptr;
+ }
+ freeOutputBuffer();
+ }
+
+ status_t initDecoder();
+ void allocOutputBuffer(size_t outputBufferSize);
+ void dumpOutput(ofstream &ostrm);
+ void freeOutputBuffer();
+ void processMpeg4H263Decoder(vector<FrameInfo> Info, int32_t offset, int32_t range,
+ ifstream &mEleStream, ofstream &ostrm, MP4DecodingMode inputMode);
+ void deInitDecoder();
+
+ ifstream mEleStream;
+ tagvideoDecControls *mDecHandle;
+ char *mInputBuffer;
+ uint8_t *mOutputBuffer[kNumOutputBuffers];
+ bool mInitialized;
+ bool mFramesConfigured;
+ uint32_t mNumSamplesOutput;
+ uint32_t mWidth;
+ uint32_t mHeight;
+};
+
+status_t Mpeg4H263DecoderTest::initDecoder() {
+ if (!mDecHandle) {
+ mDecHandle = new tagvideoDecControls;
+ }
+ if (!mDecHandle) {
+ return NO_MEMORY;
+ }
+ memset(mDecHandle, 0, sizeof(tagvideoDecControls));
+
+ return OK;
+}
+
+void Mpeg4H263DecoderTest::allocOutputBuffer(size_t outputBufferSize) {
+ for (int32_t i = 0; i < kNumOutputBuffers; ++i) {
+ if (!mOutputBuffer[i]) {
+ mOutputBuffer[i] = (uint8_t *)malloc(outputBufferSize);
+ ASSERT_NE(mOutputBuffer[i], nullptr) << "Output buffer allocation failed";
+ }
+ }
+}
+
+void Mpeg4H263DecoderTest::dumpOutput(ofstream &ostrm) {
+ uint8_t *src = mOutputBuffer[mNumSamplesOutput & 1];
+ size_t vStride = align(mHeight, 16);
+ size_t srcYStride = align(mWidth, 16);
+ size_t srcUVStride = srcYStride / 2;
+ uint8_t *srcStart = src;
+
+ /* Y buffer */
+ for (size_t i = 0; i < mHeight; ++i) {
+ ostrm.write(reinterpret_cast<char *>(src), mWidth);
+ src += srcYStride;
+ }
+ /* U buffer */
+ src = srcStart + vStride * srcYStride;
+ for (size_t i = 0; i < mHeight / 2; ++i) {
+ ostrm.write(reinterpret_cast<char *>(src), mWidth / 2);
+ src += srcUVStride;
+ }
+ /* V buffer */
+ src = srcStart + vStride * srcYStride * 5 / 4;
+ for (size_t i = 0; i < mHeight / 2; ++i) {
+ ostrm.write(reinterpret_cast<char *>(src), mWidth / 2);
+ src += srcUVStride;
+ }
+}
+
+void Mpeg4H263DecoderTest::freeOutputBuffer() {
+ for (int32_t i = 0; i < kNumOutputBuffers; ++i) {
+ if (mOutputBuffer[i]) {
+ free(mOutputBuffer[i]);
+ mOutputBuffer[i] = nullptr;
+ }
+ }
+}
+
+void Mpeg4H263DecoderTest::processMpeg4H263Decoder(vector<FrameInfo> Info, int32_t offset,
+ int32_t range, ifstream &mEleStream,
+ ofstream &ostrm, MP4DecodingMode inputMode) {
+ size_t maxWidth = (inputMode == MPEG4_MODE) ? MPEG4_MAX_WIDTH : H263_MAX_WIDTH;
+ size_t maxHeight = (inputMode == MPEG4_MODE) ? MPEG4_MAX_HEIGHT : H263_MAX_HEIGHT;
+ size_t outputBufferSize = align(maxWidth, 16) * align(maxHeight, 16) * 3 / 2;
+ uint32_t frameIndex = offset;
+ bool status = true;
+ ASSERT_GE(range, 0) << "Invalid range";
+ ASSERT_TRUE(offset >= 0 && offset <= Info.size() - 1) << "Invalid offset";
+ ASSERT_LE(range + offset, Info.size()) << "range+offset can't be greater than the no of frames";
+
+ while (1) {
+ if (frameIndex == Info.size() || frameIndex == (offset + range)) break;
+
+ int32_t bytesCount = Info[frameIndex].bytesCount;
+ ASSERT_GT(bytesCount, 0) << "Size for the memory allocation is negative";
+ mInputBuffer = (char *)malloc(bytesCount);
+ ASSERT_NE(mInputBuffer, nullptr) << "Insufficient memory to read frame";
+ mEleStream.read(mInputBuffer, bytesCount);
+ ASSERT_EQ(mEleStream.gcount(), bytesCount) << "mEleStream.gcount() != bytesCount";
+ static const uint8_t volInfo[] = {0x00, 0x00, 0x01, 0xB0};
+ bool volHeader = memcmp(mInputBuffer, volInfo, 4) == 0;
+ if (volHeader) {
+ PVCleanUpVideoDecoder(mDecHandle);
+ mInitialized = false;
+ }
+
+ if (!mInitialized) {
+ uint8_t *volData[1]{};
+ int32_t volSize = 0;
+
+ uint32_t flags = Info[frameIndex].flags;
+ bool codecConfig = flags == CODEC_CONFIG_FLAG;
+ if (codecConfig || volHeader) {
+ volData[0] = reinterpret_cast<uint8_t *>(mInputBuffer);
+ volSize = bytesCount;
+ }
+
+ status = PVInitVideoDecoder(mDecHandle, volData, &volSize, 1, maxWidth, maxHeight,
+ inputMode);
+ ASSERT_TRUE(status) << "PVInitVideoDecoder failed. Unsupported content";
+
+ mInitialized = true;
+ MP4DecodingMode actualMode = PVGetDecBitstreamMode(mDecHandle);
+ ASSERT_EQ(inputMode, actualMode)
+ << "Decoded mode not same as actual mode of the decoder";
+
+ PVSetPostProcType(mDecHandle, 0);
+
+ int32_t dispWidth, dispHeight;
+ PVGetVideoDimensions(mDecHandle, &dispWidth, &dispHeight);
+
+ int32_t bufWidth, bufHeight;
+ PVGetBufferDimensions(mDecHandle, &bufWidth, &bufHeight);
+
+ ASSERT_LE(dispWidth, bufWidth) << "Display width is greater than buffer width";
+ ASSERT_LE(dispHeight, bufHeight) << "Display height is greater than buffer height";
+
+ if (dispWidth != mWidth || dispHeight != mHeight) {
+ mWidth = dispWidth;
+ mHeight = dispHeight;
+ freeOutputBuffer();
+ if (inputMode == H263_MODE) {
+ PVCleanUpVideoDecoder(mDecHandle);
+
+ uint8_t *volData[1]{};
+ int32_t volSize = 0;
+
+ status = PVInitVideoDecoder(mDecHandle, volData, &volSize, 1, maxWidth,
+ maxHeight, H263_MODE);
+ ASSERT_TRUE(status) << "PVInitVideoDecoder failed for H263";
+ }
+ mFramesConfigured = false;
+ }
+
+ if (codecConfig) {
+ frameIndex++;
+ continue;
+ }
+ }
+
+ uint32_t yFrameSize = sizeof(uint8) * mDecHandle->size;
+ ASSERT_GE(outputBufferSize, yFrameSize * 3 / 2)
+ << "Too small output buffer: " << outputBufferSize << " bytes";
+ ASSERT_NO_FATAL_FAILURE(allocOutputBuffer(outputBufferSize));
+
+ if (!mFramesConfigured) {
+ PVSetReferenceYUV(mDecHandle, mOutputBuffer[1]);
+ mFramesConfigured = true;
+ }
+
+ // Need to check if header contains new info, e.g., width/height, etc.
+ VopHeaderInfo headerInfo;
+ uint32_t useExtTimestamp = 1;
+ int32_t inputSize = (Info)[frameIndex].bytesCount;
+ uint32_t timestamp = frameIndex;
+
+ uint8_t *bitstreamTmp = reinterpret_cast<uint8_t *>(mInputBuffer);
+
+ status = PVDecodeVopHeader(mDecHandle, &bitstreamTmp, ×tamp, &inputSize, &headerInfo,
+ &useExtTimestamp, mOutputBuffer[mNumSamplesOutput & 1]);
+ ASSERT_EQ(status, PV_TRUE) << "failed to decode vop header";
+
+ // H263 doesn't have VOL header, the frame size information is in short header, i.e. the
+ // decoder may detect size change after PVDecodeVopHeader.
+ int32_t dispWidth, dispHeight;
+ PVGetVideoDimensions(mDecHandle, &dispWidth, &dispHeight);
+
+ int32_t bufWidth, bufHeight;
+ PVGetBufferDimensions(mDecHandle, &bufWidth, &bufHeight);
+
+ ASSERT_LE(dispWidth, bufWidth) << "Display width is greater than buffer width";
+ ASSERT_LE(dispHeight, bufHeight) << "Display height is greater than buffer height";
+ if (dispWidth != mWidth || dispHeight != mHeight) {
+ mWidth = dispWidth;
+ mHeight = dispHeight;
+ }
+
+ status = PVDecodeVopBody(mDecHandle, &inputSize);
+ ASSERT_EQ(status, PV_TRUE) << "failed to decode video frame No = %d" << frameIndex;
+
+ dumpOutput(ostrm);
+
+ ++mNumSamplesOutput;
+ ++frameIndex;
+ }
+ freeOutputBuffer();
+}
+
+void Mpeg4H263DecoderTest::deInitDecoder() {
+ if (mInitialized) {
+ if (mDecHandle) {
+ PVCleanUpVideoDecoder(mDecHandle);
+ delete mDecHandle;
+ mDecHandle = nullptr;
+ }
+ mInitialized = false;
+ }
+ freeOutputBuffer();
+}
+
+void getInfo(string infoFileName, vector<FrameInfo> &Info) {
+ ifstream eleInfo;
+ eleInfo.open(infoFileName);
+ ASSERT_EQ(eleInfo.is_open(), true) << "Failed to open " << infoFileName;
+ int32_t bytesCount = 0;
+ uint32_t flags = 0;
+ uint32_t timestamp = 0;
+ while (1) {
+ if (!(eleInfo >> bytesCount)) {
+ break;
+ }
+ eleInfo >> flags;
+ eleInfo >> timestamp;
+ Info.push_back({bytesCount, flags, timestamp});
+ }
+ if (eleInfo.is_open()) eleInfo.close();
+}
+
+TEST_P(Mpeg4H263DecoderTest, DecodeTest) {
+ tuple<string /* InputFileName */, string /* InfoFileName */, bool /* mode */> params =
+ GetParam();
+
+ string inputFileName = gEnv->getRes() + get<0>(params);
+ mEleStream.open(inputFileName, ifstream::binary);
+ ASSERT_EQ(mEleStream.is_open(), true) << "Failed to open " << get<0>(params);
+
+ string infoFileName = gEnv->getRes() + get<1>(params);
+ vector<FrameInfo> Info;
+ ASSERT_NO_FATAL_FAILURE(getInfo(infoFileName, Info));
+ ASSERT_NE(Info.empty(), true) << "Invalid Info file";
+
+ ofstream ostrm;
+ ostrm.open(OUTPUT_FILE_NAME, std::ofstream::binary);
+ ASSERT_EQ(ostrm.is_open(), true) << "Failed to open output stream for " << get<0>(params);
+
+ status_t err = initDecoder();
+ ASSERT_EQ(err, OK) << "initDecoder: failed to create decoder " << err;
+
+ bool isMpeg4 = get<2>(params);
+ MP4DecodingMode inputMode = isMpeg4 ? MPEG4_MODE : H263_MODE;
+ ASSERT_NO_FATAL_FAILURE(
+ processMpeg4H263Decoder(Info, 0, Info.size(), mEleStream, ostrm, inputMode));
+ deInitDecoder();
+ ostrm.close();
+ Info.clear();
+}
+
+TEST_P(Mpeg4H263DecoderTest, FlushTest) {
+ tuple<string /* InputFileName */, string /* InfoFileName */, bool /* mode */> params =
+ GetParam();
+
+ string inputFileName = gEnv->getRes() + get<0>(params);
+ mEleStream.open(inputFileName, ifstream::binary);
+ ASSERT_EQ(mEleStream.is_open(), true) << "Failed to open " << get<0>(params);
+
+ string infoFileName = gEnv->getRes() + get<1>(params);
+ vector<FrameInfo> Info;
+ ASSERT_NO_FATAL_FAILURE(getInfo(infoFileName, Info));
+ ASSERT_NE(Info.empty(), true) << "Invalid Info file";
+
+ ofstream ostrm;
+ ostrm.open(OUTPUT_FILE_NAME, std::ofstream::binary);
+ ASSERT_EQ(ostrm.is_open(), true) << "Failed to open output stream for " << get<0>(params);
+
+ status_t err = initDecoder();
+ ASSERT_EQ(err, OK) << "initDecoder: failed to create decoder " << err;
+
+ bool isMpeg4 = get<2>(params);
+ MP4DecodingMode inputMode = isMpeg4 ? MPEG4_MODE : H263_MODE;
+ // Number of frames to be decoded before flush
+ int32_t numFrames = Info.size() / 3;
+ ASSERT_NO_FATAL_FAILURE(
+ processMpeg4H263Decoder(Info, 0, numFrames, mEleStream, ostrm, inputMode));
+
+ if (mInitialized) {
+ int32_t status = PVResetVideoDecoder(mDecHandle);
+ ASSERT_EQ(status, PV_TRUE);
+ }
+
+ // Seek to next key frame and start decoding till the end
+ int32_t index = numFrames;
+ bool keyFrame = false;
+ uint32_t flags = 0;
+ while (index < (int32_t)Info.size()) {
+ if (Info[index].flags) flags = 1u << (Info[index].flags - 1);
+ if ((flags & SYNC_FRAME) == SYNC_FRAME) {
+ keyFrame = true;
+ break;
+ }
+ flags = 0;
+ mEleStream.ignore(Info[index].bytesCount);
+ index++;
+ }
+ ALOGV("Index= %d", index);
+ if (keyFrame) {
+ mNumSamplesOutput = 0;
+ ASSERT_NO_FATAL_FAILURE(processMpeg4H263Decoder(Info, index, (int32_t)Info.size() - index,
+ mEleStream, ostrm, inputMode));
+ }
+ deInitDecoder();
+ ostrm.close();
+ Info.clear();
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ Mpeg4H263DecoderTestAll, Mpeg4H263DecoderTest,
+ ::testing::Values(make_tuple("swirl_128x96_h263.h263", "swirl_128x96_h263.info", false),
+ make_tuple("swirl_176x144_h263.h263", "swirl_176x144_h263.info", false),
+ make_tuple("swirl_352x288_h263.h263", "swirl_352x288_h263.info", false),
+ make_tuple("bbb_352x288_h263.h263", "bbb_352x288_h263.info", false),
+ make_tuple("bbb_352x288_mpeg4.m4v", "bbb_352x288_mpeg4.info", true),
+ make_tuple("qtype0_mpeg4.m4v", "qtype0_mpeg4.info", true),
+ make_tuple("qtype1_mpeg4.m4v", "qtype1_mpeg4.info", true),
+ make_tuple("qtype1_qmatrix_mpeg4.m4v", "qtype1_qmatrix_mpeg4.info", true),
+ make_tuple("swirl_128x128_mpeg4.m4v", "swirl_128x128_mpeg4.info", true),
+ make_tuple("swirl_130x132_mpeg4.m4v", "swirl_130x132_mpeg4.info", true),
+ make_tuple("swirl_132x130_mpeg4.m4v", "swirl_132x130_mpeg4.info", true),
+ make_tuple("swirl_136x144_mpeg4.m4v", "swirl_136x144_mpeg4.info", true),
+ make_tuple("swirl_144x136_mpeg4.m4v", "swirl_144x136_mpeg4.info", true)));
+
+int main(int argc, char **argv) {
+ gEnv = new Mpeg4H263DecoderTestEnvironment();
+ ::testing::AddGlobalTestEnvironment(gEnv);
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = gEnv->initFromOptions(argc, argv);
+ if (status == 0) {
+ status = RUN_ALL_TESTS();
+ ALOGD("Decoder Test Result = %d\n", status);
+ }
+ return status;
+}
diff --git a/media/codecs/m4v_h263/dec/test/Mpeg4H263DecoderTestEnvironment.h b/media/codecs/m4v_h263/dec/test/Mpeg4H263DecoderTestEnvironment.h
new file mode 100644
index 0000000..f085845
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/test/Mpeg4H263DecoderTestEnvironment.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MPEG4_H263_DECODER_TEST_ENVIRONMENT_H__
+#define __MPEG4_H263_DECODER_TEST_ENVIRONMENT_H__
+
+#include <gtest/gtest.h>
+
+#include <getopt.h>
+
+using namespace std;
+
+class Mpeg4H263DecoderTestEnvironment : public ::testing::Environment {
+ public:
+ Mpeg4H263DecoderTestEnvironment() : res("/data/local/tmp/") {}
+
+ // Parses the command line arguments
+ int initFromOptions(int argc, char **argv);
+
+ void setRes(const char *_res) { res = _res; }
+
+ const string getRes() const { return res; }
+
+ private:
+ string res;
+};
+
+int Mpeg4H263DecoderTestEnvironment::initFromOptions(int argc, char **argv) {
+ static struct option options[] = {{"path", required_argument, 0, 'P'}, {0, 0, 0, 0}};
+
+ while (true) {
+ int index = 0;
+ int c = getopt_long(argc, argv, "P:", options, &index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'P': {
+ setRes(optarg);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr,
+ "unrecognized option: %s\n\n"
+ "usage: %s <gtest options> <test options>\n\n"
+ "test options are:\n\n"
+ "-P, --path: Resource files directory location\n",
+ argv[optind ?: 1], argv[0]);
+ return 2;
+ }
+ return 0;
+}
+
+#endif // __MPEG4_H263_DECODER_TEST_ENVIRONMENT_H__
diff --git a/media/codecs/m4v_h263/dec/test/README.md b/media/codecs/m4v_h263/dec/test/README.md
new file mode 100644
index 0000000..38ac567
--- /dev/null
+++ b/media/codecs/m4v_h263/dec/test/README.md
@@ -0,0 +1,40 @@
+## Media Testing ##
+---
+#### Mpeg4H263Decoder :
+The Mpeg4H263Decoder Test Suite validates the Mpeg4 and H263 decoder available in libstagefright.
+
+Run the following steps to build the test suite:
+```
+m Mpeg4H263DecoderTest
+```
+
+The 32-bit binaries will be created in the following path : ${OUT}/data/nativetest/
+
+The 64-bit binaries will be created in the following path : ${OUT}/data/nativetest64/
+
+To test 64-bit binary push binaries from nativetest64.
+```
+adb push ${OUT}/data/nativetest64/Mpeg4H263DecoderTest/Mpeg4H263DecoderTest /data/local/tmp/
+```
+
+To test 32-bit binary push binaries from nativetest.
+```
+adb push ${OUT}/data/nativetest/Mpeg4H263DecoderTest/Mpeg4H263DecoderTest /data/local/tmp/
+```
+
+The resource file for the tests is taken from [here](https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/m4v_h263/dec/test/Mpeg4H263Decoder-1.1.zip).
+Download, unzip and push these files into device for testing.
+
+```
+adb push Mpeg4H263Decoder /data/local/tmp/
+```
+
+usage: Mpeg4H263DecoderTest -P \<path_to_folder\>
+```
+adb shell /data/local/tmp/Mpeg4H263DecoderTest -P /data/local/tmp/Mpeg4H263Decoder/
+```
+Alternatively, the test can also be run using atest command.
+
+```
+atest Mpeg4H263DecoderTest -- --enable-module-dynamic-download=true
+```
diff --git a/media/codecs/m4v_h263/enc/Android.bp b/media/codecs/m4v_h263/enc/Android.bp
new file mode 100644
index 0000000..dd7f005
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/Android.bp
@@ -0,0 +1,75 @@
+cc_library_static {
+ name: "libstagefright_m4vh263enc",
+ vendor_available: true,
+ apex_available: [
+ "//apex_available:platform",
+ "com.android.media.swcodec",
+ ],
+ min_sdk_version: "29",
+ host_supported: true,
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+
+ srcs: [
+ "src/bitstream_io.cpp",
+ "src/combined_encode.cpp", "src/datapart_encode.cpp",
+ "src/dct.cpp",
+ "src/findhalfpel.cpp",
+ "src/fastcodemb.cpp",
+ "src/fastidct.cpp",
+ "src/fastquant.cpp",
+ "src/me_utils.cpp",
+ "src/mp4enc_api.cpp",
+ "src/rate_control.cpp",
+ "src/motion_est.cpp",
+ "src/motion_comp.cpp",
+ "src/sad.cpp",
+ "src/sad_halfpel.cpp",
+ "src/vlc_encode.cpp",
+ "src/vop.cpp",
+ ],
+
+ cflags: [
+ "-DBX_RC",
+ "-Werror",
+ ],
+
+ local_include_dirs: ["src"],
+ export_include_dirs: ["include"],
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ ],
+ cfi: true,
+ },
+}
+
+//###############################################################################
+
+cc_test {
+ name: "libstagefright_m4vh263enc_test",
+ gtest: false,
+
+ srcs: ["test/m4v_h263_enc_test.cpp"],
+
+ local_include_dirs: ["src"],
+
+ cflags: [
+ "-DBX_RC",
+ "-Wall",
+ "-Werror",
+ ],
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ ],
+ cfi: true,
+ },
+
+ static_libs: ["libstagefright_m4vh263enc"],
+}
diff --git a/media/codecs/m4v_h263/enc/MODULE_LICENSE_APACHE2 b/media/codecs/m4v_h263/enc/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/m4v_h263/enc/NOTICE b/media/codecs/m4v_h263/enc/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/m4v_h263/enc/include/cvei.h b/media/codecs/m4v_h263/enc/include/cvei.h
new file mode 100644
index 0000000..18e54dc
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/include/cvei.h
@@ -0,0 +1,437 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*********************************************************************************/
+/* File: cvei.h */
+/* Purpose: */
+/* Date: */
+/* Revision History: */
+/** @introduction Common Video Encoder Interface (CVEI) is intended to be used by
+ application developers who want to create a multimedia application with video
+ encoding feature. CVEI is designed such that new video encoder algorithms or
+ modules can be plugged in seamlessly without user interaction. In other words,
+ any changes to the CVEI library are transparent to the users. Users can still
+ use the same set of APIs for new encoding tools.
+
+ @requirement CVEI will take an input frame in one of several format supported
+ by PV and encode it to an MPEG4 bitstream. It will also return a reconstructed
+ image in YUV 4:2:0 format. Currently the input format supported are YUV 4:2:0,
+ RGB24 and UYVY 4:2:2.
+
+ CVEI is designed such that it is simple to use. It should hides implementation
+ dependency from the users. In this version, we decided that the operation will
+ be synchronous, i.e., the encoding will be a blocked call. Asynchronous operation
+ will be in the level above CVEI, i.e., in Author Engine Video Module which will
+ take care of capturing device as well.
+
+ @brief The following classes are used to interface with codecs. Their names
+ are CPVxxxVideoEncoder where xxx is codec specific such as MPEG4, H263, H26L,
+ etc. All of them are subclasses of CPVCommonVideoEncoder.
+*/
+/*********************************************************************************/
+
+#ifndef __CVEI_H
+#define __CVEI_H
+
+#include "oscl_scheduler_ao.h"
+#include "oscl_base.h"
+#include "mp4enc_api.h" /* for MP4HintTrack */
+
+#define MAX_LAYER 2
+
+/** General returned values. */
+enum TCVEI_RETVAL
+{
+ ECVEI_SUCCESS,
+ ECVEI_FAIL,
+ ECVEI_FLUSH,
+ ECVEI_MORE_OUTPUT
+} ;
+
+/** Returned events with the callback function. */
+enum TCVEI_EVENT
+{
+ /** Called when a packet or a frame of output bitstream is ready. */
+ ECVEI_BUFFER_READY,
+
+ /** Called when the last packet of a frame of output bitstream is ready. */
+ ECVEI_FRAME_DONE,
+
+ /** Called when no buffers is available for output bitstream. A buffer can be added thru AddBuffer API. */
+ ECVEI_NO_BUFFERS,
+
+ /** Called when there is an error with the encoding operation. */
+ ECVEI_ERROR
+};
+
+/** Contains supported input format */
+enum TPVVideoFormat
+{
+ ECVEI_RGB24,
+ ECVEI_RGB12,
+ ECVEI_YUV420,
+ ECVEI_UYVY,
+ ECVEI_YUV420SEMIPLANAR
+};
+
+/** Type of contents for optimal encoding mode. */
+enum TPVContentType
+{
+ /** Content is to be streamed in real-time. */
+ ECVEI_STREAMING,
+
+ /** Content is to be downloaded and playbacked later.*/
+ ECVEI_DOWNLOAD,
+
+ /** Content is to be 3gpp baseline compliant. */
+ ECVEI_H263
+};
+
+/** Rate control type. */
+enum TMP4RateControlType
+{
+ /** Constant quality, variable bit rate, fixed quantization level. */
+ ECONSTANT_Q,
+
+ /** Short-term constant bit rate control. */
+ ECBR_1,
+
+ /** Long-term constant bit rate control. */
+ EVBR_1
+};
+
+/** Targeted profile and level to encode. */
+enum TPVM4VProfileLevel
+{
+ /* Non-scalable profile */
+ ECVEI_SIMPLE_LEVEL0 = 0,
+ ECVEI_SIMPLE_LEVEL1,
+ ECVEI_SIMPLE_LEVEL2,
+ ECVEI_SIMPLE_LEVEL3,
+ ECVEI_CORE_LEVEL1,
+ ECVEI_CORE_LEVEL2,
+
+ /* Scalable profile */
+ ECVEI_SIMPLE_SCALABLE_LEVEL0 = 6,
+ ECVEI_SIMPLE_SCALABLE_LEVEL1,
+ ECVEI_SIMPLE_SCALABLE_LEVEL2,
+
+ ECVEI_CORE_SCALABLE_LEVEL1 = 10,
+ ECVEI_CORE_SCALABLE_LEVEL2,
+ ECVEI_CORE_SCALABLE_LEVEL3
+};
+
+/** This structure contains encoder settings. */
+struct TPVVideoEncodeParam
+{
+ /** Specifies an ID that will be used to specify this encoder while returning
+ the bitstream in asynchronous mode. */
+ uint32 iEncodeID;
+
+ /** Specifies whether base only (iNumLayer = 1) or base + enhancement layer
+ (iNumLayer =2 ) is to be used. */
+ int32 iNumLayer;
+
+ /** Specifies the width in pixels of the encoded frames. IFrameWidth[0] is for
+ base layer and iFrameWidth[1] is for enhanced layer. */
+ int iFrameWidth[MAX_LAYER];
+
+ /** Specifies the height in pixels of the encoded frames. IFrameHeight[0] is for
+ base layer and iFrameHeight[1] is for enhanced layer. */
+ int iFrameHeight[MAX_LAYER];
+
+ /** Specifies the cumulative bit rate in bit per second. IBitRate[0] is for base
+ layer and iBitRate[1] is for base+enhanced layer.*/
+ int iBitRate[MAX_LAYER];
+
+ /** Specifies the cumulative frame rate in frame per second. IFrameRate[0] is for
+ base layer and iFrameRate[1] is for base+enhanced layer. */
+ float iFrameRate[MAX_LAYER];
+
+ /** Specifies the picture quality factor on the scale of 1 to 10. It trades off
+ the picture quality with the frame rate. Higher frame quality means lower frame rate.
+ Lower frame quality for higher frame rate.*/
+ int32 iFrameQuality;
+
+ /** Enable the use of iFrameQuality to determine the frame rate. If it is false,
+ the encoder will try to meet the specified frame rate regardless of the frame quality.*/
+ bool iEnableFrameQuality;
+
+ /** Specifies the maximum number of P-frames between 2 INTRA frames. An INTRA mode is
+ forced to a frame once this interval is reached. When there is only one I-frame is present
+ at the beginning of the clip, iIFrameInterval should be set to -1. */
+ int32 iIFrameInterval;
+
+ /** According to iIFrameInterval setting, the minimum number of intra MB per frame is
+ optimally calculated for error resiliency. However, when iIFrameInterval is set to -1,
+ iNumIntraMBRefresh must be specified to guarantee the minimum number of intra
+ macroblocks per frame.*/
+ uint32 iNumIntraMBRefresh;
+
+ /** Specifies the VBV buffer size which determines the end-to-end delay between the
+ encoder and the decoder. The size is in unit of seconds. For download application,
+ the buffer size can be larger than the streaming application. For 2-way application,
+ this buffer shall be kept minimal. For a special case, in VBR mode, iBufferDelay will
+ be set to -1 to allow buffer underflow. */
+ float iBufferDelay;
+
+ /** Specifies the type of the access whether it is streaming, CVEI_STREAMING
+ (data partitioning mode) or download, CVEI_DOWNLOAD (combined mode).*/
+ TPVContentType iContentType;
+
+ /** Specifies the rate control algorithm among one of the following constant Q,
+ CBR and VBR. The structure TMP4RateControlType is defined below.*/
+ TMP4RateControlType iRateControlType;
+
+ /** Specifies high quality but also high complexity mode for rate control. */
+ bool iRDOptimal;
+
+ /** Specifies the initial quantization parameter for the first I-frame. If constant Q
+ rate control is used, this QP will be used for all the I-frames. This number must be
+ set between 1 and 31, otherwise, Initialize() will fail. */
+ int iIquant[2];
+
+ /** Specifies the initial quantization parameter for the first P-frame. If constant Q
+ rate control is used, this QP will be used for all the P-frames. This number must be
+ set between 1 and 31, otherwise, Initialize() will fail. */
+ int iPquant[2];
+
+ /** Specifies the initial quantization parameter for the first B-frame. If constant Q
+ rate control is used, this QP will be used for all the B-frames. This number must be
+ set between 1 and 31, otherwise, Initialize() will fail. */
+ int iBquant[2];
+
+ /** Specifies the search range in pixel unit for motion vector. The range of the
+ motion vector will be of dimension [-iSearchRange.5, +iSearchRange.0]. */
+ int32 iSearchRange;
+
+ /** Specifies the use of 8x8 motion vectors. */
+ bool iMV8x8;
+
+ /** Specifies the use of half-pel motion vectors. */
+ bool iMVHalfPel;
+
+ /** Specifies automatic scene detection where I-frame will be used the the first frame
+ in a new scene. */
+ bool iSceneDetection;
+
+ /** Specifies the packet size in bytes which represents the number of bytes between two resync markers.
+ For ECVEI_DOWNLOAD and ECVEI_H263, if iPacketSize is set to 0, there will be no resync markers in the bitstream.
+ For ECVEI_STREAMING is parameter must be set to a value greater than 0.*/
+ uint32 iPacketSize;
+
+ /** Specifies whether the current frame skipping decision is allowed after encoding
+ the current frame. If there is no memory of what has been coded for the current frame,
+ iNoCurrentSkip has to be on. */
+ bool iNoCurrentSkip;
+
+ /** Specifies that no frame skipping is allowed. Frame skipping is a tool used to
+ control the average number of bits spent to meet the target bit rate. */
+ bool iNoFrameSkip;
+
+ /** Specifies the duration of the clip in millisecond.*/
+ int32 iClipDuration;
+
+ /** Specifies the profile and level used to encode the bitstream. When present,
+ other settings will be checked against the range allowable by this target profile
+ and level. Fail may be returned from the Initialize call. */
+ TPVM4VProfileLevel iProfileLevel;
+
+ /** Specifies FSI Buffer input */
+ uint8* iFSIBuff;
+
+ /** Specifies FSI Buffer Length */
+ int iFSIBuffLength;
+
+
+};
+
+
+/** Structure for input format information */
+struct TPVVideoInputFormat
+{
+ /** Contains the width in pixels of the input frame. */
+ int32 iFrameWidth;
+
+ /** Contains the height in pixels of the input frame. */
+ int32 iFrameHeight;
+
+ /** Contains the input frame rate in the unit of frame per second. */
+ float iFrameRate;
+
+ /** Contains Frame Orientation. Used for RGB input. 1 means Bottom_UP RGB, 0 means Top_Down RGB, -1 for video formats other than RGB*/
+ int iFrameOrientation;
+
+ /** Contains the format of the input video, e.g., YUV 4:2:0, UYVY, RGB24, etc. */
+ TPVVideoFormat iVideoFormat;
+};
+
+
+/** Contains the input data information */
+struct TPVVideoInputData
+{
+ /** Pointer to an input frame buffer in input source format.*/
+ uint8 *iSource;
+
+ /** The corresponding time stamp of the input frame. */
+ uint32 iTimeStamp;
+};
+
+/** Contains the output data information */
+struct TPVVideoOutputData
+{
+ /** Pointer to the reconstructed frame buffer in YUV 4:2:0 domain. */
+ uint8 *iFrame;
+
+ /** The number of layer encoded, 0 for base, 1 for enhanced. */
+ int32 iLayerNumber;
+
+ /** Pointer to the encoded bitstream buffer. */
+ uint8 *iBitStream;
+
+ /** The size in bytes of iBStream. */
+ int32 iBitStreamSize;
+
+ /** The time stamp of the encoded frame according to the bitstream. */
+ uint32 iVideoTimeStamp;
+
+ /** The time stamp of the encoded frame as given before the encoding. */
+ uint32 iExternalTimeStamp;
+
+ /** The hint track information. */
+ MP4HintTrack iHintTrack;
+};
+
+/** An observer class for callbacks to report the status of the CVEI */
+class MPVCVEIObserver
+{
+ public:
+ /** The callback funtion with aEvent being one of TCVEIEvent enumeration. */
+ virtual void HandlePVCVEIEvent
+ (uint32 aId, uint32 aEvent, uint32 aParam1 = 0) = 0;
+ virtual ~MPVCVEIObserver() {}
+};
+
+/** This class is the base class for codec specific interface class.
+The users must maintain an instance of the codec specific class throughout
+the encoding session.
+*/
+class CommonVideoEncoder : public OsclTimerObject
+{
+ public:
+ /** Constructor for CVEI class. */
+ CommonVideoEncoder() : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PVEncoder") {};
+
+ /** Initialization function to set the input video format and the
+ encoding parameters. This function returns CVEI_ERROR if there is
+ any errors. Otherwise, the function returns CVEI_SUCCESS.*/
+ virtual TCVEI_RETVAL Initialize(TPVVideoInputFormat *aVidInFormat, TPVVideoEncodeParam *aEncParam) = 0;
+
+ /** Set the observer for asynchronous encoding mode. */
+ virtual TCVEI_RETVAL SetObserver(MPVCVEIObserver *aObserver) = 0;
+
+ /** Add a buffer to the queue of output buffers for output bitstream in
+ asynchronous encoding mode. */
+ virtual TCVEI_RETVAL AddBuffer(TPVVideoOutputData *aVidOut) = 0;
+
+ /** This function sends in an input video data structure containing a source
+ frame and the associated timestamp. The encoded bitstream will be returned by
+ observer callback.
+ The above 3 APIs only replace EncodeFrame() API. Other APIs such as initialization
+ and update parameters remain the same. */
+ virtual TCVEI_RETVAL Encode(TPVVideoInputData *aVidIn) = 0;
+
+ /** This function returns the maximum VBV buffer size such that the
+ application can allocate a buffer that guarantees to fit one frame.*/
+ virtual int32 GetBufferSize() = 0;
+
+ /** This function returns the VOL header part (starting from the VOS header)
+ of the encoded bitstream. This function must be called after Initialize.
+ The output is written to the memory (volHeader) allocated by the users.*/
+ virtual TCVEI_RETVAL GetVolHeader(uint8 *volHeader, int32 *size, int32 layer) = 0;
+
+ /** This function sends in an input video data structure containing a source
+ frame and the associated timestamp. It returns an output video data structure
+ containing coded bit stream, reconstructed frame in YUV 4:2:0 (can be changed
+ to source format) and the timestamp associated with the coded frame.
+ The input timestamp may not correspond to the output timestamp. User can send
+ an input structure in without getting any encoded data back or getting an encoded
+ frame in the past. This function returns ECVEI_ERROR if there is any errors.
+ Otherwise, the function returns ECVEI_SUCCESS.
+ In case of Overrun Buffer usage, it is possible that return value is ECVEI_MORE_OUTPUT
+ which indicates that frame cannot fit in the current buffer*/
+ virtual TCVEI_RETVAL EncodeFrame(TPVVideoInputData *aVidIn, TPVVideoOutputData *aVidOut, int *aRemainingBytes
+#ifdef PVAUTHOR_PROFILING
+ , void *aParam1 = 0
+#endif
+ ) = 0;
+
+ /** Before the termination of the encoding process, the users have to query
+ whether there are any encoded frame pending inside the CVEI. The returned value
+ will indicate whether there are more frames to be flushed (ECVEI_FLUSH).
+ FlushOutput has to be called until there are no more frames, i.e., it returns
+ ECVEI_SUCCESS. This function may be called during the encoding operation if
+ there is no input frame and the application does not want to waste the time
+ waiting for input frame. It can call this function to flush encoded frame
+ out of the memory. */
+ virtual TCVEI_RETVAL FlushOutput(TPVVideoOutputData *aVidOut) = 0;
+
+ /** This function cleanup the CVEI allocated resources. */
+ virtual TCVEI_RETVAL Terminate() = 0;
+
+ /**This function dynamically changes the target bit rate of the encoder
+ while encoding. aBitRate[n] is the new accumulate target bit rate of layer n.
+ Successful update is returned with ECVEI_SUCCESS.*/
+ virtual TCVEI_RETVAL UpdateBitRate(int32 aNumLayer, int32 *aBitRate) = 0;
+
+ /** This function dynamically changes the target frame rate of the encoder
+ while encoding. aFrameRate[n] is the new accumulate target frame rate of
+ layer n. Successful update is returned with ECVEI_SUCCESS. */
+ virtual TCVEI_RETVAL UpdateFrameRate(int32 aNumLayer, float *aFrameRate) = 0;
+
+ /** This function dynamically changes the I-Vop update interval while
+ encoding to a new value, aIFrameInterval. */
+ virtual TCVEI_RETVAL UpdateIFrameInterval(int32 aIFrameInterval) = 0;
+
+ /** This function forces an I-Vop mode to the next frame to be encoded. */
+ virtual TCVEI_RETVAL IFrameRequest() = 0;
+
+ /** This function returns the input width of a specific layer
+ (not necessarily multiple of 16). */
+ virtual int32 GetEncodeWidth(int32 aLayer) = 0;
+
+ /** This function returns the input height of a specific layer
+ (not necessarily multiple of 16). */
+ virtual int32 GetEncodeHeight(int32 aLayer) = 0;
+
+ /** This function returns the target encoded frame rate of a specific layer. */
+ virtual float GetEncodeFrameRate(int32 aLayer) = 0;
+ protected:
+ virtual void Run(void) = 0;
+ virtual void DoCancel(void) = 0;
+ /* internal enum */
+ enum TCVEIState
+ {
+ EIdle,
+ EEncode
+ };
+
+ TCVEIState iState;
+ uint32 iId;
+};
+
+#endif
diff --git a/media/codecs/m4v_h263/enc/include/mp4enc_api.h b/media/codecs/m4v_h263/enc/include/mp4enc_api.h
new file mode 100644
index 0000000..9f824b1
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/include/mp4enc_api.h
@@ -0,0 +1,465 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _MP4ENC_API_H_
+#define _MP4ENC_API_H_
+
+#include <stdint.h>
+#include <string.h>
+
+#ifndef _PV_TYPES_
+#define _PV_TYPES_
+typedef uint8_t UChar;
+typedef int8_t Char;
+typedef unsigned int UInt;
+typedef int Int;
+typedef uint16_t UShort;
+typedef int16_t Short;
+typedef unsigned int Bool;
+typedef uint32_t ULong;
+
+#define PV_CODEC_INIT 0
+#define PV_CODEC_STOP 1
+#endif
+
+#define PV_TRUE 1
+#define PV_FALSE 0
+
+#ifndef OSCL_IMPORT_REF
+#define OSCL_IMPORT_REF /* empty */
+#endif
+#ifndef OSCL_EXPORT_REF
+#define OSCL_EXPORT_REF /* empty */
+#endif
+#ifndef OSCL_UNUSED_ARG
+#define OSCL_UNUSED_ARG(x) ((void)(x))
+#endif
+
+typedef enum
+{
+ SHORT_HEADER,
+ SHORT_HEADER_WITH_ERR_RES,
+ H263_MODE,
+ H263_MODE_WITH_ERR_RES,
+ DATA_PARTITIONING_MODE,
+ COMBINE_MODE_NO_ERR_RES,
+ COMBINE_MODE_WITH_ERR_RES
+
+} MP4EncodingMode;
+
+typedef enum
+{
+ CONSTANT_Q,
+ CBR_1,
+ VBR_1,
+ CBR_2,
+ VBR_2,
+ CBR_LOWDELAY
+} MP4RateControlType;
+
+typedef enum
+{
+ PASS1,
+ PASS2
+} PassNum;
+
+typedef enum
+{
+ PV_OFF,
+ PV_ON
+} ParamEncMode;
+
+
+/* {SPL0, SPL1, SPL2, SPL3, CPL1, CPL2, CPL2, CPL2} , SPL0: Simple Profile@Level0 , CPL1: Core Profile@Level1 */
+/* {SSPL0, SSPL1, SSPL2, SSPL2, CSPL1, CSPL2, CSPL3, CSPL3} , SSPL0: Simple Scalable Profile@Level0, CPL1: Core Scalable Profile@Level1 */
+
+typedef enum
+{
+ /* Non-scalable profile */
+ SIMPLE_PROFILE_LEVEL0 = 0,
+ SIMPLE_PROFILE_LEVEL1,
+ SIMPLE_PROFILE_LEVEL2,
+ SIMPLE_PROFILE_LEVEL3,
+ CORE_PROFILE_LEVEL1,
+ CORE_PROFILE_LEVEL2,
+
+ /* Scalable profile */
+ SIMPLE_SCALABLE_PROFILE_LEVEL0 = 6,
+ SIMPLE_SCALABLE_PROFILE_LEVEL1,
+ SIMPLE_SCALABLE_PROFILE_LEVEL2,
+
+ CORE_SCALABLE_PROFILE_LEVEL1 = 10,
+ CORE_SCALABLE_PROFILE_LEVEL2,
+ CORE_SCALABLE_PROFILE_LEVEL3
+
+} ProfileLevelType;
+
+
+typedef struct tagMP4HintTrack
+{
+ UChar MTB;
+ UChar LayerID;
+ UChar CodeType;
+ UChar RefSelCode;
+} MP4HintTrack;
+
+typedef struct tagvideoEncControls
+{
+ void *videoEncoderData;
+ Int videoEncoderInit;
+} VideoEncControls;
+
+
+typedef struct tagvideoEncFrameIO
+{
+ UChar *yChan; /* pointer to Y */
+ UChar *uChan; /* pointer to U */
+ UChar *vChan; /* pointer to V */
+ Int height; /* height for Y */
+ Int pitch; /* stride for Y */
+ ULong timestamp; /* modulo timestamp in millisecond*/
+
+} VideoEncFrameIO ;
+
+/**
+@brief Encoding options structure */
+typedef struct tagvideoEncOptions
+{
+ /** @brief Sets the encoding mode, defined by the above enumaration. If there are conflicts between the encoding mode
+ * and subsequent encoding options, encoding mode take precedent over encoding options. */
+ MP4EncodingMode encMode;
+
+ /** @brief Sets the number of bytes per packet, only used in DATA_PARTITIONING_MODE or COMBINE_MODE_WITH_ERR_RES mode.
+ * The resync marker will be inserted as often as the size of the packet.*/
+ Int packetSize;
+
+ /** @brief Selects MPEG-4/H.263 profile and level, if specified other encoding options must conform with it. */
+ ProfileLevelType profile_level;
+
+ /** @brief Enables reversible variable length code (RVLC) mode. Normally it is set to PV_OFF.*/
+ ParamEncMode rvlcEnable;
+
+ /** @brief Set the frequency of GOB header interval */
+ Int gobHeaderInterval;
+
+ /** @brief Sets the number of bitstream layers: 1 is base only: 2 is base + enhancement */
+ Int numLayers;
+
+ /** @brief Sets the number of ticks per second used for timing information encoded in MPEG4 bitstream.*/
+ Int timeIncRes;
+
+ /** @brief Sets the number of ticks in time increment resolution between 2 source frames (equivalent to source frame rate). */
+ Int tickPerSrc;
+
+ /** @brief Specifies encoded heights in pixels, height[n] represents the n-th layer's height. */
+ Int encHeight[2];
+
+ /** @brief Specifies encoded widths in pixels, width[n] represents the n-th layer's width.*/
+ Int encWidth[2];
+
+ /** @brief Specifies target frame rates in frames per second, frameRate[n] represents the n-th layer's target frame rate.*/
+ float encFrameRate[2];
+
+ /** @brief Specifies target bit rates in bits per second unit, bitRate[n] represents the n-th layer's target bit rate. */
+ Int bitRate[2];
+
+ /** @brief Specifies default quantization parameters for I-Vop. Iquant[n] represents the n-th layer default quantization parameter. The default is Iquant[0]=12.*/
+ Int iQuant[2];
+
+ /** @brief Specifies default quantization parameters for P-Vop. Pquant[n] represents the n-th layer default quantization parameter. The default is Pquant[0]=10.*/
+ Int pQuant[2];
+
+ /** @brief specifies quantization mode (H263 mode or MPEG mode) of the encoded base and enhance layer (if any).
+ * In Simple and Simple Scalable profile, we use only H263 mode.*/
+ Int quantType[2];
+
+ /** @brief Sets rate control algorithm, one of (CONSTANT_Q, CBR_1, or VBR_1).
+ * CONSTANT_Q uses the default quantization values to encode the sequence.
+ * CBR_1 (constant bit rate) controls the output at a desired bit rate
+ * VBR_1 (variable bit rate) gives better picture quality at the expense of bit rate fluctuation
+ * Note: type=CONSTANT_Q produces sequences with arbitrary bit rate.
+ * type=CBR_1 produces sequences suitable for streaming.
+ * type=VBR_1 produces sequences suitable for download. */
+ MP4RateControlType rcType;
+
+ /** @brief Sets the VBV buffer size (in the unit of second delay) used to prevent buffer overflow and underflow
+ * on the decoder side. This function is redundant to PVSetVBVSize. Either one of them is used at a time. */
+ float vbvDelay;
+
+ /** @brief Specifies whether frame skipping is permitted or not. When rate control type is set to CONSTANT_Q
+ * frame skipping is automatically banned. In CBR_1 and VBR_1 rate control, frame skipping is allowed by default.
+ * However, users can force no frame skipping with this flag, but buffer constraint may be violated.*/
+ ParamEncMode noFrameSkipped;
+
+ /** @brief Sets the maximum number of P-frames between two I-frames. I-frame mode is periodically forced
+ * if no I-frame is encoded after the specified period to add error resiliency and help resynchronize in case of errors.
+ * If scene change detection can add additional I-frame if new scenes are detected.
+ * intraPeriod is the I frame interval in terms of second.
+ * intraPeriod =0 indicates I-frame encoding only;
+ * intraPeriod = -1 indicates I-frame followed by all P-frames; (default)
+ * intraPeriod = N, indicates the number of P-frames between 2 I-frames.*/
+ Int intraPeriod;
+
+
+ /** @brief Specifies the number Intra MBs to be refreshed in a P-frame. */
+ Int numIntraMB;
+
+ /**
+ * @brief Specifies whether the scene change detection (SCD) is enabled or disabled.
+ * With SCD enable, when a new scene is detected, I-Vop mode will be used for the first frame of
+ * the new scene resulting in better picture quality. An insertion of an I-VOP resets the intraPeriod
+ * specified by the IntraPeriodAPI().*/
+ ParamEncMode sceneDetect;
+
+ /** @brief Specifies the search range of motion estimation search. Larger value implies
+ * larger search range, better motion vector match, but more complexity.
+ * If searchRange=n, the motion vector search is in the range of [-n,n-1] pixels.
+ * If half-pel mode is on, the range is [-n, (n-1)+1/2] pixels. The default value is 16.*/
+ Int searchRange;
+
+ /** @brief Turns on/off 8x8 block motion estimation and compensation.
+ * If on, four motion vectors may be used for motion estimation and compensation of a macroblock,
+ * otherwise one motion vector per macroblock is used. When the 8x8 MV is off, the total encoding complexity
+ * is less but the image quality is also worse. Therefore, it can be used in complexity limited environment.*/
+ ParamEncMode mv8x8Enable;
+
+
+ /** @brief Set the threshold for using intra DC VLC.
+ * Value must range from 0-7.*/
+ Int intraDCVlcTh;
+
+ /** @brief This flag turns on the use of AC prediction */
+ Bool useACPred;
+
+} VideoEncOptions;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ /* API's */
+ /* Always start with this one !!*/
+ /**
+ * @brief Gets default encoding options. This way users only have to set relevant encoding options and leave the one
+ * they are unsure of.
+ * @encOption Pointer to VideoEncOption structure.
+ * @encUseCase This value determines the set of default encoding options, for example, different encoding options
+ * are assigned to streaming use-case as compared to download use-case. It can be project dependent too.
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVGetDefaultEncOption(VideoEncOptions *encOption, Int encUseCase);
+
+ /**
+ * @brief Verifies the consistency of encoding parameters, allocates memory needed and set necessary internal variables.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encCtrl, VideoEncOptions *encOption);
+
+ /* acquiring encoder info APIs */
+ /**
+ * @brief This function returns VOL header. It has to be called before the frame is encoded. If so,
+ * then the VOL Header is passed back to the application. Then all frames that are encoded do not contain the VOL Header.
+ * If you do not call the API then the VOL Header is passed within the first frame that is encoded.
+ * The behavior is unknown if it is called after the first frame is encoded. It is mainly used for MP4 file format authoring.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs.
+ * @param volHeader is the Buffer for VOL header.
+ * @param size is the size of VOL header in bytes.
+ * @param layer is the layer of the requested VOL header.
+ * @return true for correct operation; false if error happens.
+ */
+ OSCL_IMPORT_REF Bool PVGetVolHeader(VideoEncControls *encCtrl, UChar *volHeader, Int *size, Int layer);
+
+ /**
+ * @brief This function returns the profile and level in H.263 coding when the encoding parameters are set
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs.
+ * @param profileID is the pointer of the profile ID. Right now we only support profile 0
+ * @param levelID is the pointer of the level ID that could be 10-70.
+ * @return true for correct operation; false if error happens.
+ */
+ OSCL_IMPORT_REF Bool PVGetH263ProfileLevelID(VideoEncControls *encCtrl, Int *profileID, Int *levelID);
+
+ /**
+ * @brief This function returns the profile and level of MPEG4 when the encoding parameters are set
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs.
+ * @param profile_level is the pointer of the profile enumeration
+ * @param nLayer is the index of the layer of interest
+ * @return true for correct operation; false if error happens.
+ */
+ OSCL_IMPORT_REF Bool PVGetMPEG4ProfileLevelID(VideoEncControls *encCtrl, Int *profile_level, Int nLayer);
+
+ /**
+ * @brief This function returns maximum frame size in bytes
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param maxVideoFrameSize is the pointer of the maximum frame size
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVGetMaxVideoFrameSize(VideoEncControls *encCtrl, Int *maxVideoFrameSize);
+
+#ifndef LIMITED_API
+ /**
+ * @brief This function returns the total amount of memory (in bytes) allocated by the encoder library.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Int PVGetEncMemoryUsage(VideoEncControls *encCtrl);
+
+ /**
+ * @brief This function is used by PVAuthor to get the size of the VBV buffer.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param VBVSize is the pointer of The size of the VBV buffer in bytes.
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVGetVBVSize(VideoEncControls *encCtrl, Int *VBVSize);
+#endif
+
+ /**
+ * @brief This function encodes a frame in YUV 4:2:0 format from the *video_in input frame and put the result in YUV
+ * for reconstructed frame and bstream for MPEG4 bitstream. The application is required to allocate memory for
+ * bitstream buffer.The size of the input bitstream memory and the returned output buffer are specified in the
+ * size field. The encoded layer is specified by the nLayer field. If the current frame is not encoded, size=0 and nLayer=-1.
+ * Note: If the allocated buffer size is too small to fit a bitstream of a frame, then those extra bits will be left out
+ * which can cause syntactic error at the decoder side.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param vid_in is the pointer to VideoEncFrameIO structure containing the YUV input data
+ * @param vid_out is the pointer to VideoEncFrameIO structure containing the reconstructed YUV output data after encoding
+ * @param nextModTime is the timestamp encoder expects from the next input
+ * @param bstream is the pointer to MPEG4 bitstream buffer
+ * @param size is the size of bitstream buffer allocated (input) and size of the encoded bitstream (output).
+ * @param nLayer is the layer of the encoded frame either 0 for base or 1 for enhancement layer. The value -1 indicates skipped frame due to buffer overflow.
+ * @return true newfor correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVEncodeVideoFrame(VideoEncControls *encCtrl, VideoEncFrameIO *vid_in, VideoEncFrameIO *vid_out,
+ ULong *nextModTime, UChar *bstream, Int *size, Int *nLayer);
+
+
+ /**
+ * @brief This function is used to query overrun buffer. It is used when PVEncodeVideoFrame.returns size that is
+ * larger than the input size.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @return Pointer to the overrun buffer. NULL if overrun buffer is not used.
+ */
+ OSCL_IMPORT_REF UChar* PVGetOverrunBuffer(VideoEncControls *encCtrl);
+
+#ifndef NO_SLICE_ENCODE /* This set of APIs are not working. This functionality has been partially
+ replaced by the introduction of overrun buffer. */
+
+ /* slice-based coding */
+ /**
+ * @brief This function sets the input YUV frame and timestamp to be encoded by the slice-based encoding function PVEncodeSlice().
+ * It also return the memory address the reconstructed frame will be copied to (in advance) and the coded layer number.
+ * The encoder library processes the timestamp and determine if this frame is to be encoded or not. If the current frame
+ * is not encoded, nLayer=-1. For frame-based motion estimation, the motion estimation of the entire frame is also performed
+ * in this function. For MB-based motion estimation, the motion vector is searched while coding each MB in PVEncodeSlice().
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param vid_in is the pointer to VideoEncFrameIO structure containing the YUV input data
+ * @param nextModTime is the timestamp encoder expects from the next input if this input is rejected and nLayer is set to -1.
+ * @param nLayer is the layer of the encoded frame either 0 for base or 1 for enhancement layer. The value -1 indicates skipped frame due to buffer overflow.
+ * @return true newfor correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVEncodeFrameSet(VideoEncControls *encCtrl, VideoEncFrameIO *vid_in, ULong *nextModTime, Int *nLayer);
+ /**
+ * @brief This function encodes a GOB (short header mode) or a packet (data partitioning mode or combined mode with resync marker)
+ * and output the reconstructed frame and MPEG4 bitstream. The application is required to allocate memory for the bitstream buffer.
+ * The size of the input bitstream memory and the returned output buffer are specified in the size field. If the buffer size is
+ * smaller than the requested packet size, user has to call PVEncodeSlice again to get the rest of that pending packet before moving
+ * on to the next packet. For the combined mode without resync marker, the function returns when the buffer is full.
+ * The end-of-frame flag indicates the completion of the frame encoding. Next frame must be sent in with PVEncodeFrameSet().
+ * At the end-of-frame, the next video input address and the next video modulo timestamp will be set.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param bstream is the pointer to MPEG4 bitstream buffer.
+ * @param size is the size of bitstream buffer allocated (input) and size of the encoded bitstream (output).
+ * @param endofFrame is a flag indicating the end-of-frame, '1'. Otherwise, '0'. When PVSetNoCurrentFrameSkip is OFF,
+ * end-of-frame '-1' indicates current frame bitstream must be disregarded.
+ * @param vid_out is the pointer to VideoEncFrameIO structure containing the reconstructed YUV output data after encoding
+ * @param nextModTime is the timestamp encoder expects from the next input
+ * @return true newfor correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVEncodeSlice(VideoEncControls *encCtrl, UChar *bstream, Int *size,
+ Int *endofFrame, VideoEncFrameIO *vid_out, ULong *nextModTime);
+#endif
+
+ /**
+ * @brief This function returns MP4 file format hint track information.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param info is the structure for MP4 hint track information
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVGetHintTrack(VideoEncControls *encCtrl, MP4HintTrack *info);
+
+#ifndef LIMITED_API
+ /**
+ * @brief updates target frame rates of the encoded base and enhance layer (if any) while encoding operation is ongoing.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param frameRate is the pointers to array of target frame rates in frames per second,
+ * frameRate[n] represents the n-th layer's target frame rate.
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVUpdateEncFrameRate(VideoEncControls *encCtrl, float *frameRate); /* for 2-way */
+
+
+ /**
+ * @brief updates target bit rates of the encoded base and enhance layer (if any) while encoding operation is ongoing.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param bitRate is the pointers to array of target bit rates in bits per second unit,
+ * bitRate[n] represents the n-th layer's target bit rate.
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVUpdateBitRate(VideoEncControls *encCtrl, Int *bitRate); /* for 2-way */
+
+
+ /**
+ * @brief updates the INTRA frame refresh interval while encoding operation is ongoing.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param aIFramePeriod is a new value of INTRA frame interval in the unit of number of coded frames.
+ * @return true for correct operation; false if error happens
+ */
+
+ OSCL_IMPORT_REF Bool PVUpdateIFrameInterval(VideoEncControls *encCtrl, Int aIFramePeriod);/* for 2-way */
+
+ /**
+ * @brief specifies the number Intra MBs to be refreshed
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @param numMB is the number of Intra MBs to be refreshed
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVUpdateNumIntraMBRefresh(VideoEncControls *encCtrl, Int numMB); /* for 2-way */
+
+ /**
+ * @brief This function is called whenever users want the next base frame to be encoded as an I-Vop.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVIFrameRequest(VideoEncControls *encCtrl); /* for 2-way */
+
+#endif // LIMITED_API
+
+ /* finishing encoder */
+ /**
+ * @brief This function frees up all the memory allocated by the encoder library.
+ * @param encCtrl is video encoder control structure that is always passed as input in all APIs
+ * @return true for correct operation; false if error happens
+ */
+ OSCL_IMPORT_REF Bool PVCleanUpVideoEncoder(VideoEncControls *encCtrl);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _MP4ENC_API_H_ */
+
diff --git a/media/codecs/m4v_h263/enc/src/bitstream_io.cpp b/media/codecs/m4v_h263/enc/src/bitstream_io.cpp
new file mode 100644
index 0000000..5c4c4ab
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/bitstream_io.cpp
@@ -0,0 +1,859 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/* Date: 8/02/04 */
+/* Description: */
+/* Change the bitstream parsing algorithm. Use temporary word of 2 or 4 bytes */
+/* before writing it to the bitstream buffer. */
+/* Note byteCount doesn't have to be multiple of 2 or 4 */
+/*********************************************************************************/
+
+#include "bitstream_io.h"
+#include "m4venc_oscl.h"
+#include <stdlib.h>
+
+static const UChar Mask[ ] =
+{
+ 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF
+};
+
+#define WORD_SIZE 4 /* for 32-bit machine */
+
+/*Note:
+ 1. There is a problem when output the last bits(which can not form a byte yet
+ so when you output, you need to stuff to make sure it is a byte
+ 2. I now hard coded byte to be 8 bits*/
+
+
+/* ======================================================================== */
+/* Function : BitStreamCreateEnc(Int bufferSize ) */
+/* Date : 08/29/2000 */
+/* Purpose : Create a bitstream to hold one encoded video packet or frame */
+/* In/out : */
+/* bufferSize : size of the bitstream buffer in bytes */
+/* Return : Pointer to the BitstreamEncVideo */
+/* Modified : */
+/* ======================================================================== */
+
+BitstreamEncVideo *BitStreamCreateEnc(Int bufferSize)
+{
+ BitstreamEncVideo *stream;
+ stream = (BitstreamEncVideo *) M4VENC_MALLOC(sizeof(BitstreamEncVideo));
+ if (stream == NULL)
+ {
+ return NULL;
+ }
+ stream->bufferSize = bufferSize;
+ stream->bitstreamBuffer = (UChar *) M4VENC_MALLOC(stream->bufferSize * sizeof(UChar));
+ if (stream->bitstreamBuffer == NULL)
+ {
+ M4VENC_FREE(stream);
+ stream = NULL;
+ return NULL;
+ }
+ M4VENC_MEMSET(stream->bitstreamBuffer, 0, stream->bufferSize*sizeof(UChar));
+ stream->word = 0;
+#if WORD_SIZE==4
+ stream->bitLeft = 32;
+#else
+ stream->bitLeft = 16;
+#endif
+ stream->byteCount = 0;
+
+ stream->overrunBuffer = NULL;
+ stream->oBSize = 0;
+
+ return stream;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamCloseEnc( ) */
+/* Date : 08/29/2000 */
+/* Purpose : close a bitstream */
+/* In/out :
+ stream : the bitstream to be closed */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+Void BitstreamCloseEnc(BitstreamEncVideo *stream)
+{
+ if (stream)
+ {
+ if (stream->bitstreamBuffer)
+ {
+ M4VENC_FREE(stream->bitstreamBuffer);
+ }
+
+ M4VENC_FREE(stream);
+ }
+}
+
+
+/* ======================================================================== */
+/* Function : BitstreamPutBits(BitstreamEncVideo *stream, Int Length,
+ Int Value) */
+/* Date : 08/29/2000 */
+/* Purpose : put Length (1-16) number of bits to the stream */
+/* for 32-bit machine this function can do upto 32 bit input */
+/* In/out : */
+/* stream the bitstream where the bits are put in */
+/* Length bits length (should belong to 1 to 16) */
+/* Value those bits value */
+/* Return : PV_STATUS */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS BitstreamPutBits(BitstreamEncVideo *stream, Int Length, UInt Value)
+{
+ PV_STATUS status;
+
+ if (stream->bitLeft > Length)
+ {
+ stream->word <<= Length;
+ stream->word |= Value; /* assuming Value is not larger than Length */
+ stream->bitLeft -= Length;
+ return PV_SUCCESS;
+ }
+ else
+ {
+
+ stream->word <<= stream->bitLeft;
+ Length -= stream->bitLeft;
+ stream->word |= ((UInt)Value >> Length);
+
+ status = BitstreamSaveWord(stream);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ /* we got new Length and Value */
+ /* note that Value is not "clean" because of msb are not masked out */
+ stream->word = Value;
+ stream->bitLeft -= Length;
+ /* assuming that Length is no more than 16 bits */
+ /* stream->bitLeft should be greater than zero at this point */
+ //if(stream->bitLeft<=0)
+ // exit(-1);
+ return PV_SUCCESS;
+ }
+}
+
+/* ======================================================================== */
+/* Function : BitstreamPutGT16Bits(BitstreamEncVideo *stream, Int Length, UInt32 Value) */
+/* Date : 08/29/2000 */
+/* Purpose : Use this function to put Length (17-32) number of bits to */
+/* for 16-bit machine the stream. */
+/* In/out : */
+/* stream the bitstream where the bits are put in */
+/* Length bits length (should belong to 17 to 32) */
+/* Value those bits value */
+/* Return : PV_STATUS */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS BitstreamPutGT16Bits(BitstreamEncVideo *stream, Int Length, ULong Value)
+{
+ PV_STATUS status;
+ UInt topValue;
+ Int topLength;
+
+ topValue = (Value >> 16);
+ topLength = Length - 16;
+
+ if (topLength > 0)
+ {
+ status = BitstreamPutBits(stream, topLength, topValue);
+
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ status = BitstreamPutBits(stream, 16, (UInt)(Value & 0xFFFF));
+
+ return status;
+ }
+ else
+ {
+ status = BitstreamPutBits(stream, Length, (UInt)Value);
+ return status;
+ }
+}
+
+/* ======================================================================== */
+/* Function : BitstreamSaveWord */
+/* Date : 08/03/2004 */
+/* Purpose : save written word into the bitstream buffer. */
+/* In/out : */
+/* stream the bitstream where the bits are put in */
+/* Return : PV_STATUS */
+/* Modified : */
+/* ======================================================================== */
+
+PV_STATUS BitstreamSaveWord(BitstreamEncVideo *stream)
+{
+ UChar *ptr;
+ UInt word;
+
+ /* assume that stream->bitLeft is always zero when this function is called */
+ if (stream->byteCount + WORD_SIZE > stream->bufferSize)
+ {
+ if (PV_SUCCESS != BitstreamUseOverrunBuffer(stream, WORD_SIZE))
+ {
+ stream->byteCount += WORD_SIZE;
+ return PV_FAIL;
+ }
+ }
+
+ ptr = stream->bitstreamBuffer + stream->byteCount;
+ word = stream->word;
+ stream->word = 0; /* important to reset to zero */
+
+ /* NOTE: byteCount does not have to be multiple of 2 or 4 */
+#if (WORD_SIZE == 4)
+ *ptr++ = word >> 24;
+ *ptr++ = 0xFF & (word >> 16);
+#endif
+
+ *ptr++ = 0xFF & (word >> 8);
+ *ptr = 0xFF & word;
+
+#if (WORD_SIZE == 4)
+ stream->byteCount += 4;
+ stream->bitLeft = 32;
+#else
+ stream->byteCount += 2;
+ stream->bitLeft = 16;
+#endif
+
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : BitstreamSavePartial */
+/* Date : 08/03/2004 */
+/* Purpose : save unfinished written word into the bitstream buffer. */
+/* In/out : */
+/* stream the bitstream where the bits are put in */
+/* Return : PV_STATUS */
+/* Modified : */
+/* ======================================================================== */
+
+PV_STATUS BitstreamSavePartial(BitstreamEncVideo *stream, Int *fraction)
+{
+ UChar *ptr;
+ UInt word, shift;
+ Int numbyte, bitleft, bitused;
+
+ bitleft = stream->bitLeft;
+ bitused = (WORD_SIZE << 3) - bitleft; /* number of bits used */
+ numbyte = bitused >> 3; /* number of byte fully used */
+
+ if (stream->byteCount + numbyte > stream->bufferSize)
+ {
+ if (PV_SUCCESS != BitstreamUseOverrunBuffer(stream, numbyte))
+ {
+ stream->byteCount += numbyte;
+ return PV_FAIL;
+ }
+ }
+
+ ptr = stream->bitstreamBuffer + stream->byteCount;
+ word = stream->word;
+ word <<= bitleft; /* word is not all consumed */
+ bitleft = bitused - (numbyte << 3); /* number of bits used (fraction) */
+ stream->byteCount += numbyte;
+ if (bitleft)
+ {
+ *fraction = 1;
+ }
+ else
+ {
+ *fraction = 0;
+ }
+ bitleft = (WORD_SIZE << 3) - bitleft;
+ /* save new value */
+ stream->bitLeft = bitleft;
+
+ shift = ((WORD_SIZE - 1) << 3);
+ while (numbyte)
+ {
+ *ptr++ = (UChar)((word >> shift) & 0xFF);
+ word <<= 8;
+ numbyte--;
+ }
+
+ if (*fraction)
+ {// this could lead to buffer overrun when ptr is already out of bound.
+ // *ptr = (UChar)((word>>shift)&0xFF); /* need to do it for the last fractional byte */
+ }
+
+ /* save new values */
+ stream->word = word >> bitleft;
+
+ /* note we don't update byteCount, bitLeft and word */
+ /* so that encoder can continue PutBits if they don't */
+
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : BitstreamShortHeaderByteAlignStuffing( */
+/* BitstreamEncVideo *stream) */
+/* Date : 08/29/2000 */
+/* Purpose : bit stuffing for next start code in short video header */
+/* In/out : */
+/* Return : number of bits to be stuffed */
+/* Modified : */
+/* ======================================================================== */
+
+Int BitstreamShortHeaderByteAlignStuffing(BitstreamEncVideo *stream)
+{
+ UInt restBits;
+ Int fraction;
+
+ restBits = (stream->bitLeft & 0x7); /* modulo 8 */
+
+ if (restBits) /*short_video_header[0] is 1 in h263 baseline*/
+ {
+ /* H.263 style stuffing */
+ BitstreamPutBits(stream, restBits, 0);
+ }
+
+ if (stream->bitLeft != (WORD_SIZE << 3))
+ {
+ BitstreamSavePartial(stream, &fraction);
+ }
+
+ return restBits;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamMpeg4ByteAlignStuffing(BitstreamEncVideo *stream) */
+/* Date : 08/29/2000 */
+/* Purpose : bit stuffing for next start code in MPEG-4 */
+/* In/out : */
+/* Return : number of bits to be stuffed */
+/* Modified : */
+/* ======================================================================== */
+Int BitstreamMpeg4ByteAlignStuffing(BitstreamEncVideo *stream)
+{
+
+ UInt restBits;
+ Int fraction;
+ /* Question: in MPEG-4 , short_video_header[0]==0 => even already byte aligned, will still stuff 8 bits
+ need to check with */
+ /*if (!(getPointerENC(index1, index2)%8) && short_video_header[0]) return 0;*/
+
+ /* need stuffing bits, */
+ BitstreamPutBits(stream, 1, 0);
+
+ restBits = (stream->bitLeft & 0x7); /* modulo 8 */
+
+ if (restBits) /*short_video_header[0] is 1 in h263 baseline*/
+ {
+ /* need stuffing bits, */
+ BitstreamPutBits(stream, restBits, Mask[restBits]);
+ }
+
+ if (stream->bitLeft != (WORD_SIZE << 3))
+ {
+ BitstreamSavePartial(stream, &fraction);
+ }
+
+ return (restBits);
+}
+
+/*does bit stuffing for next resync marker*/
+/* does bit stuffing for next resync marker
+ * "0"
+ * "01"
+ * "011"
+ * "0111"
+ * "01111"
+ * "011111"
+ * "0111111"
+ * "01111111" (8-bit codeword)
+ */
+
+/*Int BitstreamNextResyncMarkerEnc(BitstreamEncVideo *stream)
+{
+ Int count;
+ BitstreamPut1Bits(stream,0);
+ count=8-stream->totalBits & 8;
+ BitstreamPutBits(stream,count,Mask[count]);
+ return count;
+}*/
+
+/* ======================================================================== */
+/* Function : BitstreamAppendEnc( BitstreamEncVideo *bitstream1, */
+/* BitstreamEncVideo *bitstream2 ) */
+/* Date : 08/29/2000 */
+/* Purpose : Append the intermediate bitstream (bitstream2) to the end of */
+/* output bitstream(bitstream1) */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+
+PV_STATUS BitstreamAppendEnc(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2)
+{
+ PV_STATUS status;
+ UChar *ptrBS2, *ptrBS1;
+ UChar byteBS2, byteBS1;
+ Int numbyte2;
+ Int bitused, bitleft, offset, fraction;
+
+ status = BitstreamSavePartial(bitstream1, &fraction);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ offset = fraction;
+ status = BitstreamSavePartial(bitstream2, &fraction);
+ if (status != PV_SUCCESS)
+ {
+ return status;
+ }
+
+ if (!offset) /* bitstream1 is byte-aligned */
+ {
+ return BitstreamAppendPacket(bitstream1, bitstream2);
+ }
+
+ offset += fraction;
+
+ /* since bitstream1 doesn't have to be byte-aligned, we have to process byte by byte */
+ /* we read one byte from bitstream2 and use BitstreamPutBits to do the job */
+ if (bitstream1->byteCount + bitstream2->byteCount + offset > bitstream1->bufferSize)
+ {
+ if (PV_SUCCESS != BitstreamUseOverrunBuffer(bitstream1, bitstream2->byteCount + offset))
+ {
+ bitstream1->byteCount += (bitstream2->byteCount + offset);
+ return PV_FAIL;
+ }
+ }
+
+ ptrBS1 = bitstream1->bitstreamBuffer + bitstream1->byteCount; /* move ptr bs1*/
+ ptrBS2 = bitstream2->bitstreamBuffer;
+
+ bitused = (WORD_SIZE << 3) - bitstream1->bitLeft; /* this must be between 1-7 */
+ bitleft = 8 - bitused;
+
+ numbyte2 = bitstream2->byteCount; /* number of byte to copy from bs2 */
+ bitstream1->byteCount += numbyte2; /* new byteCount */
+
+ byteBS1 = ((UChar) bitstream1->word) << bitleft; /* fraction byte from bs1 */
+
+ while (numbyte2)
+ {
+ byteBS2 = *ptrBS2++;
+ byteBS1 |= (byteBS2 >> bitused);
+ *ptrBS1++ = byteBS1;
+ byteBS1 = byteBS2 << bitleft;
+ numbyte2--;
+ }
+
+ bitstream1->word = byteBS1 >> bitleft; /* bitstream->bitLeft remains the same */
+
+ /* now save bs2->word in bs1 */
+ status = BitstreamPutBits(bitstream1, (WORD_SIZE << 3) - bitstream2->bitLeft, bitstream2->word);
+
+ return status;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamAppendPacket( BitstreamEncVideo *bitstream1, */
+/* BitstreamEncVideo *bitstream2 ) */
+/* Date : 05/31/2001 */
+/* Purpose : Append the intermediate bitstream (bitstream2) to the end of */
+/* output bitstream(bitstream1) knowing that bitstream1 is byte-aligned*/
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS BitstreamAppendPacket(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2)
+{
+ UChar *ptrBS2, *ptrBS1;
+ Int numbyte2;
+
+ if (bitstream1->byteCount + bitstream2->byteCount > bitstream1->bufferSize)
+ {
+ if (PV_SUCCESS != BitstreamUseOverrunBuffer(bitstream1, bitstream2->byteCount))
+ {
+ bitstream1->byteCount += bitstream2->byteCount; /* legacy, to keep track of total bytes */
+ return PV_FAIL;
+ }
+ }
+
+ ptrBS1 = bitstream1->bitstreamBuffer + bitstream1->byteCount; /* move ptr bs1*/
+ ptrBS2 = bitstream2->bitstreamBuffer;
+
+ numbyte2 = bitstream2->byteCount;
+ bitstream1->byteCount += numbyte2; /* new byteCount */
+
+ /*copy all the bytes in bitstream2*/
+ M4VENC_MEMCPY(ptrBS1, ptrBS2, sizeof(UChar)*numbyte2);
+
+ bitstream1->word = bitstream2->word; /* bitstream1->bitLeft is the same */
+ bitstream1->bitLeft = bitstream2->bitLeft;
+
+ return PV_SUCCESS;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamAppendPacketNoOffset( BitstreamEncVideo *bitstream1,*/
+/* BitstreamEncVideo *bitstream2 ) */
+/* Date : 04/23/2002 */
+/* Purpose : Append the intermediate bitstream (bitstream2) to the end of */
+/* output bitstream(bitstream1) , for slice-based coding only */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS BitstreamAppendPacketNoOffset(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2)
+{
+ PV_STATUS status = PV_SUCCESS;
+ UChar *ptrBS2, *ptrBS1;
+ Int numbyte2;
+ Int byteleft;
+
+ numbyte2 = bitstream2->byteCount;
+
+ if (bitstream1->byteCount + bitstream2->byteCount > bitstream1->bufferSize)
+ {
+ numbyte2 = bitstream1->bufferSize - bitstream1->byteCount;
+ status = PV_END_OF_BUF; /* signal end of buffer */
+ }
+
+ ptrBS1 = bitstream1->bitstreamBuffer; /* move ptr bs1*/
+ ptrBS2 = bitstream2->bitstreamBuffer;
+
+ bitstream1->byteCount += numbyte2; /* should be equal to bufferSize */
+
+ /*copy all the bytes in bitstream2*/
+ M4VENC_MEMCPY(ptrBS1, ptrBS2, sizeof(UChar)*numbyte2);
+ bitstream1->word = 0;
+ bitstream1->bitLeft = (WORD_SIZE << 3);
+
+ if (status == PV_END_OF_BUF) /* re-position bitstream2 */
+ {
+ byteleft = bitstream2->byteCount - numbyte2;
+
+ M4VENC_MEMCPY(ptrBS2, ptrBS2 + numbyte2, sizeof(UChar)*byteleft);
+
+ bitstream2->byteCount = byteleft;
+ /* bitstream2->word and bitstream->bitLeft are unchanged.
+ they should be 0 and (WORD_SIZE<<3) */
+ }
+
+ return status;
+}
+
+#ifndef NO_SLICE_ENCODE
+/* ======================================================================== */
+/* Function : BitstreamRepos( BitstreamEncVideo *bitstream, */
+/* Int byteCount, Int bitCount) */
+/* Date : 04/28/2002 */
+/* Purpose : Reposition the size of the buffer content (curtail) */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS BitstreamRepos(BitstreamEncVideo *bitstream, Int byteCount, Int bitCount)
+{
+ UChar *ptr, byte;
+ UInt word;
+ Int fraction;
+
+ BitstreamSavePartial(bitstream, &fraction);
+
+ bitstream->byteCount = byteCount;
+ ptr = bitstream->bitstreamBuffer + byteCount; /* get fraction of the byte */
+ if (bitCount)
+ {
+ bitstream->bitLeft = (WORD_SIZE << 3) - bitCount; /* bitCount should be 0-31 */
+ word = *ptr++;
+ byte = *ptr++;
+ word = byte | (word << 8);
+#if (WORD_SIZE == 4)
+ byte = *ptr++;
+ word = byte | (word << 8);
+ byte = *ptr++;
+ word = byte | (word << 8);
+#endif
+ bitstream->word = word >> (bitstream->bitLeft);
+ }
+ else
+ {
+ bitstream->word = 0;
+ bitstream->bitLeft = (WORD_SIZE << 3);
+ }
+
+ return PV_SUCCESS;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamFlushBits(BitstreamEncVideo *bitstream1, */
+/* Int num_bit_left) */
+/* Date : 04/24/2002 */
+/* Purpose : Flush buffer except the last num_bit_left bits. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+
+PV_STATUS BitstreamFlushBits(BitstreamEncVideo *bitstream1, Int num_bit_left)
+{
+ Int i;
+ UChar *ptrDst, *ptrSrc;
+ Int leftover, bitused;
+ Int new_byte = (num_bit_left >> 3);
+ Int new_bit = num_bit_left - (new_byte << 3); /* between 0-7 */
+
+ ptrSrc = bitstream1->bitstreamBuffer + bitstream1->byteCount;
+ ptrDst = bitstream1->bitstreamBuffer;
+
+ bitused = (WORD_SIZE << 3) - bitstream1->bitLeft;
+
+ leftover = 8 - bitused; /* bitused should be between 0-7 */
+
+ bitstream1->byteCount = new_byte;
+ bitstream1->bitLeft = (WORD_SIZE << 3) - new_bit;
+
+ if (!bitused) /* byte aligned */
+ {
+ M4VENC_MEMCPY(ptrDst, ptrSrc, new_byte + 1);
+ }
+ else
+ {
+ /*copy all the bytes in bitstream2*/
+ for (i = 0; i < new_byte; i++)
+ {
+ *ptrDst++ = (ptrSrc[0] << bitused) | (ptrSrc[1] >> leftover);
+ ptrSrc++;
+ }
+ /* copy for the last byte of ptrSrc, copy extra bits doesn't hurt */
+ if (new_bit)
+ {
+ *ptrDst++ = (ptrSrc[0] << bitused) | (ptrSrc[1] >> leftover);
+ ptrSrc++;
+ }
+ }
+ if (new_bit)
+ {
+ ptrSrc = bitstream1->bitstreamBuffer + new_byte;
+ bitstream1->word = (*ptrSrc) >> (8 - new_bit);
+ }
+
+ return PV_SUCCESS;
+}
+
+/* ======================================================================== */
+/* Function : BitstreamPrependPacket( BitstreamEncVideo *bitstream1, */
+/* BitstreamEncVideo *bitstream2 ) */
+/* Date : 04/26/2002 */
+/* Purpose : Prepend the intermediate bitstream (bitstream2) to the beginning of */
+/* output bitstream(bitstream1) */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS BitstreamPrependPacket(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2)
+{
+ UChar *pSrc, *pDst, byte;
+ Int movebyte, bitused, leftover, i, fraction;
+
+ BitstreamSavePartial(bitstream2, &fraction); /* make sure only fraction of byte left */
+ BitstreamSavePartial(bitstream1, &fraction);
+
+ if (bitstream1->byteCount + bitstream2->byteCount >= bitstream1->bufferSize)
+ {
+ bitstream1->byteCount += bitstream2->byteCount;
+ return PV_END_OF_BUF;
+ }
+
+ movebyte = bitstream1->byteCount;
+ if (movebyte < bitstream2->byteCount)
+ movebyte = bitstream2->byteCount;
+ movebyte++;
+
+ /* shift bitstream1 to the right by movebyte */
+ pSrc = bitstream1->bitstreamBuffer;
+ pDst = pSrc + movebyte;
+
+ M4VENC_MEMCPY(pDst, pSrc, bitstream1->byteCount + 1);
+
+ /* copy bitstream2 to the beginning of bitstream1 */
+ M4VENC_MEMCPY(pSrc, bitstream2->bitstreamBuffer, bitstream2->byteCount + 1);
+
+ /* now shift back previous bitstream1 buffer to the end */
+ pSrc = pDst;
+ pDst = bitstream1->bitstreamBuffer + bitstream2->byteCount;
+
+ bitused = (WORD_SIZE << 3) - bitstream2->bitLeft;
+ leftover = 8 - bitused; /* bitused should be 0-7 */
+
+ byte = (bitstream2->word) << leftover;
+
+ *pDst++ = byte | (pSrc[0] >> bitused);
+
+ for (i = 0; i < bitstream1->byteCount + 1; i++)
+ {
+ *pDst++ = ((pSrc[0] << leftover) | (pSrc[1] >> bitused));
+ pSrc++;
+ }
+
+ bitstream1->byteCount += bitstream2->byteCount;
+ //bitstream1->bitCount += bitstream2->bitCount;
+ bitused = (WORD_SIZE << 4) - (bitstream1->bitLeft + bitstream2->bitLeft);
+
+ if (bitused >= 8)
+ {
+ bitused -= 8;
+ bitstream1->byteCount++;
+ }
+
+ bitstream1->bitLeft = (WORD_SIZE << 3) - bitused;
+
+ bitstream2->byteCount = bitstream2->word = 0;
+ bitstream2->bitLeft = (WORD_SIZE << 3);
+
+ pSrc = bitstream1->bitstreamBuffer + bitstream1->byteCount;
+ leftover = 8 - bitused;
+ //*pSrc = (pSrc[0]>>leftover)<<leftover; /* make sure the rest of bits are zeros */
+
+ bitstream1->word = (UInt)((pSrc[0]) >> leftover);
+
+ return PV_SUCCESS;
+}
+#endif /* NO_SLICE_ENCODE */
+
+
+/* ======================================================================== */
+/* Function : BitstreamGetPos( BitstreamEncVideo *stream */
+/* Date : 08/05/2004 */
+/* Purpose : Get the bit position. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+Int BitstreamGetPos(BitstreamEncVideo *stream)
+{
+
+ return stream->byteCount*8 + (WORD_SIZE << 3) - stream->bitLeft;
+}
+
+void BitstreamEncReset(BitstreamEncVideo *stream)
+{
+ stream->bitLeft = (WORD_SIZE << 3);
+ stream->word = 0;
+ stream->byteCount = 0;
+ return ;
+}
+
+/* This function set the overrun buffer, and VideoEncData context for callback to reallocate
+overrun buffer. */
+Void BitstreamSetOverrunBuffer(BitstreamEncVideo* stream, UChar* overrunBuffer, Int oBSize, VideoEncData *video)
+{
+ stream->overrunBuffer = overrunBuffer;
+ stream->oBSize = oBSize;
+ stream->video = video;
+
+ return ;
+}
+
+
+/* determine whether overrun buffer can be used or not */
+PV_STATUS BitstreamUseOverrunBuffer(BitstreamEncVideo* stream, Int numExtraBytes)
+{
+ VideoEncData *video = stream->video;
+
+ if (stream->overrunBuffer != NULL) // overrunBuffer is set
+ {
+ if (stream->bitstreamBuffer != stream->overrunBuffer) // not already used
+ {
+ if (stream->byteCount + numExtraBytes >= stream->oBSize)
+ {
+ stream->oBSize = stream->byteCount + numExtraBytes + 100;
+ stream->oBSize &= (~0x3); // make it multiple of 4
+
+ // allocate new overrun Buffer
+ if (video->overrunBuffer)
+ {
+ M4VENC_FREE(video->overrunBuffer);
+ }
+ video->oBSize = stream->oBSize;
+ video->overrunBuffer = (UChar*) M4VENC_MALLOC(sizeof(UChar) * stream->oBSize);
+ stream->overrunBuffer = video->overrunBuffer;
+ if (stream->overrunBuffer == NULL)
+ {
+ return PV_FAIL;
+ }
+ }
+
+ // copy everything to overrun buffer and start using it.
+ memcpy(stream->overrunBuffer, stream->bitstreamBuffer, stream->byteCount);
+ stream->bitstreamBuffer = stream->overrunBuffer;
+ stream->bufferSize = stream->oBSize;
+ }
+ else // overrun buffer is already used
+ {
+ if (stream->byteCount + numExtraBytes >= stream->oBSize)
+ {
+ stream->oBSize = stream->byteCount + numExtraBytes + 100;
+ }
+
+ // allocate new overrun buffer
+ stream->oBSize &= (~0x3); // make it multiple of 4
+ video->oBSize = stream->oBSize;
+ video->overrunBuffer = (UChar*) M4VENC_MALLOC(sizeof(UChar) * stream->oBSize);
+ if (video->overrunBuffer == NULL)
+ {
+ return PV_FAIL;
+ }
+
+ // copy from the old buffer to new buffer
+ memcpy(video->overrunBuffer, stream->overrunBuffer, stream->byteCount);
+ // free old buffer
+ M4VENC_FREE(stream->overrunBuffer);
+ // assign pointer to new buffer
+ stream->overrunBuffer = video->overrunBuffer;
+ stream->bitstreamBuffer = stream->overrunBuffer;
+ stream->bufferSize = stream->oBSize;
+ }
+
+ return PV_SUCCESS;
+ }
+ else // overrunBuffer is not enable.
+ {
+ return PV_FAIL;
+ }
+
+}
+
+
+
+
+
+
+
diff --git a/media/codecs/m4v_h263/enc/src/bitstream_io.h b/media/codecs/m4v_h263/enc/src/bitstream_io.h
new file mode 100644
index 0000000..0bce257
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/bitstream_io.h
@@ -0,0 +1,57 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _BITSTREAM_IO_H_
+#define _BITSTREAM_IO_H_
+
+#define BitstreamPut1Bits(x,y) BitstreamPutBits(x,1,y)
+#define BitstreamPutGT8Bits(x,y,z) BitstreamPutBits(x,y,z)
+
+#include "mp4lib_int.h"
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ BitstreamEncVideo *BitStreamCreateEnc(Int bufferSize);
+ Void BitstreamCloseEnc(BitstreamEncVideo *stream);
+ PV_STATUS BitstreamPutBits(BitstreamEncVideo *stream, Int Length, UInt Value);
+ PV_STATUS BitstreamPutGT16Bits(BitstreamEncVideo *stream, Int Length, ULong Value);
+ PV_STATUS BitstreamSaveWord(BitstreamEncVideo *stream);
+ PV_STATUS BitstreamSavePartial(BitstreamEncVideo *stream, Int *fraction);
+ Int BitstreamGetPos(BitstreamEncVideo *stream);
+ void BitstreamEncReset(BitstreamEncVideo *stream);
+
+ Int BitstreamShortHeaderByteAlignStuffing(BitstreamEncVideo *stream);
+ Int BitstreamMpeg4ByteAlignStuffing(BitstreamEncVideo *stream);
+ PV_STATUS BitstreamAppendEnc(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2);
+ PV_STATUS BitstreamAppendPacket(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2);
+ PV_STATUS BitstreamAppendPacketNoOffset(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2);
+ PV_STATUS BitstreamRepos(BitstreamEncVideo *bitstream, Int byteCount, Int bitCount);
+ PV_STATUS BitstreamFlushBits(BitstreamEncVideo *bitstream1, Int num_bit_left);
+ PV_STATUS BitstreamPrependPacket(BitstreamEncVideo *bitstream1, BitstreamEncVideo *bitstream2);
+
+
+ Void BitstreamSetOverrunBuffer(BitstreamEncVideo *stream, UChar *overrunBuffer, Int oBSize, VideoEncData *video);
+ PV_STATUS BitstreamUseOverrunBuffer(BitstreamEncVideo* stream, Int numExtraBytes);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BITSTREAM_IO_H_ */
diff --git a/media/codecs/m4v_h263/enc/src/combined_encode.cpp b/media/codecs/m4v_h263/enc/src/combined_encode.cpp
new file mode 100644
index 0000000..e725680
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/combined_encode.cpp
@@ -0,0 +1,693 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4enc_lib.h"
+#include "mp4lib_int.h"
+#include "bitstream_io.h"
+#include "vlc_encode.h"
+#include "m4venc_oscl.h"
+
+PV_STATUS EncodeGOBHeader(VideoEncData *video, Int GOB_number, Int quant_scale, Int bs1stream);
+
+/* ======================================================================== */
+/* Function : EncodeFrameCombinedMode() */
+/* Date : 09/01/2000 */
+/* History : */
+/* Purpose : Encode a frame of MPEG4 bitstream in Combined mode. */
+/* In/out : */
+/* Return : PV_SUCCESS if successful else PV_FAIL */
+/* Modified : */
+/* */
+/* ======================================================================== */
+PV_STATUS EncodeFrameCombinedMode(VideoEncData *video)
+{
+ PV_STATUS status = PV_SUCCESS;
+ Vol *currVol = video->vol[video->currLayer];
+ Vop *currVop = video->currVop;
+ VideoEncParams *encParams = video->encParams;
+ Int width = currVop->width; /* has to be Vop, for multiple of 16 */
+ Int lx = currVop->pitch; /* with padding */
+ Int offset = 0;
+ Int ind_x, ind_y;
+ Int start_packet_header = 0;
+ UChar *QPMB = video->QPMB;
+ Int QP;
+ Int mbnum = 0, slice_counter = 0, curr_slice_counter = 0;
+ Int num_bits, packet_size = encParams->ResyncPacketsize;
+ Int GOB_Header_Interval = encParams->GOB_Header_Interval;
+ BitstreamEncVideo *bs1 = video->bitstream1;
+ Int numHeaderBits;
+ approxDCT fastDCTfunction;
+ Int ncoefblck[6] = {64, 64, 64, 64, 64, 64}; /* for FastCodeMB, 5/18/2001 */
+ PV_STATUS(*CodeMB)(VideoEncData *, approxDCT *, Int, Int[]);
+ void (*MBVlcEncode)(VideoEncData*, Int[], void *);
+ void (*BlockCodeCoeff)(RunLevelBlock*, BitstreamEncVideo*, Int, Int, UChar);
+
+ /* for H263 GOB changes */
+//MP4RateControlType rc_type = encParams->RC_Type;
+
+ video->QP_prev = currVop->quantizer;
+
+ numHeaderBits = BitstreamGetPos(bs1);
+
+ /* determine type of quantization */
+#ifndef NO_MPEG_QUANT
+ if (currVol->quantType == 0)
+ CodeMB = &CodeMB_H263;
+ else
+ CodeMB = &CodeMB_MPEG;
+#else
+ CodeMB = &CodeMB_H263;
+#endif
+
+ /* determine which functions to be used, in MB-level */
+ if (currVop->predictionType == P_VOP)
+ MBVlcEncode = &MBVlcEncodeCombined_P_VOP;
+ else if (currVop->predictionType == I_VOP)
+ MBVlcEncode = &MBVlcEncodeCombined_I_VOP;
+ else /* B_VOP not implemented yet */
+ return PV_FAIL;
+
+ /* determine which VLC table to be used */
+#ifndef H263_ONLY
+ if (currVol->shortVideoHeader)
+ BlockCodeCoeff = &BlockCodeCoeff_ShortHeader;
+#ifndef NO_RVLC
+ else if (currVol->useReverseVLC)
+ BlockCodeCoeff = &BlockCodeCoeff_RVLC;
+#endif
+ else
+ BlockCodeCoeff = &BlockCodeCoeff_Normal;
+#else
+ BlockCodeCoeff = &BlockCodeCoeff_ShortHeader;
+#endif
+
+ /* gob_frame_id is the same for different vop types - the reason should be SCD */
+ if (currVol->shortVideoHeader && currVop->gobFrameID != currVop->predictionType)
+ currVop->gobFrameID = currVop->predictionType;
+
+
+ video->usePrevQP = 0;
+
+ for (ind_y = 0; ind_y < currVol->nMBPerCol; ind_y++) /* Col MB Loop */
+ {
+
+ video->outputMB->mb_y = ind_y; /* 5/28/01 */
+
+ if (currVol->shortVideoHeader) /* ShortVideoHeader Mode */
+ {
+
+ if (slice_counter && GOB_Header_Interval && (ind_y % GOB_Header_Interval == 0)) /* Encode GOB Header */
+ {
+ QP = QPMB[mbnum]; /* Get quant_scale */
+ video->header_bits -= BitstreamGetPos(currVol->stream); /* Header Bits */
+ status = EncodeGOBHeader(video, slice_counter, QP, 0); //ind_y /* Encode GOB Header */
+ video->header_bits += BitstreamGetPos(currVol->stream); /* Header Bits */
+ curr_slice_counter = slice_counter;
+ }
+ }
+
+ for (ind_x = 0; ind_x < currVol->nMBPerRow; ind_x++) /* Row MB Loop */
+ {
+ video->outputMB->mb_x = ind_x; /* 5/28/01 */
+ video->mbnum = mbnum;
+ QP = QPMB[mbnum]; /* always read new QP */
+
+ if (GOB_Header_Interval)
+ video->sliceNo[mbnum] = curr_slice_counter; /* Update MB slice number */
+ else
+ video->sliceNo[mbnum] = slice_counter;
+
+ /****************************************************************************************/
+ /* MB Prediction:Put into MC macroblock, substract from currVop, put in predMB */
+ /****************************************************************************************/
+ getMotionCompensatedMB(video, ind_x, ind_y, offset);
+
+#ifndef H263_ONLY
+ if (start_packet_header)
+ {
+ slice_counter++; /* Increment slice counter */
+ video->sliceNo[mbnum] = slice_counter; /* Update MB slice number*/
+ video->header_bits -= BitstreamGetPos(bs1); /* Header Bits */
+ video->QP_prev = currVop->quantizer;
+ status = EncodeVideoPacketHeader(video, mbnum, video->QP_prev, 0);
+ video->header_bits += BitstreamGetPos(bs1); /* Header Bits */
+ numHeaderBits = BitstreamGetPos(bs1);
+ start_packet_header = 0;
+ video->usePrevQP = 0;
+ }
+#endif
+ /***********************************************/
+ /* Code_MB: DCT, Q, Q^(-1), IDCT, Motion Comp */
+ /***********************************************/
+
+ status = (*CodeMB)(video, &fastDCTfunction, (offset << 5) + QP, ncoefblck);
+
+ /************************************/
+ /* MB VLC Encode: VLC Encode MB */
+ /************************************/
+
+ (*MBVlcEncode)(video, ncoefblck, (void*)BlockCodeCoeff);
+
+ /*************************************************************/
+ /* Assemble Packets: Assemble the MB VLC codes into Packets */
+ /*************************************************************/
+
+ /* Assemble_Packet(video) */
+#ifndef H263_ONLY
+ if (!currVol->shortVideoHeader) /* Not in ShortVideoHeader mode */
+ {
+ if (!currVol->ResyncMarkerDisable) /* RESYNC MARKER MODE */
+ {
+ num_bits = BitstreamGetPos(bs1) - numHeaderBits;
+ if (num_bits > packet_size)
+ {
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1); /* Byte align Packet */
+
+ status = BitstreamAppendPacket(currVol->stream, bs1); /* Put Packet to Buffer */
+ /* continue even if status == PV_END_OF_BUF, to get the stats */
+
+ BitstreamEncReset(bs1);
+
+ start_packet_header = 1;
+ }
+ }
+ else /* NO RESYNC MARKER MODE */
+ {
+ status = BitstreamAppendEnc(currVol->stream, bs1); /* Initialize to 0 */
+ /* continue even if status == PV_END_OF_BUF, to get the stats */
+
+ BitstreamEncReset(bs1);
+ }
+ }
+ else
+#endif /* H263_ONLY */
+ { /* ShortVideoHeader Mode */
+ status = BitstreamAppendEnc(currVol->stream, bs1); /* Initialize to 0 */
+ /* continue even if status == PV_END_OF_BUF, to get the stats */
+
+ BitstreamEncReset(bs1);
+ }
+ mbnum++;
+ offset += 16;
+ } /* End of For ind_x */
+
+ offset += (lx << 4) - width;
+ if (currVol->shortVideoHeader) /* ShortVideoHeader = 1 */
+ {
+
+ if (GOB_Header_Interval) slice_counter++;
+ }
+
+ } /* End of For ind_y */
+
+ if (currVol->shortVideoHeader) /* ShortVideoHeader = 1 */
+ {
+
+ video->header_bits += BitstreamShortHeaderByteAlignStuffing(currVol->stream); /* Byte Align */
+ }
+#ifndef H263_ONLY
+ else /* Combined Mode*/
+ {
+ if (!currVol->ResyncMarkerDisable) /* Resync Markers */
+ {
+
+ if (!start_packet_header)
+ {
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1);/* Byte Align */
+
+ status = BitstreamAppendPacket(currVol->stream, bs1); /* Put Packet to Buffer */
+ /* continue even if status == PV_END_OF_BUF, to get the stats */
+
+ BitstreamEncReset(bs1);
+ }
+ }
+ else /* No Resync Markers */
+ {
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(currVol->stream); /* Byte Align */
+ }
+ }
+#endif /* H263_ONLY */
+
+ return status; /* if status == PV_END_OF_BUF, this frame will be pre-skipped */
+}
+
+#ifndef NO_SLICE_ENCODE
+/* ======================================================================== */
+/* Function : EncodeSliceCombinedMode() */
+/* Date : 04/19/2002 */
+/* History : */
+/* Purpose : Encode a slice of MPEG4 bitstream in Combined mode and save */
+/* the current MB to continue next time it is called. */
+/* In/out : */
+/* Return : PV_SUCCESS if successful else PV_FAIL */
+/* Modified : */
+/* */
+/* ======================================================================== */
+PV_STATUS EncodeSliceCombinedMode(VideoEncData *video)
+{
+ PV_STATUS status = PV_SUCCESS;
+ Vol *currVol = video->vol[video->currLayer];
+ Vop *currVop = video->currVop;
+ UChar mode = MODE_INTRA;
+ UChar *Mode = video->headerInfo.Mode;
+ VideoEncParams *encParams = video->encParams;
+ Int nTotalMB = currVol->nTotalMB;
+ Int width = currVop->width; /* has to be Vop, for multiple of 16 */
+ Int lx = currVop->pitch; /* , with padding */
+// rateControl *rc = encParams->rc[video->currLayer];
+ UChar *QPMB = video->QPMB;
+ Int QP;
+ Int ind_x = video->outputMB->mb_x, ind_y = video->outputMB->mb_y;
+ Int offset = video->offset; /* get current MB location */
+ Int mbnum = video->mbnum, slice_counter = video->sliceNo[mbnum]; /* get current MB location */
+ Int firstMB = mbnum;
+ Int start_packet_header = 0;
+ Int num_bits = 0;
+ Int packet_size = encParams->ResyncPacketsize - 1;
+ Int resync_marker = ((!currVol->shortVideoHeader) && (!currVol->ResyncMarkerDisable));
+ BitstreamEncVideo *bs1 = video->bitstream1;
+ Int byteCount = 0, byteCount1 = 0, bitCount = 0;
+ Int numHeaderBits = 0;
+ approxDCT fastDCTfunction;
+ Int ncoefblck[6] = {64, 64, 64, 64, 64, 64}; /* for FastCodeMB, 5/18/2001 */
+ UChar CBP = 0;
+ Short outputMB[6][64];
+ Int k;
+ PV_STATUS(*CodeMB)(VideoEncData *, approxDCT *, Int, Int[]);
+ void (*MBVlcEncode)(VideoEncData*, Int[], void *);
+ void (*BlockCodeCoeff)(RunLevelBlock*, BitstreamEncVideo*, Int, Int, UChar);
+
+ video->QP_prev = 31;
+
+#define H263_GOB_CHANGES
+
+
+ if (video->end_of_buf) /* left-over from previous run */
+ {
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+ if (status != PV_END_OF_BUF)
+ {
+ BitstreamEncReset(bs1);
+ video->end_of_buf = 0;
+ }
+ return status;
+ }
+
+
+ if (mbnum == 0) /* only do this at the start of a frame */
+ {
+ QPMB[0] = video->QP_prev = QP = currVop->quantizer;
+ video->usePrevQP = 0;
+
+ numHeaderBits = BitstreamGetPos(bs1);
+ }
+
+ /* Re-assign fast functions on every slice, don't have to put it in the memory */
+ QP = QPMB[mbnum];
+ if (mbnum > 0) video->QP_prev = QPMB[mbnum-1];
+
+ /* determine type of quantization */
+#ifndef NO_MPEG_QUANT
+ if (currVol->quantType == 0)
+ CodeMB = &CodeMB_H263;
+ else
+ CodeMB = &CodeMB_MPEG;
+#else
+ CodeMB = &CodeMB_H263;
+#endif
+
+ /* determine which functions to be used, in MB-level */
+ if (currVop->predictionType == P_VOP)
+ MBVlcEncode = &MBVlcEncodeCombined_P_VOP;
+ else if (currVop->predictionType == I_VOP)
+ MBVlcEncode = &MBVlcEncodeCombined_I_VOP;
+ else /* B_VOP not implemented yet */
+ return PV_FAIL;
+
+ /* determine which VLC table to be used */
+#ifndef H263_ONLY
+ if (currVol->shortVideoHeader)
+ BlockCodeCoeff = &BlockCodeCoeff_ShortHeader;
+#ifndef NO_RVLC
+ else if (currVol->useReverseVLC)
+ BlockCodeCoeff = &BlockCodeCoeff_RVLC;
+#endif
+ else
+ BlockCodeCoeff = &BlockCodeCoeff_Normal;
+#else
+ BlockCodeCoeff = &BlockCodeCoeff_ShortHeader;
+#endif
+
+ /* (gob_frame_id is the same for different vop types) The reason should be SCD */
+ if (currVol->shortVideoHeader && currVop->gobFrameID != currVop->predictionType)
+ currVop->gobFrameID = currVop->predictionType;
+
+
+ if (mbnum != 0)
+ {
+ if (currVol->shortVideoHeader)
+ {
+ /* Encode GOB Header */
+ bitCount = BitstreamGetPos(bs1);
+ byteCount1 = byteCount = bitCount >> 3; /* save the position before GOB header */
+ bitCount = bitCount & 0x7;
+
+#ifdef H263_GOB_CHANGES
+ video->header_bits -= BitstreamGetPos(bs1); /* Header Bits */
+ status = EncodeGOBHeader(video, slice_counter, QP, 1); //ind_y /* Encode GOB Header */
+ video->header_bits += BitstreamGetPos(bs1); /* Header Bits */
+#endif
+ goto JUMP_IN_SH;
+ }
+ else if (currVol->ResyncMarkerDisable)
+ {
+ goto JUMP_IN_SH;
+ }
+ else
+ {
+ start_packet_header = 1;
+ goto JUMP_IN;
+ }
+ }
+
+ for (ind_y = 0; ind_y < currVol->nMBPerCol; ind_y++) /* Col MB Loop */
+ {
+
+ video->outputMB->mb_y = ind_y; /* 5/28/01, do not remove */
+
+ for (ind_x = 0; ind_x < currVol->nMBPerRow; ind_x++) /* Row MB Loop */
+ {
+
+ video->outputMB->mb_x = ind_x; /* 5/28/01, do not remove */
+ video->mbnum = mbnum;
+ video->sliceNo[mbnum] = slice_counter; /* Update MB slice number */
+JUMP_IN_SH:
+ /****************************************************************************************/
+ /* MB Prediction:Put into MC macroblock, substract from currVop, put in predMB */
+ /****************************************************************************************/
+ getMotionCompensatedMB(video, ind_x, ind_y, offset);
+
+JUMP_IN:
+ QP = QPMB[mbnum]; /* always read new QP */
+#ifndef H263_ONLY
+ if (start_packet_header)
+ {
+ slice_counter++; /* Increment slice counter */
+ video->sliceNo[mbnum] = slice_counter; /* Update MB slice number*/
+ video->QP_prev = currVop->quantizer; /* store QP */
+ num_bits = BitstreamGetPos(bs1);
+ status = EncodeVideoPacketHeader(video, mbnum, video->QP_prev, 1);
+ numHeaderBits = BitstreamGetPos(bs1) - num_bits;
+ video->header_bits += numHeaderBits; /* Header Bits */
+ start_packet_header = 0;
+ video->usePrevQP = 0;
+ }
+ else /* don't encode the first MB in packet again */
+#endif /* H263_ONLY */
+ {
+ /***********************************************/
+ /* Code_MB: DCT, Q, Q^(-1), IDCT, Motion Comp */
+ /***********************************************/
+ status = (*CodeMB)(video, &fastDCTfunction, (offset << 5) + QP, ncoefblck);
+ }
+
+ /************************************/
+ /* MB VLC Encode: VLC Encode MB */
+ /************************************/
+
+ /* save the state before VLC encoding */
+ if (resync_marker)
+ {
+ bitCount = BitstreamGetPos(bs1);
+ byteCount = bitCount >> 3; /* save the state before encoding */
+ bitCount = bitCount & 0x7;
+ mode = Mode[mbnum];
+ CBP = video->headerInfo.CBP[mbnum];
+ for (k = 0; k < 6; k++)
+ {
+ M4VENC_MEMCPY(outputMB[k], video->outputMB->block[k], sizeof(Short) << 6);
+ }
+ }
+ /*************************************/
+
+ (*MBVlcEncode)(video, ncoefblck, (void*)BlockCodeCoeff);
+
+ /*************************************************************/
+ /* Assemble Packets: Assemble the MB VLC codes into Packets */
+ /*************************************************************/
+
+ /* Assemble_Packet(video) */
+#ifndef H263_ONLY
+ if (!currVol->shortVideoHeader)
+ {
+ if (!currVol->ResyncMarkerDisable)
+ {
+ /* Not in ShortVideoHeader mode and RESYNC MARKER MODE */
+
+ num_bits = BitstreamGetPos(bs1) ;//- numHeaderBits; // include header
+
+ /* Assemble packet and return when size reached */
+ if (num_bits > packet_size && mbnum != firstMB)
+ {
+
+ BitstreamRepos(bs1, byteCount, bitCount); /* rewind one MB */
+
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1); /* Byte align Packet */
+
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1); /* Put Packet to Buffer */
+
+ if (status == PV_END_OF_BUF)
+ {
+ video->end_of_buf = 1;
+ }
+ else
+ {
+ BitstreamEncReset(bs1);
+ }
+
+ start_packet_header = 1;
+
+ if (mbnum < nTotalMB || video->end_of_buf) /* return here */
+ {
+ video->mbnum = mbnum;
+ video->sliceNo[mbnum] = slice_counter;
+ video->offset = offset;
+ Mode[mbnum] = mode;
+ video->headerInfo.CBP[mbnum] = CBP;
+
+ for (k = 0; k < 6; k++)
+ {
+ M4VENC_MEMCPY(video->outputMB->block[k], outputMB[k], sizeof(Short) << 6);
+ }
+
+ return status;
+ }
+ }
+ }
+ else /* NO RESYNC MARKER , return when buffer is full*/
+ {
+
+ if (mbnum < nTotalMB - 1 && currVol->stream->byteCount + bs1->byteCount + 1 >= currVol->stream->bufferSize)
+ {
+ /* find maximum bytes to fit in the buffer */
+ byteCount = currVol->stream->bufferSize - currVol->stream->byteCount - 1;
+
+ num_bits = BitstreamGetPos(bs1) - (byteCount << 3);
+ BitstreamRepos(bs1, byteCount, 0);
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+ BitstreamFlushBits(bs1, num_bits);
+
+ /* move on to next MB */
+ mbnum++ ;
+ offset += 16;
+ video->outputMB->mb_x++;
+ if (video->outputMB->mb_x >= currVol->nMBPerRow)
+ {
+ video->outputMB->mb_x = 0;
+ video->outputMB->mb_y++;
+ offset += (lx << 4) - width;
+ }
+ video->mbnum = mbnum;
+ video->offset = offset;
+ video->sliceNo[mbnum] = slice_counter;
+ return status;
+ }
+ }
+ }
+#endif /* H263_ONLY */
+ offset += 16;
+ mbnum++; /* has to increment before SCD, to preserve Mode[mbnum] */
+
+ } /* End of For ind_x */
+
+ offset += (lx << 4) - width;
+
+ if (currVol->shortVideoHeader) /* ShortVideoHeader = 1 */
+ {
+#ifdef H263_GOB_CHANGES
+ slice_counter++;
+ video->header_bits += BitstreamShortHeaderByteAlignStuffing(bs1);
+#endif
+ //video->header_bits+=BitstreamShortHeaderByteAlignStuffing(bs1);
+
+ /* check if time to packetize */
+ if (currVol->stream->byteCount + bs1->byteCount > currVol->stream->bufferSize)
+ {
+ if (byteCount == byteCount1) /* a single GOB bigger than packet size */
+ {
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+ status = PV_END_OF_BUF;
+ video->end_of_buf = 1;
+ start_packet_header = 1;
+ }
+ else /* for short_header scooch back to previous GOB */
+ {
+ num_bits = ((bs1->byteCount - byteCount) << 3);
+ //num_bits = ((bs1->byteCount<<3) + bs1->bitCount) - ((byteCount<<3) + bitCount);
+ BitstreamRepos(bs1, byteCount, 0);
+ //BitstreamRepos(bs1,byteCount,bitCount);
+// k = currVol->stream->byteCount; /* save state before appending */
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+ BitstreamFlushBits(bs1, num_bits);
+// if(mbnum == nTotalMB || k + bs1->byteCount >= currVol->stream->bufferSize){
+ /* last GOB or current one with larger size will be returned next run */
+// status = PV_END_OF_BUF;
+// video->end_of_buf = 1;
+// }
+ start_packet_header = 1;
+ if (mbnum == nTotalMB) /* there's one more GOB to packetize for the next round */
+ {
+ status = PV_END_OF_BUF;
+ video->end_of_buf = 1;
+ }
+ }
+
+ if (mbnum < nTotalMB) /* return here */
+ {
+ /* move on to next MB */
+ video->outputMB->mb_x = 0;
+ video->outputMB->mb_y++;
+ video->mbnum = mbnum;
+ video->offset = offset;
+ video->sliceNo[mbnum] = slice_counter;
+ return status;
+ }
+ }
+ else if (mbnum < nTotalMB) /* do not write GOB header if end of vop */
+ {
+ bitCount = BitstreamGetPos(bs1);
+ byteCount = bitCount >> 3; /* save the position before GOB header */
+ bitCount = bitCount & 0x7;
+#ifdef H263_GOB_CHANGES
+ video->header_bits -= BitstreamGetPos(bs1); /* Header Bits */
+ status = EncodeGOBHeader(video, slice_counter, QP, 1); /* Encode GOB Header */
+ video->header_bits += BitstreamGetPos(bs1); /* Header Bits */
+#endif
+ }
+ }
+
+ } /* End of For ind_y */
+#ifndef H263_ONLY
+ if (!currVol->shortVideoHeader) /* Combined Mode*/
+ {
+ if (!currVol->ResyncMarkerDisable) /* Resync Markers */
+ {
+
+ if (!start_packet_header)
+ {
+
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1);/* Byte Align */
+
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1); /* Put Packet to Buffer */
+ if (status == PV_END_OF_BUF)
+ {
+ video->end_of_buf = 1;
+ }
+ else
+ {
+ BitstreamEncReset(bs1);
+ }
+ }
+ }
+ else /* No Resync Markers */
+ {
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1); /* Byte Align */
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1); /* Initialize to 0 */
+ if (status == PV_END_OF_BUF)
+ {
+ video->end_of_buf = 1;
+ }
+ else
+ {
+ BitstreamEncReset(bs1);
+ }
+ }
+ }
+ else
+#endif /* H263_ONLY */
+ {
+ if (!start_packet_header) /* not yet packetized */
+ {
+ video->header_bits += BitstreamShortHeaderByteAlignStuffing(bs1);
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+ if (status == PV_END_OF_BUF)
+ {
+ video->end_of_buf = 1;
+ }
+ else
+ {
+ BitstreamEncReset(bs1);
+ video->end_of_buf = 0;
+ }
+ }
+ }
+
+ video->mbnum = mbnum;
+ if (mbnum < nTotalMB)
+ video->sliceNo[mbnum] = slice_counter;
+ video->offset = offset;
+
+ return status;
+}
+#endif /* NO_SLICE_ENCODE */
+
+/* ======================================================================== */
+/* Function : EncodeGOBHeader() */
+/* Date : 09/05/2000 */
+/* History : */
+/* Purpose : Encode a frame of MPEG4 bitstream in Combined mode. */
+/* In/out : */
+/* Return : PV_SUCCESS if successful else PV_FAIL */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+PV_STATUS EncodeGOBHeader(VideoEncData *video, Int GOB_number, Int quant_scale, Int bs1stream)
+{
+ PV_STATUS status = PV_SUCCESS;
+ BitstreamEncVideo *stream = (bs1stream ? video->bitstream1 : video->vol[video->currLayer]->stream);
+
+ status = BitstreamPutGT16Bits(stream, 17, GOB_RESYNC_MARKER); /* gob_resync_marker */
+ status = BitstreamPutBits(stream, 5, GOB_number); /* Current gob_number */
+ status = BitstreamPutBits(stream, 2, video->currVop->gobFrameID); /* gob_frame_id */
+ status = BitstreamPutBits(stream, 5, quant_scale); /* quant_scale */
+ return status;
+}
+
+
diff --git a/media/codecs/m4v_h263/enc/src/datapart_encode.cpp b/media/codecs/m4v_h263/enc/src/datapart_encode.cpp
new file mode 100644
index 0000000..16c8e79
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/datapart_encode.cpp
@@ -0,0 +1,482 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef H263_ONLY
+
+#include "mp4def.h"
+#include "mp4lib_int.h"
+#include "bitstream_io.h"
+#include "mp4enc_lib.h"
+#include "m4venc_oscl.h"
+
+/* ======================================================================== */
+/* Function : EncodeFrameDataPartMode() */
+/* Date : 09/6/2000 */
+/* History : */
+/* Purpose : Encode a frame of MPEG4 bitstream in datapartitioning mode. */
+/* In/out : */
+/* Return : PV_SUCCESS if successful else PV_FAIL */
+/* Modified : */
+/* */
+/* ======================================================================== */
+PV_STATUS EncodeFrameDataPartMode(VideoEncData *video)
+{
+ PV_STATUS status = PV_SUCCESS;
+ Vol *currVol = video->vol[video->currLayer];
+ Vop *currVop = video->currVop;
+ VideoEncParams *encParams = video->encParams;
+ Int width = currVop->width; /* has to be Vop, for multiple of 16 */
+ Int lx = currVop->pitch; /* with padding */
+ Int offset = 0;
+ Int ind_x, ind_y;
+ Int start_packet_header = 0;
+ UChar *QPMB = video->QPMB;
+ Int QP;
+ Int mbnum = 0, slice_counter = 0;
+ Int num_bits, packet_size = encParams->ResyncPacketsize;
+ BitstreamEncVideo *bs1 = video->bitstream1;
+ BitstreamEncVideo *bs2 = video->bitstream2;
+ BitstreamEncVideo *bs3 = video->bitstream3;
+ Int numHeaderBits;
+ approxDCT fastDCTfunction;
+ Int ncoefblck[6] = {64, 64, 64, 64, 64, 64}; /* for FastCodeMB, 5/18/2001 */
+ PV_STATUS(*CodeMB)(VideoEncData *, approxDCT *, Int, Int[]);
+ void (*MBVlcEncode)(VideoEncData*, Int[], void *);
+ void (*BlockCodeCoeff)(RunLevelBlock*, BitstreamEncVideo*, Int, Int, UChar);
+
+ video->QP_prev = currVop->quantizer;
+
+ numHeaderBits = BitstreamGetPos(bs1); /* Number of bits in VOP Header */
+
+ /* determine type of quantization */
+#ifndef NO_MPEG_QUANT
+ if (currVol->quantType == 0)
+ CodeMB = &CodeMB_H263;
+ else
+ CodeMB = &CodeMB_MPEG;
+#else
+ CodeMB = &CodeMB_H263;
+#endif
+
+ /* determine which functions to be used, in MB-level */
+ if (currVop->predictionType == P_VOP)
+ MBVlcEncode = &MBVlcEncodeDataPar_P_VOP;
+ else if (currVop->predictionType == I_VOP)
+ MBVlcEncode = &MBVlcEncodeDataPar_I_VOP;
+ else /* B_VOP not implemented yet */
+ return PV_FAIL;
+
+ /* determine which VLC table to be used */
+ if (currVol->shortVideoHeader)
+ BlockCodeCoeff = &BlockCodeCoeff_ShortHeader;
+#ifndef NO_RVLC
+ else if (currVol->useReverseVLC)
+ BlockCodeCoeff = &BlockCodeCoeff_RVLC;
+#endif
+ else
+ BlockCodeCoeff = &BlockCodeCoeff_Normal;
+
+ video->usePrevQP = 0;
+
+ for (ind_y = 0; ind_y < currVol->nMBPerCol; ind_y++) /* Col MB Loop */
+ {
+
+ video->outputMB->mb_y = ind_y; /* 5/28/01 */
+
+ for (ind_x = 0; ind_x < currVol->nMBPerRow; ind_x++) /* Row MB Loop */
+ {
+ video->outputMB->mb_x = ind_x; /* 5/28/01 */
+ video->mbnum = mbnum;
+ video->sliceNo[mbnum] = slice_counter; /* Update MB slice number */
+ QP = QPMB[mbnum]; /* always read new QP */
+
+ /****************************************************************************************/
+ /* MB Prediction:Put into MC macroblock, substract from currVop, put in predMB */
+ /****************************************************************************************/
+
+ getMotionCompensatedMB(video, ind_x, ind_y, offset);
+
+ if (start_packet_header)
+ {
+ slice_counter++; /* Increment slice counter */
+ video->sliceNo[mbnum] = slice_counter; /* Update MB slice number*/
+ video->header_bits -= BitstreamGetPos(bs1); /* Header Bits */
+ video->QP_prev = currVop->quantizer; /* store QP */
+ status = EncodeVideoPacketHeader(video, mbnum, video->QP_prev, 0);
+ video->header_bits += BitstreamGetPos(bs1); /* Header Bits */
+ numHeaderBits = BitstreamGetPos(bs1);
+ start_packet_header = 0;
+ video->usePrevQP = 0;
+ }
+
+ /***********************************************/
+ /* Code_MB: DCT, Q, Q^(-1), IDCT, Motion Comp */
+ /***********************************************/
+
+ status = (*CodeMB)(video, &fastDCTfunction, (offset << 5) + QP, ncoefblck);
+
+ /************************************/
+ /* MB VLC Encode: VLC Encode MB */
+ /************************************/
+
+ MBVlcEncode(video, ncoefblck, (void*)BlockCodeCoeff);
+
+ /*************************************************************/
+ /* Assemble Packets: Assemble the MB VLC codes into Packets */
+ /*************************************************************/
+
+ /* INCLUDE VOP HEADER IN COUNT */
+
+ num_bits = BitstreamGetPos(bs1) + BitstreamGetPos(bs2) +
+ BitstreamGetPos(bs3) - numHeaderBits;
+
+ /* Assemble_Packet(video) */
+
+ if (num_bits > packet_size)
+ {
+ if (video->currVop->predictionType == I_VOP)
+ BitstreamPutGT16Bits(bs1, 19, DC_MARKER); /* Add dc_marker */
+ else
+ BitstreamPutGT16Bits(bs1, 17, MOTION_MARKER_COMB); /*Add motion_marker*/
+ BitstreamAppendEnc(bs1, bs2); /* Combine bs1 and bs2 */
+ BitstreamAppendEnc(bs1, bs3); /* Combine bs1 and bs3 */
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1); /* Byte align Packet */
+
+ status = BitstreamAppendPacket(currVol->stream, bs1); /* Put Packet to Buffer */
+ /* continue even if status == PV_END_OF_BUF, to get the stats */
+
+ BitstreamEncReset(bs1); /* Initialize to 0 */
+ BitstreamEncReset(bs2);
+ BitstreamEncReset(bs3);
+ start_packet_header = 1;
+ }
+ mbnum++;
+ offset += 16;
+ } /* End of For ind_x */
+
+ offset += (lx << 4) - width;
+ } /* End of For ind_y */
+
+ if (!start_packet_header)
+ {
+ if (video->currVop->predictionType == I_VOP)
+ {
+ BitstreamPutGT16Bits(bs1, 19, DC_MARKER); /* Add dc_marker */
+ video->header_bits += 19;
+ }
+ else
+ {
+ BitstreamPutGT16Bits(bs1, 17, MOTION_MARKER_COMB); /* Add motion_marker */
+ video->header_bits += 17;
+ }
+ BitstreamAppendEnc(bs1, bs2);
+ BitstreamAppendEnc(bs1, bs3);
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1); /* Byte align Packet */
+ status = BitstreamAppendPacket(currVol->stream, bs1); /* Put Packet to Buffer */
+ /* continue even if status == PV_END_OF_BUF, to get the stats */
+ BitstreamEncReset(bs1); /* Initialize to 0 */
+ BitstreamEncReset(bs2);
+ BitstreamEncReset(bs3);
+ }
+
+ return status; /* if status == PV_END_OF_BUF, this frame will be pre-skipped */
+}
+
+#ifndef NO_SLICE_ENCODE
+/* ======================================================================== */
+/* Function : EncodeSliceDataPartMode() */
+/* Date : 04/19/2002 */
+/* History : */
+/* Purpose : Encode a slice of MPEG4 bitstream in DataPar mode and save */
+/* the current MB to continue next time it is called. */
+/* In/out : */
+/* Return : PV_SUCCESS if successful else PV_FAIL */
+/* Modified : */
+/* */
+/* ======================================================================== */
+PV_STATUS EncodeSliceDataPartMode(VideoEncData *video)
+{
+ PV_STATUS status = PV_SUCCESS;
+ Vol *currVol = video->vol[video->currLayer];
+ Vop *currVop = video->currVop;
+ UChar mode, *Mode = video->headerInfo.Mode;
+ VideoEncParams *encParams = video->encParams;
+ Int nTotalMB = currVol->nTotalMB;
+ Int width = currVop->width; /* has to be Vop, for multiple of 16 */
+ Int lx = currVop->pitch; /* , with pading */
+ UChar *QPMB = video->QPMB;
+ Int QP;
+ Int ind_x = video->outputMB->mb_x, ind_y = video->outputMB->mb_y;
+ Int offset = video->offset; /* get current MB location */
+ Int mbnum = video->mbnum, slice_counter = video->sliceNo[mbnum]; /* get current MB location */
+ Int firstMB = mbnum;
+ Int start_packet_header = (mbnum != 0);
+ Int num_bits = 0;
+ Int packet_size = encParams->ResyncPacketsize - 1 - (currVop->predictionType == I_VOP ? 19 : 17);
+ BitstreamEncVideo *bs1 = video->bitstream1;
+ BitstreamEncVideo *bs2 = video->bitstream2;
+ BitstreamEncVideo *bs3 = video->bitstream3;
+ Int bitCount1 = 0, bitCount2 = 0, bitCount3 = 0, byteCount1 = 0, byteCount2 = 0, byteCount3 = 0;
+ Int numHeaderBits = 0;
+ approxDCT fastDCTfunction;
+ Int ncoefblck[6] = {64, 64, 64, 64, 64, 64}; /* for FastCodeMB, 5/18/2001 */
+ UChar CBP;
+ Short outputMB[6][64];
+ PV_STATUS(*CodeMB)(VideoEncData *, approxDCT *, Int, Int[]);
+ void (*MBVlcEncode)(VideoEncData*, Int[], void *);
+ void (*BlockCodeCoeff)(RunLevelBlock*, BitstreamEncVideo*, Int, Int, UChar);
+ Int k;
+
+ video->QP_prev = 31;
+
+ if (video->end_of_buf) /* left-over from previous run */
+ {
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+ if (status != PV_END_OF_BUF)
+ {
+ BitstreamEncReset(bs1);
+ video->end_of_buf = 0;
+ }
+ return status;
+ }
+
+ if (mbnum == 0) /* only do this at the start of a frame */
+ {
+ QPMB[0] = video->QP_prev = QP = currVop->quantizer;
+ video->usePrevQP = 0;
+
+ numHeaderBits = BitstreamGetPos(bs1); /* Number of bits in VOP Header */
+
+ }
+
+
+ /* Re-assign fast functions on every slice, don't have to put it in the memory */
+ QP = QPMB[mbnum];
+ if (mbnum > 0) video->QP_prev = QPMB[mbnum-1];
+
+ /* determine type of quantization */
+#ifndef NO_MPEG_QUANT
+ if (currVol->quantType == 0)
+ CodeMB = &CodeMB_H263;
+ else
+ CodeMB = &CodeMB_MPEG;
+#else
+ CodeMB = &CodeMB_H263;
+#endif
+
+ /* determine which functions to be used, in MB-level */
+ if (currVop->predictionType == P_VOP)
+ MBVlcEncode = &MBVlcEncodeDataPar_P_VOP;
+ else if (currVop->predictionType == I_VOP)
+ MBVlcEncode = &MBVlcEncodeDataPar_I_VOP;
+ else /* B_VOP not implemented yet */
+ return PV_FAIL;
+
+ /* determine which VLC table to be used */
+#ifndef NO_RVLC
+ if (currVol->useReverseVLC)
+ BlockCodeCoeff = &BlockCodeCoeff_RVLC;
+ else
+#endif
+ BlockCodeCoeff = &BlockCodeCoeff_Normal;
+
+ if (mbnum != 0)
+ {
+ goto JUMP_IN;
+ }
+
+ for (ind_y = 0; ind_y < currVol->nMBPerCol; ind_y++) /* Col MB Loop */
+ {
+
+ video->outputMB->mb_y = ind_y; /* 5/28/01 */
+
+ for (ind_x = 0; ind_x < currVol->nMBPerRow; ind_x++) /* Row MB Loop */
+ {
+
+ video->outputMB->mb_x = ind_x; /* 5/28/01 */
+ video->mbnum = mbnum;
+ video->sliceNo[mbnum] = slice_counter; /* Update MB slice number */
+
+ /****************************************************************************************/
+ /* MB Prediction:Put into MC macroblock, substract from currVop, put in predMB */
+ /****************************************************************************************/
+ getMotionCompensatedMB(video, ind_x, ind_y, offset);
+
+JUMP_IN:
+
+ QP = QPMB[mbnum]; /* always read new QP */
+
+ if (start_packet_header)
+ {
+ slice_counter++; /* Increment slice counter */
+ video->sliceNo[mbnum] = slice_counter; /* Update MB slice number*/
+ video->QP_prev = currVop->quantizer; /* store QP */
+ num_bits = BitstreamGetPos(bs1);
+ status = EncodeVideoPacketHeader(video, mbnum, video->QP_prev, 0);
+ numHeaderBits = BitstreamGetPos(bs1) - num_bits;
+ video->header_bits += numHeaderBits; /* Header Bits */
+ start_packet_header = 0;
+ video->usePrevQP = 0;
+ }
+ else /* don't encode the first MB in packet again */
+ {
+ /***********************************************/
+ /* Code_MB: DCT, Q, Q^(-1), IDCT, Motion Comp */
+ /***********************************************/
+
+ status = (*CodeMB)(video, &fastDCTfunction, (offset << 5) + QP, ncoefblck);
+ for (k = 0; k < 6; k++)
+ {
+ M4VENC_MEMCPY(outputMB[k], video->outputMB->block[k], sizeof(Short) << 6);
+ }
+ }
+
+ /************************************/
+ /* MB VLC Encode: VLC Encode MB */
+ /************************************/
+
+ /* save the state before VLC encoding */
+ bitCount1 = BitstreamGetPos(bs1);
+ bitCount2 = BitstreamGetPos(bs2);
+ bitCount3 = BitstreamGetPos(bs3);
+ byteCount1 = bitCount1 >> 3;
+ byteCount2 = bitCount2 >> 3;
+ byteCount3 = bitCount3 >> 3;
+ bitCount1 &= 0x7;
+ bitCount2 &= 0x7;
+ bitCount3 &= 0x7;
+ mode = Mode[mbnum];
+ CBP = video->headerInfo.CBP[mbnum];
+
+ /*************************************/
+
+ MBVlcEncode(video, ncoefblck, (void*)BlockCodeCoeff);
+
+ /*************************************************************/
+ /* Assemble Packets: Assemble the MB VLC codes into Packets */
+ /*************************************************************/
+
+ num_bits = BitstreamGetPos(bs1) + BitstreamGetPos(bs2) +
+ BitstreamGetPos(bs3);// - numHeaderBits; //include header bits
+
+ /* Assemble_Packet(video) */
+ if (num_bits > packet_size && mbnum != firstMB) /* encoding at least one more MB*/
+ {
+
+ BitstreamRepos(bs1, byteCount1, bitCount1); /* rewind one MB */
+ BitstreamRepos(bs2, byteCount2, bitCount2); /* rewind one MB */
+ BitstreamRepos(bs3, byteCount3, bitCount3); /* rewind one MB */
+
+ if (video->currVop->predictionType == I_VOP)
+ {
+ BitstreamPutGT16Bits(bs1, 19, DC_MARKER); /* Add dc_marker */
+ video->header_bits += 19;
+ }
+ else
+ {
+ BitstreamPutGT16Bits(bs1, 17, MOTION_MARKER_COMB); /*Add motion_marker*/
+ video->header_bits += 17;
+ }
+
+ status = BitstreamAppendEnc(bs1, bs2); /* Combine with bs2 */
+ status = BitstreamAppendEnc(bs1, bs3); /* Combine with bs3 */
+
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1); /* Byte align Packet */
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+
+ BitstreamEncReset(bs2);
+ BitstreamEncReset(bs3);
+
+ if (status == PV_END_OF_BUF) /* if cannot fit a buffer */
+ {
+ video->end_of_buf = 1;
+ }
+ else
+ {
+ BitstreamEncReset(bs1);
+ }
+
+ start_packet_header = 1;
+
+ if (mbnum < nTotalMB || video->end_of_buf) /* return here */
+ {
+ video->mbnum = mbnum;
+ video->sliceNo[mbnum] = slice_counter;
+ video->offset = offset;
+ Mode[mbnum] = mode;
+ video->headerInfo.CBP[mbnum] = CBP;
+
+ for (k = 0; k < 6; k++)
+ {
+ M4VENC_MEMCPY(video->outputMB->block[k], outputMB[k], sizeof(Short) << 6);
+ }
+
+ return status;
+ }
+ }
+
+ offset += 16;
+ mbnum++; /* has to increment before SCD, to preserve Mode[mbnum] */
+ } /* End of For ind_x */
+
+ offset += (lx << 4) - width;
+
+ } /* End of For ind_y */
+
+ if (!start_packet_header)
+ {
+ if (video->currVop->predictionType == I_VOP)
+ {
+ BitstreamPutGT16Bits(bs1, 19, DC_MARKER); /* Add dc_marker */
+ video->header_bits += 19;
+ }
+ else
+ {
+ BitstreamPutGT16Bits(bs1, 17, MOTION_MARKER_COMB); /*Add motion_marker*/
+ video->header_bits += 17;
+ }
+
+ status = BitstreamAppendEnc(bs1, bs2); /* Combine with bs2 */
+ status = BitstreamAppendEnc(bs1, bs3); /* Combine with bs3 */
+
+ video->header_bits += BitstreamMpeg4ByteAlignStuffing(bs1); /* Byte align Packet */
+ status = BitstreamAppendPacketNoOffset(currVol->stream, bs1);
+
+ BitstreamEncReset(bs2);
+ BitstreamEncReset(bs3);
+
+ if (status == PV_END_OF_BUF)
+ {
+ video->end_of_buf = 1;
+ }
+ else
+ {
+ BitstreamEncReset(bs1);
+ }
+ }
+
+ video->mbnum = mbnum;
+ if (mbnum < nTotalMB)
+ video->sliceNo[mbnum] = slice_counter;
+ video->offset = offset;
+
+ return status;
+}
+#endif /* NO_SLICE_ENCODE */
+#endif /* H263_ONLY */
+
+
diff --git a/media/codecs/m4v_h263/enc/src/dct.cpp b/media/codecs/m4v_h263/enc/src/dct.cpp
new file mode 100644
index 0000000..8d7d9f1
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/dct.cpp
@@ -0,0 +1,1283 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4enc_lib.h"
+#include "mp4lib_int.h"
+#include "dct_inline.h"
+
+#define FDCT_SHIFT 10
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**************************************************************************/
+ /* Function: BlockDCT_AANwSub
+ Date: 7/31/01
+ Input:
+ Output: out[64] ==> next block
+ Purpose: Do subtraction for zero MV first
+ Modified:
+ **************************************************************************/
+
+ Void BlockDCT_AANwSub(Short *out, UChar *cur, UChar *pred, Int width)
+ {
+ Short *dst;
+ Int k0, k1, k2, k3, k4, k5, k6, k7;
+ Int round;
+ Int k12 = 0x022A02D4;
+ Int k14 = 0x0188053A;
+ Int abs_sum;
+ Int mask;
+ Int tmp, tmp2;
+ Int ColTh;
+
+ dst = out + 64 ;
+ ColTh = *dst;
+ out += 128;
+ round = 1 << (FDCT_SHIFT - 1);
+
+ do /* fdct_nextrow */
+ {
+ /* assuming the block is word-aligned */
+ mask = 0x1FE;
+ tmp = *((Int*) cur); /* contains 4 pixels */
+ tmp2 = *((Int*) pred); /* prediction 4 pixels */
+ k0 = tmp2 & 0xFF;
+ k1 = mask & (tmp << 1);
+ k0 = k1 - (k0 << 1);
+ k1 = (tmp2 >> 8) & 0xFF;
+ k2 = mask & (tmp >> 7);
+ k1 = k2 - (k1 << 1);
+ k2 = (tmp2 >> 16) & 0xFF;
+ k3 = mask & (tmp >> 15);
+ k2 = k3 - (k2 << 1);
+ k3 = (tmp2 >> 24) & 0xFF;
+ k4 = mask & (tmp >> 23);
+ k3 = k4 - (k3 << 1);
+ tmp = *((Int*)(cur + 4)); /* another 4 pixels */
+ tmp2 = *((Int*)(pred + 4));
+ k4 = tmp2 & 0xFF;
+ k5 = mask & (tmp << 1);
+ k4 = k5 - (k4 << 1);
+ k5 = (tmp2 >> 8) & 0xFF;
+ k6 = mask & (tmp >> 7);
+ k5 = k6 - (k5 << 1);
+ k6 = (tmp2 >> 16) & 0xFF;
+ k7 = mask & (tmp >> 15);
+ k6 = k7 - (k6 << 1);
+ k7 = (tmp2 >> 24) & 0xFF;
+ tmp = mask & (tmp >> 23);
+ k7 = tmp - (k7 << 1);
+ cur += width;
+ pred += 16;
+
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ k1 = k0 - (k1 << 1);
+ /**********/
+ dst[0] = k0;
+ dst[4] = k1; /* col. 4 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ k3 = (k3 << 1) - k2;
+ /********/
+ dst[2] = k2; /* col. 2 */
+ k3 <<= 1; /* scale up col. 6 */
+ dst[6] = k3; /* col. 6 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k4 = k4 + k7;
+ k7 = (k7 << 1) - k4;
+ k5 = k5 + k6;
+ k4 <<= 1; /* scale up col.5 */
+ k6 = k5 - (k6 << 1);
+ /********/
+ dst[5] = k4; /* col. 5 */
+ k6 <<= 2; /* scale up col. 7 */
+ dst[1] = k5; /* col. 1 */
+ dst[7] = k6; /* col. 7 */
+ dst[3] = k7; /* col. 3 */
+ dst += 8;
+ }
+ while (dst < out);
+
+ out -= 64;
+ dst = out + 8;
+
+ /* Vertical Block Loop */
+ do /* Vertical 8xDCT loop */
+ {
+ k0 = out[0];
+ k1 = out[8];
+ k2 = out[16];
+ k3 = out[24];
+ k4 = out[32];
+ k5 = out[40];
+ k6 = out[48];
+ k7 = out[56];
+ /* deadzone thresholding for column */
+
+ abs_sum = sum_abs(k0, k1, k2, k3, k4, k5, k6, k7);
+
+ if (abs_sum < ColTh)
+ {
+ out[0] = 0x7fff;
+ out++;
+ continue;
+ }
+
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ k1 = k0 - (k1 << 1);
+ /**********/
+ out[32] = k1; /* row 4 */
+ out[0] = k0; /* row 0 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ k3 = (k3 << 1) - k2;
+ k3 <<= 1; /* scale up col. 6 */
+ /********/
+ out[48] = k3; /* row 6 */
+ out[16] = k2; /* row 2 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k4 = k4 + k7;
+ k7 = (k7 << 1) - k4;
+ k5 = k5 + k6;
+ k4 <<= 1; /* scale up col. 5 */
+ k6 = k5 - (k6 << 1);
+ /********/
+ out[24] = k7 ; /* row 3 */
+ k6 <<= 2; /* scale up col. 7 */
+ out[56] = k6 ; /* row 7 */
+ out[8] = k5 ; /* row 1 */
+ out[40] = k4 ; /* row 5 */
+ out++;
+ }
+ while ((uintptr_t)out < (uintptr_t)dst) ;
+
+ return ;
+ }
+
+ /**************************************************************************/
+ /* Function: Block4x4DCT_AANwSub
+ Date: 7/31/01
+ Input:
+ Output: out[64] ==> next block
+ Purpose: Do subtraction for zero MV first before 4x4 DCT
+ Modified:
+ **************************************************************************/
+
+ Void Block4x4DCT_AANwSub(Short *out, UChar *cur, UChar *pred, Int width)
+ {
+ Short *dst;
+ Int k0, k1, k2, k3, k4, k5, k6, k7;
+ Int round;
+ Int k12 = 0x022A02D4;
+ Int k14 = 0x0188053A;
+ Int mask;
+ Int tmp, tmp2;
+ Int abs_sum;
+ Int ColTh;
+
+ dst = out + 64 ;
+ ColTh = *dst;
+ out += 128;
+ round = 1 << (FDCT_SHIFT - 1);
+
+ do /* fdct_nextrow */
+ {
+ /* assuming the block is word-aligned */
+ mask = 0x1FE;
+ tmp = *((Int*) cur); /* contains 4 pixels */
+ tmp2 = *((Int*) pred); /* prediction 4 pixels */
+ k0 = tmp2 & 0xFF;
+ k1 = mask & (tmp << 1);
+ k0 = k1 - (k0 << 1);
+ k1 = (tmp2 >> 8) & 0xFF;
+ k2 = mask & (tmp >> 7);
+ k1 = k2 - (k1 << 1);
+ k2 = (tmp2 >> 16) & 0xFF;
+ k3 = mask & (tmp >> 15);
+ k2 = k3 - (k2 << 1);
+ k3 = (tmp2 >> 24) & 0xFF;
+ k4 = mask & (tmp >> 23);
+ k3 = k4 - (k3 << 1);
+ tmp = *((Int*)(cur + 4)); /* another 4 pixels */
+ tmp2 = *((Int*)(pred + 4));
+ k4 = tmp2 & 0xFF;
+ k5 = mask & (tmp << 1);
+ k4 = k5 - (k4 << 1);
+ k5 = (tmp2 >> 8) & 0xFF;
+ k6 = mask & (tmp >> 7);
+ k5 = k6 - (k5 << 1);
+ k6 = (tmp2 >> 16) & 0xFF;
+ k7 = mask & (tmp >> 15);
+ k6 = k7 - (k6 << 1);
+ k7 = (tmp2 >> 24) & 0xFF;
+ tmp = mask & (tmp >> 23);
+ k7 = tmp - (k7 << 1);
+ cur += width;
+ pred += 16;
+
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ dst[0] = k0;
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ /********/
+ dst[2] = k2; /* col. 2 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k7 = k7 - k4;
+ k5 = k5 + k6;
+ /********/
+ dst[1] = k5; /* col. 1 */
+ dst[3] = k7; /* col. 3 */
+ dst += 8;
+ }
+ while (dst < out);
+
+ out -= 64;
+ dst = out + 4;
+
+ /* Vertical Block Loop */
+ do /* Vertical 8xDCT loop */
+ {
+ k0 = out[0];
+ k1 = out[8];
+ k2 = out[16];
+ k3 = out[24];
+ k4 = out[32];
+ k5 = out[40];
+ k6 = out[48];
+ k7 = out[56];
+
+ abs_sum = sum_abs(k0, k1, k2, k3, k4, k5, k6, k7);
+
+ if (abs_sum < ColTh)
+ {
+ out[0] = 0x7fff;
+ out++;
+ continue;
+ }
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ out[0] = k0; /* row 0 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ /********/
+ out[16] = k2; /* row 2 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k7 = k7 - k4 ;
+ k5 = k5 + k6;
+ /********/
+ out[24] = k7 ; /* row 3 */
+ out[8] = k5 ; /* row 1 */
+ out++;
+ }
+ while ((uintptr_t)out < (uintptr_t)dst) ;
+
+ return ;
+ }
+
+ /**************************************************************************/
+ /* Function: Block2x2DCT_AANwSub
+ Date: 7/31/01
+ Input:
+ Output: out[64] ==> next block
+ Purpose: Do subtraction for zero MV first before 2x2 DCT
+ Modified:
+ **************************************************************************/
+
+
+ Void Block2x2DCT_AANwSub(Short *out, UChar *cur, UChar *pred, Int width)
+ {
+ Short *dst;
+ Int k0, k1, k2, k3, k4, k5, k6, k7;
+ Int round;
+ Int k12 = 0x022A02D4;
+ Int k14 = 0x018803B2;
+ Int mask;
+ Int tmp, tmp2;
+ Int abs_sum;
+ Int ColTh;
+
+ dst = out + 64 ;
+ ColTh = *dst;
+ out += 128;
+ round = 1 << (FDCT_SHIFT - 1);
+
+ do /* fdct_nextrow */
+ {
+ /* assuming the block is word-aligned */
+ mask = 0x1FE;
+ tmp = *((Int*) cur); /* contains 4 pixels */
+ tmp2 = *((Int*) pred); /* prediction 4 pixels */
+ k0 = tmp2 & 0xFF;
+ k1 = mask & (tmp << 1);
+ k0 = k1 - (k0 << 1);
+ k1 = (tmp2 >> 8) & 0xFF;
+ k2 = mask & (tmp >> 7);
+ k1 = k2 - (k1 << 1);
+ k2 = (tmp2 >> 16) & 0xFF;
+ k3 = mask & (tmp >> 15);
+ k2 = k3 - (k2 << 1);
+ k3 = (tmp2 >> 24) & 0xFF;
+ k4 = mask & (tmp >> 23);
+ k3 = k4 - (k3 << 1);
+ tmp = *((Int*)(cur + 4)); /* another 4 pixels */
+ tmp2 = *((Int*)(pred + 4));
+ k4 = tmp2 & 0xFF;
+ k5 = mask & (tmp << 1);
+ k4 = k5 - (k4 << 1);
+ k5 = (tmp2 >> 8) & 0xFF;
+ k6 = mask & (tmp >> 7);
+ k5 = k6 - (k5 << 1);
+ k6 = (tmp2 >> 16) & 0xFF;
+ k7 = mask & (tmp >> 15);
+ k6 = k7 - (k6 << 1);
+ k7 = (tmp2 >> 24) & 0xFF;
+ tmp = mask & (tmp >> 23);
+ k7 = tmp - (k7 << 1);
+ cur += width;
+ pred += 16;
+
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ dst[0] = k0;
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ /*****************/
+ /********/
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k1 = mla392(k4, k14, round);
+ k1 = mla946(k6, k14, k1);
+
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k5 = k5 + k6;
+ /********/
+ dst[1] = k5;
+ dst += 8;
+ }
+ while (dst < out);
+ out -= 64;
+ dst = out + 2;
+ /* Vertical Block Loop */
+ do /* Vertical 8xDCT loop */
+ {
+ k0 = out[0];
+ k1 = out[8];
+ k2 = out[16];
+ k3 = out[24];
+ k4 = out[32];
+ k5 = out[40];
+ k6 = out[48];
+ k7 = out[56];
+
+ abs_sum = sum_abs(k0, k1, k2, k3, k4, k5, k6, k7);
+
+ if (abs_sum < ColTh)
+ {
+ out[0] = 0x7fff;
+ out++;
+ continue;
+ }
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ out[0] = k0; /* row 0 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ /*****************/
+ /********/
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k1 = mla392(k4, k14, round);
+ k1 = mla946(k6, k14, k1);
+
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k5 = k5 + k6;
+ /********/
+ out[8] = k5 ; /* row 1 */
+ out++;
+ }
+ while ((uintptr_t)out < (uintptr_t)dst) ;
+
+ return ;
+ }
+
+ /**************************************************************************/
+ /* Function: BlockDCT_AANIntra
+ Date: 8/9/01
+ Input: rec
+ Output: out[64] ==> next block
+ Purpose: Input directly from rec frame.
+ Modified:
+ **************************************************************************/
+
+ Void BlockDCT_AANIntra(Short *out, UChar *cur, UChar *dummy2, Int width)
+ {
+ Short *dst;
+ Int k0, k1, k2, k3, k4, k5, k6, k7;
+ Int round;
+ Int k12 = 0x022A02D4;
+ Int k14 = 0x0188053A;
+ Int abs_sum;
+ Int mask;
+ Int *curInt, tmp;
+ Int ColTh;
+
+ OSCL_UNUSED_ARG(dummy2);
+
+ dst = out + 64 ;
+ ColTh = *dst;
+ out += 128;
+ round = 1 << (FDCT_SHIFT - 1);
+
+ do /* fdct_nextrow */
+ {
+ mask = 0x1FE;
+ curInt = (Int*) cur;
+ tmp = curInt[0]; /* contains 4 pixels */
+ k0 = mask & (tmp << 1);
+ k1 = mask & (tmp >> 7);
+ k2 = mask & (tmp >> 15);
+ k3 = mask & (tmp >> 23);
+ tmp = curInt[1]; /* another 4 pixels */
+ k4 = mask & (tmp << 1);
+ k5 = mask & (tmp >> 7);
+ k6 = mask & (tmp >> 15);
+ k7 = mask & (tmp >> 23);
+ cur += width;
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ k1 = k0 - (k1 << 1);
+ /**********/
+ dst[0] = k0;
+ dst[4] = k1; /* col. 4 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ k3 = (k3 << 1) - k2;
+ /********/
+ dst[2] = k2; /* col. 2 */
+ k3 <<= 1; /* scale up col. 6 */
+ dst[6] = k3; /* col. 6 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k4 = k4 + k7;
+ k7 = (k7 << 1) - k4;
+ k5 = k5 + k6;
+ k4 <<= 1; /* scale up col.5 */
+ k6 = k5 - (k6 << 1);
+ /********/
+ dst[5] = k4; /* col. 5 */
+ k6 <<= 2; /* scale up col. 7 */
+ dst[1] = k5; /* col. 1 */
+ dst[7] = k6; /* col. 7 */
+ dst[3] = k7; /* col. 3 */
+ dst += 8;
+ }
+ while (dst < out);
+
+ out -= 64;
+ dst = out + 8;
+
+ /* Vertical Block Loop */
+ do /* Vertical 8xDCT loop */
+ {
+ k0 = out[0];
+ k1 = out[8];
+ k2 = out[16];
+ k3 = out[24];
+ k4 = out[32];
+ k5 = out[40];
+ k6 = out[48];
+ k7 = out[56];
+ /* deadzone thresholding for column */
+
+ abs_sum = sum_abs(k0, k1, k2, k3, k4, k5, k6, k7);
+
+ if (abs_sum < ColTh)
+ {
+ out[0] = 0x7fff;
+ out++;
+ continue;
+ }
+
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ k1 = k0 - (k1 << 1);
+ /**********/
+ out[32] = k1; /* row 4 */
+ out[0] = k0; /* row 0 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ k3 = (k3 << 1) - k2;
+ k3 <<= 1; /* scale up col. 6 */
+ /********/
+ out[48] = k3; /* row 6 */
+ out[16] = k2; /* row 2 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k4 = k4 + k7;
+ k7 = (k7 << 1) - k4;
+ k5 = k5 + k6;
+ k4 <<= 1; /* scale up col. 5 */
+ k6 = k5 - (k6 << 1);
+ /********/
+ out[24] = k7 ; /* row 3 */
+ k6 <<= 2; /* scale up col. 7 */
+ out[56] = k6 ; /* row 7 */
+ out[8] = k5 ; /* row 1 */
+ out[40] = k4 ; /* row 5 */
+ out++;
+ }
+ while ((uintptr_t)out < (uintptr_t)dst) ;
+
+ return ;
+ }
+
+ /**************************************************************************/
+ /* Function: Block4x4DCT_AANIntra
+ Date: 8/9/01
+ Input: prev
+ Output: out[64] ==> next block
+ Purpose: Input directly from prev frame. output 2x2 DCT
+ Modified:
+ **************************************************************************/
+
+ Void Block4x4DCT_AANIntra(Short *out, UChar *cur, UChar *dummy2, Int width)
+ {
+ Short *dst;
+ Int k0, k1, k2, k3, k4, k5, k6, k7;
+ Int round;
+ Int k12 = 0x022A02D4;
+ Int k14 = 0x0188053A;
+ Int mask;
+ Int *curInt, tmp;
+ Int abs_sum;
+ Int ColTh;
+
+ OSCL_UNUSED_ARG(dummy2);
+
+ dst = out + 64 ;
+ ColTh = *dst;
+ out += 128;
+ round = 1 << (FDCT_SHIFT - 1);
+
+ do /* fdct_nextrow */
+ {
+ mask = 0x1FE;
+ curInt = (Int*) cur;
+ tmp = curInt[0]; /* contains 4 pixels */
+ k0 = mask & (tmp << 1);
+ k1 = mask & (tmp >> 7);
+ k2 = mask & (tmp >> 15);
+ k3 = mask & (tmp >> 23);
+ tmp = curInt[1]; /* another 4 pixels */
+ k4 = mask & (tmp << 1);
+ k5 = mask & (tmp >> 7);
+ k6 = mask & (tmp >> 15);
+ k7 = mask & (tmp >> 23);
+ cur += width;
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ dst[0] = k0;
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ /********/
+ dst[2] = k2; /* col. 2 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k7 = k7 - k4;
+ k5 = k5 + k6;
+ /********/
+ dst[1] = k5; /* col. 1 */
+ dst[3] = k7; /* col. 3 */
+ dst += 8;
+ }
+ while (dst < out);
+
+ out -= 64;
+ dst = out + 4;
+
+ /* Vertical Block Loop */
+ do /* Vertical 8xDCT loop */
+ {
+ k0 = out[0];
+ k1 = out[8];
+ k2 = out[16];
+ k3 = out[24];
+ k4 = out[32];
+ k5 = out[40];
+ k6 = out[48];
+ k7 = out[56];
+
+ abs_sum = sum_abs(k0, k1, k2, k3, k4, k5, k6, k7);
+
+ if (abs_sum < ColTh)
+ {
+ out[0] = 0x7fff;
+ out++;
+ continue;
+ }
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ out[0] = k0; /* row 0 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ k2 = k2 + k3;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+ k0 = mla724(k12, k2, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ k2 = k0 >> FDCT_SHIFT;
+ /*****************/
+ k2 = k2 + k3;
+ /********/
+ out[16] = k2; /* row 2 */
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k0 = k4 - k6;
+
+ k1 = mla392(k0, k14, round);
+ k0 = mla554(k4, k12, k1);
+ k1 = mla1338(k6, k14, k1);
+
+ k4 = k0 >> FDCT_SHIFT;
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k7 = (k7 << 1) - k5;
+ k7 = k7 - k4 ;
+ k5 = k5 + k6;
+ /********/
+ out[24] = k7 ; /* row 3 */
+ out[8] = k5 ; /* row 1 */
+ out++;
+ }
+ while ((uintptr_t)out < (uintptr_t)dst) ;
+
+ return ;
+ }
+
+ /**************************************************************************/
+ /* Function: Block2x2DCT_AANIntra
+ Date: 8/9/01
+ Input: prev
+ Output: out[64] ==> next block
+ Purpose: Input directly from prev frame. output 2x2 DCT
+ Modified:
+ **************************************************************************/
+
+ Void Block2x2DCT_AANIntra(Short *out, UChar *cur, UChar *dummy2, Int width)
+ {
+ Short *dst;
+ Int k0, k1, k2, k3, k4, k5, k6, k7;
+ Int round;
+ Int k12 = 0x022A02D4;
+ Int k14 = 0x018803B2;
+ Int mask;
+ Int *curInt, tmp;
+ Int abs_sum;
+ Int ColTh;
+
+ OSCL_UNUSED_ARG(dummy2);
+
+ dst = out + 64 ;
+ ColTh = *dst;
+ out += 128;
+ round = 1 << (FDCT_SHIFT - 1);
+
+ do /* fdct_nextrow */
+ {
+ mask = 0x1FE;
+ curInt = (Int*) cur;
+ tmp = curInt[0]; /* contains 4 pixels */
+ k0 = mask & (tmp << 1);
+ k1 = mask & (tmp >> 7);
+ k2 = mask & (tmp >> 15);
+ k3 = mask & (tmp >> 23);
+ tmp = curInt[1]; /* another 4 pixels */
+ k4 = mask & (tmp << 1);
+ k5 = mask & (tmp >> 7);
+ k6 = mask & (tmp >> 15);
+ k7 = mask & (tmp >> 23);
+ cur += width;
+
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ dst[0] = k0;
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ /*****************/
+ /********/
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k1 = mla392(k4, k14, round);
+ k1 = mla946(k6, k14, k1);
+
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k5 = k5 + k6;
+ /********/
+ dst[1] = k5;
+ dst += 8;
+ }
+ while (dst < out);
+ out -= 64;
+ dst = out + 2;
+ /* Vertical Block Loop */
+ do /* Vertical 8xDCT loop */
+ {
+ k0 = out[0];
+ k1 = out[8];
+ k2 = out[16];
+ k3 = out[24];
+ k4 = out[32];
+ k5 = out[40];
+ k6 = out[48];
+ k7 = out[56];
+
+ abs_sum = sum_abs(k0, k1, k2, k3, k4, k5, k6, k7);
+
+ if (abs_sum < ColTh)
+ {
+ out[0] = 0x7fff;
+ out++;
+ continue;
+ }
+ /* fdct_1 */
+ k0 = k0 + k7;
+ k7 = k0 - (k7 << 1);
+ k1 = k1 + k6;
+ k6 = k1 - (k6 << 1);
+ k2 = k2 + k5;
+ k5 = k2 - (k5 << 1);
+ k3 = k3 + k4;
+ k4 = k3 - (k4 << 1);
+
+ k0 = k0 + k3;
+ k3 = k0 - (k3 << 1);
+ k1 = k1 + k2;
+ k2 = k1 - (k2 << 1);
+
+ k0 = k0 + k1;
+ /**********/
+ out[0] = k0; /* row 0 */
+ /* fdct_2 */
+ k4 = k4 + k5;
+ k5 = k5 + k6;
+ k6 = k6 + k7;
+ /* MUL2C k2,k5,724,FDCT_SHIFT */
+ /* k0, k1 become scratch */
+ /* assume FAST MULTIPLY */
+ k1 = mla724(k12, k5, round);
+
+ k5 = k1 >> FDCT_SHIFT;
+ /*****************/
+ /********/
+ /* fdct_3 */
+ /* ROTATE k4,k6,392,946, FDCT_SHIFT */
+ /* assume FAST MULTIPLY */
+ /* k0, k1 are output */
+ k1 = mla392(k4, k14, round);
+ k1 = mla946(k6, k14, k1);
+
+ k6 = k1 >> FDCT_SHIFT;
+ /***********************/
+ k5 = k5 + k7;
+ k5 = k5 + k6;
+ /********/
+ out[8] = k5 ; /* row 1 */
+ out++;
+ }
+ while ((uintptr_t)out < (uintptr_t)dst) ;
+
+ return ;
+ }
+ /**************************************************************************/
+ /* Function: Block1x1DCTwSub
+ Date: 8/9/01
+ Input: block
+ Output: y
+ Purpose: Compute DC value only
+ Modified:
+ **************************************************************************/
+ void Block1x1DCTwSub(Short *out, UChar *cur, UChar *pred, Int width)
+ {
+ UChar *end;
+ Int temp = 0;
+ Int offset2;
+
+ offset2 = width - 8;
+ end = pred + (16 << 3);
+ do
+ {
+ temp += (*cur++ - *pred++);
+ temp += (*cur++ - *pred++);
+ temp += (*cur++ - *pred++);
+ temp += (*cur++ - *pred++);
+ temp += (*cur++ - *pred++);
+ temp += (*cur++ - *pred++);
+ temp += (*cur++ - *pred++);
+ temp += (*cur++ - *pred++);
+ cur += offset2;
+ pred += 8;
+ }
+ while (pred < end) ;
+
+ out[1] = out[2] = out[3] = out[4] = out[5] = out[6] = out[7] = 0;
+ out[0] = temp >> 3;
+
+ return ;
+ }
+
+ /**************************************************************************/
+ /* Function: Block1x1DCTIntra
+ Date: 8/9/01
+ Input: prev
+ Output: out
+ Purpose: Compute DC value only
+ Modified:
+ **************************************************************************/
+ void Block1x1DCTIntra(Short *out, UChar *cur, UChar *dummy2, Int width)
+ {
+ UChar *end;
+ Int temp = 0;
+ ULong word;
+
+ OSCL_UNUSED_ARG(dummy2);
+
+ end = cur + (width << 3);
+ do
+ {
+ word = *((ULong*)cur);
+ temp += (word >> 24);
+ temp += ((word >> 16) & 0xFF);
+ temp += ((word >> 8) & 0xFF);
+ temp += (word & 0xFF);
+
+ word = *((ULong*)(cur + 4));
+ temp += (word >> 24);
+ temp += ((word >> 16) & 0xFF);
+ temp += ((word >> 8) & 0xFF);
+ temp += (word & 0xFF);
+
+ cur += width;
+ }
+ while (cur < end) ;
+
+ out[1] = out[2] = out[3] = out[4] = out[5] = out[6] = out[7] = 0;
+ out[0] = temp >> 3;
+
+ return ;
+ }
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/media/codecs/m4v_h263/enc/src/dct.h b/media/codecs/m4v_h263/enc/src/dct.h
new file mode 100644
index 0000000..3dceb66
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/dct.h
@@ -0,0 +1,191 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _DCT_H_
+#define _DCT_H_
+
+const static Int ColThInter[32] = {0, 0x1C, 0x4C, 0x6C, 0x9C, 0xBC, 0xEC, 0x10C,
+ 0x13C, 0x15C, 0x18C, 0x1AC, 0x1DC, 0x1FC, 0x22C, 0x24C,
+ 0x27C, 0x29C, 0x2CC, 0x2EC, 0x31C, 0x33C, 0x36C, 0x38C,
+ 0x3BC, 0x3DC, 0x40C, 0x42C, 0x45C, 0x47C, 0x4AC, 0x4CC
+ };
+
+const static Int ColThIntra[32] = {0, 0x1C, 0x3C, 0x5C, 0x7C, 0x9C, 0xBC, 0xDC,
+ 0xFC, 0x11C, 0x13C, 0x15C, 0x17C, 0x19C, 0x1BC, 0x1DC,
+ 0x1FC, 0x21C, 0x23C, 0x25C, 0x27C, 0x29C, 0x2BC, 0x2DC,
+ 0x2FC, 0x31C, 0x33C, 0x35C, 0x37C, 0x39C, 0x3BC, 0x3DC
+ };
+
+/******************************************************/
+/********** IDCT part **************************/
+const static unsigned char imask[8] = {128, 64, 32, 16, 8, 4, 2, 1};
+const static unsigned char mask[8] = {0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe};
+
+#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */
+#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */
+#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */
+#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */
+#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */
+#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /* Reduced input IDCT */
+ void idct_col0(Short *blk);
+ void idct_col1(Short *blk);
+ void idct_col2(Short *blk);
+ void idct_col3(Short *blk);
+ void idct_col4(Short *blk);
+ void idct_col0x40(Short *blk);
+ void idct_col0x20(Short *blk);
+ void idct_col0x10(Short *blk);
+
+ void idct_rowInter(Short *srce, UChar *rec, Int lx);
+ void idct_row0Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row1Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row2Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row3Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row4Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row0x40Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row0x20Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row0x10Inter(Short *blk, UChar *rec, Int lx);
+ void idct_row0xCCInter(Short *blk, UChar *rec, Int lx);
+ void idct_rowIntra(Short *srce, UChar *rec, Int lx);
+ void idct_row0Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row1Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row2Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row3Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row4Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row0x40Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row0x20Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row0x10Intra(Short *blk, UChar *rec, Int lx);
+ void idct_row0xCCIntra(Short *blk, UChar *rec, Int lx);
+ void idct_rowzmv(Short *srce, UChar *rec, UChar *prev, Int lx);
+ void idct_row0zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row1zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row2zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row3zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row4zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row0x40zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row0x20zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row0x10zmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+ void idct_row0xCCzmv(Short *blk, UChar *rec, UChar *prev, Int lx);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/* Look-up table mapping to RIDCT from bitmap */
+#ifdef SMALL_DCT
+
+static void (*const idctcolVCA[16])(Short*) =
+{
+ &idct_col0, &idct_col4, &idct_col3, &idct_col4,
+ &idct_col2, &idct_col4, &idct_col3, &idct_col4,
+ &idct_col1, &idct_col4, &idct_col3, &idct_col4,
+ &idct_col2, &idct_col4, &idct_col3, &idct_col4
+};
+
+static void (*const idctrowVCAInter[16])(Short*, UChar*, Int) =
+{
+ &idct_row0Inter, &idct_row4Inter, &idct_row3Inter, &idct_row4Inter,
+ &idct_row2Inter, &idct_row4Inter, &idct_row3Inter, &idct_row4Inter,
+ &idct_row1Inter, &idct_row4Inter, &idct_row3Inter, &idct_row4Inter,
+ &idct_row2Inter, &idct_row4Inter, &idct_row3Inter, &idct_row4Inter
+};
+
+static void (*const idctrowVCAzmv[16])(Short*, UChar*, UChar*, Int) =
+{
+ &idct_row0zmv, &idct_row4zmv, &idct_row3zmv, &idct_row4zmv,
+ &idct_row2zmv, &idct_row4zmv, &idct_row3zmv, &idct_row4zmv,
+ &idct_row1zmv, &idct_row4zmv, &idct_row3zmv, &idct_row4zmv,
+ &idct_row2zmv, &idct_row4zmv, &idct_row3zmv, &idct_row4zmv
+};
+
+
+static void (*const idctrowVCAIntra[16])(Short*, UChar*, Int) =
+{
+ &idct_row0Intra, &idct_row4Intra, &idct_row3Intra, &idct_row4Intra,
+ &idct_row2Intra, &idct_row4Intra, &idct_row3Intra, &idct_row4Intra,
+ &idct_row1Intra, &idct_row4Intra, &idct_row3Intra, &idct_row4Intra,
+ &idct_row2Intra, &idct_row4Intra, &idct_row3Intra, &idct_row4Intra
+};
+
+#else /* SMALL_DCT */
+
+static void (*const idctcolVCA[16])(Short*) =
+{
+ &idct_col0, &idct_col0x10, &idct_col0x20, &idct_col4,
+ &idct_col0x40, &idct_col4, &idct_col3, &idct_col4,
+ &idct_col1, &idct_col4, &idct_col3, &idct_col4,
+ &idct_col2, &idct_col4, &idct_col3, &idct_col4
+};
+
+static void (*const idctrowVCAInter[16])(Short*, UChar*, Int) =
+{
+ &idct_row0Inter, &idct_row0x10Inter, &idct_row0x20Inter, &idct_row4Inter,
+ &idct_row0x40Inter, &idct_row4Inter, &idct_row3Inter, &idct_row4Inter,
+ &idct_row1Inter, &idct_row4Inter, &idct_row3Inter, &idct_row4Inter,
+ &idct_row2Inter, &idct_row4Inter, &idct_row3Inter, &idct_row4Inter
+};
+
+static void (*const idctrowVCAzmv[16])(Short*, UChar*, UChar*, Int) =
+{
+ &idct_row0zmv, &idct_row0x10zmv, &idct_row0x20zmv, &idct_row4zmv,
+ &idct_row0x40zmv, &idct_row4zmv, &idct_row3zmv, &idct_row4zmv,
+ &idct_row1zmv, &idct_row4zmv, &idct_row3zmv, &idct_row4zmv,
+ &idct_row2zmv, &idct_row4zmv, &idct_row3zmv, &idct_row4zmv
+};
+
+static void (*const idctrowVCAIntra[16])(Short*, UChar*, Int) =
+{
+ &idct_row0Intra, &idct_row0x10Intra, &idct_row0x20Intra, &idct_row4Intra,
+ &idct_row0x40Intra, &idct_row4Intra, &idct_row3Intra, &idct_row4Intra,
+ &idct_row1Intra, &idct_row4Intra, &idct_row3Intra, &idct_row4Intra,
+ &idct_row2Intra, &idct_row4Intra, &idct_row3Intra, &idct_row4Intra
+};
+
+#endif /* SMALL_DCT */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ /* part in AppVCA_dct.c */
+//void Block1x1DCTzmv (Short *out,UChar *prev,UChar *cur,UChar *rec,Int lx,Int chroma);
+ void Block1x1DCTwSub(Short *out, UChar *cur, UChar *prev, Int pitch_chroma);
+ void Block1x1DCTIntra(Short *out, UChar *cur, UChar *dummy1, Int pitch_chroma);
+ /* This part is in dct_aan.c */
+ Void BlockDCT_AANwSub(Short *out, UChar *cur, UChar *prev, Int pitch_chroma);
+ Void Block4x4DCT_AANwSub(Short *out, UChar *cur, UChar *prev, Int pitch_chroma);
+ Void Block2x2DCT_AANwSub(Short *out, UChar *cur, UChar *prev, Int pitch_chroma);
+//Void BlockDCT_AANzmv(Short *out,UChar *prev,UChar *cur,UChar *rec,Int ColTh,Int lx,Int chroma);
+//Void Block4x4DCT_AANzmv(Short *out,UChar *prev,UChar *cur,UChar *rec,Int ColTh,Int lx,Int chroma);
+//Void Block2x2DCT_AANzmv(Short *out,UChar *prev,UChar *cur,UChar *rec,Int ColTh,Int lx,Int chroma);
+ Void BlockDCT_AANIntra(Short *out, UChar *cur, UChar *dummy1, Int pitch_chroma);
+ Void Block4x4DCT_AANIntra(Short *out, UChar *cur, UChar *dummy1, Int pitch_chroma);
+ Void Block2x2DCT_AANIntra(Short *out, UChar *cur, UChar *dummy1, Int pitch_chroma);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //_DCT_H_
diff --git a/media/codecs/m4v_h263/enc/src/dct_inline.h b/media/codecs/m4v_h263/enc/src/dct_inline.h
new file mode 100644
index 0000000..f795bd9
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/dct_inline.h
@@ -0,0 +1,395 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/* Filename: dct_inline.h */
+/* Description: Implementation for in-line functions used in dct.cpp */
+/* Modified: */
+/*********************************************************************************/
+#ifndef _DCT_INLINE_H_
+#define _DCT_INLINE_H_
+
+#if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4)
+
+__inline int32 mla724(int32 op1, int32 op2, int32 op3)
+{
+ int32 out;
+
+ OSCL_UNUSED_ARG(op1);
+
+ out = op2 * 724 + op3; /* op1 is not used here */
+
+ return out;
+}
+
+__inline int32 mla392(int32 k0, int32 k14, int32 round)
+{
+ int32 k1;
+
+ OSCL_UNUSED_ARG(k14);
+
+ k1 = k0 * 392 + round;
+
+ return k1;
+}
+
+__inline int32 mla554(int32 k4, int32 k12, int32 k1)
+{
+ int32 k0;
+
+ OSCL_UNUSED_ARG(k12);
+
+ k0 = k4 * 554 + k1;
+
+ return k0;
+}
+
+__inline int32 mla1338(int32 k6, int32 k14, int32 k1)
+{
+ int32 out;
+
+ OSCL_UNUSED_ARG(k14);
+
+ out = k6 * 1338 + k1;
+
+ return out;
+}
+
+__inline int32 mla946(int32 k6, int32 k14, int32 k1)
+{
+ int32 out;
+
+ OSCL_UNUSED_ARG(k14);
+
+ out = k6 * 946 + k1;
+
+ return out;
+}
+
+__inline int32 sum_abs(int32 k0, int32 k1, int32 k2, int32 k3,
+ int32 k4, int32 k5, int32 k6, int32 k7)
+{
+ int32 carry, abs_sum;
+
+ carry = k0 >> 31;
+ abs_sum = (k0 ^ carry);
+ carry = k1 >> 31;
+ abs_sum += (k1 ^ carry) - carry;
+ carry = k2 >> 31;
+ abs_sum += (k2 ^ carry) - carry;
+ carry = k3 >> 31;
+ abs_sum += (k3 ^ carry) - carry;
+ carry = k4 >> 31;
+ abs_sum += (k4 ^ carry) - carry;
+ carry = k5 >> 31;
+ abs_sum += (k5 ^ carry) - carry;
+ carry = k6 >> 31;
+ abs_sum += (k6 ^ carry) - carry;
+ carry = k7 >> 31;
+ abs_sum += (k7 ^ carry) - carry;
+
+ return abs_sum;
+}
+
+#elif defined(__CC_ARM) /* only work with arm v5 */
+
+#if defined(__TARGET_ARCH_5TE)
+
+__inline int32 mla724(int32 op1, int32 op2, int32 op3)
+{
+ int32 out;
+
+ __asm
+ {
+ smlabb out, op1, op2, op3
+ }
+
+ return out;
+}
+
+__inline int32 mla392(int32 k0, int32 k14, int32 round)
+{
+ int32 k1;
+
+ __asm
+ {
+ smlabt k1, k0, k14, round
+ }
+
+ return k1;
+}
+
+__inline int32 mla554(int32 k4, int32 k12, int32 k1)
+{
+ int32 k0;
+
+ __asm
+ {
+ smlabt k0, k4, k12, k1
+ }
+
+ return k0;
+}
+
+__inline int32 mla1338(int32 k6, int32 k14, int32 k1)
+{
+ int32 out;
+
+ __asm
+ {
+ smlabb out, k6, k14, k1
+ }
+
+ return out;
+}
+
+__inline int32 mla946(int32 k6, int32 k14, int32 k1)
+{
+ int32 out;
+
+ __asm
+ {
+ smlabb out, k6, k14, k1
+ }
+
+ return out;
+}
+
+#else // not ARM5TE
+
+
+__inline int32 mla724(int32 op1, int32 op2, int32 op3)
+{
+ int32 out;
+
+ __asm
+ {
+ and out, op2, #0xFFFF
+ mla out, op1, out, op3
+ }
+
+ return out;
+}
+
+__inline int32 mla392(int32 k0, int32 k14, int32 round)
+{
+ int32 k1;
+
+ __asm
+ {
+ mov k1, k14, asr #16
+ mla k1, k0, k1, round
+ }
+
+ return k1;
+}
+
+__inline int32 mla554(int32 k4, int32 k12, int32 k1)
+{
+ int32 k0;
+
+ __asm
+ {
+ mov k0, k12, asr #16
+ mla k0, k4, k0, k1
+ }
+
+ return k0;
+}
+
+__inline int32 mla1338(int32 k6, int32 k14, int32 k1)
+{
+ int32 out;
+
+ __asm
+ {
+ and out, k14, 0xFFFF
+ mla out, k6, out, k1
+ }
+
+ return out;
+}
+
+__inline int32 mla946(int32 k6, int32 k14, int32 k1)
+{
+ int32 out;
+
+ __asm
+ {
+ and out, k14, 0xFFFF
+ mla out, k6, out, k1
+ }
+
+ return out;
+}
+
+#endif
+
+__inline int32 sum_abs(int32 k0, int32 k1, int32 k2, int32 k3,
+ int32 k4, int32 k5, int32 k6, int32 k7)
+{
+ int32 carry, abs_sum;
+ __asm
+ {
+ eor carry, k0, k0, asr #31 ;
+ eors abs_sum, k1, k1, asr #31 ;
+ adc abs_sum, abs_sum, carry ;
+ eors carry, k2, k2, asr #31 ;
+ adc abs_sum, abs_sum, carry ;
+ eors carry, k3, k3, asr #31 ;
+ adc abs_sum, abs_sum, carry ;
+ eors carry, k4, k4, asr #31 ;
+ adc abs_sum, abs_sum, carry ;
+ eors carry, k5, k5, asr #31 ;
+ adc abs_sum, abs_sum, carry ;
+ eors carry, k6, k6, asr #31 ;
+ adc abs_sum, abs_sum, carry ;
+ eors carry, k7, k7, asr #31 ;
+ adc abs_sum, abs_sum, carry ;
+ }
+
+ return abs_sum;
+}
+
+#elif ( defined(PV_ARM_GCC_V5) || defined(PV_ARM_GCC_V4) ) /* ARM GNU COMPILER */
+
+__inline int32 mla724(int32 op1, int32 op2, int32 op3)
+{
+ register int32 out;
+ register int32 aa = (int32)op1;
+ register int32 bb = (int32)op2;
+ register int32 cc = (int32)op3;
+
+ asm volatile("smlabb %0, %1, %2, %3"
+ : "=&r"(out)
+ : "r"(aa),
+ "r"(bb),
+ "r"(cc));
+ return out;
+}
+
+
+__inline int32 mla392(int32 k0, int32 k14, int32 round)
+{
+ register int32 out;
+ register int32 aa = (int32)k0;
+ register int32 bb = (int32)k14;
+ register int32 cc = (int32)round;
+
+ asm volatile("smlabt %0, %1, %2, %3"
+ : "=&r"(out)
+ : "r"(aa),
+ "r"(bb),
+ "r"(cc));
+
+ return out;
+}
+
+__inline int32 mla554(int32 k4, int32 k12, int32 k1)
+{
+ register int32 out;
+ register int32 aa = (int32)k4;
+ register int32 bb = (int32)k12;
+ register int32 cc = (int32)k1;
+
+ asm volatile("smlabt %0, %1, %2, %3"
+ : "=&r"(out)
+ : "r"(aa),
+ "r"(bb),
+ "r"(cc));
+
+ return out;
+}
+
+__inline int32 mla1338(int32 k6, int32 k14, int32 k1)
+{
+ register int32 out;
+ register int32 aa = (int32)k6;
+ register int32 bb = (int32)k14;
+ register int32 cc = (int32)k1;
+
+ asm volatile("smlabb %0, %1, %2, %3"
+ : "=&r"(out)
+ : "r"(aa),
+ "r"(bb),
+ "r"(cc));
+ return out;
+}
+
+__inline int32 mla946(int32 k6, int32 k14, int32 k1)
+{
+ register int32 out;
+ register int32 aa = (int32)k6;
+ register int32 bb = (int32)k14;
+ register int32 cc = (int32)k1;
+
+ asm volatile("smlabb %0, %1, %2, %3"
+ : "=&r"(out)
+ : "r"(aa),
+ "r"(bb),
+ "r"(cc));
+ return out;
+}
+
+__inline int32 sum_abs(int32 k0, int32 k1, int32 k2, int32 k3,
+ int32 k4, int32 k5, int32 k6, int32 k7)
+{
+ register int32 carry;
+ register int32 abs_sum;
+ register int32 aa = (int32)k0;
+ register int32 bb = (int32)k1;
+ register int32 cc = (int32)k2;
+ register int32 dd = (int32)k3;
+ register int32 ee = (int32)k4;
+ register int32 ff = (int32)k5;
+ register int32 gg = (int32)k6;
+ register int32 hh = (int32)k7;
+
+ asm volatile("eor %0, %2, %2, asr #31\n\t"
+ "eors %1, %3, %3, asr #31\n\t"
+ "adc %1, %1, %0\n\t"
+ "eors %0, %4, %4, asr #31\n\t"
+ "adc %1, %1, %0\n\t"
+ "eors %0, %5, %5, asr #31\n\t"
+ "adc %1, %1, %0\n\t"
+ "eors %0, %6, %6, asr #31\n\t"
+ "adc %1, %1, %0\n\t"
+ "eors %0, %7, %7, asr #31\n\t"
+ "adc %1, %1, %0\n\t"
+ "eors %0, %8, %8, asr #31\n\t"
+ "adc %1, %1, %0\n\t"
+ "eors %0, %9, %9, asr #31\n\t"
+ "adc %1, %1, %0\n\t"
+
+ : "=&r"(carry),
+ "=&r"(abs_sum):
+ "r"(aa),
+ "r"(bb),
+ "r"(cc),
+ "r"(dd),
+ "r"(ee),
+ "r"(ff),
+ "r"(gg),
+ "r"(hh));
+
+ return abs_sum;
+}
+
+#endif // Diff. OS
+
+#endif //_DCT_INLINE_H_
+
+
diff --git a/media/codecs/m4v_h263/enc/src/fastcodemb.cpp b/media/codecs/m4v_h263/enc/src/fastcodemb.cpp
new file mode 100644
index 0000000..50c8161
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/fastcodemb.cpp
@@ -0,0 +1,627 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4lib_int.h"
+#include "mp4enc_lib.h"
+#include "dct.h"
+#include "m4venc_oscl.h"
+
+/* ======================================================================== */
+/* Function : CodeMB_H263( ) */
+/* Date : 8/15/2001 */
+/* Purpose : Perform residue calc (only zero MV), DCT, H263 Quant/Dequant,*/
+/* IDCT and motion compensation.Modified from FastCodeMB() */
+/* Input : */
+/* video Video encoder data structure */
+/* function Approximate DCT function, scaling and threshold */
+/* ncoefblck Array for last nonzero coeff for speedup in VlcEncode */
+/* QP Combined offset from the origin to the current */
+/* macroblock and QP for current MB. */
+/* Output : */
+/* video->outputMB Quantized DCT coefficients. */
+/* currVop->yChan,uChan,vChan Reconstructed pixels */
+/* */
+/* Return : PV_STATUS */
+/* Modified : */
+/* 2/26/01
+ -modified threshold based on correlation coeff 0.75 only for mode H.263
+ -ncoefblck[] as input, to keep position of last non-zero coeff*/
+/* 8/10/01
+ -modified threshold based on correlation coeff 0.5
+ -used column threshold to speedup column DCT.
+ -used bitmap zigzag to speedup RunLevel(). */
+/* ======================================================================== */
+
+PV_STATUS CodeMB_H263(VideoEncData *video, approxDCT *function, Int QP, Int ncoefblck[])
+{
+ Int sad, k, CBP, mbnum = video->mbnum;
+ Short *output, *dataBlock;
+ UChar Mode = video->headerInfo.Mode[mbnum];
+ UChar *bitmapcol, *bitmaprow = video->bitmaprow;
+ UInt *bitmapzz ;
+ UChar shortHeader = video->vol[video->currLayer]->shortVideoHeader;
+ Int dc_scaler = 8;
+ Int intra = (Mode == MODE_INTRA || Mode == MODE_INTRA_Q);
+ struct QPstruct QuantParam;
+ Int dctMode, DctTh1;
+ Int ColTh;
+ Int(*BlockQuantDequantH263)(Short *, Short *, struct QPstruct *,
+ UChar[], UChar *, UInt *, Int, Int, Int, UChar);
+ Int(*BlockQuantDequantH263DC)(Short *, Short *, struct QPstruct *,
+ UChar *, UInt *, Int, UChar);
+ void (*BlockDCT1x1)(Short *, UChar *, UChar *, Int);
+ void (*BlockDCT2x2)(Short *, UChar *, UChar *, Int);
+ void (*BlockDCT4x4)(Short *, UChar *, UChar *, Int);
+ void (*BlockDCT8x8)(Short *, UChar *, UChar *, Int);
+
+ /* motion comp. related var. */
+ Vop *currVop = video->currVop;
+ VideoEncFrameIO *inputFrame = video->input;
+ Int ind_x = video->outputMB->mb_x;
+ Int ind_y = video->outputMB->mb_y;
+ Int lx = currVop->pitch;
+ Int width = currVop->width;
+ UChar *rec, *input, *pred;
+ Int offset = QP >> 5; /* QP is combined offset and QP */
+ Int offsetc = (offset >> 2) + (ind_x << 2); /* offset for chrom */
+ /*****************************/
+
+ OSCL_UNUSED_ARG(function);
+
+ output = video->outputMB->block[0];
+ CBP = 0;
+ QP = QP & 0x1F;
+// M4VENC_MEMSET(output,0,(sizeof(Short)<<6)*6); /* reset quantized coeff. to zero , 7/24/01*/
+
+ QuantParam.QPx2 = QP << 1;
+ QuantParam.QP = QP;
+ QuantParam.QPdiv2 = QP >> 1;
+ QuantParam.QPx2plus = QuantParam.QPx2 + QuantParam.QPdiv2;
+ QuantParam.Addition = QP - 1 + (QP & 0x1);
+
+ if (intra)
+ {
+ BlockDCT1x1 = &Block1x1DCTIntra;
+ BlockDCT2x2 = &Block2x2DCT_AANIntra;
+ BlockDCT4x4 = &Block4x4DCT_AANIntra;
+ BlockDCT8x8 = &BlockDCT_AANIntra;
+ BlockQuantDequantH263 = &BlockQuantDequantH263Intra;
+ BlockQuantDequantH263DC = &BlockQuantDequantH263DCIntra;
+ if (shortHeader)
+ {
+ dc_scaler = 8;
+ }
+ else
+ {
+ dc_scaler = cal_dc_scalerENC(QP, 1); /* luminance blocks */
+ }
+ DctTh1 = (Int)(dc_scaler * 3);//*1.829
+ ColTh = ColThIntra[QP];
+ }
+ else
+ {
+ BlockDCT1x1 = &Block1x1DCTwSub;
+ BlockDCT2x2 = &Block2x2DCT_AANwSub;
+ BlockDCT4x4 = &Block4x4DCT_AANwSub;
+ BlockDCT8x8 = &BlockDCT_AANwSub;
+
+ BlockQuantDequantH263 = &BlockQuantDequantH263Inter;
+ BlockQuantDequantH263DC = &BlockQuantDequantH263DCInter;
+ ColTh = ColThInter[QP];
+ DctTh1 = (Int)(16 * QP); //9*QP;
+ }
+
+ rec = currVop->yChan + offset;
+ input = inputFrame->yChan + offset;
+ if (lx != width) input -= (ind_y << 9); /* non-padded offset */
+
+ dataBlock = video->dataBlock;
+ pred = video->predictedMB;
+
+ for (k = 0; k < 6; k++)
+ {
+ CBP <<= 1;
+ bitmapcol = video->bitmapcol[k];
+ bitmapzz = video->bitmapzz[k]; /* 7/30/01 */
+ if (k < 4)
+ {
+ sad = video->mot[mbnum][k+1].sad;
+ if (k&1)
+ {
+ rec += 8;
+ input += 8;
+ }
+ else if (k == 2)
+ {
+ dctMode = ((width << 3) - 8);
+ input += dctMode;
+ dctMode = ((lx << 3) - 8);
+ rec += dctMode;
+ }
+ }
+ else
+ {
+ if (k == 4)
+ {
+ rec = currVop->uChan + offsetc;
+ input = inputFrame->uChan + offsetc;
+ if (lx != width) input -= (ind_y << 7);
+ lx >>= 1;
+ width >>= 1;
+ if (intra)
+ {
+ sad = getBlockSum(input, width);
+ if (shortHeader)
+ dc_scaler = 8;
+ else
+ {
+ dc_scaler = cal_dc_scalerENC(QP, 2); /* chrominance blocks */
+ }
+ DctTh1 = (Int)(dc_scaler * 3);//*1.829
+ }
+ else
+ sad = Sad8x8(input, pred, width);
+ }
+ else
+ {
+ rec = currVop->vChan + offsetc;
+ input = inputFrame->vChan + offsetc;
+ if (lx != width) input -= (ind_y << 7);
+ if (intra)
+ {
+ sad = getBlockSum(input, width);
+ }
+ else
+ sad = Sad8x8(input, pred, width);
+ }
+ }
+
+ if (sad < DctTh1 && !(shortHeader && intra)) /* all-zero */
+ { /* For shortHeader intra block, DC value cannot be zero */
+ dctMode = 0;
+ CBP |= 0;
+ ncoefblck[k] = 0;
+ }
+ else if (sad < 18*QP/*(QP<<4)*/) /* DC-only */
+ {
+ dctMode = 1;
+ BlockDCT1x1(dataBlock, input, pred, width);
+
+ CBP |= (*BlockQuantDequantH263DC)(dataBlock, output, &QuantParam,
+ bitmaprow + k, bitmapzz, dc_scaler, shortHeader);
+ ncoefblck[k] = 1;
+ }
+ else
+ {
+
+ dataBlock[64] = ColTh;
+
+ if (sad < 22*QP/*(QP<<4)+(QP<<1)*/) /* 2x2 DCT */
+ {
+ dctMode = 2;
+ BlockDCT2x2(dataBlock, input, pred, width);
+ ncoefblck[k] = 6;
+ }
+ else if (sad < (QP << 5)) /* 4x4 DCT */
+ {
+ dctMode = 4;
+ BlockDCT4x4(dataBlock, input, pred, width);
+ ncoefblck[k] = 26;
+ }
+ else /* Full-DCT */
+ {
+ dctMode = 8;
+ BlockDCT8x8(dataBlock, input, pred, width);
+ ncoefblck[k] = 64;
+ }
+
+ CBP |= (*BlockQuantDequantH263)(dataBlock, output, &QuantParam,
+ bitmapcol, bitmaprow + k, bitmapzz, dctMode, k, dc_scaler, shortHeader);
+ }
+ BlockIDCTMotionComp(dataBlock, bitmapcol, bitmaprow[k], dctMode, rec, pred, (lx << 1) | intra);
+ output += 64;
+ if (!(k&1))
+ {
+ pred += 8;
+ }
+ else
+ {
+ pred += 120;
+ }
+ }
+
+ video->headerInfo.CBP[mbnum] = CBP; /* 5/18/2001 */
+ return PV_SUCCESS;
+}
+
+#ifndef NO_MPEG_QUANT
+/* ======================================================================== */
+/* Function : CodeMB_MPEG( ) */
+/* Date : 8/15/2001 */
+/* Purpose : Perform residue calc (only zero MV), DCT, MPEG Quant/Dequant,*/
+/* IDCT and motion compensation.Modified from FastCodeMB() */
+/* Input : */
+/* video Video encoder data structure */
+/* function Approximate DCT function, scaling and threshold */
+/* ncoefblck Array for last nonzero coeff for speedup in VlcEncode */
+/* QP Combined offset from the origin to the current */
+/* macroblock and QP for current MB. */
+/* Output : */
+/* video->outputMB Quantized DCT coefficients. */
+/* currVop->yChan,uChan,vChan Reconstructed pixels */
+/* */
+/* Return : PV_STATUS */
+/* Modified : */
+/* 2/26/01
+ -modified threshold based on correlation coeff 0.75 only for mode H.263
+ -ncoefblck[] as input, keep position of last non-zero coeff*/
+/* 8/10/01
+ -modified threshold based on correlation coeff 0.5
+ -used column threshold to speedup column DCT.
+ -used bitmap zigzag to speedup RunLevel(). */
+/* ======================================================================== */
+
+PV_STATUS CodeMB_MPEG(VideoEncData *video, approxDCT *function, Int QP, Int ncoefblck[])
+{
+ Int sad, k, CBP, mbnum = video->mbnum;
+ Short *output, *dataBlock;
+ UChar Mode = video->headerInfo.Mode[mbnum];
+ UChar *bitmapcol, *bitmaprow = video->bitmaprow;
+ UInt *bitmapzz ;
+ Int dc_scaler = 8;
+ Vol *currVol = video->vol[video->currLayer];
+ Int intra = (Mode == MODE_INTRA || Mode == MODE_INTRA_Q);
+ Int *qmat;
+ Int dctMode, DctTh1, DctTh2, DctTh3, DctTh4;
+ Int ColTh;
+
+ Int(*BlockQuantDequantMPEG)(Short *, Short *, Int, Int *,
+ UChar [], UChar *, UInt *, Int, Int, Int);
+ Int(*BlockQuantDequantMPEGDC)(Short *, Short *, Int, Int *,
+ UChar [], UChar *, UInt *, Int);
+
+ void (*BlockDCT1x1)(Short *, UChar *, UChar *, Int);
+ void (*BlockDCT2x2)(Short *, UChar *, UChar *, Int);
+ void (*BlockDCT4x4)(Short *, UChar *, UChar *, Int);
+ void (*BlockDCT8x8)(Short *, UChar *, UChar *, Int);
+
+ /* motion comp. related var. */
+ Vop *currVop = video->currVop;
+ VideoEncFrameIO *inputFrame = video->input;
+ Int ind_x = video->outputMB->mb_x;
+ Int ind_y = video->outputMB->mb_y;
+ Int lx = currVop->pitch;
+ Int width = currVop->width;
+ UChar *rec, *input, *pred;
+ Int offset = QP >> 5;
+ Int offsetc = (offset >> 2) + (ind_x << 2); /* offset for chrom */
+ /*****************************/
+
+ OSCL_UNUSED_ARG(function);
+
+ output = video->outputMB->block[0];
+ CBP = 0;
+ QP = QP & 0x1F;
+// M4VENC_MEMSET(output,0,(sizeof(Short)<<6)*6); /* reset quantized coeff. to zero , 7/24/01*/
+
+ if (intra)
+ {
+ BlockDCT1x1 = &Block1x1DCTIntra;
+ BlockDCT2x2 = &Block2x2DCT_AANIntra;
+ BlockDCT4x4 = &Block4x4DCT_AANIntra;
+ BlockDCT8x8 = &BlockDCT_AANIntra;
+
+ BlockQuantDequantMPEG = &BlockQuantDequantMPEGIntra;
+ BlockQuantDequantMPEGDC = &BlockQuantDequantMPEGDCIntra;
+ dc_scaler = cal_dc_scalerENC(QP, 1); /* luminance blocks */
+ qmat = currVol->iqmat;
+ DctTh1 = (Int)(3 * dc_scaler);//2*dc_scaler);
+ DctTh2 = (Int)((1.25 * QP - 1) * qmat[1] * 0.45);//0.567);//0.567);
+ DctTh3 = (Int)((1.25 * QP - 1) * qmat[2] * 0.55);//1.162); /* 8/2/2001 */
+ DctTh4 = (Int)((1.25 * QP - 1) * qmat[32] * 0.8);//1.7583);//0.7942);
+ ColTh = ColThIntra[QP];
+ }
+ else
+ {
+ BlockDCT1x1 = &Block1x1DCTwSub;
+ BlockDCT2x2 = &Block2x2DCT_AANwSub;
+ BlockDCT4x4 = &Block4x4DCT_AANwSub;
+ BlockDCT8x8 = &BlockDCT_AANwSub;
+
+ BlockQuantDequantMPEG = &BlockQuantDequantMPEGInter;
+ BlockQuantDequantMPEGDC = &BlockQuantDequantMPEGDCInter;
+ qmat = currVol->niqmat;
+ DctTh1 = (Int)(((QP << 1) - 0.5) * qmat[0] * 0.4);//0.2286);//0.3062);
+ DctTh2 = (Int)(((QP << 1) - 0.5) * qmat[1] * 0.45);//0.567);//0.4);
+ DctTh3 = (Int)(((QP << 1) - 0.5) * qmat[2] * 0.55);//1.162); /* 8/2/2001 */
+ DctTh4 = (Int)(((QP << 1) - 0.5) * qmat[32] * 0.8);//1.7583);//0.7942);
+ ColTh = ColThInter[QP];
+ }// get qmat, DctTh1, DctTh2, DctTh3
+
+ rec = currVop->yChan + offset;
+ input = inputFrame->yChan + offset;
+ if (lx != width) input -= (ind_y << 9); /* non-padded offset */
+
+ dataBlock = video->dataBlock;
+ pred = video->predictedMB;
+
+ for (k = 0; k < 6; k++)
+ {
+ CBP <<= 1;
+ bitmapcol = video->bitmapcol[k];
+ bitmapzz = video->bitmapzz[k]; /* 8/2/01 */
+ if (k < 4)
+ {//Y block
+ sad = video->mot[mbnum][k+1].sad;
+ if (k&1)
+ {
+ rec += 8;
+ input += 8;
+ }
+ else if (k == 2)
+ {
+ dctMode = ((width << 3) - 8);
+ input += dctMode;
+ dctMode = ((lx << 3) - 8);
+ rec += dctMode;
+ }
+ }
+ else
+ {// U, V block
+ if (k == 4)
+ {
+ rec = currVop->uChan + offsetc;
+ input = inputFrame->uChan + offsetc;
+ if (lx != width) input -= (ind_y << 7);
+ lx >>= 1;
+ width >>= 1;
+ if (intra)
+ {
+ dc_scaler = cal_dc_scalerENC(QP, 2); /* luminance blocks */
+ DctTh1 = dc_scaler * 3;
+ sad = getBlockSum(input, width);
+ }
+ else
+ sad = Sad8x8(input, pred, width);
+ }
+ else
+ {
+ rec = currVop->vChan + offsetc;
+ input = inputFrame->vChan + offsetc;
+ if (lx != width) input -= (ind_y << 7);
+ if (intra)
+ sad = getBlockSum(input, width);
+ else
+ sad = Sad8x8(input, pred, width);
+ }
+ }
+
+ if (sad < DctTh1) /* all-zero */
+ {
+ dctMode = 0;
+ CBP |= 0;
+ ncoefblck[k] = 0;
+ }
+ else if (sad < DctTh2) /* DC-only */
+ {
+ dctMode = 1;
+ BlockDCT1x1(dataBlock, input, pred, width);
+
+ CBP |= (*BlockQuantDequantMPEGDC)(dataBlock, output, QP, qmat,
+ bitmapcol, bitmaprow + k, bitmapzz, dc_scaler);
+ ncoefblck[k] = 1;
+ }
+ else
+ {
+ dataBlock[64] = ColTh;
+
+ if (sad < DctTh3) /* 2x2-DCT */
+ {
+ dctMode = 2;
+ BlockDCT2x2(dataBlock, input, pred, width);
+ ncoefblck[k] = 6;
+ }
+ else if (sad < DctTh4) /* 4x4 DCT */
+ {
+ dctMode = 4;
+ BlockDCT4x4(dataBlock, input, pred, width);
+ ncoefblck[k] = 26;
+ }
+ else /* full-DCT */
+ {
+ dctMode = 8;
+ BlockDCT8x8(dataBlock, input, pred, width);
+ ncoefblck[k] = 64;
+ }
+
+ CBP |= (*BlockQuantDequantMPEG)(dataBlock, output, QP, qmat,
+ bitmapcol, bitmaprow + k, bitmapzz, dctMode, k, dc_scaler); //
+ }
+ dctMode = 8; /* for mismatch handle */
+ BlockIDCTMotionComp(dataBlock, bitmapcol, bitmaprow[k], dctMode, rec, pred, (lx << 1) | (intra));
+
+ output += 64;
+ if (!(k&1))
+ {
+ pred += 8;
+ }
+ else
+ {
+ pred += 120;
+ }
+ }
+
+ video->headerInfo.CBP[mbnum] = CBP; /* 5/18/2001 */
+ return PV_SUCCESS;
+}
+
+#endif
+
+/* ======================================================================== */
+/* Function : getBlockSAV( ) */
+/* Date : 8/10/2000 */
+/* Purpose : Get SAV for one block */
+/* In/out : block[64] contain one block data */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+/* can be written in MMX or SSE, 2/22/2001 */
+Int getBlockSAV(Short block[])
+{
+ Int i, val, sav = 0;
+
+ i = 8;
+ while (i--)
+ {
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ val = *block++;
+ if (val > 0) sav += val;
+ else sav -= val;
+ }
+
+ return sav;
+
+}
+
+/* ======================================================================== */
+/* Function : Sad8x8( ) */
+/* Date : 8/10/2000 */
+/* Purpose : Find SAD between prev block and current block */
+/* In/out : Previous and current frame block pointers, and frame width */
+/* Return : */
+/* Modified : */
+/* 8/15/01, - do 4 pixel at a time assuming 32 bit register */
+/* ======================================================================== */
+#ifdef __clang__
+__attribute((no_sanitize("integer")))
+#endif
+Int Sad8x8(UChar *cur, UChar *prev, Int width)
+{
+ UChar *end = cur + (width << 3);
+ Int sad = 0;
+ Int *curInt = (Int*) cur;
+ Int *prevInt = (Int*) prev;
+ Int cur1, cur2, prev1, prev2;
+ UInt mask, sgn_msk = 0x80808080;
+ Int sum2 = 0, sum4 = 0;
+ Int tmp;
+ do
+ {
+ mask = ~(0xFF00);
+ cur1 = curInt[1]; /* load cur[4..7] */
+ cur2 = curInt[0];
+ curInt += (width >> 2); /* load cur[0..3] and +=lx */
+ prev1 = prevInt[1];
+ prev2 = prevInt[0];
+ prevInt += 4;
+
+ tmp = prev2 ^ cur2;
+ cur2 = prev2 - cur2;
+ tmp = tmp ^ cur2; /* (^)^(-) last bit is one if carry */
+ tmp = sgn_msk & ((UInt)tmp >> 1); /* check the sign of each byte */
+ if (cur2 < 0) tmp = tmp | 0x80000000; /* corcurt sign of first byte */
+ tmp = (tmp << 8) - tmp; /* carry borrowed bytes are marked with 0x1FE */
+ cur2 = cur2 + (tmp >> 7); /* negative bytes is added with 0xFF, -1 */
+ cur2 = cur2 ^(tmp >> 7); /* take absolute by inverting bits (EOR) */
+
+ tmp = prev1 ^ cur1;
+ cur1 = prev1 - cur1;
+ tmp = tmp ^ cur1; /* (^)^(-) last bit is one if carry */
+ tmp = sgn_msk & ((UInt)tmp >> 1); /* check the sign of each byte */
+ if (cur1 < 0) tmp = tmp | 0x80000000; /* corcurt sign of first byte */
+ tmp = (tmp << 8) - tmp; /* carry borrowed bytes are marked with 0x1FE */
+ cur1 = cur1 + (tmp >> 7); /* negative bytes is added with 0xFF, -1 */
+ cur1 = cur1 ^(tmp >> 7); /* take absolute by inverting bits (EOR) */
+
+ sum4 = sum4 + cur1;
+ cur1 = cur1 & (mask << 8); /* mask first and third bytes */
+ sum2 = sum2 + ((UInt)cur1 >> 8);
+ sum4 = sum4 + cur2;
+ cur2 = cur2 & (mask << 8); /* mask first and third bytes */
+ sum2 = sum2 + ((UInt)cur2 >> 8);
+ }
+ while ((uintptr_t)curInt < (uintptr_t)end);
+
+ cur1 = sum4 - (sum2 << 8); /* get even-sum */
+ cur1 = cur1 + sum2; /* add 16 bit even-sum and odd-sum*/
+ cur1 = cur1 + (cur1 << 16); /* add upper and lower 16 bit sum */
+ sad = ((UInt)cur1 >> 16); /* take upper 16 bit */
+ return sad;
+}
+
+/* ======================================================================== */
+/* Function : getBlockSum( ) */
+/* Date : 8/10/2000 */
+/* Purpose : Find summation of value within a block. */
+/* In/out : Pointer to current block in a frame and frame width */
+/* Return : */
+/* Modified : */
+/* 8/15/01, - SIMD 4 pixels at a time */
+/* ======================================================================== */
+#ifdef __clang__
+__attribute((no_sanitize("integer")))
+#endif
+Int getBlockSum(UChar *cur, Int width)
+{
+ Int sad = 0, sum4 = 0, sum2 = 0;
+ UChar *end = cur + (width << 3);
+ Int *curInt = (Int*)cur;
+ UInt mask = ~(0xFF00);
+ Int load1, load2;
+
+ do
+ {
+ load1 = curInt[1];
+ load2 = curInt[0];
+ curInt += (width >> 2);
+ sum4 += load1;
+ load1 = load1 & (mask << 8); /* even bytes */
+ sum2 += ((UInt)load1 >> 8); /* sum even bytes, 16 bit */
+ sum4 += load2;
+ load2 = load2 & (mask << 8); /* even bytes */
+ sum2 += ((UInt)load2 >> 8); /* sum even bytes, 16 bit */
+ }
+ while ((uintptr_t)curInt < (uintptr_t)end);
+ load1 = sum4 - (sum2 << 8); /* get even-sum */
+ load1 = load1 + sum2; /* add 16 bit even-sum and odd-sum*/
+ load1 = load1 + (load1 << 16); /* add upper and lower 16 bit sum */
+ sad = ((UInt)load1 >> 16); /* take upper 16 bit */
+
+ return sad;
+}
+
diff --git a/media/codecs/m4v_h263/enc/src/fastcodemb.h b/media/codecs/m4v_h263/enc/src/fastcodemb.h
new file mode 100644
index 0000000..686a66d
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/fastcodemb.h
@@ -0,0 +1,103 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/* ===================================================================== */
+/* File: FastCodeMB.h */
+/* Description: This file contains structure and function prototypes used
+ in FastCodeMB() function. When it is decided to use FastCodeMB
+ instead of CodeMB, all of this prototypes should be migrated to
+ mp4enc_lib.h. */
+/* Rev: */
+/* Created: 8/14/01 */
+/* //////////////////////////////////////////////////////////////////////// */
+
+typedef struct struct_approxDCT approxDCT;
+struct struct_approxDCT
+{
+ const Int *scale;
+ Int(*DCT)(Int block[ ], Int coeff[ ], approxDCT *);
+
+ // Threshold value for H.263 Quantizer
+ Int th_app_all[8];
+ Int th_app_odd[8];
+ Int th_app_even[8];
+ Int th_app_even1[8];
+ Int th_app_even2[8];
+};
+
+struct QPstruct
+{
+ Int QPx2 ;
+ Int QP;
+ Int QPdiv2;
+ Int QPx2plus;
+ Int Addition;
+};
+
+/*---- FastCodeMB.c -----*/
+void initCodeMB(approxDCT *function, Int QP);
+PV_STATUS CodeMB_H263(VideoEncData *video, approxDCT *function, Int QP, Int ncoefblck[], Int offset);
+PV_STATUS CodeMB_MPEG(VideoEncData *video, approxDCT *function, Int QP, Int ncoefblck[], Int offset);
+Int getBlockSAV(Int block[]);
+Int Sad8x8(UChar *rec, UChar *prev, Int lx);
+Int getBlockSum(UChar *rec, Int lx);
+
+/*---- AppVCA_dct.c -----*/
+Int AppVCA1_dct(Int block[], Int out[ ], approxDCT *function);
+Int AppVCA2_dct(Int block[], Int out[ ], approxDCT *function);
+Int AppVCA3_dct(Int block[], Int out[ ], approxDCT *function);
+Int AppVCA4_dct(Int block[], Int out[ ], approxDCT *function);
+Int AppVCA5_dct(Int block[], Int out[ ], approxDCT *function);
+
+/*---- FastQuant.c -----*/
+Int cal_dc_scalerENC(Int QP, Int type) ;
+Int BlockQuantDequantH263Inter(Int *rcoeff, Int *qcoeff, struct QPstruct *QuantParam,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dummy);
+
+Int BlockQuantDequantH263Intra(Int *rcoeff, Int *qcoeff, struct QPstruct *QuantParam,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dc_scaler);
+
+Int BlockQuantDequantH263DCInter(Int *rcoeff, Int *qcoeff, struct QPstruct *QuantParam,
+ UChar *bitmaprow, UInt *bitmapzz, Int dummy);
+
+Int BlockQuantDequantH263DCIntra(Int *rcoeff, Int *qcoeff, struct QPstruct *QuantParam,
+ UChar *bitmaprow, UInt *bitmapzz, Int dc_scaler);
+
+Int BlockQuantDequantMPEGInter(Int *rcoeff, Int *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int DctMode, Int comp, Int dc_scaler);
+
+Int BlockQuantDequantMPEGIntra(Int *rcoeff, Int *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int DctMode, Int comp, Int dc_scaler);
+
+Int BlockQuantDequantMPEGDCInter(Int *rcoeff, Int *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, Int dummy);
+
+Int BlockQuantDequantMPEGDCIntra(Int *rcoeff, Int *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, Int dc_scaler);
+
+/*---- FastIDCT.c -----*/
+void BlockIDCTMotionComp(Int *block, UChar *bitmapcol, UChar bitmaprow,
+ Int dctMode, UChar *rec, Int lx, Int intra);
+
+/*---- motion_comp.c -----*/
+void PutSkippedBlock(UChar *rec, UChar *prev, Int lx);
+
+
diff --git a/media/codecs/m4v_h263/enc/src/fastidct.cpp b/media/codecs/m4v_h263/enc/src/fastidct.cpp
new file mode 100644
index 0000000..688effc
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/fastidct.cpp
@@ -0,0 +1,2020 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+ Who: Date: July/2001
+ Description: 1. Optimized BlockIDCT bitmap checking.
+ 2. Rearranged functions.
+ 3. Do column IDCT first, then row IDCT.
+ 4. Combine motion comp and IDCT, require
+ two sets of row IDCTs one for INTRA
+ and one for INTER.
+ 5. Add AAN IDCT
+
+ Who: Date: 8/16/01
+ 1. Increase the input precision to 8 bits, i.e. change RDCTBITS
+ to 11, have to comment out all in-line assembly since 16 bit
+ multiplication doesn't work. Try to use diffent precision with
+ 32 bit mult. but hasn't finished. Turns out that without in-line
+ assembly the performance doesn't change much (only 1%).
+ Who: Date: 9/04/05
+ 1. Replace AAN IDCT with Chen's IDCT to accommodate 16 bit data type.
+
+*/
+#include "mp4def.h"
+#include "mp4enc_lib.h"
+#include "mp4lib_int.h"
+#include "dct.h"
+
+#define ADD_CLIP { \
+ tmp = *rec + tmp; \
+ if((UInt)tmp > mask) tmp = mask&(~(tmp>>31)); \
+ *rec++ = tmp; \
+ }
+
+#define INTRA_CLIP { \
+ if((UInt)tmp > mask) tmp = mask&(~(tmp>>31)); \
+ *rec++ = tmp; \
+ }
+
+
+#define CLIP_RESULT(x) if((UInt)(x) > 0xFF){(x) = 0xFF & (~((x)>>31));}
+#define ADD_AND_CLIP1(x) x += (pred_word&0xFF); CLIP_RESULT(x);
+#define ADD_AND_CLIP2(x) x += ((pred_word>>8)&0xFF); CLIP_RESULT(x);
+#define ADD_AND_CLIP3(x) x += ((pred_word>>16)&0xFF); CLIP_RESULT(x);
+#define ADD_AND_CLIP4(x) x += ((pred_word>>24)&0xFF); CLIP_RESULT(x);
+
+
+void idct_col0(Short *blk)
+{
+ OSCL_UNUSED_ARG(blk);
+
+ return;
+}
+
+void idct_col1(Short *blk)
+{
+ blk[0] = blk[8] = blk[16] = blk[24] = blk[32] = blk[40] = blk[48] = blk[56] =
+ blk[0] << 3;
+ return ;
+}
+
+void idct_col2(Short *blk)
+{
+ int32 x0, x1, x3, x5, x7;//, x8;
+
+ x1 = blk[8];
+ x0 = ((int32)blk[0] << 11) + 128;
+ /* both upper and lower*/
+
+ x7 = W7 * x1;
+ x1 = W1 * x1;
+
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ blk[0] = (x0 + x1) >> 8;
+ blk[8] = (x0 + x7) >> 8;
+ blk[16] = (x0 + x5) >> 8;
+ blk[24] = (x0 + x3) >> 8;
+ blk[56] = (x0 - x1) >> 8;
+ blk[48] = (x0 - x7) >> 8;
+ blk[40] = (x0 - x5) >> 8;
+ blk[32] = (x0 - x3) >> 8;
+ return ;
+}
+
+void idct_col3(Short *blk)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+
+ x2 = blk[16];
+ x1 = blk[8];
+ x0 = ((int32)blk[0] << 11) + 128;
+
+ x4 = x0;
+ x6 = W6 * x2;
+ x2 = W2 * x2;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = W7 * x1;
+ x1 = W1 * x1;
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ blk[0] = (x0 + x1) >> 8;
+ blk[8] = (x4 + x7) >> 8;
+ blk[16] = (x6 + x5) >> 8;
+ blk[24] = (x2 + x3) >> 8;
+ blk[56] = (x0 - x1) >> 8;
+ blk[48] = (x4 - x7) >> 8;
+ blk[40] = (x6 - x5) >> 8;
+ blk[32] = (x2 - x3) >> 8;
+ return ;
+}
+
+void idct_col4(Short *blk)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ x2 = blk[16];
+ x1 = blk[8];
+ x3 = blk[24];
+ x0 = ((int32)blk[0] << 11) + 128;
+
+ x4 = x0;
+ x6 = W6 * x2;
+ x2 = W2 * x2;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = W7 * x1;
+ x1 = W1 * x1;
+ x5 = W3 * x3;
+ x3 = -W5 * x3;
+ x8 = x1 - x5;
+ x1 += x5;
+ x5 = x8;
+ x8 = x7 - x3;
+ x3 += x7;
+ x7 = (181 * (x5 + x8) + 128) >> 8;
+ x5 = (181 * (x5 - x8) + 128) >> 8;
+
+
+ blk[0] = (x0 + x1) >> 8;
+ blk[8] = (x4 + x7) >> 8;
+ blk[16] = (x6 + x5) >> 8;
+ blk[24] = (x2 + x3) >> 8;
+ blk[56] = (x0 - x1) >> 8;
+ blk[48] = (x4 - x7) >> 8;
+ blk[40] = (x6 - x5) >> 8;
+ blk[32] = (x2 - x3) >> 8;
+ return ;
+}
+
+#ifndef SMALL_DCT
+void idct_col0x40(Short *blk)
+{
+ int32 x1, x3, x5, x7;//, x8;
+
+ x1 = blk[8];
+ /* both upper and lower*/
+
+ x7 = W7 * x1;
+ x1 = W1 * x1;
+
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ blk[0] = (128 + x1) >> 8;
+ blk[8] = (128 + x7) >> 8;
+ blk[16] = (128 + x5) >> 8;
+ blk[24] = (128 + x3) >> 8;
+ blk[56] = (128 - x1) >> 8;
+ blk[48] = (128 - x7) >> 8;
+ blk[40] = (128 - x5) >> 8;
+ blk[32] = (128 - x3) >> 8;
+
+ return ;
+}
+
+void idct_col0x20(Short *blk)
+{
+ int32 x0, x2, x4, x6;
+
+ x2 = blk[16];
+ x6 = W6 * x2;
+ x2 = W2 * x2;
+ x0 = 128 + x2;
+ x2 = 128 - x2;
+ x4 = 128 + x6;
+ x6 = 128 - x6;
+
+ blk[0] = (x0) >> 8;
+ blk[56] = (x0) >> 8;
+ blk[8] = (x4) >> 8;
+ blk[48] = (x4) >> 8;
+ blk[16] = (x6) >> 8;
+ blk[40] = (x6) >> 8;
+ blk[24] = (x2) >> 8;
+ blk[32] = (x2) >> 8;
+
+ return ;
+}
+
+void idct_col0x10(Short *blk)
+{
+ int32 x1, x3, x5, x7;
+
+ x3 = blk[24];
+ x1 = W3 * x3;
+ x3 = W5 * x3;
+
+ x7 = (181 * (x3 - x1) + 128) >> 8;
+ x5 = (-181 * (x1 + x3) + 128) >> 8;
+
+
+ blk[0] = (128 + x1) >> 8;
+ blk[8] = (128 + x7) >> 8;
+ blk[16] = (128 + x5) >> 8;
+ blk[24] = (128 - x3) >> 8;
+ blk[56] = (128 - x1) >> 8;
+ blk[48] = (128 - x7) >> 8;
+ blk[40] = (128 - x5) >> 8;
+ blk[32] = (128 + x3) >> 8;
+
+ return ;
+}
+
+#endif /* SMALL_DCT */
+
+void idct_col(Short *blk)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+
+ x1 = (int32)blk[32] << 11;
+ x2 = blk[48];
+ x3 = blk[16];
+ x4 = blk[8];
+ x5 = blk[56];
+ x6 = blk[40];
+ x7 = blk[24];
+ x0 = ((int32)blk[0] << 11) + 128;
+
+ /* first stage */
+ x8 = W7 * (x4 + x5);
+ x4 = x8 + (W1 - W7) * x4;
+ x5 = x8 - (W1 + W7) * x5;
+ x8 = W3 * (x6 + x7);
+ x6 = x8 - (W3 - W5) * x6;
+ x7 = x8 - (W3 + W5) * x7;
+
+ /* second stage */
+ x8 = x0 + x1;
+ x0 -= x1;
+ x1 = W6 * (x3 + x2);
+ x2 = x1 - (W2 + W6) * x2;
+ x3 = x1 + (W2 - W6) * x3;
+ x1 = x4 + x6;
+ x4 -= x6;
+ x6 = x5 + x7;
+ x5 -= x7;
+
+ /* third stage */
+ x7 = x8 + x3;
+ x8 -= x3;
+ x3 = x0 + x2;
+ x0 -= x2;
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x4 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ blk[0] = (x7 + x1) >> 8;
+ blk[8] = (x3 + x2) >> 8;
+ blk[16] = (x0 + x4) >> 8;
+ blk[24] = (x8 + x6) >> 8;
+ blk[32] = (x8 - x6) >> 8;
+ blk[40] = (x0 - x4) >> 8;
+ blk[48] = (x3 - x2) >> 8;
+ blk[56] = (x7 - x1) >> 8;
+
+ return ;
+}
+
+/* This function should not be called at all ****/
+void idct_row0Inter(Short *srce, UChar *rec, Int lx)
+{
+ OSCL_UNUSED_ARG(srce);
+
+ OSCL_UNUSED_ARG(rec);
+
+ OSCL_UNUSED_ARG(lx);
+
+ return;
+}
+
+void idct_row1Inter(Short *blk, UChar *rec, Int lx)
+{
+ int tmp;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ blk -= 8;
+
+ while (i--)
+ {
+ tmp = (*(blk += 8) + 32) >> 6;
+ *blk = 0;
+
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+ res = tmp + (pred_word & 0xFF);
+ CLIP_RESULT(res);
+ res2 = tmp + ((pred_word >> 8) & 0xFF);
+ CLIP_RESULT(res2);
+ dst_word = (res2 << 8) | res;
+ res = tmp + ((pred_word >> 16) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 16);
+ res = tmp + ((pred_word >> 24) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+ res = tmp + (pred_word & 0xFF);
+ CLIP_RESULT(res);
+ res2 = tmp + ((pred_word >> 8) & 0xFF);
+ CLIP_RESULT(res2);
+ dst_word = (res2 << 8) | res;
+ res = tmp + ((pred_word >> 16) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 16);
+ res = tmp + ((pred_word >> 24) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return;
+}
+
+void idct_row2Inter(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x4, x5;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ blk -= 8;
+
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+ res = (x0 + x4) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 + x5) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+ res = (x0 - x5) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 - x1) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x4) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+void idct_row3Inter(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ blk -= 8;
+
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+ res = (x2 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+
+ return ;
+}
+
+void idct_row4Inter(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ blk -= 8;
+
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x3 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x5 = (W3 * x3 + 4) >> 3;
+ x3 = (- W5 * x3 + 4) >> 3;
+ x8 = x1 - x5;
+ x1 += x5;
+ x5 = x8;
+ x8 = x7 - x3;
+ x3 += x7;
+ x7 = (181 * (x5 + x8) + 128) >> 8;
+ x5 = (181 * (x5 - x8) + 128) >> 8;
+
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+ res = (x2 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+#ifndef SMALL_DCT
+void idct_row0x40Inter(Short *blk, UChar *rec, Int lx)
+{
+ int32 x1, x2, x4, x5;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[1];
+ blk[1] = 0;
+ blk += 8; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+ res = (8192 + x4) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 + x1) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 + x5) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+ res = (8192 - x5) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 - x1) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 - x4) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+void idct_row0x20Inter(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x2, x4, x6;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+
+ while (i--)
+ {
+ x2 = blk[2];
+ blk[2] = 0;
+ blk += 8; /* for proper rounding in the fourth stage */
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x0 = 8192 + x2;
+ x2 = 8192 - x2;
+ x4 = 8192 + x6;
+ x6 = 8192 - x6;
+
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+ res = (x0) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+ res = (x2) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+
+ return ;
+}
+
+void idct_row0x10Inter(Short *blk, UChar *rec, Int lx)
+{
+ int32 x1, x3, x5, x7;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+
+ while (i--)
+ {
+ x3 = blk[3];
+ blk[3] = 0;
+ blk += 8;
+
+ x1 = (W3 * x3 + 4) >> 3;
+ x3 = (-W5 * x3 + 4) >> 3;
+
+ x7 = (-181 * (x3 + x1) + 128) >> 8;
+ x5 = (181 * (x3 - x1) + 128) >> 8;
+
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+ res = (8192 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+ res = (8192 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+#endif /* SMALL_DCT */
+
+void idct_rowInter(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ blk -= 8;
+
+ while (i--)
+ {
+ x1 = (int32)blk[12] << 8;
+ blk[12] = 0;
+ x2 = blk[14];
+ blk[14] = 0;
+ x3 = blk[10];
+ blk[10] = 0;
+ x4 = blk[9];
+ blk[9] = 0;
+ x5 = blk[15];
+ blk[15] = 0;
+ x6 = blk[13];
+ blk[13] = 0;
+ x7 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x8 = W7 * (x4 + x5) + 4;
+ x4 = (x8 + (W1 - W7) * x4) >> 3;
+ x5 = (x8 - (W1 + W7) * x5) >> 3;
+ x8 = W3 * (x6 + x7) + 4;
+ x6 = (x8 - (W3 - W5) * x6) >> 3;
+ x7 = (x8 - (W3 + W5) * x7) >> 3;
+
+ /* second stage */
+ x8 = x0 + x1;
+ x0 -= x1;
+ x1 = W6 * (x3 + x2) + 4;
+ x2 = (x1 - (W2 + W6) * x2) >> 3;
+ x3 = (x1 + (W2 - W6) * x3) >> 3;
+ x1 = x4 + x6;
+ x4 -= x6;
+ x6 = x5 + x7;
+ x5 -= x7;
+
+ /* third stage */
+ x7 = x8 + x3;
+ x8 -= x3;
+ x3 = x0 + x2;
+ x0 -= x2;
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x4 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(rec += lx)); /* read 4 bytes from pred */
+
+ res = (x7 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x3 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 + x4) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x8 + x6) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)rec) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(rec + 4)); /* read 4 bytes from pred */
+
+ res = (x8 - x6) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 - x4) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x3 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x7 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return;
+}
+
+void idct_row0Intra(Short *srce, UChar *rec, Int lx)
+{
+ OSCL_UNUSED_ARG(srce);
+
+ OSCL_UNUSED_ARG(rec);
+
+ OSCL_UNUSED_ARG(lx);
+
+ return;
+}
+
+void idct_row1Intra(Short *blk, UChar *rec, Int lx)
+{
+ int32 tmp;
+ int i = 8;
+
+ rec -= lx;
+ blk -= 8;
+ while (i--)
+ {
+ tmp = ((*(blk += 8) + 32) >> 6);
+ *blk = 0;
+ CLIP_RESULT(tmp)
+
+ tmp |= (tmp << 8);
+ tmp |= (tmp << 16);
+ *((uint32*)(rec += lx)) = tmp;
+ *((uint32*)(rec + 4)) = tmp;
+ }
+ return;
+}
+
+void idct_row2Intra(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x4, x5;
+ int res, res2;
+ uint32 dst_word;
+ int i = 8;
+
+ rec -= lx;
+ blk -= 8;
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ res = ((x0 + x4) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x0 + x2) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x0 + x1) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x0 + x5) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word;
+
+ res = ((x0 - x5) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x0 - x1) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x0 - x2) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x0 - x4) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word;
+ }
+ return ;
+}
+
+void idct_row3Intra(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int res, res2;
+ uint32 dst_word;
+ int i = 8;
+
+ rec -= lx;
+ blk -= 8;
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0;/* for proper rounding in the fourth stage */
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ res = ((x0 + x1) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x4 + x7) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x6 + x5) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x2 + x3) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word;
+
+ res = ((x2 - x3) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x6 - x5) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x4 - x7) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x0 - x1) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word;
+
+ }
+ return ;
+}
+
+void idct_row4Intra(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int res, res2;
+ uint32 dst_word;
+ int i = 8;
+
+ rec -= lx;
+ blk -= 8;
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x3 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x5 = (W3 * x3 + 4) >> 3;
+ x3 = (- W5 * x3 + 4) >> 3;
+ x8 = x1 - x5;
+ x1 += x5;
+ x5 = x8;
+ x8 = x7 - x3;
+ x3 += x7;
+ x7 = (181 * (x5 + x8) + 128) >> 8;
+ x5 = (181 * (x5 - x8) + 128) >> 8;
+
+ res = ((x0 + x1) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x4 + x7) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x6 + x5) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x2 + x3) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word;
+
+ res = ((x2 - x3) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x6 - x5) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x4 - x7) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x0 - x1) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word;
+ }
+
+ return ;
+}
+
+#ifndef SMALL_DCT
+void idct_row0x40Intra(Short *blk, UChar *rec, Int lx)
+{
+ int32 x1, x2, x4, x5;
+ int res, res2;
+ uint32 dst_word;
+ int i = 8;
+
+ rec -= lx;
+
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[1];
+ blk[1] = 0;
+ blk += 8;
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ res = ((8192 + x4) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((8192 + x2) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((8192 + x1) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((8192 + x5) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word;
+
+ res = ((8192 - x5) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((8192 - x1) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((8192 - x2) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((8192 - x4) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word;
+
+ }
+ return ;
+}
+
+void idct_row0x20Intra(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x2, x4, x6;
+ int res, res2;
+ uint32 dst_word;
+ int i = 8;
+
+ rec -= lx;
+ while (i--)
+ {
+ x2 = blk[2];
+ blk[2] = 0;
+ blk += 8;
+
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x0 = 8192 + x2;
+ x2 = 8192 - x2;
+ x4 = 8192 + x6;
+ x6 = 8192 - x6;
+
+ res = ((x0) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x4) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x6) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x2) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word;
+
+ res = ((x2) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x6) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((x4) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x0) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word;
+
+ }
+ return ;
+}
+
+void idct_row0x10Intra(Short *blk, UChar *rec, Int lx)
+{
+ int32 x1, x3, x5, x7;
+ int res, res2;
+ uint32 dst_word;
+ int i = 8;
+
+ rec -= lx;
+ while (i--)
+ {
+ x3 = blk[3];
+ blk[3] = 0 ;
+ blk += 8;
+
+ x1 = (W3 * x3 + 4) >> 3;
+ x3 = (W5 * x3 + 4) >> 3;
+
+ x7 = (181 * (x3 - x1) + 128) >> 8;
+ x5 = (-181 * (x1 + x3) + 128) >> 8;
+
+ res = ((8192 + x1) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((8192 + x7) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((8192 + x5) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((8192 - x3) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word;
+
+ res = ((8192 + x3) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((8192 - x5) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = (res2 << 8) | res;
+ res = ((8192 - x7) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((8192 - x1) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word;
+
+ }
+
+ return ;
+}
+
+#endif /* SMALL_DCT */
+void idct_rowIntra(Short *blk, UChar *rec, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ int res, res2;
+ uint32 dst_word;
+
+ blk -= 8;
+ rec -= lx;
+
+ while (i--)
+ {
+ x1 = (int32)blk[12] << 8;
+ blk[12] = 0;
+ x2 = blk[14];
+ blk[14] = 0;
+ x3 = blk[10];
+ blk[10] = 0;
+ x4 = blk[9];
+ blk[9] = 0;
+ x5 = blk[15];
+ blk[15] = 0;
+ x6 = blk[13];
+ blk[13] = 0;
+ x7 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x8 = W7 * (x4 + x5) + 4;
+ x4 = (x8 + (W1 - W7) * x4) >> 3;
+ x5 = (x8 - (W1 + W7) * x5) >> 3;
+ x8 = W3 * (x6 + x7) + 4;
+ x6 = (x8 - (W3 - W5) * x6) >> 3;
+ x7 = (x8 - (W3 + W5) * x7) >> 3;
+
+ /* second stage */
+ x8 = x0 + x1;
+ x0 -= x1;
+ x1 = W6 * (x3 + x2) + 4;
+ x2 = (x1 - (W2 + W6) * x2) >> 3;
+ x3 = (x1 + (W2 - W6) * x3) >> 3;
+ x1 = x4 + x6;
+ x4 -= x6;
+ x6 = x5 + x7;
+ x5 -= x7;
+
+ /* third stage */
+ x7 = x8 + x3;
+ x8 -= x3;
+ x3 = x0 + x2;
+ x0 -= x2;
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x4 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ res = ((x7 + x1) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x3 + x2) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = res | (res2 << 8);
+ res = ((x0 + x4) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x8 + x6) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word;
+
+ res = ((x8 - x6) >> 14);
+ CLIP_RESULT(res)
+ res2 = ((x0 - x4) >> 14);
+ CLIP_RESULT(res2)
+ dst_word = res | (res2 << 8);
+ res = ((x3 - x2) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 16);
+ res = ((x7 - x1) >> 14);
+ CLIP_RESULT(res)
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word;
+ }
+ return;
+}
+
+
+/* This function should not be called at all ****/
+void idct_row0zmv(Short *srce, UChar *rec, UChar *pred, Int lx)
+{
+ OSCL_UNUSED_ARG(srce);
+ OSCL_UNUSED_ARG(rec);
+ OSCL_UNUSED_ARG(pred);
+ OSCL_UNUSED_ARG(lx);
+
+ return;
+}
+
+void idct_row1zmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int tmp;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ pred -= 16;
+ rec -= lx;
+ blk -= 8;
+
+ while (i--)
+ {
+ tmp = (*(blk += 8) + 32) >> 6;
+ *blk = 0;
+
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+ res = tmp + (pred_word & 0xFF);
+ CLIP_RESULT(res);
+ res2 = tmp + ((pred_word >> 8) & 0xFF);
+ CLIP_RESULT(res2);
+ dst_word = (res2 << 8) | res;
+ res = tmp + ((pred_word >> 16) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 16);
+ res = tmp + ((pred_word >> 24) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+ res = tmp + (pred_word & 0xFF);
+ CLIP_RESULT(res);
+ res2 = tmp + ((pred_word >> 8) & 0xFF);
+ CLIP_RESULT(res2);
+ dst_word = (res2 << 8) | res;
+ res = tmp + ((pred_word >> 16) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 16);
+ res = tmp + ((pred_word >> 24) & 0xFF);
+ CLIP_RESULT(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return;
+}
+
+void idct_row2zmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int32 x0, x1, x2, x4, x5;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ pred -= 16;
+ blk -= 8;
+
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+ res = (x0 + x4) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 + x5) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+ res = (x0 - x5) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 - x1) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x4) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+void idct_row3zmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ pred -= 16;
+ blk -= 8;
+
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x3 = x7;
+ x5 = (181 * (x1 - x7) + 128) >> 8;
+ x7 = (181 * (x1 + x7) + 128) >> 8;
+
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+ res = (x2 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+
+ return ;
+}
+
+void idct_row4zmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ pred -= 16;
+ blk -= 8;
+
+ while (i--)
+ {
+ x2 = blk[10];
+ blk[10] = 0;
+ x1 = blk[9];
+ blk[9] = 0;
+ x3 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ x4 = x0;
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x8 = x0 - x2;
+ x0 += x2;
+ x2 = x8;
+ x8 = x4 - x6;
+ x4 += x6;
+ x6 = x8;
+
+ x7 = (W7 * x1 + 4) >> 3;
+ x1 = (W1 * x1 + 4) >> 3;
+ x5 = (W3 * x3 + 4) >> 3;
+ x3 = (- W5 * x3 + 4) >> 3;
+ x8 = x1 - x5;
+ x1 += x5;
+ x5 = x8;
+ x8 = x7 - x3;
+ x3 += x7;
+ x7 = (181 * (x5 + x8) + 128) >> 8;
+ x5 = (181 * (x5 - x8) + 128) >> 8;
+
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+ res = (x0 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+ res = (x2 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+#ifndef SMALL_DCT
+void idct_row0x40zmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int32 x1, x2, x4, x5;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ pred -= 16;
+
+ while (i--)
+ {
+ /* shortcut */
+ x4 = blk[1];
+ blk[1] = 0;
+ blk += 8; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x5 = (W7 * x4 + 4) >> 3;
+ x4 = (W1 * x4 + 4) >> 3;
+
+ /* third stage */
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x1 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+ res = (8192 + x4) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 + x1) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 + x5) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+ res = (8192 - x5) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 - x1) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 - x4) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+void idct_row0x20zmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int32 x0, x2, x4, x6;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ pred -= 16;
+
+ while (i--)
+ {
+ x2 = blk[2];
+ blk[2] = 0;
+ blk += 8; /* for proper rounding in the fourth stage */
+ /* both upper and lower*/
+ /* both x2orx6 and x0orx4 */
+ x6 = (W6 * x2 + 4) >> 3;
+ x2 = (W2 * x2 + 4) >> 3;
+ x0 = 8192 + x2;
+ x2 = 8192 - x2;
+ x4 = 8192 + x6;
+ x6 = 8192 - x6;
+
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+ res = (x0) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x4) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x6) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x2) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+ res = (x2) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x6) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x4) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x0) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+
+ return ;
+}
+
+void idct_row0x10zmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int32 x1, x3, x5, x7;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ pred -= 16;
+
+ while (i--)
+ {
+ x3 = blk[3];
+ blk[3] = 0;
+ blk += 8;
+
+ x1 = (W3 * x3 + 4) >> 3;
+ x3 = (-W5 * x3 + 4) >> 3;
+
+ x7 = (-181 * (x3 + x1) + 128) >> 8;
+ x5 = (181 * (x3 - x1) + 128) >> 8;
+
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+ res = (8192 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 + x7) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 + x5) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 + x3) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+ res = (8192 - x3) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (8192 - x5) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (8192 - x7) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (8192 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return ;
+}
+
+#endif /* SMALL_DCT */
+
+void idct_rowzmv(Short *blk, UChar *rec, UChar *pred, Int lx)
+{
+ int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int i = 8;
+ uint32 pred_word, dst_word;
+ int res, res2;
+
+ /* preset the offset, such that we can take advantage pre-offset addressing mode */
+ rec -= lx;
+ pred -= 16;
+ blk -= 8;
+
+ while (i--)
+ {
+ x1 = (int32)blk[12] << 8;
+ blk[12] = 0;
+ x2 = blk[14];
+ blk[14] = 0;
+ x3 = blk[10];
+ blk[10] = 0;
+ x4 = blk[9];
+ blk[9] = 0;
+ x5 = blk[15];
+ blk[15] = 0;
+ x6 = blk[13];
+ blk[13] = 0;
+ x7 = blk[11];
+ blk[11] = 0;
+ x0 = ((*(blk += 8)) << 8) + 8192;
+ *blk = 0; /* for proper rounding in the fourth stage */
+
+ /* first stage */
+ x8 = W7 * (x4 + x5) + 4;
+ x4 = (x8 + (W1 - W7) * x4) >> 3;
+ x5 = (x8 - (W1 + W7) * x5) >> 3;
+ x8 = W3 * (x6 + x7) + 4;
+ x6 = (x8 - (W3 - W5) * x6) >> 3;
+ x7 = (x8 - (W3 + W5) * x7) >> 3;
+
+ /* second stage */
+ x8 = x0 + x1;
+ x0 -= x1;
+ x1 = W6 * (x3 + x2) + 4;
+ x2 = (x1 - (W2 + W6) * x2) >> 3;
+ x3 = (x1 + (W2 - W6) * x3) >> 3;
+ x1 = x4 + x6;
+ x4 -= x6;
+ x6 = x5 + x7;
+ x5 -= x7;
+
+ /* third stage */
+ x7 = x8 + x3;
+ x8 -= x3;
+ x3 = x0 + x2;
+ x0 -= x2;
+ x2 = (181 * (x4 + x5) + 128) >> 8;
+ x4 = (181 * (x4 - x5) + 128) >> 8;
+
+ /* fourth stage */
+ pred_word = *((uint32*)(pred += 16)); /* read 4 bytes from pred */
+
+ res = (x7 + x1) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x3 + x2) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x0 + x4) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x8 + x6) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec += lx)) = dst_word; /* save 4 bytes to dst */
+
+ pred_word = *((uint32*)(pred + 4)); /* read 4 bytes from pred */
+
+ res = (x8 - x6) >> 14;
+ ADD_AND_CLIP1(res);
+ res2 = (x0 - x4) >> 14;
+ ADD_AND_CLIP2(res2);
+ dst_word = (res2 << 8) | res;
+ res = (x3 - x2) >> 14;
+ ADD_AND_CLIP3(res);
+ dst_word |= (res << 16);
+ res = (x7 - x1) >> 14;
+ ADD_AND_CLIP4(res);
+ dst_word |= (res << 24);
+ *((uint32*)(rec + 4)) = dst_word; /* save 4 bytes to dst */
+ }
+ return;
+}
+
+/*----------------------------------------------------------------------------
+; End Function: idctcol
+----------------------------------------------------------------------------*/
+/* ======================================================================== */
+/* Function : BlockIDCTMotionComp */
+/* Date : 10/16/2000 */
+/* Purpose : fast IDCT routine */
+/* In/out : */
+/* Int* coeff_in Dequantized coefficient
+ Int block_out output IDCT coefficient
+ Int maxval clip value */
+/* Modified : 7/31/01, add checking for all-zero and DC-only block. */
+/* do 8 columns at a time */
+/* 8/2/01, do column first then row-IDCT. */
+/* 8/2/01, remove clipping (included in motion comp). */
+/* 8/7/01, combine with motion comp. */
+/* 8/8/01, use AAN IDCT */
+/* 9/4/05, use Chen's IDCT and 16 bit block */
+/* ======================================================================== */
+void BlockIDCTMotionComp(Short *block, UChar *bitmapcol, UChar bitmaprow,
+ Int dctMode, UChar *rec, UChar *pred, Int lx_intra)
+{
+ Int i;
+ Int tmp, tmp2;
+ ULong tmp4;
+ Int bmap;
+ Short *ptr = block;
+ UChar *endcol;
+ UInt mask = 0xFF;
+ Int lx = lx_intra >> 1;
+ Int intra = (lx_intra & 1);
+
+ /* all-zero block */
+ if (dctMode == 0 || bitmaprow == 0)
+ {
+ if (intra)
+ {
+ *((ULong*)rec) = *((ULong*)(rec + 4)) = 0;
+ *((ULong*)(rec += lx)) = 0;
+ *((ULong*)(rec + 4)) = 0;
+ *((ULong*)(rec += lx)) = 0;
+ *((ULong*)(rec + 4)) = 0;
+ *((ULong*)(rec += lx)) = 0;
+ *((ULong*)(rec + 4)) = 0;
+ *((ULong*)(rec += lx)) = 0;
+ *((ULong*)(rec + 4)) = 0;
+ *((ULong*)(rec += lx)) = 0;
+ *((ULong*)(rec + 4)) = 0;
+ *((ULong*)(rec += lx)) = 0;
+ *((ULong*)(rec + 4)) = 0;
+ *((ULong*)(rec += lx)) = 0;
+ *((ULong*)(rec + 4)) = 0;
+ return ;
+ }
+ else /* copy from previous frame */
+ {
+ *((ULong*)rec) = *((ULong*)pred);
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ *((ULong*)(rec += lx)) = *((ULong*)(pred += 16));
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ *((ULong*)(rec += lx)) = *((ULong*)(pred += 16));
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ *((ULong*)(rec += lx)) = *((ULong*)(pred += 16));
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ *((ULong*)(rec += lx)) = *((ULong*)(pred += 16));
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ *((ULong*)(rec += lx)) = *((ULong*)(pred += 16));
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ *((ULong*)(rec += lx)) = *((ULong*)(pred += 16));
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ *((ULong*)(rec += lx)) = *((ULong*)(pred += 16));
+ *((ULong*)(rec + 4)) = *((ULong*)(pred + 4));
+ return ;
+ }
+ }
+
+ /* Test for DC only block */
+ if (dctMode == 1 || (bitmaprow == 0x80 && bitmapcol[0] == 0x80))
+ {
+ i = ((block[0] << 3) + 32) >> 6;
+ block[0] = 0;
+ if (intra)
+ {
+ if ((UInt)i > mask) i = mask & (~(i >> 31));
+
+ tmp = i | (i << 8);
+ tmp |= (tmp << 16);
+
+ *((ULong*)rec) = *((ULong*)(rec + 4)) = tmp;
+ *((ULong*)(rec += lx)) = tmp;
+ *((ULong*)(rec + 4)) = tmp;
+ *((ULong*)(rec += lx)) = tmp;
+ *((ULong*)(rec + 4)) = tmp;
+ *((ULong*)(rec += lx)) = tmp;
+ *((ULong*)(rec + 4)) = tmp;
+ *((ULong*)(rec += lx)) = tmp;
+ *((ULong*)(rec + 4)) = tmp;
+ *((ULong*)(rec += lx)) = tmp;
+ *((ULong*)(rec + 4)) = tmp;
+ *((ULong*)(rec += lx)) = tmp;
+ *((ULong*)(rec + 4)) = tmp;
+ *((ULong*)(rec += lx)) = tmp;
+ *((ULong*)(rec + 4)) = tmp;
+
+ return ;
+ }
+ else
+ {
+ endcol = rec + (lx << 3);
+ do
+ {
+ tmp4 = *((ULong*)pred);
+ tmp2 = tmp4 & 0xFF;
+ tmp2 += i;
+ if ((UInt)tmp2 > mask) tmp2 = mask & (~(tmp2 >> 31));
+ tmp = (tmp4 >> 8) & 0xFF;
+ tmp += i;
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ tmp2 |= (tmp << 8);
+ tmp = (tmp4 >> 16) & 0xFF;
+ tmp += i;
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ tmp2 |= (tmp << 16);
+ tmp = (tmp4 >> 24) & 0xFF;
+ tmp += i;
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ tmp2 |= (tmp << 24);
+ *((ULong*)rec) = tmp2;
+
+ tmp4 = *((ULong*)(pred + 4));
+ tmp2 = tmp4 & 0xFF;
+ tmp2 += i;
+ if ((UInt)tmp2 > mask) tmp2 = mask & (~(tmp2 >> 31));
+ tmp = (tmp4 >> 8) & 0xFF;
+ tmp += i;
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ tmp2 |= (tmp << 8);
+ tmp = (tmp4 >> 16) & 0xFF;
+ tmp += i;
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ tmp2 |= (tmp << 16);
+ tmp = (tmp4 >> 24) & 0xFF;
+ tmp += i;
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ tmp2 |= (tmp << 24);
+ *((ULong*)(rec + 4)) = tmp2;
+
+ rec += lx;
+ pred += 16;
+ }
+ while (rec < endcol);
+ return ;
+ }
+ }
+
+ for (i = 0; i < dctMode; i++)
+ {
+ bmap = (Int)bitmapcol[i];
+ if (bmap)
+ {
+ if ((bmap&0xf) == 0)
+ (*(idctcolVCA[bmap>>4]))(ptr);
+ else
+ idct_col(ptr);
+ }
+ ptr++;
+ }
+
+ if ((bitmaprow&0xf) == 0)
+ {
+ if (intra)
+ (*(idctrowVCAIntra[(Int)(bitmaprow>>4)]))(block, rec, lx);
+ else
+ (*(idctrowVCAzmv[(Int)(bitmaprow>>4)]))(block, rec, pred, lx);
+ }
+ else
+ {
+ if (intra)
+ idct_rowIntra(block, rec, lx);
+ else
+ idct_rowzmv(block, rec, pred, lx);
+ }
+}
diff --git a/media/codecs/m4v_h263/enc/src/fastquant.cpp b/media/codecs/m4v_h263/enc/src/fastquant.cpp
new file mode 100644
index 0000000..466ce47
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/fastquant.cpp
@@ -0,0 +1,967 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4enc_lib.h"
+#include "fastquant_inline.h"
+
+#define siz 63
+#define LSL 18
+
+
+const static UChar imask[8] = {128, 64, 32, 16, 8, 4, 2, 1};
+#define SIGN0(a) ( ((a)<0) ? -1 : (((a)>0) ? 1 : 0) )
+
+/* variable bit precision quantization scale */
+/* used to avoid using 32-bit multiplication */
+const static Short scaleArrayV[32] = {0, 16384, 8192, 5462, /* 15 */
+ 4096, 3277, 2731, 2341,
+ 4096, 3641, 3277, 2979, /* 16 */
+ 2731, 2521, 2341, 2185,
+ 4096, 3856, 3641, 3450, /* 17 */
+ 3277, 3121, 2979, 2850,
+ 5462, 5243, 5042, 4855, /* 18 */
+ 4682, 4520, 4370, 4229
+ };
+
+/* scale for dc_scaler and qmat, note, no value smaller than 8 */
+const static Short scaleArrayV2[47] = {0, 0, 0, 0, 0, 0, 0, 0, /* 15 */
+ 4096, 3641, 3277, 2979, 2731, 2521, 2341, 2185,
+ 4096, 3856, 3641, 3450, 3277, 3121, 2979, 2850, /* 16 */
+ 2731, 2622, 2521, 2428, 2341, 2260, 2185, 2115,
+ 4096, 3972, 3856, 3745, 3641, 3543, 3450, 3361, /* 17 */
+ 3277, 3197, 3121, 3049, 2979, 2913, 2850
+ };
+
+/* AAN scale and zigzag */
+const static Short AANScale[64] =
+{
+ /* 0 */ 0x1000, 0x0B89, 0x0C3E, 0x0D9B, 0x1000, 0x0A2E, 0x0EC8, 0x0E7F,
+ /* 1 */ 0x0B89, 0x0851, 0x08D4, 0x09CF, 0x0B89, 0x0757, 0x0AA8, 0x0A73,
+ /* 2 */ 0x0C3E, 0x08D4, 0x095F, 0x0A6A, 0x0C3E, 0x07CB, 0x0B50, 0x0B18,
+ /* 3 */ 0x0D9B, 0x09CF, 0x0A6A, 0x0B92, 0x0D9B, 0x08A8, 0x0C92, 0x0C54,
+ /* 4 */ 0x1000, 0x0B89, 0x0C3E, 0x0D9B, 0x1000, 0x0A2E, 0x0EC8, 0x0E7F,
+ /* 5 */ 0x0A2E, 0x0757, 0x07CB, 0x08A8, 0x0A2E, 0x067A, 0x0968, 0x0939,
+ /* 6 */ 0x0EC8, 0x0AA8, 0x0B50, 0x0C92, 0x0EC8, 0x0968, 0x0DA8, 0x0D64,
+ /* 7 */ 0x0E7F, 0x0A73, 0x0B18, 0x0C54, 0x0E7F, 0x0939, 0x0D64, 0x0D23
+};
+
+const static UShort ZZTab[64] =
+{
+ /* 0 */ 0x0, 0x2, 0xA, 0xC, 0x1C, 0x1E, 0x36, 0x38,
+ /* 1 */ 0x4, 0x8, 0xE, 0x1A, 0x20, 0x34, 0x3A, 0x54,
+ /* 2 */ 0x6, 0x10, 0x18, 0x22, 0x32, 0x3C, 0x52, 0x56,
+ /* 3 */ 0x12, 0x16, 0x24, 0x30, 0x3E, 0x50, 0x58, 0x6A,
+ /* 4 */ 0x14, 0x26, 0x2E, 0x40, 0x4E, 0x5A, 0x68, 0x6C,
+ /* 5 */ 0x28, 0x2C, 0x42, 0x4C, 0x5C, 0x66, 0x6E, 0x78,
+ /* 6 */ 0x2A, 0x44, 0x4A, 0x5E, 0x64, 0x70, 0x76, 0x7A,
+ /* 7 */ 0x46, 0x48, 0x60, 0x62, 0x72, 0x74, 0x7C, 0x7E
+};
+
+
+//Tao need to remove, write another version of abs
+//#include <math.h>
+
+/* ======================================================================== */
+/* Function : cal_dc_scalerENC */
+/* Date : 01/25/2000 */
+/* Purpose : calculation of DC quantization scale according to the
+ incoming Q and type; */
+/* In/out : */
+/* Int Qp Quantizer */
+/* Return : */
+/* DC Scaler */
+/* Modified : */
+/* ======================================================================== */
+/* ======================================================================== */
+Int cal_dc_scalerENC(Int QP, Int type)
+{
+
+ Int dc_scaler;
+ if (type == 1)
+ {
+ if (QP > 0 && QP < 5)
+ dc_scaler = 8;
+ else if (QP > 4 && QP < 9)
+ dc_scaler = 2 * QP;
+ else if (QP > 8 && QP < 25)
+ dc_scaler = QP + 8;
+ else
+ dc_scaler = 2 * QP - 16;
+ }
+ else
+ {
+ if (QP > 0 && QP < 5)
+ dc_scaler = 8;
+ else if (QP > 4 && QP < 25)
+ dc_scaler = (QP + 13) / 2;
+ else
+ dc_scaler = QP - 6;
+ }
+ return dc_scaler;
+}
+
+
+/***********************************************************************
+ Function: BlckQuantDequantH263
+ Date: June 15, 1999
+ Purpose: Combine BlockQuantH263 and BlockDequantH263ENC
+ Input: coeff=> DCT coefficient
+ Output: qcoeff=> quantized coefficient
+ rcoeff=> reconstructed coefficient
+ return CBP for this block
+ 4/2/01, correct dc_scaler for short_header mode.
+ 5/14/01,
+ changed the division into LUT multiplication/shift and other
+ modifications to speed up fastQuant/DeQuant (check for zero 1st, rowq LUT,
+ fast bitmaprow mask and borrowed Addition method instead of ifs from , ).
+ 6/25/01,
+ Further optimization (~100K/QCIF), need more testing/comment before integration.
+
+ 7/4/01, break up Inter / Intra function and merge for different cases.
+ 7/22/01, combine AAN scaling here and reordering.
+ 7/24/01, , reorder already done in FDCT, the input here is in the next block and
+ it's the
+ transpose of the raster scan. Output the same order (for proof of concenpt).
+ 8/1/01, , change FDCT to do row/column FDCT without reordering, input is still
+ in the next block. The reconstructed DCT output is current block in normal
+ order. The quantized output is in zigzag scan order for INTER, row/column for
+ INTRA. Use bitmapzz for zigzag RunLevel for INTER. The quantization is done
+ in column/row scanning order.
+ 8/2/01, , change IDCT to do column/row, change bitmaprow/col to the opposite.
+ 8/3/01, , add clipping to the reconstructed coefficient [-2047,2047]
+ 9/4/05, , removed scaling for AAN IDCT, use Chen IDCT instead.
+ ********************************************************************/
+
+Int BlockQuantDequantH263Inter(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dummy, UChar shortHeader)
+{
+ Int i, zz;
+ Int tmp, coeff, q_value;
+ Int QPdiv2 = QuantParam->QPdiv2;
+ Int QPx2 = QuantParam->QPx2;
+ Int Addition = QuantParam->Addition;
+ Int QPx2plus = QuantParam->QPx2plus;
+ Int round = 1 << 15;
+ Int q_scale = scaleArrayV[QuantParam->QP];
+ Int shift = 15 + (QPx2 >> 4);
+ Int *temp;
+ UChar *bcolptr = bitmapcol;
+ Int ac_clip; /* quantized coeff bound */
+
+ OSCL_UNUSED_ARG(comp);
+ OSCL_UNUSED_ARG(dummy);
+
+
+ if (shortHeader) ac_clip = 126; /* clip between [-127,126] (standard allows 127!) */
+ else ac_clip = 2047; /* clip between [-2048,2047] */
+
+ /* reset all bitmap to zero */
+ temp = (Int*) bitmapcol;
+ temp[0] = temp[1] = 0;
+ bitmapzz[0] = bitmapzz[1] = 0;
+ *bitmaprow = 0;
+ QPx2plus <<= 4;
+ QPx2plus -= 8;
+
+ rcoeff += 64; /* actual data is 64 item ahead */
+ //end = rcoeff + dctMode - 1;
+ //rcoeff--;
+ bcolptr--;
+ i = 0;
+
+ do
+ {
+ bcolptr++;
+ //rcoeff++;
+ //i=0;
+ coeff = rcoeff[i];
+ if (coeff == 0x7fff) /* all zero column */
+ {
+ i++;
+ continue;
+ }
+
+ do
+ {
+ if (coeff >= -QPx2plus && coeff < QPx2plus) /* quantize to zero */
+ {
+ i += 8;
+ if (i < (dctMode << 3))
+ {
+ coeff = rcoeff[i];
+ if (coeff > -QPx2plus && coeff < QPx2plus) /* quantize to zero */
+ {
+ i += 8;
+ coeff = rcoeff[i];
+ continue;
+ }
+ else
+ goto NONZERO1;
+ }
+ }
+ else
+ {
+NONZERO1:
+ /* scaling */
+ q_value = AANScale[i]; /* load scale AAN */
+ zz = ZZTab[i]; /* zigzag order */
+
+ coeff = aan_scale(q_value, coeff, round, QPdiv2);
+ q_value = coeff_quant(coeff, q_scale, shift);
+
+ /* dequantization */
+ if (q_value)
+ {
+
+ //coeff = PV_MIN(ac_clip,PV_MAX(-ac_clip-1, q_value));
+ q_value = coeff_clip(q_value, ac_clip);
+ qcoeff[zz>>1] = q_value;
+
+ // dequant and clip
+ //coeff = PV_MIN(2047,PV_MAX(-2048, q_value));
+ tmp = 2047;
+ coeff = coeff_dequant(q_value, QPx2, Addition, tmp);
+ rcoeff[i-64] = coeff;
+
+ (*bcolptr) |= imask[i>>3];
+ if ((zz >> 1) > 31) bitmapzz[1] |= (1 << (63 - (zz >> 1)));
+ else bitmapzz[0] |= (1 << (31 - (zz >> 1)));
+ }
+ i += 8;
+ coeff = rcoeff[i];
+ }
+ }
+ while (i < (dctMode << 3));
+
+ i += (1 - (dctMode << 3));
+ }
+ while (i < dctMode) ;
+
+ i = dctMode;
+ tmp = 1 << (8 - i);
+ while (i--)
+ {
+ if (bitmapcol[i])(*bitmaprow) |= tmp;
+ tmp <<= 1;
+ }
+
+ if (*bitmaprow)
+ return 1;
+ else
+ return 0;
+}
+
+Int BlockQuantDequantH263Intra(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dc_scaler, UChar shortHeader)
+{
+ Int i;
+ Int tmp, coeff, q_value;
+ Int QPx2 = QuantParam->QPx2;
+ Int Addition = QuantParam->Addition;
+ Int QPx2plus = QuantParam->QPx2plus;
+ Int round = 1 << 15;
+ Int q_scale = scaleArrayV[QuantParam->QP];
+ Int shift = 15 + (QPx2 >> 4);
+ UChar *bmcolptr = bitmapcol;
+ Int ac_clip; /* quantized coeff bound */
+
+ OSCL_UNUSED_ARG(bitmapzz);
+ OSCL_UNUSED_ARG(comp);
+
+
+ if (shortHeader) ac_clip = 126; /* clip between [-127,126] (standard allows 127!) */
+ else ac_clip = 2047; /* clip between [-2048,2047] */
+
+ *((Int*)bitmapcol) = *((Int*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+
+ QPx2plus = QPx2 << 4;
+ QPx2plus -= 8;
+
+ rcoeff += 64; /* actual data is 64 element ahead */
+ i = 0;
+
+ /* DC value */
+ coeff = *rcoeff;
+ /* scaling */
+ if (coeff == 0x7fff && !shortHeader) /* all zero column */
+ {
+ bmcolptr++;
+ i++;
+ }
+ else
+ {
+ if (coeff == 0x7fff) /* shortHeader on */
+ {
+ coeff = 1; /* can't be zero */
+ qcoeff[0] = coeff;
+ coeff = coeff * dc_scaler;
+ coeff = PV_MAX(-2048, PV_MIN(2047, coeff));
+ rcoeff[-64] = coeff;
+ bitmapcol[0] |= 128;
+ bmcolptr++;
+ //qcoeff++;
+ //rcoeff++;
+ //i=0;
+ i++;
+ }
+ else
+ {
+ q_value = round + (coeff << 12);
+ coeff = q_value >> 16;
+ if (coeff >= 0) coeff += (dc_scaler >> 1) ;
+ else coeff -= (dc_scaler >> 1) ;
+ q_value = scaleArrayV2[dc_scaler];
+ coeff = coeff * q_value;
+ coeff >>= (15 + (dc_scaler >> 4));
+ coeff += ((UInt)coeff >> 31);
+
+ if (shortHeader)
+ coeff = PV_MAX(1, PV_MIN(254, coeff));
+
+ if (coeff)
+ {
+ qcoeff[0] = coeff;
+ coeff = coeff * dc_scaler;
+ coeff = PV_MAX(-2048, PV_MIN(2047, coeff));
+ rcoeff[-64] = coeff;
+ bitmapcol[0] |= 128;
+ }
+ i += 8;
+ }
+ }
+ /* AC values */
+ do
+ {
+ coeff = rcoeff[i];
+ if (coeff == 0x7fff) /* all zero row */
+ {
+ bmcolptr++;
+ i++;
+ continue;
+ }
+ do
+ {
+ if (coeff >= -QPx2plus && coeff < QPx2plus) /* quantize to zero */
+ {
+ i += 8;
+ if (i < dctMode << 3)
+ {
+ coeff = rcoeff[i];
+ if (coeff > -QPx2plus && coeff < QPx2plus) /* quantize to zero */
+ {
+ i += 8;
+ coeff = rcoeff[i];
+ continue;
+ }
+ else
+ goto NONZERO2;
+ }
+ }
+ else
+ {
+NONZERO2: /* scaling */
+ q_value = AANScale[i]; /* 09/02/05 */
+
+ /* scale aan */
+ q_value = smlabb(q_value, coeff, round);
+ coeff = q_value >> 16;
+ /* quant */
+ q_value = smulbb(q_scale, coeff); /*mov q_value, coeff, lsl #14 */
+ /*smull tmp, coeff, q_value, q_scale*/
+ q_value >>= shift;
+ q_value += ((UInt)q_value >> 31); /* add 1 if negative */
+
+ if (q_value)
+ {
+ //coeff = PV_MIN(ac_clip,PV_MAX(-ac_clip-1, q_value));
+ q_value = coeff_clip(q_value, ac_clip);
+ qcoeff[i] = q_value;
+
+ // dequant and clip
+ //coeff = PV_MIN(2047,PV_MAX(-2048, q_value));
+ tmp = 2047;
+ coeff = coeff_dequant(q_value, QPx2, Addition, tmp);
+ rcoeff[i-64] = coeff;
+
+ (*bmcolptr) |= imask[i>>3];
+ }
+ i += 8;
+ coeff = rcoeff[i];
+ }
+ }
+ while (i < (dctMode << 3)) ;
+
+ //qcoeff++; /* next column */
+ bmcolptr++;
+ //rcoeff++;
+ i += (1 - (dctMode << 3)); //i = 0;
+ }
+ while (i < dctMode);//while(rcoeff < end) ;
+
+ i = dctMode;
+ tmp = 1 << (8 - i);
+ while (i--)
+ {
+ if (bitmapcol[i])(*bitmaprow) |= tmp;
+ tmp <<= 1;
+ }
+
+ if (((*bitmaprow)&127) || (bitmapcol[0]&127)) /* exclude DC */
+ return 1;
+ else
+ return 0;
+}
+
+
+/***********************************************************************
+ Function: BlckQuantDequantH263DC
+ Date: 5/3/2001
+ Purpose: H.263 quantization mode, only for DC component
+ 6/25/01,
+ Further optimization (~100K/QCIF), need more testing/comment before integration.
+
+ ********************************************************************/
+Int BlockQuantDequantH263DCInter(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar *bitmaprow, UInt *bitmapzz, Int dummy, UChar shortHeader)
+{
+ Int coeff, scale_q;
+ Int CBP = 0;
+ Int QP = QuantParam->QP;
+ Int QPx2plus = QuantParam->QPx2plus;
+ Int Addition = QuantParam->Addition;
+ Int shift = 15 + (QP >> 3);
+ Int ac_clip; /* quantized coeff bound */
+ Int tmp;
+
+ OSCL_UNUSED_ARG(dummy);
+
+ if (shortHeader) ac_clip = 126; /* clip between [-127,126] (standard allows 127!) */
+ else ac_clip = 2047; /* clip between [-2048,2047] */
+
+ *bitmaprow = 0;
+ bitmapzz[0] = bitmapzz[1] = 0;
+ coeff = rcoeff[0];
+
+ if (coeff >= -QPx2plus && coeff < QPx2plus)
+ {
+ rcoeff[0] = 0;
+ return CBP;//rcoeff[0] = 0; not needed since CBP will be zero
+ }
+ else
+ {
+ scale_q = scaleArrayV[QP];
+
+ coeff = aan_dc_scale(coeff, QP);
+
+ scale_q = coeff_quant(coeff, scale_q, shift);
+
+ //coeff = PV_MIN(ac_clip,PV_MAX(-ac_clip-1, tmp));
+ scale_q = coeff_clip(scale_q, ac_clip);
+
+ qcoeff[0] = scale_q;
+
+ QP <<= 1;
+ //coeff = PV_MIN(2047,PV_MAX(-2048, tmp));
+ tmp = 2047;
+ coeff = coeff_dequant(scale_q, QP, Addition, tmp);
+
+ rcoeff[0] = coeff;
+
+ (*bitmaprow) = 128;
+ bitmapzz[0] = (ULong)1 << 31;
+ CBP = 1;
+ }
+ return CBP;
+}
+
+
+Int BlockQuantDequantH263DCIntra(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar *bitmaprow, UInt *bitmapzz, Int dc_scaler, UChar shortHeader)
+{
+ Int tmp, coeff;
+
+ OSCL_UNUSED_ARG(QuantParam);
+
+ *bitmaprow = 0;
+ coeff = rcoeff[0];
+
+ if (coeff >= 0) coeff += (dc_scaler >> 1) ;
+ else coeff -= (dc_scaler >> 1) ;
+ tmp = scaleArrayV2[dc_scaler];
+ tmp = coeff * tmp;
+ tmp >>= (15 + (dc_scaler >> 4));
+ tmp += ((UInt)tmp >> 31);
+
+ if (shortHeader)
+ tmp = PV_MAX(1, PV_MIN(254, tmp));
+
+ if (tmp)
+ {
+ qcoeff[0] = tmp;
+ coeff = tmp * dc_scaler;
+ coeff = PV_MAX(-2048, PV_MIN(2047, coeff));
+ rcoeff[0] = coeff;
+ *bitmaprow = 128;
+ bitmapzz[0] = (ULong)1 << 31;
+ }
+
+ return 0;
+}
+
+#ifndef NO_MPEG_QUANT
+/***********************************************************************
+ Function: BlckQuantDequantMPEG
+ Date: June 15, 1999
+ Purpose: Combine BlockQuantMPEG and BlockDequantMPEGENC
+ Input: coeff=> DCT coefficient
+ Output: qcoeff=> quantized coefficient
+ rcoeff=> reconstructed coefficient
+ Modified: 7/5/01, break up function for Intra/Inter
+ 8/3/01, update with changes from H263 quant mode.
+ 8/3/01, add clipping to the reconstructed coefficient [-2048,2047]
+ 8/6/01, optimize using multiplicative lookup-table.
+ can be further optimized using ARM assembly, e.g.,
+ clipping, 16-bit mult., etc !!!!!!!!!!!!!
+ ********************************************************************/
+
+Int BlockQuantDequantMPEGInter(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dc_scaler)
+{
+ Int i, zz;
+ Int tmp, coeff, q_value = 0;
+ Int sum = 0;
+ Int stepsize, QPx2 = QP << 1;
+ Int CBP = 0;
+ Int round = 1 << 15;
+ Int q_scale = scaleArrayV[QP];
+ Int shift = 15 + (QP >> 3);
+ UChar *bcolptr = bitmapcol;
+
+ OSCL_UNUSED_ARG(dc_scaler);
+ OSCL_UNUSED_ARG(comp);
+
+
+ *((Int*)bitmapcol) = *((Int*)(bitmapcol + 4)) = 0;
+ bitmapzz[0] = bitmapzz[1] = 0;
+ *bitmaprow = 0;
+
+ rcoeff += 64;
+ i = 0;
+ bcolptr--;
+
+ do
+ {
+ bcolptr++;
+ coeff = rcoeff[i];
+ if (coeff == 0x7fff) /* all zero column */
+ {
+ i++;
+ continue;
+ }
+ do
+ {
+ q_value = AANScale[i]; /* 09/02/05 scaling for AAN*/
+ /* aan scaling */
+ q_value = smlabb(q_value, coeff, round);
+
+ coeff = q_value >> 16;
+
+ stepsize = qmat[i];
+// if(coeff>0) coeff = (16*coeff + (stepsize/2)) / stepsize;
+// else coeff = (16*coeff - (stepsize/2)) / stepsize;
+ coeff <<= 4;
+ if (coeff >= 0) coeff += (stepsize >> 1) ;
+ else coeff -= (stepsize >> 1) ;
+ q_value = scaleArrayV2[stepsize];
+ /* mpeg quant table scale */
+ coeff = smulbb(coeff, q_value);
+
+ coeff >>= (15 + (stepsize >> 4));
+ coeff += ((UInt)coeff >> 31);
+
+ /* QP scale */
+ if (coeff >= -QPx2 && coeff < QPx2) /* quantized to zero*/
+ {
+ i += 8;
+ }
+ else
+ {
+// q_value = coeff/(QPx2);
+ q_value = coeff_quant(coeff, q_scale, shift);
+
+ if (q_value) /* dequant */
+ {
+
+ zz = ZZTab[i]; /* zigzag order */
+
+ tmp = 2047;
+
+ q_value = clip_2047(q_value, tmp);
+
+ qcoeff[zz>>1] = q_value;
+
+ //q_value=(((coeff*2)+SIGN0(coeff))*stepsize*QP)/16;
+ /* no need for SIGN0, no zero coming in this {} */
+ q_value = coeff_dequant_mpeg(q_value, stepsize, QP, tmp);
+
+ rcoeff[i-64] = q_value;
+
+ sum += q_value;
+ (*bcolptr) |= imask[i>>3];
+ if ((zz >> 1) > 31) bitmapzz[1] |= (1 << (63 - (zz >> 1)));
+ else bitmapzz[0] |= (1 << (31 - (zz >> 1)));
+ }
+ i += 8;
+ }
+ coeff = rcoeff[i];
+ }
+ while (i < (dctMode << 3)) ;
+
+ i += (1 - (dctMode << 3));
+ }
+ while (i < dctMode) ;
+
+ i = dctMode;
+ tmp = 1 << (8 - i);
+ while (i--)
+ {
+ if (bitmapcol[i])(*bitmaprow) |= tmp;
+ tmp <<= 1;
+ }
+
+ if (*bitmaprow)
+ CBP = 1; /* check CBP before mismatch control, 7/5/01 */
+
+ /* Mismatch control, 5/3/01 */
+ if (CBP)
+ {
+ if ((sum&0x1) == 0)
+ {
+ rcoeff--; /* rcoeff[63] */
+ coeff = *rcoeff;
+ coeff ^= 0x1;
+ *rcoeff = coeff;
+ if (coeff)
+ {
+ bitmapcol[7] |= 1;
+ (*bitmaprow) |= 1;
+ }
+ }
+ }
+
+ return CBP;
+}
+
+Int BlockQuantDequantMPEGIntra(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dc_scaler)
+{
+ Int i;
+ Int tmp, coeff, q_value = 0;
+ Int sum = 0;
+ Int stepsize;
+ Int CBP = 0;
+ Int round = 1 << 15;
+ Int q_scale = scaleArrayV[QP];
+ Int shift = 15 + (QP >> 3);
+ Int round2 = (3 * QP + 2) >> 2;
+ Int QPx2plus = (QP << 1) - round2;
+ UChar *bmcolptr = bitmapcol;
+
+ OSCL_UNUSED_ARG(bitmapzz);
+ OSCL_UNUSED_ARG(comp);
+
+ *((Int*)bitmapcol) = *((Int*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+
+ rcoeff += 64;
+ i = 0;
+
+ /* DC value */
+ coeff = *rcoeff;
+
+ if (coeff == 0x7fff) /* all zero column */
+ {
+ bmcolptr++;
+ i++;
+ }
+ else
+ {
+ q_value = round + (coeff << 12);
+ coeff = q_value >> 16;
+ /*if (coeff >= 0) coeff = (coeff + (dc_scaler/2)) / dc_scaler;
+ else coeff = (coeff - (dc_scaler/2)) / dc_scaler;*/
+ if (coeff >= 0) coeff += (dc_scaler >> 1) ;
+ else coeff -= (dc_scaler >> 1) ;
+ q_value = scaleArrayV2[dc_scaler];
+
+ /* mpeg quant table scale */
+ coeff = smulbb(coeff, q_value);
+
+ coeff >>= (15 + (dc_scaler >> 4));
+ coeff += ((UInt)coeff >> 31);
+
+ if (coeff)
+ {
+ coeff = PV_MAX(1, PV_MIN(254, coeff));
+ qcoeff[0] = coeff;
+
+ coeff = smulbb(coeff, dc_scaler);
+
+ q_value = clip_2047(coeff, 2047);
+
+ sum = q_value;
+
+ rcoeff[-64] = q_value;
+
+ bitmapcol[0] |= 128;
+ }
+ i += 8;
+ }
+ /* AC values */
+ do
+ {
+ coeff = rcoeff[i];
+ if (coeff == 0x7fff) /* all zero row */
+ {
+ bmcolptr++;
+ i++;
+ continue;
+ }
+ do
+ {
+ /* scaling */
+ q_value = AANScale[i]; /* 09/02/05 */
+
+ /* q_value = coeff*q_value + round */
+ q_value = smlabb(coeff, q_value, round);
+ coeff = q_value >> 16;
+
+ stepsize = qmat[i];
+ /*if(coeff>0) coeff = (16*coeff + (stepsize/2)) / stepsize;
+ else coeff = (16*coeff - (stepsize/2)) / stepsize;*/
+ coeff <<= 4;
+ if (coeff >= 0) coeff += (stepsize >> 1) ;
+ else coeff -= (stepsize >> 1) ;
+ q_value = scaleArrayV2[stepsize];
+
+ /* scale mpeg quant */
+ coeff = smulbb(coeff, q_value);
+
+ coeff >>= (15 + (stepsize >> 4));
+ coeff += ((UInt)coeff >> 31);
+
+ if (coeff >= -QPx2plus && coeff < QPx2plus)
+ {
+ i += 8;
+ }
+ else
+ {
+ //q_value = ( coeff + SIGN0(coeff)*((3*QP+2)/4))/(2*QP);
+ if (coeff > 0) coeff += round2;
+ else if (coeff < 0) coeff -= round2;
+
+ q_value = smulbb(coeff, q_scale);
+ q_value >>= shift;
+ q_value += ((UInt)q_value >> 31);
+
+ if (q_value)
+ {
+ tmp = 2047;
+ q_value = clip_2047(q_value, tmp);
+
+ qcoeff[i] = q_value;
+
+ stepsize = smulbb(stepsize, QP);
+ q_value = smulbb(q_value, stepsize);
+
+ q_value = coeff_dequant_mpeg_intra(q_value, tmp);
+ //q_value = (coeff*stepsize*QP*2)/16;
+
+ rcoeff[i-64] = q_value;
+
+ sum += q_value;
+ (*bmcolptr) |= imask[i>>3];
+ }
+ i += 8;
+ }
+ coeff = rcoeff[i];
+ }
+ while (i < (dctMode << 3)) ;
+
+ bmcolptr++;
+ i += (1 - (dctMode << 3));
+ }
+ while (i < dctMode) ;
+
+ i = dctMode;
+ tmp = 1 << (8 - i);
+ while (i--)
+ {
+ if (bitmapcol[i])(*bitmaprow) |= tmp;
+ tmp <<= 1;
+ }
+
+ if (((*bitmaprow) &127) || (bitmapcol[0]&127))
+ CBP = 1; /* check CBP before mismatch control, 7/5/01 */
+
+ /* Mismatch control, 5/3/01 */
+ if (CBP || bitmapcol[0])
+ {
+ if ((sum&0x1) == 0)
+ {
+ rcoeff--; /* rcoeff[63] */
+ coeff = *rcoeff;
+ coeff ^= 0x1;
+ *rcoeff = coeff;
+ if (coeff)
+ {
+ bitmapcol[7] |= 1;
+ (*bitmaprow) |= 1;
+ }
+ }
+ }
+
+ return CBP;
+}
+
+
+/***********************************************************************
+ Function: BlckQuantDequantMPEGDC
+ Date: 5/3/2001
+ Purpose: MPEG Quant/Dequant for DC only block.
+ ********************************************************************/
+Int BlockQuantDequantMPEGDCInter(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, Int dummy)
+{
+ Int q_value, coeff, stepsize;
+ Int CBP = 0;
+ Int q_scale = scaleArrayV[QP];
+ Int shift = 15 + (QP >> 3);
+ Int QPx2 = QP << 1;
+
+ OSCL_UNUSED_ARG(dummy);
+
+ *((Int*)bitmapcol) = *((Int*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+ bitmapzz[0] = bitmapzz[1] = 0;
+ coeff = rcoeff[0];
+ stepsize = qmat[0];
+
+ /*if(coeff>0) coeff = (16*coeff + (stepsize/2)) / stepsize;
+ else coeff = (16*coeff - (stepsize/2)) / stepsize;*/
+ coeff <<= 4;
+ if (coeff >= 0) coeff += (stepsize >> 1) ;
+ else coeff -= (stepsize >> 1) ;
+ q_value = scaleArrayV2[stepsize];
+
+ coeff = smulbb(coeff, q_value);
+
+ coeff >>= (15 + (stepsize >> 4));
+ coeff += ((UInt)coeff >> 31);
+
+ if (coeff >= -QPx2 && coeff < QPx2)
+ {
+ rcoeff[0] = 0;
+ return CBP;
+ }
+ else
+ {
+// q_value = coeff/(QPx2);
+ q_value = coeff_quant(coeff, q_scale, shift);
+
+ if (q_value)
+ {
+
+ //PV_MIN(2047,PV_MAX(-2048, q_value));
+ q_value = clip_2047(q_value, 2047);
+ qcoeff[0] = q_value;
+ q_value = coeff_dequant_mpeg(q_value, stepsize, QP, 2047);
+ //q_value=(((coeff*2)+SIGN0(coeff))*stepsize*QP)/16;
+ rcoeff[0] = q_value;
+
+ bitmapcol[0] = 128;
+ (*bitmaprow) = 128;
+ bitmapzz[0] = (UInt)1 << 31;
+ CBP = 1;
+
+ /* Mismatch control, 5/3/01 */
+ if ((q_value&0x1) == 0)
+ {
+ rcoeff[63] = 1; /* after scaling it remains the same */
+ bitmapcol[7] |= 1;
+ (*bitmaprow) |= 1;
+ }
+ }
+ }
+ return CBP;
+}
+
+
+Int BlockQuantDequantMPEGDCIntra(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dc_scaler)
+{
+ Int tmp, coeff, q_value;
+
+ OSCL_UNUSED_ARG(QP);
+ OSCL_UNUSED_ARG(qmat);
+
+
+ *((Int*)bitmapcol) = *((Int*)(bitmapcol + 4)) = 0;
+ *bitmaprow = 0;
+ coeff = rcoeff[0];
+
+ /*if (coeff >= 0) tmp = (coeff + dc_scaler/2) / dc_scaler;
+ else tmp = (coeff - dc_scaler/2) / dc_scaler;*/
+ if (coeff >= 0) coeff += (dc_scaler >> 1) ;
+ else coeff -= (dc_scaler >> 1) ;
+ tmp = scaleArrayV2[dc_scaler];
+
+ tmp = smulbb(tmp, coeff);
+ tmp >>= (15 + (dc_scaler >> 4));
+ tmp += ((UInt)tmp >> 31);
+
+ if (tmp)
+ {
+ coeff = PV_MAX(1, PV_MIN(254, tmp));
+ qcoeff[0] = coeff;
+
+ q_value = smulbb(coeff, dc_scaler);
+ q_value = clip_2047(q_value, 2047);
+ rcoeff[0] = q_value;
+ bitmapcol[0] = 128;
+ *bitmaprow = 128;
+ bitmapzz[0] = (UInt)1 << 31;
+
+ /* Mismatch control, 5/3/01 */
+ if ((q_value&0x1) == 0)
+ {
+ rcoeff[63] = 1; /* after scaling it remains the same */
+ bitmapcol[7] |= 1;
+ (*bitmaprow) |= 1;
+ }
+ }
+
+ return 0;
+}
+#endif
+
diff --git a/media/codecs/m4v_h263/enc/src/fastquant_inline.h b/media/codecs/m4v_h263/enc/src/fastquant_inline.h
new file mode 100644
index 0000000..79d0ebf
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/fastquant_inline.h
@@ -0,0 +1,625 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*********************************************************************************/
+/* Filename: fastquant_inline.h */
+/* Description: Implementation for in-line functions used in dct.cpp */
+/* Modified: */
+/*********************************************************************************/
+#ifndef _FASTQUANT_INLINE_H_
+#define _FASTQUANT_INLINE_H_
+
+#include "mp4def.h"
+
+#if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) /* ARM GNU COMPILER */
+
+__inline int32 aan_scale(int32 q_value, int32 coeff, int32 round, int32 QPdiv2)
+{
+ q_value = coeff * q_value + round;
+ coeff = q_value >> 16;
+ if (coeff < 0) coeff += QPdiv2;
+ else coeff -= QPdiv2;
+
+ return coeff;
+}
+
+
+__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
+{
+ int32 q_value;
+
+ q_value = coeff * q_scale; //q_value = -((-(coeff + QPdiv2)*q_scale)>>LSL);
+ q_value >>= shift; //q_value = (((coeff - QPdiv2)*q_scale)>>LSL );
+ q_value += ((UInt)q_value >> 31); /* add one if negative */
+
+ return q_value;
+}
+
+__inline int32 coeff_clip(int32 q_value, int32 ac_clip)
+{
+ int32 coeff = q_value + ac_clip;
+
+ if ((UInt)coeff > (UInt)(ac_clip << 1))
+ q_value = ac_clip ^(q_value >> 31);
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
+{
+ int32 coeff;
+
+ OSCL_UNUSED_ARG(tmp);
+
+ if (q_value < 0)
+ {
+ coeff = q_value * QPx2 - Addition;
+ if (coeff < -2048)
+ coeff = -2048;
+ }
+ else
+ {
+ coeff = q_value * QPx2 + Addition;
+ if (coeff > 2047)
+ coeff = 2047;
+ }
+ return coeff;
+}
+
+__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
+{
+ q_value = coeff * q_value + round;
+
+ return q_value;
+}
+
+__inline int32 smulbb(int32 q_scale, int32 coeff)
+{
+ int32 q_value;
+
+ q_value = coeff * q_scale;
+
+ return q_value;
+}
+
+__inline int32 aan_dc_scale(int32 coeff, int32 QP)
+{
+
+ if (coeff < 0) coeff += (QP >> 1);
+ else coeff -= (QP >> 1);
+
+ return coeff;
+}
+
+__inline int32 clip_2047(int32 q_value, int32 tmp)
+{
+ OSCL_UNUSED_ARG(tmp);
+
+ if (q_value < -2048)
+ {
+ q_value = -2048;
+ }
+ else if (q_value > 2047)
+ {
+ q_value = 2047;
+ }
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
+{
+ int32 coeff;
+
+ OSCL_UNUSED_ARG(tmp);
+
+ coeff = q_value << 1;
+ stepsize *= QP;
+ if (coeff > 0)
+ {
+ q_value = (coeff + 1) * stepsize;
+ q_value >>= 4;
+ if (q_value > 2047) q_value = 2047;
+ }
+ else
+ {
+ q_value = (coeff - 1) * stepsize;
+ q_value += 15;
+ q_value >>= 4;
+ if (q_value < -2048) q_value = -2048;
+ }
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant_mpeg_intra(int32 q_value, int32 tmp)
+{
+ OSCL_UNUSED_ARG(tmp);
+
+ q_value <<= 1;
+ if (q_value > 0)
+ {
+ q_value >>= 4;
+ if (q_value > 2047) q_value = 2047;
+ }
+ else
+ {
+ q_value += 15;
+ q_value >>= 4;
+ if (q_value < -2048) q_value = -2048;
+ }
+
+ return q_value;
+}
+
+#elif defined(__CC_ARM) /* only work with arm v5 */
+
+#if defined(__TARGET_ARCH_5TE)
+
+__inline int32 aan_scale(int32 q_value, int32 coeff,
+ int32 round, int32 QPdiv2)
+{
+ __asm
+ {
+ smlabb q_value, coeff, q_value, round
+ movs coeff, q_value, asr #16
+ addle coeff, coeff, QPdiv2
+ subgt coeff, coeff, QPdiv2
+ }
+
+ return coeff;
+}
+
+__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
+{
+ int32 q_value;
+
+ __asm
+ {
+ smulbb q_value, q_scale, coeff /*mov coeff, coeff, lsl #14*/
+ mov coeff, q_value, asr shift /*smull tmp, coeff, q_scale, coeff*/
+ add q_value, coeff, coeff, lsr #31
+ }
+
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
+{
+ int32 coeff;
+
+ __asm
+ {
+ cmp q_value, #0
+ smulbb coeff, q_value, QPx2
+ sublt coeff, coeff, Addition
+ addge coeff, coeff, Addition
+ add q_value, coeff, tmp
+ subs q_value, q_value, #3840
+ subcss q_value, q_value, #254
+ eorhi coeff, tmp, coeff, asr #31
+ }
+
+ return coeff;
+}
+
+__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
+{
+ __asm
+ {
+ smlabb q_value, coeff, q_value, round
+ }
+
+ return q_value;
+}
+
+__inline int32 smulbb(int32 q_scale, int32 coeff)
+{
+ int32 q_value;
+
+ __asm
+ {
+ smulbb q_value, q_scale, coeff
+ }
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
+{
+ /* tmp must have value of 2047 */
+ int32 coeff;
+ __asm
+ {
+ movs coeff, q_value, lsl #1
+ smulbb stepsize, stepsize, QP
+ addgt coeff, coeff, #1
+ sublt coeff, coeff, #1
+ smulbb q_value, coeff, stepsize
+ addlt q_value, q_value, #15
+ mov q_value, q_value, asr #4
+ add coeff, q_value, tmp
+ subs coeff, coeff, #0xf00
+ subcss coeff, coeff, #0xfe
+ eorhi q_value, tmp, q_value, asr #31
+ }
+
+ return q_value;
+}
+
+
+#else // not ARMV5TE
+
+__inline int32 aan_scale(int32 q_value, int32 coeff,
+ int32 round, int32 QPdiv2)
+{
+ __asm
+ {
+ mla q_value, coeff, q_value, round
+ movs coeff, q_value, asr #16
+ addle coeff, coeff, QPdiv2
+ subgt coeff, coeff, QPdiv2
+ }
+
+ return coeff;
+}
+
+__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
+{
+ int32 q_value;
+
+ __asm
+ {
+ mul q_value, q_scale, coeff /*mov coeff, coeff, lsl #14*/
+ mov coeff, q_value, asr shift /*smull tmp, coeff, q_scale, coeff*/
+ add q_value, coeff, coeff, lsr #31
+ }
+
+
+ return q_value;
+}
+
+
+__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
+{
+ int32 coeff;
+
+ __asm
+ {
+ cmp q_value, #0
+ mul coeff, q_value, QPx2
+ sublt coeff, coeff, Addition
+ addge coeff, coeff, Addition
+ add q_value, coeff, tmp
+ subs q_value, q_value, #3840
+ subcss q_value, q_value, #254
+ eorhi coeff, tmp, coeff, asr #31
+ }
+
+ return coeff;
+}
+
+__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
+{
+ __asm
+ {
+ mla q_value, coeff, q_value, round
+ }
+
+ return q_value;
+}
+
+__inline int32 smulbb(int32 q_scale, int32 coeff)
+{
+ int32 q_value;
+
+ __asm
+ {
+ mul q_value, q_scale, coeff
+ }
+
+ return q_value;
+}
+
+
+__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
+{
+ /* tmp must have value of 2047 */
+ int32 coeff;
+ __asm
+ {
+ movs coeff, q_value, lsl #1
+ mul stepsize, stepsize, QP
+ addgt coeff, coeff, #1
+ sublt coeff, coeff, #1
+ mul q_value, coeff, stepsize
+ addlt q_value, q_value, #15
+ mov q_value, q_value, asr #4
+ add coeff, q_value, tmp
+ subs coeff, coeff, #0xf00
+ subcss coeff, coeff, #0xfe
+ eorhi q_value, tmp, q_value, asr #31
+ }
+
+ return q_value;
+}
+
+
+#endif
+
+__inline int32 coeff_clip(int32 q_value, int32 ac_clip)
+{
+ int32 coeff;
+
+ __asm
+ {
+ add coeff, q_value, ac_clip
+ subs coeff, coeff, ac_clip, lsl #1
+ eorhi q_value, ac_clip, q_value, asr #31
+ }
+
+ return q_value;
+}
+
+__inline int32 aan_dc_scale(int32 coeff, int32 QP)
+{
+
+ __asm
+ {
+ cmp coeff, #0
+ addle coeff, coeff, QP, asr #1
+ subgt coeff, coeff, QP, asr #1
+ }
+
+ return coeff;
+}
+
+__inline int32 clip_2047(int32 q_value, int32 tmp)
+{
+ /* tmp must have value of 2047 */
+ int32 coeff;
+
+ __asm
+ {
+ add coeff, q_value, tmp
+ subs coeff, coeff, #0xf00
+ subcss coeff, coeff, #0xfe
+ eorhi q_value, tmp, q_value, asr #31
+ }
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant_mpeg_intra(int32 q_value, int32 tmp)
+{
+ int32 coeff;
+
+ __asm
+ {
+ movs q_value, q_value, lsl #1
+ addlt q_value, q_value, #15
+ mov q_value, q_value, asr #4
+ add coeff, q_value, tmp
+ subs coeff, coeff, #0xf00
+ subcss coeff, coeff, #0xfe
+ eorhi q_value, tmp, q_value, asr #31
+ }
+
+ return q_value;
+}
+
+#elif ( defined(PV_ARM_GCC_V4) || defined(PV_ARM_GCC_V5) ) /* ARM GNU COMPILER */
+
+__inline int32 aan_scale(int32 q_value, int32 coeff,
+ int32 round, int32 QPdiv2)
+{
+ register int32 out;
+ register int32 qv = q_value;
+ register int32 cf = coeff;
+ register int32 rr = round;
+ register int32 qp = QPdiv2;
+
+ asm volatile("smlabb %0, %2, %1, %3\n\t"
+ "movs %0, %0, asr #16\n\t"
+ "addle %0, %0, %4\n\t"
+ "subgt %0, %0, %4"
+ : "=&r"(out)
+ : "r"(qv),
+ "r"(cf),
+ "r"(rr),
+ "r"(qp));
+ return out;
+}
+
+__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
+{
+ register int32 out;
+ register int32 temp1;
+ register int32 cc = coeff;
+ register int32 qs = q_scale;
+ register int32 ss = shift;
+
+ asm volatile("smulbb %0, %3, %2\n\t"
+ "mov %1, %0, asr %4\n\t"
+ "add %0, %1, %1, lsr #31"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(cc),
+ "r"(qs),
+ "r"(ss));
+
+ return out;
+}
+
+__inline int32 coeff_clip(int32 q_value, int32 ac_clip)
+{
+ register int32 coeff;
+
+ asm volatile("add %1, %0, %2\n\t"
+ "subs %1, %1, %2, lsl #1\n\t"
+ "eorhi %0, %2, %0, asr #31"
+ : "+r"(q_value),
+ "=&r"(coeff)
+ : "r"(ac_clip));
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
+{
+ register int32 out;
+ register int32 temp1;
+ register int32 qv = q_value;
+ register int32 qp = QPx2;
+ register int32 aa = Addition;
+ register int32 tt = tmp;
+
+ asm volatile("cmp %2, #0\n\t"
+ "mul %0, %2, %3\n\t"
+ "sublt %0, %0, %4\n\t"
+ "addge %0, %0, %4\n\t"
+ "add %1, %0, %5\n\t"
+ "subs %1, %1, #3840\n\t"
+ "subcss %1, %1, #254\n\t"
+ "eorhi %0, %5, %0, asr #31"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(qv),
+ "r"(qp),
+ "r"(aa),
+ "r"(tt));
+
+ return out;
+}
+
+__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
+{
+ register int32 out;
+ register int32 aa = (int32)q_value;
+ register int32 bb = (int32)coeff;
+ register int32 cc = (int32)round;
+
+ asm volatile("smlabb %0, %1, %2, %3"
+ : "=&r"(out)
+ : "r"(aa),
+ "r"(bb),
+ "r"(cc));
+ return out;
+}
+
+__inline int32 smulbb(int32 q_scale, int32 coeff)
+{
+ register int32 out;
+ register int32 aa = (int32)q_scale;
+ register int32 bb = (int32)coeff;
+
+ asm volatile("smulbb %0, %1, %2"
+ : "=&r"(out)
+ : "r"(aa),
+ "r"(bb));
+ return out;
+}
+
+__inline int32 aan_dc_scale(int32 coeff, int32 QP)
+{
+ register int32 out;
+ register int32 cc = coeff;
+ register int32 qp = QP;
+
+ asm volatile("cmp %1, #0\n\t"
+ "addle %0, %1, %2, asr #1\n\t"
+ "subgt %0, %1, %2, asr #1"
+ : "=&r"(out)
+ : "r"(cc),
+ "r"(qp));
+ return out;
+}
+
+__inline int32 clip_2047(int32 q_value, int32 tmp)
+{
+ register int32 coeff;
+ asm volatile("add %1, %0, %2\n\t"
+ "subs %1, %1, #0xF00\n\t"
+ "subcss %1, %1, #0xFE\n\t"
+ "eorhi %0, %2, %0, asr #31"
+ : "+r"(q_value),
+ "=&r"(coeff)
+ : "r"(tmp));
+
+ return q_value;
+}
+
+__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
+{
+ register int32 out;
+ register int32 temp1;
+ register int32 qv = q_value;
+ register int32 ss = stepsize;
+ register int32 qp = QP;
+ register int32 tt = tmp;
+
+ asm volatile("movs %1, %2, lsl #1\n\t"
+ "mul %0, %3, %4\n\t"
+ "addgt %1, %1, #1\n\t"
+ "sublt %1, %1, #1\n\t"
+ "mul %0, %1, %0\n\t"
+ "addlt %0, %0, #15\n\t"
+ "mov %0, %0, asr #4\n\t"
+ "add %1, %0, %5\n\t"
+ "subs %1, %1, #0xF00\n\t"
+ "subcss %1, %1, #0xFE\n\t"
+ "eorhi %0, %5, %0, asr #31"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(qv),
+ "r"(ss),
+ "r"(qp),
+ "r"(tt));
+
+ return out;
+
+}
+
+__inline int32 coeff_dequant_mpeg_intra(int32 q_value, int32 tmp)
+{
+ register int32 out;
+ register int32 temp1;
+ register int32 qv = q_value;
+ register int32 tt = tmp;
+
+ asm volatile("movs %1, %2, lsl #1\n\t"
+ "addlt %1, %1, #15\n\t"
+ "mov %0, %1, asr #4\n\t"
+ "add %1, %0, %3\n\t"
+ "subs %1, %1, #0xF00\n\t"
+ "subcss %1, %1, #0xFE\n\t"
+ "eorhi %0, %3, %0, asr #31"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(qv),
+ "r"(tt));
+ return out;
+}
+
+
+#endif // Platform
+
+
+#endif //_FASTQUANT_INLINE_H_
+
+
diff --git a/media/codecs/m4v_h263/enc/src/findhalfpel.cpp b/media/codecs/m4v_h263/enc/src/findhalfpel.cpp
new file mode 100644
index 0000000..319c76f
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/findhalfpel.cpp
@@ -0,0 +1,287 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4enc_lib.h"
+#include "mp4lib_int.h"
+#include "m4venc_oscl.h"
+
+/* 3/29/01 fast half-pel search based on neighboring guess */
+/* value ranging from 0 to 4, high complexity (more accurate) to
+ low complexity (less accurate) */
+#define HP_DISTANCE_TH 2 /* half-pel distance threshold */
+
+#define PREF_16_VEC 129 /* 1MV bias versus 4MVs*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ void GenerateSearchRegion(UChar *searchPadding, UChar *ref, Int width, Int height,
+ Int ilow, Int ihigh, Int jlow, Int jhigh);
+
+ void InterpDiag(UChar *prev, Int lx, UChar *pred_block);
+ void InterpHorz(UChar *prev, Int lx, UChar *pred_block);
+ void InterpVert(UChar *prev, Int lx, UChar *pred_block);
+#ifdef __cplusplus
+}
+#endif
+
+
+const static Int distance_tab[9][9] = /* [hp_guess][k] */
+{
+ {0, 1, 1, 1, 1, 1, 1, 1, 1},
+ {1, 0, 1, 2, 3, 4, 3, 2, 1},
+ {1, 0, 0, 0, 1, 2, 3, 2, 1},
+ {1, 2, 1, 0, 1, 2, 3, 4, 3},
+ {1, 2, 1, 0, 0, 0, 1, 2, 3},
+ {1, 4, 3, 2, 1, 0, 1, 2, 3},
+ {1, 2, 3, 2, 1, 0, 0, 0, 1},
+ {1, 2, 3, 4, 3, 2, 1, 0, 1},
+ {1, 0, 1, 2, 3, 2, 1, 0, 0}
+};
+
+
+/*=====================================================================
+ Function: FindHalfPelMB
+ Date: 10/7/2000
+ Purpose: Find half pel resolution MV surrounding the full-pel MV
+=====================================================================*/
+
+void FindHalfPelMB(VideoEncData *video, UChar *cur, MOT *mot, UChar *ncand,
+ Int xpos, Int ypos, Int *xhmin, Int *yhmin, Int hp_guess)
+{
+// hp_mem = ULong *vertArray; /* 20x17 */
+// ULong *horzArray; /* 20x16 */
+// ULong *diagArray; /* 20x17 */
+ Int dmin, d;
+
+ Int xh, yh;
+ Int k, kmin = 0;
+ Int imin, jmin, ilow, jlow;
+ Int h263_mode = video->encParams->H263_Enabled; /* 3/29/01 */
+ Int in_range[9] = {0, 1, 1, 1, 1, 1, 1, 1, 1}; /* 3/29/01 */
+ Int range = video->encParams->SearchRange;
+ Int lx = video->currVop->pitch;
+ Int width = video->currVop->width; /* padding */
+ Int height = video->vol[video->currLayer]->height;
+ Int(**SAD_MB_HalfPel)(UChar*, UChar*, Int, void*) =
+ video->functionPointer->SAD_MB_HalfPel;
+ void *extra_info = video->sad_extra_info;
+
+ Int next_hp_pos[9][2] = {{0, 0}, {2, 0}, {1, 1}, {0, 2}, { -1, 1}, { -2, 0}, { -1, -1}, {0, -2}, {0, -1}};
+ Int next_ncand[9] = {0, 1 , lx, lx, 0, -1, -1, -lx, -lx};
+
+ cur = video->currYMB;
+
+ /**************** check range ***************************/
+ /* 3/29/01 */
+ imin = xpos + (mot[0].x >> 1);
+ jmin = ypos + (mot[0].y >> 1);
+ ilow = xpos - range;
+ jlow = ypos - range;
+
+ if (!h263_mode)
+ {
+ if (imin <= -15 || imin == ilow)
+ in_range[1] = in_range[7] = in_range[8] = 0;
+ else if (imin >= width - 1)
+ in_range[3] = in_range[4] = in_range[5] = 0;
+ if (jmin <= -15 || jmin == jlow)
+ in_range[1] = in_range[2] = in_range[3] = 0;
+ else if (jmin >= height - 1)
+ in_range[5] = in_range[6] = in_range[7] = 0;
+ }
+ else
+ {
+ if (imin <= 0 || imin == ilow)
+ in_range[1] = in_range[7] = in_range[8] = 0;
+ else if (imin >= width - 16)
+ in_range[3] = in_range[4] = in_range[5] = 0;
+ if (jmin <= 0 || jmin == jlow)
+ in_range[1] = in_range[2] = in_range[3] = 0;
+ else if (jmin >= height - 16)
+ in_range[5] = in_range[6] = in_range[7] = 0;
+ }
+
+ xhmin[0] = 0;
+ yhmin[0] = 0;
+ dmin = mot[0].sad;
+
+ xh = 0;
+ yh = -1;
+ ncand -= lx; /* initial position */
+
+ for (k = 2; k <= 8; k += 2)
+ {
+ if (distance_tab[hp_guess][k] < HP_DISTANCE_TH)
+ {
+ if (in_range[k])
+ {
+ d = (*(SAD_MB_HalfPel[((yh&1)<<1)+(xh&1)]))(ncand, cur, (dmin << 16) | lx, extra_info);
+
+ if (d < dmin)
+ {
+ dmin = d;
+ xhmin[0] = xh;
+ yhmin[0] = yh;
+ kmin = k;
+ }
+ else if (d == dmin &&
+ PV_ABS(mot[0].x + xh) + PV_ABS(mot[0].y + yh) < PV_ABS(mot[0].x + xhmin[0]) + PV_ABS(mot[0].y + yhmin[0]))
+ {
+ xhmin[0] = xh;
+ yhmin[0] = yh;
+ kmin = k;
+ }
+
+ }
+ }
+ xh += next_hp_pos[k][0];
+ yh += next_hp_pos[k][1];
+ ncand += next_ncand[k];
+
+ if (k == 8)
+ {
+ if (xhmin[0] != 0 || yhmin[0] != 0)
+ {
+ k = -1;
+ hp_guess = kmin;
+ }
+ }
+ }
+
+ mot[0].sad = dmin;
+ mot[0].x += xhmin[0];
+ mot[0].y += yhmin[0];
+
+ return ;
+}
+
+#ifndef NO_INTER4V
+/*=====================================================================
+ Function: FindHalfPelBlk
+ Date: 10/7/2000
+ Purpose: Find half pel resolution MV surrounding the full-pel MV
+ And decide between 1MV or 4MV mode
+=====================================================================*/
+///// THIS FUNCTION IS NOT WORKING!!! NEED TO BE RIVISITED
+
+Int FindHalfPelBlk(VideoEncData *video, UChar *cur, MOT *mot, Int sad16, UChar *ncand8[],
+ UChar *mode, Int xpos, Int ypos, Int *xhmin, Int *yhmin, UChar *hp_mem)
+{
+ Int k, comp;
+ Int xh, yh;//, xhmin, yhmin;
+ Int imin, jmin, ilow, jlow;
+ Int height;
+ UChar *cand, *cur8;
+ UChar *hmem;//[17*17]; /* half-pel memory */
+ Int d, dmin, sad8;
+ Int lx = video->currVop->pitch;
+ Int width = video->currVop->width; /* , padding */
+ Int(*SAD_Blk_HalfPel)(UChar*, UChar*, Int, Int, Int, Int, Int, void*) = video->functionPointer->SAD_Blk_HalfPel;
+ void *extra_info = video->sad_extra_info;
+ Int in_range[8]; /* 3/29/01 */
+ Int range = video->encParams->SearchRange;
+ Int swidth;
+ Int next_hp_pos[8][2] = {{1, 0}, {1, 0}, {0, 1}, {0, 1}, { -1, 0}, { -1, 0}, {0, -1}, {0, -1}};
+
+ height = video->vol[video->currLayer]->height;
+
+ hmem = hp_mem;
+ sad8 = 0;
+ for (comp = 0; comp < 4; comp++)
+ {
+#ifdef _SAD_STAT
+ num_HP_Blk++;
+#endif
+ /**************** check range ***************************/
+ /* 3/29/01 */
+ M4VENC_MEMSET(in_range, 1, sizeof(Int) << 3);
+ imin = xpos + ((comp & 1) << 3) + (mot[comp+1].x >> 1);
+ jmin = ypos + ((comp & 2) << 2) + (mot[comp+1].y >> 1);
+ ilow = xpos + ((comp & 1) << 3) - range;
+ jlow = ypos + ((comp & 2) << 2) - range;
+
+ if (imin <= -15 || imin == ilow)
+ in_range[0] = in_range[6] = in_range[7] = 0;
+ else if (imin >= width - 1)
+ in_range[2] = in_range[3] = in_range[4] = 0;
+
+ if (jmin <= -15 || jmin == jlow)
+ in_range[0] = in_range[1] = in_range[2] = 0;
+ else if (jmin >= height - 1)
+ in_range[4] = in_range[5] = in_range[6] = 0;
+
+ /**************** half-pel search ***********************/
+ cur8 = cur + ((comp & 1) << 3) + ((comp & 2) << 2) * width ;
+
+ /* generate half-pel search region */
+ {
+ cand = ncand8[comp+1];
+ swidth = lx;
+ }
+
+ xhmin[comp+1] = 0;
+ yhmin[comp+1] = 0;
+ dmin = mot[comp+1].sad;
+
+ xh = -1;
+ yh = -1;
+ for (k = 0; k < 8; k++)
+ {
+ if (in_range[k])
+ {
+ d = (*SAD_Blk_HalfPel)(cand, cur8, dmin, lx, swidth, xh, yh, extra_info);
+
+ if (d < dmin)
+ {
+ dmin = d;
+ xhmin[comp+1] = xh;
+ yhmin[comp+1] = yh;
+ }
+ }
+ xh += next_hp_pos[k][0];
+ yh += next_hp_pos[k][1];
+ }
+ /********************************************/
+ mot[comp+1].x += xhmin[comp+1];
+ mot[comp+1].y += yhmin[comp+1];
+ mot[comp+1].sad = dmin;
+ sad8 += dmin;
+
+ if (sad8 >= sad16 - PREF_16_VEC)
+ {
+ *mode = MODE_INTER;
+ for (k = 1; k <= 4; k++)
+ {
+ mot[k].sad = (mot[0].sad + 2) >> 2;
+ mot[k].x = mot[0].x;
+ mot[k].y = mot[0].y;
+ }
+ return sad8;
+ }
+
+ hmem += (10 * 10);
+ }
+
+ *mode = MODE_INTER4V;
+
+ return sad8;
+}
+#endif /* NO_INTER4V */
+
diff --git a/media/codecs/m4v_h263/enc/src/m4venc_oscl.h b/media/codecs/m4v_h263/enc/src/m4venc_oscl.h
new file mode 100644
index 0000000..c9e18d5
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/m4venc_oscl.h
@@ -0,0 +1,43 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*********************************************************************************/
+/* Revision History */
+/* Date: 11/04/05 */
+/* Description: Created for abstracting out OSCL such that the code can be used */
+/* by both V3 and V4 OSCL library. This file is for V4. */
+/*********************************************************************************/
+
+#ifndef _M4VENC_OSCL_H_
+#define _M4VENC_OSCL_H_
+
+#include <stdlib.h>
+#include <math.h>
+
+#define M4VENC_MALLOC(size) malloc(size)
+#define M4VENC_FREE(ptr) free(ptr)
+
+#define M4VENC_MEMSET(ptr,val,size) memset(ptr,val,size)
+#define M4VENC_MEMCPY(dst,src,size) memcpy(dst,src,size)
+
+#define M4VENC_LOG(x) log(x)
+#define M4VENC_SQRT(x) sqrt(x)
+#define M4VENC_POW(x,y) pow(x,y)
+
+#define M4VENC_HAS_SYMBIAN_SUPPORT OSCL_HAS_SYMBIAN_SUPPORT
+
+#endif //_M4VENC_OSCL_H_
diff --git a/media/codecs/m4v_h263/enc/src/me_utils.cpp b/media/codecs/m4v_h263/enc/src/me_utils.cpp
new file mode 100644
index 0000000..6dab31a
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/me_utils.cpp
@@ -0,0 +1,386 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4enc_lib.h"
+#include "mp4lib_int.h"
+#include "m4venc_oscl.h"
+
+#define VOP_OFFSET ((lx<<4)+16) /* for offset to image area */
+#define CVOP_OFFSET ((lx<<2)+8)
+
+#define PREF_INTRA 512 /* bias for INTRA coding */
+
+/*===============================================================
+ Function: ChooseMode
+ Date: 09/21/2000
+ Purpose: Choosing between INTRA or INTER
+ Input/Output: Pointer to the starting point of the macroblock.
+ Note:
+===============================================================*/
+void ChooseMode_C(UChar *Mode, UChar *cur, Int lx, Int min_SAD)
+{
+ Int i, j;
+ Int MB_mean, A, tmp, Th;
+ Int offset = (lx >> 2) - 4;
+ UChar *p = cur;
+ Int *pint = (Int *) cur, temp = 0;
+ MB_mean = 0;
+ A = 0;
+ Th = (min_SAD - PREF_INTRA) >> 1;
+
+ for (j = 0; j < 8; j++)
+ {
+
+ /* Odd Rows */
+ temp += (*pint++) & 0x00FF00FF;
+ temp += (*pint++) & 0x00FF00FF;
+ temp += (*pint++) & 0x00FF00FF;
+ temp += (*pint++) & 0x00FF00FF;
+ pint += offset;
+
+ /* Even Rows */
+ temp += (*pint++ >> 8) & 0x00FF00FF;
+ temp += (*pint++ >> 8) & 0x00FF00FF;
+ temp += (*pint++ >> 8) & 0x00FF00FF;
+ temp += (*pint++ >> 8) & 0x00FF00FF;
+ pint += offset;
+
+ }
+
+ MB_mean = (((temp & 0x0000FFFF)) + ((temp & 0xFFFF0000) >> 16)) >> 7;
+
+ p = cur;
+ offset = lx - 16;
+ for (j = 0; j < 16; j++)
+ {
+ temp = (j & 1);
+ p += temp;
+ i = 8;
+ while (i--)
+ {
+ tmp = *p - MB_mean;
+ p += 2;
+ if (tmp > 0) A += tmp;
+ else A -= tmp;
+ }
+
+ if (A >= Th)
+ {
+ *Mode = MODE_INTER;
+ return ;
+ }
+ p += (offset - temp);
+ }
+
+ if (A < Th)
+ *Mode = MODE_INTRA;
+ else
+ *Mode = MODE_INTER;
+
+ return ;
+}
+
+
+/*===============================================================
+ Function: GetHalfPelMBRegion
+ Date: 09/17/2000
+ Purpose: Interpolate the search region for half-pel search
+ Input/Output: Center of the search, Half-pel memory, width
+ Note: rounding type should be parameterized.
+ Now fixed it to zero!!!!!!
+
+===============================================================*/
+
+
+void GetHalfPelMBRegion_C(UChar *cand, UChar *hmem, Int lx)
+{
+ Int i, j;
+ UChar *p1, *p2, *p3, *p4;
+ UChar *hmem1 = hmem;
+ UChar *hmem2 = hmem1 + 33;
+ Int offset = lx - 17;
+
+ p1 = cand - lx - 1;
+ p2 = cand - lx;
+ p3 = cand - 1;
+ p4 = cand;
+
+ for (j = 0; j < 16; j++)
+ {
+ for (i = 0; i < 16; i++)
+ {
+ *hmem1++ = ((*p1++) + *p2 + *p3 + *p4 + 2) >> 2;
+ *hmem1++ = ((*p2++) + *p4 + 1) >> 1;
+ *hmem2++ = ((*p3++) + *p4 + 1) >> 1;
+ *hmem2++ = *p4++;
+ }
+ /* last pixel */
+ *hmem1++ = ((*p1++) + (*p2++) + *p3 + *p4 + 2) >> 2;
+ *hmem2++ = ((*p3++) + (*p4++) + 1) >> 1;
+ hmem1 += 33;
+ hmem2 += 33;
+ p1 += offset;
+ p2 += offset;
+ p3 += offset;
+ p4 += offset;
+ }
+ /* last row */
+ for (i = 0; i < 16; i++)
+ {
+ *hmem1++ = ((*p1++) + *p2 + (*p3++) + *p4 + 2) >> 2;
+ *hmem1++ = ((*p2++) + (*p4++) + 1) >> 1;
+
+ }
+ *hmem1 = (*p1 + *p2 + *p3 + *p4 + 2) >> 2;
+
+ return ;
+}
+
+/*===============================================================
+ Function: GetHalfPelBlkRegion
+ Date: 09/20/2000
+ Purpose: Interpolate the search region for half-pel search
+ in 4MV mode.
+ Input/Output: Center of the search, Half-pel memory, width
+ Note: rounding type should be parameterized.
+ Now fixed it to zero!!!!!!
+
+===============================================================*/
+
+
+void GetHalfPelBlkRegion(UChar *cand, UChar *hmem, Int lx)
+{
+ Int i, j;
+ UChar *p1, *p2, *p3, *p4;
+ UChar *hmem1 = hmem;
+ UChar *hmem2 = hmem1 + 17;
+ Int offset = lx - 9;
+
+ p1 = cand - lx - 1;
+ p2 = cand - lx;
+ p3 = cand - 1;
+ p4 = cand;
+
+ for (j = 0; j < 8; j++)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ *hmem1++ = ((*p1++) + *p2 + *p3 + *p4 + 2) >> 2;
+ *hmem1++ = ((*p2++) + *p4 + 1) >> 1;
+ *hmem2++ = ((*p3++) + *p4 + 1) >> 1;
+ *hmem2++ = *p4++;
+ }
+ /* last pixel */
+ *hmem1++ = ((*p1++) + (*p2++) + *p3 + *p4 + 2) >> 2;
+ *hmem2++ = ((*p3++) + (*p4++) + 1) >> 1;
+ hmem1 += 17;
+ hmem2 += 17;
+ p1 += offset;
+ p2 += offset;
+ p3 += offset;
+ p4 += offset;
+ }
+ /* last row */
+ for (i = 0; i < 8; i++)
+ {
+ *hmem1++ = ((*p1++) + *p2 + (*p3++) + *p4 + 2) >> 2;
+ *hmem1++ = ((*p2++) + (*p4++) + 1) >> 1;
+
+ }
+ *hmem1 = (*p1 + *p2 + *p3 + *p4 + 2) >> 2;
+
+ return ;
+}
+
+
+/*=====================================================================
+ Function: PaddingEdge
+ Date: 09/16/2000
+ Purpose: Pad edge of a Vop
+ Modification: 09/20/05.
+=====================================================================*/
+
+void PaddingEdge(Vop *refVop)
+{
+ UChar *src, *dst;
+ Int i;
+ Int pitch, width, height;
+ ULong temp1, temp2;
+
+ width = refVop->width;
+ height = refVop->height;
+ pitch = refVop->pitch;
+
+ /* pad top */
+ src = refVop->yChan;
+
+ temp1 = *src; /* top-left corner */
+ temp2 = src[width-1]; /* top-right corner */
+ temp1 |= (temp1 << 8);
+ temp1 |= (temp1 << 16);
+ temp2 |= (temp2 << 8);
+ temp2 |= (temp2 << 16);
+
+ dst = src - (pitch << 4);
+
+ *((ULong*)(dst - 16)) = temp1;
+ *((ULong*)(dst - 12)) = temp1;
+ *((ULong*)(dst - 8)) = temp1;
+ *((ULong*)(dst - 4)) = temp1;
+
+ M4VENC_MEMCPY(dst, src, width);
+
+ *((ULong*)(dst += width)) = temp2;
+ *((ULong*)(dst + 4)) = temp2;
+ *((ULong*)(dst + 8)) = temp2;
+ *((ULong*)(dst + 12)) = temp2;
+
+ dst = dst - width - 16;
+
+ i = 15;
+ while (i--)
+ {
+ M4VENC_MEMCPY(dst + pitch, dst, pitch);
+ dst += pitch;
+ }
+
+ /* pad sides */
+ dst += (pitch + 16);
+ src = dst;
+ i = height;
+ while (i--)
+ {
+ temp1 = *src;
+ temp2 = src[width-1];
+ temp1 |= (temp1 << 8);
+ temp1 |= (temp1 << 16);
+ temp2 |= (temp2 << 8);
+ temp2 |= (temp2 << 16);
+
+ *((ULong*)(dst - 16)) = temp1;
+ *((ULong*)(dst - 12)) = temp1;
+ *((ULong*)(dst - 8)) = temp1;
+ *((ULong*)(dst - 4)) = temp1;
+
+ *((ULong*)(dst += width)) = temp2;
+ *((ULong*)(dst + 4)) = temp2;
+ *((ULong*)(dst + 8)) = temp2;
+ *((ULong*)(dst + 12)) = temp2;
+
+ src += pitch;
+ dst = src;
+ }
+
+ /* pad bottom */
+ dst -= 16;
+ i = 16;
+ while (i--)
+ {
+ M4VENC_MEMCPY(dst, dst - pitch, pitch);
+ dst += pitch;
+ }
+
+
+ return ;
+}
+
+/*===================================================================
+ Function: ComputeMBSum
+ Date: 10/28/2000
+ Purpose: Compute sum of absolute value (SAV) of blocks in a macroblock
+ in INTRA mode needed for rate control. Thus, instead of
+ computing the SAV, we can compute first order moment or
+ variance .
+
+ 11/28/00: add MMX
+ 9/3/01: do parallel comp for C function.
+===================================================================*/
+void ComputeMBSum_C(UChar *cur, Int lx, MOT *mot_mb)
+{
+ Int j;
+ Int *cInt, *cInt2;
+ Int sad1 = 0, sad2 = 0, sad3 = 0, sad4 = 0;
+ Int tmp, tmp2, mask = 0x00FF00FF;
+
+ cInt = (Int*)cur; /* make sure this is word-align */
+ cInt2 = (Int*)(cur + (lx << 3));
+ j = 8;
+ while (j--)
+ {
+ tmp = cInt[3]; /* load 4 pixels at a time */
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad2 += tmp;
+ tmp = cInt[2];
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad2 += tmp;
+ tmp = cInt[1];
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad1 += tmp;
+ tmp = *cInt;
+ cInt += (lx >> 2);
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad1 += tmp;
+
+ tmp = cInt2[3];
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad4 += tmp;
+ tmp = cInt2[2];
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad4 += tmp;
+ tmp = cInt2[1];
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad3 += tmp;
+ tmp = *cInt2;
+ cInt2 += (lx >> 2);
+ tmp2 = tmp & mask;
+ tmp = (tmp >> 8) & mask;
+ tmp += tmp2;
+ sad3 += tmp;
+ }
+ sad1 += (sad1 << 16);
+ sad2 += (sad2 << 16);
+ sad3 += (sad3 << 16);
+ sad4 += (sad4 << 16);
+ sad1 >>= 16;
+ sad2 >>= 16;
+ sad3 >>= 16;
+ sad4 >>= 16;
+
+ mot_mb[1].sad = sad1;
+ mot_mb[2].sad = sad2;
+ mot_mb[3].sad = sad3;
+ mot_mb[4].sad = sad4;
+ mot_mb[0].sad = sad1 + sad2 + sad3 + sad4;
+
+ return ;
+}
+
diff --git a/media/codecs/m4v_h263/enc/src/motion_comp.cpp b/media/codecs/m4v_h263/enc/src/motion_comp.cpp
new file mode 100644
index 0000000..9a967c2
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/motion_comp.cpp
@@ -0,0 +1,1965 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4lib_int.h"
+#include "mp4enc_lib.h"
+
+//const static Int roundtab4[] = {0,1,1,1};
+//const static Int roundtab8[] = {0,0,1,1,1,1,1,2};
+//const static Int roundtab12[] = {0,0,0,1,1,1,1,1,1,1,2,2};
+const static Int roundtab16[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
+
+#define FORWARD_MODE 1
+#define BACKWARD_MODE 2
+#define BIDIRECTION_MODE 3
+#define DIRECT_MODE 4
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ /*Function Prototype */
+ /* no-edge padding */
+ Int EncGetPredOutside(Int xpos, Int ypos, UChar *c_prev, UChar *rec,
+ Int width, Int height, Int rnd1);
+
+ void Copy_MB_from_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width);
+ void Copy_B_from_Vop(UChar *comp, Int cChan[], Int width);
+ void Copy_MB_into_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width);
+ void Copy_B_into_Vop(UChar *comp, Int cChan[], Int width);
+ void get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v,
+ Short mb[6][64], Int lx, Int lx_uv);
+
+ Int GetPredAdvBy0x0(
+ UChar *c_prev, /* i */
+ UChar *pred_block, /* i */
+ Int lx, /* i */
+ Int rnd1 /* i */
+ );
+
+ Int GetPredAdvBy0x1(
+ UChar *c_prev, /* i */
+ UChar *pred_block, /* i */
+ Int lx, /* i */
+ Int rnd1 /* i */
+ );
+
+ Int GetPredAdvBy1x0(
+ UChar *c_prev, /* i */
+ UChar *pred_block, /* i */
+ Int lx, /* i */
+ Int rnd1 /* i */
+ );
+
+ Int GetPredAdvBy1x1(
+ UChar *c_prev, /* i */
+ UChar *pred_block, /* i */
+ Int lx, /* i */
+ Int rnd1 /* i */
+ );
+
+ static Int(*const GetPredAdvBTable[2][2])(UChar*, UChar*, Int, Int) =
+ {
+ {&GetPredAdvBy0x0, &GetPredAdvBy0x1},
+ {&GetPredAdvBy1x0, &GetPredAdvBy1x1}
+ };
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+/* ======================================================================== */
+/* Function : getMotionCompensatedMB( ) */
+/* Date : 4/17/2001 */
+/* Purpose : Get the motion compensate block into video->predictionMB */
+/* and generate video->predictionErrorMB */
+/* modified from MBMotionComp() function in the decoder */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+void getMotionCompensatedMB(VideoEncData *video, Int ind_x, Int ind_y, Int offset)
+{
+ Vop *prevVop = video->forwardRefVop; //reference frame
+ Vop *currVop = video->currVop;
+ Int mbnum = video->mbnum; //mb index
+ MOT *mot = video->mot[mbnum];
+ Int ypos, xpos;
+ UChar *c_prev, *cu_prev, *cv_prev;
+ UChar *c_rec, *cu_rec, *cv_rec;
+ Int height, pitch, pitch_uv, height_uv;
+ Int mode = video->headerInfo.Mode[mbnum]; /* get mode */
+ Int dx, dy;
+ Int xpred, ypred;
+ Int xsum, ysum;
+ Int round1;
+
+ OSCL_UNUSED_ARG(offset);
+
+ round1 = (Int)(1 - video->currVop->roundingType);
+
+ pitch = currVop->pitch;
+ height = currVop->height;
+ pitch_uv = pitch >> 1;
+ height_uv = height >> 1;
+
+ ypos = ind_y << 4 ;
+ xpos = ind_x << 4 ;
+
+ c_rec = video->predictedMB;
+ cu_rec = video->predictedMB + 256;
+ cv_rec = video->predictedMB + 264;
+
+ if (mode == MODE_INTER || mode == MODE_INTER_Q)
+ {
+ /* Motion vector in x direction */
+ dx = mot[0].x;
+ dy = mot[0].y;
+
+ c_prev = prevVop->yChan;
+
+ xpred = (xpos << 1) + dx ;
+ ypred = (ypos << 1) + dy ;
+
+ /* Call function that performs luminance prediction */
+ EncPrediction_INTER(xpred, ypred, c_prev, c_rec,
+ pitch, round1);
+
+ if ((dx & 3) == 0) dx = dx >> 1;
+ else dx = (dx >> 1) | 1;
+
+ if ((dy & 3) == 0) dy = dy >> 1;
+ else dy = (dy >> 1) | 1;
+
+ xpred = xpos + dx;
+ ypred = ypos + dy;
+
+ cu_prev = prevVop->uChan;
+ cv_prev = prevVop->vChan;
+
+ EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec,
+ pitch_uv, (currVop->width) >> 1, height_uv, round1);
+ }
+#ifndef NO_INTER4V
+ else if (mode == MODE_INTER4V)
+ {
+ c_prev = prevVop->yChan;
+ cu_prev = prevVop->uChan;
+ cv_prev = prevVop->vChan;
+
+ EncPrediction_INTER4V(xpos, ypos, mot, c_prev, c_rec,
+ pitch, round1);
+
+ xsum = mot[1].x + mot[2].x + mot[3].x + mot[4].x;
+ ysum = mot[1].y + mot[2].y + mot[3].y + mot[4].y;
+
+ dx = PV_SIGN(xsum) * (roundtab16[(PV_ABS(xsum)) & 0xF] +
+ (((PV_ABS(xsum)) >> 4) << 1));
+ dy = PV_SIGN(ysum) * (roundtab16[(PV_ABS(ysum)) & 0xF] +
+ (((PV_ABS(ysum)) >> 4) << 1));
+
+ ypred = ypos + dy;
+ xpred = xpos + dx;
+
+ EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec,
+ pitch_uv, (currVop->width) >> 1, height_uv, round1);
+ }
+#endif
+ else
+ {
+ ;//printf("Error, MODE_SKIPPED is not decided yet!\n");
+ }
+
+ return ;
+}
+
+/***************************************************************************
+ Function: EncPrediction_INTER
+ Date: 04/17/2001
+ Purpose: Get predicted area for luminance and compensate with the residue.
+ Modified from luminance_pred_mode_inter() in decoder.
+***************************************************************************/
+
+void EncPrediction_INTER(
+ Int xpred, /* i */
+ Int ypred, /* i */
+ UChar *c_prev, /* i */
+ UChar *c_rec, /* i */
+ Int lx, /* i */
+ Int round1 /* i */
+)
+{
+ c_prev += (xpred >> 1) + ((ypred >> 1) * lx);
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
+
+ c_prev += B_SIZE;
+ c_rec += B_SIZE;
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
+
+ c_prev += (lx << 3) - B_SIZE;
+ c_rec += (16 << 3) - B_SIZE; /* padding */
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
+
+ c_prev += B_SIZE;
+ c_rec += B_SIZE;
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
+
+ return;
+}
+
+#ifndef NO_INTER4V
+/***************************************************************************
+ Function: EncPrediction_INTER4V
+ Date: 04/17/2001
+ Purpose: Get predicted area for luminance and compensate with the residue.
+ Modified from luminance_pred_mode_inter4v() in decoder.
+***************************************************************************/
+
+void EncPrediction_INTER4V(
+ Int xpos, /* i */
+ Int ypos, /* i */
+ MOT *mot, /* i */
+ UChar *c_prev, /* i */
+ UChar *c_rec, /* i */
+ Int lx, /* i */
+ Int round1 /* i */
+)
+{
+ Int ypred, xpred;
+
+ xpred = (Int)((xpos << 1) + mot[1].x);
+ ypred = (Int)((ypos << 1) + mot[1].y);
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
+ c_rec, lx, round1);
+
+ c_rec += B_SIZE;
+
+ xpred = (Int)(((xpos + B_SIZE) << 1) + mot[2].x);
+ ypred = (Int)((ypos << 1) + mot[2].y);
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
+ c_rec, lx, round1);
+
+ c_rec += (16 << 3) - B_SIZE; /* padding */
+
+ xpred = (Int)((xpos << 1) + mot[3].x);
+ ypred = (Int)(((ypos + B_SIZE) << 1) + mot[3].y);
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
+ c_rec, lx, round1);
+
+ c_rec += B_SIZE;
+
+ xpred = (Int)(((xpos + B_SIZE) << 1) + mot[4].x);
+ ypred = (Int)(((ypos + B_SIZE) << 1) + mot[4].y);
+
+ GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
+ c_rec, lx, round1);
+
+ return;
+}
+#endif /* NO_INTER4V */
+
+/***************************************************************************
+ Function: EncPrediction_Chrom
+ Date: 04/17/2001
+ Purpose: Get predicted area for chrominance and compensate with the residue.
+ Modified from chrominance_pred() in decoder.
+***************************************************************************/
+
+void EncPrediction_Chrom(
+ Int xpred, /* i */
+ Int ypred, /* i */
+ UChar *cu_prev, /* i */
+ UChar *cv_prev, /* i */
+ UChar *cu_rec,
+ UChar *cv_rec,
+ Int lx,
+ Int width_uv, /* i */
+ Int height_uv, /* i */
+ Int round1 /* i */
+)
+{
+ /* check whether the MV points outside the frame */
+ /* Compute prediction for Chrominance b block (block[4]) */
+ if (xpred >= 0 && xpred <= ((width_uv << 1) - (2*B_SIZE)) && ypred >= 0 &&
+ ypred <= ((height_uv << 1) - (2*B_SIZE)))
+ {
+ /*****************************/
+ /* (x,y) is inside the frame */
+ /*****************************/
+
+ /* Compute prediction for Chrominance b (block[4]) */
+ GetPredAdvBTable[ypred&1][xpred&1](cu_prev + (xpred >> 1) + ((ypred >> 1)*lx),
+ cu_rec, lx, round1);
+
+ /* Compute prediction for Chrominance r (block[5]) */
+ GetPredAdvBTable[ypred&1][xpred&1](cv_prev + (xpred >> 1) + ((ypred >> 1)*lx),
+ cv_rec, lx, round1);
+ }
+ else
+ {
+ /******************************/
+ /* (x,y) is outside the frame */
+ /******************************/
+
+ /* Compute prediction for Chrominance b (block[4]) */
+ EncGetPredOutside(xpred, ypred,
+ cu_prev, cu_rec,
+ width_uv, height_uv, round1);
+
+ /* Compute prediction for Chrominance r (block[5]) */
+ EncGetPredOutside(xpred, ypred,
+ cv_prev, cv_rec,
+ width_uv, height_uv, round1);
+ }
+
+ return;
+}
+/***************************************************************************
+ Function: GetPredAdvancedB
+ Date: 04/17/2001
+ Purpose: Get predicted area (block) and compensate with the residue.
+ - modified from GetPredAdvancedBAdd in decoder.
+ Intput/Output:
+ Modified:
+***************************************************************************/
+
+Int GetPredAdvBy0x0(
+ UChar *prev, /* i */
+ UChar *rec, /* i */
+ Int lx, /* i */
+ Int rnd /* i */
+)
+{
+ Int i; /* loop variable */
+ ULong pred_word, word1, word2;
+ Int tmp;
+
+ OSCL_UNUSED_ARG(rnd);
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+
+ tmp = (uintptr_t)prev & 0x3;
+
+ if (tmp == 0) /* word-aligned */
+ {
+ rec -= 16; /* preset */
+ prev -= lx;
+
+ for (i = 8; i > 0; i--)
+ {
+ *((ULong*)(rec += 16)) = *((ULong*)(prev += lx));
+ *((ULong*)(rec + 4)) = *((ULong*)(prev + 4));
+ }
+ return 1;
+ }
+ else if (tmp == 1) /* first position */
+ {
+ prev--; /* word-aligned */
+ rec -= 16; /* preset */
+ prev -= lx;
+
+ for (i = 8; i > 0; i--)
+ {
+ word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
+ word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */
+ word1 >>= 8; /* 0 b4 b3 b2 */
+ pred_word = word1 | (word2 << 24); /* b5 b4 b3 b2 */
+ *((ULong*)(rec += 16)) = pred_word;
+
+ word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
+ word2 >>= 8; /* 0 b8 b7 b6 */
+ pred_word = word2 | (word1 << 24); /* b9 b8 b7 b6 */
+ *((ULong*)(rec + 4)) = pred_word;
+ }
+
+ return 1;
+ }
+ else if (tmp == 2) /* second position */
+ {
+ prev -= 2; /* word1-aligned */
+ rec -= 16; /* preset */
+ prev -= lx;
+
+ for (i = 8; i > 0; i--)
+ {
+ word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
+ word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */
+ word1 >>= 16; /* 0 0 b4 b3 */
+ pred_word = word1 | (word2 << 16); /* b6 b5 b4 b3 */
+ *((ULong*)(rec += 16)) = pred_word;
+
+ word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
+ word2 >>= 16; /* 0 0 b8 b7 */
+ pred_word = word2 | (word1 << 16); /* b10 b9 b8 b7 */
+ *((ULong*)(rec + 4)) = pred_word;
+ }
+
+ return 1;
+ }
+ else /* third position */
+ {
+ prev -= 3; /* word1-aligned */
+ rec -= 16; /* preset */
+ prev -= lx;
+
+ for (i = 8; i > 0; i--)
+ {
+ word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
+ word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */
+ word1 >>= 24; /* 0 0 0 b4 */
+ pred_word = word1 | (word2 << 8); /* b7 b6 b5 b4 */
+ *((ULong*)(rec += 16)) = pred_word;
+
+ word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
+ word2 >>= 24; /* 0 0 0 b8 */
+ pred_word = word2 | (word1 << 8); /* b11 b10 b9 b8 */
+ *((ULong*)(rec + 4)) = pred_word;
+
+ }
+
+ return 1;
+ }
+}
+/**************************************************************************/
+Int GetPredAdvBy0x1(
+ UChar *prev, /* i */
+ UChar *rec, /* i */
+ Int lx, /* i */
+ Int rnd1 /* i */
+)
+{
+ Int i; /* loop variable */
+ Int offset;
+ ULong word1, word2, word3, word12;
+ Int tmp;
+ ULong mask;
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+ offset = lx - B_SIZE; /* offset for prev */
+
+ /* Branch based on pixel location (half-pel or full-pel) for x and y */
+ rec -= 12; /* preset */
+
+ tmp = (uintptr_t)prev & 3;
+ mask = 254;
+ mask |= (mask << 8);
+ mask |= (mask << 16); /* 0xFEFEFEFE */
+
+ if (tmp == 0) /* word-aligned */
+ {
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b4 b3 b2 b1 */
+ word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */
+ word12 = (word1 >> 8); /* 0 b4 b3 b2 */
+ word12 |= (word2 << 24); /* b5 b4 b3 b2 */
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */
+ word12 = (word2 >> 8); /* 0 b8 b7 b6 */
+ word12 |= (word1 << 24); /* b9 b8 b7 b6 */
+ word3 = word2 | word12;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 == 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b4 b3 b2 b1 */
+
+ word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */
+ word12 = (word1 >> 8); /* 0 b4 b3 b2 */
+ word12 |= (word2 << 24); /* b5 b4 b3 b2 */
+ word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */
+ word12 = (word2 >> 8); /* 0 b8 b7 b6 */
+ word12 |= (word1 << 24); /* b9 b8 b7 b6 */
+ word3 = word2 & word12;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ } /* rnd1 */
+ }
+ else if (tmp == 1)
+ {
+ prev--; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b3 b2 b1 b0 */
+ word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */
+ word12 = (word1 >> 8); /* 0 b3 b2 b1 */
+ word1 >>= 16; /* 0 0 b3 b2 */
+ word12 |= (word2 << 24); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 16); /* b5 b4 b3 b2 */
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */
+ word12 = (word2 >> 8); /* 0 b7 b6 b5 */
+ word2 >>= 16; /* 0 0 b7 b6 */
+ word12 |= (word1 << 24); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 16); /* b9 b8 b7 b6 */
+ word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word2&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b3 b2 b1 b0 */
+
+ word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */
+ word12 = (word1 >> 8); /* 0 b3 b2 b1 */
+ word1 >>= 16; /* 0 0 b3 b2 */
+ word12 |= (word2 << 24); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 16); /* b5 b4 b3 b2 */
+ word3 = word1 & word12;
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */
+ word12 = (word2 >> 8); /* 0 b7 b6 b5 */
+ word2 >>= 16; /* 0 0 b7 b6 */
+ word12 |= (word1 << 24); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 16); /* b9 b8 b7 b6 */
+ word3 = word2 & word12;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+
+ prev += offset;
+ }
+ return 1;
+ } /* rnd1 */
+ }
+ else if (tmp == 2)
+ {
+ prev -= 2; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */
+ word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */
+ word12 = (word1 >> 16); /* 0 0 b2 b1 */
+ word1 >>= 24; /* 0 0 0 b2 */
+ word12 |= (word2 << 16); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 8); /* b5 b4 b3 b2 */
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */
+ word12 = (word2 >> 16); /* 0 0 b6 b5 */
+ word2 >>= 24; /* 0 0 0 b6 */
+ word12 |= (word1 << 16); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 8); /* b9 b8 b7 b6 */
+ word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 == 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */
+ word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */
+ word12 = (word1 >> 16); /* 0 0 b2 b1 */
+ word1 >>= 24; /* 0 0 0 b2 */
+ word12 |= (word2 << 16); /* b4 b3 b2 b1 */
+ word1 |= (word2 << 8); /* b5 b4 b3 b2 */
+ word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */
+ word12 = (word2 >> 16); /* 0 0 b6 b5 */
+ word2 >>= 24; /* 0 0 0 b6 */
+ word12 |= (word1 << 16); /* b8 b7 b6 b5 */
+ word2 |= (word1 << 8); /* b9 b8 b7 b6 */
+ word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+ else /* tmp = 3 */
+ {
+ prev -= 3; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */
+ word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */
+ word12 = (word1 >> 24); /* 0 0 0 b1 */
+ word12 |= (word2 << 8); /* b4 b3 b2 b1 */
+ word1 = word2;
+ word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */
+ word12 = (word2 >> 24); /* 0 0 0 b5 */
+ word12 |= (word1 << 8); /* b8 b7 b6 b5 */
+ word2 = word1; /* b9 b8 b7 b6 */
+ word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ else
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */
+ word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */
+ word12 = (word1 >> 24); /* 0 0 0 b1 */
+ word12 |= (word2 << 8); /* b4 b3 b2 b1 */
+ word1 = word2;
+ word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word12 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
+
+ word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */
+ word12 = (word2 >> 24); /* 0 0 0 b5 */
+ word12 |= (word1 << 8); /* b8 b7 b6 b5 */
+ word2 = word1; /* b9 b8 b7 b6 */
+ word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 &= mask;
+ word2 >>= 1;
+ word2 = word2 + (word12 >> 1);
+ word2 += word3;
+ *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+}
+
+/**************************************************************************/
+Int GetPredAdvBy1x0(
+ UChar *prev, /* i */
+ UChar *rec, /* i */
+ Int lx, /* i */
+ Int rnd1 /* i */
+)
+{
+ Int i; /* loop variable */
+ Int offset;
+ ULong word1, word2, word3, word12, word22;
+ Int tmp;
+ ULong mask;
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+ offset = lx - B_SIZE; /* offset for prev */
+
+ /* Branch based on pixel location (half-pel or full-pel) for x and y */
+ rec -= 12; /* preset */
+
+ tmp = (uintptr_t)prev & 3;
+ mask = 254;
+ mask |= (mask << 8);
+ mask |= (mask << 16); /* 0xFEFEFEFE */
+
+ if (tmp == 0) /* word-aligned */
+ {
+ prev -= 4;
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)(prev += 4));
+ word2 = *((ULong*)(prev + lx));
+ word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1;
+ word1 = *((ULong*)(prev += 4));
+ word2 = *((ULong*)(prev + lx));
+ word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word1 = *((ULong*)(prev += 4));
+ word2 = *((ULong*)(prev + lx));
+ word3 = word1 & word2; /* rnd1 = 0; */
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 12)) = word1;
+ word1 = *((ULong*)(prev += 4));
+ word2 = *((ULong*)(prev + lx));
+ word3 = word1 & word2; /* rnd1 = 0; */
+ word1 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word2 &= mask;
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+ else if (tmp == 1)
+ {
+ prev--; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((ULong*)(prev + lx));
+
+ word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((ULong*)(prev + lx));
+ word12 >>= 8; /* 0 b4 b3 b2 */
+ word22 >>= 8;
+ word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
+ word22 = word22 | (word2 << 24);
+ word3 = word12 | word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((ULong*)(rec += 12)) = word12;
+
+ word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((ULong*)(prev + lx));
+ word1 >>= 8; /* 0 b8 b7 b6 */
+ word2 >>= 8;
+ word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
+ word2 = word2 | (word22 << 24);
+ word3 = word1 | word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((ULong*)(prev + lx));
+
+ word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((ULong*)(prev + lx));
+ word12 >>= 8; /* 0 b4 b3 b2 */
+ word22 >>= 8;
+ word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
+ word22 = word22 | (word2 << 24);
+ word3 = word12 & word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((ULong*)(rec += 12)) = word12;
+
+ word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((ULong*)(prev + lx));
+ word1 >>= 8; /* 0 b8 b7 b6 */
+ word2 >>= 8;
+ word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
+ word2 = word2 | (word22 << 24);
+ word3 = word1 & word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ }
+ else if (tmp == 2)
+ {
+ prev -= 2; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((ULong*)(prev + lx));
+
+ word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((ULong*)(prev + lx));
+ word12 >>= 16; /* 0 0 b4 b3 */
+ word22 >>= 16;
+ word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
+ word22 = word22 | (word2 << 16);
+ word3 = word12 | word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((ULong*)(rec += 12)) = word12;
+
+ word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((ULong*)(prev + lx));
+ word1 >>= 16; /* 0 0 b8 b7 */
+ word2 >>= 16;
+ word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
+ word2 = word2 | (word22 << 16);
+ word3 = word1 | word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((ULong*)(prev + lx));
+
+ word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((ULong*)(prev + lx));
+ word12 >>= 16; /* 0 0 b4 b3 */
+ word22 >>= 16;
+ word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
+ word22 = word22 | (word2 << 16);
+ word3 = word12 & word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((ULong*)(rec += 12)) = word12;
+
+ word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((ULong*)(prev + lx));
+ word1 >>= 16; /* 0 0 b8 b7 */
+ word2 >>= 16;
+ word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
+ word2 = word2 | (word22 << 16);
+ word3 = word1 & word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+ prev += offset;
+ }
+
+ return 1;
+ }
+ }
+ else /* tmp == 3 */
+ {
+ prev -= 3; /* word-aligned */
+ if (rnd1 == 1)
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((ULong*)(prev + lx));
+
+ word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((ULong*)(prev + lx));
+ word12 >>= 24; /* 0 0 0 b4 */
+ word22 >>= 24;
+ word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
+ word22 = word22 | (word2 << 8);
+ word3 = word12 | word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((ULong*)(rec += 12)) = word12;
+
+ word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((ULong*)(prev + lx));
+ word1 >>= 24; /* 0 0 0 b8 */
+ word2 >>= 24;
+ word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
+ word2 = word2 | (word22 << 8);
+ word3 = word1 | word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* rnd1 = 0 */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
+ word22 = *((ULong*)(prev + lx));
+
+ word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
+ word2 = *((ULong*)(prev + lx));
+ word12 >>= 24; /* 0 0 0 b4 */
+ word22 >>= 24;
+ word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
+ word22 = word22 | (word2 << 8);
+ word3 = word12 & word22;
+ word12 &= mask;
+ word22 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word12 >>= 1;
+ word12 = word12 + (word22 >> 1);
+ word12 += word3;
+ *((ULong*)(rec += 12)) = word12;
+
+ word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
+ word22 = *((ULong*)(prev + lx));
+ word1 >>= 24; /* 0 0 0 b8 */
+ word2 >>= 24;
+ word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
+ word2 = word2 | (word22 << 8);
+ word3 = word1 & word2;
+ word1 &= mask;
+ word2 &= mask;
+ word3 &= (~mask); /* 0x1010101, check last bit */
+ word1 >>= 1;
+ word1 = word1 + (word2 >> 1);
+ word1 += word3;
+ *((ULong*)(rec += 4)) = word1;
+ prev += offset;
+ }
+ return 1;
+ } /* rnd */
+ } /* tmp */
+}
+
+/**********************************************************************************/
+Int GetPredAdvBy1x1(
+ UChar *prev, /* i */
+ UChar *rec, /* i */
+ Int lx, /* i */
+ Int rnd1 /* i */
+)
+{
+ Int i; /* loop variable */
+ Int offset;
+ ULong x1, x2, x1m, x2m, y1, y2, y1m, y2m; /* new way */
+ Int tmp;
+ Int rnd2;
+ ULong mask;
+
+ /* initialize offset to adjust pixel counter */
+ /* the next row; full-pel resolution */
+ offset = lx - B_SIZE; /* offset for prev */
+
+ rnd2 = rnd1 + 1;
+ rnd2 |= (rnd2 << 8);
+ rnd2 |= (rnd2 << 16);
+
+ mask = 0x3F;
+ mask |= (mask << 8);
+ mask |= (mask << 16); /* 0x3f3f3f3f */
+
+ tmp = (uintptr_t)prev & 3;
+
+ rec -= 4; /* preset */
+
+ if (tmp == 0) /* word-aligned */
+ {
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
+ y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ y2m = x1m >> 8;
+ y2 = x1 >> 8;
+ y2m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */
+ y2 |= (y1 << 24);
+ x1m += y2m; /* a3+b3+a4+b4, ....., a0+b0+a1+b1 */
+ x1 += y2;
+ x1 += rnd2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((ULong*)(rec += 4)) = x1m; /* save x1m */
+
+ y2m = y1m >> 8;
+ y2 = y1 >> 8;
+ y2m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */
+ y2 |= (x2 << 24);
+ y1m += y2m; /* a7+b7+a8+b8, ....., a4+b4+a5+b5 */
+ y1 += y2;
+ y1 += rnd2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((ULong*)(rec += 4)) = y1m; /* save y1m */
+
+ rec += 8;
+ prev += offset;
+ }
+
+ return 1;
+ }
+ else if (tmp == 1)
+ {
+ prev--; /* to word-aligned */
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
+ y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ x1m >>= 8 ;
+ x1 >>= 8;
+ x1m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */
+ x1 |= (y1 << 24);
+ y2m = (y1m << 16);
+ y2 = (y1 << 16);
+ y2m |= (x1m >> 8); /* a5+b5, a4+b4, a3+b3, a2+b2 */
+ y2 |= (x1 >> 8);
+ x1 += rnd2;
+ x1m += y2m; /* a4+b4+a5+b5, ....., a1+b1+a2+b2 */
+ x1 += y2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((ULong*)(rec += 4)) = x1m; /* save x1m */
+
+ y1m >>= 8;
+ y1 >>= 8;
+ y1m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */
+ y1 |= (x2 << 24);
+ y2m = (x2m << 16);
+ y2 = (x2 << 16);
+ y2m |= (y1m >> 8); /* a9+b9, a8+b8, a7+b7, a6+b6,*/
+ y2 |= (y1 >> 8);
+ y1 += rnd2;
+ y1m += y2m; /* a8+b8+a9+b9, ....., a5+b5+a6+b6 */
+ y1 += y2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((ULong*)(rec += 4)) = y1m; /* save y1m */
+
+ rec += 8;
+ prev += offset;
+ }
+ return 1;
+ }
+ else if (tmp == 2)
+ {
+ prev -= 2; /* to word-aligned */
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
+ y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ x1m >>= 16 ;
+ x1 >>= 16;
+ x1m |= (y1m << 16); /* a5+b5, a4+b4, a3+b3, a2+b2 */
+ x1 |= (y1 << 16);
+ y2m = (y1m << 8);
+ y2 = (y1 << 8);
+ y2m |= (x1m >> 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */
+ y2 |= (x1 >> 8);
+ x1 += rnd2;
+ x1m += y2m; /* a5+b5+a6+b6, ....., a2+b2+a3+b3 */
+ x1 += y2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((ULong*)(rec += 4)) = x1m; /* save x1m */
+
+ y1m >>= 16;
+ y1 >>= 16;
+ y1m |= (x2m << 16); /* a9+b9, a8+b8, a7+b7, a6+b6 */
+ y1 |= (x2 << 16);
+ y2m = (x2m << 8);
+ y2 = (x2 << 8);
+ y2m |= (y1m >> 8); /* a10+b10, a9+b9, a8+b8, a7+b7,*/
+ y2 |= (y1 >> 8);
+ y1 += rnd2;
+ y1m += y2m; /* a9+b9+a10+b10, ....., a6+b6+a7+b7 */
+ y1 += y2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((ULong*)(rec += 4)) = y1m; /* save y1m */
+
+ rec += 8;
+ prev += offset;
+ }
+ return 1;
+ }
+ else /* tmp == 3 */
+ {
+ prev -= 3; /* to word-aligned */
+ for (i = B_SIZE; i > 0; i--)
+ {
+ x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
+ x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
+ y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
+ y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
+
+ x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
+ x2m = (x2 >> 2) & mask;
+ x1 = x1 ^(x1m << 2);
+ x2 = x2 ^(x2m << 2);
+ x1m += x2m;
+ x1 += x2;
+
+ /* x2m, x2 free */
+ y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
+ y2m = (y2 >> 2) & mask;
+ y1 = y1 ^(y1m << 2);
+ y2 = y2 ^(y2m << 2);
+ y1m += y2m;
+ y1 += y2;
+
+ /* y2m, y2 free */
+ /* x2m, x2 free */
+ x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
+ y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
+ x2m = (x2 >> 2) & mask;
+ y2m = (y2 >> 2) & mask;
+ x2 = x2 ^(x2m << 2);
+ y2 = y2 ^(y2m << 2);
+ x2m += y2m;
+ x2 += y2;
+ /* y2m, y2 free */
+
+ /* now operate on x1m, x1, y1m, y1, x2m, x2 */
+ /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
+ /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
+ /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
+ /* x1, y1, x2 */
+
+ x1m >>= 24 ;
+ x1 >>= 24;
+ x1m |= (y1m << 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */
+ x1 |= (y1 << 8);
+
+ x1m += y1m; /* a6+b6+a7+b7, ....., a3+b3+a4+b4 */
+ x1 += y1;
+ x1 += rnd2;
+ x1 &= (mask << 2);
+ x1m += (x1 >> 2);
+ *((ULong*)(rec += 4)) = x1m; /* save x1m */
+
+ y1m >>= 24;
+ y1 >>= 24;
+ y1m |= (x2m << 8); /* a10+b10, a9+b9, a8+b8, a7+b7 */
+ y1 |= (x2 << 8);
+ y1m += x2m; /* a10+b10+a11+b11, ....., a7+b7+a8+b8 */
+ y1 += x2;
+ y1 += rnd2;
+ y1 &= (mask << 2);
+ y1m += (y1 >> 2);
+ *((ULong*)(rec += 4)) = y1m; /* save y1m */
+
+ rec += 8;
+ prev += offset;
+ }
+ return 1;
+ }
+}
+
+
+/*=============================================================================
+ Function: EncGetPredOutside
+ Date: 04/17/2001
+ Purpose: - modified from GetPredOutside in the decoder.
+ Modified: 09/24/05
+ use the existing non-initialized padded region
+=============================================================================*/
+// not really needed since padding is included
+#define PAD_CORNER { temp = *src; \
+ temp |= (temp<<8); \
+ temp |= (temp<<16); \
+ *((ULong*)dst) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; }
+
+#define PAD_ROW { temp = *((ULong*)src); \
+ temp2 = *((ULong*)(src+4)); \
+ *((ULong*)dst) = temp; \
+ *((ULong*)(dst+4)) = temp2; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp2; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp2; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp2; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp2; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp2; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp2; \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp2; }
+
+#define PAD_COL { temp = *src; temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)dst) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; \
+ temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
+ *((ULong*)(dst+=lx)) = temp; \
+ *((ULong*)(dst+4)) = temp; }
+
+
+Int EncGetPredOutside(Int xpos, Int ypos, UChar *c_prev, UChar *rec,
+ Int width, Int height, Int rnd1)
+{
+ Int lx;
+ UChar *src, *dst;
+ ULong temp, temp2;
+ Int xoffset;
+
+ lx = width + 16; /* only works for chroma */
+
+ if (xpos < 0)
+ {
+ if (ypos < 0) /* pad top-left */
+ {
+ /* pad corner */
+ src = c_prev;
+ dst = c_prev - (lx << 3) - 8;
+ PAD_CORNER
+
+ /* pad top */
+ dst = c_prev - (lx << 3);
+ PAD_ROW
+
+ /* pad left */
+ dst = c_prev - 8;
+ PAD_COL
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ else if ((ypos >> 1) < (height - 8)) /* pad left of frame */
+ {
+ /* pad left */
+ src = c_prev + (ypos >> 1) * lx;
+ dst = src - 8;
+ PAD_COL
+ /* pad extra row */
+ temp = *(src += lx);
+ temp |= (temp << 8);
+ temp |= (temp << 16);
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst + 4)) = temp;
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ else /* pad bottom-left */
+ {
+ /* pad corner */
+ src = c_prev + (height - 1) * lx;
+ dst = src + lx - 8;
+ PAD_CORNER
+
+ /* pad bottom */
+ dst = src + lx;
+ PAD_ROW
+
+ /* pad left */
+ src -= (lx << 3);
+ src += lx;
+ dst = src - 8;
+ PAD_COL
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ }
+ else if ((xpos >> 1) < (width - 8))
+ {
+ if (ypos < 0) /* pad top of frame */
+ {
+ xoffset = (xpos >> 1) & 0x3;
+ src = c_prev + (xpos >> 1) - xoffset;
+ dst = src - (lx << 3);
+ PAD_ROW
+ if (xoffset || (xpos&1))
+ {
+ temp = *((ULong*)(src + 8));
+ dst = src - (lx << 3) + 8;
+ *((ULong*)dst) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ }
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ else /* pad bottom of frame */
+ {
+ xoffset = (xpos >> 1) & 0x3;
+ src = c_prev + (xpos >> 1) - xoffset + (height - 1) * lx;
+ dst = src + lx;
+ PAD_ROW
+ if (xoffset || (xpos&1))
+ {
+ temp = *((ULong*)(src + 8));
+ dst = src + lx + 8;
+ *((ULong*)dst) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst += lx)) = temp;
+ }
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ }
+ else
+ {
+ if (ypos < 0) /* pad top-right */
+ {
+ /* pad corner */
+ src = c_prev + width - 1;
+ dst = src - (lx << 3) + 1;
+ PAD_CORNER
+
+ /* pad top */
+ src -= 7;
+ dst = src - (lx << 3);
+ PAD_ROW
+
+ /* pad left */
+ src += 7;
+ dst = src + 1;
+ PAD_COL
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ else if ((ypos >> 1) < (height - B_SIZE)) /* pad right of frame */
+ {
+ /* pad left */
+ src = c_prev + (ypos >> 1) * lx + width - 1;
+ dst = src + 1;
+ PAD_COL
+ /* pad extra row */
+ temp = *(src += lx);
+ temp |= (temp << 8);
+ temp |= (temp << 16);
+ *((ULong*)(dst += lx)) = temp;
+ *((ULong*)(dst + 4)) = temp;
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ else /* pad bottom-right */
+ {
+ /* pad left */
+ src = c_prev + (height - 8) * lx + width - 1;
+ dst = src + 1;
+ PAD_COL
+
+ /* pad corner */
+ dst = src + lx + 1;
+ PAD_CORNER
+
+ /* pad bottom */
+ src -= 7;
+ dst = src + lx;
+ PAD_ROW
+
+ GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
+ rec, lx, rnd1);
+
+ return 1;
+ }
+ }
+}
+
+/* ====================================================================== /
+ Function : Copy_MB_from_Vop()
+ Date : 04/17/2001
+ ====================================================================== */
+
+void Copy_MB_from_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int pitch)
+{
+ Int row, col, i;
+ Int *src1, *src2;
+ Int offset = pitch - MB_SIZE;
+ ULong temp;
+
+ for (i = 0; i < 4; i += 2)
+ {
+ src1 = yChan[i];
+ src2 = yChan[i+1];
+
+ row = B_SIZE;
+ while (row--)
+ {
+ col = B_SIZE;
+ while (col)
+ {
+ temp = *((ULong*)comp);
+ *src1++ = (Int)(temp & 0xFF);
+ *src1++ = (Int)((temp >> 8) & 0xFF);
+ *src1++ = (Int)((temp >> 16) & 0xFF);
+ *src1++ = (Int)((temp >> 24) & 0xFF);
+ comp += 4;
+ col -= 4;
+ }
+ col = B_SIZE;
+ while (col)
+ {
+ temp = *((ULong*)comp);
+ *src2++ = (Int)(temp & 0xFF);
+ *src2++ = (Int)((temp >> 8) & 0xFF);
+ *src2++ = (Int)((temp >> 16) & 0xFF);
+ *src2++ = (Int)((temp >> 24) & 0xFF);
+ comp += 4;
+ col -= 4;
+ }
+ comp += offset;
+ }
+ }
+ return ;
+}
+
+/* ====================================================================== /
+ Function : Copy_B_from_Vop()
+ Date : 04/17/2001
+/ ====================================================================== */
+
+void Copy_B_from_Vop(UChar *comp, Int cChan[], Int pitch)
+{
+ Int row, col;
+ Int offset = pitch - B_SIZE;
+ ULong temp;
+
+ row = B_SIZE;
+ while (row--)
+ {
+ col = B_SIZE;
+ while (col)
+ {
+ temp = *((ULong*)comp);
+ *cChan++ = (Int)(temp & 0xFF);
+ *cChan++ = (Int)((temp >> 8) & 0xFF);
+ *cChan++ = (Int)((temp >> 16) & 0xFF);
+ *cChan++ = (Int)((temp >> 24) & 0xFF);
+ comp += 4;
+ col -= 4;
+ }
+ comp += offset;
+ }
+}
+
+/* ====================================================================== /
+ Function : Copy_MB_into_Vop()
+ Date : 04/17/2001
+ History : From decoder
+/ ====================================================================== */
+
+void Copy_MB_into_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int pitch)
+{
+ Int row, col, i;
+ Int *src1, *src2;
+ Int offset = pitch - MB_SIZE;
+ UChar mask = 0xFF;
+ Int tmp;
+ ULong temp;
+
+ for (i = 0; i < 4; i += 2)
+ {
+ src1 = yChan[i];
+ src2 = yChan[i+1];
+
+ row = B_SIZE;
+ while (row--)
+ {
+ col = B_SIZE;
+ while (col)
+ {
+ tmp = (*src1++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp = tmp << 24;
+ tmp = (*src1++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= (tmp << 16);
+ tmp = (*src1++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= (tmp << 8);
+ tmp = (*src1++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= tmp;
+ *((ULong*)comp) = temp;
+ comp += 4;
+ col -= 4;
+ }
+ col = B_SIZE;
+ while (col)
+ {
+ tmp = (*src2++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp = tmp << 24;
+ tmp = (*src2++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= (tmp << 16);
+ tmp = (*src2++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= (tmp << 8);
+ tmp = (*src2++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= tmp;
+ *((ULong*)comp) = temp;
+ comp += 4;
+ col -= 4;
+ }
+ comp += offset;
+ }
+ }
+ return ;
+}
+
+
+/* ====================================================================== /
+ Function : Copy_B_into_Vop()
+ Date : 04/17/2001
+ History : From decoder
+/ ====================================================================== */
+
+void Copy_B_into_Vop(UChar *comp, Int cChan[], Int pitch)
+{
+ Int row, col;
+ Int offset = pitch - B_SIZE;
+ Int tmp;
+ UChar mask = 0xFF;
+ ULong temp;
+
+ row = B_SIZE;
+ while (row--)
+ {
+ col = B_SIZE;
+ while (col)
+ {
+ tmp = (*cChan++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp = tmp << 24;
+ tmp = (*cChan++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= (tmp << 16);
+ tmp = (*cChan++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= (tmp << 8);
+ tmp = (*cChan++);
+ if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
+ temp |= tmp;
+ *((ULong*)comp) = temp;
+ comp += 4;
+ col -= 4;
+ }
+ comp += offset;
+ }
+}
+
+/* ======================================================================== */
+/* Function : get_MB( ) */
+/* Date : 10/03/2000 */
+/* Purpose : Copy 4 Y to reference frame */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+void get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v,
+ Short mb[6][64], Int lx, Int lx_uv)
+
+{
+ Int i, j, count = 0, count1 = 0;
+ Int k1 = lx - MB_SIZE, k2 = lx_uv - B_SIZE;
+
+ for (i = 0; i < B_SIZE; i++)
+ {
+ for (j = 0; j < B_SIZE; j++)
+ {
+ mb[0][count] = (Int)(*c_prev++);
+ mb[4][count] = (Int)(*c_prev_u++);
+ mb[5][count++] = (Int)(*c_prev_v++);
+ }
+
+ for (j = 0; j < B_SIZE; j++)
+ mb[1][count1++] = (Int)(*c_prev++);
+
+ c_prev += k1;
+ c_prev_u += k2;
+ c_prev_v += k2;
+
+
+ }
+
+ count = count1 = 0;
+ for (i = 0; i < B_SIZE; i++)
+ {
+ for (j = 0; j < B_SIZE; j++)
+ mb[2][count++] = (Int)(*c_prev++);
+
+ for (j = 0; j < B_SIZE; j++)
+ mb[3][count1++] = (Int)(*c_prev++);
+
+ c_prev += k1;
+ }
+}
+
+void PutSkippedBlock(UChar *rec, UChar *prev, Int lx)
+{
+ UChar *end;
+ Int offset = (lx - 8) >> 2;
+ Int *src, *dst;
+
+ dst = (Int*)rec;
+ src = (Int*)prev;
+
+ end = prev + (lx << 3);
+
+ do
+ {
+ *dst++ = *src++;
+ *dst++ = *src++;
+ dst += offset;
+ src += offset;
+ }
+ while ((uintptr_t)src < (uintptr_t)end);
+
+ return ;
+}
diff --git a/media/codecs/m4v_h263/enc/src/motion_est.cpp b/media/codecs/m4v_h263/enc/src/motion_est.cpp
new file mode 100644
index 0000000..997b78d
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/motion_est.cpp
@@ -0,0 +1,1741 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4enc_lib.h"
+#include "mp4lib_int.h"
+#include "m4venc_oscl.h"
+
+//#define PRINT_MV
+#define MIN_GOP 1 /* minimum size of GOP, 1/23/01, need to be tested */
+
+#define CANDIDATE_DISTANCE 0 /* distance candidate from one another to consider as a distinct one */
+/* shouldn't be more than 3 */
+
+#define ZERO_MV_PREF 0 /* 0: bias (0,0)MV before full-pel search, lowest complexity*/
+/* 1: bias (0,0)MV after full-pel search, before half-pel, highest comp */
+/* 2: bias (0,0)MV after half-pel, high comp, better PSNR */
+
+#define RASTER_REFRESH /* instead of random INTRA refresh, do raster scan, 2/26/01 */
+
+#ifdef RASTER_REFRESH
+#define TARGET_REFRESH_PER_REGION 4 /* , no. MB per frame to be INTRA refreshed */
+#else
+#define TARGET_REFRESH_PER_REGION 1 /* , no. MB per region to be INTRA refreshed */
+#endif
+
+#define ALL_CAND_EQUAL 10 /* any number greater than 5 will work */
+
+#define NumPixelMB 256 /* number of pixels used in SAD calculation */
+
+#define DEF_8X8_WIN 3 /* search region for 8x8 MVs around the 16x16 MV */
+#define MB_Nb 256
+
+#define PREF_NULL_VEC 129 /* for zero vector bias */
+#define PREF_16_VEC 129 /* 1MV bias versus 4MVs*/
+#define PREF_INTRA 512 /* bias for INTRA coding */
+
+const static Int tab_exclude[9][9] = // [last_loc][curr_loc]
+{
+ {0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 1, 1, 1, 0, 0},
+ {0, 0, 0, 0, 1, 1, 1, 1, 1},
+ {0, 0, 0, 0, 0, 0, 1, 1, 1},
+ {0, 1, 1, 0, 0, 0, 1, 1, 1},
+ {0, 1, 1, 0, 0, 0, 0, 0, 1},
+ {0, 1, 1, 1, 1, 0, 0, 0, 1},
+ {0, 0, 1, 1, 1, 0, 0, 0, 0},
+ {0, 0, 1, 1, 1, 1, 1, 0, 0}
+}; //to decide whether to continue or compute
+
+const static Int refine_next[8][2] = /* [curr_k][increment] */
+{
+ {0, 0}, {2, 0}, {1, 1}, {0, 2}, { -1, 1}, { -2, 0}, { -1, -1}, {0, -2}
+};
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void MBMotionSearch(VideoEncData *video, UChar *cur, UChar *best_cand[],
+ Int i0, Int j0, Int type_pred, Int fullsearch, Int *hp_guess);
+
+ Int fullsearch(VideoEncData *video, Vol *currVol, UChar *ref, UChar *cur,
+ Int *imin, Int *jmin, Int ilow, Int ihigh, Int jlow, Int jhigh);
+ Int fullsearchBlk(VideoEncData *video, Vol *currVol, UChar *cent, UChar *cur,
+ Int *imin, Int *jmin, Int ilow, Int ihigh, Int jlow, Int jhigh, Int range);
+ void CandidateSelection(Int *mvx, Int *mvy, Int *num_can, Int imb, Int jmb,
+ VideoEncData *video, Int type_pred);
+ void RasterIntraUpdate(UChar *intraArray, UChar *Mode, Int totalMB, Int numRefresh);
+ void ResetIntraUpdate(UChar *intraArray, Int totalMB);
+ void ResetIntraUpdateRegion(UChar *intraArray, Int start_i, Int rwidth,
+ Int start_j, Int rheight, Int mbwidth, Int mbheight);
+
+ void MoveNeighborSAD(Int dn[], Int new_loc);
+ Int FindMin(Int dn[]);
+ void PrepareCurMB(VideoEncData *video, UChar *cur);
+
+#ifdef __cplusplus
+}
+#endif
+
+/***************************************/
+/* 2/28/01, for HYPOTHESIS TESTING */
+#ifdef HTFM /* defined in mp4def.h */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ void CalcThreshold(double pf, double exp_lamda[], Int nrmlz_th[]);
+ void HTFMPrepareCurMB(VideoEncData *video, HTFM_Stat *htfm_stat, UChar *cur);
+#ifdef __cplusplus
+}
+#endif
+
+
+#define HTFM_Pf 0.25 /* 3/2/1, probability of false alarm, can be varied from 0 to 0.5 */
+/***************************************/
+#endif
+
+#ifdef _SAD_STAT
+ULong num_MB = 0;
+ULong num_HP_MB = 0;
+ULong num_Blk = 0;
+ULong num_HP_Blk = 0;
+ULong num_cand = 0;
+ULong num_better_hp = 0;
+ULong i_dist_from_guess = 0;
+ULong j_dist_from_guess = 0;
+ULong num_hp_not_zero = 0;
+#endif
+
+
+
+/*==================================================================
+ Function: MotionEstimation
+ Date: 10/3/2000
+ Purpose: Go through all macroblock for motion search and
+ determine scene change detection.
+====================================================================*/
+
+void MotionEstimation(VideoEncData *video)
+{
+ UChar use_4mv = video->encParams->MV8x8_Enabled;
+ Vol *currVol = video->vol[video->currLayer];
+ Vop *currVop = video->currVop;
+ VideoEncFrameIO *currFrame = video->input;
+ Int i, j, comp;
+ Int mbwidth = currVol->nMBPerRow;
+ Int mbheight = currVol->nMBPerCol;
+ Int totalMB = currVol->nTotalMB;
+ Int width = currFrame->pitch;
+ UChar *mode_mb, *Mode = video->headerInfo.Mode;
+ MOT *mot_mb, **mot = video->mot;
+ UChar *intraArray = video->intraArray;
+ Int FS_en = video->encParams->FullSearch_Enabled;
+ void (*ComputeMBSum)(UChar *, Int, MOT *) = video->functionPointer->ComputeMBSum;
+ void (*ChooseMode)(UChar*, UChar*, Int, Int) = video->functionPointer->ChooseMode;
+
+ Int numIntra, start_i, numLoop, incr_i;
+ Int mbnum, offset;
+ UChar *cur, *best_cand[5];
+ Int sad8 = 0, sad16 = 0;
+ Int totalSAD = 0; /* average SAD for rate control */
+ Int skip_halfpel_4mv;
+ Int f_code_p, f_code_n, max_mag = 0, min_mag = 0;
+ Int type_pred;
+ Int xh[5] = {0, 0, 0, 0, 0};
+ Int yh[5] = {0, 0, 0, 0, 0}; /* half-pel */
+ UChar hp_mem4MV[17*17*4];
+
+#ifdef HTFM
+ /***** HYPOTHESIS TESTING ********/ /* 2/28/01 */
+ Int collect = 0;
+ HTFM_Stat htfm_stat;
+ double newvar[16];
+ double exp_lamda[15];
+ /*********************************/
+#endif
+ Int hp_guess = 0;
+#ifdef PRINT_MV
+ FILE *fp_debug;
+#endif
+
+// FILE *fstat;
+// static int frame_num = 0;
+
+ offset = 0;
+
+ if (video->currVop->predictionType == I_VOP)
+ { /* compute the SAV */
+ mbnum = 0;
+ cur = currFrame->yChan;
+
+ for (j = 0; j < mbheight; j++)
+ {
+ for (i = 0; i < mbwidth; i++)
+ {
+ video->mbnum = mbnum;
+ mot_mb = mot[mbnum];
+
+ (*ComputeMBSum)(cur + (i << 4), width, mot_mb);
+
+ totalSAD += mot_mb[0].sad;
+
+ mbnum++;
+ }
+ cur += (width << 4);
+ }
+
+ video->sumMAD = (float)totalSAD / (float)NumPixelMB;
+
+ ResetIntraUpdate(intraArray, totalMB);
+
+ return ;
+ }
+
+ /* 09/20/05 */
+ if (video->prevBaseVop->padded == 0 && !video->encParams->H263_Enabled)
+ {
+ PaddingEdge(video->prevBaseVop);
+ video->prevBaseVop->padded = 1;
+ }
+
+ /* Random INTRA update */
+ /* suggest to do it in CodeMB */
+ /* 2/21/2001 */
+ //if(video->encParams->RC_Type == CBR_1 || video->encParams->RC_Type == CBR_2)
+ if (video->currLayer == 0 && video->encParams->Refresh)
+ {
+ RasterIntraUpdate(intraArray, Mode, totalMB, video->encParams->Refresh);
+ }
+
+ video->sad_extra_info = NULL;
+
+#ifdef HTFM
+ /***** HYPOTHESIS TESTING ********/ /* 2/28/01 */
+ InitHTFM(video, &htfm_stat, newvar, &collect);
+ /*********************************/
+#endif
+
+ if ((video->encParams->SceneChange_Det == 1) /*&& video->currLayer==0 */
+ && ((video->encParams->LayerFrameRate[0] < 5.0) || (video->numVopsInGOP > MIN_GOP)))
+ /* do not try to detect a new scene if low frame rate and too close to previous I-frame */
+ {
+ incr_i = 2;
+ numLoop = 2;
+ start_i = 1;
+ type_pred = 0; /* for initial candidate selection */
+ }
+ else
+ {
+ incr_i = 1;
+ numLoop = 1;
+ start_i = 0;
+ type_pred = 2;
+ }
+
+ /* First pass, loop thru half the macroblock */
+ /* determine scene change */
+ /* Second pass, for the rest of macroblocks */
+ numIntra = 0;
+ while (numLoop--)
+ {
+ for (j = 0; j < mbheight; j++)
+ {
+ if (incr_i > 1)
+ start_i = (start_i == 0 ? 1 : 0) ; /* toggle 0 and 1 */
+
+ offset = width * (j << 4) + (start_i << 4);
+
+ mbnum = j * mbwidth + start_i;
+
+ for (i = start_i; i < mbwidth; i += incr_i)
+ {
+ video->mbnum = mbnum;
+ mot_mb = mot[mbnum];
+ mode_mb = Mode + mbnum;
+
+ cur = currFrame->yChan + offset;
+
+
+ if (*mode_mb != MODE_INTRA)
+ {
+#if defined(HTFM)
+ HTFMPrepareCurMB(video, &htfm_stat, cur);
+#else
+ PrepareCurMB(video, cur);
+#endif
+ /************************************************************/
+ /******** full-pel 1MV and 4MVs search **********************/
+
+#ifdef _SAD_STAT
+ num_MB++;
+#endif
+ MBMotionSearch(video, cur, best_cand, i << 4, j << 4, type_pred,
+ FS_en, &hp_guess);
+
+#ifdef PRINT_MV
+ fp_debug = fopen("c:\\bitstream\\mv1_debug.txt", "a");
+ fprintf(fp_debug, "#%d (%d,%d,%d) : ", mbnum, mot_mb[0].x, mot_mb[0].y, mot_mb[0].sad);
+ fprintf(fp_debug, "(%d,%d,%d) : (%d,%d,%d) : (%d,%d,%d) : (%d,%d,%d) : ==>\n",
+ mot_mb[1].x, mot_mb[1].y, mot_mb[1].sad,
+ mot_mb[2].x, mot_mb[2].y, mot_mb[2].sad,
+ mot_mb[3].x, mot_mb[3].y, mot_mb[3].sad,
+ mot_mb[4].x, mot_mb[4].y, mot_mb[4].sad);
+ fclose(fp_debug);
+#endif
+ sad16 = mot_mb[0].sad;
+#ifdef NO_INTER4V
+ sad8 = sad16;
+#else
+ sad8 = mot_mb[1].sad + mot_mb[2].sad + mot_mb[3].sad + mot_mb[4].sad;
+#endif
+
+ /* choose between INTRA or INTER */
+ (*ChooseMode)(mode_mb, cur, width, ((sad8 < sad16) ? sad8 : sad16));
+ }
+ else /* INTRA update, use for prediction 3/23/01 */
+ {
+ mot_mb[0].x = mot_mb[0].y = 0;
+ }
+
+ if (*mode_mb == MODE_INTRA)
+ {
+ numIntra++ ;
+
+ /* compute SAV for rate control and fast DCT, 11/28/00 */
+ (*ComputeMBSum)(cur, width, mot_mb);
+
+ /* leave mot_mb[0] as it is for fast motion search */
+ /* set the 4 MVs to zeros */
+ for (comp = 1; comp <= 4; comp++)
+ {
+ mot_mb[comp].x = 0;
+ mot_mb[comp].y = 0;
+ }
+#ifdef PRINT_MV
+ fp_debug = fopen("c:\\bitstream\\mv1_debug.txt", "a");
+ fprintf(fp_debug, "\n");
+ fclose(fp_debug);
+#endif
+ }
+ else /* *mode_mb = MODE_INTER;*/
+ {
+ if (video->encParams->HalfPel_Enabled)
+ {
+#ifdef _SAD_STAT
+ num_HP_MB++;
+#endif
+ /* find half-pel resolution motion vector */
+ FindHalfPelMB(video, cur, mot_mb, best_cand[0],
+ i << 4, j << 4, xh, yh, hp_guess);
+#ifdef PRINT_MV
+ fp_debug = fopen("c:\\bitstream\\mv1_debug.txt", "a");
+ fprintf(fp_debug, "(%d,%d), %d\n", mot_mb[0].x, mot_mb[0].y, mot_mb[0].sad);
+ fclose(fp_debug);
+#endif
+ skip_halfpel_4mv = ((sad16 - mot_mb[0].sad) <= (MB_Nb >> 1) + 1);
+ sad16 = mot_mb[0].sad;
+
+#ifndef NO_INTER4V
+ if (use_4mv && !skip_halfpel_4mv)
+ {
+ /* Also decide 1MV or 4MV !!!!!!!!*/
+ sad8 = FindHalfPelBlk(video, cur, mot_mb, sad16,
+ best_cand, mode_mb, i << 4, j << 4, xh, yh, hp_mem4MV);
+
+#ifdef PRINT_MV
+ fp_debug = fopen("c:\\bitstream\\mv1_debug.txt", "a");
+ fprintf(fp_debug, " (%d,%d,%d) : (%d,%d,%d) : (%d,%d,%d) : (%d,%d,%d) \n",
+ mot_mb[1].x, mot_mb[1].y, mot_mb[1].sad,
+ mot_mb[2].x, mot_mb[2].y, mot_mb[2].sad,
+ mot_mb[3].x, mot_mb[3].y, mot_mb[3].sad,
+ mot_mb[4].x, mot_mb[4].y, mot_mb[4].sad);
+ fclose(fp_debug);
+#endif
+ }
+#endif /* NO_INTER4V */
+ }
+ else /* HalfPel_Enabled ==0 */
+ {
+#ifndef NO_INTER4V
+ //if(sad16 < sad8-PREF_16_VEC)
+ if (sad16 - PREF_16_VEC > sad8)
+ {
+ *mode_mb = MODE_INTER4V;
+ }
+#endif
+ }
+#if (ZERO_MV_PREF==2) /* use mot_mb[7].sad as d0 computed in MBMotionSearch*/
+ /******************************************************/
+ if (mot_mb[7].sad - PREF_NULL_VEC < sad16 && mot_mb[7].sad - PREF_NULL_VEC < sad8)
+ {
+ mot_mb[0].sad = mot_mb[7].sad - PREF_NULL_VEC;
+ mot_mb[0].x = mot_mb[0].y = 0;
+ *mode_mb = MODE_INTER;
+ }
+ /******************************************************/
+#endif
+ if (*mode_mb == MODE_INTER)
+ {
+ if (mot_mb[0].x == 0 && mot_mb[0].y == 0) /* use zero vector */
+ mot_mb[0].sad += PREF_NULL_VEC; /* add back the bias */
+
+ mot_mb[1].sad = mot_mb[2].sad = mot_mb[3].sad = mot_mb[4].sad = (mot_mb[0].sad + 2) >> 2;
+ mot_mb[1].x = mot_mb[2].x = mot_mb[3].x = mot_mb[4].x = mot_mb[0].x;
+ mot_mb[1].y = mot_mb[2].y = mot_mb[3].y = mot_mb[4].y = mot_mb[0].y;
+
+ }
+ }
+
+ /* find maximum magnitude */
+ /* compute average SAD for rate control, 11/28/00 */
+ if (*mode_mb == MODE_INTER)
+ {
+#ifdef PRINT_MV
+ fp_debug = fopen("c:\\bitstream\\mv1_debug.txt", "a");
+ fprintf(fp_debug, "%d MODE_INTER\n", mbnum);
+ fclose(fp_debug);
+#endif
+ totalSAD += mot_mb[0].sad;
+ if (mot_mb[0].x > max_mag)
+ max_mag = mot_mb[0].x;
+ if (mot_mb[0].y > max_mag)
+ max_mag = mot_mb[0].y;
+ if (mot_mb[0].x < min_mag)
+ min_mag = mot_mb[0].x;
+ if (mot_mb[0].y < min_mag)
+ min_mag = mot_mb[0].y;
+ }
+ else if (*mode_mb == MODE_INTER4V)
+ {
+#ifdef PRINT_MV
+ fp_debug = fopen("c:\\bitstream\\mv1_debug.txt", "a");
+ fprintf(fp_debug, "%d MODE_INTER4V\n", mbnum);
+ fclose(fp_debug);
+#endif
+ totalSAD += sad8;
+ for (comp = 1; comp <= 4; comp++)
+ {
+ if (mot_mb[comp].x > max_mag)
+ max_mag = mot_mb[comp].x;
+ if (mot_mb[comp].y > max_mag)
+ max_mag = mot_mb[comp].y;
+ if (mot_mb[comp].x < min_mag)
+ min_mag = mot_mb[comp].x;
+ if (mot_mb[comp].y < min_mag)
+ min_mag = mot_mb[comp].y;
+ }
+ }
+ else /* MODE_INTRA */
+ {
+#ifdef PRINT_MV
+ fp_debug = fopen("c:\\bitstream\\mv1_debug.txt", "a");
+ fprintf(fp_debug, "%d MODE_INTRA\n", mbnum);
+ fclose(fp_debug);
+#endif
+ totalSAD += mot_mb[0].sad;
+ }
+ mbnum += incr_i;
+ offset += (incr_i << 4);
+
+ }
+ }
+
+ if (incr_i > 1 && numLoop) /* scene change on and first loop */
+ {
+ //if(numIntra > ((totalMB>>3)<<1) + (totalMB>>3)) /* 75% of 50%MBs */
+ if (numIntra > (0.30*(totalMB / 2.0))) /* 15% of 50%MBs */
+ {
+ /******** scene change detected *******************/
+ currVop->predictionType = I_VOP;
+ M4VENC_MEMSET(Mode, MODE_INTRA, sizeof(UChar)*totalMB); /* set this for MB level coding*/
+ currVop->quantizer = video->encParams->InitQuantIvop[video->currLayer];
+
+ /* compute the SAV for rate control & fast DCT */
+ totalSAD = 0;
+ offset = 0;
+ mbnum = 0;
+ cur = currFrame->yChan;
+
+ for (j = 0; j < mbheight; j++)
+ {
+ for (i = 0; i < mbwidth; i++)
+ {
+ video->mbnum = mbnum;
+ mot_mb = mot[mbnum];
+
+
+ (*ComputeMBSum)(cur + (i << 4), width, mot_mb);
+ totalSAD += mot_mb[0].sad;
+
+ mbnum++;
+ }
+ cur += (width << 4);
+ }
+
+ video->sumMAD = (float)totalSAD / (float)NumPixelMB;
+ ResetIntraUpdate(intraArray, totalMB);
+ /* video->numVopsInGOP=0; 3/13/01 move it to vop.c*/
+
+ return ;
+ }
+ }
+ /******** no scene change, continue motion search **********************/
+ start_i = 0;
+ type_pred++; /* second pass */
+ }
+
+ video->sumMAD = (float)totalSAD / (float)NumPixelMB; /* avg SAD */
+
+ /* find f_code , 10/27/2000 */
+ f_code_p = 1;
+ while ((max_mag >> (4 + f_code_p)) > 0)
+ f_code_p++;
+
+ f_code_n = 1;
+ min_mag *= -1;
+ while ((min_mag - 1) >> (4 + f_code_n) > 0)
+ f_code_n++;
+
+ currVop->fcodeForward = (f_code_p > f_code_n ? f_code_p : f_code_n);
+
+#ifdef HTFM
+ /***** HYPOTHESIS TESTING ********/ /* 2/28/01 */
+ if (collect)
+ {
+ collect = 0;
+ UpdateHTFM(video, newvar, exp_lamda, &htfm_stat);
+ }
+ /*********************************/
+#endif
+
+ return ;
+}
+
+
+#ifdef HTFM
+void InitHTFM(VideoEncData *video, HTFM_Stat *htfm_stat, double *newvar, Int *collect)
+{
+ Int i;
+ Int lx = video->currVop->width; // padding
+ Int lx2 = lx << 1;
+ Int lx3 = lx2 + lx;
+ Int rx = video->currVop->pitch;
+ Int rx2 = rx << 1;
+ Int rx3 = rx2 + rx;
+
+ Int *offset, *offset2;
+
+ /* 4/11/01, collect data every 30 frames, doesn't have to be base layer */
+ if (((Int)video->numVopsInGOP) % 30 == 1)
+ {
+
+ *collect = 1;
+
+ htfm_stat->countbreak = 0;
+ htfm_stat->abs_dif_mad_avg = 0;
+
+ for (i = 0; i < 16; i++)
+ {
+ newvar[i] = 0.0;
+ }
+// video->functionPointer->SAD_MB_PADDING = &SAD_MB_PADDING_HTFM_Collect;
+ video->functionPointer->SAD_Macroblock = &SAD_MB_HTFM_Collect;
+ video->functionPointer->SAD_MB_HalfPel[0] = NULL;
+ video->functionPointer->SAD_MB_HalfPel[1] = &SAD_MB_HP_HTFM_Collectxh;
+ video->functionPointer->SAD_MB_HalfPel[2] = &SAD_MB_HP_HTFM_Collectyh;
+ video->functionPointer->SAD_MB_HalfPel[3] = &SAD_MB_HP_HTFM_Collectxhyh;
+ video->sad_extra_info = (void*)(htfm_stat);
+ offset = htfm_stat->offsetArray;
+ offset2 = htfm_stat->offsetRef;
+ }
+ else
+ {
+// video->functionPointer->SAD_MB_PADDING = &SAD_MB_PADDING_HTFM;
+ video->functionPointer->SAD_Macroblock = &SAD_MB_HTFM;
+ video->functionPointer->SAD_MB_HalfPel[0] = NULL;
+ video->functionPointer->SAD_MB_HalfPel[1] = &SAD_MB_HP_HTFMxh;
+ video->functionPointer->SAD_MB_HalfPel[2] = &SAD_MB_HP_HTFMyh;
+ video->functionPointer->SAD_MB_HalfPel[3] = &SAD_MB_HP_HTFMxhyh;
+ video->sad_extra_info = (void*)(video->nrmlz_th);
+ offset = video->nrmlz_th + 16;
+ offset2 = video->nrmlz_th + 32;
+ }
+
+ offset[0] = 0;
+ offset[1] = lx2 + 2;
+ offset[2] = 2;
+ offset[3] = lx2;
+ offset[4] = lx + 1;
+ offset[5] = lx3 + 3;
+ offset[6] = lx + 3;
+ offset[7] = lx3 + 1;
+ offset[8] = lx;
+ offset[9] = lx3 + 2;
+ offset[10] = lx3 ;
+ offset[11] = lx + 2 ;
+ offset[12] = 1;
+ offset[13] = lx2 + 3;
+ offset[14] = lx2 + 1;
+ offset[15] = 3;
+
+ offset2[0] = 0;
+ offset2[1] = rx2 + 2;
+ offset2[2] = 2;
+ offset2[3] = rx2;
+ offset2[4] = rx + 1;
+ offset2[5] = rx3 + 3;
+ offset2[6] = rx + 3;
+ offset2[7] = rx3 + 1;
+ offset2[8] = rx;
+ offset2[9] = rx3 + 2;
+ offset2[10] = rx3 ;
+ offset2[11] = rx + 2 ;
+ offset2[12] = 1;
+ offset2[13] = rx2 + 3;
+ offset2[14] = rx2 + 1;
+ offset2[15] = 3;
+
+ return ;
+}
+
+void UpdateHTFM(VideoEncData *video, double *newvar, double *exp_lamda, HTFM_Stat *htfm_stat)
+{
+ if (htfm_stat->countbreak == 0)
+ htfm_stat->countbreak = 1;
+
+ newvar[0] = (double)(htfm_stat->abs_dif_mad_avg) / (htfm_stat->countbreak * 16.);
+
+ if (newvar[0] < 0.001)
+ {
+ newvar[0] = 0.001; /* to prevent floating overflow */
+ }
+ exp_lamda[0] = 1 / (newvar[0] * 1.4142136);
+ exp_lamda[1] = exp_lamda[0] * 1.5825;
+ exp_lamda[2] = exp_lamda[0] * 2.1750;
+ exp_lamda[3] = exp_lamda[0] * 3.5065;
+ exp_lamda[4] = exp_lamda[0] * 3.1436;
+ exp_lamda[5] = exp_lamda[0] * 3.5315;
+ exp_lamda[6] = exp_lamda[0] * 3.7449;
+ exp_lamda[7] = exp_lamda[0] * 4.5854;
+ exp_lamda[8] = exp_lamda[0] * 4.6191;
+ exp_lamda[9] = exp_lamda[0] * 5.4041;
+ exp_lamda[10] = exp_lamda[0] * 6.5974;
+ exp_lamda[11] = exp_lamda[0] * 10.5341;
+ exp_lamda[12] = exp_lamda[0] * 10.0719;
+ exp_lamda[13] = exp_lamda[0] * 12.0516;
+ exp_lamda[14] = exp_lamda[0] * 15.4552;
+
+ CalcThreshold(HTFM_Pf, exp_lamda, video->nrmlz_th);
+ return ;
+}
+
+
+void CalcThreshold(double pf, double exp_lamda[], Int nrmlz_th[])
+{
+ Int i;
+ double temp[15];
+ // printf("\nLamda: ");
+
+ /* parametric PREMODELling */
+ for (i = 0; i < 15; i++)
+ {
+ // printf("%g ",exp_lamda[i]);
+ if (pf < 0.5)
+ temp[i] = 1 / exp_lamda[i] * M4VENC_LOG(2 * pf);
+ else
+ temp[i] = -1 / exp_lamda[i] * M4VENC_LOG(2 * (1 - pf));
+ }
+
+ nrmlz_th[15] = 0;
+ for (i = 0; i < 15; i++) /* scale upto no.pixels */
+ nrmlz_th[i] = (Int)(temp[i] * ((i + 1) << 4) + 0.5);
+
+ return ;
+}
+
+void HTFMPrepareCurMB(VideoEncData *video, HTFM_Stat *htfm_stat, UChar *cur)
+{
+ void* tmp = (void*)(video->currYMB);
+ ULong *htfmMB = (ULong*)tmp;
+ UChar *ptr, byte;
+ Int *offset;
+ Int i;
+ ULong word;
+ Int width = video->currVop->width;
+
+ if (((Int)video->numVopsInGOP) % 30 == 1)
+ {
+ offset = htfm_stat->offsetArray;
+ }
+ else
+ {
+ offset = video->nrmlz_th + 16;
+ }
+
+ for (i = 0; i < 16; i++)
+ {
+ ptr = cur + offset[i];
+ word = ptr[0];
+ byte = ptr[4];
+ word |= (byte << 8);
+ byte = ptr[8];
+ word |= (byte << 16);
+ byte = ptr[12];
+ word |= (byte << 24);
+ *htfmMB++ = word;
+
+ word = *(ptr += (width << 2));
+ byte = ptr[4];
+ word |= (byte << 8);
+ byte = ptr[8];
+ word |= (byte << 16);
+ byte = ptr[12];
+ word |= (byte << 24);
+ *htfmMB++ = word;
+
+ word = *(ptr += (width << 2));
+ byte = ptr[4];
+ word |= (byte << 8);
+ byte = ptr[8];
+ word |= (byte << 16);
+ byte = ptr[12];
+ word |= (byte << 24);
+ *htfmMB++ = word;
+
+ word = *(ptr += (width << 2));
+ byte = ptr[4];
+ word |= (byte << 8);
+ byte = ptr[8];
+ word |= (byte << 16);
+ byte = ptr[12];
+ word |= (byte << 24);
+ *htfmMB++ = word;
+ }
+
+ return ;
+}
+
+
+#endif
+
+void PrepareCurMB(VideoEncData *video, UChar *cur)
+{
+ void* tmp = (void*)(video->currYMB);
+ ULong *currYMB = (ULong*)tmp;
+ Int i;
+ Int width = video->currVop->width;
+
+ cur -= width;
+
+ for (i = 0; i < 16; i++)
+ {
+ *currYMB++ = *((ULong*)(cur += width));
+ *currYMB++ = *((ULong*)(cur + 4));
+ *currYMB++ = *((ULong*)(cur + 8));
+ *currYMB++ = *((ULong*)(cur + 12));
+ }
+
+ return ;
+}
+
+
+/*==================================================================
+ Function: MBMotionSearch
+ Date: 09/06/2000
+ Purpose: Perform motion estimation for a macroblock.
+ Find 1MV and 4MVs in half-pels resolutions.
+ Using ST1 algorithm provided by Chalidabhongse and Kuo
+ CSVT March'98.
+
+==================================================================*/
+
+void MBMotionSearch(VideoEncData *video, UChar *cur, UChar *best_cand[],
+ Int i0, Int j0, Int type_pred, Int FS_en, Int *hp_guess)
+{
+ Vol *currVol = video->vol[video->currLayer];
+ UChar *ref, *cand, *ncand = NULL, *cur8;
+ void *extra_info = video->sad_extra_info;
+ Int mbnum = video->mbnum;
+ Int width = video->currVop->width; /* 6/12/01, must be multiple of 16 */
+ Int height = video->currVop->height;
+ MOT **mot = video->mot;
+ UChar use_4mv = video->encParams->MV8x8_Enabled;
+ UChar h263_mode = video->encParams->H263_Enabled;
+ Int(*SAD_Macroblock)(UChar*, UChar*, Int, void*) = video->functionPointer->SAD_Macroblock;
+ Int(*SAD_Block)(UChar*, UChar*, Int, Int, void*) = video->functionPointer->SAD_Block;
+ VideoEncParams *encParams = video->encParams;
+ Int range = encParams->SearchRange;
+
+ Int lx = video->currVop->pitch; /* padding */
+ Int comp;
+ Int i, j, imin, jmin, ilow, ihigh, jlow, jhigh, iorg, jorg;
+ Int d, dmin, dn[9];
+#if (ZERO_MV_PREF==1) /* compute (0,0) MV at the end */
+ Int d0;
+#endif
+ Int k;
+ Int mvx[5], mvy[5], imin0, jmin0;
+ Int num_can, center_again;
+ Int last_loc, new_loc = 0;
+ Int step, max_step = range >> 1;
+ Int next;
+
+ ref = video->forwardRefVop->yChan; /* origin of actual frame */
+
+ cur = video->currYMB; /* use smaller memory space for current MB */
+
+ /* find limit of the search (adjusting search range)*/
+
+ if (!h263_mode)
+ {
+ ilow = i0 - range;
+ if (ilow < -15)
+ ilow = -15;
+ ihigh = i0 + range - 1;
+ if (ihigh > width - 1)
+ ihigh = width - 1;
+ jlow = j0 - range;
+ if (jlow < -15)
+ jlow = -15;
+ jhigh = j0 + range - 1;
+ if (jhigh > height - 1)
+ jhigh = height - 1;
+ }
+ else
+ {
+ ilow = i0 - range;
+ if (ilow < 0)
+ ilow = 0;
+ ihigh = i0 + range - 1;
+ if (ihigh > width - 16)
+ ihigh = width - 16;
+ jlow = j0 - range;
+ if (jlow < 0)
+ jlow = 0;
+ jhigh = j0 + range - 1;
+ if (jhigh > height - 16)
+ jhigh = height - 16;
+ }
+
+ imin = i0;
+ jmin = j0; /* needed for fullsearch */
+ ncand = ref + imin + jmin * lx;
+
+ /* for first row of MB, fullsearch can be used */
+ if (FS_en)
+ {
+ *hp_guess = 0; /* no guess for fast half-pel */
+
+ dmin = fullsearch(video, currVol, ref, cur, &imin, &jmin, ilow, ihigh, jlow, jhigh);
+
+ ncand = ref + imin + jmin * lx;
+
+ mot[mbnum][0].sad = dmin;
+ mot[mbnum][0].x = (imin - i0) << 1;
+ mot[mbnum][0].y = (jmin - j0) << 1;
+ imin0 = imin << 1; /* 16x16 MV in half-pel resolution */
+ jmin0 = jmin << 1;
+ best_cand[0] = ncand;
+ }
+ else
+ { /* 4/7/01, modified this testing for fullsearch the top row to only upto (0,3) MB */
+ /* upto 30% complexity saving with the same complexity */
+ if (video->forwardRefVop->predictionType == I_VOP && j0 == 0 && i0 <= 64 && type_pred != 1)
+ {
+ *hp_guess = 0; /* no guess for fast half-pel */
+ dmin = fullsearch(video, currVol, ref, cur, &imin, &jmin, ilow, ihigh, jlow, jhigh);
+ ncand = ref + imin + jmin * lx;
+ }
+ else
+ {
+ /************** initialize candidate **************************/
+ /* find initial motion vector */
+ CandidateSelection(mvx, mvy, &num_can, i0 >> 4, j0 >> 4, video, type_pred);
+
+ dmin = 65535;
+
+ /* check if all are equal */
+ if (num_can == ALL_CAND_EQUAL)
+ {
+ i = i0 + mvx[0];
+ j = j0 + mvy[0];
+
+ if (i >= ilow && i <= ihigh && j >= jlow && j <= jhigh)
+ {
+ cand = ref + i + j * lx;
+
+ d = (*SAD_Macroblock)(cand, cur, (dmin << 16) | lx, extra_info);
+
+ if (d < dmin)
+ {
+ dmin = d;
+ imin = i;
+ jmin = j;
+ ncand = cand;
+ }
+ }
+ }
+ else
+ {
+ /************** evaluate unique candidates **********************/
+ for (k = 0; k < num_can; k++)
+ {
+ i = i0 + mvx[k];
+ j = j0 + mvy[k];
+
+ if (i >= ilow && i <= ihigh && j >= jlow && j <= jhigh)
+ {
+ cand = ref + i + j * lx;
+ d = (*SAD_Macroblock)(cand, cur, (dmin << 16) | lx, extra_info);
+
+ if (d < dmin)
+ {
+ dmin = d;
+ imin = i;
+ jmin = j;
+ ncand = cand;
+ }
+ else if ((d == dmin) && PV_ABS(mvx[k]) + PV_ABS(mvy[k]) < PV_ABS(i0 - imin) + PV_ABS(j0 - jmin))
+ {
+ dmin = d;
+ imin = i;
+ jmin = j;
+ ncand = cand;
+ }
+ }
+ }
+ }
+ if (num_can == 0 || dmin == 65535) /* no candidate selected */
+ {
+ ncand = ref + i0 + j0 * lx; /* use (0,0) MV as initial value */
+ mot[mbnum][7].sad = dmin = (*SAD_Macroblock)(ncand, cur, (65535 << 16) | lx, extra_info);
+#if (ZERO_MV_PREF==1) /* compute (0,0) MV at the end */
+ d0 = dmin;
+#endif
+ imin = i0;
+ jmin = j0;
+ }
+
+#if (ZERO_MV_PREF==0) /* COMPUTE ZERO VECTOR FIRST !!!!!*/
+ dmin -= PREF_NULL_VEC;
+#endif
+
+ /******************* local refinement ***************************/
+ center_again = 0;
+ last_loc = new_loc = 0;
+ // ncand = ref + jmin*lx + imin; /* center of the search */
+ step = 0;
+ dn[0] = dmin;
+ while (!center_again && step <= max_step)
+ {
+
+ MoveNeighborSAD(dn, last_loc);
+
+ center_again = 1;
+ i = imin;
+ j = jmin - 1;
+ cand = ref + i + j * lx;
+
+ /* starting from [0,-1] */
+ /* spiral check one step at a time*/
+ for (k = 2; k <= 8; k += 2)
+ {
+ if (!tab_exclude[last_loc][k]) /* exclude last step computation */
+ { /* not already computed */
+ if (i >= ilow && i <= ihigh && j >= jlow && j <= jhigh)
+ {
+ d = (*SAD_Macroblock)(cand, cur, (dmin << 16) | lx, extra_info);
+ dn[k] = d; /* keep it for half pel use */
+
+ if (d < dmin)
+ {
+ ncand = cand;
+ dmin = d;
+ imin = i;
+ jmin = j;
+ center_again = 0;
+ new_loc = k;
+ }
+ else if ((d == dmin) && PV_ABS(i0 - i) + PV_ABS(j0 - j) < PV_ABS(i0 - imin) + PV_ABS(j0 - jmin))
+ {
+ ncand = cand;
+ imin = i;
+ jmin = j;
+ center_again = 0;
+ new_loc = k;
+ }
+ }
+ }
+ if (k == 8) /* end side search*/
+ {
+ if (!center_again)
+ {
+ k = -1; /* start diagonal search */
+ cand -= lx;
+ j--;
+ }
+ }
+ else
+ {
+ next = refine_next[k][0];
+ i += next;
+ cand += next;
+ next = refine_next[k][1];
+ j += next;
+ cand += lx * next;
+ }
+ }
+ last_loc = new_loc;
+ step ++;
+ }
+ if (!center_again)
+ MoveNeighborSAD(dn, last_loc);
+
+ *hp_guess = FindMin(dn);
+
+ }
+
+#if (ZERO_MV_PREF==1) /* compute (0,0) MV at the end */
+ if (d0 - PREF_NULL_VEC < dmin)
+ {
+ ncand = ref + i0 + j0 * lx;
+ dmin = d0;
+ imin = i0;
+ jmin = j0;
+ }
+#endif
+ mot[mbnum][0].sad = dmin;
+ mot[mbnum][0].x = (imin - i0) << 1;
+ mot[mbnum][0].y = (jmin - j0) << 1;
+ imin0 = imin << 1; /* 16x16 MV in half-pel resolution */
+ jmin0 = jmin << 1;
+ best_cand[0] = ncand;
+ }
+ /* imin and jmin is the best 1 MV */
+#ifndef NO_INTER4V
+ /******************* Find 4 motion vectors ****************************/
+ if (use_4mv && !h263_mode)
+ {
+#ifdef _SAD_STAT
+ num_Blk += 4;
+#endif
+ /* starting from the best 1MV */
+ //offset = imin + jmin*lx;
+ iorg = i0;
+ jorg = j0;
+
+ for (comp = 0; comp < 4; comp++)
+ {
+ i0 = iorg + ((comp & 1) << 3);
+ j0 = jorg + ((comp & 2) << 2);
+
+ imin = (imin0 >> 1) + ((comp & 1) << 3); /* starting point from 16x16 MV */
+ jmin = (jmin0 >> 1) + ((comp & 2) << 2);
+ ncand = ref + imin + jmin * lx;
+
+ cur8 = cur + ((comp & 1) << 3) + (((comp & 2) << 2) << 4) ; /* 11/30/05, smaller cache */
+
+ /* find limit of the search (adjusting search range)*/
+ ilow = i0 - range;
+ ihigh = i0 + range - 1 ;/* 4/9/01 */
+ if (ilow < -15)
+ ilow = -15;
+ if (ihigh > width - 1)
+ ihigh = width - 1;
+ jlow = j0 - range;
+ jhigh = j0 + range - 1 ;/* 4/9/01 */
+ if (jlow < -15)
+ jlow = -15;
+ if (jhigh > height - 1)
+ jhigh = height - 1;
+
+ SAD_Block = video->functionPointer->SAD_Block;
+
+ if (FS_en) /* fullsearch enable, center around 16x16 MV */
+ {
+ dmin = fullsearchBlk(video, currVol, ncand, cur8, &imin, &jmin, ilow, ihigh, jlow, jhigh, range);
+ ncand = ref + imin + jmin * lx;
+
+ mot[mbnum][comp+1].sad = dmin;
+ mot[mbnum][comp+1].x = (imin - i0) << 1;
+ mot[mbnum][comp+1].y = (jmin - j0) << 1;
+ best_cand[comp+1] = ncand;
+ }
+ else /* no fullsearch, do local search */
+ {
+ /* starting point from 16x16 */
+ dmin = (*SAD_Block)(ncand, cur8, 65536, lx, extra_info);
+
+ /******************* local refinement ***************************/
+ center_again = 0;
+ last_loc = 0;
+
+ while (!center_again)
+ {
+ center_again = 1;
+ i = imin;
+ j = jmin - 1;
+ cand = ref + i + j * lx;
+
+ /* starting from [0,-1] */
+ /* spiral check one step at a time*/
+ for (k = 2; k <= 8; k += 2)
+ {
+ if (!tab_exclude[last_loc][k]) /* exclude last step computation */
+ { /* not already computed */
+ if (i >= ilow && i <= ihigh && j >= jlow && j <= jhigh)
+ {
+ d = (*SAD_Block)(cand, cur8, dmin, lx, extra_info);
+
+ if (d < dmin)
+ {
+ ncand = cand;
+ dmin = d;
+ imin = i;
+ jmin = j;
+ center_again = 0;
+ new_loc = k;
+ }
+ else if ((d == dmin) &&
+ PV_ABS(i0 - i) + PV_ABS(j0 - j) < PV_ABS(i0 - imin) + PV_ABS(j0 - jmin))
+ {
+ ncand = cand;
+ imin = i;
+ jmin = j;
+ center_again = 0;
+ new_loc = k;
+ }
+ }
+ }
+ if (k == 8) /* end side search*/
+ {
+ if (!center_again)
+ {
+ k = -1; /* start diagonal search */
+ if (j <= height - 1 && j > 0) cand -= lx;
+ j--;
+ }
+ }
+ else
+ {
+ next = refine_next[k][0];
+ cand += next;
+ i += next;
+ next = refine_next[k][1];
+ cand += lx * next;
+ j += next;
+ }
+ }
+ last_loc = new_loc;
+ }
+ mot[mbnum][comp+1].sad = dmin;
+ mot[mbnum][comp+1].x = (imin - i0) << 1;
+ mot[mbnum][comp+1].y = (jmin - j0) << 1;
+ best_cand[comp+1] = ncand;
+ }
+ /********************************************/
+ }
+ }
+ else
+#endif /* NO_INTER4V */
+ {
+ mot[mbnum][1].sad = mot[mbnum][2].sad = mot[mbnum][3].sad = mot[mbnum][4].sad = (dmin + 2) >> 2;
+ mot[mbnum][1].x = mot[mbnum][2].x = mot[mbnum][3].x = mot[mbnum][4].x = mot[mbnum][0].x;
+ mot[mbnum][1].y = mot[mbnum][2].y = mot[mbnum][3].y = mot[mbnum][4].y = mot[mbnum][0].y;
+ best_cand[1] = best_cand[2] = best_cand[3] = best_cand[4] = ncand;
+
+ }
+ return ;
+}
+
+
+/*===============================================================================
+ Function: fullsearch
+ Date: 09/16/2000
+ Purpose: Perform full-search motion estimation over the range of search
+ region in a spiral-outward manner.
+ Input/Output: VideoEncData, current Vol, previou Vop, pointer to the left corner of
+ current VOP, current coord (also output), boundaries.
+===============================================================================*/
+
+Int fullsearch(VideoEncData *video, Vol *currVol, UChar *prev, UChar *cur,
+ Int *imin, Int *jmin, Int ilow, Int ihigh, Int jlow, Int jhigh)
+{
+ Int range = video->encParams->SearchRange;
+ UChar *cand;
+ Int i, j, k, l;
+ Int d, dmin;
+ Int i0 = *imin; /* current position */
+ Int j0 = *jmin;
+ Int(*SAD_Macroblock)(UChar*, UChar*, Int, void*) = video->functionPointer->SAD_Macroblock;
+ void *extra_info = video->sad_extra_info;
+// UChar h263_mode = video->encParams->H263_Enabled;
+ Int lx = video->currVop->pitch; /* with padding */
+
+ Int offset = i0 + j0 * lx;
+
+ OSCL_UNUSED_ARG(currVol);
+
+ cand = prev + offset;
+
+ dmin = (*SAD_Macroblock)(cand, cur, (65535 << 16) | lx, (void*)extra_info) - PREF_NULL_VEC;
+
+ /* perform spiral search */
+ for (k = 1; k <= range; k++)
+ {
+
+ i = i0 - k;
+ j = j0 - k;
+
+ cand = prev + i + j * lx;
+
+ for (l = 0; l < 8*k; l++)
+ {
+ /* no need for boundary checking again */
+ if (i >= ilow && i <= ihigh && j >= jlow && j <= jhigh)
+ {
+ d = (*SAD_Macroblock)(cand, cur, (dmin << 16) | lx, (void*)extra_info);
+
+ if (d < dmin)
+ {
+ dmin = d;
+ *imin = i;
+ *jmin = j;
+ }
+ else if ((d == dmin) && PV_ABS(i0 - i) + PV_ABS(j0 - j) < PV_ABS(i0 - *imin) + PV_ABS(j0 - *jmin))
+ {
+ dmin = d;
+ *imin = i;
+ *jmin = j;
+ }
+ }
+
+ if (l < (k << 1))
+ {
+ i++;
+ cand++;
+ }
+ else if (l < (k << 2))
+ {
+ j++;
+ cand += lx;
+ }
+ else if (l < ((k << 2) + (k << 1)))
+ {
+ i--;
+ cand--;
+ }
+ else
+ {
+ j--;
+ cand -= lx;
+ }
+ }
+ }
+
+ return dmin;
+}
+
+#ifndef NO_INTER4V
+/*===============================================================================
+ Function: fullsearchBlk
+ Date: 01/9/2001
+ Purpose: Perform full-search motion estimation of an 8x8 block over the range
+ of search region in a spiral-outward manner centered at the 16x16 MV.
+ Input/Output: VideoEncData, MB coordinate, pointer to the initial MV on the
+ reference, pointer to coor of current block, search range.
+===============================================================================*/
+Int fullsearchBlk(VideoEncData *video, Vol *currVol, UChar *cent, UChar *cur,
+ Int *imin, Int *jmin, Int ilow, Int ihigh, Int jlow, Int jhigh, Int range)
+{
+ UChar *cand, *ref;
+ Int i, j, k, l, istart, jstart;
+ Int d, dmin;
+ Int lx = video->currVop->pitch; /* with padding */
+ Int(*SAD_Block)(UChar*, UChar*, Int, Int, void*) = video->functionPointer->SAD_Block;
+ void *extra_info = video->sad_extra_info;
+
+ OSCL_UNUSED_ARG(currVol);
+
+ /* starting point centered at 16x16 MV */
+ ref = cent;
+ istart = *imin;
+ jstart = *jmin;
+
+ dmin = (*SAD_Block)(ref, cur, 65536, lx, (void*)extra_info);
+
+ cand = ref;
+ /* perform spiral search */
+ for (k = 1; k <= range; k++)
+ {
+
+ i = istart - k;
+ j = jstart - k;
+ cand -= (lx + 1); /* candidate region */
+
+ for (l = 0; l < 8*k; l++)
+ {
+ /* no need for boundary checking again */
+ if (i >= ilow && i <= ihigh && j >= jlow && j <= jhigh)
+ {
+ d = (*SAD_Block)(cand, cur, dmin, lx, (void*)extra_info);
+
+ if (d < dmin)
+ {
+ dmin = d;
+ *imin = i;
+ *jmin = j;
+ }
+ else if ((d == dmin) &&
+ PV_ABS(istart - i) + PV_ABS(jstart - j) < PV_ABS(istart - *imin) + PV_ABS(jstart - *jmin))
+ {
+ dmin = d;
+ *imin = i;
+ *jmin = j;
+ }
+ }
+
+ if (l < (k << 1))
+ {
+ i++;
+ cand++;
+ }
+ else if (l < (k << 2))
+ {
+ j++;
+ cand += lx;
+ }
+ else if (l < ((k << 2) + (k << 1)))
+ {
+ i--;
+ cand--;
+ }
+ else
+ {
+ j--;
+ cand -= lx;
+ }
+ }
+ }
+
+ return dmin;
+}
+#endif /* NO_INTER4V */
+
+/*===============================================================================
+ Function: CandidateSelection
+ Date: 09/16/2000
+ Purpose: Fill up the list of candidate using spatio-temporal correlation
+ among neighboring blocks.
+ Input/Output: type_pred = 0: first pass, 1: second pass, or no SCD
+ Modified: 09/23/01, get rid of redundant candidates before passing back.
+===============================================================================*/
+
+void CandidateSelection(Int *mvx, Int *mvy, Int *num_can, Int imb, Int jmb,
+ VideoEncData *video, Int type_pred)
+{
+ MOT **mot = video->mot;
+ MOT *pmot;
+ Int mbnum = video->mbnum;
+ Vol *currVol = video->vol[video->currLayer];
+ Int mbwidth = currVol->nMBPerRow;
+ Int mbheight = currVol->nMBPerCol;
+ Int i, j, same, num1;
+
+ *num_can = 0;
+
+ if (video->forwardRefVop->predictionType == P_VOP)
+ {
+ /* Spatio-Temporal Candidate (five candidates) */
+ if (type_pred == 0) /* first pass */
+ {
+ pmot = &mot[mbnum][0]; /* same coordinate previous frame */
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ if (imb >= (mbwidth >> 1) && imb > 0) /*left neighbor previous frame */
+ {
+ pmot = &mot[mbnum-1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ else if (imb + 1 < mbwidth) /*right neighbor previous frame */
+ {
+ pmot = &mot[mbnum+1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+
+ if (jmb < mbheight - 1) /*bottom neighbor previous frame */
+ {
+ pmot = &mot[mbnum+mbwidth][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ else if (jmb > 0) /*upper neighbor previous frame */
+ {
+ pmot = &mot[mbnum-mbwidth][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+
+ if (imb > 0 && jmb > 0) /* upper-left neighbor current frame*/
+ {
+ pmot = &mot[mbnum-mbwidth-1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (jmb > 0 && imb < mbheight - 1) /* upper right neighbor current frame*/
+ {
+ pmot = &mot[mbnum-mbwidth+1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ }
+ else /* second pass */
+ /* original ST1 algorithm */
+ {
+ pmot = &mot[mbnum][0]; /* same coordinate previous frame */
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+
+ if (imb > 0) /*left neighbor current frame */
+ {
+ pmot = &mot[mbnum-1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (jmb > 0) /*upper neighbor current frame */
+ {
+ pmot = &mot[mbnum-mbwidth][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (imb < mbwidth - 1) /*right neighbor previous frame */
+ {
+ pmot = &mot[mbnum+1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (jmb < mbheight - 1) /*bottom neighbor previous frame */
+ {
+ pmot = &mot[mbnum+mbwidth][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ }
+ }
+ else /* only Spatial Candidate (four candidates)*/
+ {
+ if (type_pred == 0) /*first pass*/
+ {
+ if (imb > 1) /* neighbor two blocks away to the left */
+ {
+ pmot = &mot[mbnum-2][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (imb > 0 && jmb > 0) /* upper-left neighbor */
+ {
+ pmot = &mot[mbnum-mbwidth-1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (jmb > 0 && imb < mbheight - 1) /* upper right neighbor */
+ {
+ pmot = &mot[mbnum-mbwidth+1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ }
+//#ifdef SCENE_CHANGE_DETECTION
+ /* second pass (ST2 algorithm)*/
+ else if (type_pred == 1) /* 4/7/01 */
+ {
+ if (imb > 0) /*left neighbor current frame */
+ {
+ pmot = &mot[mbnum-1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (jmb > 0) /*upper neighbor current frame */
+ {
+ pmot = &mot[mbnum-mbwidth][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (imb < mbwidth - 1) /*right neighbor current frame */
+ {
+ pmot = &mot[mbnum+1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ if (jmb < mbheight - 1) /*bottom neighbor current frame */
+ {
+ pmot = &mot[mbnum+mbwidth][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ }
+//#else
+ else /* original ST1 algorithm */
+ {
+ if (imb > 0) /*left neighbor current frame */
+ {
+ pmot = &mot[mbnum-1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+
+ if (jmb > 0) /*upper-left neighbor current frame */
+ {
+ pmot = &mot[mbnum-mbwidth-1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+
+ }
+ if (jmb > 0) /*upper neighbor current frame */
+ {
+ pmot = &mot[mbnum-mbwidth][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+
+ if (imb < mbheight - 1) /*upper-right neighbor current frame */
+ {
+ pmot = &mot[mbnum-mbwidth+1][0];
+ mvx[(*num_can)] = (pmot->x) >> 1;
+ mvy[(*num_can)++] = (pmot->y) >> 1;
+ }
+ }
+ }
+//#endif
+ }
+
+ /* 3/23/01, remove redundant candidate (possible k-mean) */
+ num1 = *num_can;
+ *num_can = 1;
+ for (i = 1; i < num1; i++)
+ {
+ same = 0;
+ j = 0;
+ while (!same && j < *num_can)
+ {
+#if (CANDIDATE_DISTANCE==0)
+ if (mvx[i] == mvx[j] && mvy[i] == mvy[j])
+#else
+ // modified k-mean, 3/24/01, shouldn't be greater than 3
+ if (PV_ABS(mvx[i] - mvx[j]) + PV_ABS(mvy[i] - mvy[j]) < CANDIDATE_DISTANCE)
+#endif
+ same = 1;
+ j++;
+ }
+ if (!same)
+ {
+ mvx[*num_can] = mvx[i];
+ mvy[*num_can] = mvy[i];
+ (*num_can)++;
+ }
+ }
+
+#ifdef _SAD_STAT
+ num_cand += (*num_can);
+#endif
+
+ if (num1 == 5 && *num_can == 1)
+ *num_can = ALL_CAND_EQUAL; /* all are equal */
+
+ return ;
+}
+
+/*===========================================================================
+ Function: RasterIntraUpdate
+ Date: 2/26/01
+ Purpose: To raster-scan assign INTRA-update .
+ N macroblocks are updated (also was programmable).
+===========================================================================*/
+void RasterIntraUpdate(UChar *intraArray, UChar *Mode, Int totalMB, Int numRefresh)
+{
+ Int indx, i;
+
+ /* find the last refresh MB */
+ indx = 0;
+ while (intraArray[indx] == 1 && indx < totalMB)
+ indx++;
+
+ /* add more */
+ for (i = 0; i < numRefresh && indx < totalMB; i++)
+ {
+ Mode[indx] = MODE_INTRA;
+ intraArray[indx++] = 1;
+ }
+
+ /* if read the end of frame, reset and loop around */
+ if (indx >= totalMB - 1)
+ {
+ ResetIntraUpdate(intraArray, totalMB);
+ indx = 0;
+ while (i < numRefresh && indx < totalMB)
+ {
+ intraArray[indx] = 1;
+ Mode[indx++] = MODE_INTRA;
+ i++;
+ }
+ }
+
+ return ;
+}
+
+/*===========================================================================
+ Function: ResetIntraUpdate
+ Date: 11/28/00
+ Purpose: Reset already intra updated flags to all zero
+===========================================================================*/
+
+void ResetIntraUpdate(UChar *intraArray, Int totalMB)
+{
+ M4VENC_MEMSET(intraArray, 0, sizeof(UChar)*totalMB);
+ return ;
+}
+
+/*===========================================================================
+ Function: ResetIntraUpdateRegion
+ Date: 12/1/00
+ Purpose: Reset already intra updated flags in one region to all zero
+===========================================================================*/
+void ResetIntraUpdateRegion(UChar *intraArray, Int start_i, Int rwidth,
+ Int start_j, Int rheight, Int mbwidth, Int mbheight)
+{
+ Int indx, j;
+
+ if (start_i + rwidth >= mbwidth)
+ rwidth = mbwidth - start_i;
+ if (start_j + rheight >= mbheight)
+ rheight = mbheight - start_j;
+
+ for (j = start_j; j < start_j + rheight; j++)
+ {
+ indx = j * mbwidth;
+ M4VENC_MEMSET(intraArray + indx + start_i, 0, sizeof(UChar)*rwidth);
+ }
+
+ return ;
+}
+
+/*************************************************************
+ Function: MoveNeighborSAD
+ Date: 3/27/01
+ Purpose: Move neighboring SAD around when center has shifted
+*************************************************************/
+
+void MoveNeighborSAD(Int dn[], Int new_loc)
+{
+ Int tmp[9];
+ tmp[0] = dn[0];
+ tmp[1] = dn[1];
+ tmp[2] = dn[2];
+ tmp[3] = dn[3];
+ tmp[4] = dn[4];
+ tmp[5] = dn[5];
+ tmp[6] = dn[6];
+ tmp[7] = dn[7];
+ tmp[8] = dn[8];
+ dn[0] = dn[1] = dn[2] = dn[3] = dn[4] = dn[5] = dn[6] = dn[7] = dn[8] = 65536;
+
+ switch (new_loc)
+ {
+ case 0:
+ break;
+ case 1:
+ dn[4] = tmp[2];
+ dn[5] = tmp[0];
+ dn[6] = tmp[8];
+ break;
+ case 2:
+ dn[4] = tmp[3];
+ dn[5] = tmp[4];
+ dn[6] = tmp[0];
+ dn[7] = tmp[8];
+ dn[8] = tmp[1];
+ break;
+ case 3:
+ dn[6] = tmp[4];
+ dn[7] = tmp[0];
+ dn[8] = tmp[2];
+ break;
+ case 4:
+ dn[1] = tmp[2];
+ dn[2] = tmp[3];
+ dn[6] = tmp[5];
+ dn[7] = tmp[6];
+ dn[8] = tmp[0];
+ break;
+ case 5:
+ dn[1] = tmp[0];
+ dn[2] = tmp[4];
+ dn[8] = tmp[6];
+ break;
+ case 6:
+ dn[1] = tmp[8];
+ dn[2] = tmp[0];
+ dn[3] = tmp[4];
+ dn[4] = tmp[5];
+ dn[8] = tmp[7];
+ break;
+ case 7:
+ dn[2] = tmp[8];
+ dn[3] = tmp[0];
+ dn[4] = tmp[6];
+ break;
+ case 8:
+ dn[2] = tmp[1];
+ dn[3] = tmp[2];
+ dn[4] = tmp[0];
+ dn[5] = tmp[6];
+ dn[6] = tmp[7];
+ break;
+ }
+ dn[0] = tmp[new_loc];
+
+ return ;
+}
+
+/* 3/28/01, find minimal of dn[9] */
+
+Int FindMin(Int dn[])
+{
+ Int min, i;
+ Int dmin;
+
+ dmin = dn[1];
+ min = 1;
+ for (i = 2; i < 9; i++)
+ {
+ if (dn[i] < dmin)
+ {
+ dmin = dn[i];
+ min = i;
+ }
+ }
+
+ return min;
+}
+
+
+
diff --git a/media/codecs/m4v_h263/enc/src/mp4def.h b/media/codecs/m4v_h263/enc/src/mp4def.h
new file mode 100644
index 0000000..dbd70dc
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/mp4def.h
@@ -0,0 +1,229 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _PVDECDEF_H_
+#define _PVDECDEF_H_
+
+#include <stdint.h> // for uint8_t, etc
+#include <stdlib.h>
+#include <string.h>
+
+// Redefine the int types
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef int16_t int16;
+typedef uint32_t uint32;
+typedef int32_t int32;
+typedef unsigned int uint;
+
+/********** platform dependent in-line assembly *****************************/
+
+/*************** Intel *****************/
+
+/*************** ARM *****************/
+/* for general ARM instruction. #define __ARM has to be defined in compiler set up.*/
+/* for DSP MUL */
+#ifdef __TARGET_FEATURE_DSPMUL
+#define _ARM_DSP_MUL
+#endif
+
+/* for Count Leading Zero instruction */
+#ifdef __TARGET_ARCH_5T
+#define _ARM_CLZ
+#endif
+#ifdef __TARGET_ARCH_5TE
+#define _ARM_CLZ
+#endif
+/****************************************************************************/
+
+#ifndef _PV_TYPES_
+#define _PV_TYPES_
+typedef uint8_t UChar;
+typedef int8_t Char;
+typedef unsigned int UInt;
+typedef int Int;
+typedef uint16_t UShort;
+typedef int16_t Short;
+typedef int16_t SInt;
+typedef unsigned int Bool;
+typedef uint32_t ULong;
+typedef void Void;
+
+#define PV_CODEC_INIT 0
+#define PV_CODEC_STOP 1
+#define PV_CODEC_RUNNING 2
+#define PV_CODEC_RESET 3
+#endif
+
+typedef enum
+{
+ PV_SUCCESS,
+ PV_FAIL,
+ PV_EOS, /* hit End_Of_Sequence */
+ PV_MB_STUFFING, /* hit Macroblock_Stuffing */
+ PV_END_OF_VOP, /* hit End_of_Video_Object_Plane */
+ PV_END_OF_MB, /* hit End_of_Macroblock */
+ PV_END_OF_BUF /* hit End_of_Bitstream_Buffer */
+} PV_STATUS;
+
+typedef UChar PIXEL;
+//typedef Int MOT; /* : "int" type runs faster on RISC machine */
+
+#define HTFM /* 3/2/01, Hypothesis Test Fast Matching for early drop-out*/
+//#define _MOVE_INTERFACE
+
+//#define RANDOM_REFSELCODE
+
+/* handle the case of devision by zero in RC */
+#define MAD_MIN 1
+
+/* 4/11/01, if SSE or MMX, no HTFM, no SAD_HP_FLY */
+
+/* Code size reduction related Macros */
+#ifdef H263_ONLY
+#ifndef NO_RVLC
+#define NO_RVLC
+#endif
+#ifndef NO_MPEG_QUANT
+#define NO_MPEG_QUANT
+#endif
+#ifndef NO_INTER4V
+#define NO_INTER4V
+#endif
+#endif
+/**************************************/
+
+#define TRUE 1
+#define FALSE 0
+
+#define PV_ABS(x) (((x)<0)? -(x) : (x))
+#define PV_SIGN(x) (((x)<0)? -1 : 1)
+#define PV_SIGN0(a) (((a)<0)? -1 : (((a)>0) ? 1 : 0))
+#define PV_MAX(a,b) ((a)>(b)? (a):(b))
+#define PV_MIN(a,b) ((a)<(b)? (a):(b))
+
+#define MODE_INTRA 0
+#define MODE_INTER 1
+#define MODE_INTRA_Q 2
+#define MODE_INTER_Q 3
+#define MODE_INTER4V 4
+#define MODE_SKIPPED 6
+
+#define I_VOP 0
+#define P_VOP 1
+#define B_VOP 2
+
+/*09/04/00 Add MB height and width */
+#define MB_WIDTH 16
+#define MB_HEIGHT 16
+
+#define VOP_BRIGHT_WHITEENC 255
+
+
+#define LUMINANCE_DC_TYPE 1
+#define CHROMINANCE_DC_TYPE 2
+
+#define EOB_CODE 1
+#define EOB_CODE_LENGTH 32
+
+/* 11/30/98 */
+#define FoundRM 1 /* Resync Marker */
+#define FoundVSC 2 /* VOP_START_CODE. */
+#define FoundGSC 3 /* GROUP_START_CODE */
+#define FoundEOB 4 /* EOB_CODE */
+
+
+/* 05/08/2000, the error code returned from BitstreamShowBits() */
+#define BITSTREAM_ERROR_CODE 0xFFFFFFFF
+
+/* PacketVideo "absolution timestamp" object. 06/13/2000 */
+#define PVTS_START_CODE 0x01C4
+#define PVTS_START_CODE_LENGTH 32
+
+/* session layer and vop layer start codes */
+
+#define SESSION_START_CODE 0x01B0
+#define SESSION_END_CODE 0x01B1
+#define VISUAL_OBJECT_START_CODE 0x01B5
+
+#define VO_START_CODE 0x8
+#define VO_HEADER_LENGTH 32 /* lengtho of VO header: VO_START_CODE + VO_ID */
+
+#define SOL_START_CODE 0x01BE
+#define SOL_START_CODE_LENGTH 32
+
+#define VOL_START_CODE 0x12
+#define VOL_START_CODE_LENGTH 28
+
+#define VOP_START_CODE 0x1B6
+#define VOP_START_CODE_LENGTH 32
+
+#define GROUP_START_CODE 0x01B3
+#define GROUP_START_CODE_LENGTH 32
+
+#define VOP_ID_CODE_LENGTH 5
+#define VOP_TEMP_REF_CODE_LENGTH 16
+
+#define USER_DATA_START_CODE 0x01B2
+#define USER_DATA_START_CODE_LENGTH 32
+
+#define START_CODE_PREFIX 0x01
+#define START_CODE_PREFIX_LENGTH 24
+
+#define SHORT_VIDEO_START_MARKER 0x20
+#define SHORT_VIDEO_START_MARKER_LENGTH 22
+#define SHORT_VIDEO_END_MARKER 0x3F
+#define GOB_RESYNC_MARKER 0x01
+#define GOB_RESYNC_MARKER_LENGTH 17
+
+/* motion and resync markers used in error resilient mode */
+
+#define DC_MARKER 438273
+#define DC_MARKER_LENGTH 19
+
+#define MOTION_MARKER_COMB 126977
+#define MOTION_MARKER_COMB_LENGTH 17
+
+#define MOTION_MARKER_SEP 81921
+#define MOTION_MARKER_SEP_LENGTH 17
+
+#define RESYNC_MARKER 1
+#define RESYNC_MARKER_LENGTH 17
+
+#define SPRITE_NOT_USED 0
+#define STATIC_SPRITE 1
+#define ONLINE_SPRITE 2
+#define GMC_SPRITE 3
+
+/* macroblock and block size */
+#define MB_SIZE 16
+#define NCOEFF_MB (MB_SIZE*MB_SIZE)
+#define B_SIZE 8
+#define NCOEFF_BLOCK (B_SIZE*B_SIZE)
+#define NCOEFF_Y NCOEFF_MB
+#define NCOEFF_U NCOEFF_BLOCK
+#define NCOEFF_V NCOEFF_BLOCK
+
+/* overrun buffer size */
+#define DEFAULT_OVERRUN_BUFFER_SIZE 1000
+
+
+/* VLC decoding related definitions */
+#define VLC_ERROR (-1)
+#define VLC_ESCAPE 7167
+
+#endif /* _PVDECDEF_H_ */
diff --git a/media/codecs/m4v_h263/enc/src/mp4enc_api.cpp b/media/codecs/m4v_h263/enc/src/mp4enc_api.cpp
new file mode 100644
index 0000000..7ab8f45
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/mp4enc_api.cpp
@@ -0,0 +1,3307 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#include "mp4enc_lib.h"
+#include "bitstream_io.h"
+#include "rate_control.h"
+#include "m4venc_oscl.h"
+
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffff
+#endif
+
+#ifndef SIZE_MAX
+#define SIZE_MAX ((size_t) -1)
+#endif
+
+/* Inverse normal zigzag */
+const static Int zigzag_i[NCOEFF_BLOCK] =
+{
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
+};
+
+/* INTRA */
+const static Int mpeg_iqmat_def[NCOEFF_BLOCK] =
+ { 8, 17, 18, 19, 21, 23, 25, 27,
+ 17, 18, 19, 21, 23, 25, 27, 28,
+ 20, 21, 22, 23, 24, 26, 28, 30,
+ 21, 22, 23, 24, 26, 28, 30, 32,
+ 22, 23, 24, 26, 28, 30, 32, 35,
+ 23, 24, 26, 28, 30, 32, 35, 38,
+ 25, 26, 28, 30, 32, 35, 38, 41,
+ 27, 28, 30, 32, 35, 38, 41, 45
+ };
+
+/* INTER */
+const static Int mpeg_nqmat_def[64] =
+ { 16, 17, 18, 19, 20, 21, 22, 23,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 18, 19, 20, 21, 22, 23, 24, 25,
+ 19, 20, 21, 22, 23, 24, 26, 27,
+ 20, 21, 22, 23, 25, 26, 27, 28,
+ 21, 22, 23, 24, 26, 27, 28, 30,
+ 22, 23, 24, 26, 27, 28, 30, 31,
+ 23, 24, 25, 27, 28, 30, 31, 33
+ };
+
+/* Profiles and levels */
+/* Simple profile(level 0-3) and Core profile (level 1-2) */
+/* {SPL0, SPL1, SPL2, SPL3, CPL1, CPL2, CPL2, CPL2} , SPL0: Simple Profile@Level0, CPL1: Core Profile@Level1, the last two are redundant for easy table manipulation */
+const static Int profile_level_code[8] =
+{
+ 0x08, 0x01, 0x02, 0x03, 0x21, 0x22, 0x22, 0x22
+};
+
+const static Int profile_level_max_bitrate[8] =
+{
+ 64000, 64000, 128000, 384000, 384000, 2000000, 2000000, 2000000
+};
+
+const static Int profile_level_max_packet_size[8] =
+{
+ 2048, 2048, 4096, 8192, 4096, 8192, 8192, 8192
+};
+
+const static Int profile_level_max_mbsPerSec[8] =
+{
+ 1485, 1485, 5940, 11880, 5940, 23760, 23760, 23760
+};
+
+const static Int profile_level_max_VBV_size[8] =
+{
+ 163840, 163840, 655360, 655360, 262144, 1310720, 1310720, 1310720
+};
+
+
+/* Simple scalable profile (level 0-2) and Core scalable profile (level 1-3) */
+/* {SSPL0, SSPL1, SSPL2, SSPL2, CSPL1, CSPL2, CSPL3, CSPL3} , SSPL0: Simple Scalable Profile@Level0, CSPL1: Core Scalable Profile@Level1, the fourth is redundant for easy table manipulation */
+
+const static Int scalable_profile_level_code[8] =
+{
+ 0x10, 0x11, 0x12, 0x12, 0xA1, 0xA2, 0xA3, 0xA3
+};
+
+const static Int scalable_profile_level_max_bitrate[8] =
+{
+ 128000, 128000, 256000, 256000, 768000, 1500000, 4000000, 4000000
+};
+
+/* in bits */
+const static Int scalable_profile_level_max_packet_size[8] =
+{
+ 2048, 2048, 4096, 4096, 4096, 4096, 16384, 16384
+};
+
+const static Int scalable_profile_level_max_mbsPerSec[8] =
+{
+ 1485, 7425, 23760, 23760, 14850, 29700, 120960, 120960
+};
+
+const static Int scalable_profile_level_max_VBV_size[8] =
+{
+ 163840, 655360, 655360, 655360, 1048576, 1310720, 1310720, 1310720
+};
+
+
+/* H263 profile 0 @ level 10-70 */
+const static Int h263Level[8] = {0, 10, 20, 30, 40, 50, 60, 70};
+const static float rBR_bound[8] = {0, 1, 2, 6, 32, 64, 128, 256};
+const static float max_h263_framerate[2] = {(float)30000 / (float)2002,
+ (float)30000 / (float)1001
+ };
+const static Int max_h263_width[2] = {176, 352};
+const static Int max_h263_height[2] = {144, 288};
+
+/* 6/2/2001, newly added functions to make PVEncodeVop more readable. */
+Int DetermineCodingLayer(VideoEncData *video, Int *nLayer, ULong modTime);
+void DetermineVopType(VideoEncData *video, Int currLayer);
+Int UpdateSkipNextFrame(VideoEncData *video, ULong *modTime, Int *size, PV_STATUS status);
+Bool SetProfile_BufferSize(VideoEncData *video, float delay, Int bInitialized);
+
+#ifdef PRINT_RC_INFO
+extern FILE *facct;
+extern int tiTotalNumBitsGenerated;
+extern int iStuffBits;
+#endif
+
+#ifdef PRINT_EC
+extern FILE *fec;
+#endif
+
+
+/* ======================================================================== */
+/* Function : PVGetDefaultEncOption() */
+/* Date : 12/12/2005 */
+/* Purpose : */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVGetDefaultEncOption(VideoEncOptions *encOption, Int encUseCase)
+{
+ VideoEncOptions defaultUseCase = {H263_MODE, profile_level_max_packet_size[SIMPLE_PROFILE_LEVEL0] >> 3,
+ SIMPLE_PROFILE_LEVEL0, PV_OFF, 0, 1, 1000, 33, {144, 144}, {176, 176}, {15, 30}, {64000, 128000},
+ {10, 10}, {12, 12}, {0, 0}, CBR_1, 0.0, PV_OFF, -1, 0, PV_OFF, 16, PV_OFF, 0, PV_ON
+ };
+
+ OSCL_UNUSED_ARG(encUseCase); // unused for now. Later we can add more defaults setting and use this
+ // argument to select the right one.
+ /* in the future we can create more meaningful use-cases */
+ if (encOption == NULL)
+ {
+ return PV_FALSE;
+ }
+
+ M4VENC_MEMCPY(encOption, &defaultUseCase, sizeof(VideoEncOptions));
+
+ return PV_TRUE;
+}
+
+/* ======================================================================== */
+/* Function : PVInitVideoEncoder() */
+/* Date : 08/22/2000 */
+/* Purpose : Initialization of MP4 Encoder and VO bitstream */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : 5/21/01, allocate only yChan and assign uChan & vChan */
+/* 12/12/05, add encoding option as input argument */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encoderControl, VideoEncOptions *encOption)
+{
+
+ Bool status = PV_TRUE;
+ Int nLayers, idx, i, j;
+ Int max = 0, max_width = 0, max_height = 0, pitch, offset;
+ Int size = 0, nTotalMB = 0;
+ VideoEncData *video;
+ Vol *pVol;
+ VideoEncParams *pEncParams;
+ Int temp_w, temp_h, mbsPerSec;
+
+ /******************************************/
+ /* this part use to be PVSetEncode() */
+ Int profile_table_index, *profile_level_table;
+ Int profile_level = encOption->profile_level;
+ Int PacketSize = encOption->packetSize << 3;
+ Int timeInc, timeIncRes;
+ float profile_max_framerate;
+ VideoEncParams *encParams;
+
+ if (encoderControl->videoEncoderData) /* this has been called */
+ {
+ if (encoderControl->videoEncoderInit) /* check if PVInitVideoEncoder() has been called */
+ {
+ PVCleanUpVideoEncoder(encoderControl);
+ encoderControl->videoEncoderInit = 0;
+ }
+
+ M4VENC_FREE(encoderControl->videoEncoderData);
+ encoderControl->videoEncoderData = NULL;
+ }
+ encoderControl->videoEncoderInit = 0; /* reset this value */
+
+ video = (VideoEncData *)M4VENC_MALLOC(sizeof(VideoEncData)); /* allocate memory for encData */
+
+ if (video == NULL)
+ return PV_FALSE;
+
+ M4VENC_MEMSET(video, 0, sizeof(VideoEncData));
+
+ encoderControl->videoEncoderData = (void *) video; /* set up pointer in VideoEncData structure */
+
+ video->encParams = (VideoEncParams *)M4VENC_MALLOC(sizeof(VideoEncParams));
+ if (video->encParams == NULL)
+ goto CLEAN_UP;
+
+ M4VENC_MEMSET(video->encParams, 0, sizeof(VideoEncParams));
+
+ encParams = video->encParams;
+ encParams->nLayers = encOption->numLayers;
+
+ /* Check whether the input packetsize is valid (Note: put code here (before any memory allocation) in order to avoid memory leak */
+ if ((Int)profile_level < (Int)(SIMPLE_SCALABLE_PROFILE_LEVEL0)) /* non-scalable profile */
+ {
+ profile_level_table = (Int *)profile_level_max_packet_size;
+ profile_table_index = (Int)profile_level;
+ if (encParams->nLayers != 1)
+ {
+ goto CLEAN_UP;
+ }
+
+ encParams->LayerMaxMbsPerSec[0] = profile_level_max_mbsPerSec[profile_table_index];
+
+ }
+ else /* scalable profile */
+ {
+ profile_level_table = (Int *)scalable_profile_level_max_packet_size;
+ profile_table_index = (Int)profile_level - (Int)(SIMPLE_SCALABLE_PROFILE_LEVEL0);
+ if (encParams->nLayers < 2)
+ {
+ goto CLEAN_UP;
+ }
+ for (i = 0; i < encParams->nLayers; i++)
+ {
+ encParams->LayerMaxMbsPerSec[i] = scalable_profile_level_max_mbsPerSec[profile_table_index];
+ }
+
+ }
+
+ /* cannot have zero size packet with these modes */
+ if (PacketSize == 0)
+ {
+ if (encOption->encMode == DATA_PARTITIONING_MODE)
+ {
+ goto CLEAN_UP;
+ }
+ if (encOption->encMode == COMBINE_MODE_WITH_ERR_RES)
+ {
+ encOption->encMode = COMBINE_MODE_NO_ERR_RES;
+ }
+ }
+
+ if (encOption->gobHeaderInterval == 0)
+ {
+ if (encOption->encMode == H263_MODE_WITH_ERR_RES)
+ {
+ encOption->encMode = H263_MODE;
+ }
+
+ if (encOption->encMode == SHORT_HEADER_WITH_ERR_RES)
+ {
+ encOption->encMode = SHORT_HEADER;
+ }
+ }
+
+ if (PacketSize > profile_level_table[profile_table_index])
+ goto CLEAN_UP;
+
+ /* Initial Defaults for all Modes */
+
+ encParams->SequenceStartCode = 1;
+ encParams->GOV_Enabled = 0;
+ encParams->RoundingType = 0;
+ encParams->IntraDCVlcThr = PV_MAX(PV_MIN(encOption->intraDCVlcTh, 7), 0);
+ encParams->ACDCPrediction = ((encOption->useACPred == PV_ON) ? TRUE : FALSE);
+ encParams->RC_Type = encOption->rcType;
+ encParams->Refresh = encOption->numIntraMB;
+ encParams->ResyncMarkerDisable = 0; /* Enable Resync Marker */
+
+ for (i = 0; i < encOption->numLayers; i++)
+ {
+#ifdef NO_MPEG_QUANT
+ encParams->QuantType[i] = 0;
+#else
+ encParams->QuantType[i] = encOption->quantType[i]; /* H263 */
+#endif
+ if (encOption->pQuant[i] >= 1 && encOption->pQuant[i] <= 31)
+ {
+ encParams->InitQuantPvop[i] = encOption->pQuant[i];
+ }
+ else
+ {
+ goto CLEAN_UP;
+ }
+ if (encOption->iQuant[i] >= 1 && encOption->iQuant[i] <= 31)
+ {
+ encParams->InitQuantIvop[i] = encOption->iQuant[i];
+ }
+ else
+ {
+ goto CLEAN_UP;
+ }
+ }
+
+ encParams->HalfPel_Enabled = 1;
+ encParams->SearchRange = encOption->searchRange; /* 4/16/2001 */
+ encParams->FullSearch_Enabled = 0;
+#ifdef NO_INTER4V
+ encParams->MV8x8_Enabled = 0;
+#else
+ encParams->MV8x8_Enabled = 0;// comment out for now!! encOption->mv8x8Enable;
+#endif
+ encParams->H263_Enabled = 0;
+ encParams->GOB_Header_Interval = 0; // need to be reset to 0
+ encParams->IntraPeriod = encOption->intraPeriod; /* Intra update period update default*/
+ encParams->SceneChange_Det = encOption->sceneDetect;
+ encParams->FineFrameSkip_Enabled = 0;
+ encParams->NoFrameSkip_Enabled = encOption->noFrameSkipped;
+ encParams->NoPreSkip_Enabled = encOption->noFrameSkipped;
+ encParams->GetVolHeader[0] = 0;
+ encParams->GetVolHeader[1] = 0;
+ encParams->ResyncPacketsize = encOption->packetSize << 3;
+ encParams->LayerMaxBitRate[0] = 0;
+ encParams->LayerMaxBitRate[1] = 0;
+ encParams->LayerMaxFrameRate[0] = (float)0.0;
+ encParams->LayerMaxFrameRate[1] = (float)0.0;
+ encParams->VBV_delay = encOption->vbvDelay; /* 2sec VBV buffer size */
+
+ switch (encOption->encMode)
+ {
+
+ case SHORT_HEADER:
+ case SHORT_HEADER_WITH_ERR_RES:
+
+ /* From Table 6-26 */
+ encParams->nLayers = 1;
+ encParams->QuantType[0] = 0; /*H263 */
+ encParams->ResyncMarkerDisable = 1; /* Disable Resync Marker */
+ encParams->DataPartitioning = 0; /* Combined Mode */
+ encParams->ReversibleVLC = 0; /* Disable RVLC */
+ encParams->RoundingType = 0;
+ encParams->IntraDCVlcThr = 7; /* use_intra_dc_vlc = 0 */
+ encParams->MV8x8_Enabled = 0;
+
+ encParams->GOB_Header_Interval = encOption->gobHeaderInterval;
+ encParams->H263_Enabled = 2;
+ encParams->GOV_Enabled = 0;
+ encParams->TimeIncrementRes = 30000; /* timeIncrementRes for H263 */
+ break;
+
+ case H263_MODE:
+ case H263_MODE_WITH_ERR_RES:
+
+ /* From Table 6-26 */
+ encParams->nLayers = 1;
+ encParams->QuantType[0] = 0; /*H263 */
+ encParams->ResyncMarkerDisable = 1; /* Disable Resync Marker */
+ encParams->DataPartitioning = 0; /* Combined Mode */
+ encParams->ReversibleVLC = 0; /* Disable RVLC */
+ encParams->RoundingType = 0;
+ encParams->IntraDCVlcThr = 7; /* use_intra_dc_vlc = 0 */
+ encParams->MV8x8_Enabled = 0;
+
+ encParams->H263_Enabled = 1;
+ encParams->GOV_Enabled = 0;
+ encParams->TimeIncrementRes = 30000; /* timeIncrementRes for H263 */
+
+ break;
+#ifndef H263_ONLY
+ case DATA_PARTITIONING_MODE:
+
+ encParams->DataPartitioning = 1; /* Base Layer Data Partitioning */
+ encParams->ResyncMarkerDisable = 0; /* Resync Marker */
+#ifdef NO_RVLC
+ encParams->ReversibleVLC = 0;
+#else
+ encParams->ReversibleVLC = (encOption->rvlcEnable == PV_ON); /* RVLC when Data Partitioning */
+#endif
+ encParams->ResyncPacketsize = PacketSize;
+ break;
+
+ case COMBINE_MODE_WITH_ERR_RES:
+
+ encParams->DataPartitioning = 0; /* Combined Mode */
+ encParams->ResyncMarkerDisable = 0; /* Resync Marker */
+ encParams->ReversibleVLC = 0; /* No RVLC */
+ encParams->ResyncPacketsize = PacketSize;
+ break;
+
+ case COMBINE_MODE_NO_ERR_RES:
+
+ encParams->DataPartitioning = 0; /* Combined Mode */
+ encParams->ResyncMarkerDisable = 1; /* Disable Resync Marker */
+ encParams->ReversibleVLC = 0; /* No RVLC */
+ break;
+#endif
+ default:
+ goto CLEAN_UP;
+ }
+ /* Set the constraints (maximum values) according to the input profile and level */
+ /* Note that profile_table_index is already figured out above */
+
+ /* base layer */
+ encParams->profile_table_index = profile_table_index; /* Used to limit the profile and level in SetProfile_BufferSize() */
+
+ /* check timeIncRes */
+ timeIncRes = encOption->timeIncRes;
+ timeInc = encOption->tickPerSrc;
+
+ if ((timeIncRes >= 1) && (timeIncRes <= 65536) && (timeInc < timeIncRes) && (timeInc != 0))
+ {
+ if (!encParams->H263_Enabled)
+ {
+ encParams->TimeIncrementRes = timeIncRes;
+ }
+ else
+ {
+ encParams->TimeIncrementRes = 30000;
+// video->FrameRate = 30000/(float)1001; /* fix it to 29.97 fps */
+ }
+ video->FrameRate = timeIncRes / ((float)timeInc);
+ }
+ else
+ {
+ goto CLEAN_UP;
+ }
+
+ /* check frame dimension */
+ if (encParams->H263_Enabled)
+ {
+ switch (encOption->encWidth[0])
+ {
+ case 128:
+ if (encOption->encHeight[0] != 96) /* source_format = 1 */
+ goto CLEAN_UP;
+ break;
+ case 176:
+ if (encOption->encHeight[0] != 144) /* source_format = 2 */
+ goto CLEAN_UP;
+ break;
+ case 352:
+ if (encOption->encHeight[0] != 288) /* source_format = 2 */
+ goto CLEAN_UP;
+ break;
+
+ case 704:
+ if (encOption->encHeight[0] != 576) /* source_format = 2 */
+ goto CLEAN_UP;
+ break;
+ case 1408:
+ if (encOption->encHeight[0] != 1152) /* source_format = 2 */
+ goto CLEAN_UP;
+ break;
+
+ default:
+ goto CLEAN_UP;
+ }
+ }
+ for (i = 0; i < encParams->nLayers; i++)
+ {
+ encParams->LayerHeight[i] = encOption->encHeight[i];
+ encParams->LayerWidth[i] = encOption->encWidth[i];
+ }
+
+ /* check frame rate */
+ for (i = 0; i < encParams->nLayers; i++)
+ {
+ encParams->LayerFrameRate[i] = encOption->encFrameRate[i];
+ }
+
+ if (encParams->nLayers > 1)
+ {
+ if (encOption->encFrameRate[0] == encOption->encFrameRate[1] ||
+ encOption->encFrameRate[0] == 0. || encOption->encFrameRate[1] == 0.) /* 7/31/03 */
+ goto CLEAN_UP;
+ }
+ /* set max frame rate */
+ for (i = 0; i < encParams->nLayers; i++)
+ {
+
+ /* Make sure the maximum framerate is consistent with the given profile and level */
+ nTotalMB = ((encParams->LayerWidth[i] + 15) / 16) * ((encParams->LayerHeight[i] + 15) / 16);
+
+ if (nTotalMB > 0)
+ profile_max_framerate = (float)encParams->LayerMaxMbsPerSec[i] / (float)nTotalMB;
+
+ else
+ profile_max_framerate = (float)30.0;
+
+ encParams->LayerMaxFrameRate[i] = PV_MIN(profile_max_framerate, encParams->LayerFrameRate[i]);
+ }
+
+ /* check bit rate */
+ /* set max bit rate */
+ for (i = 0; i < encParams->nLayers; i++)
+ {
+ encParams->LayerBitRate[i] = encOption->bitRate[i];
+ encParams->LayerMaxBitRate[i] = encOption->bitRate[i];
+ }
+ if (encParams->nLayers > 1)
+ {
+ if (encOption->bitRate[0] == encOption->bitRate[1] ||
+ encOption->bitRate[0] == 0 || encOption->bitRate[1] == 0) /* 7/31/03 */
+ goto CLEAN_UP;
+ }
+ /* check rate control and vbv delay*/
+ encParams->RC_Type = encOption->rcType;
+
+ if (encOption->vbvDelay == 0.0) /* set to default */
+ {
+ switch (encOption->rcType)
+ {
+ case CBR_1:
+ case CBR_2:
+ encParams->VBV_delay = (float)2.0; /* default 2sec VBV buffer size */
+ break;
+
+ case CBR_LOWDELAY:
+ encParams->VBV_delay = (float)0.5; /* default 0.5sec VBV buffer size */
+ break;
+
+ case VBR_1:
+ case VBR_2:
+ encParams->VBV_delay = (float)10.0; /* default 10sec VBV buffer size */
+ break;
+ default:
+ break;
+ }
+ }
+ else /* force this value */
+ {
+ encParams->VBV_delay = encOption->vbvDelay;
+ }
+
+ /* check search range */
+ if (encParams->H263_Enabled && encOption->searchRange > 16)
+ {
+ encParams->SearchRange = 16; /* 4/16/2001 */
+ }
+
+ /*****************************************/
+ /* checking for conflict between options */
+ /*****************************************/
+
+ if (video->encParams->RC_Type == CBR_1 || video->encParams->RC_Type == CBR_2 || video->encParams->RC_Type == CBR_LOWDELAY) /* if CBR */
+ {
+#ifdef _PRINT_STAT
+ if (video->encParams->NoFrameSkip_Enabled == PV_ON ||
+ video->encParams->NoPreSkip_Enabled == PV_ON) /* don't allow frame skip*/
+ printf("WARNING!!!! CBR with NoFrameSkip\n");
+#endif
+ }
+ else if (video->encParams->RC_Type == CONSTANT_Q) /* constant_Q */
+ {
+ video->encParams->NoFrameSkip_Enabled = PV_ON; /* no frame skip */
+ video->encParams->NoPreSkip_Enabled = PV_ON; /* no frame skip */
+#ifdef _PRINT_STAT
+ printf("Turn on NoFrameSkip\n");
+#endif
+ }
+
+ if (video->encParams->NoFrameSkip_Enabled == PV_ON) /* if no frame skip */
+ {
+ video->encParams->FineFrameSkip_Enabled = PV_OFF;
+#ifdef _PRINT_STAT
+ printf("NoFrameSkip !!! may violate VBV_BUFFER constraint.\n");
+ printf("Turn off FineFrameSkip\n");
+#endif
+ }
+
+ /******************************************/
+ /******************************************/
+
+ nLayers = video->encParams->nLayers; /* Number of Layers to be encoded */
+
+ /* Find the maximum width*height for memory allocation of the VOPs */
+ for (idx = 0; idx < nLayers; idx++)
+ {
+ temp_w = video->encParams->LayerWidth[idx];
+ temp_h = video->encParams->LayerHeight[idx];
+
+ if ((temp_w*temp_h) > max)
+ {
+ max = temp_w * temp_h;
+ max_width = ((temp_w + 15) >> 4) << 4;
+ max_height = ((temp_h + 15) >> 4) << 4;
+ if (((uint64_t)max_width * max_height) > (uint64_t)INT32_MAX
+ || temp_w > INT32_MAX - 15 || temp_h > INT32_MAX - 15) {
+ goto CLEAN_UP;
+ }
+ nTotalMB = ((max_width * max_height) >> 8);
+ }
+
+ /* Check if the video size and framerate(MBsPerSec) are vald */
+ mbsPerSec = (Int)(nTotalMB * video->encParams->LayerFrameRate[idx]);
+ if (mbsPerSec > video->encParams->LayerMaxMbsPerSec[idx]) status = PV_FALSE;
+ }
+
+ /****************************************************/
+ /* Set Profile and Video Buffer Size for each layer */
+ /****************************************************/
+ if (video->encParams->RC_Type == CBR_LOWDELAY) video->encParams->VBV_delay = 0.5; /* For CBR_LOWDELAY, we set 0.5sec buffer */
+ status = SetProfile_BufferSize(video, video->encParams->VBV_delay, 1);
+ if (status != PV_TRUE)
+ goto CLEAN_UP;
+
+ /****************************************/
+ /* memory allocation and initialization */
+ /****************************************/
+
+ if (video == NULL) goto CLEAN_UP;
+
+ /* cyclic reference for passing through both structures */
+ video->videoEncControls = encoderControl;
+
+ //video->currLayer = 0; /* Set current Layer to 0 */
+ //video->currFrameNo = 0; /* Set current frame Number to 0 */
+ video->nextModTime = 0;
+ video->nextEncIVop = 0; /* Sets up very first frame to be I-VOP! */
+ video->numVopsInGOP = 0; /* counter for Vops in Gop, 2/8/01 */
+
+ //video->frameRate = video->encParams->LayerFrameRate[0]; /* Set current layer frame rate */
+
+ video->QPMB = (UChar *) M4VENC_MALLOC(nTotalMB * sizeof(UChar)); /* Memory for MB quantizers */
+ if (video->QPMB == NULL) goto CLEAN_UP;
+
+
+ video->headerInfo.Mode = (UChar *) M4VENC_MALLOC(sizeof(UChar) * nTotalMB); /* Memory for MB Modes */
+ if (video->headerInfo.Mode == NULL) goto CLEAN_UP;
+ video->headerInfo.CBP = (UChar *) M4VENC_MALLOC(sizeof(UChar) * nTotalMB); /* Memory for CBP (Y and C) of each MB */
+ if (video->headerInfo.CBP == NULL) goto CLEAN_UP;
+
+ /* Allocating motion vector space and interpolation memory*/
+
+ if ((size_t)nTotalMB > SIZE_MAX / sizeof(MOT *)) {
+ goto CLEAN_UP;
+ }
+ video->mot = (MOT **)M4VENC_MALLOC(sizeof(MOT *) * nTotalMB);
+ if (video->mot == NULL) goto CLEAN_UP;
+
+ for (idx = 0; idx < nTotalMB; idx++)
+ {
+ video->mot[idx] = (MOT *)M4VENC_MALLOC(sizeof(MOT) * 8);
+ if (video->mot[idx] == NULL)
+ {
+ goto CLEAN_UP;
+ }
+ }
+
+ video->intraArray = (UChar *)M4VENC_MALLOC(sizeof(UChar) * nTotalMB);
+ if (video->intraArray == NULL) goto CLEAN_UP;
+
+ video->sliceNo = (UChar *) M4VENC_MALLOC(nTotalMB); /* Memory for Slice Numbers */
+ if (video->sliceNo == NULL) goto CLEAN_UP;
+ /* Allocating space for predDCAC[][8][16], Not that I intentionally */
+ /* increase the dimension of predDCAC from [][6][15] to [][8][16] */
+ /* so that compilers can generate faster code to indexing the */
+ /* data inside (by using << instead of *). 04/14/2000. */
+ /* 5/29/01, use decoder lib ACDC prediction memory scheme. */
+ if ((size_t)nTotalMB > SIZE_MAX / sizeof(typeDCStore)) {
+ goto CLEAN_UP;
+ }
+ video->predDC = (typeDCStore *) M4VENC_MALLOC(nTotalMB * sizeof(typeDCStore));
+ if (video->predDC == NULL) goto CLEAN_UP;
+
+ if (!video->encParams->H263_Enabled)
+ {
+ if ((size_t)((max_width >> 4) + 1) > SIZE_MAX / sizeof(typeDCACStore)) {
+ goto CLEAN_UP;
+ }
+ video->predDCAC_col = (typeDCACStore *) M4VENC_MALLOC(((max_width >> 4) + 1) * sizeof(typeDCACStore));
+ if (video->predDCAC_col == NULL) goto CLEAN_UP;
+
+ /* element zero will be used for storing vertical (col) AC coefficients */
+ /* the rest will be used for storing horizontal (row) AC coefficients */
+ video->predDCAC_row = video->predDCAC_col + 1; /* ACDC */
+
+ if ((size_t)nTotalMB > SIZE_MAX / sizeof(Int)) {
+ goto CLEAN_UP;
+ }
+ video->acPredFlag = (Int *) M4VENC_MALLOC(nTotalMB * sizeof(Int)); /* Memory for acPredFlag */
+ if (video->acPredFlag == NULL) goto CLEAN_UP;
+ }
+
+ video->outputMB = (MacroBlock *) M4VENC_MALLOC(sizeof(MacroBlock)); /* Allocating macroblock space */
+ if (video->outputMB == NULL) goto CLEAN_UP;
+ M4VENC_MEMSET(video->outputMB->block[0], 0, (sizeof(Short) << 6)*6);
+
+ M4VENC_MEMSET(video->dataBlock, 0, sizeof(Short) << 7);
+ /* Allocate (2*packetsize) working bitstreams */
+
+ video->bitstream1 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 1*/
+ if (video->bitstream1 == NULL) goto CLEAN_UP;
+ video->bitstream2 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 2*/
+ if (video->bitstream2 == NULL) goto CLEAN_UP;
+ video->bitstream3 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 3*/
+ if (video->bitstream3 == NULL) goto CLEAN_UP;
+
+ /* allocate overrun buffer */
+ // this buffer is used when user's buffer is too small to hold one frame.
+ // It is not needed for slice-based encoding.
+ if (nLayers == 1)
+ {
+ video->oBSize = encParams->BufferSize[0] >> 3;
+ }
+ else
+ {
+ video->oBSize = PV_MAX((encParams->BufferSize[0] >> 3), (encParams->BufferSize[1] >> 3));
+ }
+
+ if (video->oBSize > DEFAULT_OVERRUN_BUFFER_SIZE || encParams->RC_Type == CONSTANT_Q) // set limit
+ {
+ video->oBSize = DEFAULT_OVERRUN_BUFFER_SIZE;
+ }
+ video->overrunBuffer = (UChar*) M4VENC_MALLOC(sizeof(UChar) * video->oBSize);
+ if (video->overrunBuffer == NULL) goto CLEAN_UP;
+
+
+ video->currVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Current VOP */
+ if (video->currVop == NULL) goto CLEAN_UP;
+
+ /* add padding, 09/19/05 */
+ if (video->encParams->H263_Enabled) /* make it conditional 11/28/05 */
+ {
+ pitch = max_width;
+ offset = 0;
+ }
+ else
+ {
+ pitch = max_width + 32;
+ offset = (pitch << 4) + 16;
+ max_height += 32;
+ }
+ if (((uint64_t)pitch * max_height) > (uint64_t)INT32_MAX) {
+ goto CLEAN_UP;
+ }
+ size = pitch * max_height;
+
+ if (size > INT32_MAX - (size >> 1)
+ || (size_t)(size + (size >> 1)) > SIZE_MAX / sizeof(PIXEL)) {
+ goto CLEAN_UP;
+ }
+ video->currVop->allChan = video->currVop->yChan = (PIXEL *)M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for currVop Y */
+ if (video->currVop->yChan == NULL) goto CLEAN_UP;
+ video->currVop->uChan = video->currVop->yChan + size;/* Memory for currVop U */
+ video->currVop->vChan = video->currVop->uChan + (size >> 2);/* Memory for currVop V */
+
+ /* shift for the offset */
+ if (offset)
+ {
+ video->currVop->yChan += offset; /* offset to the origin.*/
+ video->currVop->uChan += (offset >> 2) + 4;
+ video->currVop->vChan += (offset >> 2) + 4;
+ }
+
+ video->forwardRefVop = video->currVop; /* Initialize forwardRefVop */
+ video->backwardRefVop = video->currVop; /* Initialize backwardRefVop */
+
+ video->prevBaseVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Previous Base Vop */
+ if (video->prevBaseVop == NULL) goto CLEAN_UP;
+ video->prevBaseVop->allChan = video->prevBaseVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for prevBaseVop Y */
+ if (video->prevBaseVop->yChan == NULL) goto CLEAN_UP;
+ video->prevBaseVop->uChan = video->prevBaseVop->yChan + size; /* Memory for prevBaseVop U */
+ video->prevBaseVop->vChan = video->prevBaseVop->uChan + (size >> 2); /* Memory for prevBaseVop V */
+
+ if (offset)
+ {
+ video->prevBaseVop->yChan += offset; /* offset to the origin.*/
+ video->prevBaseVop->uChan += (offset >> 2) + 4;
+ video->prevBaseVop->vChan += (offset >> 2) + 4;
+ }
+
+
+ if (0) /* If B Frames */
+ {
+ video->nextBaseVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Next Base Vop */
+ if (video->nextBaseVop == NULL) goto CLEAN_UP;
+ video->nextBaseVop->allChan = video->nextBaseVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for nextBaseVop Y */
+ if (video->nextBaseVop->yChan == NULL) goto CLEAN_UP;
+ video->nextBaseVop->uChan = video->nextBaseVop->yChan + size; /* Memory for nextBaseVop U */
+ video->nextBaseVop->vChan = video->nextBaseVop->uChan + (size >> 2); /* Memory for nextBaseVop V */
+
+ if (offset)
+ {
+ video->nextBaseVop->yChan += offset; /* offset to the origin.*/
+ video->nextBaseVop->uChan += (offset >> 2) + 4;
+ video->nextBaseVop->vChan += (offset >> 2) + 4;
+ }
+ }
+
+ if (nLayers > 1) /* If enhancement layers */
+ {
+ video->prevEnhanceVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Previous Enhancement Vop */
+ if (video->prevEnhanceVop == NULL) goto CLEAN_UP;
+ video->prevEnhanceVop->allChan = video->prevEnhanceVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for Previous Ehancement Y */
+ if (video->prevEnhanceVop->yChan == NULL) goto CLEAN_UP;
+ video->prevEnhanceVop->uChan = video->prevEnhanceVop->yChan + size; /* Memory for Previous Enhancement U */
+ video->prevEnhanceVop->vChan = video->prevEnhanceVop->uChan + (size >> 2); /* Memory for Previous Enhancement V */
+
+ if (offset)
+ {
+ video->prevEnhanceVop->yChan += offset; /* offset to the origin.*/
+ video->prevEnhanceVop->uChan += (offset >> 2) + 4;
+ video->prevEnhanceVop->vChan += (offset >> 2) + 4;
+ }
+ }
+
+ video->numberOfLayers = nLayers; /* Number of Layers */
+ video->sumMAD = 0;
+
+
+ /* 04/09/01, for Vops in the use multipass processing */
+ for (idx = 0; idx < nLayers; idx++)
+ {
+ video->pMP[idx] = (MultiPass *)M4VENC_MALLOC(sizeof(MultiPass));
+ if (video->pMP[idx] == NULL) goto CLEAN_UP;
+ M4VENC_MEMSET(video->pMP[idx], 0, sizeof(MultiPass));
+
+ video->pMP[idx]->encoded_frames = -1; /* forget about the very first I frame */
+
+
+ /* RDInfo **pRDSamples */
+ video->pMP[idx]->pRDSamples = (RDInfo **)M4VENC_MALLOC(30 * sizeof(RDInfo *));
+ if (video->pMP[idx]->pRDSamples == NULL) goto CLEAN_UP;
+ for (i = 0; i < 30; i++)
+ {
+ video->pMP[idx]->pRDSamples[i] = (RDInfo *)M4VENC_MALLOC(32 * sizeof(RDInfo));
+ if (video->pMP[idx]->pRDSamples[i] == NULL) goto CLEAN_UP;
+ for (j = 0; j < 32; j++) M4VENC_MEMSET(&(video->pMP[idx]->pRDSamples[i][j]), 0, sizeof(RDInfo));
+ }
+ video->pMP[idx]->frameRange = (Int)(video->encParams->LayerFrameRate[idx] * 1.0); /* 1.0s time frame*/
+ video->pMP[idx]->frameRange = PV_MAX(video->pMP[idx]->frameRange, 5);
+ video->pMP[idx]->frameRange = PV_MIN(video->pMP[idx]->frameRange, 30);
+
+ video->pMP[idx]->framePos = -1;
+
+ }
+ /* /// End /////////////////////////////////////// */
+
+
+ if ((size_t)nLayers > SIZE_MAX / sizeof(Vol *)) {
+ goto CLEAN_UP;
+ }
+ video->vol = (Vol **)M4VENC_MALLOC(nLayers * sizeof(Vol *)); /* Memory for VOL pointers */
+
+ /* Memory allocation and Initialization of Vols and writing of headers */
+ if (video->vol == NULL) goto CLEAN_UP;
+
+ for (idx = 0; idx < nLayers; idx++)
+ {
+ video->volInitialize[idx] = 1;
+ video->refTick[idx] = 0;
+ video->relLayerCodeTime[idx] = 1000;
+ video->vol[idx] = (Vol *)M4VENC_MALLOC(sizeof(Vol));
+ if (video->vol[idx] == NULL) goto CLEAN_UP;
+
+ pVol = video->vol[idx];
+ pEncParams = video->encParams;
+
+ M4VENC_MEMSET(video->vol[idx], 0, sizeof(Vol));
+ /* Initialize some VOL parameters */
+ pVol->volID = idx; /* Set VOL ID */
+ pVol->shortVideoHeader = pEncParams->H263_Enabled; /*Short Header */
+ pVol->GOVStart = pEncParams->GOV_Enabled; /* GOV Header */
+ pVol->timeIncrementResolution = video->encParams->TimeIncrementRes;
+ pVol->nbitsTimeIncRes = 1;
+ while (pVol->timeIncrementResolution > (1 << pVol->nbitsTimeIncRes))
+ {
+ pVol->nbitsTimeIncRes++;
+ }
+
+ /* timing stuff */
+ pVol->timeIncrement = 0;
+ pVol->moduloTimeBase = 0;
+ pVol->fixedVopRate = 0; /* No fixed VOP rate */
+ pVol->stream = (BitstreamEncVideo *)M4VENC_MALLOC(sizeof(BitstreamEncVideo)); /* allocate BitstreamEncVideo Instance */
+ if (pVol->stream == NULL) goto CLEAN_UP;
+
+ pVol->width = pEncParams->LayerWidth[idx]; /* Layer Width */
+ pVol->height = pEncParams->LayerHeight[idx]; /* Layer Height */
+ // pVol->intra_acdcPredDisable = pEncParams->ACDCPrediction; /* ACDC Prediction */
+ pVol->ResyncMarkerDisable = pEncParams->ResyncMarkerDisable; /* Resync Marker Mode */
+ pVol->dataPartitioning = pEncParams->DataPartitioning; /* Data Partitioning */
+ pVol->useReverseVLC = pEncParams->ReversibleVLC; /* RVLC */
+ if (idx > 0) /* Scalability layers */
+ {
+ pVol->ResyncMarkerDisable = 1;
+ pVol->dataPartitioning = 0;
+ pVol->useReverseVLC = 0; /* No RVLC */
+ }
+ pVol->quantType = pEncParams->QuantType[idx]; /* Quantizer Type */
+
+ /* no need to init Quant Matrices */
+
+ pVol->scalability = 0; /* Vol Scalability */
+ if (idx > 0)
+ pVol->scalability = 1; /* Multiple layers => Scalability */
+
+ /* Initialize Vol to Temporal scalability. It can change during encoding */
+ pVol->scalType = 1;
+ /* Initialize reference Vol ID to the base layer = 0 */
+ pVol->refVolID = 0;
+ /* Initialize layer resolution to same as the reference */
+ pVol->refSampDir = 0;
+ pVol->horSamp_m = 1;
+ pVol->horSamp_n = 1;
+ pVol->verSamp_m = 1;
+ pVol->verSamp_n = 1;
+ pVol->enhancementType = 0; /* We always enhance the entire region */
+
+ pVol->nMBPerRow = (pVol->width + 15) / 16;
+ pVol->nMBPerCol = (pVol->height + 15) / 16;
+ pVol->nTotalMB = pVol->nMBPerRow * pVol->nMBPerCol;
+
+ if (pVol->nTotalMB >= 1)
+ pVol->nBitsForMBID = 1;
+ if (pVol->nTotalMB >= 3)
+ pVol->nBitsForMBID = 2;
+ if (pVol->nTotalMB >= 5)
+ pVol->nBitsForMBID = 3;
+ if (pVol->nTotalMB >= 9)
+ pVol->nBitsForMBID = 4;
+ if (pVol->nTotalMB >= 17)
+ pVol->nBitsForMBID = 5;
+ if (pVol->nTotalMB >= 33)
+ pVol->nBitsForMBID = 6;
+ if (pVol->nTotalMB >= 65)
+ pVol->nBitsForMBID = 7;
+ if (pVol->nTotalMB >= 129)
+ pVol->nBitsForMBID = 8;
+ if (pVol->nTotalMB >= 257)
+ pVol->nBitsForMBID = 9;
+ if (pVol->nTotalMB >= 513)
+ pVol->nBitsForMBID = 10;
+ if (pVol->nTotalMB >= 1025)
+ pVol->nBitsForMBID = 11;
+ if (pVol->nTotalMB >= 2049)
+ pVol->nBitsForMBID = 12;
+ if (pVol->nTotalMB >= 4097)
+ pVol->nBitsForMBID = 13;
+ if (pVol->nTotalMB >= 8193)
+ pVol->nBitsForMBID = 14;
+ if (pVol->nTotalMB >= 16385)
+ pVol->nBitsForMBID = 15;
+ if (pVol->nTotalMB >= 32769)
+ pVol->nBitsForMBID = 16;
+ if (pVol->nTotalMB >= 65537)
+ pVol->nBitsForMBID = 17;
+ if (pVol->nTotalMB >= 131073)
+ pVol->nBitsForMBID = 18;
+
+ if (pVol->shortVideoHeader)
+ {
+ switch (pVol->width)
+ {
+ case 128:
+ if (pVol->height == 96) /* source_format = 1 */
+ {
+ pVol->nGOBinVop = 6;
+ pVol->nMBinGOB = 8;
+ }
+ else
+ status = PV_FALSE;
+ break;
+
+ case 176:
+ if (pVol->height == 144) /* source_format = 2 */
+ {
+ pVol->nGOBinVop = 9;
+ pVol->nMBinGOB = 11;
+ }
+ else
+ status = PV_FALSE;
+ break;
+ case 352:
+ if (pVol->height == 288) /* source_format = 2 */
+ {
+ pVol->nGOBinVop = 18;
+ pVol->nMBinGOB = 22;
+ }
+ else
+ status = PV_FALSE;
+ break;
+
+ case 704:
+ if (pVol->height == 576) /* source_format = 2 */
+ {
+ pVol->nGOBinVop = 18;
+ pVol->nMBinGOB = 88;
+ }
+ else
+ status = PV_FALSE;
+ break;
+ case 1408:
+ if (pVol->height == 1152) /* source_format = 2 */
+ {
+ pVol->nGOBinVop = 18;
+ pVol->nMBinGOB = 352;
+ }
+ else
+ status = PV_FALSE;
+ break;
+
+ default:
+ status = PV_FALSE;
+ break;
+ }
+ }
+ }
+
+ /***************************************************/
+ /* allocate and initialize rate control parameters */
+ /***************************************************/
+
+ /* BEGIN INITIALIZATION OF ANNEX L RATE CONTROL */
+ if (video->encParams->RC_Type != CONSTANT_Q)
+ {
+ for (idx = 0; idx < nLayers; idx++) /* 12/25/00 */
+ {
+ video->rc[idx] =
+ (rateControl *)M4VENC_MALLOC(sizeof(rateControl));
+
+ if (video->rc[idx] == NULL) goto CLEAN_UP;
+
+ M4VENC_MEMSET(video->rc[idx], 0, sizeof(rateControl));
+ }
+ if (PV_SUCCESS != RC_Initialize(video))
+ {
+ goto CLEAN_UP;
+ }
+ /* initialization for 2-pass rate control */
+ }
+ /* END INITIALIZATION OF ANNEX L RATE CONTROL */
+
+ /********** assign platform dependent functions ***********************/
+ /* 1/23/01 */
+ /* This must be done at run-time not a compile time */
+ video->functionPointer = (FuncPtr*) M4VENC_MALLOC(sizeof(FuncPtr));
+ if (video->functionPointer == NULL) goto CLEAN_UP;
+
+ video->functionPointer->ComputeMBSum = &ComputeMBSum_C;
+ video->functionPointer->SAD_MB_HalfPel[0] = NULL;
+ video->functionPointer->SAD_MB_HalfPel[1] = &SAD_MB_HalfPel_Cxh;
+ video->functionPointer->SAD_MB_HalfPel[2] = &SAD_MB_HalfPel_Cyh;
+ video->functionPointer->SAD_MB_HalfPel[3] = &SAD_MB_HalfPel_Cxhyh;
+
+#ifndef NO_INTER4V
+ video->functionPointer->SAD_Blk_HalfPel = &SAD_Blk_HalfPel_C;
+ video->functionPointer->SAD_Block = &SAD_Block_C;
+#endif
+ video->functionPointer->SAD_Macroblock = &SAD_Macroblock_C;
+ video->functionPointer->ChooseMode = &ChooseMode_C;
+ video->functionPointer->GetHalfPelMBRegion = &GetHalfPelMBRegion_C;
+// video->functionPointer->SAD_MB_PADDING = &SAD_MB_PADDING; /* 4/21/01 */
+
+
+ encoderControl->videoEncoderInit = 1; /* init done! */
+
+ return PV_TRUE;
+
+CLEAN_UP:
+ PVCleanUpVideoEncoder(encoderControl);
+
+ return PV_FALSE;
+}
+
+
+/* ======================================================================== */
+/* Function : PVCleanUpVideoEncoder() */
+/* Date : 08/22/2000 */
+/* Purpose : Deallocates allocated memory from InitVideoEncoder() */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : 5/21/01, free only yChan in Vop */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVCleanUpVideoEncoder(VideoEncControls *encoderControl)
+{
+ Int idx, i;
+ VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
+ int nTotalMB;
+ int max_width, offset;
+
+#ifdef PRINT_RC_INFO
+ if (facct != NULL)
+ {
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fprintf(facct, "TOTAL NUM BITS GENERATED %d\n", tiTotalNumBitsGenerated);
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fprintf(facct, "TOTAL NUMBER OF FRAMES CODED %d\n",
+ video->encParams->rc[0]->totalFrameNumber);
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fprintf(facct, "Average BitRate %d\n",
+ (tiTotalNumBitsGenerated / (90 / 30)));
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fprintf(facct, "TOTAL NUMBER OF STUFF BITS %d\n", (iStuffBits + 10740));
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fprintf(facct, "TOTAL NUMBER OF BITS TO NETWORK %d\n", (35800*90 / 30));;
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fprintf(facct, "SUM OF STUFF BITS AND GENERATED BITS %d\n",
+ (tiTotalNumBitsGenerated + iStuffBits + 10740));
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fprintf(facct, "UNACCOUNTED DIFFERENCE %d\n",
+ ((35800*90 / 30) - (tiTotalNumBitsGenerated + iStuffBits + 10740)));
+ fprintf(facct, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+ fclose(facct);
+ }
+#endif
+
+#ifdef PRINT_EC
+ fclose(fec);
+#endif
+
+ if (video != NULL)
+ {
+
+ if (video->QPMB) M4VENC_FREE(video->QPMB);
+ if (video->headerInfo.Mode)M4VENC_FREE(video->headerInfo.Mode);
+ if (video->headerInfo.CBP)M4VENC_FREE(video->headerInfo.CBP);
+
+
+ if (video->mot)
+ {
+ nTotalMB = video->vol[0]->nTotalMB;
+ for (idx = 1; idx < video->currLayer; idx++)
+ if (video->vol[idx]->nTotalMB > nTotalMB)
+ nTotalMB = video->vol[idx]->nTotalMB;
+ for (idx = 0; idx < nTotalMB; idx++)
+ {
+ if (video->mot[idx])
+ M4VENC_FREE(video->mot[idx]);
+ }
+ M4VENC_FREE(video->mot);
+ }
+
+ if (video->intraArray) M4VENC_FREE(video->intraArray);
+
+ if (video->sliceNo)M4VENC_FREE(video->sliceNo);
+ if (video->acPredFlag)M4VENC_FREE(video->acPredFlag);
+// if(video->predDCAC)M4VENC_FREE(video->predDCAC);
+ if (video->predDC) M4VENC_FREE(video->predDC);
+ video->predDCAC_row = NULL;
+ if (video->predDCAC_col) M4VENC_FREE(video->predDCAC_col);
+ if (video->outputMB)M4VENC_FREE(video->outputMB);
+
+ if (video->bitstream1)BitstreamCloseEnc(video->bitstream1);
+ if (video->bitstream2)BitstreamCloseEnc(video->bitstream2);
+ if (video->bitstream3)BitstreamCloseEnc(video->bitstream3);
+
+ if (video->overrunBuffer) M4VENC_FREE(video->overrunBuffer);
+
+ max_width = video->encParams->LayerWidth[0];
+ max_width = (((max_width + 15) >> 4) << 4); /* 09/19/05 */
+ if (video->encParams->H263_Enabled)
+ {
+ offset = 0;
+ }
+ else
+ {
+ offset = ((max_width + 32) << 4) + 16;
+ }
+
+ if (video->currVop)
+ {
+ if (video->currVop->allChan)
+ {
+ M4VENC_FREE(video->currVop->allChan);
+ }
+ M4VENC_FREE(video->currVop);
+ }
+
+ if (video->nextBaseVop)
+ {
+ if (video->nextBaseVop->allChan)
+ {
+ M4VENC_FREE(video->nextBaseVop->allChan);
+ }
+ M4VENC_FREE(video->nextBaseVop);
+ }
+
+ if (video->prevBaseVop)
+ {
+ if (video->prevBaseVop->allChan)
+ {
+ M4VENC_FREE(video->prevBaseVop->allChan);
+ }
+ M4VENC_FREE(video->prevBaseVop);
+ }
+ if (video->prevEnhanceVop)
+ {
+ if (video->prevEnhanceVop->allChan)
+ {
+ M4VENC_FREE(video->prevEnhanceVop->allChan);
+ }
+ M4VENC_FREE(video->prevEnhanceVop);
+ }
+
+ /* 04/09/01, for Vops in the use multipass processing */
+ for (idx = 0; idx < video->encParams->nLayers; idx++)
+ {
+ if (video->pMP[idx])
+ {
+ if (video->pMP[idx]->pRDSamples)
+ {
+ for (i = 0; i < 30; i++)
+ {
+ if (video->pMP[idx]->pRDSamples[i])
+ M4VENC_FREE(video->pMP[idx]->pRDSamples[i]);
+ }
+ M4VENC_FREE(video->pMP[idx]->pRDSamples);
+ }
+
+ M4VENC_MEMSET(video->pMP[idx], 0, sizeof(MultiPass));
+ M4VENC_FREE(video->pMP[idx]);
+ }
+ }
+ /* // End /////////////////////////////////////// */
+
+ if (video->vol)
+ {
+ for (idx = 0; idx < video->encParams->nLayers; idx++)
+ {
+ if (video->vol[idx])
+ {
+ if (video->vol[idx]->stream)
+ M4VENC_FREE(video->vol[idx]->stream);
+ M4VENC_FREE(video->vol[idx]);
+ }
+ }
+ M4VENC_FREE(video->vol);
+ }
+
+ /***************************************************/
+ /* stop rate control parameters */
+ /***************************************************/
+
+ /* ANNEX L RATE CONTROL */
+ if (video->encParams->RC_Type != CONSTANT_Q)
+ {
+ RC_Cleanup(video->rc, video->encParams->nLayers);
+
+ for (idx = 0; idx < video->encParams->nLayers; idx++)
+ {
+ if (video->rc[idx])
+ M4VENC_FREE(video->rc[idx]);
+ }
+ }
+
+ if (video->functionPointer) M4VENC_FREE(video->functionPointer);
+
+ /* If application has called PVCleanUpVideoEncoder then we deallocate */
+ /* If PVInitVideoEncoder class it, then we DO NOT deallocate */
+ if (video->encParams)
+ {
+ M4VENC_FREE(video->encParams);
+ }
+
+ M4VENC_FREE(video);
+ encoderControl->videoEncoderData = NULL; /* video */
+ }
+
+ encoderControl->videoEncoderInit = 0;
+
+ return PV_TRUE;
+}
+
+/* ======================================================================== */
+/* Function : PVGetVolHeader() */
+/* Date : 7/17/2001, */
+/* Purpose : */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVGetVolHeader(VideoEncControls *encCtrl, UChar *volHeader, Int *size, Int layer)
+{
+ VideoEncData *encData;
+ PV_STATUS EncodeVOS_Start(VideoEncControls *encCtrl);
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+
+ encData->currLayer = layer; /* Set Layer */
+ /*pv_status = */
+ EncodeVOS_Start(encCtrl); /* Encode VOL Header */
+
+ encData->encParams->GetVolHeader[layer] = 1; /* Set usage flag: Needed to support old method*/
+
+ /* Copy bitstream to buffer and set the size */
+
+ if (*size > encData->bitstream1->byteCount)
+ {
+ *size = encData->bitstream1->byteCount;
+ M4VENC_MEMCPY(volHeader, encData->bitstream1->bitstreamBuffer, *size);
+ }
+ else
+ return PV_FALSE;
+
+ /* Reset bitstream1 buffer parameters */
+ BitstreamEncReset(encData->bitstream1);
+
+ return PV_TRUE;
+}
+
+/* ======================================================================== */
+/* Function : PVGetOverrunBuffer() */
+/* Purpose : Get the overrun buffer ` */
+/* In/out : */
+/* Return : Pointer to overrun buffer. */
+/* Modified : */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF UChar* PVGetOverrunBuffer(VideoEncControls *encCtrl)
+{
+ VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
+ Int currLayer = video->currLayer;
+ Vol *currVol = video->vol[currLayer];
+
+ if (currVol->stream->bitstreamBuffer != video->overrunBuffer) // not used
+ {
+ return NULL;
+ }
+
+ return video->overrunBuffer;
+}
+
+
+
+
+/* ======================================================================== */
+/* Function : EncodeVideoFrame() */
+/* Date : 08/22/2000 */
+/* Purpose : Encode video frame and return bitstream */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* 02.14.2001 */
+/* Finishing new timestamp 32-bit input */
+/* Applications need to take care of wrap-around */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVEncodeVideoFrame(VideoEncControls *encCtrl, VideoEncFrameIO *vid_in, VideoEncFrameIO *vid_out,
+ ULong *nextModTime, UChar *bstream, Int *size, Int *nLayer)
+{
+ Bool status = PV_TRUE;
+ PV_STATUS pv_status;
+ VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
+ VideoEncParams *encParams = video->encParams;
+ Vol *currVol;
+ Vop *tempForwRefVop = NULL;
+ Int tempRefSelCode = 0;
+ PV_STATUS EncodeVOS_Start(VideoEncControls *encCtrl);
+ Int width_16, height_16;
+ Int width, height;
+ Vop *temp;
+ Int encodeVop = 0;
+ void PaddingEdge(Vop *padVop);
+ Int currLayer = -1;
+ //Int nLayers = encParams->nLayers;
+
+ ULong modTime = vid_in->timestamp;
+
+#ifdef RANDOM_REFSELCODE /* add random selection of reference Vop */
+ Int random_val[30] = {0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0};
+ static Int rand_idx = 0;
+#endif
+
+ /*******************************************************/
+ /* Determine Next Vop to encode, if any, and nLayer */
+ /*******************************************************/
+ //i = nLayers-1;
+
+ if (video->volInitialize[0]) /* first vol to code */
+ {
+ video->nextModTime = video->modTimeRef = ((modTime) - ((modTime) % 1000));
+ }
+
+ encodeVop = DetermineCodingLayer(video, nLayer, modTime);
+ currLayer = *nLayer;
+ if ((currLayer < 0) || (currLayer > encParams->nLayers - 1))
+ return PV_FALSE;
+
+ /******************************************/
+ /* If post-skipping still effective --- return */
+ /******************************************/
+
+ if (!encodeVop) /* skip enh layer, no base layer coded --- return */
+ {
+#ifdef _PRINT_STAT
+ printf("No frame coded. Continue to next frame.");
+#endif
+ /* expected next code time, convert back to millisec */
+ *nextModTime = video->nextModTime;
+
+#ifdef ALLOW_VOP_NOT_CODED
+ if (video->vol[0]->shortVideoHeader) /* Short Video Header = 1 */
+ {
+ *size = 0;
+ *nLayer = -1;
+ }
+ else
+ {
+ *nLayer = 0;
+ EncodeVopNotCoded(video, bstream, size, modTime);
+ *size = video->vol[0]->stream->byteCount;
+ }
+#else
+ *size = 0;
+ *nLayer = -1;
+#endif
+ return status;
+ }
+
+
+//ENCODE_VOP_AGAIN: /* 12/30/00 */
+
+ /**************************************************************/
+ /* Initialize Vol stream structure with application bitstream */
+ /**************************************************************/
+
+ currVol = video->vol[currLayer];
+ currVol->stream->bitstreamBuffer = bstream;
+ currVol->stream->bufferSize = *size;
+ BitstreamEncReset(currVol->stream);
+ BitstreamSetOverrunBuffer(currVol->stream, video->overrunBuffer, video->oBSize, video);
+
+ /***********************************************************/
+ /* Encode VOS and VOL Headers on first call for each layer */
+ /***********************************************************/
+
+ if (video->volInitialize[currLayer])
+ {
+ video->currVop->timeInc = 0;
+ video->prevBaseVop->timeInc = 0;
+ if (!video->encParams->GetVolHeader[currLayer])
+ pv_status = EncodeVOS_Start(encCtrl);
+ }
+
+ /***************************************************/
+ /* Copy Input Video Frame to Internal Video Buffer */
+ /***************************************************/
+ /* Determine Width and Height of Vop Layer */
+
+ width = encParams->LayerWidth[currLayer]; /* Get input width */
+ height = encParams->LayerHeight[currLayer]; /* Get input height */
+ /* Round Up to nearest multiple of 16 : MPEG-4 Standard */
+
+ width_16 = ((width + 15) / 16) * 16; /* Round up to nearest multiple of 16 */
+ height_16 = ((height + 15) / 16) * 16; /* Round up to nearest multiple of 16 */
+
+ video->input = vid_in; /* point to the frame input */
+
+ /*// End ////////////////////////////// */
+
+
+ /**************************************/
+ /* Determine VOP Type */
+ /* 6/2/2001, separate function */
+ /**************************************/
+ DetermineVopType(video, currLayer);
+
+ /****************************/
+ /* Initialize VOP */
+ /****************************/
+ video->currVop->volID = currVol->volID;
+ video->currVop->width = width_16;
+ video->currVop->height = height_16;
+ if (video->encParams->H263_Enabled) /* 11/28/05 */
+ {
+ video->currVop->pitch = width_16;
+ }
+ else
+ {
+ video->currVop->pitch = width_16 + 32;
+ }
+ video->currVop->timeInc = currVol->timeIncrement;
+ video->currVop->vopCoded = 1;
+ video->currVop->roundingType = 0;
+ video->currVop->intraDCVlcThr = encParams->IntraDCVlcThr;
+
+ if (currLayer == 0
+#ifdef RANDOM_REFSELCODE /* add random selection of reference Vop */
+ || random_val[rand_idx] || video->volInitialize[currLayer]
+#endif
+ )
+ {
+ tempForwRefVop = video->forwardRefVop; /* keep initial state */
+ if (tempForwRefVop != NULL) tempRefSelCode = tempForwRefVop->refSelectCode;
+
+ video->forwardRefVop = video->prevBaseVop;
+ video->forwardRefVop->refSelectCode = 1;
+ }
+#ifdef RANDOM_REFSELCODE
+ else
+ {
+ tempForwRefVop = video->forwardRefVop; /* keep initial state */
+ if (tempForwRefVop != NULL) tempRefSelCode = tempForwRefVop->refSelectCode;
+
+ video->forwardRefVop = video->prevEnhanceVop;
+ video->forwardRefVop->refSelectCode = 0;
+ }
+ rand_idx++;
+ rand_idx %= 30;
+#endif
+
+ video->currVop->refSelectCode = video->forwardRefVop->refSelectCode;
+ video->currVop->gobNumber = 0;
+ video->currVop->gobFrameID = video->currVop->predictionType;
+ video->currVop->temporalRef = (modTime * 30 / 1001) % 256;
+
+ video->currVop->temporalInterval = 0;
+
+ if (video->currVop->predictionType == I_VOP)
+ video->currVop->quantizer = encParams->InitQuantIvop[currLayer];
+ else
+ video->currVop->quantizer = encParams->InitQuantPvop[currLayer];
+
+
+ /****************/
+ /* Encode Vop */
+ /****************/
+ video->slice_coding = 0;
+
+ pv_status = EncodeVop(video);
+#ifdef _PRINT_STAT
+ if (video->currVop->predictionType == I_VOP)
+ printf(" I-VOP ");
+ else
+ printf(" P-VOP (ref.%d)", video->forwardRefVop->refSelectCode);
+#endif
+
+ /************************************/
+ /* Update Skip Next Frame */
+ /************************************/
+ *nLayer = UpdateSkipNextFrame(video, nextModTime, size, pv_status);
+ if (*nLayer == -1) /* skip current frame */
+ {
+ /* make sure that pointers are restored to the previous state */
+ if (currLayer == 0)
+ {
+ video->forwardRefVop = tempForwRefVop; /* For P-Vop base only */
+ video->forwardRefVop->refSelectCode = tempRefSelCode;
+ }
+
+ return status;
+ }
+
+ /* If I-VOP was encoded, reset IntraPeriod */
+ if ((currLayer == 0) && (encParams->IntraPeriod > 0) && (video->currVop->predictionType == I_VOP))
+ video->nextEncIVop = encParams->IntraPeriod;
+
+ /* Set HintTrack Information */
+ if (currLayer != -1)
+ {
+ if (currVol->prevModuloTimeBase)
+ video->hintTrackInfo.MTB = 1;
+ else
+ video->hintTrackInfo.MTB = 0;
+ video->hintTrackInfo.LayerID = (UChar)currVol->volID;
+ video->hintTrackInfo.CodeType = (UChar)video->currVop->predictionType;
+ video->hintTrackInfo.RefSelCode = (UChar)video->currVop->refSelectCode;
+ }
+
+ /************************************************/
+ /* Determine nLayer and timeInc for next encode */
+ /* 12/27/00 always go by the highest layer*/
+ /************************************************/
+
+ /**********************************************************/
+ /* Copy Reconstructed Buffer to Output Video Frame Buffer */
+ /**********************************************************/
+ vid_out->yChan = video->currVop->yChan;
+ vid_out->uChan = video->currVop->uChan;
+ vid_out->vChan = video->currVop->vChan;
+ if (video->encParams->H263_Enabled)
+ {
+ vid_out->height = video->currVop->height; /* padded height */
+ vid_out->pitch = video->currVop->width; /* padded width */
+ }
+ else
+ {
+ vid_out->height = video->currVop->height + 32; /* padded height */
+ vid_out->pitch = video->currVop->width + 32; /* padded width */
+ }
+ //video_out->timestamp = video->modTime;
+ vid_out->timestamp = (ULong)(((video->prevFrameNum[currLayer] * 1000) / encParams->LayerFrameRate[currLayer]) + video->modTimeRef + 0.5);
+
+ /*// End /////////////////////// */
+
+ /***********************************/
+ /* Update Ouput bstream byte count */
+ /***********************************/
+
+ *size = currVol->stream->byteCount;
+
+ /****************************************/
+ /* Swap Vop Pointers for Base Layer */
+ /****************************************/
+ if (currLayer == 0)
+ {
+ temp = video->prevBaseVop;
+ video->prevBaseVop = video->currVop;
+ video->prevBaseVop->padded = 0; /* not padded */
+ video->currVop = temp;
+ video->forwardRefVop = video->prevBaseVop; /* For P-Vop base only */
+ video->forwardRefVop->refSelectCode = 1;
+ }
+ else
+ {
+ temp = video->prevEnhanceVop;
+ video->prevEnhanceVop = video->currVop;
+ video->prevEnhanceVop->padded = 0; /* not padded */
+ video->currVop = temp;
+ video->forwardRefVop = video->prevEnhanceVop;
+ video->forwardRefVop->refSelectCode = 0;
+ }
+
+ /****************************************/
+ /* Modify the intialize flag at the end.*/
+ /****************************************/
+ if (video->volInitialize[currLayer])
+ video->volInitialize[currLayer] = 0;
+
+ return status;
+}
+
+#ifndef NO_SLICE_ENCODE
+/* ======================================================================== */
+/* Function : PVEncodeFrameSet() */
+/* Date : 04/18/2000 */
+/* Purpose : Enter a video frame and perform front-end time check plus ME */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVEncodeFrameSet(VideoEncControls *encCtrl, VideoEncFrameIO *vid_in, ULong *nextModTime, Int *nLayer)
+{
+ Bool status = PV_TRUE;
+ VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
+ VideoEncParams *encParams = video->encParams;
+ Vol *currVol;
+ PV_STATUS EncodeVOS_Start(VideoEncControls *encCtrl);
+ Int width_16, height_16;
+ Int width, height;
+ Int encodeVop = 0;
+ void PaddingEdge(Vop *padVop);
+ Int currLayer = -1;
+ //Int nLayers = encParams->nLayers;
+
+ ULong modTime = vid_in->timestamp;
+
+#ifdef RANDOM_REFSELCODE /* add random selection of reference Vop */
+ Int random_val[30] = {0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0};
+ static Int rand_idx = 0;
+#endif
+ /*******************************************************/
+ /* Determine Next Vop to encode, if any, and nLayer */
+ /*******************************************************/
+
+ video->modTime = modTime;
+
+ //i = nLayers-1;
+
+ if (video->volInitialize[0]) /* first vol to code */
+ {
+ video->nextModTime = video->modTimeRef = ((modTime) - ((modTime) % 1000));
+ }
+
+
+ encodeVop = DetermineCodingLayer(video, nLayer, modTime);
+
+ currLayer = *nLayer;
+
+ /******************************************/
+ /* If post-skipping still effective --- return */
+ /******************************************/
+
+ if (!encodeVop) /* skip enh layer, no base layer coded --- return */
+ {
+#ifdef _PRINT_STAT
+ printf("No frame coded. Continue to next frame.");
+#endif
+ *nLayer = -1;
+
+ /* expected next code time, convert back to millisec */
+ *nextModTime = video->nextModTime;;
+ return status;
+ }
+
+ /**************************************************************/
+ /* Initialize Vol stream structure with application bitstream */
+ /**************************************************************/
+
+ currVol = video->vol[currLayer];
+ currVol->stream->bufferSize = 0;
+ BitstreamEncReset(currVol->stream);
+
+ /***********************************************************/
+ /* Encode VOS and VOL Headers on first call for each layer */
+ /***********************************************************/
+
+ if (video->volInitialize[currLayer])
+ {
+ video->currVop->timeInc = 0;
+ video->prevBaseVop->timeInc = 0;
+ }
+
+ /***************************************************/
+ /* Copy Input Video Frame to Internal Video Buffer */
+ /***************************************************/
+ /* Determine Width and Height of Vop Layer */
+
+ width = encParams->LayerWidth[currLayer]; /* Get input width */
+ height = encParams->LayerHeight[currLayer]; /* Get input height */
+ /* Round Up to nearest multiple of 16 : MPEG-4 Standard */
+
+ width_16 = ((width + 15) / 16) * 16; /* Round up to nearest multiple of 16 */
+ height_16 = ((height + 15) / 16) * 16; /* Round up to nearest multiple of 16 */
+
+ video->input = vid_in; /* point to the frame input */
+
+ /*// End ////////////////////////////// */
+
+
+ /**************************************/
+ /* Determine VOP Type */
+ /* 6/2/2001, separate function */
+ /**************************************/
+ DetermineVopType(video, currLayer);
+
+ /****************************/
+ /* Initialize VOP */
+ /****************************/
+ video->currVop->volID = currVol->volID;
+ video->currVop->width = width_16;
+ video->currVop->height = height_16;
+ if (video->encParams->H263_Enabled) /* 11/28/05 */
+ {
+ video->currVop->pitch = width_16;
+ }
+ else
+ {
+ video->currVop->pitch = width_16 + 32;
+ }
+ video->currVop->timeInc = currVol->timeIncrement;
+ video->currVop->vopCoded = 1;
+ video->currVop->roundingType = 0;
+ video->currVop->intraDCVlcThr = encParams->IntraDCVlcThr;
+
+ if (currLayer == 0
+#ifdef RANDOM_REFSELCODE /* add random selection of reference Vop */
+ || random_val[rand_idx] || video->volInitialize[currLayer]
+#endif
+ )
+ {
+ video->tempForwRefVop = video->forwardRefVop; /* keep initial state */
+ if (video->tempForwRefVop != NULL) video->tempRefSelCode = video->tempForwRefVop->refSelectCode;
+
+ video->forwardRefVop = video->prevBaseVop;
+ video->forwardRefVop->refSelectCode = 1;
+ }
+#ifdef RANDOM_REFSELCODE
+ else
+ {
+ video->tempForwRefVop = video->forwardRefVop; /* keep initial state */
+ if (video->tempForwRefVop != NULL) video->tempRefSelCode = video->tempForwRefVop->refSelectCode;
+
+ video->forwardRefVop = video->prevEnhanceVop;
+ video->forwardRefVop->refSelectCode = 0;
+ }
+ rand_idx++;
+ rand_idx %= 30;
+#endif
+
+ video->currVop->refSelectCode = video->forwardRefVop->refSelectCode;
+ video->currVop->gobNumber = 0;
+ video->currVop->gobFrameID = video->currVop->predictionType;
+ video->currVop->temporalRef = ((modTime) * 30 / 1001) % 256;
+
+ video->currVop->temporalInterval = 0;
+
+ if (video->currVop->predictionType == I_VOP)
+ video->currVop->quantizer = encParams->InitQuantIvop[currLayer];
+ else
+ video->currVop->quantizer = encParams->InitQuantPvop[currLayer];
+
+ /****************/
+ /* Encode Vop */
+ /****************/
+ video->slice_coding = 1;
+
+ /*pv_status =*/
+ EncodeVop(video);
+
+#ifdef _PRINT_STAT
+ if (video->currVop->predictionType == I_VOP)
+ printf(" I-VOP ");
+ else
+ printf(" P-VOP (ref.%d)", video->forwardRefVop->refSelectCode);
+#endif
+
+ /* Set HintTrack Information */
+ if (currVol->prevModuloTimeBase)
+ video->hintTrackInfo.MTB = 1;
+ else
+ video->hintTrackInfo.MTB = 0;
+
+ video->hintTrackInfo.LayerID = (UChar)currVol->volID;
+ video->hintTrackInfo.CodeType = (UChar)video->currVop->predictionType;
+ video->hintTrackInfo.RefSelCode = (UChar)video->currVop->refSelectCode;
+
+ return status;
+}
+#endif /* NO_SLICE_ENCODE */
+
+#ifndef NO_SLICE_ENCODE
+/* ======================================================================== */
+/* Function : PVEncodePacket() */
+/* Date : 04/18/2002 */
+/* Purpose : Encode one packet and return bitstream */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVEncodeSlice(VideoEncControls *encCtrl, UChar *bstream, Int *size,
+ Int *endofFrame, VideoEncFrameIO *vid_out, ULong *nextModTime)
+{
+ PV_STATUS pv_status;
+ VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
+ VideoEncParams *encParams = video->encParams;
+ Vol *currVol;
+ PV_STATUS EncodeVOS_Start(VideoEncControls *encCtrl);
+ Vop *temp;
+ void PaddingEdge(Vop *padVop);
+ Int currLayer = video->currLayer;
+ Int pre_skip;
+ Int pre_size;
+ /**************************************************************/
+ /* Initialize Vol stream structure with application bitstream */
+ /**************************************************************/
+
+ currVol = video->vol[currLayer];
+ currVol->stream->bitstreamBuffer = bstream;
+ pre_size = currVol->stream->byteCount;
+ currVol->stream->bufferSize = pre_size + (*size);
+
+ /***********************************************************/
+ /* Encode VOS and VOL Headers on first call for each layer */
+ /***********************************************************/
+
+ if (video->volInitialize[currLayer])
+ {
+ if (!video->encParams->GetVolHeader[currLayer])
+ pv_status = EncodeVOS_Start(encCtrl);
+ }
+
+ /****************/
+ /* Encode Slice */
+ /****************/
+ pv_status = EncodeSlice(video);
+
+ *endofFrame = 0;
+
+ if (video->mbnum >= currVol->nTotalMB && !video->end_of_buf)
+ {
+ *endofFrame = 1;
+
+ /************************************/
+ /* Update Skip Next Frame */
+ /************************************/
+ pre_skip = UpdateSkipNextFrame(video, nextModTime, size, pv_status); /* modified such that no pre-skipped */
+
+ if (pre_skip == -1) /* error */
+ {
+ *endofFrame = -1;
+ /* make sure that pointers are restored to the previous state */
+ if (currLayer == 0)
+ {
+ video->forwardRefVop = video->tempForwRefVop; /* For P-Vop base only */
+ video->forwardRefVop->refSelectCode = video->tempRefSelCode;
+ }
+
+ return pv_status;
+ }
+
+ /* If I-VOP was encoded, reset IntraPeriod */
+ if ((currLayer == 0) && (encParams->IntraPeriod > 0) && (video->currVop->predictionType == I_VOP))
+ video->nextEncIVop = encParams->IntraPeriod;
+
+ /**********************************************************/
+ /* Copy Reconstructed Buffer to Output Video Frame Buffer */
+ /**********************************************************/
+ vid_out->yChan = video->currVop->yChan;
+ vid_out->uChan = video->currVop->uChan;
+ vid_out->vChan = video->currVop->vChan;
+ if (video->encParams->H263_Enabled)
+ {
+ vid_out->height = video->currVop->height; /* padded height */
+ vid_out->pitch = video->currVop->width; /* padded width */
+ }
+ else
+ {
+ vid_out->height = video->currVop->height + 32; /* padded height */
+ vid_out->pitch = video->currVop->width + 32; /* padded width */
+ }
+ //vid_out->timestamp = video->modTime;
+ vid_out->timestamp = (ULong)(((video->prevFrameNum[currLayer] * 1000) / encParams->LayerFrameRate[currLayer]) + video->modTimeRef + 0.5);
+
+ /*// End /////////////////////// */
+
+ /****************************************/
+ /* Swap Vop Pointers for Base Layer */
+ /****************************************/
+
+ if (currLayer == 0)
+ {
+ temp = video->prevBaseVop;
+ video->prevBaseVop = video->currVop;
+ video->prevBaseVop->padded = 0; /* not padded */
+ video->currVop = temp;
+ video->forwardRefVop = video->prevBaseVop; /* For P-Vop base only */
+ video->forwardRefVop->refSelectCode = 1;
+ }
+ else
+ {
+ temp = video->prevEnhanceVop;
+ video->prevEnhanceVop = video->currVop;
+ video->prevEnhanceVop->padded = 0; /* not padded */
+ video->currVop = temp;
+ video->forwardRefVop = video->prevEnhanceVop;
+ video->forwardRefVop->refSelectCode = 0;
+ }
+ }
+
+ /***********************************/
+ /* Update Ouput bstream byte count */
+ /***********************************/
+
+ *size = currVol->stream->byteCount - pre_size;
+
+ /****************************************/
+ /* Modify the intialize flag at the end.*/
+ /****************************************/
+ if (video->volInitialize[currLayer])
+ video->volInitialize[currLayer] = 0;
+
+ return pv_status;
+}
+#endif /* NO_SLICE_ENCODE */
+
+
+/* ======================================================================== */
+/* Function : PVGetH263ProfileLevelID() */
+/* Date : 02/05/2003 */
+/* Purpose : Get H.263 Profile ID and level ID for profile 0 */
+/* In/out : Profile ID=0, levelID is what we want */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* Note : h263Level[8], rBR_bound[8], max_h263_framerate[2] */
+/* max_h263_width[2], max_h263_height[2] are global */
+/* */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVGetH263ProfileLevelID(VideoEncControls *encCtrl, Int *profileID, Int *levelID)
+{
+ VideoEncData *encData;
+ Int width, height;
+ float bitrate_r, framerate;
+
+
+ /* For this version, we only support H.263 profile 0 */
+ *profileID = 0;
+
+ *levelID = 0;
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+ if (!encData->encParams->H263_Enabled) return PV_FALSE;
+
+
+ /* get image width, height, bitrate and framerate */
+ width = encData->encParams->LayerWidth[0];
+ height = encData->encParams->LayerHeight[0];
+ bitrate_r = (float)(encData->encParams->LayerBitRate[0]) / (float)64000.0;
+ framerate = encData->encParams->LayerFrameRate[0];
+ if (!width || !height || !(bitrate_r > 0 && framerate > 0)) return PV_FALSE;
+
+ /* This is the most frequent case : level 10 */
+ if (bitrate_r <= rBR_bound[1] && framerate <= max_h263_framerate[0] &&
+ (width <= max_h263_width[0] && height <= max_h263_height[0]))
+ {
+ *levelID = h263Level[1];
+ return PV_TRUE;
+ }
+ else if (bitrate_r > rBR_bound[4] ||
+ (width > max_h263_width[1] || height > max_h263_height[1]) ||
+ framerate > max_h263_framerate[1]) /* check the highest level 70 */
+ {
+ *levelID = h263Level[7];
+ return PV_TRUE;
+ }
+ else /* search level 20, 30, 40 */
+ {
+
+ /* pick out level 20 */
+ if (bitrate_r <= rBR_bound[2] &&
+ ((width <= max_h263_width[0] && height <= max_h263_height[0] && framerate <= max_h263_framerate[1]) ||
+ (width <= max_h263_width[1] && height <= max_h263_height[1] && framerate <= max_h263_framerate[0])))
+ {
+ *levelID = h263Level[2];
+ return PV_TRUE;
+ }
+ else /* width, height and framerate are ok, now choose level 30 or 40 */
+ {
+ *levelID = (bitrate_r <= rBR_bound[3] ? h263Level[3] : h263Level[4]);
+ return PV_TRUE;
+ }
+ }
+}
+
+/* ======================================================================== */
+/* Function : PVGetMPEG4ProfileLevelID() */
+/* Date : 26/06/2008 */
+/* Purpose : Get MPEG4 Level after initialized */
+/* In/out : profile_level according to interface */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVGetMPEG4ProfileLevelID(VideoEncControls *encCtrl, Int *profile_level, Int nLayer)
+{
+ VideoEncData* video;
+ Int i;
+
+ video = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (nLayer == 0)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ if (video->encParams->ProfileLevel[0] == profile_level_code[i])
+ {
+ break;
+ }
+ }
+ *profile_level = i;
+ }
+ else
+ {
+ for (i = 0; i < 8; i++)
+ {
+ if (video->encParams->ProfileLevel[0] == scalable_profile_level_code[i])
+ {
+ break;
+ }
+ }
+ *profile_level = i + SIMPLE_SCALABLE_PROFILE_LEVEL0;
+ }
+
+ return true;
+}
+
+#ifndef LIMITED_API
+/* ======================================================================== */
+/* Function : PVUpdateEncFrameRate */
+/* Date : 04/08/2002 */
+/* Purpose : Update target frame rates of the encoded base and enhance */
+/* layer(if any) while encoding operation is ongoing */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVUpdateEncFrameRate(VideoEncControls *encCtrl, float *frameRate)
+{
+ VideoEncData *encData;
+ Int i;// nTotalMB, mbPerSec;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+ /* Update the framerates for all the layers */
+ for (i = 0; i < encData->encParams->nLayers; i++)
+ {
+
+ /* New check: encoding framerate should be consistent with the given profile and level */
+ //nTotalMB = (((encData->encParams->LayerWidth[i]+15)/16)*16)*(((encData->encParams->LayerHeight[i]+15)/16)*16)/(16*16);
+ //mbPerSec = (Int)(nTotalMB * frameRate[i]);
+ //if(mbPerSec > encData->encParams->LayerMaxMbsPerSec[i]) return PV_FALSE;
+ if (frameRate[i] > encData->encParams->LayerMaxFrameRate[i]) return PV_FALSE; /* set by users or profile */
+
+ encData->encParams->LayerFrameRate[i] = frameRate[i];
+ }
+
+ return RC_UpdateBXRCParams((void*) encData);
+
+}
+#endif
+#ifndef LIMITED_API
+/* ======================================================================== */
+/* Function : PVUpdateBitRate */
+/* Date : 04/08/2002 */
+/* Purpose : Update target bit rates of the encoded base and enhance */
+/* layer(if any) while encoding operation is ongoing */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVUpdateBitRate(VideoEncControls *encCtrl, Int *bitRate)
+{
+ VideoEncData *encData;
+ Int i;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+ /* Update the bitrates for all the layers */
+ for (i = 0; i < encData->encParams->nLayers; i++)
+ {
+ if (bitRate[i] > encData->encParams->LayerMaxBitRate[i]) /* set by users or profile */
+ {
+ return PV_FALSE;
+ }
+ encData->encParams->LayerBitRate[i] = bitRate[i];
+ }
+
+ return RC_UpdateBXRCParams((void*) encData);
+
+}
+#endif
+#ifndef LIMITED_API
+/* ============================================================================ */
+/* Function : PVUpdateVBVDelay() */
+/* Date : 4/23/2004 */
+/* Purpose : Update VBV buffer size(in delay) */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ============================================================================ */
+
+Bool PVUpdateVBVDelay(VideoEncControls *encCtrl, float delay)
+{
+
+ VideoEncData *encData;
+ Int total_bitrate, max_buffer_size;
+ int index;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+ /* Check whether the input delay is valid based on the given profile */
+ total_bitrate = (encData->encParams->nLayers == 1 ? encData->encParams->LayerBitRate[0] :
+ encData->encParams->LayerBitRate[1]);
+ index = encData->encParams->profile_table_index;
+ max_buffer_size = (encData->encParams->nLayers == 1 ? profile_level_max_VBV_size[index] :
+ scalable_profile_level_max_VBV_size[index]);
+
+ if (total_bitrate*delay > (float)max_buffer_size)
+ return PV_FALSE;
+
+ encData->encParams->VBV_delay = delay;
+ return PV_TRUE;
+
+}
+#endif
+#ifndef LIMITED_API
+/* ======================================================================== */
+/* Function : PVUpdateIFrameInterval() */
+/* Date : 04/10/2002 */
+/* Purpose : updates the INTRA frame refresh interval while encoding */
+/* is ongoing */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVUpdateIFrameInterval(VideoEncControls *encCtrl, Int aIFramePeriod)
+{
+ VideoEncData *encData;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+ encData->encParams->IntraPeriod = aIFramePeriod;
+ return PV_TRUE;
+}
+#endif
+#ifndef LIMITED_API
+/* ======================================================================== */
+/* Function : PVSetNumIntraMBRefresh() */
+/* Date : 08/05/2003 */
+/* Purpose : */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+OSCL_EXPORT_REF Bool PVUpdateNumIntraMBRefresh(VideoEncControls *encCtrl, Int numMB)
+{
+ VideoEncData *encData;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+
+ encData->encParams->Refresh = numMB;
+
+ return PV_TRUE;
+}
+#endif
+#ifndef LIMITED_API
+/* ======================================================================== */
+/* Function : PVIFrameRequest() */
+/* Date : 04/10/2002 */
+/* Purpose : encodes the next base frame as an I-Vop */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVIFrameRequest(VideoEncControls *encCtrl)
+{
+ VideoEncData *encData;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+ encData->nextEncIVop = 1;
+ return PV_TRUE;
+}
+#endif
+#ifndef LIMITED_API
+/* ======================================================================== */
+/* Function : PVGetEncMemoryUsage() */
+/* Date : 10/17/2000 */
+/* Purpose : */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Int PVGetEncMemoryUsage(VideoEncControls *encCtrl)
+{
+ VideoEncData *encData;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+ return encData->encParams->MemoryUsage;
+}
+#endif
+
+/* ======================================================================== */
+/* Function : PVGetHintTrack() */
+/* Date : 1/17/2001, */
+/* Purpose : */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVGetHintTrack(VideoEncControls *encCtrl, MP4HintTrack *info)
+{
+ VideoEncData *encData;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+ info->MTB = encData->hintTrackInfo.MTB;
+ info->LayerID = encData->hintTrackInfo.LayerID;
+ info->CodeType = encData->hintTrackInfo.CodeType;
+ info->RefSelCode = encData->hintTrackInfo.RefSelCode;
+
+ return PV_TRUE;
+}
+
+/* ======================================================================== */
+/* Function : PVGetMaxVideoFrameSize() */
+/* Date : 7/17/2001, */
+/* Purpose : Function merely returns the maximum buffer size */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVGetMaxVideoFrameSize(VideoEncControls *encCtrl, Int *maxVideoFrameSize)
+{
+ VideoEncData *encData;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+
+
+ *maxVideoFrameSize = encData->encParams->BufferSize[0];
+
+ if (encData->encParams->nLayers == 2)
+ if (*maxVideoFrameSize < encData->encParams->BufferSize[1])
+ *maxVideoFrameSize = encData->encParams->BufferSize[1];
+ *maxVideoFrameSize >>= 3; /* Convert to Bytes */
+
+ if (*maxVideoFrameSize <= 4000)
+ *maxVideoFrameSize = 4000;
+
+ return PV_TRUE;
+}
+#ifndef LIMITED_API
+/* ======================================================================== */
+/* Function : PVGetVBVSize() */
+/* Date : 4/15/2002 */
+/* Purpose : Function merely returns the maximum buffer size */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+OSCL_EXPORT_REF Bool PVGetVBVSize(VideoEncControls *encCtrl, Int *VBVSize)
+{
+ VideoEncData *encData;
+
+ encData = (VideoEncData *)encCtrl->videoEncoderData;
+
+ if (encData == NULL)
+ return PV_FALSE;
+ if (encData->encParams == NULL)
+ return PV_FALSE;
+
+ *VBVSize = encData->encParams->BufferSize[0];
+ if (encData->encParams->nLayers == 2)
+ *VBVSize += encData->encParams->BufferSize[1];
+
+ return PV_TRUE;
+
+}
+#endif
+/* ======================================================================== */
+/* Function : EncodeVOS_Start() */
+/* Date : 08/22/2000 */
+/* Purpose : Encodes the VOS,VO, and VOL or Short Headers */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+PV_STATUS EncodeVOS_Start(VideoEncControls *encoderControl)
+{
+
+ VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
+ Vol *currVol = video->vol[video->currLayer];
+ PV_STATUS status = PV_SUCCESS;
+ //int profile_level=0x01;
+ BitstreamEncVideo *stream = video->bitstream1;
+ int i, j;
+
+ /********************************/
+ /* Check for short_video_header */
+ /********************************/
+ if (currVol->shortVideoHeader == 1)
+ return status;
+ else
+ {
+ /* Short Video Header or M4V */
+
+ /**************************/
+ /* VisualObjectSequence ()*/
+ /**************************/
+ status = BitstreamPutGT16Bits(stream, 32, SESSION_START_CODE);
+ /* Determine profile_level */
+ status = BitstreamPutBits(stream, 8, video->encParams->ProfileLevel[video->currLayer]);
+
+ /******************/
+ /* VisualObject() */
+ /******************/
+
+ status = BitstreamPutGT16Bits(stream, 32, VISUAL_OBJECT_START_CODE);
+ status = BitstreamPut1Bits(stream, 0x00); /* visual object identifier */
+ status = BitstreamPutBits(stream, 4, 0x01); /* visual object Type == "video ID" */
+ status = BitstreamPut1Bits(stream, 0x00); /* no video signal type */
+
+ /*temp = */
+ BitstreamMpeg4ByteAlignStuffing(stream);
+
+
+ status = BitstreamPutGT16Bits(stream, 27, VO_START_CODE);/* byte align: should be 2 bits */
+ status = BitstreamPutBits(stream, 5, 0x00);/* Video ID = 0 */
+
+
+
+ /**********************/
+ /* VideoObjectLayer() */
+ /**********************/
+ if (currVol->shortVideoHeader == 0)
+ { /* M4V else Short Video Header */
+ status = BitstreamPutGT16Bits(stream, VOL_START_CODE_LENGTH, VOL_START_CODE);
+ status = BitstreamPutBits(stream, 4, currVol->volID);/* video_object_layer_id */
+ status = BitstreamPut1Bits(stream, 0x00);/* Random Access = 0 */
+
+ if (video->currLayer == 0)
+ status = BitstreamPutBits(stream, 8, 0x01);/* Video Object Type Indication = 1 ... Simple Object Type */
+ else
+ status = BitstreamPutBits(stream, 8, 0x02);/* Video Object Type Indication = 2 ... Simple Scalable Object Type */
+
+ status = BitstreamPut1Bits(stream, 0x00);/* is_object_layer_identifer = 0 */
+
+
+ status = BitstreamPutBits(stream, 4, 0x01); /* aspect_ratio_info = 1 ... 1:1(Square) */
+ status = BitstreamPut1Bits(stream, 0x00);/* vol_control_parameters = 0 */
+ status = BitstreamPutBits(stream, 2, 0x00);/* video_object_layer_shape = 00 ... rectangular */
+ status = BitstreamPut1Bits(stream, 0x01);/* marker bit */
+ status = BitstreamPutGT8Bits(stream, 16, currVol->timeIncrementResolution);/* vop_time_increment_resolution */
+ status = BitstreamPut1Bits(stream, 0x01);/* marker bit */
+ status = BitstreamPut1Bits(stream, currVol->fixedVopRate);/* fixed_vop_rate = 0 */
+
+ /* For Rectangular VO layer shape */
+ status = BitstreamPut1Bits(stream, 0x01);/* marker bit */
+ status = BitstreamPutGT8Bits(stream, 13, currVol->width);/* video_object_layer_width */
+ status = BitstreamPut1Bits(stream, 0x01);/* marker bit */
+ status = BitstreamPutGT8Bits(stream, 13, currVol->height);/* video_object_layer_height */
+ status = BitstreamPut1Bits(stream, 0x01);/*marker bit */
+
+ status = BitstreamPut1Bits(stream, 0x00);/*interlaced = 0 */
+ status = BitstreamPut1Bits(stream, 0x01);/* obmc_disable = 1 */
+ status = BitstreamPut1Bits(stream, 0x00);/* sprite_enable = 0 */
+ status = BitstreamPut1Bits(stream, 0x00);/* not_8_bit = 0 */
+ status = BitstreamPut1Bits(stream, currVol->quantType);/* quant_type */
+
+ if (currVol->quantType)
+ {
+ status = BitstreamPut1Bits(stream, currVol->loadIntraQuantMat); /* Intra quant matrix */
+ if (currVol->loadIntraQuantMat)
+ {
+ for (j = 63; j >= 1; j--)
+ if (currVol->iqmat[*(zigzag_i+j)] != currVol->iqmat[*(zigzag_i+j-1)])
+ break;
+ if ((j == 1) && (currVol->iqmat[*(zigzag_i+j)] == currVol->iqmat[*(zigzag_i+j-1)]))
+ j = 0;
+ for (i = 0; i < j + 1; i++)
+ BitstreamPutBits(stream, 8, currVol->iqmat[*(zigzag_i+i)]);
+ if (j < 63)
+ BitstreamPutBits(stream, 8, 0);
+ }
+ else
+ {
+ for (j = 0; j < 64; j++)
+ currVol->iqmat[j] = mpeg_iqmat_def[j];
+
+ }
+ status = BitstreamPut1Bits(stream, currVol->loadNonIntraQuantMat); /* Non-Intra quant matrix */
+ if (currVol->loadNonIntraQuantMat)
+ {
+ for (j = 63; j >= 1; j--)
+ if (currVol->niqmat[*(zigzag_i+j)] != currVol->niqmat[*(zigzag_i+j-1)])
+ break;
+ if ((j == 1) && (currVol->niqmat[*(zigzag_i+j)] == currVol->niqmat[*(zigzag_i+j-1)]))
+ j = 0;
+ for (i = 0; i < j + 1; i++)
+ BitstreamPutBits(stream, 8, currVol->niqmat[*(zigzag_i+i)]);
+ if (j < 63)
+ BitstreamPutBits(stream, 8, 0);
+ }
+ else
+ {
+ for (j = 0; j < 64; j++)
+ currVol->niqmat[j] = mpeg_nqmat_def[j];
+ }
+ }
+
+ status = BitstreamPut1Bits(stream, 0x01); /* complexity_estimation_disable = 1 */
+ status = BitstreamPut1Bits(stream, currVol->ResyncMarkerDisable);/* Resync_marker_disable */
+ status = BitstreamPut1Bits(stream, currVol->dataPartitioning);/* Data partitioned */
+
+ if (currVol->dataPartitioning)
+ status = BitstreamPut1Bits(stream, currVol->useReverseVLC); /* Reversible_vlc */
+
+
+ if (currVol->scalability) /* Scalability*/
+ {
+
+ status = BitstreamPut1Bits(stream, currVol->scalability);/* Scalability = 1 */
+ status = BitstreamPut1Bits(stream, currVol->scalType);/* hierarchy _type ... Spatial= 0 and Temporal = 1 */
+ status = BitstreamPutBits(stream, 4, currVol->refVolID);/* ref_layer_id */
+ status = BitstreamPut1Bits(stream, currVol->refSampDir);/* ref_layer_sampling_direc*/
+ status = BitstreamPutBits(stream, 5, currVol->horSamp_n);/*hor_sampling_factor_n*/
+ status = BitstreamPutBits(stream, 5, currVol->horSamp_m);/*hor_sampling_factor_m*/
+ status = BitstreamPutBits(stream, 5, currVol->verSamp_n);/*vert_sampling_factor_n*/
+ status = BitstreamPutBits(stream, 5, currVol->verSamp_m);/*vert_sampling_factor_m*/
+ status = BitstreamPut1Bits(stream, currVol->enhancementType);/* enhancement_type*/
+ }
+ else /* No Scalability */
+ status = BitstreamPut1Bits(stream, currVol->scalability);/* Scalability = 0 */
+
+ /*temp = */
+ BitstreamMpeg4ByteAlignStuffing(stream); /* Byte align Headers for VOP */
+ }
+ }
+
+ return status;
+}
+
+/* ======================================================================== */
+/* Function : VOS_End() */
+/* Date : 08/22/2000 */
+/* Purpose : Visual Object Sequence End */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+PV_STATUS VOS_End(VideoEncControls *encoderControl)
+{
+ PV_STATUS status = PV_SUCCESS;
+ VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
+ Vol *currVol = video->vol[video->currLayer];
+ BitstreamEncVideo *stream = currVol->stream;
+
+
+ status = BitstreamPutBits(stream, SESSION_END_CODE, 32);
+
+ return status;
+}
+
+/* ======================================================================== */
+/* Function : DetermineCodingLayer */
+/* Date : 06/02/2001 */
+/* Purpose : Find layer to code based on current mod time, assuming that
+ it's time to encode enhanced layer. */
+/* In/out : */
+/* Return : Number of layer to code. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+Int DetermineCodingLayer(VideoEncData *video, Int *nLayer, ULong modTime)
+{
+ Vol **vol = video->vol;
+ VideoEncParams *encParams = video->encParams;
+ Int numLayers = encParams->nLayers;
+ UInt modTimeRef = video->modTimeRef;
+ float *LayerFrameRate = encParams->LayerFrameRate;
+ UInt frameNum[4], frameTick;
+ ULong frameModTime, nextFrmModTime;
+#ifdef REDUCE_FRAME_VARIANCE /* To limit how close 2 frames can be */
+ float frameInterval;
+#endif
+ float srcFrameInterval;
+ Int frameInc;
+ Int i, extra_skip;
+ Int encodeVop = 0;
+
+ i = numLayers - 1;
+
+ if (modTime - video->nextModTime > ((ULong)(-1)) >> 1) /* next time wrapped around */
+ return 0; /* not time to code it yet */
+
+ video->relLayerCodeTime[i] -= 1000;
+ video->nextEncIVop--; /* number of Vops in highest layer resolution. */
+ video->numVopsInGOP++;
+
+ /* from this point frameModTime and nextFrmModTime are internal */
+
+ frameNum[i] = (UInt)((modTime - modTimeRef) * LayerFrameRate[i] + 500) / 1000;
+ if (video->volInitialize[i])
+ {
+ video->prevFrameNum[i] = frameNum[i] - 1;
+ }
+ else if (frameNum[i] <= video->prevFrameNum[i])
+ {
+ return 0; /* do not encode this frame */
+ }
+
+ /**** this part computes expected next frame *******/
+ frameModTime = (ULong)(((frameNum[i] * 1000) / LayerFrameRate[i]) + modTimeRef + 0.5); /* rec. time */
+ nextFrmModTime = (ULong)((((frameNum[i] + 1) * 1000) / LayerFrameRate[i]) + modTimeRef + 0.5); /* rec. time */
+
+ srcFrameInterval = 1000 / video->FrameRate;
+
+ video->nextModTime = nextFrmModTime - (ULong)(srcFrameInterval / 2.) - 1; /* between current and next frame */
+
+#ifdef REDUCE_FRAME_VARIANCE /* To limit how close 2 frames can be */
+ frameInterval = 1000 / LayerFrameRate[i]; /* next rec. time */
+ delta = (Int)(frameInterval / 4); /* empirical number */
+ if (video->nextModTime - modTime < (ULong)delta) /* need to move nextModTime further. */
+ {
+ video->nextModTime += ((delta - video->nextModTime + modTime)); /* empirical formula */
+ }
+#endif
+ /****************************************************/
+
+ /* map frame no.to tick from modTimeRef */
+ /*frameTick = (frameNum[i]*vol[i]->timeIncrementResolution) ;
+ frameTick = (UInt)((frameTick + (encParams->LayerFrameRate[i]/2))/encParams->LayerFrameRate[i]);*/
+ /* 11/16/01, change frameTick to be the closest tick from the actual modTime */
+ /* 12/12/02, add (double) to prevent large number wrap-around */
+ frameTick = (Int)(((double)(modTime - modTimeRef) * vol[i]->timeIncrementResolution + 500) / 1000);
+
+ /* find timeIncrement to be put in the bitstream */
+ /* refTick is second boundary reference. */
+ vol[i]->timeIncrement = frameTick - video->refTick[i];
+
+
+ vol[i]->moduloTimeBase = 0;
+ while (vol[i]->timeIncrement >= vol[i]->timeIncrementResolution)
+ {
+ vol[i]->timeIncrement -= vol[i]->timeIncrementResolution;
+ vol[i]->moduloTimeBase++;
+ /* do not update refTick and modTimeRef yet, do it after encoding!! */
+ }
+
+ if (video->relLayerCodeTime[i] <= 0) /* no skipping */
+ {
+ encodeVop = 1;
+ video->currLayer = *nLayer = i;
+ video->relLayerCodeTime[i] += 1000;
+
+ /* takes care of more dropped frame than expected */
+ extra_skip = -1;
+ frameInc = (frameNum[i] - video->prevFrameNum[i]);
+ extra_skip += frameInc;
+
+ if (extra_skip > 0)
+ { /* update rc->Nr, rc->B, (rc->Rr)*/
+ video->nextEncIVop -= extra_skip;
+ video->numVopsInGOP += extra_skip;
+ if (encParams->RC_Type != CONSTANT_Q)
+ {
+ RC_UpdateBuffer(video, i, extra_skip);
+ }
+ }
+
+ }
+ /* update frame no. */
+ video->prevFrameNum[i] = frameNum[i];
+
+ /* go through all lower layer */
+ for (i = (numLayers - 2); i >= 0; i--)
+ {
+
+ video->relLayerCodeTime[i] -= 1000;
+
+ /* find timeIncrement to be put in the bitstream */
+ vol[i]->timeIncrement = frameTick - video->refTick[i];
+
+ if (video->relLayerCodeTime[i] <= 0) /* time to encode base */
+ {
+ /* 12/27/00 */
+ encodeVop = 1;
+ video->currLayer = *nLayer = i;
+ video->relLayerCodeTime[i] +=
+ (Int)((1000.0 * encParams->LayerFrameRate[numLayers-1]) / encParams->LayerFrameRate[i]);
+
+ vol[i]->moduloTimeBase = 0;
+ while (vol[i]->timeIncrement >= vol[i]->timeIncrementResolution)
+ {
+ vol[i]->timeIncrement -= vol[i]->timeIncrementResolution;
+ vol[i]->moduloTimeBase++;
+ /* do not update refTick and modTimeRef yet, do it after encoding!! */
+ }
+
+ /* takes care of more dropped frame than expected */
+ frameNum[i] = (UInt)((frameModTime - modTimeRef) * encParams->LayerFrameRate[i] + 500) / 1000;
+ if (video->volInitialize[i])
+ video->prevFrameNum[i] = frameNum[i] - 1;
+
+ extra_skip = -1;
+ frameInc = (frameNum[i] - video->prevFrameNum[i]);
+ extra_skip += frameInc;
+
+ if (extra_skip > 0)
+ { /* update rc->Nr, rc->B, (rc->Rr)*/
+ if (encParams->RC_Type != CONSTANT_Q)
+ {
+ RC_UpdateBuffer(video, i, extra_skip);
+ }
+ }
+ /* update frame no. */
+ video->prevFrameNum[i] = frameNum[i];
+ }
+ }
+
+#ifdef _PRINT_STAT
+ if (encodeVop)
+ printf(" TI: %d ", vol[*nLayer]->timeIncrement);
+#endif
+
+ return encodeVop;
+}
+
+/* ======================================================================== */
+/* Function : DetermineVopType */
+/* Date : 06/02/2001 */
+/* Purpose : The name says it all. */
+/* In/out : */
+/* Return : void . */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+void DetermineVopType(VideoEncData *video, Int currLayer)
+{
+ VideoEncParams *encParams = video->encParams;
+// Vol *currVol = video->vol[currLayer];
+
+ if (encParams->IntraPeriod == 0) /* I-VOPs only */
+ {
+ if (video->currLayer > 0)
+ video->currVop->predictionType = P_VOP;
+ else
+ {
+ video->currVop->predictionType = I_VOP;
+ if (video->numVopsInGOP >= 132)
+ video->numVopsInGOP = 0;
+ }
+ }
+ else if (encParams->IntraPeriod == -1) /* IPPPPP... */
+ {
+
+ /* maintain frame type if previous frame is pre-skipped, 06/02/2001 */
+ if (encParams->RC_Type == CONSTANT_Q || video->rc[currLayer]->skip_next_frame != -1)
+ video->currVop->predictionType = P_VOP;
+
+ if (video->currLayer == 0)
+ {
+ if (/*video->numVopsInGOP>=132 || */video->volInitialize[currLayer])
+ {
+ video->currVop->predictionType = I_VOP;
+ video->numVopsInGOP = 0; /* force INTRA update every 132 base frames*/
+ video->nextEncIVop = 1;
+ }
+ else if (video->nextEncIVop == 0 || video->currVop->predictionType == I_VOP)
+ {
+ video->numVopsInGOP = 0;
+ video->nextEncIVop = 1;
+ }
+ }
+ }
+ else /* IntraPeriod>0 : IPPPPPIPPPPPI... */
+ {
+
+ /* maintain frame type if previous frame is pre-skipped, 06/02/2001 */
+ if (encParams->RC_Type == CONSTANT_Q || video->rc[currLayer]->skip_next_frame != -1)
+ video->currVop->predictionType = P_VOP;
+
+ if (currLayer == 0)
+ {
+ if (video->nextEncIVop <= 0 || video->currVop->predictionType == I_VOP)
+ {
+ video->nextEncIVop = encParams->IntraPeriod;
+ video->currVop->predictionType = I_VOP;
+ video->numVopsInGOP = 0;
+ }
+ }
+ }
+
+ return ;
+}
+
+/* ======================================================================== */
+/* Function : UpdateSkipNextFrame */
+/* Date : 06/02/2001 */
+/* Purpose : From rate control frame skipping decision, update timing
+ related parameters. */
+/* In/out : */
+/* Return : Current coded layer. */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+Int UpdateSkipNextFrame(VideoEncData *video, ULong *modTime, Int *size, PV_STATUS status)
+{
+ Int currLayer = video->currLayer;
+ Int nLayer = currLayer;
+ VideoEncParams *encParams = video->encParams;
+ Int numLayers = encParams->nLayers;
+ Vol *currVol = video->vol[currLayer];
+ Vol **vol = video->vol;
+ Int num_skip, extra_skip;
+ Int i;
+ UInt newRefTick, deltaModTime;
+ UInt temp;
+
+ if (encParams->RC_Type != CONSTANT_Q)
+ {
+ if (video->volInitialize[0] && currLayer == 0) /* always encode the first frame */
+ {
+ RC_ResetSkipNextFrame(video, currLayer);
+ //return currLayer; 09/15/05
+ }
+ else
+ {
+ if (RC_GetSkipNextFrame(video, currLayer) < 0 || status == PV_END_OF_BUF) /* Skip Current Frame */
+ {
+
+#ifdef _PRINT_STAT
+ printf("Skip current frame");
+#endif
+ currVol->moduloTimeBase = currVol->prevModuloTimeBase;
+
+ /*********************/
+ /* prepare to return */
+ /*********************/
+ *size = 0; /* Set Bitstream buffer to zero */
+
+ /* Determine nLayer and modTime for next encode */
+
+ *modTime = video->nextModTime;
+ nLayer = -1;
+
+ return nLayer; /* return immediately without updating RefTick & modTimeRef */
+ /* If I-VOP was attempted, then ensure next base is I-VOP */
+ /*if((encParams->IntraPeriod>0) && (video->currVop->predictionType == I_VOP))
+ video->nextEncIVop = 0; commented out by 06/05/01 */
+
+ }
+ else if ((num_skip = RC_GetSkipNextFrame(video, currLayer)) > 0)
+ {
+
+#ifdef _PRINT_STAT
+ printf("Skip next %d frames", num_skip);
+#endif
+ /* to keep the Nr of enh layer the same */
+ /* adjust relLayerCodeTime only, do not adjust layerCodeTime[numLayers-1] */
+ extra_skip = 0;
+ for (i = 0; i < currLayer; i++)
+ {
+ if (video->relLayerCodeTime[i] <= 1000)
+ {
+ extra_skip = 1;
+ break;
+ }
+ }
+
+ for (i = currLayer; i < numLayers; i++)
+ {
+ video->relLayerCodeTime[i] += (num_skip + extra_skip) *
+ ((Int)((1000.0 * encParams->LayerFrameRate[numLayers-1]) / encParams->LayerFrameRate[i]));
+ }
+ }
+ }/* first frame */
+ }
+ /***** current frame is encoded, now update refTick ******/
+
+ video->refTick[currLayer] += vol[currLayer]->prevModuloTimeBase * vol[currLayer]->timeIncrementResolution;
+
+ /* Reset layerCodeTime every I-VOP to prevent overflow */
+ if (currLayer == 0)
+ {
+ /* 12/12/02, fix for weird targer frame rate of 9.99 fps or 3.33 fps */
+ if (((encParams->IntraPeriod != 0) /*&& (video->currVop->predictionType==I_VOP)*/) ||
+ ((encParams->IntraPeriod == 0) && (video->numVopsInGOP == 0)))
+ {
+ newRefTick = video->refTick[0];
+
+ for (i = 1; i < numLayers; i++)
+ {
+ if (video->refTick[i] < newRefTick)
+ newRefTick = video->refTick[i];
+ }
+
+ /* check to make sure that the update is integer multiple of frame number */
+ /* how many msec elapsed from last modTimeRef */
+ deltaModTime = (newRefTick / vol[0]->timeIncrementResolution) * 1000;
+
+ for (i = numLayers - 1; i >= 0; i--)
+ {
+ temp = (UInt)(deltaModTime * encParams->LayerFrameRate[i]); /* 12/12/02 */
+ if (temp % 1000)
+ newRefTick = 0;
+
+ }
+ if (newRefTick > 0)
+ {
+ video->modTimeRef += deltaModTime;
+ for (i = numLayers - 1; i >= 0; i--)
+ {
+ video->prevFrameNum[i] -= (UInt)(deltaModTime * encParams->LayerFrameRate[i]) / 1000;
+ video->refTick[i] -= newRefTick;
+ }
+ }
+ }
+ }
+
+ *modTime = video->nextModTime;
+
+ return nLayer;
+}
+
+
+#ifndef ORIGINAL_VERSION
+
+/* ======================================================================== */
+/* Function : SetProfile_BufferSize */
+/* Date : 04/08/2002 */
+/* Purpose : Set profile and video buffer size, copied from Jim's code */
+/* in PVInitVideoEncoder(.), since we have different places */
+/* to reset profile and video buffer size */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+Bool SetProfile_BufferSize(VideoEncData *video, float delay, Int bInitialized)
+{
+ Int i, j, start, end;
+// Int BaseMBsPerSec = 0, EnhMBsPerSec = 0;
+ Int nTotalMB = 0;
+ Int idx, temp_w, temp_h, max = 0, max_width, max_height;
+
+ Int nLayers = video->encParams->nLayers; /* Number of Layers to be encoded */
+
+ Int total_bitrate = 0, base_bitrate;
+ Int total_packet_size = 0, base_packet_size;
+ Int total_MBsPerSec = 0, base_MBsPerSec;
+ Int total_VBV_size = 0, base_VBV_size, enhance_VBV_size = 0;
+ float total_framerate, base_framerate;
+ float upper_bound_ratio;
+ Int bFound = 0;
+ Int k = 0, width16, height16, index;
+ Int lowest_level;
+
+#define MIN_BUFF 16000 /* 16k minimum buffer size */
+#define BUFF_CONST 2.0 /* 2000ms */
+#define UPPER_BOUND_RATIO 8.54 /* upper_bound = 1.4*(1.1+bound/10)*bitrate/framerate */
+
+#define QCIF_WIDTH 176
+#define QCIF_HEIGHT 144
+
+ index = video->encParams->profile_table_index;
+
+ /* Calculate "nTotalMB" */
+ /* Find the maximum width*height for memory allocation of the VOPs */
+ for (idx = 0; idx < nLayers; idx++)
+ {
+ temp_w = video->encParams->LayerWidth[idx];
+ temp_h = video->encParams->LayerHeight[idx];
+
+ if ((temp_w*temp_h) > max)
+ {
+ max = temp_w * temp_h;
+ max_width = temp_w;
+ max_height = temp_h;
+ nTotalMB = ((max_width + 15) >> 4) * ((max_height + 15) >> 4);
+ }
+ }
+ upper_bound_ratio = (video->encParams->RC_Type == CBR_LOWDELAY ? (float)5.0 : (float)UPPER_BOUND_RATIO);
+
+
+ /* Get the basic information: bitrate, packet_size, MBs/s and VBV_size */
+ base_bitrate = video->encParams->LayerBitRate[0];
+ if (video->encParams->LayerMaxBitRate[0] != 0) /* video->encParams->LayerMaxBitRate[0] == 0 means it has not been set */
+ {
+ base_bitrate = PV_MAX(base_bitrate, video->encParams->LayerMaxBitRate[0]);
+ }
+ else /* if the max is not set, set it to the specified profile/level */
+ {
+ video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[index];
+ }
+
+ base_framerate = video->encParams->LayerFrameRate[0];
+ if (video->encParams->LayerMaxFrameRate[0] != 0)
+ {
+ base_framerate = PV_MAX(base_framerate, video->encParams->LayerMaxFrameRate[0]);
+ }
+ else /* if the max is not set, set it to the specified profile/level */
+ {
+ video->encParams->LayerMaxFrameRate[0] = (float)profile_level_max_mbsPerSec[index] / nTotalMB;
+ }
+
+ base_packet_size = video->encParams->ResyncPacketsize;
+ base_MBsPerSec = (Int)(base_framerate * nTotalMB);
+ base_VBV_size = PV_MAX((Int)(base_bitrate * delay),
+ (Int)(upper_bound_ratio * base_bitrate / base_framerate));
+ base_VBV_size = PV_MAX(base_VBV_size, MIN_BUFF);
+
+ /* if the buffer is larger than maximum buffer size, we'll clip it */
+ if (base_VBV_size > profile_level_max_VBV_size[5])
+ base_VBV_size = profile_level_max_VBV_size[5];
+
+
+ /* Check if the buffer exceeds the maximum buffer size given the maximum profile and level */
+ if (nLayers == 1 && base_VBV_size > profile_level_max_VBV_size[index])
+ return FALSE;
+
+
+ if (nLayers == 2)
+ {
+ total_bitrate = video->encParams->LayerBitRate[1];
+ if (video->encParams->LayerMaxBitRate[1] != 0)
+ {
+ total_bitrate = PV_MIN(total_bitrate, video->encParams->LayerMaxBitRate[1]);
+ }
+ else /* if the max is not set, set it to the specified profile/level */
+ {
+ video->encParams->LayerMaxBitRate[1] = scalable_profile_level_max_bitrate[index];
+ }
+
+ total_framerate = video->encParams->LayerFrameRate[1];
+ if (video->encParams->LayerMaxFrameRate[1] != 0)
+ {
+ total_framerate = PV_MIN(total_framerate, video->encParams->LayerMaxFrameRate[1]);
+ }
+ else /* if the max is not set, set it to the specified profile/level */
+ {
+ video->encParams->LayerMaxFrameRate[1] = (float)scalable_profile_level_max_mbsPerSec[index] / nTotalMB;
+ }
+
+ total_packet_size = video->encParams->ResyncPacketsize;
+ total_MBsPerSec = (Int)(total_framerate * nTotalMB);
+
+ enhance_VBV_size = PV_MAX((Int)((total_bitrate - base_bitrate) * delay),
+ (Int)(upper_bound_ratio * (total_bitrate - base_bitrate) / (total_framerate - base_framerate)));
+ enhance_VBV_size = PV_MAX(enhance_VBV_size, MIN_BUFF);
+
+ total_VBV_size = base_VBV_size + enhance_VBV_size;
+
+ /* if the buffer is larger than maximum buffer size, we'll clip it */
+ if (total_VBV_size > scalable_profile_level_max_VBV_size[6])
+ {
+ total_VBV_size = scalable_profile_level_max_VBV_size[6];
+ enhance_VBV_size = total_VBV_size - base_VBV_size;
+ }
+
+ /* Check if the buffer exceeds the maximum buffer size given the maximum profile and level */
+ if (total_VBV_size > scalable_profile_level_max_VBV_size[index])
+ return FALSE;
+ }
+
+
+ if (!bInitialized) /* Has been initialized --> profile @ level has been figured out! */
+ {
+ video->encParams->BufferSize[0] = base_VBV_size;
+ if (nLayers > 1)
+ video->encParams->BufferSize[1] = enhance_VBV_size;
+
+ return PV_TRUE;
+ }
+
+
+ /* Profile @ level determination */
+ if (nLayers == 1)
+ {
+ /* BASE ONLY : Simple Profile(SP) Or Core Profile(CP) */
+ if (base_bitrate > profile_level_max_bitrate[index] ||
+ base_packet_size > profile_level_max_packet_size[index] ||
+ base_MBsPerSec > profile_level_max_mbsPerSec[index] ||
+ base_VBV_size > profile_level_max_VBV_size[index])
+
+ return PV_FALSE; /* Beyond the bound of Core Profile @ Level2 */
+
+ /* For H263/Short header, determine k*16384 */
+ width16 = ((video->encParams->LayerWidth[0] + 15) >> 4) << 4;
+ height16 = ((video->encParams->LayerHeight[0] + 15) >> 4) << 4;
+ if (video->encParams->H263_Enabled)
+ {
+ k = 4;
+ if (width16 == 2*QCIF_WIDTH && height16 == 2*QCIF_HEIGHT) /* CIF */
+ k = 16;
+
+ else if (width16 == 4*QCIF_WIDTH && height16 == 4*QCIF_HEIGHT) /* 4CIF */
+ k = 32;
+
+ else if (width16 == 8*QCIF_WIDTH && height16 == 8*QCIF_HEIGHT) /* 16CIF */
+ k = 64;
+
+ video->encParams->maxFrameSize = k * 16384;
+
+ /* Make sure the buffer size is limited to the top profile and level: the Core profile and level 2 */
+ if (base_VBV_size > (Int)(k*16384 + 4*(float)profile_level_max_bitrate[5]*1001.0 / 30000.0))
+ base_VBV_size = (Int)(k * 16384 + 4 * (float)profile_level_max_bitrate[5] * 1001.0 / 30000.0);
+
+ if (base_VBV_size > (Int)(k*16384 + 4*(float)profile_level_max_bitrate[index]*1001.0 / 30000.0))
+ return PV_FALSE;
+ }
+
+ /* Search the appropriate profile@level index */
+ if (!video->encParams->H263_Enabled &&
+ (video->encParams->IntraDCVlcThr != 0 || video->encParams->SearchRange > 16))
+ {
+ lowest_level = 1; /* cannot allow SPL0 */
+ }
+ else
+ {
+ lowest_level = 0; /* SPL0 */
+ }
+
+ for (i = lowest_level; i <= index; i++)
+ {
+ if (i != 4 && /* skip Core Profile@Level1 because the parameters in it are smaller than those in Simple Profile@Level3 */
+ base_bitrate <= profile_level_max_bitrate[i] &&
+ base_packet_size <= profile_level_max_packet_size[i] &&
+ base_MBsPerSec <= profile_level_max_mbsPerSec[i] &&
+ base_VBV_size <= (video->encParams->H263_Enabled ? (Int)(k*16384 + 4*(float)profile_level_max_bitrate[i]*1001.0 / 30000.0) :
+ profile_level_max_VBV_size[i]))
+ break;
+ }
+ if (i > index) return PV_FALSE; /* Nothing found!! */
+
+ /* Found out the actual profile @ level : index "i" */
+ if (i == 0)
+ {
+ /* For Simple Profile @ Level 0, we need to do one more check: image size <= QCIF */
+ if (width16 > QCIF_WIDTH || height16 > QCIF_HEIGHT)
+ i = 1; /* image size > QCIF, then set SP level1 */
+ }
+
+ video->encParams->ProfileLevel[0] = profile_level_code[i];
+ video->encParams->BufferSize[0] = base_VBV_size;
+
+ if (video->encParams->LayerMaxBitRate[0] == 0)
+ video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[i];
+
+ if (video->encParams->LayerMaxFrameRate[0] == 0)
+ video->encParams->LayerMaxFrameRate[0] = PV_MIN(30, (float)profile_level_max_mbsPerSec[i] / nTotalMB);
+
+ /* For H263/Short header, one special constraint for VBV buffer size */
+ if (video->encParams->H263_Enabled)
+ video->encParams->BufferSize[0] = (Int)(k * 16384 + 4 * (float)profile_level_max_bitrate[i] * 1001.0 / 30000.0);
+
+ }
+ else
+ {
+ /* SCALABALE MODE: Simple Scalable Profile(SSP) Or Core Scalable Profile(CSP) */
+
+ if (total_bitrate > scalable_profile_level_max_bitrate[index] ||
+ total_packet_size > scalable_profile_level_max_packet_size[index] ||
+ total_MBsPerSec > scalable_profile_level_max_mbsPerSec[index] ||
+ total_VBV_size > scalable_profile_level_max_VBV_size[index])
+
+ return PV_FALSE; /* Beyond given profile and level */
+
+ /* One-time check: Simple Scalable Profile or Core Scalable Profile */
+ if (total_bitrate <= scalable_profile_level_max_bitrate[2] &&
+ total_packet_size <= scalable_profile_level_max_packet_size[2] &&
+ total_MBsPerSec <= scalable_profile_level_max_mbsPerSec[2] &&
+ total_VBV_size <= scalable_profile_level_max_VBV_size[2])
+
+ {
+ start = 0;
+ end = index;
+ }
+
+ else
+ {
+ start = 4;
+ end = index;
+ }
+
+
+ /* Search the scalable profile */
+ for (i = start; i <= end; i++)
+ {
+ if (total_bitrate <= scalable_profile_level_max_bitrate[i] &&
+ total_packet_size <= scalable_profile_level_max_packet_size[i] &&
+ total_MBsPerSec <= scalable_profile_level_max_mbsPerSec[i] &&
+ total_VBV_size <= scalable_profile_level_max_VBV_size[i])
+
+ break;
+ }
+ if (i > end) return PV_FALSE;
+
+ /* Search the base profile */
+ if (i == 0)
+ {
+ j = 0;
+ bFound = 1;
+ }
+ else bFound = 0;
+
+ for (j = start; !bFound && j <= i; j++)
+ {
+ if (base_bitrate <= profile_level_max_bitrate[j] &&
+ base_packet_size <= profile_level_max_packet_size[j] &&
+ base_MBsPerSec <= profile_level_max_mbsPerSec[j] &&
+ base_VBV_size <= profile_level_max_VBV_size[j])
+
+ {
+ bFound = 1;
+ break;
+ }
+ }
+
+ if (!bFound) // && start == 4)
+ return PV_FALSE; /* mis-match in the profiles between base layer and enhancement layer */
+
+ /* j for base layer, i for enhancement layer */
+ video->encParams->ProfileLevel[0] = profile_level_code[j];
+ video->encParams->ProfileLevel[1] = scalable_profile_level_code[i];
+ video->encParams->BufferSize[0] = base_VBV_size;
+ video->encParams->BufferSize[1] = enhance_VBV_size;
+
+ if (video->encParams->LayerMaxBitRate[0] == 0)
+ video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[j];
+
+ if (video->encParams->LayerMaxBitRate[1] == 0)
+ video->encParams->LayerMaxBitRate[1] = scalable_profile_level_max_bitrate[i];
+
+ if (video->encParams->LayerMaxFrameRate[0] == 0)
+ video->encParams->LayerMaxFrameRate[0] = PV_MIN(30, (float)profile_level_max_mbsPerSec[j] / nTotalMB);
+
+ if (video->encParams->LayerMaxFrameRate[1] == 0)
+ video->encParams->LayerMaxFrameRate[1] = PV_MIN(30, (float)scalable_profile_level_max_mbsPerSec[i] / nTotalMB);
+
+
+ } /* end of: if(nLayers == 1) */
+
+
+ if (!video->encParams->H263_Enabled && (video->encParams->ProfileLevel[0] == 0x08)) /* SPL0 restriction*/
+ {
+ /* PV only allow frame-based rate control, no QP change from one MB to another
+ if(video->encParams->ACDCPrediction == TRUE && MB-based rate control)
+ return PV_FALSE */
+ }
+
+ return PV_TRUE;
+}
+
+#endif /* #ifndef ORIGINAL_VERSION */
+
+
+
diff --git a/media/codecs/m4v_h263/enc/src/mp4enc_lib.h b/media/codecs/m4v_h263/enc/src/mp4enc_lib.h
new file mode 100644
index 0000000..8293576
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/mp4enc_lib.h
@@ -0,0 +1,207 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _MP4ENC_LIB_H_
+#define _MP4ENC_LIB_H_
+
+#include "mp4def.h" // typedef
+#include "mp4lib_int.h" // main video structure
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /* defined in vop.c */
+ PV_STATUS EncodeVop(VideoEncData *video);
+ PV_STATUS EncodeSlice(VideoEncData *video);
+ PV_STATUS EncodeVideoPacketHeader(VideoEncData *video, int MB_number,
+ int quant_scale, Int insert);
+#ifdef ALLOW_VOP_NOT_CODED
+ PV_STATUS EncodeVopNotCoded(VideoEncData *video, UChar *bstream, Int *size, ULong modTime);
+#endif
+
+ /* defined in combined_decode.c */
+ PV_STATUS EncodeFrameCombinedMode(VideoEncData *video);
+ PV_STATUS EncodeSliceCombinedMode(VideoEncData *video);
+
+ /* defined in datapart_decode.c */
+ PV_STATUS EncodeFrameDataPartMode(VideoEncData *video);
+ PV_STATUS EncodeSliceDataPartMode(VideoEncData *video);
+
+ /* defined in fastcodeMB.c */
+
+//void m4v_memset(void *adr_dst, uint8 value, uint32 size);
+
+ PV_STATUS CodeMB_H263(VideoEncData *video, approxDCT *function, Int offsetQP, Int ncoefblck[]);
+#ifndef NO_MPEG_QUANT
+ PV_STATUS CodeMB_MPEG(VideoEncData *video, approxDCT *function, Int offsetQP, Int ncoefblck[]);
+#endif
+ Int getBlockSAV(Short block[]);
+ Int Sad8x8(UChar *rec, UChar *prev, Int lx);
+ Int getBlockSum(UChar *rec, Int lx);
+
+ /* defined in dct.c */
+ void blockIdct(Short *block);
+ void blockIdct_SSE(Short *input);
+ void BlockDCTEnc(Short *blockData, Short *blockCoeff);
+
+ /*---- FastQuant.c -----*/
+ Int cal_dc_scalerENC(Int QP, Int type) ;
+ Int BlockQuantDequantH263Inter(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dummy, UChar shortHeader);
+
+ Int BlockQuantDequantH263Intra(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int dctMode, Int comp, Int dc_scaler, UChar shortHeader);
+
+ Int BlockQuantDequantH263DCInter(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar *bitmaprow, UInt *bitmapzz, Int dummy, UChar shortHeader);
+
+ Int BlockQuantDequantH263DCIntra(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam,
+ UChar *bitmaprow, UInt *bitmapzz, Int dc_scaler, UChar shortHeader);
+
+#ifndef NO_MPEG_QUANT
+ Int BlockQuantDequantMPEGInter(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int DctMode, Int comp, Int dc_scaler);
+
+ Int BlockQuantDequantMPEGIntra(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz,
+ Int DctMode, Int comp, Int dc_scaler);
+
+ Int BlockQuantDequantMPEGDCInter(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, Int dummy);
+
+ Int BlockQuantDequantMPEGDCIntra(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat,
+ UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, Int dc_scaler);
+#endif
+
+ /*---- FastIDCT.c -----*/
+ void BlockIDCTMotionComp(Short *block, UChar *bitmapcol, UChar bitmaprow,
+ Int dctMode, UChar *rec, UChar *prev, Int lx_intra_zeroMV);
+
+
+ /* defined in motion_comp.c */
+ void getMotionCompensatedMB(VideoEncData *video, Int ind_x, Int ind_y, Int offset);
+ void EncPrediction_INTER(Int xpred, Int ypred, UChar *c_prev, UChar *c_rec,
+ Int width, Int round1);
+
+ void EncPrediction_INTER4V(Int xpred, Int ypred, MOT *mot, UChar *c_prev, UChar *c_rec,
+ Int width, Int round1);
+
+ void EncPrediction_Chrom(Int xpred, Int ypred, UChar *cu_prev, UChar *cv_prev, UChar *cu_rec,
+ UChar *cv_rec, Int pitch_uv, Int width_uv, Int height_uv, Int round1);
+
+ void get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v,
+ Short mb[6][64], Int width, Int width_uv);
+
+ void PutSkippedBlock(UChar *rec, UChar *prev, Int lx);
+
+ /* defined in motion_est.c */
+ void MotionEstimation(VideoEncData *video);
+#ifdef HTFM
+ void InitHTFM(VideoEncData *video, HTFM_Stat *htfm_stat, double *newvar, Int *collect);
+ void UpdateHTFM(VideoEncData *video, double *newvar, double *exp_lamda, HTFM_Stat *htfm_stat);
+#endif
+
+ /* defined in ME_utils.c */
+ void ChooseMode_C(UChar *Mode, UChar *cur, Int lx, Int min_SAD);
+ void ChooseMode_MMX(UChar *Mode, UChar *cur, Int lx, Int min_SAD);
+ void GetHalfPelMBRegion_C(UChar *cand, UChar *hmem, Int lx);
+ void GetHalfPelMBRegion_SSE(UChar *cand, UChar *hmem, Int lx);
+ void GetHalfPelBlkRegion(UChar *cand, UChar *hmem, Int lx);
+ void PaddingEdge(Vop *padVop);
+ void ComputeMBSum_C(UChar *cur, Int lx, MOT *mot_mb);
+ void ComputeMBSum_MMX(UChar *cur, Int lx, MOT *mot_mb);
+ void ComputeMBSum_SSE(UChar *cur, Int lx, MOT *mot_mb);
+ void GetHalfPelMBRegionPadding(UChar *ncand, UChar *hmem, Int lx, Int *reptl);
+ void GetHalfPelBlkRegionPadding(UChar *ncand, UChar *hmem, Int lx, Int *reptl);
+
+ /* defined in findhalfpel.c */
+ void FindHalfPelMB(VideoEncData *video, UChar *cur, MOT *mot, UChar *ncand,
+ Int xpos, Int ypos, Int *xhmin, Int *yhmin, Int hp_guess);
+ Int FindHalfPelBlk(VideoEncData *video, UChar *cur, MOT *mot, Int sad16, UChar *ncand8[],
+ UChar *mode, Int xpos, Int ypos, Int *xhmin, Int *yhmin, UChar *hp_mem);
+
+
+ /* defined in sad.c */
+ Int SAD_MB_HalfPel_Cxhyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HalfPel_Cyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HalfPel_Cxh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HalfPel_MMX(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HalfPel_SSE(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_Blk_HalfPel_C(UChar *ref, UChar *blk, Int dmin, Int lx, Int rx, Int xh, Int yh, void *extra_info);
+ Int SAD_Blk_HalfPel_MMX(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+ Int SAD_Blk_HalfPel_SSE(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+ Int SAD_Macroblock_C(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_Macroblock_MMX(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_Macroblock_SSE(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_Block_C(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+ Int SAD_Block_MMX(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+ Int SAD_Block_SSE(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+
+#ifdef HTFM /* Hypothesis Testing Fast Matching */
+ Int SAD_MB_HP_HTFM_Collectxhyh(UChar *ref, UChar *blk, Int dmin_x, void *extra_info);
+ Int SAD_MB_HP_HTFM_Collectyh(UChar *ref, UChar *blk, Int dmin_x, void *extra_info);
+ Int SAD_MB_HP_HTFM_Collectxh(UChar *ref, UChar *blk, Int dmin_x, void *extra_info);
+ Int SAD_MB_HP_HTFMxhyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HP_HTFMyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HP_HTFMxh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HTFM_Collect(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int SAD_MB_HTFM(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+#endif
+ /* on-the-fly padding */
+ Int SAD_Blk_PADDING(UChar *ref, UChar *cur, Int dmin, Int lx, void *extra_info);
+ Int SAD_MB_PADDING(UChar *ref, UChar *cur, Int dmin, Int lx, void *extra_info);
+#ifdef HTFM
+ Int SAD_MB_PADDING_HTFM_Collect(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+ Int SAD_MB_PADDING_HTFM(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+#endif
+
+ /* defined in rate_control.c */
+ /* These are APIs to rate control exposed to core encoder module. */
+ PV_STATUS RC_Initialize(void *video);
+ PV_STATUS RC_VopQPSetting(VideoEncData *video, rateControl *rc[]);
+ PV_STATUS RC_VopUpdateStat(VideoEncData *video, rateControl *rc);
+ PV_STATUS RC_MBQPSetting(VideoEncData *video, rateControl *rc, Int start_packet_header);
+ PV_STATUS RC_MBUpdateStat(VideoEncData *video, rateControl *rc, Int Bi, Int Hi);
+ PV_STATUS RC_Cleanup(rateControl *rc[], Int numLayers);
+
+ Int RC_GetSkipNextFrame(VideoEncData *video, Int currLayer);
+ Int RC_GetRemainingVops(VideoEncData *video, Int currLayer);
+ void RC_ResetSkipNextFrame(VideoEncData *video, Int currLayer);
+ PV_STATUS RC_UpdateBuffer(VideoEncData *video, Int currLayer, Int num_skip);
+ PV_STATUS RC_UpdateBXRCParams(void *input);
+
+
+ /* defined in vlc_encode.c */
+ void MBVlcEncodeDataPar_I_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr);
+ void MBVlcEncodeDataPar_P_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr);
+ void MBVlcEncodeCombined_I_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr);
+ void MBVlcEncodeCombined_P_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr);
+ void BlockCodeCoeff_ShortHeader(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode);
+ void BlockCodeCoeff_RVLC(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode);
+ void BlockCodeCoeff_Normal(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MP4ENC_LIB_H_ */
+
diff --git a/media/codecs/m4v_h263/enc/src/mp4lib_int.h b/media/codecs/m4v_h263/enc/src/mp4lib_int.h
new file mode 100644
index 0000000..b05099c
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/mp4lib_int.h
@@ -0,0 +1,473 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#ifndef _MP4LIB_INT_H_
+#define _MP4LIB_INT_H_
+
+#include "mp4def.h"
+#include "mp4enc_api.h"
+#include "rate_control.h"
+
+/* BitstreamEncVideo will be modified */
+typedef struct tagBitstream
+{
+ Int(*writeVideoPacket)(UChar *buf, Int nbytes_required); /*write video packet out */
+ UChar *bitstreamBuffer; /*buffer to hold one video packet*/
+ Int bufferSize; /*total bitstream buffer size in bytes */
+ Int byteCount; /*how many bytes already encoded*/
+ UInt word; /*hold one word temporarily */
+ Int bitLeft; /*number of bits left in "word" */
+ UChar* overrunBuffer; /* pointer to overrun buffer */
+ Int oBSize; /* length of overrun buffer */
+ struct tagVideoEncData *video;
+} BitstreamEncVideo;
+
+typedef struct tagVOP
+{
+ PIXEL *allChan; /* [yuv]Chan point into this buffer */
+ PIXEL *yChan; /* The Y component */
+ PIXEL *uChan; /* The U component */
+ PIXEL *vChan; /* The V component */
+ Int frame; /* frame number */
+ Int volID; /* Layer number */
+ //Int timeStamp; /* Vop TimeStamp in msec */
+
+ /* Syntax elements copied from VOL (standard) */
+ Int width; /* Width (multiple of 16) */
+ Int height; /* Height (multiple of 16) */
+ Int pitch; /* Pitch (differs from width for UMV case) */
+ Int padded; /* flag whether this frame has been padded */
+
+ /* Actual syntax elements for VOP (standard) */
+ Int predictionType; /* VOP prediction type */
+ Int timeInc; /* VOP time increment (relative to last mtb) */
+ Int vopCoded;
+ Int roundingType;
+ Int intraDCVlcThr;
+ Int quantizer; /* VOP quantizer */
+ Int fcodeForward; /* VOP dynamic range of motion vectors */
+ Int fcodeBackward; /* VOP dynamic range of motion vectors */
+ Int refSelectCode; /* enhancement layer reference select code */
+
+ /* H.263 parameters */
+ Int gobNumber;
+ Int gobFrameID;
+ Int temporalRef; /* temporal reference, roll over at 256 */
+ Int temporalInterval; /* increase every 256 temporalRef */
+
+} Vop;
+
+typedef struct tagVol
+{
+ Int volID; /* VOL identifier (for tracking) */
+ Int shortVideoHeader; /* shortVideoHeader mode */
+ Int GOVStart; /* Insert GOV Header */
+ Int timeIncrementResolution; /* VOL time increment */
+ Int nbitsTimeIncRes; /* number of bits for time increment */
+ Int timeIncrement; /* time increment */
+ Int moduloTimeBase; /* internal decoder clock */
+ Int prevModuloTimeBase; /* in case of pre-frameskip */
+
+ Int fixedVopRate;
+ BitstreamEncVideo *stream; /* library bitstream buffer (input buffer) */
+
+ /* VOL Dimensions */
+ Int width; /* Width */
+ Int height; /* Height */
+
+ /* Error Resilience Flags */
+ Int ResyncMarkerDisable; /* VOL Disable Resynch Markers */
+ Int useReverseVLC; /* VOL reversible VLCs */
+ Int dataPartitioning; /* VOL data partitioning */
+
+ /* Quantization related parameters */
+ Int quantPrecision; /* Quantizer precision */
+ Int quantType; /* MPEG-4 or H.263 Quantization Type */
+
+ /* Added loaded quant mat, 05/22/2000 */
+ Int loadIntraQuantMat; /* Load intra quantization matrix */
+ Int loadNonIntraQuantMat; /* Load nonintra quantization matrix */
+ Int iqmat[64]; /* Intra quant.matrix */
+ Int niqmat[64]; /* Non-intra quant.matrix */
+
+
+ /* Parameters used for scalability */
+ Int scalability; /* VOL scalability (flag) */
+ Int scalType; /* temporal = 0, spatial = 1, both = 2 */
+
+ Int refVolID; /* VOL id of reference VOL */
+ Int refSampDir; /* VOL resol. of ref. VOL */
+ Int horSamp_n; /* VOL hor. resampling of ref. VOL given by */
+ Int horSamp_m; /* sampfac = hor_samp_n/hor_samp_m */
+ Int verSamp_n; /* VOL ver. resampling of ref. VOL given by */
+ Int verSamp_m; /* sampfac = ver_samp_n/ver_samp_m */
+ Int enhancementType; /* VOL type of enhancement layer */
+
+ /* These variables were added since they are used a lot. */
+ Int nMBPerRow, nMBPerCol; /* number of MBs in each row & column */
+ Int nTotalMB;
+ Int nBitsForMBID; /* how many bits required for MB number? */
+
+ /* for short video header */
+ Int nMBinGOB; /* number of MBs in GOB, 05/22/00 */
+ Int nGOBinVop; /* number of GOB in Vop 05/22/00 */
+} Vol;
+
+typedef struct tagMacroBlock
+{
+ Int mb_x; /* X coordinate */
+ Int mb_y; /* Y coordinate */
+ Short block[9][64]; /* 4-Y, U and V blocks , and AAN Scale*/
+} MacroBlock;
+
+typedef struct tagRunLevelBlock
+{
+ Int run[64]; /* Runlength */
+ Int level[64]; /* Abs(level) */
+ Int s[64]; /* sign level */
+} RunLevelBlock;
+
+typedef struct tagHeaderInfoDecVideo
+{
+ UChar *Mode; /* Modes INTRA/INTER/etc. */
+ UChar *CBP; /* MCBPC/CBPY stuff */
+} HeaderInfoEncVideo;
+
+typedef Short typeDCStore[6]; /* ACDC */
+typedef Short typeDCACStore[4][8];
+
+typedef struct tagMOT
+{
+ Int x; /* half-pel resolution x component */
+ Int y; /* half-pel resolution y component */
+ Int sad; /* SAD */
+} MOT;
+
+typedef struct tagHintTrackInfo
+{
+ UChar MTB;
+ UChar LayerID;
+ UChar CodeType;
+ UChar RefSelCode;
+
+} HintTrackInfo;
+
+
+typedef struct tagVideoEncParams
+{
+ //Int Width; /* Input Width */
+ //Int Height; /* Input Height */
+ //float FrameRate; /* Input Frame Rate */
+ UInt TimeIncrementRes; /* timeIncrementRes */
+
+ /*VOL Parameters */
+ Int nLayers;
+ Int LayerWidth[4]; /* Encoded Width */
+ Int LayerHeight[4]; /* Encoded Height */
+ float LayerFrameRate[4]; /* Encoded Frame Rate */
+ Int LayerBitRate[4]; /* Encoded BitRate */
+ Int LayerMaxBitRate[4]; /* Maximum Encoded BitRate */
+ float LayerMaxFrameRate[4]; /* Maximum Encoded Frame Rate */
+ Int LayerMaxMbsPerSec[4]; /* Maximum mbs per second, according to the specified profile and level */
+ Int LayerMaxBufferSize[4]; /* Maximum buffer size, according to the specified profile and level */
+
+ Bool ResyncMarkerDisable; /* Disable Resync Marker */
+ Bool DataPartitioning; /* Base Layer Data Partitioning */
+ Bool ReversibleVLC; /* RVLC when Data Partitioning */
+ Bool ACDCPrediction; /* AC/DC Prediction */
+ Int QuantType[4]; /* H263, MPEG2 */
+ Int InitQuantBvop[4];
+ Int InitQuantPvop[4];
+ Int InitQuantIvop[4];
+ Int ResyncPacketsize;
+
+ Int RoundingType;
+ Int IntraDCVlcThr;
+
+ /* Rate Control Parameters */
+ MP4RateControlType RC_Type; /*Constant Q, M4 constantRate, VM5+, M4RC,MPEG2TM5 */
+
+ /* Intra Refresh Parameters */
+ Int IntraPeriod; /* Intra update period */
+ Int Refresh; /* Number of MBs refresh in each frame */
+ /* Other Parameters */
+ Bool SceneChange_Det; /* scene change detection */
+ Bool FineFrameSkip_Enabled; /* src rate resolution frame skipping */
+ Bool VBR_Enabled; /* VBR rate control */
+ Bool NoFrameSkip_Enabled; /* do not allow frame skip */
+ Bool NoPreSkip_Enabled; /* do not allow pre-skip */
+
+ Bool H263_Enabled; /* H263 Short Header */
+ Bool GOV_Enabled; /* GOV Header Enabled */
+ Bool SequenceStartCode; /* This probably should be removed */
+ Bool FullSearch_Enabled; /* full-pel exhaustive search motion estimation */
+ Bool HalfPel_Enabled; /* Turn Halfpel ME on or off */
+ Bool MV8x8_Enabled; /* Enable 8x8 motion vectors */
+ Bool RD_opt_Enabled; /* Enable operational R-D optimization */
+ Int GOB_Header_Interval; /* Enable encoding GOB header in H263_WITH_ERR_RES and SHORT_HERDER_WITH_ERR_RES */
+ Int SearchRange; /* Search range for 16x16 motion vector */
+ Int MemoryUsage; /* Amount of memory allocated */
+ Int GetVolHeader[2]; /* Flag to check if Vol Header has been retrieved */
+ Int BufferSize[2]; /* Buffer Size for Base and Enhance Layers */
+ Int ProfileLevel[2]; /* Profile and Level for encoding purposes */
+ float VBV_delay; /* VBV buffer size in the form of delay */
+ Int maxFrameSize; /* maximum frame size(bits) for H263/Short header mode, k*16384 */
+ Int profile_table_index; /* index for profile and level tables given the specified profile and level */
+
+} VideoEncParams;
+
+/* platform dependent functions */
+typedef struct tagFuncPtr
+{
+// Int (*SAD_MB_HalfPel)(UChar *ref,UChar *blk,Int dmin_lx,Int xh,Int yh,void *extra_info);
+ Int(*SAD_MB_HalfPel[4])(UChar*, UChar*, Int, void *);
+ Int(*SAD_Blk_HalfPel)(UChar *ref, UChar *blk, Int dmin, Int lx, Int rx, Int xh, Int yh, void *extra_info);
+ Int(*SAD_Macroblock)(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info);
+ Int(*SAD_Block)(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info);
+ Int(*SAD_MB_PADDING)(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); /*, 4/21/01 */
+ void (*ComputeMBSum)(UChar *cur, Int lx, MOT *mot_mb);
+ void (*ChooseMode)(UChar *Mode, UChar *cur, Int lx, Int min_SAD);
+ void (*GetHalfPelMBRegion)(UChar *cand, UChar *hmem, Int lx);
+ void (*blockIdct)(Int *block);
+
+
+} FuncPtr;
+
+/* 04/09/01, for multipass rate control */
+
+typedef struct tagRDInfo
+{
+ Int QP;
+ Int actual_bits;
+ float mad;
+ float R_D;
+} RDInfo;
+
+typedef struct tagMultiPass
+{
+ /* multipass rate control data */
+ Int target_bits; /* target bits for current frame, = rc->T */
+ Int actual_bits; /* actual bits for current frame obtained after encoding, = rc->Rc*/
+ Int QP; /* quantization level for current frame, = rc->Qc*/
+ Int prev_QP; /* quantization level for previous frame */
+ Int prev_prev_QP; /* quantization level for previous frame before last*/
+ float mad; /* mad for current frame, = video->avgMAD*/
+ Int bitrate; /* bitrate for current frame */
+ float framerate; /* framerate for current frame*/
+
+ Int nRe_Quantized; /* control variable for multipass encoding, */
+ /* 0 : first pass */
+ /* 1 : intermediate pass(quantization and VLC loop only) */
+ /* 2 : final pass(de-quantization, idct, etc) */
+ /* 3 : macroblock level rate control */
+
+ Int encoded_frames; /* counter for all encoded frames */
+ Int re_encoded_frames; /* counter for all multipass encoded frames*/
+ Int re_encoded_times; /* counter for all times of multipass frame encoding */
+
+ /* Multiple frame prediction*/
+ RDInfo **pRDSamples; /* pRDSamples[30][32], 30->30fps, 32 -> 5 bit quantizer, 32 candidates*/
+ Int framePos; /* specific position in previous multiple frames*/
+ Int frameRange; /* number of overall previous multiple frames */
+ Int samplesPerFrame[30]; /* number of samples per frame, 30->30fps */
+
+ /* Bit allocation for scene change frames and high motion frames */
+ float sum_mad;
+ Int counter_BTsrc; /* BT = Bit Transfer, bit transfer from low motion frames or less complicatedly compressed frames */
+ Int counter_BTdst; /* BT = Bit Transfer, bit transfer to scene change frames or high motion frames or more complicatedly compressed frames */
+ float sum_QP;
+ Int diff_counter; /* diff_counter = -diff_counter_BTdst, or diff_counter_BTsrc */
+
+ /* For target bitrate or framerate update */
+ float target_bits_per_frame; /* = C = bitrate/framerate */
+ float target_bits_per_frame_prev; /* previous C */
+ float aver_mad; /* so-far average mad could replace sum_mad */
+ float aver_mad_prev; /* previous average mad */
+ Int overlapped_win_size; /* transition period of time */
+ Int encoded_frames_prev; /* previous encoded_frames */
+} MultiPass;
+
+/* End */
+
+#ifdef HTFM
+typedef struct tagHTFM_Stat
+{
+ Int abs_dif_mad_avg;
+ UInt countbreak;
+ Int offsetArray[16];
+ Int offsetRef[16];
+} HTFM_Stat;
+#endif
+
+/* Global structure that can be passed around */
+typedef struct tagVideoEncData
+{
+ /* VOL Header Initialization */
+ UChar volInitialize[4]; /* Used to Write VOL Headers */
+ /* Data For Layers (Scalability) */
+ Int numberOfLayers; /* Number of Layers */
+ Vol **vol; /* Data stored for each VOL */
+
+ /* Data used for encoding frames */
+ VideoEncFrameIO *input; /* original input frame */
+ Vop *currVop; /* Current reconstructed VOP */
+ Vop *prevBaseVop; /* Previous reference Base Vop */
+ Vop *nextBaseVop; /* Next reference Base Vop */
+ Vop *prevEnhanceVop;/* Previous Enhancement Layer Vop */
+ Vop *forwardRefVop; /* Forward Reference VOP */
+ Vop *backwardRefVop; /* Backward Reference VOP */
+
+ /* scratch memory */
+ BitstreamEncVideo *bitstream1; /* Used for data partitioning */
+ BitstreamEncVideo *bitstream2; /* and combined modes as */
+ BitstreamEncVideo *bitstream3; /* intermediate storages */
+
+ UChar *overrunBuffer; /* extra output buffer to prevent current skip due to output buffer overrun*/
+ Int oBSize; /* size of allocated overrun buffer */
+
+ Int dc_scalar_1; /*dc scalar for Y block */
+ Int dc_scalar_2; /*dc scalar for U, V block*/
+
+ /* Annex L Rate Control */
+ rateControl *rc[4]; /* Pointer to Rate Control structure*/
+ /* 12/25/00, each R.C. for each layer */
+
+ /********* motion compensation related variables ****************/
+ MOT **mot; /* Motion vectors */
+ /* where [mbnum][0] = 1MV.
+ [mbnum][1...4] = 4MVs
+ [mbnum][5] = backward MV.
+ [mbnum][6] = delta MV for direct mode.
+ [mbnum][7] = nothing yet. */
+ UChar *intraArray; /* Intra Update Arrary */
+ float sumMAD; /* SAD/MAD for frame */
+
+ /* to speedup the SAD calculation */
+ void *sad_extra_info;
+#ifdef HTFM
+ Int nrmlz_th[48]; /* Threshold for fast SAD calculation using HTFM */
+ HTFM_Stat htfm_stat; /* For statistics collection */
+#endif
+
+ /*Tao 04/09/00 For DCT routine */
+ UChar currYMB[256]; /* interleaved current macroblock in HTFM order */
+ MacroBlock *outputMB; /* Output MB to VLC encode */
+ UChar predictedMB[384]; /* scrath memory for predicted value */
+ RunLevelBlock RLB[6]; /* Run and Level of coefficients! */
+ Short dataBlock[128]; /* DCT block data before and after quant/dequant*/
+
+ UChar bitmaprow[8]; /* Need to keep it for ACDCPrediction, 8 bytes for alignment, need only 6 */
+ UChar bitmapcol[6][8];
+ UInt bitmapzz[6][2]; /* for zigzag bitmap */
+ Int zeroMV; /* flag for zero MV */
+
+ Int usePrevQP; /* flag for intraDCVlcThreshold switch decision */
+ Int QP_prev; /* use for DQUANT calculation */
+ Int *acPredFlag; /* */
+ typeDCStore *predDC; /* The DC coeffs for each MB */
+ typeDCACStore *predDCAC_row;
+ typeDCACStore *predDCAC_col;
+
+
+ UChar *sliceNo; /* Slice Number for each MB */
+
+ Int header_bits; /* header bits in frmae */
+ HeaderInfoEncVideo headerInfo; /* MB Header information */
+ UChar zz_direction; /* direction of zigzag scan */
+ UChar *QPMB; /* Quantizer value for each MB */
+
+ /* Miscellaneous data points to be passed */
+ float FrameRate; /* Src frame Rate */
+
+ ULong nextModTime; /* expected next frame time */
+ UInt prevFrameNum[4]; /* previous frame number starting from modTimeRef */
+ UInt modTimeRef; /* Reference modTime update every I-Vop*/
+ UInt refTick[4]; /* second aligned referenc tick */
+ Int relLayerCodeTime[4];/* Next coding time for each Layer relative to highest layer */
+
+ ULong modTime; /* Input frame modTime */
+ Int currLayer; /* Current frame layer */
+ Int mbnum; /* Macroblock number */
+
+ /* slice coding, state variables */
+ Vop *tempForwRefVop;
+ Int tempRefSelCode;
+ Int end_of_buf; /* end of bitstream buffer flag */
+ Int slice_coding; /* flag for slice based coding */
+ Int totalSAD; /* So far total SAD for a frame */
+ Int numIntra; /* So far number of Intra MB */
+ Int offset; /* So far MB offset */
+ Int ind_x, ind_y; /* So far MB coordinate */
+ Int collect;
+ Int hp_guess;
+ /*********************************/
+
+ HintTrackInfo hintTrackInfo; /* hintTrackInfo */
+ /* IntraPeriod, Timestamp, etc. */
+ float nextEncIVop; /* counter til the next I-Vop */
+ float numVopsInGOP; /* value at the beginning of nextEncIVop */
+
+ /* platform dependent functions */
+ FuncPtr *functionPointer; /* structure containing platform dependent functions */
+
+ /* Application controls */
+ VideoEncControls *videoEncControls;
+ VideoEncParams *encParams;
+
+ MultiPass *pMP[4]; /* for multipass encoding, 4 represents 4 layer encoding */
+
+} VideoEncData;
+
+/*************************************************************/
+/* VLC structures */
+/*************************************************************/
+
+typedef struct tagVLCtable
+{
+ unsigned int code; /* right justified */
+ int len;
+} VLCtable, *LPVLCtable;
+
+
+/*************************************************************/
+/* Approx DCT */
+/*************************************************************/
+typedef struct struct_approxDCT approxDCT;
+struct struct_approxDCT
+{
+ Void(*BlockDCT8x8)(Int *, Int *, UChar *, UChar *, Int, Int);
+ Void(*BlockDCT8x8Intra)(Int *, Int *, UChar *, UChar *, Int, Int);
+ Void(*BlockDCT8x8wSub)(Int *, Int *, UChar *, UChar *, Int, Int);
+};
+
+/*************************************************************/
+/* QP structure */
+/*************************************************************/
+
+struct QPstruct
+{
+ Int QPx2 ;
+ Int QP;
+ Int QPdiv2;
+ Int QPx2plus;
+ Int Addition;
+};
+
+
+#endif /* _MP4LIB_INT_H_ */
+
diff --git a/media/codecs/m4v_h263/enc/src/rate_control.cpp b/media/codecs/m4v_h263/enc/src/rate_control.cpp
new file mode 100644
index 0000000..ecc3217
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/rate_control.cpp
@@ -0,0 +1,887 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4lib_int.h"
+#include "rate_control.h"
+#include "mp4enc_lib.h"
+#include "bitstream_io.h"
+#include "m4venc_oscl.h"
+
+void targetBitCalculation(void *input);
+void calculateQuantizer_Multipass(void *video);
+void updateRateControl(rateControl *rc, VideoEncData *video);
+void updateRC_PostProc(rateControl *rc, VideoEncData *video);
+
+/***************************************************************************
+************** RC APIs to core encoding modules *******************
+
+PV_STATUS RC_Initialize(void *video);
+PV_STATUS RC_Cleanup(rateControl *rc[],Int numLayers);
+PV_STATUS RC_VopQPSetting(VideoEncData *video,rateControl *rc[]);
+PV_STATUS RC_VopUpdateStat(VideoEncData *video,rateControl *rc[]);
+PV_STATUS RC_UpdateBuffer(VideoEncData *video, Int currLayer, Int num_skip);
+Int RC_GetSkipNextFrame(VideoEncData *video,Int currLayer);
+void RC_ResetSkipNextFrame(void *video,Int currLayer);
+
+PV_STATUS RC_UpdateBXRCParams(void *input); Parameters update for target bitrate or framerate change
+
+****************************************************************************/
+
+
+/************************************************************************/
+/************ API part **************************************************/
+/* must be called before each sequence*/
+
+PV_STATUS RC_Initialize(void *input)
+{
+ VideoEncData *video = (VideoEncData *) input;
+ VideoEncParams *encParams = video->encParams;
+ rateControl **rc = video->rc;
+ Int numLayers = encParams->nLayers;
+ Int *LayerBitRate = encParams->LayerBitRate;
+ float *LayerFrameRate = encParams->LayerFrameRate;
+ MultiPass **pMP = video->pMP;
+
+ Int n;
+
+ for (n = 0; n < numLayers; n++)
+ {
+ /* rate control */
+ rc[n]->fine_frame_skip = encParams->FineFrameSkip_Enabled;
+ rc[n]->no_frame_skip = encParams->NoFrameSkip_Enabled;
+ rc[n]->no_pre_skip = encParams->NoPreSkip_Enabled;
+ rc[n]->skip_next_frame = 0; /* must be initialized */
+
+ //rc[n]->TMN_TH = (Int)((float)LayerBitRate[n]/LayerFrameRate[n]);
+ rc[n]->Bs = video->encParams->BufferSize[n];
+ rc[n]->TMN_W = 0;
+ rc[n]->VBV_fullness = (Int)(rc[n]->Bs * 0.5); /* rc[n]->Bs */
+ rc[n]->encoded_frames = 0;
+ rc[n]->framerate = LayerFrameRate[n];
+ if (n == 0)
+ {
+ rc[n]->TMN_TH = (Int)((float)LayerBitRate[n] / LayerFrameRate[n]);
+ rc[n]->bitrate = LayerBitRate[n];
+ rc[n]->framerate = LayerFrameRate[n];
+
+ // For h263 or short header mode, the bit variation is within (-2*Rmax*1001/3000, 2*Rmax*1001/3000)
+ if (video->encParams->H263_Enabled)
+ {
+ rc[n]->max_BitVariance_num = (Int)((rc[n]->Bs - video->encParams->maxFrameSize) / 2 / (rc[n]->bitrate / rc[n]->framerate / 10.0)) - 5;
+ if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
+ }
+ else // MPEG-4 normal modes
+ {
+ rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - rc[n]->VBV_fullness) / ((float)LayerBitRate[n] / LayerFrameRate[n] / 10.0)) - 5;
+ if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
+ }
+ }
+ else
+ {
+ if (LayerFrameRate[n] - LayerFrameRate[n-1] > 0) /* 7/31/03 */
+ {
+ rc[n]->TMN_TH = (Int)((float)(LayerBitRate[n] - LayerBitRate[n-1]) / (LayerFrameRate[n] - LayerFrameRate[n-1]));
+ rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - rc[n]->VBV_fullness) * 10 / ((float)rc[n]->TMN_TH)) - 5;
+ if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
+ }
+ else /* 7/31/03 */
+ {
+ rc[n]->TMN_TH = 1 << 30;
+ rc[n]->max_BitVariance_num = 0;
+ }
+ rc[n]->bitrate = LayerBitRate[n] - LayerBitRate[n-1];
+ rc[n]->framerate = LayerFrameRate[n] - LayerFrameRate[n-1];
+ }
+
+ // Set the initial buffer fullness
+ if (1) //!video->encParams->H263_Enabled) { // MPEG-4
+ {
+ /* According to the spec, the initial buffer fullness needs to be set to 1/3 */
+ rc[n]->VBV_fullness = (Int)(rc[n]->Bs / 3.0 - rc[n]->Bs / 2.0); /* the buffer range is [-Bs/2, Bs/2] */
+ pMP[n]->counter_BTsrc = (Int)((rc[n]->Bs / 2.0 - rc[n]->Bs / 3.0) / (rc[n]->bitrate / rc[n]->framerate / 10.0));
+ rc[n]->TMN_W = (Int)(rc[n]->VBV_fullness + pMP[n]->counter_BTsrc * (rc[n]->bitrate / rc[n]->framerate / 10.0));
+
+ rc[n]->low_bound = -rc[n]->Bs / 2;
+ rc[n]-> VBV_fullness_offset = 0;
+ }
+ else /* this part doesn't work in some cases, the low_bound is too high, Jan 4,2006 */
+ {
+ rc[n]->VBV_fullness = rc[n]->Bs - (Int)(video->encParams->VBV_delay * rc[n]->bitrate);
+ if (rc[n]->VBV_fullness < 0) rc[n]->VBV_fullness = 0;
+ //rc[n]->VBV_fullness = (rc[n]->Bs-video->encParams->maxFrameSize)/2 + video->encParams->maxFrameSize;
+
+ rc[n]->VBV_fullness -= rc[n]->Bs / 2; /* the buffer range is [-Bs/2, Bs/2] */
+ rc[n]->low_bound = -rc[n]->Bs / 2 + video->encParams->maxFrameSize; /* too high */
+ rc[n]->VBV_fullness_offset = video->encParams->maxFrameSize / 2; /* don't understand the meaning of this */
+ pMP[n]->counter_BTdst = pMP[n]->counter_BTsrc = 0;
+
+ }
+
+ /* Setting the bitrate and framerate */
+ pMP[n]->bitrate = rc[n]->bitrate;
+ pMP[n]->framerate = rc[n]->framerate;
+ pMP[n]->target_bits_per_frame = pMP[n]->bitrate / pMP[n]->framerate;
+
+ }
+
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : RC_Cleanup */
+/* Date : 12/20/2000 */
+/* Purpose : free Rate Control memory */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+
+PV_STATUS RC_Cleanup(rateControl *rc[], Int numLayers)
+{
+ OSCL_UNUSED_ARG(rc);
+ OSCL_UNUSED_ARG(numLayers);
+
+ return PV_SUCCESS;
+}
+
+
+
+/* ======================================================================== */
+/* Function : RC_VopQPSetting */
+/* Date : 4/11/2001 */
+/* Purpose : Reset rate control before coding VOP, moved from vop.c */
+/* Compute QP for the whole VOP and initialize MB-based RC
+ reset QPMB[], currVop->quantizer, rc->Ec, video->header_bits */
+/* to In order to work RC_VopQPSetting has to do the followings
+ 1. Set video->QPMB of all macroblocks.
+ 2. Set currVop->quantizer
+ 3. Reset video->header_bits to zero.
+ 4. Initialize internal RC parameters for Vop cooding */
+/* In/out : */
+/* Return : PV_STATUS */
+/* Modified : */
+/* ======================================================================== */
+/* To be moved to rate_control.c and separate between BX_RC and ANNEX_L */
+
+PV_STATUS RC_VopQPSetting(VideoEncData *video, rateControl *prc[])
+{
+ Int currLayer = video->currLayer;
+ Vol *currVol = video->vol[currLayer];
+ Vop *currVop = video->currVop;
+#ifdef TEST_MBBASED_QP
+ int i;
+#endif
+
+ rateControl *rc = video->rc[currLayer];
+ MultiPass *pMP = video->pMP[currLayer];
+
+ OSCL_UNUSED_ARG(prc);
+
+ if (video->encParams->RC_Type == CONSTANT_Q)
+ {
+ M4VENC_MEMSET(video->QPMB, currVop->quantizer, sizeof(UChar)*currVol->nTotalMB);
+ return PV_SUCCESS;
+ }
+ else
+ {
+
+ if (video->rc[currLayer]->encoded_frames == 0) /* rc[currLayer]->totalFrameNumber*/
+ {
+ M4VENC_MEMSET(video->QPMB, currVop->quantizer, sizeof(UChar)*currVol->nTotalMB);
+ video->rc[currLayer]->Qc = video->encParams->InitQuantIvop[currLayer];
+ }
+ else
+ {
+ calculateQuantizer_Multipass((void*) video);
+ currVop->quantizer = video->rc[currLayer]->Qc;
+#ifdef TEST_MBBASED_QP
+ i = currVol->nTotalMB; /* testing changing QP at MB level */
+ while (i)
+ {
+ i--;
+ video->QPMB[i] = (i & 1) ? currVop->quantizer - 1 : currVop->quantizer + 1;
+ }
+#else
+ M4VENC_MEMSET(video->QPMB, currVop->quantizer, sizeof(UChar)*currVol->nTotalMB);
+#endif
+ }
+
+ video->header_bits = 0;
+ }
+
+ /* update pMP->framePos */
+ if (++pMP->framePos == pMP->frameRange) pMP->framePos = 0;
+
+ if (rc->T == 0)
+ {
+ pMP->counter_BTdst = (Int)(video->encParams->LayerFrameRate[video->currLayer] * 7.5 + 0.5); /* 0.75s time frame */
+ pMP->counter_BTdst = PV_MIN(pMP->counter_BTdst, (Int)(rc->max_BitVariance_num / 2 * 0.40)); /* 0.75s time frame may go beyond VBV buffer if we set the buffer size smaller than 0.75s */
+ pMP->counter_BTdst = PV_MAX(pMP->counter_BTdst, (Int)((rc->Bs / 2 - rc->VBV_fullness) * 0.30 / (rc->TMN_TH / 10.0) + 0.5)); /* At least 30% of VBV buffer size/2 */
+ pMP->counter_BTdst = PV_MIN(pMP->counter_BTdst, 20); /* Limit the target to be smaller than 3C */
+
+ pMP->target_bits = rc->T = rc->TMN_TH = (Int)(rc->TMN_TH * (1.0 + pMP->counter_BTdst * 0.1));
+ pMP->diff_counter = pMP->counter_BTdst;
+ }
+
+ /* collect the necessary data: target bits, actual bits, mad and QP */
+ pMP->target_bits = rc->T;
+ pMP->QP = currVop->quantizer;
+
+ pMP->mad = video->sumMAD / (float)currVol->nTotalMB;
+ if (pMP->mad < MAD_MIN) pMP->mad = MAD_MIN; /* MAD_MIN is defined as 1 in mp4def.h */
+
+ pMP->bitrate = rc->bitrate; /* calculated in RCVopQPSetting */
+ pMP->framerate = rc->framerate;
+
+ /* first pass encoding */
+ pMP->nRe_Quantized = 0;
+
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : SaveRDSamples() */
+/* Date : 08/29/2001 */
+/* History : */
+/* Purpose : Save QP, actual_bits, mad and R_D of the current iteration */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+Void SaveRDSamples(MultiPass *pMP, Int counter_samples)
+{
+ /* for pMP->pRDSamples */
+ pMP->pRDSamples[pMP->framePos][counter_samples].QP = pMP->QP;
+ pMP->pRDSamples[pMP->framePos][counter_samples].actual_bits = pMP->actual_bits;
+ pMP->pRDSamples[pMP->framePos][counter_samples].mad = pMP->mad;
+ pMP->pRDSamples[pMP->framePos][counter_samples].R_D = (float)(pMP->actual_bits / (pMP->mad + 0.0001));
+
+ return ;
+}
+/* ======================================================================== */
+/* Function : RC_VopUpdateStat */
+/* Date : 12/20/2000 */
+/* Purpose : Update statistics for rate control after encoding each VOP. */
+/* No need to change anything in VideoEncData structure. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+PV_STATUS RC_VopUpdateStat(VideoEncData *video, rateControl *rc)
+{
+ Int currLayer = video->currLayer;
+ Vol *currVol = video->vol[currLayer];
+ MultiPass *pMP = video->pMP[currLayer];
+ Int diff_BTCounter;
+
+ switch (video->encParams->RC_Type)
+ {
+ case CONSTANT_Q:
+ break;
+
+ case CBR_1:
+ case CBR_2:
+ case VBR_1:
+ case VBR_2:
+ case CBR_LOWDELAY:
+
+ pMP->actual_bits = currVol->stream->byteCount << 3;
+
+ SaveRDSamples(pMP, 0);
+
+ pMP->encoded_frames++;
+
+ /* for pMP->samplesPerFrame */
+ pMP->samplesPerFrame[pMP->framePos] = 0;
+
+ pMP->sum_QP += pMP->QP;
+
+
+ /* update pMP->counter_BTsrc, pMP->counter_BTdst */
+ /* re-allocate the target bit again and then stop encoding */
+ diff_BTCounter = (Int)((float)(rc->TMN_TH - rc->TMN_W - pMP->actual_bits) /
+ (pMP->bitrate / (pMP->framerate + 0.0001) + 0.0001) / 0.1);
+ if (diff_BTCounter >= 0)
+ pMP->counter_BTsrc += diff_BTCounter; /* pMP->actual_bits is smaller */
+ else
+ pMP->counter_BTdst -= diff_BTCounter; /* pMP->actual_bits is bigger */
+
+ rc->TMN_TH -= (Int)((float)pMP->bitrate / (pMP->framerate + 0.0001) * (diff_BTCounter * 0.1));
+ rc->T = pMP->target_bits = rc->TMN_TH - rc->TMN_W;
+ pMP->diff_counter -= diff_BTCounter;
+
+ rc->Rc = currVol->stream->byteCount << 3; /* Total Bits for current frame */
+ rc->Hc = video->header_bits; /* Total Bits in Header and Motion Vector */
+
+ /* BX_RC */
+ updateRateControl(rc, video);
+
+ break;
+
+ default: /* for case CBR_1/2, VBR_1/2 */
+
+ return PV_FAIL;
+ }
+
+
+ return PV_SUCCESS;
+}
+
+/* ======================================================================== */
+/* Function : RC_GetSkipNextFrame, RC_GetRemainingVops */
+/* Date : 2/20/2001 */
+/* Purpose : To access RC parameters from other parts of the code. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+Int RC_GetSkipNextFrame(VideoEncData *video, Int currLayer)
+{
+ return video->rc[currLayer]->skip_next_frame;
+}
+
+void RC_ResetSkipNextFrame(VideoEncData *video, Int currLayer)
+{
+
+ video->rc[currLayer]->skip_next_frame = 0;
+ return ;
+}
+
+/* ======================================================================== */
+/* Function : RC_UpdateBuffer */
+/* Date : 2/20/2001 */
+/* Purpose : Update RC in case of there are frames skipped (camera freeze)*/
+/* from the application level in addition to what RC requested */
+/* In/out : Nr, B, Rr */
+/* Return : Void */
+/* Modified : */
+/* Input argument "video" is guaranteed non-null by caller */
+/* ======================================================================== */
+
+PV_STATUS RC_UpdateBuffer(VideoEncData *video, Int currLayer, Int num_skip)
+{
+ rateControl *rc = video->rc[currLayer];
+ MultiPass *pMP = video->pMP[currLayer];
+
+ if (rc == NULL || pMP == NULL)
+ return PV_FAIL;
+
+ rc->VBV_fullness -= (Int)(rc->bitrate / rc->framerate * num_skip); //rc[currLayer]->Rp;
+ pMP->counter_BTsrc += 10 * num_skip;
+
+ /* Check buffer underflow */
+ if (rc->VBV_fullness < rc->low_bound)
+ {
+ rc->VBV_fullness = rc->low_bound; // -rc->Bs/2;
+ rc->TMN_W = rc->VBV_fullness - rc->low_bound;
+ pMP->counter_BTsrc = pMP->counter_BTdst + (Int)((float)(rc->Bs / 2 - rc->low_bound) / 2.0 / (pMP->target_bits_per_frame / 10));
+ }
+
+ return PV_SUCCESS;
+}
+
+
+/* ======================================================================== */
+/* Function : RC_UpdateBXRCParams */
+/* Date : 4/08/2002 */
+/* Purpose : Update RC parameters specifically for target bitrate or */
+/* framerate update during an encoding session */
+/* In/out : */
+/* Return : PV_TRUE if successed, PV_FALSE if failed. */
+/* Modified : */
+/* ======================================================================== */
+
+PV_STATUS RC_UpdateBXRCParams(void *input)
+{
+ VideoEncData *video = (VideoEncData *) input;
+ VideoEncParams *encParams = video->encParams;
+ rateControl **rc = video->rc;
+ Int numLayers = encParams->nLayers;
+ Int *LayerBitRate = encParams->LayerBitRate;
+ float *LayerFrameRate = encParams->LayerFrameRate;
+ MultiPass **pMP = video->pMP;
+
+ Int n, VBV_fullness;
+ Int diff_counter;
+
+ extern Bool SetProfile_BufferSize(VideoEncData *video, float delay, Int bInitialized);
+
+
+ /* Reset video buffer size due to target bitrate change */
+ SetProfile_BufferSize(video, video->encParams->VBV_delay, 0); /* output: video->encParams->BufferSize[] */
+
+ for (n = 0; n < numLayers; n++)
+ {
+ /* Remaining stuff about frame dropping and underflow check in update RC */
+ updateRC_PostProc(rc[n], video);
+ rc[n]->skip_next_frame = 0; /* must be initialized */
+
+ /* New changes: bitrate and framerate, Bs, max_BitVariance_num, TMN_TH(optional), encoded_frames(optional) */
+ rc[n]->Bs = video->encParams->BufferSize[n];
+ VBV_fullness = (Int)(rc[n]->Bs * 0.5);
+
+ if (n == 0)
+ {
+ rc[n]->TMN_TH = (Int)((float)LayerBitRate[n] / LayerFrameRate[n]);
+ rc[n]->bitrate = pMP[n]->bitrate = LayerBitRate[n];
+ rc[n]->framerate = pMP[n]->framerate = LayerFrameRate[n];
+
+ // For h263 or short header mode, the bit variation is within (-2*Rmax*1001/3000, 2*Rmax*1001/3000)
+ if (video->encParams->H263_Enabled)
+ {
+ rc[n]->max_BitVariance_num = (Int)((rc[n]->Bs - video->encParams->maxFrameSize) / 2 / (rc[n]->bitrate / rc[n]->framerate / 10.0)) - 5;
+ //rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - rc[n]->VBV_fullness)/((float)LayerBitRate[n]/LayerFrameRate[n]/10.0))-5;
+ }
+ else // MPEG-4 normal modes
+ {
+ rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - VBV_fullness) * 10 / ((float)LayerBitRate[n] / LayerFrameRate[n])) - 5;
+ }
+ }
+ else
+ {
+ if (LayerFrameRate[n] - LayerFrameRate[n-1] > 0) /* 7/31/03 */
+ {
+ rc[n]->TMN_TH = (Int)((float)(LayerBitRate[n] - LayerBitRate[n-1]) / (LayerFrameRate[n] - LayerFrameRate[n-1]));
+ rc[n]->max_BitVariance_num = (Int)((float)(rc[n]->Bs - VBV_fullness) * 10 / ((float)rc[n]->TMN_TH)) - 5;
+ if (rc[n]->max_BitVariance_num < 0) rc[n]->max_BitVariance_num += 5;
+ }
+ else /* 7/31/03 */
+ {
+ rc[n]->TMN_TH = 1 << 30;
+ rc[n]->max_BitVariance_num = 0;
+ }
+ rc[n]->bitrate = pMP[n]->bitrate = LayerBitRate[n] - LayerBitRate[n-1];
+ rc[n]->framerate = pMP[n]->framerate = LayerFrameRate[n] - LayerFrameRate[n-1];
+ }
+
+ pMP[n]->target_bits_per_frame_prev = pMP[n]->target_bits_per_frame;
+ pMP[n]->target_bits_per_frame = pMP[n]->bitrate / (float)(pMP[n]->framerate + 0.0001); /* 7/31/03 */
+
+ /* rc[n]->VBV_fullness and rc[n]->TMN_W should be kept same */
+ /* update pMP[n]->counter_BTdst and pMP[n]->counter_BTsrc */
+ diff_counter = (Int)((float)(rc[n]->VBV_fullness - rc[n]->TMN_W) /
+ (pMP[n]->target_bits_per_frame / 10 + 0.0001)); /* 7/31/03 */
+
+ pMP[n]->counter_BTdst = pMP[n]->counter_BTsrc = 0;
+ if (diff_counter > 0)
+ pMP[n]->counter_BTdst = diff_counter;
+
+ else if (diff_counter < 0)
+ pMP[n]->counter_BTsrc = -diff_counter;
+
+ rc[n]->TMN_W = (Int)(rc[n]->VBV_fullness - /* re-calculate rc[n]->TMN_W in order for higher accuracy */
+ (pMP[n]->target_bits_per_frame / 10) * (pMP[n]->counter_BTdst - pMP[n]->counter_BTsrc));
+
+ /* Keep the current average mad */
+ if (pMP[n]->aver_mad != 0)
+ {
+ pMP[n]->aver_mad_prev = pMP[n]->aver_mad;
+ pMP[n]->encoded_frames_prev = pMP[n]->encoded_frames;
+ }
+
+ pMP[n]->aver_mad = 0;
+ pMP[n]->overlapped_win_size = 4;
+
+ /* Misc */
+ pMP[n]->sum_mad = pMP[n]->sum_QP = 0;
+ //pMP[n]->encoded_frames_prev = pMP[n]->encoded_frames;
+ pMP[n]->encoded_frames = pMP[n]->re_encoded_frames = pMP[n]->re_encoded_times = 0;
+
+ } /* end of: for(n=0; n<numLayers; n++) */
+
+ return PV_SUCCESS;
+
+}
+
+
+/* ================================================================================ */
+/* Function : targetBitCalculation */
+/* Date : 10/01/2001 */
+/* Purpose : quadratic bit allocation model: T(n) = C*sqrt(mad(n)/aver_mad(n-1)) */
+/* */
+/* In/out : rc->T */
+/* Return : Void */
+/* Modified : */
+/* Input argument "input" is guaranteed non-null by caller */
+/* ================================================================================ */
+
+void targetBitCalculation(void *input)
+{
+ VideoEncData *video = (VideoEncData *) input;
+ MultiPass *pMP = video->pMP[video->currLayer];
+ Vol *currVol = video->vol[video->currLayer];
+ rateControl *rc = video->rc[video->currLayer];
+
+ float curr_mad;//, average_mad;
+ Int diff_counter_BTsrc, diff_counter_BTdst, prev_counter_diff, curr_counter_diff, bound;
+ /* BT = Bit Transfer, for pMP->counter_BTsrc, pMP->counter_BTdst */
+
+ if (currVol == NULL || pMP == NULL || rc == NULL)
+ return;
+
+ /* some stuff about frame dropping remained here to be done because pMP cannot be inserted into updateRateControl()*/
+ updateRC_PostProc(rc, video);
+
+ /* update pMP->counter_BTsrc and pMP->counter_BTdst to avoid interger overflow */
+ if (pMP->counter_BTsrc > 1000 && pMP->counter_BTdst > 1000)
+ {
+ pMP->counter_BTsrc -= 1000;
+ pMP->counter_BTdst -= 1000;
+ }
+
+ /* ---------------------------------------------------------------------------------------------------*/
+ /* target calculation */
+ curr_mad = video->sumMAD / (float)currVol->nTotalMB;
+ if (curr_mad < MAD_MIN) curr_mad = MAD_MIN; /* MAD_MIN is defined as 1 in mp4def.h */
+ diff_counter_BTsrc = diff_counter_BTdst = 0;
+ pMP->diff_counter = 0;
+
+
+ /*1.calculate average mad */
+ pMP->sum_mad += curr_mad;
+ //average_mad = (pMP->encoded_frames < 1 ? curr_mad : pMP->sum_mad/(float)(pMP->encoded_frames+1)); /* this function is called from the scond encoded frame*/
+ //pMP->aver_mad = average_mad;
+ if (pMP->encoded_frames >= 0) /* pMP->encoded_frames is set to -1 initially, so forget about the very first I frame */
+ pMP->aver_mad = (pMP->aver_mad * pMP->encoded_frames + curr_mad) / (pMP->encoded_frames + 1);
+
+ if (pMP->overlapped_win_size > 0 && pMP->encoded_frames_prev >= 0) /* 7/31/03 */
+ pMP->aver_mad_prev = (pMP->aver_mad_prev * pMP->encoded_frames_prev + curr_mad) / (pMP->encoded_frames_prev + 1);
+
+ /*2.average_mad, mad ==> diff_counter_BTsrc, diff_counter_BTdst */
+ if (pMP->overlapped_win_size == 0)
+ {
+ /* original verison */
+ if (curr_mad > pMP->aver_mad*1.1)
+ {
+ if (curr_mad / (pMP->aver_mad + 0.0001) > 2)
+ diff_counter_BTdst = (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad + 0.0001)) * 10 + 0.4) - 10;
+ //diff_counter_BTdst = (Int)((sqrt(curr_mad/pMP->aver_mad)*2+curr_mad/pMP->aver_mad)/(3*0.1) + 0.4) - 10;
+ else
+ diff_counter_BTdst = (Int)(curr_mad / (pMP->aver_mad + 0.0001) * 10 + 0.4) - 10;
+ }
+ else /* curr_mad <= average_mad*1.1 */
+ //diff_counter_BTsrc = 10 - (Int)((sqrt(curr_mad/pMP->aver_mad) + pow(curr_mad/pMP->aver_mad, 1.0/3.0))/(2.0*0.1) + 0.4);
+ diff_counter_BTsrc = 10 - (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad + 0.0001)) * 10 + 0.5);
+ //diff_counter_BTsrc = 10 - (Int)(curr_mad/pMP->aver_mad/0.1 + 0.5)
+
+ /* actively fill in the possible gap */
+ if (diff_counter_BTsrc == 0 && diff_counter_BTdst == 0 &&
+ curr_mad <= pMP->aver_mad*1.1 && pMP->counter_BTsrc < pMP->counter_BTdst)
+ diff_counter_BTsrc = 1;
+
+ }
+ else if (pMP->overlapped_win_size > 0)
+ {
+ /* transition time: use previous average mad "pMP->aver_mad_prev" instead of the current average mad "pMP->aver_mad" */
+ if (curr_mad > pMP->aver_mad_prev*1.1)
+ {
+ if (curr_mad / pMP->aver_mad_prev > 2)
+ diff_counter_BTdst = (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad_prev + 0.0001)) * 10 + 0.4) - 10;
+ //diff_counter_BTdst = (Int)((M4VENC_SQRT(curr_mad/pMP->aver_mad_prev)*2+curr_mad/pMP->aver_mad_prev)/(3*0.1) + 0.4) - 10;
+ else
+ diff_counter_BTdst = (Int)(curr_mad / (pMP->aver_mad_prev + 0.0001) * 10 + 0.4) - 10;
+ }
+ else /* curr_mad <= average_mad*1.1 */
+ //diff_counter_BTsrc = 10 - (Int)((sqrt(curr_mad/pMP->aver_mad_prev) + pow(curr_mad/pMP->aver_mad_prev, 1.0/3.0))/(2.0*0.1) + 0.4);
+ diff_counter_BTsrc = 10 - (Int)(M4VENC_SQRT(curr_mad / (pMP->aver_mad_prev + 0.0001)) * 10 + 0.5);
+ //diff_counter_BTsrc = 10 - (Int)(curr_mad/pMP->aver_mad_prev/0.1 + 0.5)
+
+ /* actively fill in the possible gap */
+ if (diff_counter_BTsrc == 0 && diff_counter_BTdst == 0 &&
+ curr_mad <= pMP->aver_mad_prev*1.1 && pMP->counter_BTsrc < pMP->counter_BTdst)
+ diff_counter_BTsrc = 1;
+
+ if (--pMP->overlapped_win_size <= 0) pMP->overlapped_win_size = 0;
+ }
+
+
+ /* if difference is too much, do clipping */
+ /* First, set the upper bound for current bit allocation variance: 80% of available buffer */
+ bound = (Int)((rc->Bs / 2 - rc->VBV_fullness) * 0.6 / (pMP->target_bits_per_frame / 10)); /* rc->Bs */
+ diff_counter_BTsrc = PV_MIN(diff_counter_BTsrc, bound);
+ diff_counter_BTdst = PV_MIN(diff_counter_BTdst, bound);
+
+ /* Second, set another upper bound for current bit allocation: 4-5*bitrate/framerate */
+ bound = 50;
+// if(video->encParams->RC_Type == CBR_LOWDELAY)
+// not necessary bound = 10; /* 1/17/02 -- For Low delay */
+
+ diff_counter_BTsrc = PV_MIN(diff_counter_BTsrc, bound);
+ diff_counter_BTdst = PV_MIN(diff_counter_BTdst, bound);
+
+
+ /* Third, check the buffer */
+ prev_counter_diff = pMP->counter_BTdst - pMP->counter_BTsrc;
+ curr_counter_diff = prev_counter_diff + (diff_counter_BTdst - diff_counter_BTsrc);
+
+ if (PV_ABS(prev_counter_diff) >= rc->max_BitVariance_num || PV_ABS(curr_counter_diff) >= rc->max_BitVariance_num) // PV_ABS(curr_counter_diff) >= PV_ABS(prev_counter_diff) )
+ { //diff_counter_BTsrc = diff_counter_BTdst = 0;
+
+ if (curr_counter_diff > rc->max_BitVariance_num && diff_counter_BTdst)
+ {
+ diff_counter_BTdst = (rc->max_BitVariance_num - prev_counter_diff) + diff_counter_BTsrc;
+ if (diff_counter_BTdst < 0) diff_counter_BTdst = 0;
+ }
+
+ else if (curr_counter_diff < -rc->max_BitVariance_num && diff_counter_BTsrc)
+ {
+ diff_counter_BTsrc = diff_counter_BTdst - (-rc->max_BitVariance_num - prev_counter_diff);
+ if (diff_counter_BTsrc < 0) diff_counter_BTsrc = 0;
+ }
+ }
+
+
+ /*3.diff_counter_BTsrc, diff_counter_BTdst ==> TMN_TH */
+ //rc->TMN_TH = (Int)((float)pMP->bitrate/pMP->framerate);
+ rc->TMN_TH = (Int)(pMP->target_bits_per_frame);
+ pMP->diff_counter = 0;
+
+ if (diff_counter_BTsrc)
+ {
+ rc->TMN_TH -= (Int)(pMP->target_bits_per_frame * diff_counter_BTsrc * 0.1);
+ pMP->diff_counter = -diff_counter_BTsrc;
+ }
+ else if (diff_counter_BTdst)
+ {
+ rc->TMN_TH += (Int)(pMP->target_bits_per_frame * diff_counter_BTdst * 0.1);
+ pMP->diff_counter = diff_counter_BTdst;
+ }
+
+
+ /*4.update pMP->counter_BTsrc, pMP->counter_BTdst */
+ pMP->counter_BTsrc += diff_counter_BTsrc;
+ pMP->counter_BTdst += diff_counter_BTdst;
+
+
+ /*5.target bit calculation */
+ rc->T = rc->TMN_TH - rc->TMN_W;
+ //rc->T = rc->TMN_TH - (Int)((float)rc->TMN_W/rc->frameRate);
+
+ if (video->encParams->H263_Enabled && rc->T > video->encParams->maxFrameSize)
+ {
+ rc->T = video->encParams->maxFrameSize; // added this 11/07/05
+ }
+
+}
+
+/* ================================================================================ */
+/* Function : calculateQuantizer_Multipass */
+/* Date : 10/01/2001 */
+/* Purpose : variable rate bit allocation + new QP determination scheme */
+/* */
+/* In/out : rc->T and rc->Qc */
+/* Return : Void */
+/* Modified : */
+/* Input argument "input" is guaranteed non-null by caller */
+/* ================================================================================ */
+
+/* Mad based variable bit allocation + QP calculation with a new quadratic method */
+void calculateQuantizer_Multipass(void *input)
+{
+ VideoEncData *video = (VideoEncData *) input;
+ MultiPass *pMP = video->pMP[video->currLayer];
+ Vol *currVol = video->vol[video->currLayer];
+ rateControl *rc = video->rc[video->currLayer];
+
+ Int prev_QP, prev_actual_bits, curr_target, i, j;
+
+ float curr_mad, prev_mad, curr_RD, prev_RD, average_mad, aver_QP;
+
+
+ if (currVol == NULL || pMP == NULL || rc == NULL)
+ return;
+
+ /* Mad based variable bit allocation */
+ targetBitCalculation((void*) video);
+
+ if (rc->T <= 0 || video->sumMAD == 0)
+ {
+ if (rc->T < 0) rc->Qc = 31;
+ return;
+ }
+
+ /* ---------------------------------------------------------------------------------------------------*/
+ /* current frame QP estimation */
+ curr_target = rc->T;
+ curr_mad = video->sumMAD / (float)currVol->nTotalMB;
+ if (curr_mad < MAD_MIN) curr_mad = MAD_MIN; /* MAD_MIN is defined as 1 in mp4def.h */
+ curr_RD = (float)curr_target / curr_mad;
+
+ /* Another version of search the optimal point */
+ prev_actual_bits = pMP->pRDSamples[0][0].actual_bits;
+ prev_mad = pMP->pRDSamples[0][0].mad;
+
+ for (i = 0, j = 0; i < pMP->frameRange; i++)
+ {
+ if (pMP->pRDSamples[i][0].mad != 0 && prev_mad != 0 &&
+ PV_ABS(prev_mad - curr_mad) > PV_ABS(pMP->pRDSamples[i][0].mad - curr_mad))
+ {
+ prev_mad = pMP->pRDSamples[i][0].mad;
+ prev_actual_bits = pMP->pRDSamples[i][0].actual_bits;
+ j = i;
+ }
+ }
+ prev_QP = pMP->pRDSamples[j][0].QP;
+ for (i = 1; i < pMP->samplesPerFrame[j]; i++)
+ {
+ if (PV_ABS(prev_actual_bits - curr_target) > PV_ABS(pMP->pRDSamples[j][i].actual_bits - curr_target))
+ {
+ prev_actual_bits = pMP->pRDSamples[j][i].actual_bits;
+ prev_QP = pMP->pRDSamples[j][i].QP;
+ }
+ }
+
+ // quadratic approximation
+ prev_RD = (float)prev_actual_bits / prev_mad;
+ //rc->Qc = (Int)(prev_QP * sqrt(prev_actual_bits/curr_target) + 0.4);
+ if (prev_QP == 1) // 11/14/05, added this to allow getting out of QP = 1 easily
+ {
+ rc->Qc = (Int)(prev_RD / curr_RD + 0.5);
+ }
+ else
+ {
+ rc->Qc = (Int)(prev_QP * M4VENC_SQRT(prev_RD / curr_RD) + 0.9);
+
+ if (prev_RD / curr_RD > 0.5 && prev_RD / curr_RD < 2.0)
+ rc->Qc = (Int)(prev_QP * (M4VENC_SQRT(prev_RD / curr_RD) + prev_RD / curr_RD) / 2.0 + 0.9); /* Quadratic and linear approximation */
+ else
+ rc->Qc = (Int)(prev_QP * (M4VENC_SQRT(prev_RD / curr_RD) + M4VENC_POW(prev_RD / curr_RD, 1.0 / 3.0)) / 2.0 + 0.9);
+ }
+ //rc->Qc =(Int)(prev_QP * sqrt(prev_RD/curr_RD) + 0.4);
+ // 11/08/05
+ // lower bound on Qc should be a function of curr_mad
+ // When mad is already low, lower bound on Qc doesn't have to be small.
+ // Note, this doesn't work well for low complexity clip encoded at high bit rate
+ // it doesn't hit the target bit rate due to this QP lower bound.
+/// if((curr_mad < 8) && (rc->Qc < 12)) rc->Qc = 12;
+// else if((curr_mad < 128) && (rc->Qc < 3)) rc->Qc = 3;
+
+ if (rc->Qc < 1) rc->Qc = 1;
+ if (rc->Qc > 31) rc->Qc = 31;
+
+
+ /* active bit resource protection */
+ aver_QP = (pMP->encoded_frames == 0 ? 0 : pMP->sum_QP / (float)pMP->encoded_frames);
+ average_mad = (pMP->encoded_frames == 0 ? 0 : pMP->sum_mad / (float)pMP->encoded_frames); /* this function is called from the scond encoded frame*/
+ if (pMP->diff_counter == 0 &&
+ ((float)rc->Qc <= aver_QP*1.1 || curr_mad <= average_mad*1.1) &&
+ pMP->counter_BTsrc <= (pMP->counter_BTdst + (Int)(pMP->framerate*1.0 + 0.5)))
+ {
+ rc->TMN_TH -= (Int)(pMP->target_bits_per_frame / 10.0);
+ rc->T = rc->TMN_TH - rc->TMN_W;
+ pMP->counter_BTsrc++;
+ pMP->diff_counter--;
+ }
+
+}
+
+
+/* ======================================================================== */
+/* Function : updateRateControl */
+/* Date : 11/17/2000 */
+/* Purpose :Update the RD Modal (After Encoding the Current Frame) */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+void updateRateControl(rateControl *rc, VideoEncData *video)
+{
+ Int frame_bits;
+
+
+ /* rate contro\l */
+ frame_bits = (Int)(rc->bitrate / rc->framerate);
+ rc->TMN_W += (rc->Rc - rc->TMN_TH);
+ rc->VBV_fullness += (rc->Rc - frame_bits); //rc->Rp);
+ //if(rc->VBV_fullness < 0) rc->VBV_fullness = -1;
+
+ rc->encoded_frames++;
+
+ /* frame dropping */
+ rc->skip_next_frame = 0;
+
+ if ((video->encParams->H263_Enabled && rc->Rc > video->encParams->maxFrameSize) || /* For H263/short header mode, drop the frame if the actual frame size exceeds the bound */
+ (rc->VBV_fullness > rc->Bs / 2 && !rc->no_pre_skip)) /* skip the current frame */ /* rc->Bs */
+ {
+ rc->TMN_W -= (rc->Rc - rc->TMN_TH);
+ rc->VBV_fullness -= rc->Rc;
+ rc->skip_next_frame = -1;
+ }
+ else if ((float)(rc->VBV_fullness - rc->VBV_fullness_offset) > (rc->Bs / 2 - rc->VBV_fullness_offset)*0.95 &&
+ !rc->no_frame_skip) /* skip next frame */
+ {
+ rc->VBV_fullness -= frame_bits; //rc->Rp;
+ rc->skip_next_frame = 1;
+ /* skip more than 1 frames */
+ //while(rc->VBV_fullness > rc->Bs*0.475)
+ while ((rc->VBV_fullness - rc->VBV_fullness_offset) > (rc->Bs / 2 - rc->VBV_fullness_offset)*0.95)
+ {
+ rc->VBV_fullness -= frame_bits; //rc->Rp;
+ rc->skip_next_frame++;
+ }
+ /* END */
+ }
+
+}
+
+/* ======================================================================== */
+/* Function : updateRC_PostProc */
+/* Date : 04/08/2002 */
+/* Purpose : Remaing RC update stuff for frame skip and buffer underflow */
+/* check */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+void updateRC_PostProc(rateControl *rc, VideoEncData *video)
+{
+ MultiPass *pMP = video->pMP[video->currLayer];
+
+ if (rc->skip_next_frame == 1 && !rc->no_frame_skip) /* skip next frame */
+ {
+ pMP->counter_BTsrc += 10 * rc->skip_next_frame;
+
+ }
+ else if (rc->skip_next_frame == -1 && !rc->no_pre_skip) /* skip current frame */
+ {
+ pMP->counter_BTdst -= pMP->diff_counter;
+ pMP->counter_BTsrc += 10;
+
+ pMP->sum_mad -= pMP->mad;
+ pMP->aver_mad = (pMP->aver_mad * pMP->encoded_frames - pMP->mad) / (float)(pMP->encoded_frames - 1 + 0.0001);
+ pMP->sum_QP -= pMP->QP;
+ pMP->encoded_frames --;
+ }
+ /* some stuff in update VBV_fullness remains here */
+ //if(rc->VBV_fullness < -rc->Bs/2) /* rc->Bs */
+ if (rc->VBV_fullness < rc->low_bound)
+ {
+ rc->VBV_fullness = rc->low_bound; // -rc->Bs/2;
+ rc->TMN_W = rc->VBV_fullness - rc->low_bound;
+ pMP->counter_BTsrc = pMP->counter_BTdst + (Int)((float)(rc->Bs / 2 - rc->low_bound) / 2.0 / (pMP->target_bits_per_frame / 10));
+ }
+}
+
diff --git a/media/codecs/m4v_h263/enc/src/rate_control.h b/media/codecs/m4v_h263/enc/src/rate_control.h
new file mode 100644
index 0000000..ad29549
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/rate_control.h
@@ -0,0 +1,96 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _RATE_CONTROL_H_
+#define _RATE_CONTROL_H_
+
+#include "mp4def.h"
+
+typedef struct tagdataPointArray
+{
+ Int Qp;
+ Int Rp;
+ float Mp; /* for MB-based RC, 3/14/01 */
+ struct tagdataPointArray *next;
+ struct tagdataPointArray *prev;
+} dataPointArray;
+
+
+typedef struct
+{
+ Int alpha; /* weight for I frame */
+ Int Rs; /*bit rate for the sequence (or segment) e.g., 24000 bits/sec */
+ Int Rc; /*bits used for the current frame. It is the bit count obtained after encoding. */
+ Int Rp; /*bits to be removed from the buffer per picture. */
+ /*? is this the average one, or just the bits coded for the previous frame */
+ Int Rps; /*bit to be removed from buffer per src frame */
+ float Ts; /*number of seconds for the sequence (or segment). e.g., 10 sec */
+ float Ep;
+ float Ec; /*mean absolute difference for the current frame after motion compensation.*/
+ /*If the macroblock is intra coded, the original spatial pixel values are summed.*/
+ Int Qc; /*quantization level used for the current frame. */
+ Int Nr; /*number of P frames remaining for encoding.*/
+ Int Rr; /*number of bits remaining for encoding this sequence (or segment).*/
+ Int Rr_Old;/* 12/24/00 */
+ Int T; /*target bit to be used for the current frame.*/
+ Int S; /*number of bits used for encoding the previous frame.*/
+ Int Hc; /*header and motion vector bits used in the current frame. It includes all the information except to the residual information.*/
+ Int Hp; /*header and motion vector bits used in the previous frame. It includes all the information except to the residual information.*/
+ Int Ql; /*quantization level used in the previous frame */
+ Int Bs; /*buffer size e.g., R/2 */
+ Int B; /*current buffer level e.g., R/4 - start from the middle of the buffer */
+ float X1;
+ float X2;
+ float X11;
+ float M; /*safe margin for the buffer */
+ float smTick; /*ratio of src versus enc frame rate */
+ double remnant; /*remainder frame of src/enc frame for fine frame skipping */
+ Int timeIncRes; /* vol->timeIncrementResolution */
+
+ dataPointArray *end; /*quantization levels for the past (20) frames */
+
+ Int frameNumber; /* ranging from 0 to 20 nodes*/
+ Int w;
+ Int Nr_Original;
+ Int Nr_Old, Nr_Old2;
+ Int skip_next_frame;
+ Int Qdep; /* smooth Q adjustment */
+ Int fine_frame_skip;
+ Int VBR_Enabled;
+ Int no_frame_skip;
+ Int no_pre_skip;
+
+ Int totalFrameNumber; /* total coded frames, for debugging!!*/
+
+ char oFirstTime;
+
+ /* BX rate control */
+ Int TMN_W;
+ Int TMN_TH;
+ Int VBV_fullness;
+ Int max_BitVariance_num; /* the number of the maximum bit variance within the given buffer with the unit of 10% of bitrate/framerate*/
+ Int encoded_frames; /* counter for all encoded frames */
+ float framerate;
+ Int bitrate;
+ Int low_bound; /* bound for underflow detection, usually low_bound=-Bs/2, but could be changed in H.263 mode */
+ Int VBV_fullness_offset; /* offset of VBV_fullness, usually is zero, but can be changed in H.263 mode*/
+ /* End BX */
+
+} rateControl;
+
+
+#endif /* _RATE_CONTROL_H_ */
diff --git a/media/codecs/m4v_h263/enc/src/sad.cpp b/media/codecs/m4v_h263/enc/src/sad.cpp
new file mode 100644
index 0000000..8d18f45
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/sad.cpp
@@ -0,0 +1,375 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4lib_int.h"
+
+#include "sad_inline.h"
+
+#define Cached_lx 176
+
+#ifdef _SAD_STAT
+ULong num_sad_MB = 0;
+ULong num_sad_Blk = 0;
+ULong num_sad_MB_call = 0;
+ULong num_sad_Blk_call = 0;
+
+#define NUM_SAD_MB_CALL() num_sad_MB_call++
+#define NUM_SAD_MB() num_sad_MB++
+#define NUM_SAD_BLK_CALL() num_sad_Blk_call++
+#define NUM_SAD_BLK() num_sad_Blk++
+
+#else
+
+#define NUM_SAD_MB_CALL()
+#define NUM_SAD_MB()
+#define NUM_SAD_BLK_CALL()
+#define NUM_SAD_BLK()
+
+#endif
+
+
+/* consist of
+Int SAD_Macroblock_C(UChar *ref,UChar *blk,Int dmin,Int lx,void *extra_info)
+Int SAD_MB_HTFM_Collect(UChar *ref,UChar *blk,Int dmin,Int lx,void *extra_info)
+Int SAD_MB_HTFM(UChar *ref,UChar *blk,Int dmin,Int lx,void *extra_info)
+Int SAD_Block_C(UChar *ref,UChar *blk,Int dmin,Int lx,void *extra_info)
+Int SAD_Blk_PADDING(UChar *ref,UChar *cur,Int dmin,Int lx,void *extra_info)
+Int SAD_MB_PADDING(UChar *ref,UChar *cur,Int dmin,Int lx,void *extra_info)
+Int SAD_MB_PAD1(UChar *ref,UChar *cur,Int dmin,Int lx,Int *rep);
+Int SAD_MB_PADDING_HTFM_Collect(UChar *ref,UChar *cur,Int dmin,Int lx,void *extra_info)
+Int SAD_MB_PADDING_HTFM(UChar *ref,UChar *cur,Int dmin,Int lx,void *vptr)
+*/
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ Int SAD_MB_PAD1(UChar *ref, UChar *cur, Int dmin, Int lx, Int *rep);
+
+
+ /*==================================================================
+ Function: SAD_Macroblock
+ Date: 09/07/2000
+ Purpose: Compute SAD 16x16 between blk and ref.
+ To do: Uniform subsampling will be inserted later!
+ Hypothesis Testing Fast Matching to be used later!
+ Changes:
+ 11/7/00: implemented MMX
+ 1/24/01: implemented SSE
+ ==================================================================*/
+ /********** C ************/
+ Int SAD_Macroblock_C(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info)
+ {
+ int32 x10;
+ Int dmin = (ULong)dmin_lx >> 16;
+ Int lx = dmin_lx & 0xFFFF;
+
+ OSCL_UNUSED_ARG(extra_info);
+
+ NUM_SAD_MB_CALL();
+
+ x10 = simd_sad_mb(ref, blk, dmin, lx);
+
+ return x10;
+ }
+
+#ifdef HTFM /* HTFM with uniform subsampling implementation, 2/28/01 */
+ /*===============================================================
+ Function: SAD_MB_HTFM_Collect and SAD_MB_HTFM
+ Date: 3/2/1
+ Purpose: Compute the SAD on a 16x16 block using
+ uniform subsampling and hypothesis testing fast matching
+ for early dropout. SAD_MB_HP_HTFM_Collect is to collect
+ the statistics to compute the thresholds to be used in
+ SAD_MB_HP_HTFM.
+ Input/Output:
+ Changes:
+ ===============================================================*/
+
+ Int SAD_MB_HTFM_Collect(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info)
+ {
+ Int i;
+ Int sad = 0;
+ UChar *p1;
+ Int lx4 = (dmin_lx << 2) & 0x3FFFC;
+ ULong cur_word;
+ Int saddata[16], tmp, tmp2; /* used when collecting flag (global) is on */
+ Int difmad;
+ HTFM_Stat *htfm_stat = (HTFM_Stat*) extra_info;
+ Int *abs_dif_mad_avg = &(htfm_stat->abs_dif_mad_avg);
+ UInt *countbreak = &(htfm_stat->countbreak);
+ Int *offsetRef = htfm_stat->offsetRef;
+
+ NUM_SAD_MB_CALL();
+
+ blk -= 4;
+ for (i = 0; i < 16; i++)
+ {
+ p1 = ref + offsetRef[i];
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ NUM_SAD_MB();
+
+ saddata[i] = sad;
+
+ if (i > 0)
+ {
+ if ((ULong)sad > ((ULong)dmin_lx >> 16))
+ {
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+ return sad;
+ }
+ }
+ }
+
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+ return sad;
+ }
+
+ Int SAD_MB_HTFM(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info)
+ {
+ Int sad = 0;
+ UChar *p1;
+
+ Int i;
+ Int tmp, tmp2;
+ Int lx4 = (dmin_lx << 2) & 0x3FFFC;
+ Int sadstar = 0, madstar;
+ Int *nrmlz_th = (Int*) extra_info;
+ Int *offsetRef = (Int*) extra_info + 32;
+ ULong cur_word;
+
+ madstar = (ULong)dmin_lx >> 20;
+
+ NUM_SAD_MB_CALL();
+
+ blk -= 4;
+ for (i = 0; i < 16; i++)
+ {
+ p1 = ref + offsetRef[i];
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = (cur_word >> 24) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[8];
+ tmp2 = (cur_word >> 16) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[4];
+ tmp2 = (cur_word >> 8) & 0xFF;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = p1[0];
+ p1 += lx4;
+ tmp2 = (cur_word & 0xFF);
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ NUM_SAD_MB();
+
+ sadstar += madstar;
+ if (((ULong)sad <= ((ULong)dmin_lx >> 16)) && (sad <= (sadstar - *nrmlz_th++)))
+ ;
+ else
+ return 65536;
+ }
+
+ return sad;
+ }
+#endif /* HTFM */
+
+#ifndef NO_INTER4V
+ /*==================================================================
+ Function: SAD_Block
+ Date: 09/07/2000
+ Purpose: Compute SAD 16x16 between blk and ref.
+ To do: Uniform subsampling will be inserted later!
+ Hypothesis Testing Fast Matching to be used later!
+ Changes:
+ 11/7/00: implemented MMX
+ 1/24/01: implemented SSE
+ ==================================================================*/
+ /********** C ************/
+ Int SAD_Block_C(UChar *ref, UChar *blk, Int dmin, Int lx, void *)
+ {
+ Int sad = 0;
+
+ Int i;
+ UChar *ii;
+ Int *kk;
+ Int tmp, tmp2, tmp3, mask = 0xFF;
+ Int width = (lx - 32);
+
+ NUM_SAD_BLK_CALL();
+
+ ii = ref;
+ kk = (Int*)blk; /* assuming word-align for blk */
+ for (i = 0; i < 8; i++)
+ {
+ tmp3 = kk[1];
+ tmp = ii[7];
+ tmp2 = (UInt)tmp3 >> 24;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = ii[6];
+ tmp2 = (tmp3 >> 16) & mask;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = ii[5];
+ tmp2 = (tmp3 >> 8) & mask;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = ii[4];
+ tmp2 = tmp3 & mask;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp3 = *kk;
+ kk += (width >> 2);
+ tmp = ii[3];
+ tmp2 = (UInt)tmp3 >> 24;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = ii[2];
+ tmp2 = (tmp3 >> 16) & mask;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = ii[1];
+ tmp2 = (tmp3 >> 8) & mask;
+ sad = SUB_SAD(sad, tmp, tmp2);
+ tmp = *ii;
+ ii += lx;
+ tmp2 = tmp3 & mask;
+ sad = SUB_SAD(sad, tmp, tmp2);
+
+ NUM_SAD_BLK();
+
+ if (sad > dmin)
+ return sad;
+ }
+
+ return sad;
+ }
+
+#endif /* NO_INTER4V */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
diff --git a/media/codecs/m4v_h263/enc/src/sad_halfpel.cpp b/media/codecs/m4v_h263/enc/src/sad_halfpel.cpp
new file mode 100644
index 0000000..f05697c
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/sad_halfpel.cpp
@@ -0,0 +1,855 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/* contains
+Int HalfPel1_SAD_MB(UChar *ref,UChar *blk,Int dmin,Int width,Int ih,Int jh)
+Int HalfPel2_SAD_MB(UChar *ref,UChar *blk,Int dmin,Int width)
+Int HalfPel1_SAD_Blk(UChar *ref,UChar *blk,Int dmin,Int width,Int ih,Int jh)
+Int HalfPel2_SAD_Blk(UChar *ref,UChar *blk,Int dmin,Int width)
+
+Int SAD_MB_HalfPel_C(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info)
+Int SAD_MB_HP_HTFM_Collect(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info)
+Int SAD_MB_HP_HTFM(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info)
+Int SAD_Blk_HalfPel_C(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info)
+*/
+
+//#include <stdlib.h> /* for RAND_MAX */
+#include "mp4def.h"
+#include "mp4lib_int.h"
+#include "sad_halfpel_inline.h"
+
+#ifdef _SAD_STAT
+ULong num_sad_HP_MB = 0;
+ULong num_sad_HP_Blk = 0;
+ULong num_sad_HP_MB_call = 0;
+ULong num_sad_HP_Blk_call = 0;
+#define NUM_SAD_HP_MB_CALL() num_sad_HP_MB_call++
+#define NUM_SAD_HP_MB() num_sad_HP_MB++
+#define NUM_SAD_HP_BLK_CALL() num_sad_HP_Blk_call++
+#define NUM_SAD_HP_BLK() num_sad_HP_Blk++
+#else
+#define NUM_SAD_HP_MB_CALL()
+#define NUM_SAD_HP_MB()
+#define NUM_SAD_HP_BLK_CALL()
+#define NUM_SAD_HP_BLK()
+#endif
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ /*==================================================================
+ Function: HalfPel1_SAD_MB
+ Date: 03/27/2001
+ Purpose: Compute SAD 16x16 between blk and ref in halfpel
+ resolution,
+ Changes:
+ ==================================================================*/
+ /* One component is half-pel */
+ Int HalfPel1_SAD_MB(UChar *ref, UChar *blk, Int dmin, Int width, Int ih, Int jh)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1, *p2;
+ Int temp;
+
+ OSCL_UNUSED_ARG(jh);
+
+ p1 = ref;
+ if (ih) p2 = ref + 1;
+ else p2 = ref + width;
+ kk = blk;
+
+ for (i = 0; i < 16; i++)
+ {
+ for (j = 0; j < 16; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + 1) >> 1) - *kk++;
+ sad += PV_ABS(temp);
+ }
+
+ if (sad > dmin)
+ return sad;
+ p1 += width;
+ p2 += width;
+ }
+ return sad;
+ }
+
+ /* Two components need half-pel */
+ Int HalfPel2_SAD_MB(UChar *ref, UChar *blk, Int dmin, Int width)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1, *p2, *p3, *p4;
+ Int temp;
+
+ p1 = ref;
+ p2 = ref + 1;
+ p3 = ref + width;
+ p4 = ref + width + 1;
+ kk = blk;
+
+ for (i = 0; i < 16; i++)
+ {
+ for (j = 0; j < 16; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - *kk++;
+ sad += PV_ABS(temp);
+ }
+
+ if (sad > dmin)
+ return sad;
+
+ p1 += width;
+ p3 += width;
+ p2 += width;
+ p4 += width;
+ }
+ return sad;
+ }
+
+#ifndef NO_INTER4V
+ /*==================================================================
+ Function: HalfPel1_SAD_Blk
+ Date: 03/27/2001
+ Purpose: Compute SAD 8x8 between blk and ref in halfpel
+ resolution.
+ Changes:
+ ==================================================================*/
+ /* One component needs half-pel */
+ Int HalfPel1_SAD_Blk(UChar *ref, UChar *blk, Int dmin, Int width, Int ih, Int jh)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1, *p2;
+ Int temp;
+
+ OSCL_UNUSED_ARG(jh);
+
+ p1 = ref;
+ if (ih) p2 = ref + 1;
+ else p2 = ref + width;
+ kk = blk;
+
+ for (i = 0; i < 8; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + 1) >> 1) - *kk++;
+ sad += PV_ABS(temp);
+ }
+
+ if (sad > dmin)
+ return sad;
+ p1 += width;
+ p2 += width;
+ kk += 8;
+ }
+ return sad;
+ }
+ /* Two components need half-pel */
+ Int HalfPel2_SAD_Blk(UChar *ref, UChar *blk, Int dmin, Int width)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1, *p2, *p3, *p4;
+ Int temp;
+
+ p1 = ref;
+ p2 = ref + 1;
+ p3 = ref + width;
+ p4 = ref + width + 1;
+ kk = blk;
+
+ for (i = 0; i < 8; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - *kk++;
+ sad += PV_ABS(temp);
+ }
+
+ if (sad > dmin)
+ return sad;
+
+ p1 += width;
+ p3 += width;
+ p2 += width;
+ p4 += width;
+ kk += 8;
+ }
+ return sad;
+ }
+#endif // NO_INTER4V
+ /*===============================================================
+ Function: SAD_MB_HalfPel
+ Date: 09/17/2000
+ Purpose: Compute the SAD on the half-pel resolution
+ Input/Output: hmem is assumed to be a pointer to the starting
+ point of the search in the 33x33 matrix search region
+ Changes:
+ 11/7/00: implemented MMX
+ ===============================================================*/
+ /*==================================================================
+ Function: SAD_MB_HalfPel_C
+ Date: 04/30/2001
+ Purpose: Compute SAD 16x16 between blk and ref in halfpel
+ resolution,
+ Changes:
+ ==================================================================*/
+ /* One component is half-pel */
+ Int SAD_MB_HalfPel_Cxhyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1, *p2, *p3, *p4;
+// Int sumref=0;
+ Int temp;
+ Int rx = dmin_rx & 0xFFFF;
+
+ OSCL_UNUSED_ARG(extra_info);
+
+ NUM_SAD_HP_MB_CALL();
+
+ p1 = ref;
+ p2 = ref + 1;
+ p3 = ref + rx;
+ p4 = ref + rx + 1;
+ kk = blk;
+
+ for (i = 0; i < 16; i++)
+ {
+ for (j = 0; j < 16; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - *kk++;
+ sad += PV_ABS(temp);
+ }
+
+ NUM_SAD_HP_MB();
+
+ if (sad > (Int)((ULong)dmin_rx >> 16))
+ return sad;
+
+ p1 += rx;
+ p3 += rx;
+ p2 += rx;
+ p4 += rx;
+ }
+ return sad;
+ }
+
+ Int SAD_MB_HalfPel_Cyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1, *p2;
+// Int sumref=0;
+ Int temp;
+ Int rx = dmin_rx & 0xFFFF;
+
+ OSCL_UNUSED_ARG(extra_info);
+
+ NUM_SAD_HP_MB_CALL();
+
+ p1 = ref;
+ p2 = ref + rx; /* either left/right or top/bottom pixel */
+ kk = blk;
+
+ for (i = 0; i < 16; i++)
+ {
+ for (j = 0; j < 16; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + 1) >> 1) - *kk++;
+ sad += PV_ABS(temp);
+ }
+
+ NUM_SAD_HP_MB();
+
+ if (sad > (Int)((ULong)dmin_rx >> 16))
+ return sad;
+ p1 += rx;
+ p2 += rx;
+ }
+ return sad;
+ }
+
+ Int SAD_MB_HalfPel_Cxh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1;
+// Int sumref=0;
+ Int temp;
+ Int rx = dmin_rx & 0xFFFF;
+
+ OSCL_UNUSED_ARG(extra_info);
+
+ NUM_SAD_HP_MB_CALL();
+
+ p1 = ref;
+ kk = blk;
+
+ for (i = 0; i < 16; i++)
+ {
+ for (j = 0; j < 16; j++)
+ {
+
+ temp = ((p1[j] + p1[j+1] + 1) >> 1) - *kk++;
+ sad += PV_ABS(temp);
+ }
+
+ NUM_SAD_HP_MB();
+
+ if (sad > (Int)((ULong)dmin_rx >> 16))
+ return sad;
+ p1 += rx;
+ }
+ return sad;
+ }
+
+#ifdef HTFM /* HTFM with uniform subsampling implementation, 2/28/01 */
+
+//Checheck here
+ Int SAD_MB_HP_HTFM_Collectxhyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *p1, *p2;
+ Int rx = dmin_rx & 0xFFFF;
+ Int refwx4 = rx << 2;
+ Int saddata[16]; /* used when collecting flag (global) is on */
+ Int difmad, tmp, tmp2;
+ HTFM_Stat *htfm_stat = (HTFM_Stat*) extra_info;
+ Int *abs_dif_mad_avg = &(htfm_stat->abs_dif_mad_avg);
+ UInt *countbreak = &(htfm_stat->countbreak);
+ Int *offsetRef = htfm_stat->offsetRef;
+ ULong cur_word;
+
+ NUM_SAD_HP_MB_CALL();
+
+ blk -= 4;
+
+ for (i = 0; i < 16; i++) /* 16 stages */
+ {
+ p1 = ref + offsetRef[i];
+ p2 = p1 + rx;
+
+ j = 4;/* 4 lines */
+ do
+ {
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12] + p2[12];
+ tmp2 = p1[13] + p2[13];
+ tmp += tmp2;
+ tmp2 = (cur_word >> 24) & 0xFF;
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[8] + p2[8];
+ tmp2 = p1[9] + p2[9];
+ tmp += tmp2;
+ tmp2 = (cur_word >> 16) & 0xFF;
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[4] + p2[4];
+ tmp2 = p1[5] + p2[5];
+ tmp += tmp2;
+ tmp2 = (cur_word >> 8) & 0xFF;
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ tmp2 = p1[1] + p2[1];
+ tmp = p1[0] + p2[0];
+ p1 += refwx4;
+ p2 += refwx4;
+ tmp += tmp2;
+ tmp2 = (cur_word & 0xFF);
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ }
+ while (--j);
+
+ NUM_SAD_HP_MB();
+
+ saddata[i] = sad;
+
+ if (i > 0)
+ {
+ if (sad > (Int)((ULong)dmin_rx >> 16))
+ {
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+ return sad;
+ }
+ }
+ }
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+
+ return sad;
+ }
+
+ Int SAD_MB_HP_HTFM_Collectyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *p1, *p2;
+ Int rx = dmin_rx & 0xFFFF;
+ Int refwx4 = rx << 2;
+ Int saddata[16]; /* used when collecting flag (global) is on */
+ Int difmad, tmp, tmp2;
+ HTFM_Stat *htfm_stat = (HTFM_Stat*) extra_info;
+ Int *abs_dif_mad_avg = &(htfm_stat->abs_dif_mad_avg);
+ UInt *countbreak = &(htfm_stat->countbreak);
+ Int *offsetRef = htfm_stat->offsetRef;
+ ULong cur_word;
+
+ NUM_SAD_HP_MB_CALL();
+
+ blk -= 4;
+
+ for (i = 0; i < 16; i++) /* 16 stages */
+ {
+ p1 = ref + offsetRef[i];
+ p2 = p1 + rx;
+ j = 4;
+ do
+ {
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = p2[12];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 24) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[8];
+ tmp2 = p2[8];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 16) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[4];
+ tmp2 = p2[4];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 8) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[0];
+ p1 += refwx4;
+ tmp2 = p2[0];
+ p2 += refwx4;
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word & 0xFF);
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ }
+ while (--j);
+
+ NUM_SAD_HP_MB();
+
+ saddata[i] = sad;
+
+ if (i > 0)
+ {
+ if (sad > (Int)((ULong)dmin_rx >> 16))
+ {
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+ return sad;
+ }
+ }
+ }
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+
+ return sad;
+ }
+
+ Int SAD_MB_HP_HTFM_Collectxh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *p1;
+ Int rx = dmin_rx & 0xFFFF;
+ Int refwx4 = rx << 2;
+ Int saddata[16]; /* used when collecting flag (global) is on */
+ Int difmad, tmp, tmp2;
+ HTFM_Stat *htfm_stat = (HTFM_Stat*) extra_info;
+ Int *abs_dif_mad_avg = &(htfm_stat->abs_dif_mad_avg);
+ UInt *countbreak = &(htfm_stat->countbreak);
+ Int *offsetRef = htfm_stat->offsetRef;
+ ULong cur_word;
+
+ NUM_SAD_HP_MB_CALL();
+
+ blk -= 4;
+
+ for (i = 0; i < 16; i++) /* 16 stages */
+ {
+ p1 = ref + offsetRef[i];
+
+ j = 4; /* 4 lines */
+ do
+ {
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = p1[13];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 24) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[8];
+ tmp2 = p1[9];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 16) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[4];
+ tmp2 = p1[5];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 8) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[0];
+ tmp2 = p1[1];
+ p1 += refwx4;
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word & 0xFF);
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ }
+ while (--j);
+
+ NUM_SAD_HP_MB();
+
+ saddata[i] = sad;
+
+ if (i > 0)
+ {
+ if (sad > (Int)((ULong)dmin_rx >> 16))
+ {
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+ return sad;
+ }
+ }
+ }
+ difmad = saddata[0] - ((saddata[1] + 1) >> 1);
+ (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad);
+ (*countbreak)++;
+
+ return sad;
+ }
+
+ Int SAD_MB_HP_HTFMxhyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0, tmp, tmp2;
+ UChar *p1, *p2;
+ Int rx = dmin_rx & 0xFFFF;
+ Int refwx4 = rx << 2;
+ Int sadstar = 0, madstar;
+ Int *nrmlz_th = (Int*) extra_info;
+ Int *offsetRef = nrmlz_th + 32;
+ ULong cur_word;
+
+ madstar = (ULong)dmin_rx >> 20;
+
+ NUM_SAD_HP_MB_CALL();
+
+ blk -= 4;
+
+ for (i = 0; i < 16; i++) /* 16 stages */
+ {
+ p1 = ref + offsetRef[i];
+ p2 = p1 + rx;
+
+ j = 4; /* 4 lines */
+ do
+ {
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12] + p2[12];
+ tmp2 = p1[13] + p2[13];
+ tmp += tmp2;
+ tmp2 = (cur_word >> 24) & 0xFF;
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[8] + p2[8];
+ tmp2 = p1[9] + p2[9];
+ tmp += tmp2;
+ tmp2 = (cur_word >> 16) & 0xFF;
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[4] + p2[4];
+ tmp2 = p1[5] + p2[5];
+ tmp += tmp2;
+ tmp2 = (cur_word >> 8) & 0xFF;
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ tmp2 = p1[1] + p2[1];
+ tmp = p1[0] + p2[0];
+ p1 += refwx4;
+ p2 += refwx4;
+ tmp += tmp2;
+ tmp2 = (cur_word & 0xFF);
+ tmp += 2;
+ sad = INTERP2_SUB_SAD(sad, tmp, tmp2);;
+ }
+ while (--j);
+
+ NUM_SAD_HP_MB();
+
+ sadstar += madstar;
+ if (sad > sadstar - nrmlz_th[i] || sad > (Int)((ULong)dmin_rx >> 16))
+ {
+ return 65536;
+ }
+ }
+
+ return sad;
+ }
+
+ Int SAD_MB_HP_HTFMyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0, tmp, tmp2;
+ UChar *p1, *p2;
+ Int rx = dmin_rx & 0xFFFF;
+ Int refwx4 = rx << 2;
+ Int sadstar = 0, madstar;
+ Int *nrmlz_th = (Int*) extra_info;
+ Int *offsetRef = nrmlz_th + 32;
+ ULong cur_word;
+
+ madstar = (ULong)dmin_rx >> 20;
+
+ NUM_SAD_HP_MB_CALL();
+
+ blk -= 4;
+
+ for (i = 0; i < 16; i++) /* 16 stages */
+ {
+ p1 = ref + offsetRef[i];
+ p2 = p1 + rx;
+ j = 4;
+ do
+ {
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = p2[12];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 24) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[8];
+ tmp2 = p2[8];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 16) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[4];
+ tmp2 = p2[4];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 8) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[0];
+ p1 += refwx4;
+ tmp2 = p2[0];
+ p2 += refwx4;
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word & 0xFF);
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ }
+ while (--j);
+
+ NUM_SAD_HP_MB();
+ sadstar += madstar;
+ if (sad > sadstar - nrmlz_th[i] || sad > (Int)((ULong)dmin_rx >> 16))
+ {
+ return 65536;
+ }
+ }
+
+ return sad;
+ }
+
+ Int SAD_MB_HP_HTFMxh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0, tmp, tmp2;
+ UChar *p1;
+ Int rx = dmin_rx & 0xFFFF;
+ Int refwx4 = rx << 2;
+ Int sadstar = 0, madstar;
+ Int *nrmlz_th = (Int*) extra_info;
+ Int *offsetRef = nrmlz_th + 32;
+ ULong cur_word;
+
+ madstar = (ULong)dmin_rx >> 20;
+
+ NUM_SAD_HP_MB_CALL();
+
+ blk -= 4;
+
+ for (i = 0; i < 16; i++) /* 16 stages */
+ {
+ p1 = ref + offsetRef[i];
+
+ j = 4;/* 4 lines */
+ do
+ {
+ cur_word = *((ULong*)(blk += 4));
+ tmp = p1[12];
+ tmp2 = p1[13];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 24) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[8];
+ tmp2 = p1[9];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 16) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[4];
+ tmp2 = p1[5];
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word >> 8) & 0xFF;
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ tmp = p1[0];
+ tmp2 = p1[1];
+ p1 += refwx4;
+ tmp++;
+ tmp2 += tmp;
+ tmp = (cur_word & 0xFF);
+ sad = INTERP1_SUB_SAD(sad, tmp, tmp2);;
+ }
+ while (--j);
+
+ NUM_SAD_HP_MB();
+
+ sadstar += madstar;
+ if (sad > sadstar - nrmlz_th[i] || sad > (Int)((ULong)dmin_rx >> 16))
+ {
+ return 65536;
+ }
+ }
+
+ return sad;
+ }
+
+#endif /* HTFM */
+
+#ifndef NO_INTER4V
+ /*==================================================================
+ Function: SAD_Blk_HalfPel_C
+ Date: 04/30/2001
+ Purpose: Compute SAD 16x16 between blk and ref in halfpel
+ resolution,
+ Changes:
+ ==================================================================*/
+ /* One component is half-pel */
+ Int SAD_Blk_HalfPel_C(UChar *ref, UChar *blk, Int dmin, Int width, Int rx, Int xh, Int yh, void *extra_info)
+ {
+ Int i, j;
+ Int sad = 0;
+ UChar *kk, *p1, *p2, *p3, *p4;
+ Int temp;
+
+ OSCL_UNUSED_ARG(extra_info);
+
+ NUM_SAD_HP_BLK_CALL();
+
+ if (xh && yh)
+ {
+ p1 = ref;
+ p2 = ref + xh;
+ p3 = ref + yh * rx;
+ p4 = ref + yh * rx + xh;
+ kk = blk;
+
+ for (i = 0; i < 8; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - kk[j];
+ sad += PV_ABS(temp);
+ }
+
+ NUM_SAD_HP_BLK();
+
+ if (sad > dmin)
+ return sad;
+
+ p1 += rx;
+ p3 += rx;
+ p2 += rx;
+ p4 += rx;
+ kk += width;
+ }
+ return sad;
+ }
+ else
+ {
+ p1 = ref;
+ p2 = ref + xh + yh * rx; /* either left/right or top/bottom pixel */
+
+ kk = blk;
+
+ for (i = 0; i < 8; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+
+ temp = ((p1[j] + p2[j] + 1) >> 1) - kk[j];
+ sad += PV_ABS(temp);
+ }
+
+ NUM_SAD_HP_BLK();
+
+ if (sad > dmin)
+ return sad;
+ p1 += rx;
+ p2 += rx;
+ kk += width;
+ }
+ return sad;
+ }
+ }
+#endif /* NO_INTER4V */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
diff --git a/media/codecs/m4v_h263/enc/src/sad_halfpel_inline.h b/media/codecs/m4v_h263/enc/src/sad_halfpel_inline.h
new file mode 100644
index 0000000..d55778f
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/sad_halfpel_inline.h
@@ -0,0 +1,130 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*********************************************************************************/
+/* Filename: sad_halfpel_inline.h */
+/* Description: Implementation for in-line functions used in dct.cpp */
+/* Modified: */
+/*********************************************************************************/
+
+#ifndef _SAD_HALFPEL_INLINE_H_
+#define _SAD_HALFPEL_INLINE_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) /* ARM GNU COMPILER */
+
+ __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ tmp = (tmp2 >> 1) - tmp;
+ if (tmp > 0) sad += tmp;
+ else sad -= tmp;
+
+ return sad;
+ }
+
+ __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ tmp = (tmp >> 2) - tmp2;
+ if (tmp > 0) sad += tmp;
+ else sad -= tmp;
+
+ return sad;
+ }
+
+#elif defined(__CC_ARM) /* only work with arm v5 */
+
+ __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ __asm
+ {
+ rsbs tmp, tmp, tmp2, asr #1 ;
+ rsbmi tmp, tmp, #0 ;
+ add sad, sad, tmp ;
+ }
+
+ return sad;
+ }
+
+ __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ __asm
+ {
+ rsbs tmp, tmp2, tmp, asr #2 ;
+ rsbmi tmp, tmp, #0 ;
+ add sad, sad, tmp ;
+ }
+
+ return sad;
+ }
+
+#elif ( defined(PV_ARM_GCC_V5) || defined(PV_ARM_GCC_V4) ) /* ARM GNU COMPILER */
+
+
+ __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ register int32 out;
+ register int32 temp1;
+ register int32 ss = sad;
+ register int32 tt = tmp;
+ register int32 uu = tmp2;
+
+ asm volatile("rsbs %1, %3, %4, asr #1\n\t"
+ "rsbmi %1, %1, #0\n\t"
+ "add %0, %2, %1"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(ss),
+ "r"(tt),
+ "r"(uu));
+ return out;
+ }
+
+
+ __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+{
+ register int32 out;
+ register int32 temp1;
+ register int32 ss = sad;
+ register int32 tt = tmp;
+ register int32 uu = tmp2;
+
+ asm volatile("rsbs %1, %4, %3, asr #2\n\t"
+ "rsbmi %1, %1, #0\n\t"
+ "add %0, %2, %1"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(ss),
+ "r"(tt),
+ "r"(uu));
+ return out;
+ }
+
+
+#endif // Diff OS
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //_SAD_HALFPEL_INLINE_H_
+
diff --git a/media/codecs/m4v_h263/enc/src/sad_inline.h b/media/codecs/m4v_h263/enc/src/sad_inline.h
new file mode 100644
index 0000000..b865f23
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/sad_inline.h
@@ -0,0 +1,539 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*********************************************************************************/
+/* Filename: sad_inline.h */
+/* Description: Implementation for in-line functions used in dct.cpp */
+/* Modified: */
+/*********************************************************************************/
+#ifndef _SAD_INLINE_H_
+#define _SAD_INLINE_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) /* ARM GNU COMPILER */
+
+ __inline int32 SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ tmp = tmp - tmp2;
+ if (tmp > 0) sad += tmp;
+ else sad -= tmp;
+
+ return sad;
+ }
+
+ __inline int32 sad_4pixel(int32 src1, int32 src2, int32 mask)
+ {
+ int32 x7;
+
+ x7 = src2 ^ src1; /* check odd/even combination */
+ if ((uint32)src2 >= (uint32)src1)
+ {
+ src1 = src2 - src1; /* subs */
+ }
+ else
+ {
+ src1 = src1 - src2;
+ }
+ x7 = x7 ^ src1; /* only odd bytes need to add carry */
+ x7 = mask & ((uint32)x7 >> 1);
+ x7 = (x7 << 8) - x7;
+ src1 = src1 + (x7 >> 7); /* add 0xFF to the negative byte, add back carry */
+ src1 = src1 ^(x7 >> 7); /* take absolute value of negative byte */
+
+ return src1;
+ }
+
+#define NUMBER 3
+#define SHIFT 24
+
+#include "sad_mb_offset.h"
+
+#undef NUMBER
+#define NUMBER 2
+#undef SHIFT
+#define SHIFT 16
+#include "sad_mb_offset.h"
+
+#undef NUMBER
+#define NUMBER 1
+#undef SHIFT
+#define SHIFT 8
+#include "sad_mb_offset.h"
+
+
+ __inline int32 simd_sad_mb(UChar *ref, UChar *blk, Int dmin, Int lx)
+ {
+ int32 x4, x5, x6, x8, x9, x10, x11, x12, x14;
+
+ x9 = 0x80808080; /* const. */
+
+ x8 = (uintptr_t)ref & 0x3;
+ if (x8 == 3)
+ goto SadMBOffset3;
+ if (x8 == 2)
+ goto SadMBOffset2;
+ if (x8 == 1)
+ goto SadMBOffset1;
+
+// x5 = (x4<<8)-x4; /* x5 = x4*255; */
+ x4 = x5 = 0;
+
+ x6 = 0xFFFF00FF;
+
+ ref -= lx;
+ blk -= 16;
+
+ x8 = 16;
+
+LOOP_SAD0:
+ /****** process 8 pixels ******/
+ x10 = *((uint32*)(ref += lx));
+ x11 = *((uint32*)(ref + 4));
+ x12 = *((uint32*)(blk += 16));
+ x14 = *((uint32*)(blk + 4));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ /****** process 8 pixels ******/
+ x10 = *((uint32*)(ref + 8));
+ x11 = *((uint32*)(ref + 12));
+ x12 = *((uint32*)(blk + 8));
+ x14 = *((uint32*)(blk + 12));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ /****************/
+ x10 = x5 - (x4 << 8); /* extract low bytes */
+ x10 = x10 + x4; /* add with high bytes */
+ x10 = x10 + (x10 << 16); /* add with lower half word */
+
+ if (((uint32)x10 >> 16) <= (uint32)dmin) /* compare with dmin */
+ {
+ if (--x8)
+ {
+ goto LOOP_SAD0;
+ }
+
+ }
+
+ return ((uint32)x10 >> 16);
+
+SadMBOffset3:
+
+ return sad_mb_offset3(ref, blk, lx, dmin);
+
+SadMBOffset2:
+
+ return sad_mb_offset2(ref, blk, lx, dmin);
+
+SadMBOffset1:
+
+ return sad_mb_offset1(ref, blk, lx, dmin);
+
+ }
+
+#elif defined(__CC_ARM) /* only work with arm v5 */
+
+ __inline int32 SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ __asm
+ {
+ rsbs tmp, tmp, tmp2 ;
+ rsbmi tmp, tmp, #0 ;
+ add sad, sad, tmp ;
+ }
+
+ return sad;
+ }
+
+ __inline int32 sad_4pixel(int32 src1, int32 src2, int32 mask)
+ {
+ int32 x7;
+
+ __asm
+ {
+ EOR x7, src2, src1; /* check odd/even combination */
+ SUBS src1, src2, src1;
+ EOR x7, x7, src1;
+ AND x7, mask, x7, lsr #1;
+ ORRCC x7, x7, #0x80000000;
+ RSB x7, x7, x7, lsl #8;
+ ADD src1, src1, x7, asr #7; /* add 0xFF to the negative byte, add back carry */
+ EOR src1, src1, x7, asr #7; /* take absolute value of negative byte */
+ }
+
+ return src1;
+ }
+
+ __inline int32 sad_4pixelN(int32 src1, int32 src2, int32 mask)
+ {
+ int32 x7;
+
+ __asm
+ {
+ EOR x7, src2, src1; /* check odd/even combination */
+ ADDS src1, src2, src1;
+ EOR x7, x7, src1; /* only odd bytes need to add carry */
+ ANDS x7, mask, x7, rrx;
+ RSB x7, x7, x7, lsl #8;
+ SUB src1, src1, x7, asr #7; /* add 0xFF to the negative byte, add back carry */
+ EOR src1, src1, x7, asr #7; /* take absolute value of negative byte */
+ }
+
+ return src1;
+ }
+
+#define sum_accumulate __asm{ SBC x5, x5, x10; /* accumulate low bytes */ \
+ BIC x10, x6, x10; /* x10 & 0xFF00FF00 */ \
+ ADD x4, x4, x10,lsr #8; /* accumulate high bytes */ \
+ SBC x5, x5, x11; /* accumulate low bytes */ \
+ BIC x11, x6, x11; /* x11 & 0xFF00FF00 */ \
+ ADD x4, x4, x11,lsr #8; } /* accumulate high bytes */
+
+
+#define NUMBER 3
+#define SHIFT 24
+#define INC_X8 0x08000001
+
+#include "sad_mb_offset.h"
+
+#undef NUMBER
+#define NUMBER 2
+#undef SHIFT
+#define SHIFT 16
+#undef INC_X8
+#define INC_X8 0x10000001
+#include "sad_mb_offset.h"
+
+#undef NUMBER
+#define NUMBER 1
+#undef SHIFT
+#define SHIFT 8
+#undef INC_X8
+#define INC_X8 0x08000001
+#include "sad_mb_offset.h"
+
+
+ __inline int32 simd_sad_mb(UChar *ref, UChar *blk, Int dmin, Int lx)
+ {
+ int32 x4, x5, x6, x8, x9, x10, x11, x12, x14;
+
+ x9 = 0x80808080; /* const. */
+ x4 = x5 = 0;
+
+ __asm
+ {
+ MOVS x8, ref, lsl #31 ;
+ BHI SadMBOffset3;
+ BCS SadMBOffset2;
+ BMI SadMBOffset1;
+
+ MVN x6, #0xFF00;
+ }
+LOOP_SAD0:
+ /****** process 8 pixels ******/
+ x11 = *((int32*)(ref + 12));
+ x10 = *((int32*)(ref + 8));
+ x14 = *((int32*)(blk + 12));
+ x12 = *((int32*)(blk + 8));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ __asm
+ {
+ /****** process 8 pixels ******/
+ LDR x11, [ref, #4];
+ LDR x10, [ref], lx ;
+ LDR x14, [blk, #4];
+ LDR x12, [blk], #16 ;
+ }
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ /****************/
+ x10 = x5 - (x4 << 8); /* extract low bytes */
+ x10 = x10 + x4; /* add with high bytes */
+ x10 = x10 + (x10 << 16); /* add with lower half word */
+
+ __asm
+ {
+ /****************/
+ RSBS x11, dmin, x10, lsr #16;
+ ADDLSS x8, x8, #0x10000001;
+ BLS LOOP_SAD0;
+ }
+
+ return ((uint32)x10 >> 16);
+
+SadMBOffset3:
+
+ return sad_mb_offset3(ref, blk, lx, dmin, x8);
+
+SadMBOffset2:
+
+ return sad_mb_offset2(ref, blk, lx, dmin, x8);
+
+SadMBOffset1:
+
+ return sad_mb_offset1(ref, blk, lx, dmin, x8);
+ }
+
+
+#elif ( defined(PV_ARM_GCC_V5) || defined(PV_ARM_GCC_V4) ) /* ARM GNU COMPILER */
+
+ __inline int32 SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
+ {
+ register int32 out;
+ register int32 temp1;
+ register int32 ss = sad;
+ register int32 tt = tmp;
+ register int32 uu = tmp2;
+
+ asm volatile("rsbs %1, %4, %3\n\t"
+ "rsbmi %1, %1, #0\n\t"
+ "add %0, %2, %1"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(ss),
+ "r"(tt),
+ "r"(uu));
+ return out;
+ }
+
+ __inline int32 sad_4pixel(int32 src1, int32 src2, int32 mask)
+{
+ register int32 out;
+ register int32 temp1;
+ register int32 s1 = src1;
+ register int32 s2 = src2;
+ register int32 mm = mask;
+
+ asm volatile("eor %0, %3, %2\n\t"
+ "subs %1, %3, %2\n\t"
+ "eor %0, %0, %1\n\t"
+ "and %0, %4, %0, lsr #1\n\t"
+ "orrcc %0, %0, #0x80000000\n\t"
+ "rsb %0, %0, %0, lsl #8\n\t"
+ "add %1, %1, %0, asr #7\n\t"
+ "eor %1, %1, %0, asr #7"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(s1),
+ "r"(s2),
+ "r"(mm));
+
+ return temp1;
+ }
+
+ __inline int32 sad_4pixelN(int32 src1, int32 src2, int32 mask)
+{
+ register int32 out;
+ register int32 temp1;
+ register int32 s1 = src1;
+ register int32 s2 = src2;
+ register int32 mm = mask;
+
+ asm volatile("eor %1, %3, %2\n\t"
+ "adds %0, %3, %2\n\t"
+ "eor %1, %1, %0\n\t"
+ "ands %1, %4, %1,rrx\n\t"
+ "rsb %1, %1, %1, lsl #8\n\t"
+ "sub %0, %0, %1, asr #7\n\t"
+ "eor %0, %0, %1, asr #7"
+ : "=&r"(out),
+ "=&r"(temp1)
+ : "r"(s1),
+ "r"(s2),
+ "r"(mm));
+
+ return (out);
+ }
+
+#define sum_accumulate asm volatile("sbc %0, %0, %1\n\t" \
+ "bic %1, %4, %1\n\t" \
+ "add %2, %2, %1, lsr #8\n\t" \
+ "sbc %0, %0, %3\n\t" \
+ "bic %3, %4, %3\n\t" \
+ "add %2, %2, %3, lsr #8" \
+ :"+r"(x5), "+r"(x10), "+r"(x4), "+r"(x11) \
+ :"r"(x6));
+
+#define NUMBER 3
+#define SHIFT 24
+#define INC_X8 0x08000001
+
+#include "sad_mb_offset.h"
+
+#undef NUMBER
+#define NUMBER 2
+#undef SHIFT
+#define SHIFT 16
+#undef INC_X8
+#define INC_X8 0x10000001
+#include "sad_mb_offset.h"
+
+#undef NUMBER
+#define NUMBER 1
+#undef SHIFT
+#define SHIFT 8
+#undef INC_X8
+#define INC_X8 0x08000001
+#include "sad_mb_offset.h"
+
+
+ __inline int32 simd_sad_mb(UChar *ref, UChar *blk, Int dmin, Int lx)
+{
+ int32 x4, x5, x6, x8, x9, x10, x11, x12, x14;
+
+ x9 = 0x80808080; /* const. */
+ x4 = x5 = 0;
+
+ x8 = (uint32)ref & 0x3;
+ if (x8 == 3)
+ goto SadMBOffset3;
+ if (x8 == 2)
+ goto SadMBOffset2;
+ if (x8 == 1)
+ goto SadMBOffset1;
+
+asm volatile("mvn %0, #0xFF00": "=r"(x6));
+
+LOOP_SAD0:
+ /****** process 8 pixels ******/
+ x11 = *((int32*)(ref + 12));
+ x10 = *((int32*)(ref + 8));
+ x14 = *((int32*)(blk + 12));
+ x12 = *((int32*)(blk + 8));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ asm volatile("ldr %0, [%4, #4]\n\t"
+ "ldr %1, [%4], %6\n\t"
+ "ldr %2, [%5, #4]\n\t"
+ "ldr %3, [%5], #16"
+ : "=r"(x11), "=r"(x10), "=r"(x14), "=r"(x12), "+r"(ref), "+r"(blk)
+ : "r"(lx));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ /****************/
+ x10 = x5 - (x4 << 8); /* extract low bytes */
+ x10 = x10 + x4; /* add with high bytes */
+ x10 = x10 + (x10 << 16); /* add with lower half word */
+
+ if (((uint32)x10 >> 16) <= (uint32)dmin) /* compare with dmin */
+ {
+ if (--x8)
+ {
+ goto LOOP_SAD0;
+ }
+
+ }
+
+ return ((uint32)x10 >> 16);
+
+SadMBOffset3:
+
+ return sad_mb_offset3(ref, blk, lx, dmin);
+
+SadMBOffset2:
+
+ return sad_mb_offset2(ref, blk, lx, dmin);
+
+SadMBOffset1:
+
+ return sad_mb_offset1(ref, blk, lx, dmin);
+ }
+
+#endif // OS
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _SAD_INLINE_H_
+
diff --git a/media/codecs/m4v_h263/enc/src/sad_mb_offset.h b/media/codecs/m4v_h263/enc/src/sad_mb_offset.h
new file mode 100644
index 0000000..4c7b929
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/sad_mb_offset.h
@@ -0,0 +1,317 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*********************************************************************************/
+/* Filename: sad_mb_offset.h */
+/* Description: Implementation for in-line functions used in dct.cpp */
+/* Modified: */
+/*********************************************************************************/
+
+#if !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_GCC_V5) /* ARM GNU COMPILER */
+
+#if (NUMBER==3)
+__inline int32 sad_mb_offset3(UChar *ref, UChar *blk, Int lx, Int dmin)
+#elif (NUMBER==2)
+__inline int32 sad_mb_offset2(UChar *ref, UChar *blk, Int lx, Int dmin)
+#elif (NUMBER==1)
+__inline int32 sad_mb_offset1(UChar *ref, UChar *blk, Int lx, Int dmin)
+#endif
+{
+ int32 x4, x5, x6, x8, x9, x10, x11, x12, x14;
+
+ // x5 = (x4<<8) - x4;
+ x4 = x5 = 0;
+ x6 = 0xFFFF00FF;
+ x9 = 0x80808080; /* const. */
+ ref -= NUMBER; /* bic ref, ref, #3 */
+ ref -= lx;
+ blk -= 16;
+ x8 = 16;
+
+#if (NUMBER==3)
+LOOP_SAD3:
+#elif (NUMBER==2)
+LOOP_SAD2:
+#elif (NUMBER==1)
+LOOP_SAD1:
+#endif
+ /****** process 8 pixels ******/
+ x10 = *((uint32*)(ref += lx)); /* D C B A */
+ x11 = *((uint32*)(ref + 4)); /* H G F E */
+ x12 = *((uint32*)(ref + 8)); /* L K J I */
+
+ x10 = ((uint32)x10 >> SHIFT); /* 0 0 0 D */
+ x10 = x10 | (x11 << (32 - SHIFT)); /* G F E D */
+ x11 = ((uint32)x11 >> SHIFT); /* 0 0 0 H */
+ x11 = x11 | (x12 << (32 - SHIFT)); /* K J I H */
+
+ x12 = *((uint32*)(blk += 16));
+ x14 = *((uint32*)(blk + 4));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ /****** process 8 pixels ******/
+ x10 = *((uint32*)(ref + 8)); /* D C B A */
+ x11 = *((uint32*)(ref + 12)); /* H G F E */
+ x12 = *((uint32*)(ref + 16)); /* L K J I */
+
+ x10 = ((uint32)x10 >> SHIFT); /* mvn x10, x10, lsr #24 = 0xFF 0xFF 0xFF ~D */
+ x10 = x10 | (x11 << (32 - SHIFT)); /* bic x10, x10, x11, lsl #8 = ~G ~F ~E ~D */
+ x11 = ((uint32)x11 >> SHIFT); /* 0xFF 0xFF 0xFF ~H */
+ x11 = x11 | (x12 << (32 - SHIFT)); /* ~K ~J ~I ~H */
+
+ x12 = *((uint32*)(blk + 8));
+ x14 = *((uint32*)(blk + 12));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ x5 = x5 + x10; /* accumulate low bytes */
+ x10 = x10 & (x6 << 8); /* x10 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x10 >> 8); /* accumulate high bytes */
+ x5 = x5 + x11; /* accumulate low bytes */
+ x11 = x11 & (x6 << 8); /* x11 & 0xFF00FF00 */
+ x4 = x4 + ((uint32)x11 >> 8); /* accumulate high bytes */
+
+ /****************/
+ x10 = x5 - (x4 << 8); /* extract low bytes */
+ x10 = x10 + x4; /* add with high bytes */
+ x10 = x10 + (x10 << 16); /* add with lower half word */
+
+ if (((uint32)x10 >> 16) <= (uint32)dmin) /* compare with dmin */
+ {
+ if (--x8)
+ {
+#if (NUMBER==3)
+ goto LOOP_SAD3;
+#elif (NUMBER==2)
+ goto LOOP_SAD2;
+#elif (NUMBER==1)
+ goto LOOP_SAD1;
+#endif
+ }
+
+ }
+
+ return ((uint32)x10 >> 16);
+}
+
+#elif defined(__CC_ARM) /* only work with arm v5 */
+
+#if (NUMBER==3)
+__inline int32 sad_mb_offset3(UChar *ref, UChar *blk, Int lx, Int dmin, int32 x8)
+#elif (NUMBER==2)
+__inline int32 sad_mb_offset2(UChar *ref, UChar *blk, Int lx, Int dmin, int32 x8)
+#elif (NUMBER==1)
+__inline int32 sad_mb_offset1(UChar *ref, UChar *blk, Int lx, Int dmin, int32 x8)
+#endif
+{
+ int32 x4, x5, x6, x9, x10, x11, x12, x14;
+
+ x9 = 0x80808080; /* const. */
+ x4 = x5 = 0;
+
+ __asm{
+ MVN x6, #0xff0000;
+ BIC ref, ref, #3;
+
+#if (NUMBER==3)
+LOOP_SAD3:
+#elif (NUMBER==2)
+LOOP_SAD2:
+#elif (NUMBER==1)
+LOOP_SAD1:
+#endif
+ }
+ /****** process 8 pixels ******/
+ x11 = *((int32*)(ref + 12));
+ x12 = *((int32*)(ref + 16));
+ x10 = *((int32*)(ref + 8));
+ x14 = *((int32*)(blk + 12));
+
+ __asm{
+ MVN x10, x10, lsr #SHIFT;
+ BIC x10, x10, x11, lsl #(32-SHIFT);
+ MVN x11, x11, lsr #SHIFT;
+ BIC x11, x11, x12, lsl #(32-SHIFT);
+
+ LDR x12, [blk, #8];
+ }
+
+ /* process x11 & x14 */
+ x11 = sad_4pixelN(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixelN(x10, x12, x9);
+
+ sum_accumulate;
+
+ __asm{
+ /****** process 8 pixels ******/
+ LDR x11, [ref, #4];
+ LDR x12, [ref, #8];
+ LDR x10, [ref], lx ;
+ LDR x14, [blk, #4];
+
+ MVN x10, x10, lsr #SHIFT;
+ BIC x10, x10, x11, lsl #(32-SHIFT);
+ MVN x11, x11, lsr #SHIFT;
+ BIC x11, x11, x12, lsl #(32-SHIFT);
+
+ LDR x12, [blk], #16;
+ }
+
+ /* process x11 & x14 */
+ x11 = sad_4pixelN(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixelN(x10, x12, x9);
+
+ sum_accumulate;
+
+ /****************/
+ x10 = x5 - (x4 << 8); /* extract low bytes */
+ x10 = x10 + x4; /* add with high bytes */
+ x10 = x10 + (x10 << 16); /* add with lower half word */
+
+ __asm{
+ RSBS x11, dmin, x10, lsr #16
+ ADDLSS x8, x8, #INC_X8
+#if (NUMBER==3)
+ BLS LOOP_SAD3;
+#elif (NUMBER==2)
+BLS LOOP_SAD2;
+#elif (NUMBER==1)
+BLS LOOP_SAD1;
+#endif
+ }
+
+ return ((uint32)x10 >> 16);
+}
+
+#elif ( defined(PV_ARM_GCC_V5) || defined(PV_ARM_GCC_V4) ) /* ARM GNU COMPILER */
+
+#if (NUMBER==3)
+__inline int32 sad_mb_offset3(UChar *ref, UChar *blk, Int lx, Int dmin)
+#elif (NUMBER==2)
+__inline int32 sad_mb_offset2(UChar *ref, UChar *blk, Int lx, Int dmin)
+#elif (NUMBER==1)
+__inline int32 sad_mb_offset1(UChar *ref, UChar *blk, Int lx, Int dmin)
+#endif
+{
+ int32 x4, x5, x6, x8, x9, x10, x11, x12, x14;
+
+ // x5 = (x4<<8) - x4;
+ x4 = x5 = 0;
+ x6 = 0xFFFF00FF;
+ x9 = 0x80808080; /* const. */
+ ref -= NUMBER; /* bic ref, ref, #3 */
+ ref -= lx;
+ x8 = 16;
+
+#if (NUMBER==3)
+LOOP_SAD3:
+#elif (NUMBER==2)
+LOOP_SAD2:
+#elif (NUMBER==1)
+LOOP_SAD1:
+#endif
+ /****** process 8 pixels ******/
+ x10 = *((uint32*)(ref += lx)); /* D C B A */
+ x11 = *((uint32*)(ref + 4)); /* H G F E */
+ x12 = *((uint32*)(ref + 8)); /* L K J I */
+
+ int32 shift = SHIFT;
+ int32 shift2 = 32 - SHIFT;
+ asm volatile("ldr %3, [%4, #4]\n\t"
+ "mvn %0, %0, lsr %5\n\t"
+ "bic %0, %0, %1, lsl %6\n\t"
+ "mvn %1, %1, lsr %5\n\t"
+ "bic %1, %1, %2, lsl %6\n\t"
+ "ldr %2, [%4, #8]"
+ : "+r"(x10), "+r"(x11), "+r"(x12), "=r"(x14)
+ : "r"(blk), "r"(shift), "r"(shift2));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ sum_accumulate;
+
+ /****** process 8 pixels ******/
+ x10 = *((uint32*)(ref + 8)); /* D C B A */
+ x11 = *((uint32*)(ref + 12)); /* H G F E */
+ x12 = *((uint32*)(ref + 16)); /* L K J I */
+
+ asm volatile("ldr %3, [%4, #4]\n\t"
+ "mvn %0, %0, lsr %5\n\t"
+ "bic %0, %0, %1, lsl %6\n\t"
+ "mvn %1, %1, lsr %5\n\t"
+ "bic %1, %1, %2, lsl %6\n\t"
+ "ldr %2, [%4, #8]"
+ : "+r"(x10), "+r"(x11), "+r"(x12), "=r"(x14)
+ : "r"(blk), "r"(shift), "r"(shift2));
+
+ /* process x11 & x14 */
+ x11 = sad_4pixel(x11, x14, x9);
+
+ /* process x12 & x10 */
+ x10 = sad_4pixel(x10, x12, x9);
+
+ sum_accumulate;
+
+ /****************/
+ x10 = x5 - (x4 << 8); /* extract low bytes */
+ x10 = x10 + x4; /* add with high bytes */
+ x10 = x10 + (x10 << 16); /* add with lower half word */
+
+ if (((uint32)x10 >> 16) <= (uint32)dmin) /* compare with dmin */
+ {
+ if (--x8)
+ {
+#if (NUMBER==3)
+ goto LOOP_SAD3;
+#elif (NUMBER==2)
+goto LOOP_SAD2;
+#elif (NUMBER==1)
+goto LOOP_SAD1;
+#endif
+ }
+
+ }
+
+ return ((uint32)x10 >> 16);
+}
+
+#endif
+
diff --git a/media/codecs/m4v_h263/enc/src/vlc_enc_tab.h b/media/codecs/m4v_h263/enc/src/vlc_enc_tab.h
new file mode 100644
index 0000000..79d62e4
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/vlc_enc_tab.h
@@ -0,0 +1,1146 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/******************************************************************************
+ *
+ * This software module was originally developed by
+ *
+ * Robert Danielsen (Telenor / ACTS-MoMuSys).
+ *
+ * and edited by
+ *
+ * Minhua Zhou (HHI / ACTS-MoMuSys).
+ * Luis Ducla-Soares (IST / ACTS-MoMuSys).
+ *
+ * in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
+ * This software module is an implementation of a part of one or more MPEG-4
+ * Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
+ * 14496-2) standard.
+ *
+ * ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
+ * license to this software module or modifications thereof for use in hardware
+ * or software products claiming conformance to the MPEG-4 Video (ISO/IEC
+ * 14496-2) standard.
+ *
+ * Those intending to use this software module in hardware or software products
+ * are advised that its use may infringe existing patents. The original
+ * developer of this software module and his/her company, the subsequent
+ * editors and their companies, and ISO/IEC have no liability for use of this
+ * software module or modifications thereof in an implementation. Copyright is
+ * not released for non MPEG-4 Video (ISO/IEC 14496-2) standard conforming
+ * products.
+ *
+ * ACTS-MoMuSys partners retain full right to use the code for his/her own
+ * purpose, assign or donate the code to a third party and to inhibit third
+ * parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) standard
+ * conforming products. This copyright notice must be included in all copies or
+ * derivative works.
+ *
+ * Copyright (c) 1997
+ *
+ *****************************************************************************/
+
+
+/***********************************************************HeaderBegin*******
+ *
+ * File: vlc.h
+ *
+ * Author: Robert Danielsen
+ * Created: 07.06.96
+ *
+ * Description: vlc tables for encoder
+ *
+ * Notes: Idea taken from MPEG-2 software simulation group
+ *
+ * Modified:
+ * 28.10.96 Robert Danielsen: Added tables for Intra luminance
+ * coefficients
+ * 01.05.97 Luis Ducla-Soares: added VM7.0 Reversible VLC tables (RVLC).
+ * 13.05.97 Minhua Zhou: added cbpy_tab3,cbpy_tab2
+ *
+ ***********************************************************HeaderEnd*********/
+
+/************************ INCLUDE FILES ********************************/
+
+#ifndef _VLC_ENC_TAB_H_
+#define _VLC_ENC_TAB_H_
+
+
+#include "mp4def.h"
+/* type definitions for variable length code table entries */
+
+
+
+static const Int intra_max_level[2][64] =
+{
+ {27, 10, 5, 4, 3, 3, 3, 3,
+ 2, 2, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ },
+
+ {8, 3, 2, 2, 2, 2, 2, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0
+ }
+};
+
+
+static const Int inter_max_level[2][64] =
+{
+ {12, 6, 4, 3, 3, 3, 3, 2,
+ 2, 2, 2, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0},
+
+ {3, 2, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0}
+};
+
+
+static const Int intra_max_run0[28] = { 999, 14, 9, 7, 3, 2, 1,
+ 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0
+ };
+
+
+static const Int intra_max_run1[9] = { 999, 20, 6,
+ 1, 0, 0,
+ 0, 0, 0
+ };
+
+static const Int inter_max_run0[13] = { 999,
+ 26, 10, 6, 2, 1, 1,
+ 0, 0, 0, 0, 0, 0
+ };
+
+
+static const Int inter_max_run1[4] = { 999, 40, 1, 0 };
+
+
+
+/* DC prediction sizes */
+
+static const VLCtable DCtab_lum[13] =
+{
+ {3, 3}, {3, 2}, {2, 2}, {2, 3}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7},
+ {1, 8}, {1, 9}, {1, 10}, {1, 11}
+};
+
+static const VLCtable DCtab_chrom[13] =
+{
+ {3, 2}, {2, 2}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8},
+ {1, 9}, {1, 10}, {1, 11}, {1, 12}
+};
+
+/* Motion vectors */
+
+static const VLCtable mvtab[33] =
+{
+ {1, 1}, {1, 2}, {1, 3}, {1, 4}, {3, 6}, {5, 7}, {4, 7}, {3, 7},
+ {11, 9}, {10, 9}, {9, 9}, {17, 10}, {16, 10}, {15, 10}, {14, 10}, {13, 10},
+ {12, 10}, {11, 10}, {10, 10}, {9, 10}, {8, 10}, {7, 10}, {6, 10}, {5, 10},
+ {4, 10}, {7, 11}, {6, 11}, {5, 11}, {4, 11}, {3, 11}, {2, 11}, {3, 12},
+ {2, 12}
+};
+
+
+/* MCBPC Indexing by cbpc in first two bits, mode in last two.
+ CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.
+ Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */
+
+static const VLCtable mcbpc_intra_tab[15] =
+{
+ {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},
+ {0x00, 0}, {0x01, 3}, {0x01, 6}, {0x00, 0},
+ {0x00, 0}, {0x02, 3}, {0x02, 6}, {0x00, 0},
+ {0x00, 0}, {0x03, 3}, {0x03, 6}
+};
+
+
+/* MCBPC inter.
+ Addressing: 5 bit ccmmm (cc = CBPC, mmm = mode (1-4 binary)) */
+
+static const VLCtable mcbpc_inter_tab[29] =
+{
+ {1, 1}, {3, 3}, {2, 3}, {3, 5}, {4, 6}, {1, 9}, {0, 0}, {0, 0},
+ {3, 4}, {7, 7}, {5, 7}, {4, 8}, {4, 9}, {0, 0}, {0, 0}, {0, 0},
+ {2, 4}, {6, 7}, {4, 7}, {3, 8}, {3, 9}, {0, 0}, {0, 0}, {0, 0},
+ {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}
+};
+
+
+
+/* CBPY. Straightforward indexing */
+
+static const VLCtable cbpy_tab[16] =
+{
+ {3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4},
+ {2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2}
+};
+
+static const VLCtable cbpy_tab3[8] =
+{
+ {3, 3}, {1, 6}, {1, 5}, {2, 3}, {2, 5}, {3, 5}, {1, 3}, {1, 1}
+};
+static const VLCtable cbpy_tab2[4] =
+{
+ {1, 4}, {1, 3}, {1, 2}, {1, 1}
+};
+
+/* DCT coefficients. Four tables, two for last = 0, two for last = 1.
+ the sign bit must be added afterwards. */
+
+/* first part of coeffs for last = 0. Indexed by [run][level-1] */
+
+static const VLCtable coeff_tab0[2][12] =
+{
+ /* run = 0 */
+ {
+ {0x02, 2}, {0x0f, 4}, {0x15, 6}, {0x17, 7},
+ {0x1f, 8}, {0x25, 9}, {0x24, 9}, {0x21, 10},
+ {0x20, 10}, {0x07, 11}, {0x06, 11}, {0x20, 11}
+ },
+ /* run = 1 */
+ {
+ {0x06, 3}, {0x14, 6}, {0x1e, 8}, {0x0f, 10},
+ {0x21, 11}, {0x50, 12}, {0x00, 0}, {0x00, 0},
+ {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ }
+};
+
+/* rest of coeffs for last = 0. indexing by [run-2][level-1] */
+
+static const VLCtable coeff_tab1[25][4] =
+{
+ /* run = 2 */
+ {
+ {0x0e, 4}, {0x1d, 8}, {0x0e, 10}, {0x51, 12}
+ },
+ /* run = 3 */
+ {
+ {0x0d, 5}, {0x23, 9}, {0x0d, 10}, {0x00, 0}
+ },
+ /* run = 4-26 */
+ {
+ {0x0c, 5}, {0x22, 9}, {0x52, 12}, {0x00, 0}
+ },
+ {
+ {0x0b, 5}, {0x0c, 10}, {0x53, 12}, {0x00, 0}
+ },
+ {
+ {0x13, 6}, {0x0b, 10}, {0x54, 12}, {0x00, 0}
+ },
+ {
+ {0x12, 6}, {0x0a, 10}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x11, 6}, {0x09, 10}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x10, 6}, {0x08, 10}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x16, 7}, {0x55, 12}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x15, 7}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x14, 7}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1c, 8}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1b, 8}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x21, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x20, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1f, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1e, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1d, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1c, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1b, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x1a, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x22, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x23, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x56, 12}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ },
+ {
+ {0x57, 12}, {0x00, 0}, {0x00, 0}, {0x00, 0}
+ }
+};
+
+/* first coeffs of last = 1. indexing by [run][level-1] */
+
+static const VLCtable coeff_tab2[2][3] =
+{
+ /* run = 0 */
+ {
+ {0x07, 4}, {0x19, 9}, {0x05, 11}
+ },
+ /* run = 1 */
+ {
+ {0x0f, 6}, {0x04, 11}, {0x00, 0}
+ }
+};
+
+/* rest of coeffs for last = 1. indexing by [run-2] */
+
+static const VLCtable coeff_tab3[40] =
+{
+ {0x0e, 6}, {0x0d, 6}, {0x0c, 6},
+ {0x13, 7}, {0x12, 7}, {0x11, 7}, {0x10, 7},
+ {0x1a, 8}, {0x19, 8}, {0x18, 8}, {0x17, 8},
+ {0x16, 8}, {0x15, 8}, {0x14, 8}, {0x13, 8},
+ {0x18, 9}, {0x17, 9}, {0x16, 9}, {0x15, 9},
+ {0x14, 9}, {0x13, 9}, {0x12, 9}, {0x11, 9},
+ {0x07, 10}, {0x06, 10}, {0x05, 10}, {0x04, 10},
+ {0x24, 11}, {0x25, 11}, {0x26, 11}, {0x27, 11},
+ {0x58, 12}, {0x59, 12}, {0x5a, 12}, {0x5b, 12},
+ {0x5c, 12}, {0x5d, 12}, {0x5e, 12}, {0x5f, 12},
+ {0x00, 0}
+};
+
+/* New tables for Intra luminance coefficients. Same codewords,
+ different meaning */
+
+/* Coeffs for last = 0, run = 0. Indexed by [level-1] */
+
+static const VLCtable coeff_tab4[27] =
+{
+ /* run = 0 */
+ {0x02, 2}, {0x06, 3}, {0x0f, 4}, {0x0d, 5},
+ {0x0c, 5}, {0x15, 6}, {0x13, 6}, {0x12, 6},
+ {0x17, 7}, {0x1f, 8}, {0x1e, 8}, {0x1d, 8},
+ {0x25, 9}, {0x24, 9}, {0x23, 9}, {0x21, 9},
+ {0x21, 10}, {0x20, 10}, {0x0f, 10}, {0x0e, 10},
+ {0x07, 11}, {0x06, 11}, {0x20, 11}, {0x21, 11},
+ {0x50, 12}, {0x51, 12}, {0x52, 12}
+};
+
+/* Coeffs for last = 0, run = 1. Indexed by [level-1] */
+
+static const VLCtable coeff_tab5[10] =
+{
+ {0x0e, 4}, {0x14, 6}, {0x16, 7}, {0x1c, 8},
+ {0x20, 9}, {0x1f, 9}, {0x0d, 10}, {0x22, 11},
+ {0x53, 12}, {0x55, 12}
+};
+
+/* Coeffs for last = 0, run = 2 -> 9. Indexed by [run-2][level-1] */
+
+static const VLCtable coeff_tab6[8][5] =
+{
+ /* run = 2 */
+ {
+ {0x0b, 5}, {0x15, 7}, {0x1e, 9}, {0x0c, 10},
+ {0x56, 12}
+ },
+ /* run = 3 */
+ {
+ {0x11, 6}, {0x1b, 8}, {0x1d, 9}, {0x0b, 10},
+ {0x00, 0}
+ },
+ /* run = 4 */
+ {
+ {0x10, 6}, {0x22, 9}, {0x0a, 10}, {0x00, 0},
+ {0x00, 0}
+ },
+ /* run = 5 */
+ {
+ {0x0d, 6}, {0x1c, 9}, {0x08, 10}, {0x00, 0},
+ {0x00, 0}
+ },
+ /* run = 6 */
+ {
+ {0x12, 7}, {0x1b, 9}, {0x54, 12}, {0x00, 0},
+ {0x00, 0}
+ },
+ /* run = 7 */
+ {
+ {0x14, 7}, {0x1a, 9}, {0x57, 12}, {0x00, 0},
+ {0x00, 0}
+ },
+ /* run = 8 */
+ {
+ {0x19, 8}, {0x09, 10}, {0x00, 0}, {0x00, 0},
+ {0x00, 0}
+ },
+ /* run = 9 */
+ {
+ {0x18, 8}, {0x23, 11}, {0x00, 0}, {0x00, 0},
+ {0x00, 0}
+ }
+};
+
+/* Coeffs for last = 0, run = 10 -> 14. Indexed by [run-10] */
+
+static const VLCtable coeff_tab7[5] =
+{
+ {0x17, 8}, {0x19, 9}, {0x18, 9}, {0x07, 10},
+ {0x58, 12}
+};
+
+/* Coeffs for last = 1, run = 0. Indexed by [level-1] */
+
+static const VLCtable coeff_tab8[8] =
+{
+ {0x07, 4}, {0x0c, 6}, {0x16, 8}, {0x17, 9},
+ {0x06, 10}, {0x05, 11}, {0x04, 11}, {0x59, 12}
+};
+
+/* Coeffs for last = 1, run = 1 -> 6. Indexed by [run-1][level-1] */
+
+static const VLCtable coeff_tab9[6][3] =
+{
+ /* run = 1 */
+ {
+ {0x0f, 6}, {0x16, 9}, {0x05, 10}
+ },
+ /* run = 2 */
+ {
+ {0x0e, 6}, {0x04, 10}, {0x00, 0}
+ },
+ /* run = 3 */
+ {
+ {0x11, 7}, {0x24, 11}, {0x00, 0}
+ },
+ /* run = 4 */
+ {
+ {0x10, 7}, {0x25, 11}, {0x00, 0}
+ },
+ /* run = 5 */
+ {
+ {0x13, 7}, {0x5a, 12}, {0x00, 0}
+ },
+ /* run = 6 */
+ {
+ {0x15, 8}, {0x5b, 12}, {0x00, 0}
+ }
+};
+
+/* Coeffs for last = 1, run = 7 -> 20. Indexed by [run-7] */
+
+static const VLCtable coeff_tab10[14] =
+{
+ {0x14, 8}, {0x13, 8}, {0x1a, 8}, {0x15, 9},
+ {0x14, 9}, {0x13, 9}, {0x12, 9}, {0x11, 9},
+ {0x26, 11}, {0x27, 11}, {0x5c, 12}, {0x5d, 12},
+ {0x5e, 12}, {0x5f, 12}
+};
+
+
+#ifndef NO_RVLC
+/* RVLC tables */
+/* DCT coefficients. Four tables, two for last = 0, two for last = 1.
+ the sign bit must be added afterwards. */
+
+/* DCT coeffs (intra) for last = 0. */
+
+/* Indexed by [level-1] */
+
+static const VLCtable coeff_RVLCtab1[27] =
+{
+ /* run = 0 */
+ { 0x6, 3},
+ { 0x7, 3},
+ { 0xa, 4},
+ { 0x9, 5},
+ { 0x14, 6},
+ { 0x15, 6},
+ { 0x34, 7},
+ { 0x74, 8},
+ { 0x75, 8},
+ { 0xdd, 9},
+ { 0xec, 9},
+ { 0x1ec, 10},
+ { 0x1ed, 10},
+ { 0x1f4, 10},
+ { 0x3ec, 11},
+ { 0x3ed, 11},
+ { 0x3f4, 11},
+ { 0x77d, 12},
+ { 0x7bc, 12},
+ { 0xfbd, 13},
+ { 0xfdc, 13},
+ { 0x7bd, 12},
+ { 0xfdd, 13},
+ { 0x1fbd, 14},
+ { 0x1fdc, 14},
+ { 0x1fdd, 14},
+ { 0x1ffc, 15}
+};
+
+
+/* Indexed by [level-1] */
+
+static const VLCtable coeff_RVLCtab2[13] =
+{
+ /* run = 1 */
+ { 0x1, 4},
+ { 0x8, 5},
+ { 0x2d, 7},
+ { 0x6c, 8},
+ { 0x6d, 8},
+ { 0xdc, 9},
+ { 0x1dd, 10},
+ { 0x3dc, 11},
+ { 0x3dd, 11},
+ { 0x77c, 12},
+ { 0xfbc, 13},
+ { 0x1f7d, 14},
+ { 0x1fbc, 14}
+};
+
+
+/* Indexed by [level-1] */
+
+static const VLCtable coeff_RVLCtab3[11] =
+{
+ /* run = 2 */
+
+ { 0x4, 5},
+ { 0x2c, 7},
+ { 0xbc, 9},
+ { 0x1dc, 10},
+ { 0x3bc, 11},
+ { 0x3bd, 11},
+ { 0xefd, 13},
+ { 0xf7c, 13},
+ { 0xf7d, 13},
+ { 0x1efd, 14},
+ { 0x1f7c, 14}
+};
+
+
+/* Indexed by [level-1] */
+
+static const VLCtable coeff_RVLCtab4[9] =
+{
+ /* run = 3 */
+ { 0x5, 5},
+ { 0x5c, 8},
+ { 0xbd, 9},
+ { 0x37d, 11},
+ { 0x6fc, 12},
+ { 0xefc, 13},
+ { 0x1dfd, 14},
+ { 0x1efc, 14},
+ { 0x1ffd, 15}
+};
+
+
+/* Indexed by [run-4][level-1] */
+
+static const VLCtable coeff_RVLCtab5[2][6] =
+{
+ /* run = 4 */
+ {
+ { 0xc, 6},
+ { 0x5d, 8},
+ { 0x1bd, 10},
+ { 0x3fd, 12},
+ { 0x6fd, 12},
+ { 0x1bfd, 14}
+ },
+ /* run = 5 */
+ {
+ { 0xd, 6},
+ { 0x7d, 9},
+ { 0x2fc, 11},
+ { 0x5fc, 12},
+ { 0x1bfc, 14},
+ { 0x1dfc, 14}
+ }
+};
+
+
+/* Indexed by [run-6][level-1] */
+
+static const VLCtable coeff_RVLCtab6[2][5] =
+{
+
+ /* run = 6 */
+ {
+ { 0x1c, 7},
+ { 0x17c, 10},
+ { 0x2fd, 11},
+ { 0x5fd, 12},
+ { 0x2ffc, 15}
+ },
+ /* run = 7 */
+ {
+ { 0x1d, 7},
+ { 0x17d, 10},
+ { 0x37c, 11},
+ { 0xdfd, 13},
+ { 0x2ffd, 15}
+ }
+
+};
+/* Indexed by [run-8][level-1] */
+
+static const VLCtable coeff_RVLCtab7[2][4] =
+{
+ /* run = 8 */
+ {
+ { 0x3c, 8},
+ { 0x1bc, 10},
+ { 0xbfd, 13},
+ { 0x17fd, 14}
+ },
+ /* run = 9 */
+ {
+ { 0x3d, 8},
+ { 0x1fd, 11},
+ { 0xdfc, 13},
+ { 0x37fc, 15},
+ }
+};
+
+
+
+/* Indexed by [run-10][level-1] */
+
+static const VLCtable coeff_RVLCtab8[3][2] =
+{
+ /* run = 10 */
+ {
+ { 0x7c, 9},
+ { 0x3fc, 12}
+ },
+ /* run = 11 */
+ {
+ { 0xfc, 10},
+ { 0xbfc, 13}
+ },
+ /* run = 12 */
+ {
+ { 0xfd, 10},
+ { 0x37fd, 15}
+ }
+};
+
+
+/* Indexed by [level-1] */
+
+static const VLCtable coeff_RVLCtab9[7] =
+{
+ /* run = 13 -> 19 */
+ { 0x1fc, 11},
+ { 0x7fc, 13},
+ { 0x7fd, 13},
+ { 0xffc, 14},
+ { 0xffd, 14},
+ { 0x17fc, 14},
+ { 0x3bfc, 15}
+};
+
+
+
+/* first coeffs of last = 1. indexing by [run][level-1] */
+
+static const VLCtable coeff_RVLCtab10[2][5] =
+{
+ /* run = 0 */
+ {
+ { 0xb, 4},
+ { 0x78, 8},
+ { 0x3f5, 11},
+ { 0xfec, 13},
+ { 0x1fec, 14}
+ },
+ /* run = 1 */
+ {
+ { 0x12, 5},
+ { 0xed, 9},
+ { 0x7dc, 12},
+ { 0x1fed, 14},
+ { 0x3bfd, 15}
+ }
+
+};
+
+static const VLCtable coeff_RVLCtab11[3] =
+{
+ /* run = 2 */
+ { 0x13, 5},
+ { 0x3f8, 11},
+ { 0x3dfc, 15}
+
+};
+
+static const VLCtable coeff_RVLCtab12[11][2] =
+{
+ /* run = 3 */
+ {
+ { 0x18, 6},
+ { 0x7dd, 12}
+ },
+ /* run = 4 */
+ {
+ { 0x19, 6},
+ { 0x7ec, 12}
+ },
+ /* run = 5 */
+ {
+ { 0x22, 6},
+ { 0xfed, 13}
+ },
+ /* run = 6 */
+ {
+ { 0x23, 6},
+ { 0xff4, 13}
+ },
+ /* run = 7 */
+ {
+ { 0x35, 7},
+ { 0xff5, 13}
+ },
+ /* run = 8 */
+ {
+ { 0x38, 7},
+ { 0xff8, 13}
+ },
+ /* run = 9 */
+ {
+ { 0x39, 7},
+ { 0xff9, 13}
+ },
+ /* run = 10 */
+ {
+ { 0x42, 7},
+ { 0x1ff4, 14}
+ },
+ /* run = 11 */
+ {
+ { 0x43, 7},
+ { 0x1ff5, 14}
+ },
+ /* run = 12 */
+ {
+ { 0x79, 8},
+ { 0x1ff8, 14}
+ },
+ /* run = 13 */
+ {
+ { 0x82, 8},
+ { 0x3dfd, 15}
+ }
+
+};
+
+static const VLCtable coeff_RVLCtab13[32] =
+{
+ /* run = 14 -> 44 */
+ { 0x83, 8},
+ { 0xf4, 9},
+ { 0xf5, 9},
+ { 0xf8, 9},
+ { 0xf9, 9},
+ { 0x102, 9},
+ { 0x103, 9},
+ { 0x1f5, 10},
+ { 0x1f8, 10},
+ { 0x1f9, 10},
+ { 0x202, 10},
+ { 0x203, 10},
+ { 0x3f9, 11},
+ { 0x402, 11},
+ { 0x403, 11},
+ { 0x7ed, 12},
+ { 0x7f4, 12},
+ { 0x7f5, 12},
+ { 0x7f8, 12},
+ { 0x7f9, 12},
+ { 0x802, 12},
+ { 0x803, 12},
+ { 0x1002, 13},
+ { 0x1003, 13},
+ { 0x1ff9, 14},
+ { 0x2002, 14},
+ { 0x2003, 14},
+ { 0x3efc, 15},
+ { 0x3efd, 15},
+ { 0x3f7c, 15},
+ { 0x3f7d, 15}
+};
+
+
+
+/* Coeffs for last = 0, run = 0. Indexed by [level-1] */
+
+static const VLCtable coeff_RVLCtab14[19] =
+{
+ /* run = 0 */
+ { 0x6, 3},
+ { 0x1, 4},
+ { 0x4, 5},
+ { 0x1c, 7},
+ { 0x3c, 8},
+ { 0x3d, 8},
+ { 0x7c, 9},
+ { 0xfc, 10},
+ { 0xfd, 10},
+ { 0x1fc, 11},
+ { 0x1fd, 11},
+ { 0x3fc, 12},
+ { 0x7fc, 13},
+ { 0x7fd, 13},
+ { 0xbfc, 13},
+ { 0xbfd, 13},
+ { 0xffc, 14},
+ { 0xffd, 14},
+ { 0x1ffc, 15}
+};
+
+static const VLCtable coeff_RVLCtab15[10] =
+{
+ /* run = 1 */
+ { 0x7, 3},
+ { 0xc, 6},
+ { 0x5c, 8},
+ { 0x7d, 9},
+ { 0x17c, 10},
+ { 0x2fc, 11},
+ { 0x3fd, 12},
+ { 0xdfc, 13},
+ { 0x17fc, 14},
+ { 0x17fd, 14}
+};
+
+static const VLCtable coeff_RVLCtab16[2][7] =
+{
+ /* run = 2 */
+ {
+ { 0xa, 4},
+ { 0x1d, 7},
+ { 0xbc, 9},
+ { 0x2fd, 11},
+ { 0x5fc, 12},
+ { 0x1bfc, 14},
+ { 0x1bfd, 14}
+ },
+ /* run = 3 */
+ {
+ { 0x5, 5},
+ { 0x5d, 8},
+ { 0x17d, 10},
+ { 0x5fd, 12},
+ { 0xdfd, 13},
+ { 0x1dfc, 14},
+ { 0x1ffd, 15}
+ }
+};
+
+static const VLCtable coeff_RVLCtab17[5] =
+{
+ /* run = 4 */
+ { 0x8, 5},
+ { 0x6c, 8},
+ { 0x37c, 11},
+ { 0xefc, 13},
+ { 0x2ffc, 15}
+};
+
+static const VLCtable coeff_RVLCtab18[3][4] =
+{
+ /* run = 5 */
+ {
+ { 0x9, 5},
+ { 0xbd, 9},
+ { 0x37d, 11},
+ { 0xefd, 13}
+ },
+ /* run = 6 */
+ {
+ { 0xd, 6},
+ { 0x1bc, 10},
+ { 0x6fc, 12},
+ { 0x1dfd, 14}
+ },
+ /* run = 7 */
+ {
+ { 0x14, 6},
+ { 0x1bd, 10},
+ { 0x6fd, 12},
+ { 0x2ffd, 15}
+ }
+};
+
+static const VLCtable coeff_RVLCtab19[2][3] =
+{
+ /* run = 8 */
+ {
+ { 0x15, 6},
+ { 0x1dc, 10},
+ { 0xf7c, 13}
+ },
+ /* run = 9 */
+ {
+ { 0x2c, 7},
+ { 0x1dd, 10},
+ { 0x1efc, 14}
+ }
+};
+
+static const VLCtable coeff_RVLCtab20[8][2] =
+{
+ /* run = 10 */
+ {
+ { 0x2d, 7},
+ { 0x3bc, 11}
+ },
+ /* run = 11 */
+ {
+ { 0x34, 7},
+ { 0x77c, 12}
+ },
+ /* run = 12 */
+ {
+ { 0x6d, 8},
+ { 0xf7d, 13}
+ },
+ /* run = 13 */
+ {
+ { 0x74, 8},
+ { 0x1efd, 14}
+ },
+ /* run = 14 */
+ {
+ { 0x75, 8},
+ { 0x1f7c, 14}
+ },
+ /* run = 15 */
+ {
+ { 0xdc, 9},
+ { 0x1f7d, 14}
+ },
+ /* run = 16 */
+ {
+ { 0xdd, 9},
+ { 0x1fbc, 14}
+ },
+ /* run = 17 */
+ {
+ { 0xec, 9},
+ { 0x37fc, 15}
+ }
+};
+
+static const VLCtable coeff_RVLCtab21[21] =
+{
+ /* run = 18 -> 38 */
+ { 0x1ec, 10},
+ { 0x1ed, 10},
+ { 0x1f4, 10},
+ { 0x3bd, 11},
+ { 0x3dc, 11},
+ { 0x3dd, 11},
+ { 0x3ec, 11},
+ { 0x3ed, 11},
+ { 0x3f4, 11},
+ { 0x77d, 12},
+ { 0x7bc, 12},
+ { 0x7bd, 12},
+ { 0xfbc, 13},
+ { 0xfbd, 13},
+ { 0xfdc, 13},
+ { 0xfdd, 13},
+ { 0x1fbd, 14},
+ { 0x1fdc, 14},
+ { 0x1fdd, 14},
+ { 0x37fd, 15},
+ { 0x3bfc, 15}
+};
+
+
+/* first coeffs of last = 1. indexing by [run][level-1] */
+
+static const VLCtable coeff_RVLCtab22[2][5] =
+{
+ /* run = 0 */
+ {
+ { 0xb, 4},
+ { 0x78, 8},
+ { 0x3f5, 11},
+ { 0xfec, 13},
+ { 0x1fec, 14}
+ },
+ /* run = 1 */
+ {
+ { 0x12, 5},
+ { 0xed, 9},
+ { 0x7dc, 12},
+ { 0x1fed, 14},
+ { 0x3bfd, 15}
+ }
+
+};
+
+static const VLCtable coeff_RVLCtab23[3] =
+{
+ /* run = 2 */
+ { 0x13, 5},
+ { 0x3f8, 11},
+ { 0x3dfc, 15}
+
+};
+
+static const VLCtable coeff_RVLCtab24[11][2] =
+{
+ /* run = 3 */
+ {
+ { 0x18, 6},
+ { 0x7dd, 12}
+ },
+ /* run = 4 */
+ {
+ { 0x19, 6},
+ { 0x7ec, 12}
+ },
+ /* run = 5 */
+ {
+ { 0x22, 6},
+ { 0xfed, 13}
+ },
+ /* run = 6 */
+ {
+ { 0x23, 6},
+ { 0xff4, 13}
+ },
+ /* run = 7 */
+ {
+ { 0x35, 7},
+ { 0xff5, 13}
+ },
+ /* run = 8 */
+ {
+ { 0x38, 7},
+ { 0xff8, 13}
+ },
+ /* run = 9 */
+ {
+ { 0x39, 7},
+ { 0xff9, 13}
+ },
+ /* run = 10 */
+ {
+ { 0x42, 7},
+ { 0x1ff4, 14}
+ },
+ /* run = 11 */
+ {
+ { 0x43, 7},
+ { 0x1ff5, 14}
+ },
+ /* run = 12 */
+ {
+ { 0x79, 8},
+ { 0x1ff8, 14}
+ },
+ /* run = 13 */
+ {
+ { 0x82, 8},
+ { 0x3dfd, 15}
+ }
+
+};
+
+static const VLCtable coeff_RVLCtab25[32] =
+{
+ /* run = 14 -> 44 */
+ { 0x83, 8},
+ { 0xf4, 9},
+ { 0xf5, 9},
+ { 0xf8, 9},
+ { 0xf9, 9},
+ { 0x102, 9},
+ { 0x103, 9},
+ { 0x1f5, 10},
+ { 0x1f8, 10},
+ { 0x1f9, 10},
+ { 0x202, 10},
+ { 0x203, 10},
+ { 0x3f9, 11},
+ { 0x402, 11},
+ { 0x403, 11},
+ { 0x7ed, 12},
+ { 0x7f4, 12},
+ { 0x7f5, 12},
+ { 0x7f8, 12},
+ { 0x7f9, 12},
+ { 0x802, 12},
+ { 0x803, 12},
+ { 0x1002, 13},
+ { 0x1003, 13},
+ { 0x1ff9, 14},
+ { 0x2002, 14},
+ { 0x2003, 14},
+ { 0x3efc, 15},
+ { 0x3efd, 15},
+ { 0x3f7c, 15},
+ { 0x3f7d, 15}
+};
+
+#endif /* NO_RVLC */
+
+#endif /* _VLC_ENC_TAB_H_ */
+
diff --git a/media/codecs/m4v_h263/enc/src/vlc_encode.cpp b/media/codecs/m4v_h263/enc/src/vlc_encode.cpp
new file mode 100644
index 0000000..2aec815
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/vlc_encode.cpp
@@ -0,0 +1,2799 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/******************************************************************************
+*
+* This software module was originally developed by
+*
+* Robert Danielsen (Telenor / ACTS-MoMuSys).
+*
+* and edited by
+*
+* Luis Ducla-Soares (IST / ACTS-MoMuSys).
+* Cor Quist (KPN / ACTS-MoMuSys).
+*
+* in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
+* This software module is an implementation of a part of one or more MPEG-4
+* Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
+* license to this software module or modifications thereof for use in hardware
+* or software products claiming conformance to the MPEG-4 Video (ISO/IEC
+* 14496-2) standard.
+*
+* Those intending to use this software module in hardware or software products
+* are advised that its use may infringe existing patents. The original
+* developer of this software module and his/her company, the subsequent
+* editors and their companies, and ISO/IEC have no liability for use of this
+* software module or modifications thereof in an implementation. Copyright is
+* not released for non MPEG-4 Video (ISO/IEC 14496-2) standard conforming
+* products.
+*
+* ACTS-MoMuSys partners retain full right to use the code for his/her own
+* purpose, assign or donate the code to a third party and to inhibit third
+* parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) standard
+* conforming products. This copyright notice must be included in all copies or
+* derivative works.
+*
+* Copyright (c) 1997
+*
+*****************************************************************************/
+
+/***********************************************************HeaderBegin*******
+*
+* File: putvlc.c
+*
+* Author: Robert Danielsen, Telenor R&D
+* Created: 07.07.96
+*
+* Description: Functions for writing to bitstream
+*
+* Notes: Same kind of tables as in the MPEG-2 software simulation
+* group software.
+*
+* Modified:
+* 28.10.96 Robert Danielsen: Added PutCoeff_Intra(), renamed
+* PutCoeff() to PutCoeff_Inter().
+* 06.11.96 Robert Danielsen: Added PutMCBPC_sep()
+* 01.05.97 Luis Ducla-Soares: added PutCoeff_Intra_RVLC() and
+* PutCoeff_Inter_RVLC().
+*
+***********************************************************HeaderEnd*********/
+
+/************************ INCLUDE FILES ********************************/
+
+
+#include "mp4lib_int.h"
+#include "mp4enc_lib.h"
+#include "vlc_enc_tab.h"
+#include "bitstream_io.h"
+#include "m4venc_oscl.h"
+#include "vlc_encode_inline.h"
+
+typedef void (*BlockCodeCoeffPtr)(RunLevelBlock*, BitstreamEncVideo*, Int, Int, UChar) ;
+
+const static Int mode_MBtype[] =
+{
+ 3,
+ 0,
+ 4,
+ 1,
+ 2,
+};
+
+const static Int zigzag_inv[NCOEFF_BLOCK] =
+{
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
+};
+
+/* Horizontal zigzag inverse */
+const static Int zigzag_h_inv[NCOEFF_BLOCK] =
+{
+ 0, 1, 2, 3, 8, 9, 16, 17,
+ 10, 11, 4, 5, 6, 7, 15, 14,
+ 13, 12, 19, 18, 24, 25, 32, 33,
+ 26, 27, 20, 21, 22, 23, 28, 29,
+ 30, 31, 34, 35, 40, 41, 48, 49,
+ 42, 43, 36, 37, 38, 39, 44, 45,
+ 46, 47, 50, 51, 56, 57, 58, 59,
+ 52, 53, 54, 55, 60, 61, 62, 63
+};
+
+/* Vertical zigzag inverse */
+const static Int zigzag_v_inv[NCOEFF_BLOCK] =
+{
+ 0, 8, 16, 24, 1, 9, 2, 10,
+ 17, 25, 32, 40, 48, 56, 57, 49,
+ 41, 33, 26, 18, 3, 11, 4, 12,
+ 19, 27, 34, 42, 50, 58, 35, 43,
+ 51, 59, 20, 28, 5, 13, 6, 14,
+ 21, 29, 36, 44, 52, 60, 37, 45,
+ 53, 61, 22, 30, 7, 15, 23, 31,
+ 38, 46, 54, 62, 39, 47, 55, 63
+};
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ Int PutCoeff_Inter(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutCoeff_Inter_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutCoeff_Intra(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutCoeff_Intra_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutCBPY(Int cbpy, Char intra, BitstreamEncVideo *bitstream);
+ Int PutMCBPC_Inter(Int cbpc, Int mode, BitstreamEncVideo *bitstream);
+ Int PutMCBPC_Intra(Int cbpc, Int mode, BitstreamEncVideo *bitstream);
+ Int PutMV(Int mvint, BitstreamEncVideo *bitstream);
+ Int PutDCsize_chrom(Int size, BitstreamEncVideo *bitstream);
+ Int PutDCsize_lum(Int size, BitstreamEncVideo *bitstream);
+ Int PutDCsize_lum(Int size, BitstreamEncVideo *bitstream);
+#ifndef NO_RVLC
+ Int PutCoeff_Inter_RVLC(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutCoeff_Inter_RVLC_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutCoeff_Intra_RVLC(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutCoeff_Intra_RVLC_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+#endif
+ Int PutRunCoeff_Inter(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutRunCoeff_Inter_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutRunCoeff_Intra(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutRunCoeff_Intra_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutLevelCoeff_Inter(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutLevelCoeff_Inter_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutLevelCoeff_Intra(Int run, Int level, BitstreamEncVideo *bitstream);
+ Int PutLevelCoeff_Intra_Last(Int run, Int level, BitstreamEncVideo *bitstream);
+
+ void RunLevel(VideoEncData *video, Int intra, Int intraDC_decision, Int ncoefblck[]);
+ Int IntraDC_dpcm(Int val, Int lum, BitstreamEncVideo *bitstream);
+ Void DCACPred(VideoEncData *video, UChar Mode, Int *intraDC_decision, Int intraDCVlcQP);
+ Void find_pmvs(VideoEncData *video, Int block, Int *mvx, Int *mvy);
+ Void WriteMVcomponent(Int f_code, Int dmv, BitstreamEncVideo *bs);
+ static Bool IntraDCSwitch_Decision(Int Mode, Int intra_dc_vlc_threshold, Int intraDCVlcQP);
+
+ Void ScaleMVD(Int f_code, Int diff_vector, Int *residual, Int *vlc_code_mag);
+
+#ifdef __cplusplus
+}
+#endif
+
+Int
+PutDCsize_lum(Int size, BitstreamEncVideo *bitstream)
+{
+ Int length;
+
+ if (!(size >= 0 && size < 13))
+ return -1;
+
+ length = DCtab_lum[size].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, DCtab_lum[size].code);
+
+ return length;
+}
+
+Int
+PutDCsize_chrom(Int size, BitstreamEncVideo *bitstream)
+{
+ Int length;
+
+ if (!(size >= 0 && size < 13))
+ return -1;
+ length = DCtab_chrom[size].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, DCtab_chrom[size].code);
+
+ return length;
+}
+
+Int
+PutMV(Int mvint, BitstreamEncVideo *bitstream)
+{
+ Int sign = 0;
+ Int absmv;
+ Int length;
+
+ if (mvint > 32)
+ {
+ absmv = -mvint + 65;
+ sign = 1;
+ }
+ else
+ absmv = mvint;
+
+ length = mvtab[absmv].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, mvtab[absmv].code);
+
+ if (mvint != 0)
+ {
+ BitstreamPut1Bits(bitstream, sign);
+ return (length + 1);
+ }
+ else
+ return length;
+}
+
+Int
+PutMCBPC_Intra(Int cbp, Int mode, BitstreamEncVideo *bitstream)
+{
+ Int ind;
+ Int length;
+
+ ind = ((mode_MBtype[mode] >> 1) & 3) | ((cbp & 3) << 2);
+
+ length = mcbpc_intra_tab[ind].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, mcbpc_intra_tab[ind].code);
+
+ return length;
+}
+
+Int
+PutMCBPC_Inter(Int cbp, Int mode, BitstreamEncVideo *bitstream)
+{
+ Int ind;
+ Int length;
+
+ ind = (mode_MBtype[mode] & 7) | ((cbp & 3) << 3);
+
+ length = mcbpc_inter_tab[ind].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, mcbpc_inter_tab[ind].code);
+
+ return length;
+}
+
+Int
+PutCBPY(Int cbpy, Char intra, BitstreamEncVideo *bitstream)
+{
+ Int ind;
+ Int length;
+
+ if (intra == 0)
+ cbpy = 15 - cbpy;
+
+ ind = cbpy;
+
+ length = cbpy_tab[ind].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)cbpy_tab[ind].code);
+
+ return length;
+}
+
+/* 5/16/01, break up function for last and not-last coefficient */
+/* Note:::: I checked the ARM assembly for if( run > x && run < y) type
+ of code, they do a really good job compiling it to if( (UInt)(run-x) < y-x).
+ No need to hand-code it!!!!!, 6/1/2001 */
+
+Int PutCoeff_Inter(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run < 2 && level < 13)
+ {
+ length = coeff_tab0[run][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab0[run][level-1].code);
+ }
+ else if (run > 1 && run < 27 && level < 5)
+ {
+ length = coeff_tab1[run-2][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab1[run-2][level-1].code);
+ }
+
+ return length;
+}
+
+Int PutCoeff_Inter_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run < 2 && level < 4)
+ {
+ length = coeff_tab2[run][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab2[run][level-1].code);
+ }
+ else if (run > 1 && run < 42 && level == 1)
+ {
+ length = coeff_tab3[run-2].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab3[run-2].code);
+ }
+
+ return length;
+}
+
+/* 5/16/01, break up function for last and not-last coefficient */
+
+Int PutCoeff_Intra(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 28)
+ {
+ length = coeff_tab4[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab4[level-1].code);
+ }
+ else if (run == 1 && level < 11)
+ {
+ length = coeff_tab5[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab5[level-1].code);
+ }
+ else if (run > 1 && run < 10 && level < 6)
+ {
+ length = coeff_tab6[run-2][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab6[run-2][level-1].code);
+ }
+ else if (run > 9 && run < 15 && level == 1)
+ {
+ length = coeff_tab7[run-10].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab7[run-10].code);
+ }
+
+ return length;
+}
+
+Int PutCoeff_Intra_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 9)
+ {
+ length = coeff_tab8[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab8[level-1].code);
+ }
+ else if (run > 0 && run < 7 && level < 4)
+ {
+ length = coeff_tab9[run-1][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab9[run-1][level-1].code);
+ }
+ else if (run > 6 && run < 21 && level == 1)
+ {
+ length = coeff_tab10[run-7].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab10[run-7].code);
+ }
+
+ return length;
+}
+
+/* 5/16/01, break up function for last and not-last coefficient */
+#ifndef NO_RVLC
+Int PutCoeff_Inter_RVLC(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 20)
+ {
+ length = coeff_RVLCtab14[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab14[level-1].code);
+ }
+ else if (run == 1 && level < 11)
+ {
+ length = coeff_RVLCtab15[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab15[level-1].code);
+ }
+ else if (run > 1 && run < 4 && level < 8)
+ {
+ length = coeff_RVLCtab16[run-2][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab16[run-2][level-1].code);
+ }
+ else if (run == 4 && level < 6)
+ {
+ length = coeff_RVLCtab17[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab17[level-1].code);
+ }
+ else if (run > 4 && run < 8 && level < 5)
+ {
+ length = coeff_RVLCtab18[run-5][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab18[run-5][level-1].code);
+ }
+ else if (run > 7 && run < 10 && level < 4)
+ {
+ length = coeff_RVLCtab19[run-8][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab19[run-8][level-1].code);
+ }
+ else if (run > 9 && run < 18 && level < 3)
+ {
+ length = coeff_RVLCtab20[run-10][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab20[run-10][level-1].code);
+ }
+ else if (run > 17 && run < 39 && level == 1)
+ {
+ length = coeff_RVLCtab21[run-18].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab21[run-18].code);
+ }
+
+ return length;
+}
+
+Int PutCoeff_Inter_RVLC_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run >= 0 && run < 2 && level < 6)
+ {
+ length = coeff_RVLCtab22[run][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab22[run][level-1].code);
+ }
+ else if (run == 2 && level < 4)
+ {
+ length = coeff_RVLCtab23[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab23[level-1].code);
+ }
+ else if (run > 2 && run < 14 && level < 3)
+ {
+ length = coeff_RVLCtab24[run-3][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab24[run-3][level-1].code);
+ }
+ else if (run > 13 && run < 45 && level == 1)
+ {
+ length = coeff_RVLCtab25[run-14].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab25[run-14].code);
+ }
+
+ return length;
+}
+
+/* 5/16/01, break up function for last and not-last coefficient */
+
+Int PutCoeff_Intra_RVLC(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 28)
+ {
+ length = coeff_RVLCtab1[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab1[level-1].code);
+ }
+ else if (run == 1 && level < 14)
+ {
+ length = coeff_RVLCtab2[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab2[level-1].code);
+ }
+ else if (run == 2 && level < 12)
+ {
+ length = coeff_RVLCtab3[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab3[level-1].code);
+ }
+ else if (run == 3 && level < 10)
+ {
+ length = coeff_RVLCtab4[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab4[level-1].code);
+ }
+ else if (run > 3 && run < 6 && level < 7)
+ {
+ length = coeff_RVLCtab5[run-4][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab5[run-4][level-1].code);
+ }
+ else if (run > 5 && run < 8 && level < 6)
+ {
+ length = coeff_RVLCtab6[run-6][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab6[run-6][level-1].code);
+ }
+ else if (run > 7 && run < 10 && level < 5)
+ {
+ length = coeff_RVLCtab7[run-8][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab7[run-8][level-1].code);
+
+ }
+ else if (run > 9 && run < 13 && level < 3)
+ {
+ length = coeff_RVLCtab8[run-10][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab8[run-10][level-1].code);
+ }
+ else if (run > 12 && run < 20 && level == 1)
+ {
+ length = coeff_RVLCtab9[run-13].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab9[run-13].code);
+ }
+ return length;
+}
+
+Int PutCoeff_Intra_RVLC_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run >= 0 && run < 2 && level < 6)
+ {
+ length = coeff_RVLCtab10[run][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab10[run][level-1].code);
+ }
+ else if (run == 2 && level < 4)
+ {
+ length = coeff_RVLCtab11[level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab11[level-1].code);
+ }
+ else if (run > 2 && run < 14 && level < 3)
+ {
+ length = coeff_RVLCtab12[run-3][level-1].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab12[run-3][level-1].code);
+ }
+ else if (run > 13 && run < 45 && level == 1)
+ {
+ length = coeff_RVLCtab13[run-14].len;
+ if (length)
+ BitstreamPutBits(bitstream, length, (UInt)coeff_RVLCtab13[run-14].code);
+ }
+ return length;
+}
+#endif
+
+/* The following is for 3-mode VLC */
+
+Int
+PutRunCoeff_Inter(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run < 2 && level < 13)
+ {
+ length = coeff_tab0[run][level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab0[run][level-1].code);
+ length += 9;
+ }
+ }
+ else if (run > 1 && run < 27 && level < 5)
+ {
+ length = coeff_tab1[run-2][level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab1[run-2][level-1].code);
+ length += 9;
+ }
+ }
+ return length;
+}
+
+Int PutRunCoeff_Inter_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run < 2 && level < 4)
+ {
+ length = coeff_tab2[run][level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab2[run][level-1].code);
+ length += 9;
+ }
+ }
+ else if (run > 1 && run < 42 && level == 1)
+ {
+ length = coeff_tab3[run-2].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab3[run-2].code);
+ length += 9;
+ }
+ }
+ return length;
+}
+
+Int PutRunCoeff_Intra(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 28)
+ {
+ length = coeff_tab4[level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab4[level-1].code);
+ length += 9;
+ }
+ }
+ else if (run == 1 && level < 11)
+ {
+ length = coeff_tab5[level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab5[level-1].code);
+ length += 9;
+ }
+ }
+ else if (run > 1 && run < 10 && level < 6)
+ {
+ length = coeff_tab6[run-2][level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab6[run-2][level-1].code);
+ length += 9;
+ }
+ }
+ else if (run > 9 && run < 15 && level == 1)
+ {
+ length = coeff_tab7[run-10].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab7[run-10].code);
+ length += 9;
+ }
+ }
+ return length;
+}
+Int PutRunCoeff_Intra_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 9)
+ {
+ length = coeff_tab8[level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab8[level-1].code);
+ length += 9;
+ }
+ }
+ else if (run > 0 && run < 7 && level < 4)
+ {
+ length = coeff_tab9[run-1][level-1].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab9[run-1][level-1].code);
+ length += 9;
+ }
+ }
+ else if (run > 6 && run < 21 && level == 1)
+ {
+ length = coeff_tab10[run-7].len;
+ if (length)
+ {
+ BitstreamPutGT8Bits(bitstream, 7 + 2, 14/*3*/);
+ //BitstreamPutBits(bitstream, 2, 2);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab10[run-7].code);
+ length += 9;
+ }
+ }
+ return length;
+}
+
+Int
+PutLevelCoeff_Inter(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run < 2 && level < 13)
+ {
+ length = coeff_tab0[run][level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab0[run][level-1].code);
+ length += 8;
+ }
+ }
+ else if (run > 1 && run < 27 && level < 5)
+ {
+ length = coeff_tab1[run-2][level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab1[run-2][level-1].code);
+ length += 8;
+ }
+ }
+ return length;
+}
+
+Int PutLevelCoeff_Inter_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run < 2 && level < 4)
+ {
+ length = coeff_tab2[run][level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab2[run][level-1].code);
+ length += 8;
+ }
+ }
+ else if (run > 1 && run < 42 && level == 1)
+ {
+ length = coeff_tab3[run-2].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab3[run-2].code);
+ length += 8;
+ }
+ }
+ return length;
+}
+
+Int PutLevelCoeff_Intra(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 28)
+ {
+ length = coeff_tab4[level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab4[level-1].code);
+ length += 8;
+ }
+ }
+ else if (run == 1 && level < 11)
+ {
+ length = coeff_tab5[level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab5[level-1].code);
+ length += 8;
+ }
+ }
+ else if (run > 1 && run < 10 && level < 6)
+ {
+ length = coeff_tab6[run-2][level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab6[run-2][level-1].code);
+ length += 8;
+ }
+ }
+ else if (run > 9 && run < 15 && level == 1)
+ {
+ length = coeff_tab7[run-10].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab7[run-10].code);
+ length += 8;
+ }
+ }
+ return length;
+}
+Int PutLevelCoeff_Intra_Last(Int run, Int level, BitstreamEncVideo *bitstream)
+{
+ Int length = 0;
+
+ if (run == 0 && level < 9)
+ {
+ length = coeff_tab8[level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab8[level-1].code);
+ length += 8;
+ }
+ }
+ else if (run > 0 && run < 7 && level < 4)
+ {
+ length = coeff_tab9[run-1][level-1].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab9[run-1][level-1].code);
+ length += 8;
+ }
+ }
+ else if (run > 6 && run < 21 && level == 1)
+ {
+ length = coeff_tab10[run-7].len;
+ if (length)
+ {
+ BitstreamPutBits(bitstream, 7 + 1, 6/*3*/);
+ BitstreamPutBits(bitstream, length, (UInt)coeff_tab10[run-7].code);
+ length += 8;
+ }
+ }
+ return length;
+}
+
+
+
+/* ======================================================================== */
+/* Function : MBVlcEncode() */
+/* Date : 09/10/2000 */
+/* Purpose : Encode GOV Header */
+/* In/out : */
+/* Return : */
+/* Modified : 5/21/01, break up into smaller functions */
+/* ======================================================================== */
+#ifndef H263_ONLY
+/**************************************/
+/* Data Partitioning I-VOP Encoding */
+/**************************************/
+
+void MBVlcEncodeDataPar_I_VOP(
+ VideoEncData *video,
+ Int ncoefblck[],
+ void *blkCodePtr)
+{
+
+ BitstreamEncVideo *bs1 = video->bitstream1;
+ BitstreamEncVideo *bs2 = video->bitstream2;
+ BitstreamEncVideo *bs3 = video->bitstream3;
+ int i;
+ UChar Mode = video->headerInfo.Mode[video->mbnum];
+ UChar CBP;
+// MacroBlock *MB=video->outputMB;
+ Int mbnum = video->mbnum;
+ Int intraDC_decision, DC;
+// int temp;
+ Int dquant; /* 3/15/01 */
+ RunLevelBlock *RLB = video->RLB;
+ BlockCodeCoeffPtr BlockCodeCoeff = (BlockCodeCoeffPtr) blkCodePtr;
+
+ /* DC and AC Prediction, 5/28/01, compute CBP, intraDC_decision*/
+ DCACPred(video, Mode, &intraDC_decision, video->QP_prev);
+
+ /* CBP, Run, Level, and Sign */
+ RunLevel(video, 1, intraDC_decision, ncoefblck);
+ CBP = video->headerInfo.CBP[mbnum];
+
+ /* Compute DQuant */
+ dquant = video->QPMB[mbnum] - video->QP_prev; /* 3/15/01, QP_prev may not equal QPMB[mbnum-1] if mbnum-1 is skipped*/
+
+ video->QP_prev = video->QPMB[mbnum];
+
+ if (dquant && Mode == MODE_INTRA)
+ {
+ Mode = MODE_INTRA_Q;
+ }
+
+ if (dquant >= 0)
+ dquant = (PV_ABS(dquant) + 1);
+ else
+ dquant = (PV_ABS(dquant) - 1);
+
+ /* FIRST PART: ALL TO BS1 */
+
+ PutMCBPC_Intra(CBP, Mode, bs1); /* MCBPC */
+
+ if (Mode == MODE_INTRA_Q)
+ /* MAY NEED TO CHANGE DQUANT HERE */
+ BitstreamPutBits(bs1, 2, dquant); /* dquant*/
+
+
+ if (intraDC_decision == 0)
+ {
+ for (i = 0; i < 6; i++)
+ {
+ DC = video->RLB[i].level[0];
+ if (video->RLB[i].s[0])
+ DC = -DC;
+ if (i < 4)
+ /*temp =*/ IntraDC_dpcm(DC, 1, bs1); /* dct_dc_size_luminance, */
+ else /* dct_dc_differential, and */
+ /*temp =*/ IntraDC_dpcm(DC, 0, bs1); /* marker bit */
+ }
+ }
+
+ /* SECOND PART: ALL TO BS2*/
+
+ BitstreamPut1Bits(bs2, video->acPredFlag[video->mbnum]); /* ac_pred_flag */
+
+ /*temp=*/
+ PutCBPY(CBP >> 2, (Char)(1), bs2); /* cbpy */
+
+
+ /* THIRD PART: ALL TO BS3*/
+ /* MB_CodeCoeff(video,bs3); */ /* 5/22/01, replaced with below */
+ for (i = 0; i < 6; i++)
+ {
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs3, 1 - intraDC_decision, ncoefblck[i], Mode);/* Code Intra AC*/
+ }
+
+ return ;
+}
+
+/************************************/
+/* Data Partitioning P-VOP Encoding */
+/************************************/
+
+void MBVlcEncodeDataPar_P_VOP(
+ VideoEncData *video,
+ Int ncoefblck[],
+ void *blkCodePtr)
+{
+
+ BitstreamEncVideo *bs1 = video->bitstream1;
+ BitstreamEncVideo *bs2 = video->bitstream2;
+ BitstreamEncVideo *bs3 = video->bitstream3;
+ int i;
+ Int mbnum = video->mbnum;
+ UChar Mode = video->headerInfo.Mode[mbnum];
+ Int QP_tmp = video->QPMB[mbnum];
+ UChar CBP;
+// MacroBlock *MB=video->outputMB;
+ Int intra, intraDC_decision, DC;
+ Int pmvx, pmvy;
+// int temp;
+ Int dquant; /* 3/15/01 */
+ RunLevelBlock *RLB = video->RLB;
+ BlockCodeCoeffPtr BlockCodeCoeff = (BlockCodeCoeffPtr) blkCodePtr;
+
+ intra = (Mode == MODE_INTRA || Mode == MODE_INTRA_Q);
+
+ /* DC and AC Prediction, 5/28/01, compute CBP, intraDC_decision*/
+
+ if (intra)
+ {
+ if (video->usePrevQP)
+ {
+ QP_tmp = video->QPMB[mbnum-1];
+ }
+
+ DCACPred(video, Mode, &intraDC_decision, QP_tmp);
+ }
+ else
+ intraDC_decision = 0; /* used in RunLevel */
+
+ /* CBP, Run, Level, and Sign */
+ RunLevel(video, intra, intraDC_decision, ncoefblck);
+ CBP = video->headerInfo.CBP[mbnum];
+
+ /* Compute DQuant */
+ dquant = video->QPMB[mbnum] - video->QP_prev; /* 3/15/01, QP_prev may not equal QPMB[mbnum-1] if mbnum-1 is skipped*/
+
+ if (dquant && (Mode == MODE_INTRA || Mode == MODE_INTER))
+ {
+ Mode += 2; /* make it MODE_INTRA_Q and MODE_INTER_Q */
+ }
+
+ if (dquant >= 0)
+ dquant = (PV_ABS(dquant) + 1);
+ else
+ dquant = (PV_ABS(dquant) - 1);
+
+ /* FIRST PART: ALL TO BS1 */
+
+ if (CBP == 0 && intra == 0) /* Determine if Skipped MB */
+ {
+ if ((Mode == MODE_INTER) && (video->mot[mbnum][0].x == 0) && (video->mot[mbnum][0].y == 0))
+ Mode = video->headerInfo.Mode[video->mbnum] = MODE_SKIPPED;
+ else if ((Mode == MODE_INTER4V) && (video->mot[mbnum][1].x == 0) && (video->mot[mbnum][1].y == 0)
+ && (video->mot[mbnum][2].x == 0) && (video->mot[mbnum][2].y == 0)
+ && (video->mot[mbnum][3].x == 0) && (video->mot[mbnum][3].y == 0)
+ && (video->mot[mbnum][4].x == 0) && (video->mot[mbnum][4].y == 0))
+ Mode = video->headerInfo.Mode[video->mbnum] = MODE_SKIPPED;
+ }
+
+
+ if (Mode == MODE_SKIPPED)
+ {
+ BitstreamPut1Bits(bs1, 1); /* not_coded = 1 */
+ return;
+ }
+ else
+ BitstreamPut1Bits(bs1, 0); /* not_coded =0 */
+
+ video->QP_prev = video->QPMB[mbnum];
+ video->usePrevQP = 1;
+
+ PutMCBPC_Inter(CBP, Mode, bs1); /* MCBPC */
+
+ video->header_bits -= BitstreamGetPos(bs1); /* Header Bits */
+
+ if (Mode == MODE_INTER || Mode == MODE_INTER_Q)
+ {
+ find_pmvs(video, 0, &pmvx, &pmvy); /* Get predicted motion vectors */
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][0].x - pmvx, bs1); /* Write x to bitstream */
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][0].y - pmvy, bs1); /* Write y to bitstream */
+ }
+ else if (Mode == MODE_INTER4V)
+ {
+ for (i = 1; i < 5; i++)
+ {
+ find_pmvs(video, i, &pmvx, &pmvy);
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][i].x - pmvx, bs1);
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][i].y - pmvy, bs1);
+ }
+ }
+ video->header_bits += BitstreamGetPos(bs1); /* Header Bits */
+
+ /* SECOND PART: ALL TO BS2 */
+
+
+ if (intra)
+ {
+ BitstreamPut1Bits(bs2, video->acPredFlag[video->mbnum]); /* ac_pred_flag */
+ /*temp=*/
+ PutCBPY(CBP >> 2, (Char)(Mode == MODE_INTRA || Mode == MODE_INTRA_Q), bs2); /* cbpy */
+
+ if (Mode == MODE_INTRA_Q)
+ BitstreamPutBits(bs2, 2, dquant); /* dquant, 3/15/01*/
+
+ if (intraDC_decision == 0)
+ {
+ for (i = 0; i < 6; i++)
+ {
+ DC = video->RLB[i].level[0];
+ if (video->RLB[i].s[0])
+ DC = -DC;
+ if (i < 4)
+ /*temp =*/ IntraDC_dpcm(DC, 1, bs2); /* dct_dc_size_luminance, */
+ else /* dct_dc_differential, and */
+ /*temp =*/ IntraDC_dpcm(DC, 0, bs2); /* marker bit */
+ }
+ }
+
+ /****************************/ /* THIRD PART: ALL TO BS3 */
+ for (i = 0; i < 6; i++)
+ {
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs3, 1 - intraDC_decision, ncoefblck[i], Mode);/* Code Intra AC*/
+ }
+ }
+ else
+ {
+ /*temp=*/
+ PutCBPY(CBP >> 2, (Char)(Mode == MODE_INTRA || Mode == MODE_INTRA_Q), bs2); /* cbpy */
+ if (Mode == MODE_INTER_Q)
+ /* MAY NEED TO CHANGE DQUANT HERE */
+ BitstreamPutBits(bs2, 2, dquant); /* dquant, 3/15/01*/
+
+ /****************************/ /* THIRD PART: ALL TO BS3 */
+ for (i = 0; i < 6; i++)
+ {
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs3, 0, ncoefblck[i], Mode);/* Code Intra AC*/
+ }
+ }
+
+ return ;
+}
+#endif /* H263_ONLY */
+/****************************************************************************************/
+/* Short Header/Combined Mode with or without Error Resilience I-VOP and P-VOP Encoding */
+/* 5/21/01, B-VOP is not implemented yet!!!! */
+/****************************************************************************************/
+
+void MBVlcEncodeCombined_I_VOP(
+ VideoEncData *video,
+ Int ncoefblck[],
+ void *blkCodePtr)
+{
+
+ BitstreamEncVideo *bs1 = video->bitstream1;
+// BitstreamEncVideo *bs2 = video->bitstream2;
+// BitstreamEncVideo *bs3 = video->bitstream3;
+ int i;
+ UChar Mode = video->headerInfo.Mode[video->mbnum];
+ UChar CBP = video->headerInfo.CBP[video->mbnum];
+// MacroBlock *MB=video->outputMB;
+ Int mbnum = video->mbnum;
+ Int intraDC_decision;
+// int temp;
+ Int dquant; /* 3/15/01 */
+ RunLevelBlock *RLB = video->RLB;
+ Int DC;
+ Int shortVideoHeader = video->vol[video->currLayer]->shortVideoHeader;
+ BlockCodeCoeffPtr BlockCodeCoeff = (BlockCodeCoeffPtr) blkCodePtr;
+
+ /* DC and AC Prediction, 5/28/01, compute CBP, intraDC_decision*/
+
+#ifndef H263_ONLY
+ if (!shortVideoHeader)
+ DCACPred(video, Mode, &intraDC_decision, video->QP_prev);
+ else
+#endif
+ {
+ intraDC_decision = 0;
+ }
+
+ /* CBP, Run, Level, and Sign */
+
+ RunLevel(video, 1, intraDC_decision, ncoefblck);
+ CBP = video->headerInfo.CBP[mbnum];
+
+ /* Compute DQuant */
+ dquant = video->QPMB[mbnum] - video->QP_prev; /* 3/15/01, QP_prev may not equal QPMB[mbnum-1] if mbnum-1 is skipped*/
+
+ video->QP_prev = video->QPMB[mbnum];
+
+ if (dquant && Mode == MODE_INTRA)
+ {
+ Mode = MODE_INTRA_Q;
+ }
+
+ if (dquant >= 0)
+ dquant = (PV_ABS(dquant) + 1);
+ else
+ dquant = (PV_ABS(dquant) - 1);
+
+ PutMCBPC_Intra(CBP, Mode, bs1); /* mcbpc I_VOP */
+
+ if (!video->vol[video->currLayer]->shortVideoHeader)
+ {
+ BitstreamPut1Bits(bs1, video->acPredFlag[video->mbnum]); /* ac_pred_flag */
+ }
+
+ /*temp=*/
+ PutCBPY(CBP >> 2, (Char)(1), bs1); /* cbpy */
+
+ if (Mode == MODE_INTRA_Q)
+ /* MAY NEED TO CHANGE DQUANT HERE */
+ BitstreamPutBits(bs1, 2, dquant); /* dquant, 3/15/01*/
+
+ /*MB_CodeCoeff(video,bs1); 5/21/01, replaced by below */
+ /*******************/
+#ifndef H263_ONLY
+ if (shortVideoHeader) /* Short Header DC coefficients */
+ {
+#endif
+ for (i = 0; i < 6; i++)
+ {
+ DC = RLB[i].level[0];
+ if (RLB[i].s[0])
+ DC = -DC;
+ if (DC != 128)
+ BitstreamPutBits(bs1, 8, DC); /* intra_dc_size_luminance */
+ else
+ BitstreamPutBits(bs1, 8, 255); /* intra_dc_size_luminance */
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs1, 1, ncoefblck[i], Mode); /* Code short header Intra AC*/
+ }
+#ifndef H263_ONLY
+ }
+ else if (intraDC_decision == 0) /* Combined Intra Mode DC and AC coefficients */
+ {
+ for (i = 0; i < 6; i++)
+ {
+ DC = RLB[i].level[0];
+ if (RLB[i].s[0])
+ DC = -DC;
+
+ if (i < 4)
+ /*temp =*/ IntraDC_dpcm(DC, 1, bs1); /* dct_dc_size_luminance, */
+ else /* dct_dc_differential, and */
+ /*temp =*/ IntraDC_dpcm(DC, 0, bs1); /* marker bit */
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs1, 1, ncoefblck[i], Mode);/* Code Intra AC */
+ }
+ }
+ else /* Combined Mode Intra DC/AC coefficients */
+ {
+ for (i = 0; i < 6; i++)
+ {
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs1, 0, ncoefblck[i], Mode);/* Code Intra AC */
+ }
+ }
+#endif
+ /*******************/
+ return ;
+}
+
+void MBVlcEncodeCombined_P_VOP(
+ VideoEncData *video,
+ Int ncoefblck[],
+ void *blkCodePtr)
+{
+
+ BitstreamEncVideo *bs1 = video->bitstream1;
+// BitstreamEncVideo *bs2 = video->bitstream2;
+// BitstreamEncVideo *bs3 = video->bitstream3;
+ int i;
+ Int mbnum = video->mbnum;
+ UChar Mode = video->headerInfo.Mode[mbnum];
+ Int QP_tmp = video->QPMB[mbnum];
+ UChar CBP ;
+// MacroBlock *MB=video->outputMB;
+ Int intra, intraDC_decision;
+ Int pmvx, pmvy;
+// int temp;
+ Int dquant; /* 3/15/01 */
+ RunLevelBlock *RLB = video->RLB;
+ Int DC;
+ Int shortVideoHeader = video->vol[video->currLayer]->shortVideoHeader;
+ BlockCodeCoeffPtr BlockCodeCoeff = (BlockCodeCoeffPtr) blkCodePtr;
+
+ intra = (Mode == MODE_INTRA || Mode == MODE_INTRA_Q);
+
+ /* DC and AC Prediction, 5/28/01, compute intraDC_decision*/
+#ifndef H263_ONLY
+ if (!shortVideoHeader && intra)
+ {
+ if (video->usePrevQP)
+ {
+ QP_tmp = video->QPMB[mbnum-1];
+ }
+ DCACPred(video, Mode, &intraDC_decision, QP_tmp);
+ }
+ else
+#endif
+ intraDC_decision = 0;
+
+ /* CBP, Run, Level, and Sign */
+
+ RunLevel(video, intra, intraDC_decision, ncoefblck);
+ CBP = video->headerInfo.CBP[mbnum];
+
+ /* Compute DQuant */
+ dquant = video->QPMB[mbnum] - video->QP_prev; /* 3/15/01, QP_prev may not equal QPMB[mbnum-1] if mbnum-1 is skipped*/
+ if (dquant && (Mode == MODE_INTRA || Mode == MODE_INTER))
+ {
+ Mode += 2; /* make it MODE_INTRA_Q and MODE_INTER_Q */
+ }
+
+ if (dquant >= 0)
+ dquant = (PV_ABS(dquant) + 1);
+ else
+ dquant = (PV_ABS(dquant) - 1);
+
+ if (CBP == 0 && intra == 0) /* Determine if Skipped MB */
+ {
+ if ((Mode == MODE_INTER) && (video->mot[mbnum][0].x == 0) && (video->mot[mbnum][0].y == 0))
+ Mode = video->headerInfo.Mode[video->mbnum] = MODE_SKIPPED;
+ else if ((Mode == MODE_INTER4V) && (video->mot[mbnum][1].x == 0) && (video->mot[mbnum][1].y == 0)
+ && (video->mot[mbnum][2].x == 0) && (video->mot[mbnum][2].y == 0)
+ && (video->mot[mbnum][3].x == 0) && (video->mot[mbnum][3].y == 0)
+ && (video->mot[mbnum][4].x == 0) && (video->mot[mbnum][4].y == 0))
+ Mode = video->headerInfo.Mode[video->mbnum] = MODE_SKIPPED;
+ }
+
+ if (Mode == MODE_SKIPPED)
+ {
+ BitstreamPut1Bits(bs1, 1); /* not_coded = 1 */
+ return;
+ }
+ else
+ BitstreamPut1Bits(bs1, 0); /* not_coded =0 */
+
+ video->QP_prev = video->QPMB[mbnum];
+ video->usePrevQP = 1;
+
+ PutMCBPC_Inter(CBP, Mode, bs1); /* mcbpc P_VOP */
+
+ if (!video->vol[video->currLayer]->shortVideoHeader && intra)
+ {
+ BitstreamPut1Bits(bs1, video->acPredFlag[video->mbnum]); /* ac_pred_flag */
+ }
+
+ /*temp=*/
+ PutCBPY(CBP >> 2, (Char)(intra), bs1); /* cbpy */
+
+ if (Mode == MODE_INTRA_Q || Mode == MODE_INTER_Q)
+ /* MAY NEED TO CHANGE DQUANT HERE */
+ BitstreamPutBits(bs1, 2, dquant); /* dquant, 3/15/01*/
+
+ video->header_bits -= BitstreamGetPos(bs1); /* Header Bits */
+
+ if (!((video->vol[video->currLayer]->scalability) && (video->currVop->refSelectCode == 3)))
+ {
+ if (Mode == MODE_INTER || Mode == MODE_INTER_Q)
+ {
+ find_pmvs(video, 0, &pmvx, &pmvy); /* Get predicted motion vectors */
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][0].x - pmvx, bs1); /* Write x to bitstream */
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][0].y - pmvy, bs1); /* Write y to bitstream */
+ }
+ else if (Mode == MODE_INTER4V)
+ {
+ for (i = 1; i < 5; i++)
+ {
+ find_pmvs(video, i, &pmvx, &pmvy);
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][i].x - pmvx, bs1);
+ WriteMVcomponent(video->currVop->fcodeForward, video->mot[mbnum][i].y - pmvy, bs1);
+ }
+ }
+ }
+ video->header_bits += BitstreamGetPos(bs1); /* Header Bits */
+
+ /* MB_CodeCoeff(video,bs1); */ /* 5/22/01, replaced with below */
+ /****************************/
+ if (intra)
+ {
+#ifndef H263_ONLY
+ if (shortVideoHeader) /* Short Header DC coefficients */
+ {
+#endif
+ for (i = 0; i < 6; i++)
+ {
+ DC = RLB[i].level[0];
+ if (RLB[i].s[0])
+ DC = -DC;
+ if (DC != 128)
+ BitstreamPutBits(bs1, 8, DC); /* intra_dc_size_luminance */
+ else
+ BitstreamPutBits(bs1, 8, 255); /* intra_dc_size_luminance */
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs1, 1, ncoefblck[i], Mode); /* Code short header Intra AC*/
+ }
+#ifndef H263_ONLY
+ }
+ else if (intraDC_decision == 0) /* Combined Intra Mode DC and AC coefficients */
+ {
+ for (i = 0; i < 6; i++)
+ {
+ DC = RLB[i].level[0];
+ if (RLB[i].s[0])
+ DC = -DC;
+
+ if (i < 4)
+ /*temp =*/ IntraDC_dpcm(DC, 1, bs1); /* dct_dc_size_luminance, */
+ else /* dct_dc_differential, and */
+ /*temp =*/ IntraDC_dpcm(DC, 0, bs1); /* marker bit */
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs1, 1, ncoefblck[i], Mode);/* Code Intra AC */
+ }
+ }
+ else /* Combined Mode Intra DC/AC coefficients */
+ {
+ for (i = 0; i < 6; i++)
+ {
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs1, 0, ncoefblck[i], Mode);/* Code Intra AC */
+ }
+ }
+#endif
+ }
+ else /* Shortheader or Combined INTER Mode AC coefficients */
+ {
+ for (i = 0; i < 6; i++)
+ {
+ if (CBP&(1 << (5 - i)))
+ (*BlockCodeCoeff)(&(RLB[i]), bs1, 0, ncoefblck[i], Mode);/* Code Inter AC*/
+ }
+ }
+ /****************************/
+
+ return ;
+}
+
+/* ======================================================================== */
+/* Function : BlockCodeCoeff() */
+/* Date : 09/18/2000 */
+/* Purpose : VLC Encode AC/DC coeffs */
+/* In/out : */
+/* Return : */
+/* Modified : 5/16/01 grouping BitstreamPutBits calls */
+/* 5/22/01 break up function */
+/* ======================================================================== */
+#ifndef NO_RVLC
+/*****************/
+/* RVLC ENCODING */
+/*****************/
+Void BlockCodeCoeff_RVLC(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode)
+{
+ int length = 0;
+ int i;
+ Int level;
+ Int run;
+ Int intra = (Mode == MODE_INTRA || Mode == MODE_INTRA_Q);
+
+ /* Not Last Coefficient */
+ for (i = j_start; i < j_stop - 1; i++)
+ {
+ run = RLB->run[i];
+ level = RLB->level[i];
+ //if(i==63||RLB->run[i+1] == -1) /* Don't Code Last Coefficient Here */
+ // break;
+ /*ENCODE RUN LENGTH */
+ if (level < 28 && run < 39)
+ {
+ if (intra)
+ length = PutCoeff_Intra_RVLC(run, level, bs);
+ else
+ length = PutCoeff_Inter_RVLC(run, level, bs);
+ }
+ else
+ length = 0;
+ /* ESCAPE CODING */
+ if (length == 0)
+ {
+ BitstreamPutBits(bs, 5 + 1, 2); /* ESCAPE + Not Last Coefficient */
+ //BitstreamPutBits(bs,1,0); /* Not Last Coefficient */
+ BitstreamPutBits(bs, 6 + 1, (run << 1) | 1); /* RUN + MARKER BIT*/
+ //BitstreamPutBits(bs,1,1); /* MARKER BIT */
+ BitstreamPutGT8Bits(bs, 11, level); /* LEVEL */
+ BitstreamPutBits(bs, 1 + 4, 16); /* MARKER BIT */
+ //BitstreamPutBits(bs,4,0); /* RVLC TRAILING ESCAPE */
+ }
+ BitstreamPutBits(bs, 1, RLB->s[i]); /* SIGN BIT */
+ }
+ /* Last Coefficient!!! */
+ run = RLB->run[i];
+ level = RLB->level[i];
+
+ /*ENCODE RUN LENGTH */
+ if (level < 6 && run < 45)
+ {
+ if (intra)
+ length = PutCoeff_Intra_RVLC_Last(run, level, bs);
+ else
+ length = PutCoeff_Inter_RVLC_Last(run, level, bs);
+ }
+ else
+ length = 0;
+ /* ESCAPE CODING */
+ if (length == 0)
+ {
+ BitstreamPutBits(bs, 5 + 1, 3); /* ESCAPE CODE + Last Coefficient*/
+ //BitstreamPutBits(bs,1,1); /* Last Coefficient !*/
+ BitstreamPutBits(bs, 6 + 1, (run << 1) | 1); /* RUN + MARKER BIT*/
+ //BitstreamPutBits(bs,1,1); /* MARKER BIT */
+ BitstreamPutGT8Bits(bs, 11, level); /* LEVEL */
+ BitstreamPutBits(bs, 1 + 4, 16); /* MARKER BIT + RVLC TRAILING ESCAPE */
+ //BitstreamPutBits(bs,4,0); /* */
+ }
+ BitstreamPut1Bits(bs, RLB->s[i]); /* SIGN BIT */
+
+ return ;
+}
+#endif
+/*******************************/
+/* SHORT VIDEO HEADER ENCODING */
+/*******************************/
+
+Void BlockCodeCoeff_ShortHeader(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode)
+{
+ int length = 0;
+ int i;
+// int temp;
+ Int level;
+ Int run;
+
+ OSCL_UNUSED_ARG(Mode);
+
+ /* Not Last Coefficient */
+ for (i = j_start; i < j_stop - 1; i++)
+ {
+ run = RLB->run[i];
+ level = RLB->level[i];
+// if(i==63 ||RLB->run[i+1] == -1) /* Don't Code Last Coefficient Here */
+// break;
+ /*ENCODE RUN LENGTH */
+ if (level < 13)
+ {
+ length = PutCoeff_Inter(run, level, bs);
+ if (length != 0)
+ /*temp =*/ BitstreamPut1Bits(bs, RLB->s[i]); /* Sign Bit */
+ }
+ else
+ length = 0;
+ /* ESCAPE CODING */
+ if (length == 0)
+ {
+ if (RLB->s[i])
+ level = -level;
+ BitstreamPutBits(bs, 7 + 1, 6); /* ESCAPE CODE + Not Last Coefficient */
+ //BitstreamPutBits(bs,1,0); /* Not Last Coefficient */
+ BitstreamPutBits(bs, 6, run); /* RUN */
+ BitstreamPutBits(bs, 8, level&0xFF); /* LEVEL, mask to make sure length 8 */
+ }
+ }
+ /* Last Coefficient!!! */
+ run = RLB->run[i];
+ level = RLB->level[i];
+
+ /*ENCODE RUN LENGTH */
+ if (level < 13)
+ {
+ length = PutCoeff_Inter_Last(run, level, bs);
+ if (length != 0)
+ /*temp =*/ BitstreamPut1Bits(bs, RLB->s[i]); /* Sign Bit */
+ }
+ else
+ length = 0;
+ /* ESCAPE CODING */
+ if (length == 0)
+ {
+ if (RLB->s[i])
+ level = -level;
+ BitstreamPutBits(bs, 7 + 1, 7); /* ESCAPE CODE + Last Coefficient */
+ //BitstreamPutBits(bs,1,1); /* Last Coefficient !!!*/
+ BitstreamPutBits(bs, 6, run); /* RUN */
+ BitstreamPutBits(bs, 8, level&0xFF); /* LEVEL, mask to make sure length 8 */
+ }
+
+ return ;
+
+}
+
+#ifndef H263_ONLY
+/****************/
+/* VLC ENCODING */
+/****************/
+Void BlockCodeCoeff_Normal(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode)
+{
+ int length = 0;
+ int i;
+ //int temp;
+ Int level;
+ Int run;
+ Int intra = (Mode == MODE_INTRA || Mode == MODE_INTRA_Q);
+ Int level_minus_max;
+ Int run_minus_max;
+ Int(*PutCoeff)(Int, Int, BitstreamEncVideo *); /* pointer to functions, 5/28/01 */
+
+ /* Not Last Coefficient!!! */
+
+ if (intra)
+ PutCoeff = &PutCoeff_Intra;
+ else
+ PutCoeff = &PutCoeff_Inter;
+
+ for (i = j_start; i < j_stop - 1; i++)
+ {
+ run = RLB->run[i];
+ level = RLB->level[i];
+
+ /* Encode Run Length */
+ if (level < 28)
+ {
+ length = (*PutCoeff)(run, level, bs); /* 5/28/01 replaces above */
+ }
+ else
+ {
+ length = 0;
+ }
+
+ /* First escape mode: LEVEL OFFSET */
+ if (length == 0)
+ {
+ if (intra)
+ {
+ level_minus_max = level - intra_max_level[0][run];
+ if (level_minus_max < 28)
+ length = PutLevelCoeff_Intra(run, level_minus_max, bs);
+ else
+ length = 0;
+ }
+ else
+ {
+ level_minus_max = level - inter_max_level[0][run];
+ if (level_minus_max < 13)
+ length = PutLevelCoeff_Inter(run, level_minus_max, bs);
+ else
+ length = 0;
+ }
+
+ /* Second escape mode: RUN OFFSET */
+ if (length == 0)
+ {
+ if (level < 28)
+ {
+ if (intra)
+ {
+ run_minus_max = run - (intra_max_run0[level] + 1);
+ length = PutRunCoeff_Intra(run_minus_max, level, bs);
+ }
+ else if (level < 13)
+ {
+ run_minus_max = run - (inter_max_run0[level] + 1);
+ length = PutRunCoeff_Inter(run_minus_max, level, bs);
+ }
+ else
+ {
+ length = 0;
+ }
+ }
+ else
+ {
+ length = 0;
+ }
+
+ /* Third escape mode: FIXED LENGTH CODE */
+ if (length == 0)
+ {
+ if (RLB->s[i])
+ level = -level;
+ /*temp =*/
+ BitstreamPutBits(bs, 7 + 2 + 1, 30); /* ESCAPE CODE + Followed by 11 + Not Last Coefficient*/
+ //temp = BitstreamPutBits(bs,2,3); /* Followed by 11 */
+ //temp = BitstreamPutBits(bs, 1, 0); /* Not Last Coefficient*/
+ /*temp =*/
+ BitstreamPutBits(bs, 6 + 1, (run << 1) | 1); /* Encode Run + Marker Bit */
+ //temp = BitstreamPutBits(bs,1,1); /* Marker Bit */
+ /*temp =*/
+ BitstreamPutGT8Bits(bs, 12 + 1, ((level << 1) | 1)&0x1FFF); /* Encode Level, mask to make sure length 12 */
+ //temp = BitstreamPutBits(bs,1,1); /* Marker Bit */
+ }
+ }
+ }
+
+ /* Encode Sign Bit */
+ if (length != 0)
+ /*temp =*/ BitstreamPut1Bits(bs, RLB->s[i]); /* Sign Bit */
+
+ }
+ /* Last Coefficient */
+ run = RLB->run[i];
+ level = RLB->level[i];
+
+ /* Encode Run Length */
+ if (level < 9)
+ {
+ if (intra)
+ {
+ length = PutCoeff_Intra_Last(run, level, bs);
+ }
+ else if (level < 4)
+ {
+ length = PutCoeff_Inter_Last(run, level, bs);
+ }
+ else
+ {
+ length = 0;
+ }
+ }
+ else
+ {
+ length = 0;
+ }
+
+ /* First escape mode: LEVEL OFFSET */
+ if (length == 0)
+ {
+ if (intra)
+ {
+ level_minus_max = level - intra_max_level[1][run];
+ if (level_minus_max < 9)
+ length = PutLevelCoeff_Intra_Last(run, level_minus_max, bs);
+ else
+ length = 0;
+ }
+ else
+ {
+ level_minus_max = level - inter_max_level[1][run];
+ if (level_minus_max < 4)
+ length = PutLevelCoeff_Inter_Last(run, level_minus_max, bs);
+ else
+ length = 0;
+ }
+ /* Second escape mode: RUN OFFSET */
+ if (length == 0)
+ {
+ if (level < 9)
+ {
+ if (intra)
+ {
+ run_minus_max = run - (intra_max_run1[level] + 1);
+ length = PutRunCoeff_Intra_Last(run_minus_max, level, bs);
+ }
+ else if (level < 4)
+ {
+ run_minus_max = run - (inter_max_run1[level] + 1);
+ length = PutRunCoeff_Inter_Last(run_minus_max, level, bs);
+ }
+ else
+ {
+ length = 0;
+ }
+ }
+ else
+ {
+ length = 0;
+ }
+ /* Third escape mode: FIXED LENGTH CODE */
+ if (length == 0)
+ {
+ if (RLB->s[i])
+ level = -level;
+ /*temp =*/
+ BitstreamPutGT8Bits(bs, 7 + 2 + 1, 31); /* ESCAPE CODE + Followed by 11 + Last Coefficient*/
+ //temp = BitstreamPutBits(bs,2,3); /* Followed by 11 */
+ //temp = BitstreamPutBits(bs, 1, 1); /* Last Coefficient!!!*/
+ /*temp =*/
+ BitstreamPutBits(bs, 6 + 1, (run << 1) | 1); /* Encode Run + Marker Bit */
+ //temp = BitstreamPutBits(bs,1,1); /* Marker Bit */
+ /*temp =*/
+ BitstreamPutGT8Bits(bs, 12 + 1, ((level << 1) | 1)&0x1FFF); /* Encode Level, mask to make sure length 8 */
+ //temp = BitstreamPutBits(bs,1,1); /* Marker Bit */
+ }
+ }
+ }
+
+ /* Encode Sign Bit */
+ if (length != 0)
+ /*temp =*/ BitstreamPut1Bits(bs, RLB->s[i]);
+
+
+ return ;
+}
+
+#endif /* H263_ONLY */
+/* ======================================================================== */
+/* Function : RUNLevel */
+/* Date : 09/20/2000 */
+/* Purpose : Get the Coded Block Pattern for each block */
+/* In/out : */
+/* Int* qcoeff Quantized DCT coefficients
+ Int Mode Coding Mode
+ Int ncoeffs Number of coefficients */
+/* Return : */
+/* Int CBP Coded Block Pattern */
+/* Modified : */
+/* ======================================================================== */
+
+void RunLevel(VideoEncData *video, Int intra, Int intraDC_decision, Int ncoefblck[])
+{
+ Int i, j;
+ Int CBP = video->headerInfo.CBP[video->mbnum];
+ Int ShortNacNintra = (!(video->vol[video->currLayer]->shortVideoHeader) && video->acPredFlag[video->mbnum] && intra);
+ MacroBlock *MB = video->outputMB;
+ Short *dataBlock;
+ Int level;
+ RunLevelBlock *RLB;
+ Int run, idx;
+ Int *zz, nc, zzorder;
+ UChar imask[6] = {0x1F, 0x2F, 0x37, 0x3B, 0x3D, 0x3E};
+ UInt *bitmapzz;
+
+ /* Set Run, Level and CBP for this Macroblock */
+ /* ZZ scan is done here. */
+
+ if (intra)
+ {
+
+ if (intraDC_decision != 0)
+ intra = 0; /* DC/AC in Run/Level */
+
+ for (i = 0; i < 6 ; i++)
+ {
+
+ zz = (Int *) zigzag_inv;
+
+ RLB = video->RLB + i;
+
+ dataBlock = MB->block[i];
+
+ if (intra)
+ {
+ RLB->run[0] = 0;
+ level = dataBlock[0];
+ dataBlock[0] = 0; /* reset to zero */
+ if (level < 0)
+ {
+ RLB->level[0] = -level;
+ RLB->s[0] = 1;
+ }
+ else
+ {
+ RLB->level[0] = level;
+ RLB->s[0] = 0;
+ }
+ }
+
+ idx = intra;
+
+ if ((CBP >> (5 - i)) & 1)
+ {
+ if (ShortNacNintra)
+ {
+ switch ((video->zz_direction >> (5 - i))&1)
+ {
+ case 0:
+ zz = (Int *)zigzag_v_inv;
+ break;
+ case 1:
+ zz = (Int *)zigzag_h_inv;
+ break;
+ }
+ }
+ run = 0;
+ nc = ncoefblck[i];
+ for (j = intra, zz += intra; j < nc; j++, zz++)
+ {
+ zzorder = *zz;
+ level = dataBlock[zzorder];
+ if (level == 0)
+ run++;
+ else
+ {
+ dataBlock[zzorder] = 0; /* reset output */
+ if (level < 0)
+ {
+ RLB->level[idx] = -level;
+ RLB->s[idx] = 1;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ else
+ {
+ RLB->level[idx] = level;
+ RLB->s[idx] = 0;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ }
+ }
+ }
+
+ ncoefblck[i] = idx; /* 5/22/01, reuse ncoefblck */
+
+ if (idx == intra) /* reset CBP, nothing to be coded */
+ CBP &= imask[i];
+ }
+
+ video->headerInfo.CBP[video->mbnum] = CBP;
+
+ return ;
+ }
+ else
+ {
+// zz = (Int *) zigzag_inv; no need to use it, default
+
+ if (CBP)
+ {
+ for (i = 0; i < 6 ; i++)
+ {
+ RLB = video->RLB + i;
+ idx = 0;
+
+ if ((CBP >> (5 - i)) & 1)
+ { /* 7/30/01 */
+ /* Use bitmapzz to find the Run,Level,Sign symbols */
+ bitmapzz = video->bitmapzz[i];
+ dataBlock = MB->block[i];
+ nc = ncoefblck[i];
+
+ idx = zero_run_search(bitmapzz, dataBlock, RLB, nc);
+ }
+ ncoefblck[i] = idx; /* 5/22/01, reuse ncoefblck */
+ if (idx == 0) /* reset CBP, nothing to be coded */
+ CBP &= imask[i];
+ }
+ video->headerInfo.CBP[video->mbnum] = CBP;
+ }
+ return ;
+ }
+}
+
+#ifndef H263_ONLY
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ static Bool IntraDCSwitch_Decision(Int Mode, Int intra_dc_vlc_thr, Int intraDCVlcQP)
+ {
+ Bool switched = FALSE;
+
+ if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
+ {
+ if (intra_dc_vlc_thr != 0)
+ {
+ switched = (intra_dc_vlc_thr == 7 || intraDCVlcQP >= intra_dc_vlc_thr * 2 + 11);
+ }
+ }
+
+ return switched;
+ }
+#ifdef __cplusplus
+}
+#endif
+
+Int IntraDC_dpcm(Int val, Int lum, BitstreamEncVideo *bitstream)
+{
+ Int n_bits;
+ Int absval, size = 0;
+
+ absval = (val < 0) ? -val : val; /* abs(val) */
+
+
+ /* compute dct_dc_size */
+
+ size = 0;
+ while (absval)
+ {
+ absval >>= 1;
+ size++;
+ }
+
+ if (lum)
+ { /* luminance */
+ n_bits = PutDCsize_lum(size, bitstream);
+ }
+ else
+ { /* chrominance */
+ n_bits = PutDCsize_chrom(size, bitstream);
+ }
+
+ if (size != 0)
+ {
+ if (val >= 0)
+ {
+ ;
+ }
+ else
+ {
+ absval = -val; /* set to "-val" MW 14-NOV-1996 */
+ val = absval ^((1 << size) - 1);
+ }
+ BitstreamPutBits(bitstream, (size), (UInt)(val));
+ n_bits += size;
+
+ if (size > 8)
+ BitstreamPut1Bits(bitstream, 1);
+ }
+
+ return n_bits; /* # bits for intra_dc dpcm */
+
+}
+
+/* ======================================================================== */
+/* Function : DC_AC_PRED */
+/* Date : 09/24/2000 */
+/* Purpose : DC and AC encoding of Intra Blocks */
+/* In/out : */
+/* VideoEncData *video
+ UChar Mode */
+/* Return : */
+/* */
+/* ======================================================================== */
+Int cal_dc_scalerENC(Int QP, Int type) ;
+
+
+#define PREDICT_AC for (m = 0; m < 7; m++){ \
+ tmp = DCAC[0]*QPtmp;\
+ if(tmp<0) tmp = (tmp-(QP/2))/QP;\
+ else tmp = (tmp+(QP/2))/QP;\
+ pred[m] = tmp;\
+ DCAC++;\
+ }
+
+
+Void DCACPred(VideoEncData *video, UChar Mode, Int *intraDC_decision, Int intraDCVlcQP)
+{
+ MacroBlock *MB = video->outputMB;
+ Int mbnum = video->mbnum;
+ typeDCStore *DC_store = video->predDC + mbnum;
+ typeDCACStore *DCAC_row = video->predDCAC_row;
+ typeDCACStore *DCAC_col = video->predDCAC_col;
+ Short *DCAC;
+ UChar Mode_top, Mode_left;
+
+ Vol *currVol = video->vol[video->currLayer];
+ Int nMBPerRow = currVol->nMBPerRow;
+ Int x_pos = video->outputMB->mb_x; /* 5/28/01 */
+ Int y_pos = video->outputMB->mb_y;
+ UChar QP = video->QPMB[mbnum];
+ UChar *QPMB = video->QPMB;
+ UChar *slice_nb = video->sliceNo;
+ Bool bACPredEnable = video->encParams->ACDCPrediction;
+ Int *ACpred_flag = video->acPredFlag;
+ Int mid_grey = 128 << 3;
+ Int m;
+ Int comp;
+ Int dc_scale = 8, tmp;
+
+ static const Int Xpos[6] = { -1, 0, -1, 0, -1, -1};
+ static const Int Ypos[6] = { -1, -1, 0, 0, -1, -1};
+ static const Int Xtab[6] = {1, 0, 3, 2, 4, 5};
+ static const Int Ytab[6] = {2, 3, 0, 1, 4, 5};
+ static const Int Ztab[6] = {3, 2, 1, 0, 4, 5};
+
+ /* I added these to speed up comparisons */
+ static const Int Pos0[6] = { 1, 1, 0, 0, 1, 1};
+ static const Int Pos1[6] = { 1, 0, 1, 0, 1, 1};
+ static const Int B_Xtab[6] = {0, 1, 0, 1, 2, 3};
+ static const Int B_Ytab[6] = {0, 0, 1, 1, 2, 3};
+
+ Int direction[6]; /* 0: HORIZONTAL, 1: VERTICAL */
+ Int block_A, block_B, block_C;
+ Int grad_hor, grad_ver, DC_pred;
+ Short pred[7], *predptr;
+ Short pcoeff[42];
+ Short *qcoeff;
+ Int S = 0, S1, S2;
+ Int diff, QPtmp;
+ Int newCBP[6];
+ UChar mask1[6] = {0x20, 0x10, 0x8, 0x4, 0x2, 0x1};
+// UChar mask2[6] = {0x1f,0x2f,0x37,0x3b,0x3d,0x3e};
+
+ Int y_offset, x_offset, x_tab, y_tab, z_tab; /* speedup coefficients */
+ Int b_xtab, b_ytab;
+
+ video->zz_direction = 0;
+
+ /* Standard MPEG-4 Headers do DC/AC prediction*/
+ /* check whether neighbors are INTER */
+ if (y_pos > 0)
+ {
+ Mode_top = video->headerInfo.Mode[mbnum-nMBPerRow];
+ if (!(Mode_top == MODE_INTRA || Mode_top == MODE_INTRA_Q))
+ {
+ DCAC = DC_store[-nMBPerRow];
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ /* set to 0 DCAC_row[x_pos][0..3] */
+ if (bACPredEnable == TRUE)
+ {
+ M4VENC_MEMSET(DCAC_row[x_pos][0], 0, sizeof(Short) << 5);
+ }
+ }
+ }
+ if (x_pos > 0)
+ {
+ Mode_left = video->headerInfo.Mode[mbnum-1];
+ if (!(Mode_left == MODE_INTRA || Mode_left == MODE_INTRA_Q))
+ {
+ DCAC = DC_store[-1];
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ *DCAC++ = mid_grey;
+ /* set to 0 DCAC_col[x_pos][0..3] */
+ if (bACPredEnable == TRUE)
+ {
+ M4VENC_MEMSET(DCAC_col[0][0], 0, sizeof(Short) << 5);
+ }
+ }
+ }
+
+ S1 = 0;
+ S2 = 0;
+
+ for (comp = 0; comp < 6; comp++)
+ {
+
+ if (Ypos[comp] != 0) y_offset = -nMBPerRow;
+ else y_offset = 0;
+ x_offset = Xpos[comp];
+ x_tab = Xtab[comp];
+ y_tab = Ytab[comp];
+ z_tab = Ztab[comp];
+
+ b_xtab = B_Xtab[comp];
+ b_ytab = B_Ytab[comp];
+
+ qcoeff = MB->block[comp];
+
+ /****************************/
+ /* Store DC coefficients */
+ /****************************/
+ /* Store coeff values for Intra MB */
+ if (comp == 0) dc_scale = cal_dc_scalerENC(QP, 1) ;
+ if (comp == 4) dc_scale = cal_dc_scalerENC(QP, 2) ;
+
+ QPtmp = qcoeff[0] * dc_scale; /* DC value */
+
+ if (QPtmp > 2047) /* 10/10/01, add clipping (bug fixed) */
+ DC_store[0][comp] = 2047;
+ else if (QPtmp < -2048)
+ DC_store[0][comp] = -2048;
+ else
+ DC_store[0][comp] = QPtmp;
+
+ /**************************************************************/
+ /* Find the direction of the prediction and the DC prediction */
+ /**************************************************************/
+
+ if ((x_pos == 0) && y_pos == 0)
+ { /* top left corner */
+ block_A = (comp == 1 || comp == 3) ? DC_store[0][x_tab] : mid_grey;
+ block_B = (comp == 3) ? DC_store[x_offset][z_tab] : mid_grey;
+ block_C = (comp == 2 || comp == 3) ? DC_store[0][y_tab] : mid_grey;
+ }
+ else if (x_pos == 0)
+ { /* left edge */
+ block_A = (comp == 1 || comp == 3) ? DC_store[0][x_tab] : mid_grey;
+ block_B = ((comp == 1 && (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow])) || comp == 3) ?
+ DC_store[y_offset+x_offset][z_tab] : mid_grey;
+ block_C = (comp == 2 || comp == 3 ||
+ (Pos0[comp] && (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow]))) ?
+ DC_store[y_offset][y_tab] : mid_grey;
+ }
+ else if (y_pos == 0)
+ { /* top row */
+ block_A = (comp == 1 || comp == 3 || (Pos1[comp] && (slice_nb[mbnum] == slice_nb[mbnum-1]))) ?
+ DC_store[x_offset][x_tab] : mid_grey;
+ block_B = ((comp == 2 && (slice_nb[mbnum] == slice_nb[mbnum-1])) || comp == 3) ?
+ DC_store[y_offset + x_offset][z_tab] : mid_grey;
+ block_C = (comp == 2 || comp == 3) ?
+ DC_store[y_offset][y_tab] : mid_grey;
+ }
+ else
+ {
+ block_A = (comp == 1 || comp == 3 || (Pos1[comp] && (slice_nb[mbnum] == slice_nb[mbnum-1]))) ?
+ DC_store[x_offset][x_tab] : mid_grey;
+ block_B = (((comp == 0 || comp == 4 || comp == 5) &&
+ (slice_nb[mbnum] == slice_nb[mbnum-1-nMBPerRow])) ||
+ (comp == 1 && (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow])) ||
+ (comp == 2 && (slice_nb[mbnum] == slice_nb[mbnum-1])) || (comp == 3)) ?
+ (DC_store[y_offset + x_offset][z_tab]) : mid_grey;
+ block_C = (comp == 2 || comp == 3 || (Pos0[comp] && (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow]))) ?
+ DC_store[y_offset][y_tab] : mid_grey;
+ }
+ grad_hor = block_B - block_C;
+ grad_ver = block_A - block_B;
+
+ if ((PV_ABS(grad_ver)) < (PV_ABS(grad_hor)))
+ {
+ DC_pred = block_C;
+ direction[comp] = 1;
+ video->zz_direction = (video->zz_direction) | mask1[comp];
+
+ }
+ else
+ {
+ DC_pred = block_A;
+ direction[comp] = 0;
+ //video->zz_direction=video->zz_direction<<1;
+ }
+
+ /* DC prediction */
+ QPtmp = dc_scale; /* 5/28/01 */
+ qcoeff[0] -= (DC_pred + QPtmp / 2) / QPtmp;
+
+
+ if (bACPredEnable)
+ {
+ /***********************/
+ /* Find AC prediction */
+ /***********************/
+
+ if ((x_pos == 0) && y_pos == 0) /* top left corner */
+ {
+ if (direction[comp] == 0)
+ {
+ if (comp == 1 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+x_offset];
+ DCAC = DCAC_col[0][b_ytab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ else
+ {
+ if (comp == 2 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+ y_offset];
+ DCAC = DCAC_row[x_pos][b_xtab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ }
+ else if (x_pos == 0) /* left edge */
+ {
+ if (direction[comp] == 0)
+ {
+ if (comp == 1 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+x_offset];
+ DCAC = DCAC_col[0][b_ytab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ else
+ {
+
+ if ((Pos0[comp] && (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow]))
+ || comp == 2 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+y_offset];
+ DCAC = DCAC_row[x_pos][b_xtab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ }
+ else if (y_pos == 0) /* top row */
+ {
+ if (direction[comp] == 0)
+ {
+ if ((Pos1[comp] && (slice_nb[mbnum] == slice_nb[mbnum-1]))
+ || comp == 1 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+x_offset];
+ DCAC = DCAC_col[0][b_ytab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ else
+ {
+ if (comp == 2 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+y_offset];
+ DCAC = DCAC_row[x_pos][b_xtab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ }
+ else
+ {
+ if (direction[comp] == 0)
+ {
+ if ((Pos1[comp] && (slice_nb[mbnum] == slice_nb[mbnum-1]))
+ || comp == 1 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+x_offset];
+ DCAC = DCAC_col[0][b_ytab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ else
+ {
+ if ((Pos0[comp] && (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow]))
+ || comp == 2 || comp == 3)
+ {
+ QPtmp = QPMB[mbnum+y_offset];
+ DCAC = DCAC_row[x_pos][b_xtab];
+ if (QPtmp != QP)
+ {
+ predptr = pred;
+ PREDICT_AC
+ }
+ else
+ {
+ predptr = DCAC;
+ }
+ }
+ else
+ {
+ predptr = pred;
+ pred[0] = pred[1] = pred[2] = pred[3] = pred[4] = pred[5] = pred[6] = 0;
+ }
+ }
+ }
+
+ /************************************/
+ /* Decide and Perform AC prediction */
+ /************************************/
+ newCBP[comp] = 0;
+
+ if (direction[comp] == 0) /* Horizontal, left COLUMN of block A */
+ {
+ DCAC = pcoeff + comp * 7; /* re-use DCAC as local var */
+ qcoeff += 8;
+ for (m = 0; m < 7; m++)
+ {
+ QPtmp = qcoeff[m<<3];
+ if (QPtmp > 0) S1 += QPtmp;
+ else S1 -= QPtmp;
+ QPtmp -= predptr[m];
+ DCAC[m] = QPtmp; /* save prediction residue to pcoeff*/
+ if (QPtmp) newCBP[comp] = 1;
+ diff = PV_ABS(QPtmp);
+ S2 += diff;
+ }
+ }
+ else /* Vertical, top ROW of block C */
+ {
+ qcoeff++;
+ DCAC = pcoeff + comp * 7; /* re-use DCAC as local var */
+ for (m = 0; m < 7; m++)
+ {
+ QPtmp = qcoeff[m];
+ if (QPtmp > 0) S1 += QPtmp;
+ else S1 -= QPtmp;
+ QPtmp -= predptr[m];
+ DCAC[m] = QPtmp; /* save prediction residue to pcoeff*/
+ if (QPtmp) newCBP[comp] = 1;
+ diff = PV_ABS(QPtmp);
+ S2 += diff;
+ }
+ }
+
+ /****************************/
+ /* Store DCAC coefficients */
+ /****************************/
+ /* Store coeff values for Intra MB */
+ qcoeff = MB->block[comp];
+ DCAC = DCAC_row[x_pos][b_xtab];
+ DCAC[0] = qcoeff[1];
+ DCAC[1] = qcoeff[2];
+ DCAC[2] = qcoeff[3];
+ DCAC[3] = qcoeff[4];
+ DCAC[4] = qcoeff[5];
+ DCAC[5] = qcoeff[6];
+ DCAC[6] = qcoeff[7];
+
+ DCAC = DCAC_col[0][b_ytab];
+ DCAC[0] = qcoeff[8];
+ DCAC[1] = qcoeff[16];
+ DCAC[2] = qcoeff[24];
+ DCAC[3] = qcoeff[32];
+ DCAC[4] = qcoeff[40];
+ DCAC[5] = qcoeff[48];
+ DCAC[6] = qcoeff[56];
+
+
+ } /* bACPredEnable */
+
+ } /* END COMP FOR LOOP */
+
+ //if (diff > 2047)
+ // break;
+ S += (S1 - S2);
+
+
+ if (S >= 0 && bACPredEnable == TRUE)
+ {
+ ACpred_flag[mbnum] = 1;
+ DCAC = pcoeff; /* prediction residue */
+ qcoeff = MB->block[0];
+
+ for (comp = 0; comp < 6; comp++)
+ {
+ if (direction[comp] == 0)
+ {
+ qcoeff[8] = DCAC[0];
+ qcoeff[16] = DCAC[1];
+ qcoeff[24] = DCAC[2];
+ qcoeff[32] = DCAC[3];
+ qcoeff[40] = DCAC[4];
+ qcoeff[48] = DCAC[5];
+ qcoeff[56] = DCAC[6];
+
+ }
+ else
+ {
+ qcoeff[1] = DCAC[0];
+ qcoeff[2] = DCAC[1];
+ qcoeff[3] = DCAC[2];
+ qcoeff[4] = DCAC[3];
+ qcoeff[5] = DCAC[4];
+ qcoeff[6] = DCAC[5];
+ qcoeff[7] = DCAC[6];
+ }
+ if (newCBP[comp]) /* 5/28/01, update CBP */
+ video->headerInfo.CBP[mbnum] |= mask1[comp];
+ DCAC += 7;
+ qcoeff += 64;
+ }
+ }
+ else /* Only DC Prediction */
+ {
+ ACpred_flag[mbnum] = 0;
+ }
+
+ *intraDC_decision = IntraDCSwitch_Decision(Mode, video->currVop->intraDCVlcThr, intraDCVlcQP);
+ if (*intraDC_decision) /* code DC with AC , 5/28/01*/
+ {
+ qcoeff = MB->block[0];
+ for (comp = 0; comp < 6; comp++)
+ {
+ if (*qcoeff)
+ video->headerInfo.CBP[mbnum] |= mask1[comp];
+ qcoeff += 64;
+ }
+ }
+ return;
+}
+#endif /* H263_ONLY */
+
+
+
+Void find_pmvs(VideoEncData *video, Int block, Int *mvx, Int *mvy)
+{
+ Vol *currVol = video->vol[video->currLayer];
+// UChar *Mode = video->headerInfo.Mode; /* modes for MBs */
+ UChar *slice_nb = video->sliceNo;
+ Int nMBPerRow = currVol->nMBPerRow;
+ Int mbnum = video->mbnum;
+
+ Int p1x, p2x, p3x;
+ Int p1y, p2y, p3y;
+ Int xin1, xin2, xin3;
+ Int yin1, yin2, yin3;
+ Int vec1, vec2, vec3;
+ Int rule1, rule2, rule3;
+ MOT **motdata = video->mot;
+ Int x = mbnum % nMBPerRow;
+ Int y = mbnum / nMBPerRow;
+
+ /*
+ In a previous version, a MB vector (block = 0) was predicted the same way
+ as block 1, which is the most likely interpretation of the VM.
+
+ Therefore, if we have advanced pred. mode, and if all MBs around have
+ only one 16x16 vector each, we chose the appropiate block as if these
+ MBs have 4 vectors.
+
+ This different prediction affects only 16x16 vectors of MBs with
+ transparent blocks.
+
+ In the current version, we choose for the 16x16 mode the first
+ non-transparent block in the surrounding MBs
+ */
+
+ switch (block)
+ {
+ case 0:
+ vec1 = 2 ;
+ yin1 = y ;
+ xin1 = x - 1;
+ vec2 = 3 ;
+ yin2 = y - 1;
+ xin2 = x;
+ vec3 = 3 ;
+ yin3 = y - 1;
+ xin3 = x + 1;
+ break;
+
+ case 1:
+ vec1 = 2 ;
+ yin1 = y ;
+ xin1 = x - 1;
+ vec2 = 3 ;
+ yin2 = y - 1;
+ xin2 = x;
+ vec3 = 3 ;
+ yin3 = y - 1;
+ xin3 = x + 1;
+ break;
+
+ case 2:
+ vec1 = 1 ;
+ yin1 = y ;
+ xin1 = x;
+ vec2 = 4 ;
+ yin2 = y - 1;
+ xin2 = x;
+ vec3 = 3 ;
+ yin3 = y - 1;
+ xin3 = x + 1;
+ break;
+
+ case 3:
+ vec1 = 4 ;
+ yin1 = y ;
+ xin1 = x - 1;
+ vec2 = 1 ;
+ yin2 = y ;
+ xin2 = x;
+ vec3 = 2 ;
+ yin3 = y ;
+ xin3 = x;
+ break;
+
+ default: /* case 4 */
+ vec1 = 3 ;
+ yin1 = y ;
+ xin1 = x;
+ vec2 = 1 ;
+ yin2 = y ;
+ xin2 = x;
+ vec3 = 2 ;
+ yin3 = y ;
+ xin3 = x;
+ break;
+ }
+
+ if (block == 0)
+ {
+ /* according to the motion encoding, we must choose a first non-transparent
+ block in the surrounding MBs (16-mode)
+ */
+
+ if (x > 0 && slice_nb[mbnum] == slice_nb[mbnum-1])
+ rule1 = 0;
+ else
+ rule1 = 1;
+
+ if (y > 0 && slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow])
+ rule2 = 0;
+ else
+ rule2 = 1;
+
+ if ((x != nMBPerRow - 1) && (y > 0) && slice_nb[mbnum] == slice_nb[mbnum+1-nMBPerRow])
+ rule3 = 0;
+ else
+ rule3 = 1;
+ }
+ else
+ {
+ /* check borders for single blocks (advanced mode) */
+ /* rule 1 */
+ if (((block == 1 || block == 3) &&
+ (x == 0 || slice_nb[mbnum] != slice_nb[mbnum-1])))
+ rule1 = 1;
+ else
+ rule1 = 0;
+
+ /* rule 2 */
+ if (((block == 1 || block == 2) &&
+ (y == 0 || slice_nb[mbnum] != slice_nb[mbnum-nMBPerRow])))
+ rule2 = 1;
+ else
+ rule2 = 0;
+
+ /* rule 3 */
+ if (((block == 1 || block == 2) &&
+ (x == nMBPerRow - 1 || y == 0 || slice_nb[mbnum] != slice_nb[mbnum+1-nMBPerRow])))
+ rule3 = 1;
+ else
+ rule3 = 0;
+ }
+
+ if (rule1)
+ {
+ p1x = p1y = 0;
+ }
+ else
+ {
+
+ p1x = motdata[yin1*nMBPerRow+xin1][vec1].x;
+ p1y = motdata[yin1*nMBPerRow+xin1][vec1].y;
+ //p1x = motxdata[xin1*2+(vec1&0x1) + (yin1*2+(vec1>>1))*xB];
+ //p1y = motydata[xin1*2+(vec1&0x1) + (yin1*2+(vec1>>1))*xB];
+ }
+
+ if (rule2)
+ {
+ p2x = p2y = 0;
+ }
+ else
+ {
+ p2x = motdata[yin2*nMBPerRow+xin2][vec2].x;
+ p2y = motdata[yin2*nMBPerRow+xin2][vec2].y;
+ //p2x = motxdata[xin2*2+(vec2&0x1) + (yin2*2+(vec2>>1))*xB];
+ //p2y = motydata[xin2*2+(vec2&0x1) + (yin2*2+(vec2>>1))*xB];
+ }
+
+ if (rule3)
+ {
+ p3x = p3y = 0;
+ }
+ else
+ {
+ p3x = motdata[yin3*nMBPerRow+xin3][vec3].x;
+ p3y = motdata[yin3*nMBPerRow+xin3][vec3].y;
+ //p3x = motxdata[xin3*2+ (vec3&0x1) + (yin3*2+(vec3>>1))*xB];
+ //p3y = motydata[xin3*2+ (vec3&0x1) + (yin3*2+(vec3>>1))*xB];
+ }
+
+ if (rule1 && rule2 && rule3)
+ {
+ /* all MBs are outside the VOP */
+ *mvx = *mvy = 0;
+ }
+ else if (rule1 + rule2 + rule3 == 2)
+ {
+ /* two of three are zero */
+ *mvx = (p1x + p2x + p3x);
+ *mvy = (p1y + p2y + p3y);
+ }
+ else
+ {
+ *mvx = ((p1x + p2x + p3x - PV_MAX(p1x, PV_MAX(p2x, p3x)) - PV_MIN(p1x, PV_MIN(p2x, p3x))));
+ *mvy = ((p1y + p2y + p3y - PV_MAX(p1y, PV_MAX(p2y, p3y)) - PV_MIN(p1y, PV_MIN(p2y, p3y))));
+ }
+
+ return;
+}
+
+
+Void WriteMVcomponent(Int f_code, Int dmv, BitstreamEncVideo *bs)
+{
+ Int residual, vlc_code_mag, bits, entry;
+
+ ScaleMVD(f_code, dmv, &residual, &vlc_code_mag);
+
+ if (vlc_code_mag < 0)
+ entry = vlc_code_mag + 65;
+ else
+ entry = vlc_code_mag;
+
+ bits = PutMV(entry, bs);
+
+ if ((f_code != 1) && (vlc_code_mag != 0))
+ {
+ BitstreamPutBits(bs, f_code - 1, residual);
+ bits += f_code - 1;
+ }
+ return;
+}
+
+
+Void
+ScaleMVD(
+ Int f_code, /* <-- MV range in 1/2 units: 1=32,2=64,...,7=2048 */
+ Int diff_vector, /* <-- MV Difference commponent in 1/2 units */
+ Int *residual, /* --> value to be FLC coded */
+ Int *vlc_code_mag /* --> value to be VLC coded */
+)
+{
+ Int range;
+ Int scale_factor;
+ Int r_size;
+ Int low;
+ Int high;
+ Int aux;
+
+ r_size = f_code - 1;
+ scale_factor = 1 << r_size;
+ range = 32 * scale_factor;
+ low = -range;
+ high = range - 1;
+
+ if (diff_vector < low)
+ diff_vector += 2 * range;
+ else if (diff_vector > high)
+ diff_vector -= 2 * range;
+
+ if (diff_vector == 0)
+ {
+ *vlc_code_mag = 0;
+ *residual = 0;
+ }
+ else if (scale_factor == 1)
+ {
+ *vlc_code_mag = diff_vector;
+ *residual = 0;
+ }
+ else
+ {
+ aux = PV_ABS(diff_vector) + scale_factor - 1;
+ *vlc_code_mag = aux >> r_size;
+
+ if (diff_vector < 0)
+ *vlc_code_mag = -*vlc_code_mag;
+ *residual = aux & (scale_factor - 1);
+ }
+}
diff --git a/media/codecs/m4v_h263/enc/src/vlc_encode.h b/media/codecs/m4v_h263/enc/src/vlc_encode.h
new file mode 100644
index 0000000..3721b6b
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/vlc_encode.h
@@ -0,0 +1,42 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _VLC_ENCODE_H_
+#define _VLC_ENCODE_H_
+
+#include "mp4def.h"
+#include "mp4enc_api.h"
+
+Int PutCoeff_Inter(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+Int PutCoeff_Intra(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+Int PutCBPY(Int cbpy, Char intra, BitstreamEncVideo *bitstream);
+Int PutMCBPC_Inter(Int cbpc, Int mode, BitstreamEncVideo *bitstream);
+Int PutMCBPC_Intra(Int cbpc, Int mode, BitstreamEncVideo *bitstream);
+Int PutMV(Int mvint, BitstreamEncVideo *bitstream);
+Int PutDCsize_chrom(Int size, BitstreamEncVideo *bitstream);
+Int PutDCsize_lum(Int size, BitstreamEncVideo *bitstream);
+Int PutDCsize_lum(Int size, BitstreamEncVideo *bitstream);
+Int PutCoeff_Inter_RVLC(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+Int PutCoeff_Intra_RVLC(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+Int PutRunCoeff_Inter(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+Int PutRunCoeff_Intra(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+Int PutLevelCoeff_Inter(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+Int PutLevelCoeff_Intra(Int run, Int level, Int last, BitstreamEncVideo *bitstream);
+
+Void MB_CodeCoeff(VideoEncData *video, BitstreamEncVideo *bs);
+Void BlockCodeCoeff(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, UChar Mode, Int rvlc, Int shortVideoHeader);
+#endif /* _VLC_ENCODE_H_ */
diff --git a/media/codecs/m4v_h263/enc/src/vlc_encode_inline.h b/media/codecs/m4v_h263/enc/src/vlc_encode_inline.h
new file mode 100644
index 0000000..a2f4934
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/vlc_encode_inline.h
@@ -0,0 +1,316 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#ifndef _VLC_ENCODE_INLINE_H_
+#define _VLC_ENCODE_INLINE_H_
+
+#if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4)
+
+__inline Int zero_run_search(UInt *bitmapzz, Short *dataBlock, RunLevelBlock *RLB, Int nc)
+{
+ Int idx, run, level, j;
+ UInt end, match;
+
+ idx = 0;
+ j = 0;
+ run = 0;
+ match = 1 << 31;
+ if (nc > 32)
+ end = 1;
+ else
+ end = 1 << (32 - nc);
+
+ while (match >= end)
+ {
+ if ((match&bitmapzz[0]) == 0)
+ {
+ run++;
+ j++;
+ match >>= 1;
+ }
+ else
+ {
+ match >>= 1;
+ level = dataBlock[j];
+ dataBlock[j] = 0; /* reset output */
+ j++;
+ if (level < 0)
+ {
+ RLB->level[idx] = -level;
+ RLB->s[idx] = 1;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ else
+ {
+ RLB->level[idx] = level;
+ RLB->s[idx] = 0;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ }
+ }
+ nc -= 32;
+ if (nc > 0)
+ {
+ match = 1 << 31;
+ end = 1 << (32 - nc);
+ while (match >= end)
+ {
+ if ((match&bitmapzz[1]) == 0)
+ {
+ run++;
+ j++;
+ match >>= 1;
+ }
+ else
+ {
+ match >>= 1;
+ level = dataBlock[j];
+ dataBlock[j] = 0; /* reset output */
+ j++;
+ if (level < 0)
+ {
+ RLB->level[idx] = -level;
+ RLB->s[idx] = 1;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ else
+ {
+ RLB->level[idx] = level;
+ RLB->s[idx] = 0;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ }
+ }
+ }
+
+ return idx;
+}
+
+#elif defined(__CC_ARM) /* only work with arm v5 */
+
+__inline Int zero_run_search(UInt *bitmapzz, Short *dataBlock, RunLevelBlock *RLB, Int nc)
+{
+ OSCL_UNUSED_ARG(nc);
+ Int idx, run, level, j;
+ UInt end, match;
+ Int zzorder;
+
+ idx = 0;
+ run = 0;
+ j = -1;
+ __asm
+ {
+ ldr match, [bitmapzz]
+ clz run, match
+ }
+
+ zzorder = 0;
+
+ while (run < 32)
+ {
+ __asm
+ {
+ mov end, #0x80000000
+ mov end, end, lsr run /* mask*/
+ bic match, match, end /* remove it from bitmap */
+ mov run, run, lsl #1 /* 05/09/02 */
+ ldrsh level, [dataBlock, run] /* load data */
+ strh zzorder, [dataBlock, run] /* reset output */
+ add j, j, #1
+ rsb run, j, run, lsr #1 /* delta run */
+ add j, j, run /* current position */
+ }
+ if (level < 0)
+ {
+ RLB->level[idx] = -level;
+ RLB->s[idx] = 1;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ else
+ {
+ RLB->level[idx] = level;
+ RLB->s[idx] = 0;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ __asm
+ {
+ clz run, match
+ }
+ }
+ __asm
+ {
+ ldr match, [bitmapzz, #4]
+ clz run, match
+ }
+
+ while (run < 32)
+ {
+ __asm
+ {
+ mov end, #0x80000000
+ mov end, end, lsr run /* mask*/
+ bic match, match, end /* remove it from bitmap */
+ add run, run, #32 /* current position */
+ mov run, run, lsl #1 /* 09/02/05 */
+ ldrsh level, [dataBlock, run] /* load data */
+ strh zzorder, [dataBlock, run] /* reset output */
+ add j, j, #1
+ rsb run, j, run, lsr #1 /* delta run */
+ add j, j, run /* current position */
+ }
+ if (level < 0)
+ {
+ RLB->level[idx] = -level;
+ RLB->s[idx] = 1;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ else
+ {
+ RLB->level[idx] = level;
+ RLB->s[idx] = 0;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ __asm
+ {
+ clz run, match
+ }
+ }
+
+ return idx;
+}
+
+#elif ( defined(PV_ARM_GCC_V4) || defined(PV_ARM_GCC_V5) ) /* ARM GNU COMPILER */
+
+__inline Int m4v_enc_clz(UInt temp)
+{
+ register Int rb;
+ register UInt ra = (UInt)temp;
+
+ asm volatile("clz %0, %1"
+ : "=&r"(rb)
+ : "r"(ra)
+ );
+
+ return (rb);
+}
+
+__inline Int zero_run_search(UInt *bitmapzz, Short *dataBlock, RunLevelBlock *RLB, Int nc)
+{
+ OSCL_UNUSED_ARG(nc);
+ Int idx, run, level = 0, j;
+ UInt end = 0, match;
+ Int zzorder;
+
+ idx = 0;
+ run = 0;
+ j = -1;
+ match = *bitmapzz;
+ run = m4v_enc_clz(match);
+
+ zzorder = 0;
+
+ while (run < 32)
+ {
+ asm volatile("mov %0, #0x80000000\n\t"
+ "mov %0, %0, lsr %1\n\t"
+ "bic %2, %2, %0\n\t"
+ "mov %1, %1, lsl #1\n\t"
+ "ldrsh %3, [%6, %1]\n\t"
+ "strh %5, [%6, %1]\n\t"
+ "add %4, %4, #1\n\t"
+ "rsb %1, %4, %1, lsr #1\n\t"
+ "add %4, %4, %1"
+ : "+r"(end), "+r"(run), "+r"(match), "=r"(level), "+r"(j)
+ : "r"(zzorder), "r"(dataBlock));
+ if (level < 0)
+ {
+ RLB->level[idx] = -level;
+ RLB->s[idx] = 1;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ else
+ {
+ RLB->level[idx] = level;
+ RLB->s[idx] = 0;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ run = m4v_enc_clz(match);
+ }
+ match = bitmapzz[1];
+ run = m4v_enc_clz(match);
+
+ while (run < 32)
+ {
+ asm volatile("mov %0, #0x80000000\n\t"
+ "mov %0, %0, lsr %1\n\t"
+ "bic %2, %2, %0\n\t"
+ "add %1, %1, #32\n\t"
+ "mov %1, %1, lsl #1\n\t"
+ "ldrsh %3, [%6, %1]\n\t"
+ "strh %5, [%6, %1]\n\t"
+ "add %4, %4, #1\n\t"
+ "rsb %1, %4, %1, lsr #1\n\t"
+ "add %4, %4, %1"
+ : "+r"(end), "+r"(run), "+r"(match), "+r"(level), "+r"(j)
+ : "r"(zzorder), "r"(dataBlock));
+ if (level < 0)
+ {
+ RLB->level[idx] = -level;
+ RLB->s[idx] = 1;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ else
+ {
+ RLB->level[idx] = level;
+ RLB->s[idx] = 0;
+ RLB->run[idx] = run;
+ run = 0;
+ idx++;
+ }
+ run = m4v_enc_clz(match);
+ }
+
+ return idx;
+}
+
+#endif
+
+#endif // _VLC_ENCODE_INLINE_H_
+
+
diff --git a/media/codecs/m4v_h263/enc/src/vop.cpp b/media/codecs/m4v_h263/enc/src/vop.cpp
new file mode 100644
index 0000000..47076c3
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/src/vop.cpp
@@ -0,0 +1,581 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+#include "mp4def.h"
+#include "mp4lib_int.h"
+#include "mp4enc_lib.h"
+#include "bitstream_io.h"
+#include "m4venc_oscl.h"
+
+PV_STATUS EncodeShortHeader(BitstreamEncVideo *stream, Vop *currVop);
+PV_STATUS EncodeVOPHeader(BitstreamEncVideo *stream, Vol *currVol, Vop *currVop);
+PV_STATUS EncodeGOVHeader(BitstreamEncVideo *stream, UInt seconds);
+
+PV_STATUS EncodeVop_BXRC(VideoEncData *video);
+PV_STATUS EncodeVop_NoME(VideoEncData *video);
+
+/* ======================================================================== */
+/* Function : DecodeVop() */
+/* Date : 08/23/2000 */
+/* Purpose : Encode VOP Header */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS EncodeVop(VideoEncData *video)
+{
+
+ PV_STATUS status;
+ Int currLayer = video->currLayer;
+ Vol *currVol = video->vol[currLayer];
+ Vop *currVop = video->currVop;
+// BitstreamEncVideo *stream=video->bitstream1;
+ UChar *Mode = video->headerInfo.Mode;
+ rateControl **rc = video->rc;
+// UInt time=0;
+
+ /*******************/
+ /* Initialize mode */
+ /*******************/
+
+ switch (currVop->predictionType)
+ {
+ case I_VOP:
+ M4VENC_MEMSET(Mode, MODE_INTRA, sizeof(UChar)*currVol->nTotalMB);
+ break;
+ case P_VOP:
+ M4VENC_MEMSET(Mode, MODE_INTER, sizeof(UChar)*currVol->nTotalMB);
+ break;
+ case B_VOP:
+ /*M4VENC_MEMSET(Mode, MODE_INTER_B,sizeof(UChar)*nTotalMB);*/
+ return PV_FAIL;
+ default:
+ return PV_FAIL;
+ }
+
+ /*********************/
+ /* Motion Estimation */
+ /* compute MVs, scene change detection, edge padding, */
+ /* intra refresh, compute block activity */
+ /*********************/
+ MotionEstimation(video); /* do ME for the whole frame */
+
+ /***************************/
+ /* rate Control (assign QP) */
+ /* 4/11/01, clean-up, and put into a separate function */
+ /***************************/
+ status = RC_VopQPSetting(video, rc);
+ if (status == PV_FAIL)
+ return PV_FAIL;
+
+ /**********************/
+ /* Encode VOP */
+ /**********************/
+ if (video->slice_coding) /* end here */
+ {
+ /* initialize state variable for slice-based APIs */
+ video->totalSAD = 0;
+ video->mbnum = 0;
+ video->sliceNo[0] = 0;
+ video->numIntra = 0;
+ video->offset = 0;
+ video->end_of_buf = 0;
+ video->hp_guess = -1;
+ return status;
+ }
+
+ status = EncodeVop_NoME(video);
+
+ /******************************/
+ /* rate control (update stat) */
+ /* 6/2/01 separate function */
+ /******************************/
+
+ RC_VopUpdateStat(video, rc[currLayer]);
+
+ return status;
+}
+
+/* ======================================================================== */
+/* Function : EncodeVop_NoME() */
+/* Date : 08/28/2001 */
+/* History : */
+/* Purpose : EncodeVop without motion est. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+PV_STATUS EncodeVop_NoME(VideoEncData *video)
+{
+ Vop *currVop = video->currVop;
+ Vol *currVol = video->vol[video->currLayer];
+ BitstreamEncVideo *stream = video->bitstream1;
+ Int time = 0; /* follows EncodeVop value */
+ PV_STATUS status = PV_SUCCESS;
+
+ if (currVol->shortVideoHeader) /* Short Video Header = 1 */
+ {
+
+ status = EncodeShortHeader(stream, currVop); /* Encode Short Header */
+
+ video->header_bits = BitstreamGetPos(stream); /* Header Bits */
+
+ status = EncodeFrameCombinedMode(video);
+
+ }
+#ifndef H263_ONLY
+ else /* Short Video Header = 0 */
+ {
+
+ if (currVol->GOVStart && currVop->predictionType == I_VOP)
+ status = EncodeGOVHeader(stream, time); /* Encode GOV Header */
+
+ status = EncodeVOPHeader(stream, currVol, currVop); /* Encode VOP Header */
+
+ video->header_bits = BitstreamGetPos(stream); /* Header Bits */
+
+ if (currVop->vopCoded)
+ {
+ if (!currVol->scalability)
+ {
+ if (currVol->dataPartitioning)
+ {
+ status = EncodeFrameDataPartMode(video); /* Encode Data Partitioning Mode VOP */
+ }
+ else
+ {
+ status = EncodeFrameCombinedMode(video); /* Encode Combined Mode VOP */
+ }
+ }
+ else
+ status = EncodeFrameCombinedMode(video); /* Encode Combined Mode VOP */
+ }
+ else /* Vop Not coded */
+ {
+
+ return status;
+ }
+ }
+#endif /* H263_ONLY */
+ return status;
+
+}
+
+#ifndef NO_SLICE_ENCODE
+/* ======================================================================== */
+/* Function : EncodeSlice() */
+/* Date : 04/19/2002 */
+/* History : */
+/* Purpose : Encode one slice. */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* */
+/* ======================================================================== */
+
+PV_STATUS EncodeSlice(VideoEncData *video)
+{
+ Vop *currVop = video->currVop;
+ Int currLayer = video->currLayer;
+ Vol *currVol = video->vol[currLayer];
+ BitstreamEncVideo *stream = video->bitstream1; /* different from frame-based */
+ Int time = 0; /* follows EncodeVop value */
+ PV_STATUS status = PV_SUCCESS;
+ rateControl **rc = video->rc;
+
+ if (currVol->shortVideoHeader) /* Short Video Header = 1 */
+ {
+
+ if (video->mbnum == 0)
+ {
+ status = EncodeShortHeader(stream, currVop); /* Encode Short Header */
+
+ video->header_bits = BitstreamGetPos(stream); /* Header Bits */
+ }
+
+ status = EncodeSliceCombinedMode(video);
+
+ }
+#ifndef H263_ONLY
+ else /* Short Video Header = 0 */
+ {
+
+ if (video->mbnum == 0)
+ {
+ if (currVol->GOVStart)
+ status = EncodeGOVHeader(stream, time); /* Encode GOV Header */
+
+ status = EncodeVOPHeader(stream, currVol, currVop); /* Encode VOP Header */
+
+ video->header_bits = BitstreamGetPos(stream); /* Header Bits */
+ }
+
+ if (currVop->vopCoded)
+ {
+ if (!currVol->scalability)
+ {
+ if (currVol->dataPartitioning)
+ {
+ status = EncodeSliceDataPartMode(video); /* Encode Data Partitioning Mode VOP */
+ }
+ else
+ {
+ status = EncodeSliceCombinedMode(video); /* Encode Combined Mode VOP */
+ }
+ }
+ else
+ status = EncodeSliceCombinedMode(video); /* Encode Combined Mode VOP */
+ }
+ else /* Vop Not coded */
+ {
+
+ return status;
+ }
+ }
+#endif /* H263_ONLY */
+ if (video->mbnum >= currVol->nTotalMB && status != PV_END_OF_BUF) /* end of Vop */
+ {
+ /******************************/
+ /* rate control (update stat) */
+ /* 6/2/01 separate function */
+ /******************************/
+
+ status = RC_VopUpdateStat(video, rc[currLayer]);
+ }
+
+ return status;
+
+}
+#endif /* NO_SLICE_ENCODE */
+
+#ifndef H263_ONLY
+/* ======================================================================== */
+/* Function : EncodeGOVHeader() */
+/* Date : 08/23/2000 */
+/* Purpose : Encode GOV Header */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+PV_STATUS EncodeGOVHeader(BitstreamEncVideo *stream, UInt seconds)
+{
+ PV_STATUS status;
+// int temp;
+ UInt tmpvar;
+
+ /********************************/
+ /* Group_of_VideoObjectPlane() */
+ /********************************/
+
+ status = BitstreamPutGT16Bits(stream, 32, GROUP_START_CODE);
+ /* time_code */
+ tmpvar = seconds / 3600;
+ status = BitstreamPutBits(stream, 5, tmpvar); /* Hours*/
+
+ tmpvar = (seconds - tmpvar * 3600) / 60;
+ status = BitstreamPutBits(stream, 6, tmpvar); /* Minutes*/
+
+ status = BitstreamPut1Bits(stream, 1); /* Marker*/
+
+ tmpvar = seconds % 60;
+ status = BitstreamPutBits(stream, 6, tmpvar); /* Seconds*/
+
+ status = BitstreamPut1Bits(stream, 1); /* closed_gov */
+ status = BitstreamPut1Bits(stream, 0); /* broken_link */
+ /*temp =*/
+ BitstreamMpeg4ByteAlignStuffing(stream); /* Byte align GOV Header */
+
+ return status;
+}
+
+#ifdef ALLOW_VOP_NOT_CODED
+
+PV_STATUS EncodeVopNotCoded(VideoEncData *video, UChar *bstream, Int *size, ULong modTime)
+{
+ PV_STATUS status;
+ Vol *currVol = video->vol[0];
+ Vop *currVop = video->currVop;
+ BitstreamEncVideo *stream = currVol->stream;
+ UInt frameTick;
+ Int timeInc;
+
+ stream->bitstreamBuffer = bstream;
+ stream->bufferSize = *size;
+ BitstreamEncReset(stream);
+
+ status = BitstreamPutGT16Bits(stream, 32, VOP_START_CODE); /*Start Code for VOP*/
+ status = BitstreamPutBits(stream, 2, P_VOP);/* VOP Coding Type*/
+
+ frameTick = (Int)(((double)(modTime - video->modTimeRef) * currVol->timeIncrementResolution + 500) / 1000);
+ timeInc = frameTick - video->refTick[0];
+ while (timeInc >= currVol->timeIncrementResolution)
+ {
+ timeInc -= currVol->timeIncrementResolution;
+ status = BitstreamPut1Bits(stream, 1);
+ /* do not update refTick and modTimeRef yet, do it after encoding!! */
+ }
+ status = BitstreamPut1Bits(stream, 0);
+ status = BitstreamPut1Bits(stream, 1); /* marker bit */
+ status = BitstreamPutBits(stream, currVol->nbitsTimeIncRes, timeInc); /* vop_time_increment */
+ status = BitstreamPut1Bits(stream, 1); /* marker bit */
+ status = BitstreamPut1Bits(stream, 0); /* vop_coded bit */
+ BitstreamMpeg4ByteAlignStuffing(stream);
+
+ return status;
+}
+#endif
+
+/* ======================================================================== */
+/* Function : EncodeVOPHeader() */
+/* Date : 08/23/2000 */
+/* Purpose : Encode VOP Header */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+PV_STATUS EncodeVOPHeader(BitstreamEncVideo *stream, Vol *currVol, Vop *currVop)
+{
+ PV_STATUS status;
+ //int temp;
+
+ int MTB = currVol->moduloTimeBase;
+ /************************/
+ /* VideoObjectPlane() */
+ /************************/
+
+ status = BitstreamPutGT16Bits(stream, 32, VOP_START_CODE); /*Start Code for VOP*/
+ status = BitstreamPutBits(stream, 2, currVop->predictionType);/* VOP Coding Type*/
+
+ currVol->prevModuloTimeBase = currVol->moduloTimeBase;
+
+ while (MTB)
+ {
+ status = BitstreamPut1Bits(stream, 1);
+ MTB--;
+ }
+ status = BitstreamPut1Bits(stream, 0);
+
+ status = BitstreamPut1Bits(stream, 1); /* marker bit */
+ status = BitstreamPutBits(stream, currVol->nbitsTimeIncRes, currVop->timeInc); /* vop_time_increment */
+ status = BitstreamPut1Bits(stream, 1); /* marker bit */
+ status = BitstreamPut1Bits(stream, currVop->vopCoded); /* vop_coded bit */
+ if (currVop->vopCoded == 0)
+ {
+ /*temp =*/
+ BitstreamMpeg4ByteAlignStuffing(stream); /* Byte align VOP Header */
+ return status;
+ }
+ if (currVop->predictionType == P_VOP)
+ status = BitstreamPut1Bits(stream, currVop->roundingType); /* vop_rounding_type */
+
+ status = BitstreamPutBits(stream, 3, currVop->intraDCVlcThr); /* intra_dc_vlc_thr */
+ status = BitstreamPutBits(stream, 5, currVop->quantizer); /* vop_quant */
+
+ if (currVop->predictionType != I_VOP)
+ status = BitstreamPutBits(stream, 3, currVop->fcodeForward); /* vop_fcode_forward */
+ if (currVop->predictionType == B_VOP)
+ status = BitstreamPutBits(stream, 3, currVop->fcodeBackward);/* vop_fcode_backward */
+
+ if (currVol->scalability)
+ /* enhancement_type = 0 */
+ status = BitstreamPutBits(stream, 2, currVop->refSelectCode); /* ref_select_code */
+
+ return status;
+}
+#endif /* H263_ONLY */
+/* ======================================================================== */
+/* Function : EncodeShortHeader() */
+/* Date : 08/23/2000 */
+/* Purpose : Encode VOP Header */
+/* In/out : */
+/* Return : */
+/* Modified : */
+/* ======================================================================== */
+
+PV_STATUS EncodeShortHeader(BitstreamEncVideo *stream, Vop *currVop)
+{
+
+ PV_STATUS status;
+
+ status = BitstreamPutGT16Bits(stream, 22, SHORT_VIDEO_START_MARKER); /* Short_video_start_marker */
+ status = BitstreamPutBits(stream, 8, currVop->temporalRef); /* temporal_reference */
+ status = BitstreamPut1Bits(stream, 1); /* marker bit */
+ status = BitstreamPut1Bits(stream, 0); /* zero bit */
+ status = BitstreamPut1Bits(stream, 0); /* split_screen_indicator=0*/
+ status = BitstreamPut1Bits(stream, 0); /* document_camera_indicator=0*/
+ status = BitstreamPut1Bits(stream, 0); /* full_picture_freeze_release=0*/
+
+ switch (currVop->width)
+ {
+ case 128:
+ if (currVop->height == 96)
+ status = BitstreamPutBits(stream, 3, 1); /* source_format = 1 */
+ else
+ {
+ status = PV_FAIL;
+ return status;
+ }
+ break;
+
+ case 176:
+ if (currVop->height == 144)
+ status = BitstreamPutBits(stream, 3, 2); /* source_format = 2 */
+ else
+ {
+ status = PV_FAIL;
+ return status;
+ }
+ break;
+
+ case 352:
+ if (currVop->height == 288)
+ status = BitstreamPutBits(stream, 3, 3); /* source_format = 3 */
+ else
+ {
+ status = PV_FAIL;
+ return status;
+ }
+ break;
+
+ case 704:
+ if (currVop->height == 576)
+ status = BitstreamPutBits(stream, 3, 4); /* source_format = 4 */
+ else
+ {
+ status = PV_FAIL;
+ return status;
+ }
+ break;
+
+ case 1408:
+ if (currVop->height == 1152)
+ status = BitstreamPutBits(stream, 3, 5); /* source_format = 5 */
+ else
+ {
+ status = PV_FAIL;
+ return status;
+ }
+ break;
+
+ default:
+ status = PV_FAIL;
+ return status;
+ }
+
+
+ status = BitstreamPut1Bits(stream, currVop->predictionType); /* picture_coding type */
+ status = BitstreamPutBits(stream, 4, 0); /* four_reserved_zero_bits */
+ status = BitstreamPutBits(stream, 5, currVop->quantizer); /* vop_quant*/
+ status = BitstreamPut1Bits(stream, 0); /* zero_bit*/
+ status = BitstreamPut1Bits(stream, 0); /* pei=0 */
+
+ return status;
+}
+
+#ifndef H263_ONLY
+/* ======================================================================== */
+/* Function : EncodeVideoPacketHeader() */
+/* Date : 09/05/2000 */
+/* History : */
+/* Purpose : Encode a frame of MPEG4 bitstream in Combined mode. */
+/* In/out : */
+/* Return : */
+/* Modified : 04/25/2002 */
+/* Add bitstream structure as input argument */
+/* */
+/* ======================================================================== */
+PV_STATUS EncodeVideoPacketHeader(VideoEncData *video, int MB_number,
+ int quant_scale, Int insert)
+{
+// PV_STATUS status=PV_SUCCESS;
+ int fcode;
+ Vop *currVop = video->currVop;
+ Vol *currVol = video->vol[video->currLayer];
+ BitstreamEncVideo *bs, tmp;
+ UChar buffer[30];
+
+ if (insert) /* insert packet header to the beginning of bs1 */
+ {
+ tmp.bitstreamBuffer = buffer; /* use temporary buffer */
+ tmp.bufferSize = 30;
+ BitstreamEncReset(&tmp);
+ bs = &tmp;
+ }
+ else
+ bs = video->bitstream1;
+
+
+ if (currVop->predictionType == I_VOP)
+ BitstreamPutGT16Bits(bs, 17, 1); /* resync_marker I_VOP */
+ else if (currVop->predictionType == P_VOP)
+ {
+ fcode = currVop->fcodeForward;
+ BitstreamPutGT16Bits(bs, 16 + fcode, 1); /* resync_marker P_VOP */
+
+ }
+ else
+ {
+ fcode = currVop->fcodeForward;
+ if (currVop->fcodeBackward > fcode)
+ fcode = currVop->fcodeBackward;
+ BitstreamPutGT16Bits(bs, 16 + fcode, 1); /* resync_marker B_VOP */
+ }
+
+ BitstreamPutBits(bs, currVol->nBitsForMBID, MB_number); /* resync_marker */
+ BitstreamPutBits(bs, 5, quant_scale); /* quant_scale */
+ BitstreamPut1Bits(bs, 0); /* header_extension_code = 0 */
+
+ if (0) /* header_extension_code = 1 */
+ {
+ /* NEED modulo_time_base code here ... default 0x01 belo*/
+ /*status =*/
+ BitstreamPut1Bits(bs, 1);
+ /*status = */
+ BitstreamPut1Bits(bs, 0);
+
+ /*status = */
+ BitstreamPut1Bits(bs, 1); /* marker bit */
+ /*status = */
+ BitstreamPutBits(bs, currVol->nbitsTimeIncRes, currVop->timeInc); /* vop_time_increment */
+ /*status = */
+ BitstreamPut1Bits(bs, 1); /* marker bit */
+
+ /*status = */
+ BitstreamPutBits(bs, 2, currVop->predictionType);/* VOP Coding Type*/
+
+ /*status = */
+ BitstreamPutBits(bs, 3, currVop->intraDCVlcThr); /* intra_dc_vlc_thr */
+
+ if (currVop->predictionType != I_VOP)
+ /*status = */ BitstreamPutBits(bs, 3, currVop->fcodeForward);
+ if (currVop->predictionType == B_VOP)
+ /*status = */ BitstreamPutBits(bs, 3, currVop->fcodeBackward);
+ }
+#ifndef NO_SLICE_ENCODE
+ if (insert)
+ BitstreamPrependPacket(video->bitstream1, bs);
+#endif
+ return PV_SUCCESS;
+}
+
+#endif /* H263_ONLY */
+
+
+
diff --git a/media/codecs/m4v_h263/enc/test/Android.bp b/media/codecs/m4v_h263/enc/test/Android.bp
new file mode 100644
index 0000000..b9a8117
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/test/Android.bp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_test {
+ name: "Mpeg4H263EncoderTest",
+ gtest: true,
+
+ srcs : [ "Mpeg4H263EncoderTest.cpp" ],
+
+ shared_libs: [
+ "libutils",
+ "liblog",
+ ],
+
+ static_libs: [
+ "libstagefright_m4vh263enc",
+ ],
+
+ cflags: [
+ "-DOSCL_IMPORT_REF=",
+ "-Wall",
+ "-Werror",
+ ],
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ "unsigned-integer-overflow",
+ ],
+ cfi: true,
+ },
+}
diff --git a/media/codecs/m4v_h263/enc/test/AndroidTest.xml b/media/codecs/m4v_h263/enc/test/AndroidTest.xml
new file mode 100644
index 0000000..5218932
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/test/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for MPEG4H263 encoder unit tests">
+ <option name="test-suite-tag" value="Mpeg4H263EncoderTest" />
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="Mpeg4H263EncoderTest->/data/local/tmp/Mpeg4H263EncoderTest/" />
+ <option name="push-file"
+ key="https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/m4v_h263/enc/test/Mpeg4H263Encoder.zip?unzip=true"
+ value="/data/local/tmp/Mpeg4H263EncoderTestRes/" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="Mpeg4H263EncoderTest" />
+ <option name="native-test-flag" value="-P /data/local/tmp/Mpeg4H263EncoderTestRes/" />
+ </test>
+</configuration>
\ No newline at end of file
diff --git a/media/codecs/m4v_h263/enc/test/Mpeg4H263EncoderTest.cpp b/media/codecs/m4v_h263/enc/test/Mpeg4H263EncoderTest.cpp
new file mode 100644
index 0000000..78c705a
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/test/Mpeg4H263EncoderTest.cpp
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "Mpeg4H263EncoderTest"
+#include <utils/Log.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include "mp4enc_api.h"
+
+#include "Mpeg4H263EncoderTestEnvironment.h"
+
+#define ENCODED_FILE "/data/local/tmp/Mpeg4H263Output"
+
+// assuming a worst case compression of 2X
+constexpr int16_t kCompressionRatio = 2;
+constexpr int8_t kIDRFrameRefreshIntervalInSec = 1;
+
+static Mpeg4H263EncoderTestEnvironment *gEnv = nullptr;
+
+class Mpeg4H263EncoderTest
+ : public ::testing::TestWithParam<tuple<string, bool, int32_t, int32_t, float, int32_t>> {
+ private:
+ void initEncoderParams();
+
+ public:
+ Mpeg4H263EncoderTest()
+ : mInputBuffer(nullptr),
+ mOutputBuffer(nullptr),
+ mFpInput(nullptr),
+ mFpOutput(nullptr),
+ mEncodeHandle(nullptr),
+ mEncodeControl(nullptr) {}
+
+ ~Mpeg4H263EncoderTest() {
+ if(mFpInput) {
+ fclose(mFpInput);
+ }
+ if(mFpOutput) {
+ fclose(mFpOutput);
+ }
+ if(mInputBuffer) free(mInputBuffer);
+ if(mOutputBuffer) free(mOutputBuffer);
+ if(mEncodeHandle) free(mEncodeHandle);
+ if(mEncodeControl) free(mEncodeControl);
+ }
+
+ void SetUp() override {
+ tuple<string /* fileName */, bool /* isMpeg4 */, int32_t /* frameWidth */,
+ int32_t /* frameHeight */, float /* frameRate */, int32_t /* bitRate */>
+ params = GetParam();
+ mFileName = gEnv->getRes() + get<0>(params);
+ mIsMpeg4 = get<1>(params);
+ mFrameWidth = get<2>(params);
+ mFrameHeight = get<3>(params);
+ mFrameRate = get<4>(params);
+ mBitRate = get<5>(params);
+
+ ASSERT_TRUE(mFrameWidth % 16 == 0) << "Frame Width should be multiple of 16";
+ ASSERT_TRUE(mFrameHeight % 16 == 0) << "Frame Height should be multiple of 16";
+ ASSERT_LE(mFrameWidth, (mIsMpeg4 ? 720 : 352))
+ << "Frame Width <= 720 for Mpeg4 and <= 352 for H263";
+ ASSERT_LE(mFrameHeight, (mIsMpeg4 ? 480 : 288))
+ << "Frame Height <= 480 for Mpeg4 and <= 288 for H263";
+ ASSERT_LE(mFrameRate, 30) << "Frame rate less than or equal to 30";
+ ASSERT_LE(mBitRate, 2048) << "Bit rate less than or equal to 2048 kbps";
+
+ mOutputBufferSize = ( mFrameWidth * mFrameHeight * 3/2 ) / kCompressionRatio;
+ mEncodeHandle = new VideoEncOptions;
+ ASSERT_NE(mEncodeHandle, nullptr) << "Failed to get Video Encoding options object";
+ memset(mEncodeHandle, 0, sizeof(VideoEncOptions));
+ mEncodeControl = new VideoEncControls;
+ ASSERT_NE(mEncodeControl, nullptr) << "Failed to get Video Encoding control object";
+ memset(mEncodeControl, 0, sizeof(VideoEncControls));
+ ASSERT_NO_FATAL_FAILURE(initEncoderParams())
+ << "Failed to get the default Encoding parameters!";
+ }
+
+ int64_t getTotalFrames();
+ void processEncoder(int32_t);
+ bool mIsMpeg4;
+ int32_t mFrameWidth, mFrameHeight, mBitRate;
+ int64_t mOutputBufferSize;
+ float mFrameRate;
+ string mFileName;
+ uint8_t *mInputBuffer, *mOutputBuffer;
+ FILE *mFpInput, *mFpOutput;
+ VideoEncOptions *mEncodeHandle;
+ VideoEncControls *mEncodeControl;
+};
+
+void Mpeg4H263EncoderTest::initEncoderParams() {
+ bool status = PVGetDefaultEncOption(mEncodeHandle, 0);
+ ASSERT_TRUE(status);
+
+ mEncodeHandle->rcType = VBR_1;
+ mEncodeHandle->vbvDelay = 5.0f;
+ mEncodeHandle->profile_level = CORE_PROFILE_LEVEL2;
+ mEncodeHandle->packetSize = 32;
+ mEncodeHandle->rvlcEnable = PV_OFF;
+ mEncodeHandle->numLayers = 1;
+ mEncodeHandle->timeIncRes = 1000;
+ mEncodeHandle->iQuant[0] = 15;
+ mEncodeHandle->pQuant[0] = 12;
+ mEncodeHandle->quantType[0] = 0;
+ mEncodeHandle->noFrameSkipped = PV_OFF;
+ mEncodeHandle->numIntraMB = 0;
+ mEncodeHandle->sceneDetect = PV_ON;
+ mEncodeHandle->searchRange = 16;
+ mEncodeHandle->mv8x8Enable = PV_OFF;
+ mEncodeHandle->gobHeaderInterval = 0;
+ mEncodeHandle->useACPred = PV_ON;
+ mEncodeHandle->intraDCVlcTh = 0;
+ if(!mIsMpeg4) {
+ mEncodeHandle->encMode = H263_MODE;
+ } else {
+ mEncodeHandle->encMode = COMBINE_MODE_WITH_ERR_RES;
+ }
+ mEncodeHandle->encWidth[0] = mFrameWidth;
+ mEncodeHandle->encHeight[0] = mFrameHeight;
+ mEncodeHandle->encFrameRate[0] = mFrameRate;
+ mEncodeHandle->bitRate[0] = mBitRate * 1024;
+ mEncodeHandle->tickPerSrc = mEncodeHandle->timeIncRes / mFrameRate;
+ if (kIDRFrameRefreshIntervalInSec == 0) {
+ // All I frames.
+ mEncodeHandle->intraPeriod = 1;
+ } else {
+ mEncodeHandle->intraPeriod = (kIDRFrameRefreshIntervalInSec * mFrameRate);
+ }
+}
+
+int64_t Mpeg4H263EncoderTest::getTotalFrames() {
+ int32_t frameSize = (mFrameWidth * mFrameHeight * 3) / 2;
+ struct stat buf;
+ stat(mFileName.c_str(), &buf);
+ size_t fileSize = buf.st_size;
+ int64_t totalFrames = (int64_t)(fileSize/frameSize);
+ return totalFrames;
+}
+
+void Mpeg4H263EncoderTest::processEncoder(int32_t numFramesToEncode) {
+ bool status;
+ int64_t numEncodedFrames = 0;
+ int32_t bytesRead;
+ int32_t frameSize = (mFrameWidth * mFrameHeight * 3) / 2;
+ while(numFramesToEncode != 0) {
+ bytesRead = fread(mInputBuffer, 1, frameSize, mFpInput);
+ // End of file.
+ if (bytesRead != frameSize) {
+ break;
+ }
+
+ VideoEncFrameIO videoIn, videoOut;
+ videoIn.height = mFrameHeight;
+ videoIn.pitch = mFrameWidth;
+ videoIn.timestamp = (numEncodedFrames * 1000) / mFrameRate; // in ms.
+ videoIn.yChan = mInputBuffer;
+ videoIn.uChan = videoIn.yChan + videoIn.height * videoIn.pitch;
+ videoIn.vChan = videoIn.uChan + ((videoIn.height * videoIn.pitch) >> 2);
+ uint32_t modTimeMs = 0;
+ int32_t dataLength = mOutputBufferSize;
+ int32_t nLayer = 0;
+ status = PVEncodeVideoFrame(mEncodeControl, &videoIn, &videoOut, &modTimeMs, mOutputBuffer,
+ &dataLength, &nLayer);
+ ASSERT_TRUE(status) << "Failed to Encode: " << mFileName;
+
+ MP4HintTrack hintTrack;
+ status = PVGetHintTrack(mEncodeControl, &hintTrack);
+ ASSERT_TRUE(status) << "Failed to get hint track!";
+ UChar *overrunBuffer = PVGetOverrunBuffer(mEncodeControl);
+ ASSERT_EQ(overrunBuffer, nullptr) << "Overrun of buffer!";
+
+ int64_t numBytes = fwrite(mOutputBuffer, 1, dataLength, mFpOutput);
+ ASSERT_EQ(numBytes, dataLength) << "Failed to write to the output file!";
+ numEncodedFrames++;
+ numFramesToEncode--;
+ }
+}
+
+TEST_P(Mpeg4H263EncoderTest, EncodeTest) {
+ mInputBuffer = (uint8_t *)malloc((mFrameWidth * mFrameWidth * 3) / 2);
+ ASSERT_NE(mInputBuffer, nullptr) << "Failed to allocate the input buffer!";
+
+ mOutputBuffer = (uint8_t *)malloc(mOutputBufferSize);
+ ASSERT_NE(mOutputBuffer, nullptr) << "Failed to allocate the output buffer!";
+
+ mFpInput = fopen(mFileName.c_str(), "rb");
+ ASSERT_NE(mFpInput, nullptr) << "Failed to open the input file: " << mFileName;
+
+ mFpOutput = fopen(ENCODED_FILE, "wb");
+ ASSERT_NE(mFpOutput, nullptr) << "Failed to open the output file:" << ENCODED_FILE;
+
+ bool status = PVInitVideoEncoder(mEncodeControl, mEncodeHandle);
+ ASSERT_TRUE(status) << "Failed to initialize the encoder!";
+
+ // Get VOL header.
+ int32_t size = mOutputBufferSize;
+ status = PVGetVolHeader(mEncodeControl, mOutputBuffer, &size, 0);
+ ASSERT_TRUE(status) << "Failed to get the VOL header!";
+
+ // Write the VOL header on the first frame.
+ int32_t numBytes = fwrite(mOutputBuffer, 1, size, mFpOutput);
+ ASSERT_EQ(numBytes, size) << "Failed to write the VOL header!";
+
+ int64_t totalFrames = getTotalFrames();
+ ASSERT_NO_FATAL_FAILURE(processEncoder(totalFrames)) << "Failed to Encode: " << mFileName;
+ status = PVCleanUpVideoEncoder(mEncodeControl);
+ ASSERT_TRUE(status) << "Failed to clean up the encoder resources!";
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ EncodeTest, Mpeg4H263EncoderTest,
+ ::testing::Values(
+ make_tuple("bbb_352x288_420p_30fps_32frames.yuv", false, 352, 288, 25, 1024),
+ make_tuple("bbb_352x288_420p_30fps_32frames.yuv", true, 352, 288, 25, 1024),
+ make_tuple("bbb_352x288_420p_30fps_32frames.yuv", false, 176, 144, 25, 1024),
+ make_tuple("bbb_352x288_420p_30fps_32frames.yuv", true, 176, 144, 25, 1024),
+ make_tuple("football_qvga.yuv", false, 352, 288, 25, 1024),
+ make_tuple("football_qvga.yuv", true, 352, 288, 25, 1024),
+ make_tuple("football_qvga.yuv", false, 176, 144, 30, 1024),
+ make_tuple("football_qvga.yuv", true, 176, 144, 30, 1024)));
+
+int32_t main(int argc, char **argv) {
+ gEnv = new Mpeg4H263EncoderTestEnvironment();
+ ::testing::AddGlobalTestEnvironment(gEnv);
+ ::testing::InitGoogleTest(&argc, argv);
+ uint8_t status = gEnv->initFromOptions(argc, argv);
+ if (status == 0) {
+ status = RUN_ALL_TESTS();
+ ALOGI("Encoder Test Result = %d\n", status);
+ }
+ return status;
+}
diff --git a/media/codecs/m4v_h263/enc/test/Mpeg4H263EncoderTestEnvironment.h b/media/codecs/m4v_h263/enc/test/Mpeg4H263EncoderTestEnvironment.h
new file mode 100644
index 0000000..7ee36e0
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/test/Mpeg4H263EncoderTestEnvironment.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MPEG4_H263_ENCODER_TEST_ENVIRONMENT_H__
+#define __MPEG4_H263_ENCODER_TEST_ENVIRONMENT_H__
+
+#include <gtest/gtest.h>
+
+#include <getopt.h>
+
+using namespace std;
+
+class Mpeg4H263EncoderTestEnvironment : public::testing::Environment {
+ public:
+ Mpeg4H263EncoderTestEnvironment() : res("/data/local/tmp/Mpeg4H263EncoderTest/") {}
+
+ // Parses the command line arguments
+ int initFromOptions(int argc, char **argv);
+
+ void setRes(const char *_res) { res = _res; }
+
+ const string getRes() const { return res; }
+
+ private:
+ string res;
+};
+
+int Mpeg4H263EncoderTestEnvironment::initFromOptions(int argc, char **argv) {
+ static struct option options[] = {{"path", required_argument, 0, 'P'}, {0, 0, 0, 0}};
+
+ while (true) {
+ int index = 0;
+ int c = getopt_long(argc, argv, "P:", options, &index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'P': {
+ setRes(optarg);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr,
+ "unrecognized option: %s\n\n"
+ "usage: %s <gtest options> <test options>\n\n"
+ "test options are:\n\n"
+ "-P, --path: Resource files directory location\n",
+ argv[optind ?: 1], argv[0]);
+ return 2;
+ }
+ return 0;
+}
+
+#endif // __MPEG4_H263_ENCODER_TEST_ENVIRONMENT_H__
diff --git a/media/codecs/m4v_h263/enc/test/README.md b/media/codecs/m4v_h263/enc/test/README.md
new file mode 100644
index 0000000..25de878
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/test/README.md
@@ -0,0 +1,38 @@
+## Media Testing ##
+---
+
+#### Mpeg4H263Encoder :
+The Mpeg4H263Encoder Test Suite validates the Mpeg4 and H263 encoder available in libstagefright.
+Run the following steps to build the test suite:
+```
+m Mpeg4H263EncoderTest
+```
+
+The 32-bit binaries will be created in the following path : ${OUT}/data/nativetest/
+The 64-bit binaries will be created in the following path : ${OUT}/data/nativetest64/
+
+To test 64-bit binary push binaries from nativetest64.
+```
+adb push ${OUT}/data/nativetest64/Mpeg4H263EncoderTest/Mpeg4H263EncoderTest /data/local/tmp/
+```
+
+To test 32-bit binary push binaries from nativetest.
+```
+adb push ${OUT}/data/nativetest/Mpeg4H263EncoderTest/Mpeg4H263EncoderTest /data/local/tmp/
+```
+
+The resource file for the tests is taken from [here](https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/codecs/m4v_h263/enc/test/Mpeg4H263Encoder.zip ) Download, unzip and push these files into device for testing.
+
+```
+adb push Mpeg4H263Encoder/. /data/local/tmp/
+```
+
+usage: Mpeg4H263EncoderTest -P \<path_to_folder\>
+```
+adb shell /data/local/tmp/Mpeg4H263EncoderTest -P /data/local/tmp/
+```
+Alternatively, the test can also be run using atest command.
+
+```
+atest Mpeg4H263EncoderTest -- --enable-module-dynamic-download=true
+```
diff --git a/media/codecs/m4v_h263/enc/test/m4v_h263_enc_test.cpp b/media/codecs/m4v_h263/enc/test/m4v_h263_enc_test.cpp
new file mode 100644
index 0000000..5554ebd
--- /dev/null
+++ b/media/codecs/m4v_h263/enc/test/m4v_h263_enc_test.cpp
@@ -0,0 +1,259 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include "mp4enc_api.h"
+
+// Constants.
+enum {
+ kMaxWidth = 720,
+ kMaxHeight = 480,
+ kMaxFrameRate = 30,
+ kMaxBitrate = 2048, // in kbps.
+ kOutputBufferSize = 250 * 1024,
+ kIDRFrameRefreshIntervalInSec = 1, // in seconds.
+};
+
+int main(int argc, char *argv[]) {
+
+ if (argc < 8) {
+ fprintf(stderr, "Usage %s <input yuv> <output file> <mode> <width> "
+ "<height> <frame rate> <bitrate in kbps>\n", argv[0]);
+ fprintf(stderr, "mode : h263 or mpeg4\n");
+ fprintf(stderr, "Max width %d\n", kMaxWidth);
+ fprintf(stderr, "Max height %d\n", kMaxHeight);
+ fprintf(stderr, "Max framerate %d\n", kMaxFrameRate);
+ fprintf(stderr, "Max bitrate %d kbps\n", kMaxBitrate);
+ return EXIT_FAILURE;
+ }
+
+ // Read mode.
+ bool isH263mode;
+ if (strcmp(argv[3], "mpeg4") == 0) {
+ isH263mode = false;
+ } else if (strcmp(argv[3], "h263") == 0) {
+ isH263mode = true;
+ } else {
+ fprintf(stderr, "Unsupported mode %s\n", argv[3]);
+ return EXIT_FAILURE;
+ }
+
+ // Read height and width.
+ int32_t width;
+ int32_t height;
+ width = atoi(argv[4]);
+ height = atoi(argv[5]);
+ if (width > kMaxWidth || height > kMaxHeight || width <= 0 || height <= 0) {
+ fprintf(stderr, "Unsupported dimensions %dx%d\n", width, height);
+ return EXIT_FAILURE;
+ }
+
+ if (width % 16 != 0 || height % 16 != 0) {
+ fprintf(stderr, "Video frame size %dx%d must be a multiple of 16\n",
+ width, height);
+ return EXIT_FAILURE;
+ }
+
+ // Read frame rate.
+ int32_t frameRate;
+ frameRate = atoi(argv[6]);
+ if (frameRate > kMaxFrameRate || frameRate <= 0) {
+ fprintf(stderr, "Unsupported frame rate %d\n", frameRate);
+ return EXIT_FAILURE;
+ }
+
+ // Read bitrate.
+ int32_t bitrate;
+ bitrate = atoi(argv[7]);
+ if (bitrate > kMaxBitrate || bitrate <= 0) {
+ fprintf(stderr, "Unsupported bitrate %d\n", bitrate);
+ return EXIT_FAILURE;
+ }
+
+ // Allocate input buffer.
+ uint8_t *inputBuf = (uint8_t *)malloc((width * height * 3) / 2);
+ assert(inputBuf != NULL);
+
+ // Allocate output buffer.
+ uint8_t *outputBuf = (uint8_t *)malloc(kOutputBufferSize);
+ assert(outputBuf != NULL);
+
+ // Open the input file.
+ FILE *fpInput = fopen(argv[1], "rb");
+ if (fpInput == NULL) {
+ fprintf(stderr, "Could not open %s\n", argv[1]);
+ free(inputBuf);
+ free(outputBuf);
+ return EXIT_FAILURE;
+ }
+
+ // Open the output file.
+ FILE *fpOutput = fopen(argv[2], "wb");
+ if (fpOutput == NULL) {
+ fprintf(stderr, "Could not open %s\n", argv[2]);
+ free(inputBuf);
+ free(outputBuf);
+ fclose(fpInput);
+ return EXIT_FAILURE;
+ }
+
+ // Initialize the encoder parameters.
+ tagvideoEncOptions encParams;
+ memset(&encParams, 0, sizeof(tagvideoEncOptions));
+ if (!PVGetDefaultEncOption(&encParams, 0)) {
+ fprintf(stderr, "Failed to get default encoding parameters\n");
+ free(inputBuf);
+ free(outputBuf);
+ fclose(fpInput);
+ fclose(fpOutput);
+ return EXIT_FAILURE;
+ }
+
+ if (isH263mode == false) {
+ encParams.encMode = COMBINE_MODE_WITH_ERR_RES;
+ } else {
+ encParams.encMode = H263_MODE;
+ }
+ encParams.encWidth[0] = width;
+ encParams.encHeight[0] = height;
+ encParams.encFrameRate[0] = frameRate;
+ encParams.rcType = VBR_1;
+ encParams.vbvDelay = 5.0f;
+ encParams.profile_level = CORE_PROFILE_LEVEL2;
+ encParams.packetSize = 32;
+ encParams.rvlcEnable = PV_OFF;
+ encParams.numLayers = 1;
+ encParams.timeIncRes = 1000;
+ encParams.tickPerSrc = encParams.timeIncRes / frameRate;
+
+ encParams.bitRate[0] = bitrate * 1024;
+ encParams.iQuant[0] = 15;
+ encParams.pQuant[0] = 12;
+ encParams.quantType[0] = 0;
+ encParams.noFrameSkipped = PV_OFF;
+
+ int32_t IDRFrameRefreshIntervalInSec = kIDRFrameRefreshIntervalInSec;
+ if (IDRFrameRefreshIntervalInSec == 0) {
+ encParams.intraPeriod = 1; // All I frames.
+ } else {
+ encParams.intraPeriod = (IDRFrameRefreshIntervalInSec * frameRate);
+ }
+
+ encParams.numIntraMB = 0;
+ encParams.sceneDetect = PV_ON;
+ encParams.searchRange = 16;
+ encParams.mv8x8Enable = PV_OFF;
+ encParams.gobHeaderInterval = 0;
+ encParams.useACPred = PV_ON;
+ encParams.intraDCVlcTh = 0;
+
+ // Initialize the handle.
+ tagvideoEncControls handle;
+ memset(&handle, 0, sizeof(tagvideoEncControls));
+
+ // Initialize the encoder.
+ if (!PVInitVideoEncoder(&handle, &encParams)) {
+ fprintf(stderr, "Failed to initialize the encoder\n");
+ fclose(fpInput);
+ fclose(fpOutput);
+ free(inputBuf);
+ free(outputBuf);
+ return EXIT_FAILURE;
+ }
+
+ // Generate the header.
+ int32_t headerLength = kOutputBufferSize;
+ if (!PVGetVolHeader(&handle, outputBuf, &headerLength, 0)) {
+ fprintf(stderr, "Failed to get VOL header\n");
+ fclose(fpInput);
+ fclose(fpOutput);
+ free(inputBuf);
+ free(outputBuf);
+ return EXIT_FAILURE;
+ }
+ fwrite(outputBuf, 1, headerLength, fpOutput);
+
+ // Core loop.
+ int32_t retVal = EXIT_SUCCESS;
+ int32_t frameSize = (width * height * 3) / 2;
+ int32_t numFramesEncoded = 0;
+
+ while (1) {
+ // Read the input frame.
+ int32_t bytesRead;
+ bytesRead = fread(inputBuf, 1, frameSize, fpInput);
+ if (bytesRead != frameSize) {
+ break; // End of file.
+ }
+
+ // Encode the input frame.
+ VideoEncFrameIO vin, vout;
+ memset(&vin, 0, sizeof(vin));
+ memset(&vout, 0, sizeof(vout));
+ vin.height = height; // height is multiple of 16.
+ vin.pitch = width; // width is multiple of 16.
+ vin.timestamp = (numFramesEncoded * 1000) / frameRate; // in ms.
+ vin.yChan = inputBuf;
+ vin.uChan = vin.yChan + vin.height * vin.pitch;
+ vin.vChan = vin.uChan + ((vin.height * vin.pitch) >> 2);
+
+ uint32_t modTimeMs = 0;
+ int32_t nLayer = 0;
+ MP4HintTrack hintTrack;
+ int32_t dataLength = kOutputBufferSize;
+ if (!PVEncodeVideoFrame(&handle, &vin, &vout,
+ &modTimeMs, outputBuf, &dataLength, &nLayer) ||
+ !PVGetHintTrack(&handle, &hintTrack)) {
+ fprintf(stderr, "Failed to encode frame or get hink track at "
+ " frame %d\n", numFramesEncoded);
+ retVal = EXIT_FAILURE;
+ break;
+ }
+ PVGetOverrunBuffer(&handle);
+ numFramesEncoded++;
+
+ // Write the output.
+ fwrite(outputBuf, 1, dataLength, fpOutput);
+ }
+
+ // Close input and output file.
+ fclose(fpInput);
+ fclose(fpOutput);
+
+ // Free allocated memory.
+ free(inputBuf);
+ free(outputBuf);
+
+ // Close encoder instance.
+ PVCleanUpVideoEncoder(&handle);
+ return retVal;
+}
diff --git a/media/codecs/m4v_h263/fuzzer/Android.bp b/media/codecs/m4v_h263/fuzzer/Android.bp
new file mode 100644
index 0000000..778dafb
--- /dev/null
+++ b/media/codecs/m4v_h263/fuzzer/Android.bp
@@ -0,0 +1,111 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+
+cc_defaults {
+ name: "mpeg4_h263_dec_fuzz_defaults",
+
+ host_supported: true,
+
+ srcs: [
+ "mpeg4_h263_dec_fuzzer.cpp",
+ ],
+
+ static_libs: [
+ "libstagefright_m4vh263dec",
+ "liblog",
+ ],
+
+ cflags: [
+ "-DOSCL_IMPORT_REF=",
+ ],
+
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
+
+cc_fuzz {
+ name: "mpeg4_dec_fuzzer",
+
+ defaults: [
+ "mpeg4_h263_dec_fuzz_defaults",
+ ],
+
+ cflags: [
+ "-DMPEG4",
+ ],
+}
+
+cc_fuzz {
+ name: "h263_dec_fuzzer",
+
+ defaults: [
+ "mpeg4_h263_dec_fuzz_defaults",
+ ],
+}
+
+cc_defaults {
+ name: "mpeg4_h263_enc_fuzz_defaults",
+
+ host_supported: true,
+
+ srcs: ["mpeg4_h263_enc_fuzzer.cpp"],
+
+ shared_libs: [
+ "libutils",
+ "liblog",
+ ],
+
+ static_libs: [
+ "libstagefright_m4vh263enc",
+ ],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
+
+cc_fuzz {
+ name: "mpeg4_enc_fuzzer",
+
+ defaults: [
+ "mpeg4_h263_enc_fuzz_defaults",
+ ],
+
+ cflags: ["-DMPEG4"],
+}
+
+cc_fuzz {
+ name: "h263_enc_fuzzer",
+
+ defaults: [
+ "mpeg4_h263_enc_fuzz_defaults",
+ ],
+}
diff --git a/media/codecs/m4v_h263/fuzzer/README.md b/media/codecs/m4v_h263/fuzzer/README.md
new file mode 100644
index 0000000..ad4ff97
--- /dev/null
+++ b/media/codecs/m4v_h263/fuzzer/README.md
@@ -0,0 +1,158 @@
+# Fuzzer for libstagefright_m4vh263dec decoder
+
+## Plugin Design Considerations
+The fuzzer plugin for MPEG4/H263 is designed based on the understanding of the
+codec and tries to achieve the following:
+
+##### Maximize code coverage
+Dict files (dictionary files) are created for MPEG4 and H263 to ensure that the required start
+bytes are present in every input file that goes to the fuzzer.
+This ensures that decoder does not reject any input file in the first check
+
+##### Maximize utilization of input data
+The plugin feeds the entire input data to the codec using a loop.
+ * If the decode operation was successful, the input is advanced by the number of bytes consumed
+ in the decode call.
+ * If the decode operation was un-successful, the input is advanced by 1 byte so that the fuzzer
+ can proceed to feed the next frame.
+
+This ensures that the plugin tolerates any kind of input (empty, huge, malformed, etc)
+and doesnt `exit()` on any input and thereby increasing the chance of identifying vulnerabilities.
+
+##### Other considerations
+ * Two fuzzer binaries - mpeg4_dec_fuzzer and h263_dec_fuzzer are generated based on the presence
+ of a flag - 'MPEG4'
+ * The number of decode calls are kept to a maximum of 100 so that the fuzzer does not timeout.
+
+## Build
+
+This describes steps to build mpeg4_dec_fuzzer and h263_dec_fuzzer binary.
+
+### Android
+#### Steps to build
+Build the fuzzer
+```
+ $ mm -j$(nproc) mpeg4_dec_fuzzer
+ $ mm -j$(nproc) h263_dec_fuzzer
+```
+
+#### Steps to run
+Create a directory CORPUS_DIR and copy some MPEG4 or H263 files to that folder
+Push this directory to device.
+
+To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/mpeg4_dec_fuzzer/mpeg4_dec_fuzzer CORPUS_DIR
+ $ adb shell /data/fuzz/arm64/h263_dec_fuzzer/h263_dec_fuzzer CORPUS_DIR
+```
+To run on host
+```
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/mpeg4_dec_fuzzer/mpeg4_dec_fuzzer CORPUS_DIR
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/h263_dec_fuzzer/h263_dec_fuzzer CORPUS_DIR
+```
+
+# Fuzzer for libstagefright_m4vh263enc encoder
+
+## Plugin Design Considerations
+The fuzzer plugin for MPEG4/H263 is designed based on the understanding of the
+codec and tries to achieve the following:
+
+##### Maximize code coverage
+The configuration parameters are not hardcoded, but instead selected based on
+incoming data. This ensures more code paths are reached by the fuzzer.
+
+MPEG4/H263 supports the following parameters:
+1. Frame Width (parameter name: `encWidth`)
+2. Frame Height (parameter name: `encHeight`)
+3. Rate control mode (parameter name: `rcType`)
+4. Number of bytes per packet (parameter name: `packetSize`)
+5. Qp for I-Vop(parameter name: `iQuant`)
+6. Qp for P-Vop (parameter name: `pQuant`)
+7. Enable RVLC mode (parameter name: `rvlcEnable`)
+8. Quantization mode (parameter name: `quantType`)
+9. Disable frame skipping (parameter name: `noFrameSkipped`)
+10. Enable scene change detection (parameter name: `sceneDetect`)
+11. Number of intra MBs in P-frame(parameter name: `numIntraMB`)
+12. Search range of ME (parameter name: `searchRange`)
+13. Enable 8x8 ME and MC (parameter name: `mv8x8Enable`)
+14. Enable AC prediction (parameter name: `useACPred`)
+15. Threshold for intra DC VLC (parameter name: `intraDCVlcTh`)
+16. Encoding Mode (parameter name: `encMode`)
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `rcType` | 0. `CONSTANT_Q` 1. `CBR_1` 2. `VBR_1` 3. `CBR_2` 4. `VBR_2` 5. `CBR_LOWDELAY` | All the bits of 6th byte of data modulus 6 |
+| `packetSize` | In the range `0 to 255` | All the bits of 7th byte of data |
+| `iQuant` | In the range `1 to 31` | All the bits of 8th byte of data |
+| `pQuant` | In the range `1 to 31` | All the bits of 9th byte of data |
+| `rvlcEnable` | 0. `PV_OFF` 1. `PV_ON` | bit 0 of 10th byte of data |
+| `quantType` | 0. `0` 1. `1` | bit 0 of 11th byte of data |
+| `noFrameSkipped` | 0. `PV_OFF` 1. `PV_ON` | bit 0 of 12th byte of data |
+| `sceneDetect` | 0. `PV_OFF` 1. `PV_ON` | bit 0 of 13th byte of data |
+| `numIntraMB` | In the range `0 to 7` | bit 0, 1 and 2 of 14th byte of data |
+| `searchRange` | In the range `0 to 31` | bit 0, 1, 2, 3 and 4 of 15th byte of data |
+| `mv8x8Enable` | 0. `PV_OFF` 1. `PV_ON` | bit 0 of 16th byte of data |
+| `useACPred` | 0. `PV_OFF` 1. `PV_ON` | bit 0 of 17th byte of data |
+| `intraDCVlcTh` | In the range `0 to 7` | bit 0, 1 and 2 of 18th byte of data |
+
+Following parameters are only for mpeg4_enc_fuzzer
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `encWidth` | In the range `0 to 10239` | All the bits of 1st and 2nd byte of data |
+| `encHeight` | In the range `0 to 10239` | All the bits of 3rd and 4th byte of data |
+| `encMode` | 0. `H263_MODE` 1. `H263_MODE_WITH_ERR_RES` 2. `DATA_PARTITIONING_MODE` 3. `COMBINE_MODE_NO_ERR_RES` 4. `COMBINE_MODE_WITH_ERR_RES` | All the bits of 19th byte of data modulus 5 |
+
+Following parameters are only for h263_enc_fuzzer
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `encWidth` | 0. `128` 1. `176` 2. `352` 3. `704` 4. `1408` | All the bits of 1st byte of data modulus 5|
+| `encHeight` | 0. `96` 1. `144` 2. `288` 3. `576` 4. `1152 ` | All the bits of 3rd byte of data modulus 5|
+| `encMode` | 0. `SHORT_HEADER` 1. `SHORT_HEADER_WITH_ERR_RES` | All the bits of 19th byte of data modulus 2 |
+
+This also ensures that the plugin is always deterministic for any given input.
+
+##### Maximize utilization of input data
+The plugin feeds the entire input data to the codec using a loop.
+If the encode operation was successful, the input is advanced by the frame size.
+If the encode operation was un-successful, the input is still advanced by frame size so
+that the fuzzer can proceed to feed the next frame.
+
+This ensures that the plugin tolerates any kind of input (empty, huge,
+malformed, etc) and doesnt `exit()` on any input and thereby increasing the
+chance of identifying vulnerabilities.
+
+## Build
+
+This describes steps to build mpeg4_enc_fuzzer and h263_enc_fuzzer binary.
+
+### Android
+
+#### Steps to build
+Build the fuzzer
+```
+ $ mm -j$(nproc) mpeg4_enc_fuzzer
+ $ mm -j$(nproc) h263_enc_fuzzer
+```
+
+#### Steps to run
+Create a directory CORPUS_DIR and copy some yuv files to that folder
+Push this directory to device.
+
+To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/m4v_h263_enc_fuzzer/m4v_h263_enc_fuzzer CORPUS_DIR
+ $ adb shell /data/fuzz/arm64/h263_enc_fuzzer/h263_enc_fuzzer CORPUS_DIR
+```
+To run on host
+```
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/mpeg4_enc_fuzzer/mpeg4_enc_fuzzer CORPUS_DIR
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/h263_enc_fuzzer/h263_enc_fuzzer CORPUS_DIR
+```
+
+## References:
+ * http://llvm.org/docs/LibFuzzer.html
+ * https://github.com/google/oss-fuzz
diff --git a/media/codecs/m4v_h263/fuzzer/h263_dec_fuzzer.dict b/media/codecs/m4v_h263/fuzzer/h263_dec_fuzzer.dict
new file mode 100644
index 0000000..591d37e
--- /dev/null
+++ b/media/codecs/m4v_h263/fuzzer/h263_dec_fuzzer.dict
@@ -0,0 +1,2 @@
+# Start code (bytes 0-3)
+kw1="\x00\x00\x80\x02"
diff --git a/media/codecs/m4v_h263/fuzzer/mpeg4_dec_fuzzer.dict b/media/codecs/m4v_h263/fuzzer/mpeg4_dec_fuzzer.dict
new file mode 100644
index 0000000..76241a6
--- /dev/null
+++ b/media/codecs/m4v_h263/fuzzer/mpeg4_dec_fuzzer.dict
@@ -0,0 +1,2 @@
+# Start code (bytes 0-3)
+kw1="\x00\x00\x01\xB0"
diff --git a/media/codecs/m4v_h263/fuzzer/mpeg4_h263_dec_fuzzer.cpp b/media/codecs/m4v_h263/fuzzer/mpeg4_h263_dec_fuzzer.cpp
new file mode 100644
index 0000000..912c821
--- /dev/null
+++ b/media/codecs/m4v_h263/fuzzer/mpeg4_h263_dec_fuzzer.cpp
@@ -0,0 +1,205 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+#include "mp4dec_api.h"
+#define MPEG4_MAX_WIDTH 1920
+#define MPEG4_MAX_HEIGHT 1080
+#define H263_MAX_WIDTH 352
+#define H263_MAX_HEIGHT 288
+#define DEFAULT_WIDTH 352
+#define DEFAULT_HEIGHT 288
+
+constexpr size_t kMaxNumDecodeCalls = 100;
+constexpr uint8_t kNumOutputBuffers = 2;
+constexpr int kLayer = 1;
+
+struct tagvideoDecControls;
+
+/* == ceil(num / den) * den. T must be integer type, alignment must be positive power of 2 */
+template <class T, class U>
+inline static const T align(const T &num, const U &den) {
+ return (num + (T)(den - 1)) & (T) ~(den - 1);
+}
+
+class Codec {
+ public:
+ Codec() = default;
+ ~Codec() { deInitDecoder(); }
+ bool initDecoder();
+ bool allocOutputBuffer(size_t outputBufferSize);
+ void freeOutputBuffer();
+ void handleResolutionChange();
+ void decodeFrames(const uint8_t *data, size_t size);
+ void deInitDecoder();
+
+ private:
+ tagvideoDecControls *mDecHandle = nullptr;
+ uint8_t *mOutputBuffer[kNumOutputBuffers];
+ bool mInitialized = false;
+ bool mFramesConfigured = false;
+#ifdef MPEG4
+ MP4DecodingMode mInputMode = MPEG4_MODE;
+ size_t mMaxWidth = MPEG4_MAX_WIDTH;
+ size_t mMaxHeight = MPEG4_MAX_HEIGHT;
+#else
+ MP4DecodingMode mInputMode = H263_MODE;
+ size_t mMaxWidth = H263_MAX_WIDTH;
+ size_t mMaxHeight = H263_MAX_HEIGHT;
+#endif
+ uint32_t mNumSamplesOutput = 0;
+ uint32_t mWidth = DEFAULT_WIDTH;
+ uint32_t mHeight = DEFAULT_HEIGHT;
+};
+
+bool Codec::initDecoder() {
+ mDecHandle = new tagvideoDecControls;
+ if (!mDecHandle) {
+ return false;
+ }
+ memset(mDecHandle, 0, sizeof(tagvideoDecControls));
+ return true;
+}
+
+bool Codec::allocOutputBuffer(size_t outputBufferSize) {
+ for (uint8_t i = 0; i < kNumOutputBuffers; ++i) {
+ if (!mOutputBuffer[i]) {
+ mOutputBuffer[i] = static_cast<uint8_t *>(malloc(outputBufferSize));
+ if (!mOutputBuffer[i]) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+void Codec::freeOutputBuffer() {
+ for (uint8_t i = 0; i < kNumOutputBuffers; ++i) {
+ if (mOutputBuffer[i]) {
+ free(mOutputBuffer[i]);
+ mOutputBuffer[i] = nullptr;
+ }
+ }
+}
+
+void Codec::handleResolutionChange() {
+ int32_t dispWidth, dispHeight;
+ PVGetVideoDimensions(mDecHandle, &dispWidth, &dispHeight);
+
+ int32_t bufWidth, bufHeight;
+ PVGetBufferDimensions(mDecHandle, &bufWidth, &bufHeight);
+
+ if (dispWidth != mWidth || dispHeight != mHeight) {
+ mWidth = dispWidth;
+ mHeight = dispHeight;
+ }
+}
+
+void Codec::decodeFrames(const uint8_t *data, size_t size) {
+ size_t outputBufferSize = align(mMaxWidth, 16) * align(mMaxHeight, 16) * 3 / 2;
+ uint8_t *start_code = const_cast<uint8_t *>(data);
+ static const uint8_t volInfo[] = {0x00, 0x00, 0x01, 0xB0};
+ bool volHeader = memcmp(start_code, volInfo, 4) == 0;
+ if (volHeader) {
+ PVCleanUpVideoDecoder(mDecHandle);
+ mInitialized = false;
+ }
+
+ if (!mInitialized) {
+ uint8_t *volData[1]{};
+ int32_t volSize = 0;
+
+ if (volHeader) { /* removed some codec config part */
+ volData[0] = const_cast<uint8_t *>(data);
+ volSize = size;
+ }
+
+ if (!PVInitVideoDecoder(mDecHandle, volData, &volSize, kLayer, mMaxWidth, mMaxHeight,
+ mInputMode)) {
+ return;
+ }
+ mInitialized = true;
+ MP4DecodingMode actualMode = PVGetDecBitstreamMode(mDecHandle);
+ if (mInputMode != actualMode) {
+ return;
+ }
+
+ PVSetPostProcType(mDecHandle, 0);
+ }
+ size_t yFrameSize = sizeof(uint8) * mDecHandle->size;
+ if (outputBufferSize < yFrameSize * 3 / 2) {
+ return;
+ }
+ if (!allocOutputBuffer(outputBufferSize)) {
+ return;
+ }
+ size_t numDecodeCalls = 0;
+ while ((size > 0) && (numDecodeCalls < kMaxNumDecodeCalls)) {
+ if (!mFramesConfigured) {
+ PVSetReferenceYUV(mDecHandle, mOutputBuffer[1]);
+ mFramesConfigured = true;
+ }
+
+ // Need to check if header contains new info, e.g., width/height, etc.
+ VopHeaderInfo header_info;
+ uint32_t useExtTimestamp = (numDecodeCalls == 0);
+ int32_t tempSize = (int32_t)size;
+ uint8_t *bitstreamTmp = const_cast<uint8_t *>(data);
+ uint32_t timestamp = 0;
+ if (PVDecodeVopHeader(mDecHandle, &bitstreamTmp, ×tamp, &tempSize, &header_info,
+ &useExtTimestamp, mOutputBuffer[mNumSamplesOutput & 1]) != PV_TRUE) {
+ return;
+ }
+
+ handleResolutionChange();
+
+ PVDecodeVopBody(mDecHandle, &tempSize);
+ uint32_t bytesConsumed = 1;
+ if (size > tempSize) {
+ bytesConsumed = size - tempSize;
+ }
+ data += bytesConsumed;
+ size -= bytesConsumed;
+ ++mNumSamplesOutput;
+ ++numDecodeCalls;
+ }
+ freeOutputBuffer();
+}
+
+void Codec::deInitDecoder() {
+ PVCleanUpVideoDecoder(mDecHandle);
+ delete mDecHandle;
+ mDecHandle = nullptr;
+ mInitialized = false;
+ freeOutputBuffer();
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size < 4) {
+ return 0;
+ }
+ Codec *codec = new Codec();
+ if (!codec) {
+ return 0;
+ }
+ if (codec->initDecoder()) {
+ codec->decodeFrames(data, size);
+ }
+ delete codec;
+ return 0;
+}
diff --git a/media/codecs/m4v_h263/fuzzer/mpeg4_h263_enc_fuzzer.cpp b/media/codecs/m4v_h263/fuzzer/mpeg4_h263_enc_fuzzer.cpp
new file mode 100644
index 0000000..423325d
--- /dev/null
+++ b/media/codecs/m4v_h263/fuzzer/mpeg4_h263_enc_fuzzer.cpp
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <algorithm>
+#include "mp4enc_api.h"
+
+constexpr int8_t kIDRFrameRefreshIntervalInSec = 1;
+constexpr MP4RateControlType krcType[] = {CONSTANT_Q, CBR_1, VBR_1, CBR_2, VBR_2, CBR_LOWDELAY};
+#ifdef MPEG4
+constexpr MP4EncodingMode kEncodingMode[] = {SHORT_HEADER, SHORT_HEADER_WITH_ERR_RES,
+ DATA_PARTITIONING_MODE, COMBINE_MODE_NO_ERR_RES,
+ COMBINE_MODE_WITH_ERR_RES};
+constexpr size_t kMaxWidth = 10240;
+constexpr size_t kMaxHeight = 10240;
+#else
+constexpr MP4EncodingMode kEncodingMode[] = {H263_MODE, H263_MODE_WITH_ERR_RES};
+constexpr int kWidth[] = {128, 176, 352, 704, 1408};
+constexpr int kHeight[] = {96, 144, 288, 576, 1152};
+constexpr size_t kWidthNum = std::size(kWidth);
+constexpr size_t kHeightNum = std::size(kHeight);
+#endif
+
+constexpr size_t krcTypeNum = std::size(krcType);
+constexpr size_t kEncodingModeNum = std::size(kEncodingMode);
+constexpr size_t kMaxQP = 51;
+
+enum {
+ IDX_WD_BYTE_1,
+ IDX_WD_BYTE_2,
+ IDX_HT_BYTE_1,
+ IDX_HT_BYTE_2,
+ IDX_FRAME_RATE,
+ IDX_RC_TYPE,
+ IDX_PACKET_SIZE,
+ IDX_I_FRAME_QP,
+ IDX_P_FRAME_QP,
+ IDX_ENABLE_RVLC,
+ IDX_QUANT_TYPE,
+ IDX_NO_FRAME_SKIPPED_FLAG,
+ IDX_ENABLE_SCENE_DETECT,
+ IDX_NUM_INTRA_MB,
+ IDX_SEARCH_RANGE,
+ IDX_ENABLE_MV_8x8,
+ IDX_USE_AC_PRED,
+ IDX_INTRA_DC_VLC_THRESHOLD,
+ IDX_ENC_MODE,
+ IDX_LAST
+};
+
+class Codec {
+ public:
+ Codec() = default;
+ ~Codec() { deInitEncoder(); }
+ bool initEncoder(const uint8_t *data);
+ void encodeFrames(const uint8_t *data, size_t size);
+ void deInitEncoder();
+
+ private:
+ int32_t mFrameWidth = 352;
+ int32_t mFrameHeight = 288;
+ float mFrameRate = 25.0f;
+ VideoEncOptions *mEncodeHandle = nullptr;
+ VideoEncControls *mEncodeControl = nullptr;
+};
+
+bool Codec::initEncoder(const uint8_t *data) {
+ mEncodeHandle = new VideoEncOptions;
+ if (!mEncodeHandle) {
+ return false;
+ }
+ memset(mEncodeHandle, 0, sizeof(VideoEncOptions));
+ mEncodeControl = new VideoEncControls;
+ if (!mEncodeControl) {
+ return false;
+ }
+ memset(mEncodeControl, 0, sizeof(VideoEncControls));
+ PVGetDefaultEncOption(mEncodeHandle, 0);
+
+#ifdef MPEG4
+ mFrameWidth = ((data[IDX_WD_BYTE_1] << 8) | data[IDX_WD_BYTE_2]) % kMaxWidth;
+ mFrameHeight = ((data[IDX_HT_BYTE_1] << 8) | data[IDX_HT_BYTE_2]) % kMaxHeight;
+#else
+ mFrameWidth = kWidth[data[IDX_WD_BYTE_1] % kWidthNum];
+ mFrameHeight = kHeight[data[IDX_HT_BYTE_1] % kHeightNum];
+#endif
+ mFrameRate = data[IDX_FRAME_RATE];
+ mEncodeHandle->rcType = krcType[data[IDX_RC_TYPE] % krcTypeNum];
+ mEncodeHandle->profile_level = CORE_PROFILE_LEVEL2;
+ mEncodeHandle->packetSize = data[IDX_PACKET_SIZE];
+ mEncodeHandle->iQuant[0] = (data[IDX_I_FRAME_QP] % kMaxQP) + 1;
+ mEncodeHandle->pQuant[0] = (data[IDX_P_FRAME_QP] % kMaxQP) + 1;
+ mEncodeHandle->rvlcEnable = (data[IDX_ENABLE_RVLC] & 0x01) ? PV_OFF : PV_ON;
+ mEncodeHandle->quantType[0] = (data[IDX_QUANT_TYPE] & 0x01) ? 0 : 1;
+ mEncodeHandle->noFrameSkipped = (data[IDX_NO_FRAME_SKIPPED_FLAG] & 0x01) ? PV_OFF : PV_ON;
+ mEncodeHandle->sceneDetect = (data[IDX_ENABLE_SCENE_DETECT] & 0x01) ? PV_OFF : PV_ON;
+ mEncodeHandle->numIntraMB = data[IDX_NUM_INTRA_MB] & 0x07;
+ mEncodeHandle->searchRange = data[IDX_SEARCH_RANGE] & 0x1F;
+ mEncodeHandle->mv8x8Enable = (data[IDX_ENABLE_MV_8x8] & 0x01) ? PV_OFF : PV_ON;
+ mEncodeHandle->useACPred = (data[IDX_USE_AC_PRED] & 0x01) ? PV_OFF : PV_ON;
+ mEncodeHandle->intraDCVlcTh = data[IDX_INTRA_DC_VLC_THRESHOLD] & 0x07;
+ mEncodeHandle->encMode = kEncodingMode[data[IDX_ENC_MODE] % kEncodingModeNum];
+ mEncodeHandle->encWidth[0] = mFrameWidth;
+ mEncodeHandle->encHeight[0] = mFrameHeight;
+ mEncodeHandle->encFrameRate[0] = mFrameRate;
+ mEncodeHandle->tickPerSrc = mEncodeHandle->timeIncRes / mFrameRate;
+ mEncodeHandle->intraPeriod = (kIDRFrameRefreshIntervalInSec * mFrameRate);
+ if (!PVInitVideoEncoder(mEncodeControl, mEncodeHandle)) {
+ return false;
+ }
+ return true;
+}
+
+void Codec::deInitEncoder() {
+ if (mEncodeControl) {
+ PVCleanUpVideoEncoder(mEncodeControl);
+ delete mEncodeControl;
+ mEncodeControl = nullptr;
+ }
+ if (mEncodeHandle) {
+ delete mEncodeHandle;
+ mEncodeHandle = nullptr;
+ }
+}
+
+void Codec::encodeFrames(const uint8_t *data, size_t size) {
+ size_t inputBufferSize = (mFrameWidth * mFrameHeight * 3) / 2;
+ size_t outputBufferSize = inputBufferSize * 2;
+ uint8_t *outputBuffer = new uint8_t[outputBufferSize];
+ uint8_t *inputBuffer = new uint8_t[inputBufferSize];
+
+ // Get VOL header.
+ int32_t sizeOutputBuffer = outputBufferSize;
+ PVGetVolHeader(mEncodeControl, outputBuffer, &sizeOutputBuffer, 0);
+
+ size_t numFrame = 0;
+ while (size > 0) {
+ size_t bytesConsumed = std::min(size, inputBufferSize);
+ memcpy(inputBuffer, data, bytesConsumed);
+ if (bytesConsumed < inputBufferSize) {
+ memset(inputBuffer + bytesConsumed, data[0], inputBufferSize - bytesConsumed);
+ }
+ VideoEncFrameIO videoIn{}, videoOut{};
+ videoIn.height = mFrameHeight;
+ videoIn.pitch = mFrameWidth;
+ videoIn.timestamp = (numFrame * 1000) / mFrameRate;
+ videoIn.yChan = inputBuffer;
+ videoIn.uChan = videoIn.yChan + videoIn.height * videoIn.pitch;
+ videoIn.vChan = videoIn.uChan + ((videoIn.height * videoIn.pitch) >> 2);
+ uint32_t modTimeMs = 0;
+ int32_t dataLength = outputBufferSize;
+ int32_t nLayer = 0;
+ PVEncodeVideoFrame(mEncodeControl, &videoIn, &videoOut, &modTimeMs, outputBuffer,
+ &dataLength, &nLayer);
+ MP4HintTrack hintTrack;
+ PVGetHintTrack(mEncodeControl, &hintTrack);
+ PVGetOverrunBuffer(mEncodeControl);
+ ++numFrame;
+ data += bytesConsumed;
+ size -= bytesConsumed;
+ }
+ delete[] inputBuffer;
+ delete[] outputBuffer;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size < IDX_LAST) {
+ return 0;
+ }
+ Codec *codec = new Codec();
+ if (!codec) {
+ return 0;
+ }
+ if (codec->initEncoder(data)) {
+ data += IDX_LAST;
+ size -= IDX_LAST;
+ codec->encodeFrames(data, size);
+ }
+ delete codec;
+ return 0;
+}
diff --git a/media/codecs/m4v_h263/patent_disclaimer.txt b/media/codecs/m4v_h263/patent_disclaimer.txt
new file mode 100644
index 0000000..b4bf11d
--- /dev/null
+++ b/media/codecs/m4v_h263/patent_disclaimer.txt
@@ -0,0 +1,9 @@
+
+THIS IS NOT A GRANT OF PATENT RIGHTS.
+
+Google makes no representation or warranty that the codecs for which
+source code is made available hereunder are unencumbered by
+third-party patents. Those intending to use this source code in
+hardware or software products are advised that implementations of
+these codecs, including in open source software or shareware, may
+require patent licenses from the relevant patent holders.
diff --git a/media/codecs/mp3dec/Android.bp b/media/codecs/mp3dec/Android.bp
new file mode 100644
index 0000000..1acf0a6
--- /dev/null
+++ b/media/codecs/mp3dec/Android.bp
@@ -0,0 +1,115 @@
+cc_library_static {
+ name: "libstagefright_mp3dec",
+ vendor_available: true,
+ min_sdk_version: "29",
+
+ host_supported:true,
+ srcs: [
+ "src/pvmp3_normalize.cpp",
+ "src/pvmp3_alias_reduction.cpp",
+ "src/pvmp3_crc.cpp",
+ "src/pvmp3_decode_header.cpp",
+ "src/pvmp3_decode_huff_cw.cpp",
+ "src/pvmp3_getbits.cpp",
+ "src/pvmp3_dequantize_sample.cpp",
+ "src/pvmp3_framedecoder.cpp",
+ "src/pvmp3_get_main_data_size.cpp",
+ "src/pvmp3_get_side_info.cpp",
+ "src/pvmp3_get_scale_factors.cpp",
+ "src/pvmp3_mpeg2_get_scale_data.cpp",
+ "src/pvmp3_mpeg2_get_scale_factors.cpp",
+ "src/pvmp3_mpeg2_stereo_proc.cpp",
+ "src/pvmp3_huffman_decoding.cpp",
+ "src/pvmp3_huffman_parsing.cpp",
+ "src/pvmp3_tables.cpp",
+ "src/pvmp3_imdct_synth.cpp",
+ "src/pvmp3_mdct_6.cpp",
+ "src/pvmp3_dct_6.cpp",
+ "src/pvmp3_poly_phase_synthesis.cpp",
+ "src/pvmp3_equalizer.cpp",
+ "src/pvmp3_seek_synch.cpp",
+ "src/pvmp3_stereo_proc.cpp",
+ "src/pvmp3_reorder.cpp",
+
+ "src/pvmp3_polyphase_filter_window.cpp",
+ "src/pvmp3_mdct_18.cpp",
+ "src/pvmp3_dct_9.cpp",
+ "src/pvmp3_dct_16.cpp",
+ ],
+
+ arch: {
+ arm: {
+ exclude_srcs: [
+ "src/pvmp3_polyphase_filter_window.cpp",
+ "src/pvmp3_mdct_18.cpp",
+ "src/pvmp3_dct_9.cpp",
+ "src/pvmp3_dct_16.cpp",
+ ],
+ srcs: [
+ "src/asm/pvmp3_polyphase_filter_window_gcc.s",
+ "src/asm/pvmp3_mdct_18_gcc.s",
+ "src/asm/pvmp3_dct_9_gcc.s",
+ "src/asm/pvmp3_dct_16_gcc.s",
+ ],
+
+ instruction_set: "arm",
+ },
+ },
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ ],
+ cfi: true,
+ },
+
+ include_dirs: ["frameworks/av/media/libstagefright/include"],
+
+ export_include_dirs: [
+ "include",
+ "src",
+ ],
+
+ cflags: [
+ "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+ "-Werror",
+ ],
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+//###############################################################################
+cc_test {
+ name: "libstagefright_mp3dec_test",
+ gtest: false,
+
+ srcs: [
+ "test/mp3dec_test.cpp",
+ "test/mp3reader.cpp",
+ ],
+
+ cflags: ["-Wall", "-Werror"],
+
+ local_include_dirs: [
+ "src",
+ "include",
+ ],
+
+ sanitize: {
+ misc_undefined: [
+ "signed-integer-overflow",
+ ],
+ cfi: true,
+ },
+
+ static_libs: [
+ "libstagefright_mp3dec",
+ "libsndfile",
+ ],
+
+ shared_libs: ["libaudioutils"],
+}
diff --git a/media/codecs/mp3dec/MODULE_LICENSE_APACHE2 b/media/codecs/mp3dec/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/codecs/mp3dec/MODULE_LICENSE_APACHE2
diff --git a/media/codecs/mp3dec/NOTICE b/media/codecs/mp3dec/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/media/codecs/mp3dec/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/media/codecs/mp3dec/TEST_MAPPING b/media/codecs/mp3dec/TEST_MAPPING
new file mode 100644
index 0000000..4ef4317
--- /dev/null
+++ b/media/codecs/mp3dec/TEST_MAPPING
@@ -0,0 +1,9 @@
+// mappings for frameworks/av/media/libstagefright/codecs/mp3dec
+{
+ // tests which require dynamic content
+ // invoke with: atest -- --enable-module-dynamic-download=true
+ // TODO(b/148094059): unit tests not allowed to download content
+ "dynamic-presubmit": [
+ { "name": "Mp3DecoderTest"}
+ ]
+}
diff --git a/media/codecs/mp3dec/fuzzer/Android.bp b/media/codecs/mp3dec/fuzzer/Android.bp
new file mode 100644
index 0000000..79fa1e9
--- /dev/null
+++ b/media/codecs/mp3dec/fuzzer/Android.bp
@@ -0,0 +1,39 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+
+cc_fuzz {
+ name: "mp3_dec_fuzzer",
+ host_supported: true,
+
+ static_libs: [
+ "libstagefright_mp3dec",
+ ],
+
+ srcs: [
+ "mp3_dec_fuzzer.cpp",
+ ],
+
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
diff --git a/media/codecs/mp3dec/fuzzer/README.md b/media/codecs/mp3dec/fuzzer/README.md
new file mode 100644
index 0000000..09dd5c3
--- /dev/null
+++ b/media/codecs/mp3dec/fuzzer/README.md
@@ -0,0 +1,56 @@
+# Fuzzer for libstagefright_mp3dec decoder
+
+## Plugin Design Considerations
+The fuzzer plugin for mp3 decoder is designed based on the understanding of the
+codec and tries to achieve the following:
+
+##### Maximize code coverage
+
+This fuzzer makes use of the following config parameters:
+1. Equalizer type (parameter name: `equalizerType`)
+
+| Parameter| Valid Values| Configured Value|
+|------------- |-------------| ----- |
+| `equalizerType` | 0. `flat ` 1. `bass_boost ` 2. `rock ` 3. `pop ` 4. `jazz ` 5. `classical ` 6. `talk ` 7. `flat_ ` | Bits 0, 1 and 2 of first byte of input stream |
+| `crcEnabled` | 0. `false ` 1. `true `| Bit 0 of second byte of input stream |
+
+##### Maximize utilization of input data
+The plugin feeds the entire input data to the codec using a loop.
+ * If the decode operation was successful, the input is advanced by the number
+ of bytes used by the decoder.
+ * If the decode operation was un-successful, the input is advanced by 1 byte
+ till it reaches a valid frame or end of stream.
+
+This ensures that the plugin tolerates any kind of input (empty, huge,
+malformed, etc) and doesnt `exit()` on any input and thereby increasing the
+chance of identifying vulnerabilities.
+
+## Build
+
+This describes steps to build mp3_dec_fuzzer binary.
+
+### Android
+
+#### Steps to build
+Build the fuzzer
+```
+ $ mm -j$(nproc) mp3_dec_fuzzer
+```
+
+#### Steps to run
+Create a directory CORPUS_DIR and copy some mp3 files to that folder.
+Push this directory to device.
+
+To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/mp3_dec_fuzzer/mp3_dec_fuzzer CORPUS_DIR
+```
+To run on host
+```
+ $ $ANDROID_HOST_OUT/fuzz/x86_64/mp3_dec_fuzzer/mp3_dec_fuzzer CORPUS_DIR
+```
+
+## References:
+ * http://llvm.org/docs/LibFuzzer.html
+ * https://github.com/google/oss-fuzz
diff --git a/media/codecs/mp3dec/fuzzer/mp3_dec_fuzzer.cpp b/media/codecs/mp3dec/fuzzer/mp3_dec_fuzzer.cpp
new file mode 100644
index 0000000..847c8c4
--- /dev/null
+++ b/media/codecs/mp3dec/fuzzer/mp3_dec_fuzzer.cpp
@@ -0,0 +1,237 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+ */
+
+#include <stdlib.h>
+#include <algorithm>
+
+#include <pvmp3decoder_api.h>
+
+constexpr int kMaxFrameSamples = 4608;
+constexpr int kMaxChannels = 2;
+constexpr e_equalization kEqualizerTypes[] = {flat, bass_boost, rock, pop,
+ jazz, classical, talk, flat_};
+
+static bool parseMp3Header(uint32_t header, size_t *frame_size,
+ uint32_t *out_sampling_rate = nullptr, uint32_t *out_channels = nullptr,
+ uint32_t *out_bitrate = nullptr, uint32_t *out_num_samples = nullptr) {
+ *frame_size = 0;
+ if (out_sampling_rate) *out_sampling_rate = 0;
+ if (out_channels) *out_channels = 0;
+ if (out_bitrate) *out_bitrate = 0;
+ if (out_num_samples) *out_num_samples = 0;
+
+ if ((header & 0xffe00000) != 0xffe00000) {
+ return false;
+ }
+ unsigned version = (header >> 19) & 3;
+ if (version == 0x01) {
+ return false;
+ }
+ unsigned layer = (header >> 17) & 3;
+ if (layer == 0x00) {
+ return false;
+ }
+ unsigned bitrate_index = (header >> 12) & 0x0f;
+ if (bitrate_index == 0 || bitrate_index == 0x0f) {
+ return false;
+ }
+ unsigned sampling_rate_index = (header >> 10) & 3;
+ if (sampling_rate_index == 3) {
+ return false;
+ }
+ static const int kSamplingRateV1[] = {44100, 48000, 32000};
+ int sampling_rate = kSamplingRateV1[sampling_rate_index];
+ if (version == 2 /* V2 */) {
+ sampling_rate /= 2;
+ } else if (version == 0 /* V2.5 */) {
+ sampling_rate /= 4;
+ }
+
+ unsigned padding = (header >> 9) & 1;
+
+ if (layer == 3) { // layer I
+ static const int kBitrateV1[] = {32, 64, 96, 128, 160, 192, 224,
+ 256, 288, 320, 352, 384, 416, 448};
+ static const int kBitrateV2[] = {32, 48, 56, 64, 80, 96, 112,
+ 128, 144, 160, 176, 192, 224, 256};
+
+ int bitrate =
+ (version == 3 /* V1 */) ? kBitrateV1[bitrate_index - 1] : kBitrateV2[bitrate_index - 1];
+
+ if (out_bitrate) {
+ *out_bitrate = bitrate;
+ }
+ *frame_size = (12000 * bitrate / sampling_rate + padding) * 4;
+ if (out_num_samples) {
+ *out_num_samples = 384;
+ }
+ } else { // layer II or III
+ static const int kBitrateV1L2[] = {32, 48, 56, 64, 80, 96, 112,
+ 128, 160, 192, 224, 256, 320, 384};
+ static const int kBitrateV1L3[] = {32, 40, 48, 56, 64, 80, 96,
+ 112, 128, 160, 192, 224, 256, 320};
+ static const int kBitrateV2[] = {8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160};
+ int bitrate;
+ if (version == 3 /* V1 */) {
+ bitrate =
+ (layer == 2 /* L2 */) ? kBitrateV1L2[bitrate_index - 1] : kBitrateV1L3[bitrate_index - 1];
+
+ if (out_num_samples) {
+ *out_num_samples = 1152;
+ }
+ } else { // V2 (or 2.5)
+ bitrate = kBitrateV2[bitrate_index - 1];
+ if (out_num_samples) {
+ *out_num_samples = (layer == 1 /* L3 */) ? 576 : 1152;
+ }
+ }
+
+ if (out_bitrate) {
+ *out_bitrate = bitrate;
+ }
+
+ if (version == 3 /* V1 */) {
+ *frame_size = 144000 * bitrate / sampling_rate + padding;
+ } else { // V2 or V2.5
+ size_t tmp = (layer == 1 /* L3 */) ? 72000 : 144000;
+ *frame_size = tmp * bitrate / sampling_rate + padding;
+ }
+ }
+
+ if (out_sampling_rate) {
+ *out_sampling_rate = sampling_rate;
+ }
+
+ if (out_channels) {
+ int channel_mode = (header >> 6) & 3;
+ *out_channels = (channel_mode == 3) ? 1 : 2;
+ }
+
+ return true;
+}
+
+static uint32_t U32_AT(const uint8_t *ptr) {
+ return ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
+}
+
+static bool checkHeader(uint8 *header, size_t inSize) {
+ size_t frameSize;
+ size_t totalInSize = 0;
+ bool isValidBuffer = false;
+
+ while (totalInSize + 4 < inSize) {
+ isValidBuffer = true;
+ uint32_t val = U32_AT(header + totalInSize);
+ if (!parseMp3Header(val, &frameSize, nullptr, nullptr, nullptr, nullptr)) {
+ return false;
+ }
+ totalInSize += frameSize;
+ }
+
+ return (isValidBuffer);
+}
+
+class Codec {
+ public:
+ Codec() = default;
+ ~Codec() { deInitDecoder(); }
+
+ bool initDecoder();
+ void decodeFrames(uint8_t *data, size_t size);
+ void deInitDecoder();
+
+ private:
+ tPVMP3DecoderExternal *mConfig = nullptr;
+ void *mDecoderBuf = nullptr;
+};
+
+bool Codec::initDecoder() {
+ mConfig = new tPVMP3DecoderExternal{};
+ if (!mConfig) {
+ return false;
+ }
+ size_t decoderBufSize = pvmp3_decoderMemRequirements();
+ mDecoderBuf = malloc(decoderBufSize);
+ if (!mDecoderBuf) {
+ return false;
+ }
+ memset(mDecoderBuf, 0x0, decoderBufSize);
+ pvmp3_InitDecoder(mConfig, mDecoderBuf);
+ return true;
+}
+
+void Codec::decodeFrames(uint8_t *data, size_t size) {
+ uint8_t equalizerTypeValue = (data[0] & 0x7);
+ mConfig->equalizerType = kEqualizerTypes[equalizerTypeValue];
+ mConfig->crcEnabled = data[1] & 0x1;
+
+ while (size > 0) {
+ bool status = checkHeader(data, size);
+ if (!status) {
+ size--;
+ data++;
+ continue;
+ }
+ size_t outBufSize = kMaxFrameSamples * kMaxChannels;
+ size_t usedBytes = 0;
+ int16_t outputBuf[outBufSize];
+ mConfig->inputBufferCurrentLength = size;
+ mConfig->inputBufferUsedLength = 0;
+ mConfig->inputBufferMaxLength = 0;
+ mConfig->pInputBuffer = data;
+ mConfig->pOutputBuffer = outputBuf;
+ mConfig->outputFrameSize = outBufSize / sizeof(int16_t);
+
+ ERROR_CODE decoderErr;
+ decoderErr = pvmp3_framedecoder(mConfig, mDecoderBuf);
+ if (decoderErr != NO_DECODING_ERROR) {
+ size--;
+ data++;
+ } else {
+ usedBytes = std::min((int32_t)size, mConfig->inputBufferUsedLength);
+ size -= usedBytes;
+ data += usedBytes;
+ }
+ }
+}
+
+void Codec::deInitDecoder() {
+ if (mDecoderBuf) {
+ free(mDecoderBuf);
+ mDecoderBuf = nullptr;
+ }
+ delete mConfig;
+ mConfig = nullptr;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size < 4) {
+ return 0;
+ }
+ Codec *codec = new Codec();
+ if (!codec) {
+ return 0;
+ }
+ if (codec->initDecoder()) {
+ codec->decodeFrames(const_cast<uint8_t *>(data), size);
+ }
+ delete codec;
+ return 0;
+}
diff --git a/media/codecs/mp3dec/include/mp3_decoder_selection.h b/media/codecs/mp3dec/include/mp3_decoder_selection.h
new file mode 100644
index 0000000..e287433
--- /dev/null
+++ b/media/codecs/mp3dec/include/mp3_decoder_selection.h
@@ -0,0 +1,30 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*! \file mp3_decoder_selection.h
+ * \brief select mp3 decoder
+ *
+ */
+
+#ifndef MP3_DECODER_SELECTION_H
+#define MP3_DECODER_SELECTION_H
+
+
+#define NEW_PV_MP3_DECODER 1 // 1 == PV mp3 decoder
+
+#endif
+
diff --git a/media/codecs/mp3dec/include/pvmp3_audio_type_defs.h b/media/codecs/mp3dec/include/pvmp3_audio_type_defs.h
new file mode 100644
index 0000000..2d94384
--- /dev/null
+++ b/media/codecs/mp3dec/include/pvmp3_audio_type_defs.h
@@ -0,0 +1,77 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_audio_type_defs.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file was derived from a number of standards bodies. The type
+ definitions below were created from some of the best practices observed
+ in the standards bodies.
+
+ This file is dependent on limits.h for defining the bit widths. In an
+ ANSI C environment limits.h is expected to always be present and contain
+ the following definitions:
+
+ SCHAR_MIN
+ SCHAR_MAX
+ UCHAR_MAX
+
+ INT_MAX
+ INT_MIN
+ UINT_MAX
+
+ SHRT_MIN
+ SHRT_MAX
+ USHRT_MAX
+
+ LONG_MIN
+ LONG_MAX
+ ULONG_MAX
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PVMP3_AUDIO_TYPE_DEFS_H
+#define PVMP3_AUDIO_TYPE_DEFS_H
+
+#include <stdint.h>
+
+typedef int8_t int8;
+typedef uint8_t uint8;
+typedef int16_t int16;
+typedef uint16_t uint16;
+typedef int32_t int32;
+typedef uint32_t uint32;
+typedef int64_t int64;
+typedef uint64_t uint64;
+
+typedef int32_t Int32;
+
+#endif /* PVMP3_AUDIO_TYPE_DEFS_H */
diff --git a/media/codecs/mp3dec/include/pvmp3decoder_api.h b/media/codecs/mp3dec/include/pvmp3decoder_api.h
new file mode 100644
index 0000000..1568e7c
--- /dev/null
+++ b/media/codecs/mp3dec/include/pvmp3decoder_api.h
@@ -0,0 +1,259 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3decoder_api.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This include file defines the structure tPVMP3DecoderExternal
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3DECODER_API_H
+#define PVMP3DECODER_API_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3_dec_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; DEFINES
+ ; Include all pre-processor statements here.
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; EXTERNAL VARIABLES REFERENCES
+ ; Declare variables used in this module but defined elsewhere
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; SIMPLE TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------------------
+ ; ENUMERATED TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+ typedef enum
+ {
+ flat = 0,
+ bass_boost = 1,
+ rock = 2,
+ pop = 3,
+ jazz = 4,
+ classical = 5,
+ talk = 6,
+ flat_ = 7
+
+ } e_equalization;
+
+
+
+ typedef enum ERROR_CODE
+ {
+ NO_DECODING_ERROR = 0,
+ UNSUPPORTED_LAYER = 1,
+ UNSUPPORTED_FREE_BITRATE = 2,
+ FILE_OPEN_ERROR = 3, /* error opening file */
+ CHANNEL_CONFIG_ERROR = 4, /* error in channel configuration */
+ SYNTHESIS_WINDOW_ERROR = 5, /* error in synthesis window table */
+ READ_FILE_ERROR = 6, /* error reading input file */
+ SIDE_INFO_ERROR = 7, /* error in side info */
+ HUFFMAN_TABLE_ERROR = 8, /* error in Huffman table */
+ COMMAND_LINE_ERROR = 9, /* error in command line */
+ MEMORY_ALLOCATION_ERROR = 10, /* error allocating memory */
+ NO_ENOUGH_MAIN_DATA_ERROR = 11,
+ SYNCH_LOST_ERROR = 12,
+ OUTPUT_BUFFER_TOO_SMALL = 13 /* output buffer can't hold output */
+ } ERROR_CODE;
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ typedef struct
+#ifdef __cplusplus
+ tPVMP3DecoderExternal
+#endif
+ {
+
+ /*
+ * INPUT:
+ * Pointer to the input buffer that contains the encoded bistream data.
+ * The data is filled in such that the first bit transmitted is
+ * the most-significant bit (MSB) of the first array element.
+ * The buffer is accessed in a linear fashion for speed, and the number of
+ * bytes consumed varies frame to frame.
+ * The calling environment can change what is pointed to between calls to
+ * the decode function, library, as long as the inputBufferCurrentLength,
+ * and inputBufferUsedLength are updated too. Also, any remaining bits in
+ * the old buffer must be put at the beginning of the new buffer.
+ */
+ uint8 *pInputBuffer;
+
+ /*
+ * INPUT:
+ * Number of valid bytes in the input buffer, set by the calling
+ * function. After decoding the bitstream the library checks to
+ * see if it when past this value; it would be to prohibitive to
+ * check after every read operation. This value is not modified by
+ * the MP3 library.
+ */
+ int32 inputBufferCurrentLength;
+
+ /*
+ * INPUT/OUTPUT:
+ * Number of elements used by the library, initially set to zero by
+ * the function pvmp3_resetDecoder(), and modified by each
+ * call to pvmp3_framedecoder().
+ */
+ int32 inputBufferUsedLength;
+
+ /*
+ * OUTPUT:
+ * holds the predicted frame size. It used on the test console, for parsing
+ * purposes.
+ */
+ uint32 CurrentFrameLength;
+
+ /*
+ * INPUT:
+ * This variable holds the type of equalization used
+ *
+ *
+ */
+ e_equalization equalizerType;
+
+
+ /*
+ * INPUT:
+ * The actual size of the buffer.
+ * This variable is not used by the library, but is used by the
+ * console test application. This parameter could be deleted
+ * if this value was passed into these function.
+ */
+ int32 inputBufferMaxLength;
+
+ /*
+ * OUTPUT:
+ * The number of channels decoded from the bitstream.
+ */
+ int16 num_channels;
+
+ /*
+ * OUTPUT:
+ * The number of channels decoded from the bitstream.
+ */
+ int16 version;
+
+ /*
+ * OUTPUT:
+ * The sampling rate decoded from the bitstream, in units of
+ * samples/second.
+ */
+ int32 samplingRate;
+
+ /*
+ * OUTPUT:
+ * This value is the bitrate in units of bits/second. IT
+ * is calculated using the number of bits consumed for the current frame,
+ * and then multiplying by the sampling_rate, divided by points in a frame.
+ * This value can changes frame to frame.
+ */
+ int32 bitRate;
+
+ /*
+ * INPUT/OUTPUT:
+ * In: Inform decoder how much more room is available in the output buffer in int16 samples
+ * Out: Size of the output frame in 16-bit words, This value depends on the mp3 version
+ */
+ int32 outputFrameSize;
+
+ /*
+ * INPUT:
+ * Flag to enable/disable crc error checking
+ */
+ int32 crcEnabled;
+
+ /*
+ * OUTPUT:
+ * This value is used to accumulate bit processed and compute an estimate of the
+ * bitrate. For debugging purposes only, as it will overflow for very long clips
+ */
+ uint32 totalNumberOfBitsUsed;
+
+
+ /*
+ * INPUT: (but what is pointed to is an output)
+ * Pointer to the output buffer to hold the 16-bit PCM audio samples.
+ * If the output is stereo, both left and right channels will be stored
+ * in this one buffer.
+ */
+
+ int16 *pOutputBuffer;
+
+ } tPVMP3DecoderExternal;
+
+uint32 pvmp3_decoderMemRequirements(void);
+
+void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt,
+ void *pMem);
+
+void pvmp3_resetDecoder(void *pMem);
+
+ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
+ void *pMem);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
+
diff --git a/media/codecs/mp3dec/patent_disclaimer.txt b/media/codecs/mp3dec/patent_disclaimer.txt
new file mode 100644
index 0000000..b4bf11d
--- /dev/null
+++ b/media/codecs/mp3dec/patent_disclaimer.txt
@@ -0,0 +1,9 @@
+
+THIS IS NOT A GRANT OF PATENT RIGHTS.
+
+Google makes no representation or warranty that the codecs for which
+source code is made available hereunder are unencumbered by
+third-party patents. Those intending to use this source code in
+hardware or software products are advised that implementations of
+these codecs, including in open source software or shareware, may
+require patent licenses from the relevant patent holders.
diff --git a/media/codecs/mp3dec/src/asm/pvmp3_dct_16_gcc.s b/media/codecs/mp3dec/src/asm/pvmp3_dct_16_gcc.s
new file mode 100644
index 0000000..e61c8d3
--- /dev/null
+++ b/media/codecs/mp3dec/src/asm/pvmp3_dct_16_gcc.s
@@ -0,0 +1,476 @@
+@ ------------------------------------------------------------------
+@ Copyright (C) 1998-2009 PacketVideo
+@
+@ Licensed under the Apache License, Version 2.0 (the "License");
+@ you may not use this file except in compliance with the License.
+@ You may obtain a copy of the License at
+@
+@ http://www.apache.org/licenses/LICENSE-2.0
+@
+@ Unless required by applicable law or agreed to in writing, software
+@ distributed under the License is distributed on an "AS IS" BASIS,
+@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+@ express or implied.
+@ See the License for the specific language governing permissions
+@ and limitations under the License.
+@ -------------------------------------------------------------------
+
+@
+@
+@ Filename: pvmp3_dct_16_gcc.s
+@
+@
+@------------------------------------------------------------------------------
+@ REVISION HISTORY
+@
+@
+@ Who: Date: MM/DD/YYYY
+@ Description:
+@
+@------------------------------------------------------------------------------
+
+.arm
+
+.align 4
+
+.text
+
+.extern pvmp3_dct_16
+.extern pvmp3_merge_in_place_N32
+.extern pvmp3_split
+
+
+
+@------------------------------------------------------------------------------
+
+.global pvmp3_dct_16
+
+pvmp3_dct_16:
+ stmfd sp!,{r0,r1,r4-r11,lr}
+ ldr r1,[r0]
+ ldr r3,[r0,#0x3c]
+ ldr r12,constant1
+ sub r2,r1,r3
+ smull lr,r2,r12,r2
+ sub sp,sp,#0x1c
+ str r2,[sp,#0x14]
+ ldr r2,[r0,#0x1c]
+ ldr r12,[r0,#0x20]
+ add r1,r1,r3
+ sub r3,r2,r12
+ ldr lr,constant2
+ mov r3,r3,lsl #3
+ smull r4,r3,lr,r3
+ ldr r6,constant5
+ str r3,[sp]
+ add r3,r2,r12
+ sub r2,r1,r3
+ ldr r12,constant3
+ add r3,r1,r3
+ smull lr,r2,r12,r2
+ ldr r12,[r0,#0x38]
+ ldr r1,[r0,#4]
+ ldr lr,constant4
+ sub r4,r1,r12
+ add r1,r1,r12
+ ldr r12,[r0,#0x18]
+ smull r4,r5,lr,r4
+ ldr lr,[r0,#0x24]
+ ldr r10,constant10
+ sub r4,r12,lr
+ mov r4,r4,lsl #1
+ smull r7,r4,r6,r4
+ add r12,r12,lr
+ add r7,r1,r12
+ sub r12,r1,r12
+ ldr r1,constant6
+ str r4,[sp,#4]
+ smull r12,r4,r1,r12
+ ldr r1,[r0,#8]
+ ldr r12,[r0,#0x34]
+ ldr r6,constant7
+ sub lr,r1,r12
+ smull r8,lr,r6,lr
+ add r1,r1,r12
+ str lr,[sp,#0x10]
+ ldr r12,[r0,#0x14]
+ ldr lr,[r0,#0x28]
+ ldr r8,constant8
+ sub r6,r12,lr
+ mov r6,r6,lsl #1
+ smull r9,r6,r8,r6
+ add r12,r12,lr
+ ldr r9,constant9
+ add r8,r1,r12
+ sub r12,r1,r12
+ smull r12,lr,r9,r12
+ ldr r12,[r0,#0x30]
+ ldr r1,[r0,#0xc]
+ sub r9,r1,r12
+ smull r11,r9,r10,r9
+ add r12,r1,r12
+ str r9,[sp,#0xc]
+ ldr r9,[r0,#0x10]
+ ldr r10,constant11
+ str r9,[sp,#0x18]
+ ldr r1,[r0,#0x2c]
+ sub r9,r9,r1
+ smull r11,r9,r10,r9
+ ldr r10,constant12
+ str r9,[sp,#8]
+ ldr r9,[sp,#0x18]
+ ldr r11,constant14
+ add r9,r9,r1
+ add r1,r12,r9
+ sub r12,r12,r9
+ mov r12,r12,lsl #2
+ smull r9,r12,r10,r12
+ ldr r10,constant13
+ add r9,r3,r1
+ sub r1,r3,r1
+ smull r1,r3,r10,r1
+ sub r1,r7,r8
+ mov r1,r1,lsl #1
+ smull r1,r10,r11,r1
+ add r1,r7,r8
+ add r8,r9,r1
+ sub r7,r9,r1
+ mov r8,r8,asr #1
+ ldr r1,constant15
+ str r8,[r0]
+ smull r7,r8,r1,r7
+ sub r7,r3,r10
+ str r8,[r0,#0x20]
+ mov r7,r7,lsl #1
+ smull r8,r7,r1,r7
+ add r3,r3,r10
+ add r3,r3,r7
+ str r3,[r0,#0x10]
+ sub r3,r2,r12
+ str r7,[r0,#0x30]
+ add r2,r2,r12
+ ldr r7,constant13
+ sub r12,r4,lr
+ mov r3,r3,lsl #1
+ smull r8,r3,r7,r3
+ add lr,r4,lr
+ sub r4,r2,lr
+ mov r12,r12,lsl #2
+ smull r7,r12,r11,r12
+ add lr,lr,r2
+ sub r2,r3,r12
+ mov r2,r2,lsl #1
+ smull r7,r2,r1,r2
+ mov r4,r4,lsl #1
+ add r12,r12,r2
+ add r3,r12,r3
+ smull r7,r4,r1,r4
+ add r12,r3,lr
+ add r3,r3,r4
+ str r3,[r0,#0x18]
+ add r3,r2,r4
+ str r2,[r0,#0x38]
+ str r3,[r0,#0x28]
+ str r12,[r0,#8]
+ ldr r2,[sp,#0x14]
+ ldr r3,[sp,#0]
+ ldr lr,[sp,#4]
+ sub r2,r2,r3
+ ldr r3,constant3
+ mov r2,r2,lsl #1
+ smull r12,r2,r3,r2
+ ldr r3,[sp,#0x14]
+ ldr r12,[sp,#0]
+ ldr r4,constant6
+ add r12,r3,r12
+ ldr r3,[sp,#4]
+ sub lr,r5,lr
+ mov lr,lr,lsl #1
+ add r3,r5,r3
+ smull r5,lr,r4,lr
+ ldr r4,[sp,#0x10]
+ ldr r5,[sp,#0x10]
+ add r4,r4,r6
+ sub r5,r5,r6
+ ldr r6,constant9
+ mov r5,r5,lsl #1
+ smull r7,r5,r6,r5
+ ldr r6,[sp,#8]
+ ldr r9,[sp,#0xc]
+ ldr r10,constant12
+ sub r6,r9,r6
+ mov r6,r6,lsl #3
+ smull r7,r6,r10,r6
+ ldr r8,[sp,#0x20]
+ ldr r7,[sp,#8]
+ cmp r8,#0
+ add r7,r9,r7
+
+ bne no_flag_proc
+ rsb r12,r12,#0
+ rsb r2,r2,#0
+ rsb r3,r3,#0
+ rsb lr,lr,#0
+ rsb r4,r4,#0
+ rsb r5,r5,#0
+ rsb r7,r7,#0
+ rsb r6,r6,#0
+no_flag_proc:
+
+ sub r8,r2,r6
+ add r2,r6,r2
+ sub r6,r12,r7
+ ldr r9,constant13
+ add r12,r12,r7
+ sub r7,r3,r4
+ mov r6,r6,lsl #1
+ mov r8,r8,lsl #1
+ smull r10,r8,r9,r8
+ add r3,r3,r4
+ smull r10,r6,r9,r6
+ sub r4,lr,r5
+ mov r7,r7,lsl #2
+ smull r9,r7,r11,r7
+ add lr,lr,r5
+ sub r5,r6,r7
+ add r6,r6,r7
+ sub r7,r12,r3
+ add r3,r12,r3
+ sub r12,r2,lr
+ mov r4,r4,lsl #2
+ smull r9,r4,r11,r4
+ add lr,r2,lr
+ sub r2,r8,r4
+ mov r2,r2,lsl #1
+ mov r5,r5,lsl #1
+ mov r12,r12,lsl #1
+ mov r7,r7,lsl #1
+ smull r9,r5,r1,r5
+ smull r9,r2,r1,r2
+ add r6,r6,r5
+ smull r9,r7,r1,r7
+ smull r9,r12,r1,r12
+ add r1,r4,r2
+ add r1,r1,r8
+ add lr,lr,r1
+ add r3,r3,lr
+ str r3,[r0,#4]
+ add r3,r6,lr
+ str r3,[r0,#0xc]
+ add r1,r1,r12
+ add r3,r6,r1
+ add r1,r7,r1
+ str r1,[r0,#0x1c]
+ str r3,[r0,#0x14]
+ add r1,r12,r2
+ add r3,r7,r1
+ add r1,r5,r1
+ str r1,[r0,#0x2c]
+ str r3,[r0,#0x24]!
+ add r1,r5,r2
+ str r1,[r0,#0x10]
+ str r2,[r0,#0x18]
+ add sp,sp,#0x24
+ ldmfd sp!,{r4-r11,pc}
+
+
+
+@------------------------------------------------------------------------------
+
+.global pvmp3_merge_in_place_N32
+
+
+
+pvmp3_merge_in_place_N32:
+ stmfd sp!,{r4,lr}
+ ldr r1,[r0,#0x1c]
+ ldr r2,[r0,#0x38]
+ str r1,[r0,#0x38]
+ ldr r1,[r0,#0x18]
+ ldr r3,[r0,#0x30]
+ str r1,[r0,#0x30]
+ ldr r12,[r0,#0x14]
+ ldr r1,[r0,#0x28]
+ str r12,[r0,#0x28]
+ ldr r12,[r0,#0x10]
+ ldr lr,[r0,#0x20]
+ str r12,[r0,#0x20]
+ ldr r12,[r0,#0xc]
+ str r12,[r0,#0x18]
+ ldr r12,[r0,#8]
+ str r12,[r0,#0x10]
+ ldr r12,[r0,#4]
+ str r12,[r0,#8]
+ ldr r4,[r0,#0x40]
+ ldr r12,[r0,#0x44]
+ add r4,r4,r12
+ str r4,[r0,#4]
+ str lr,[r0,#0x40]
+ ldr lr,[r0,#0x48]
+ add r12,lr,r12
+ str r12,[r0,#0xc]
+ ldr r12,[r0,#0x4c]
+ add lr,r12,lr
+ str lr,[r0,#0x14]
+ ldr lr,[r0,#0x24]
+ str lr,[r0,#0x48]
+ ldr lr,[r0,#0x50]
+ add r12,lr,r12
+ str r12,[r0,#0x1c]
+ ldr r12,[r0,#0x54]
+ str r1,[r0,#0x50]
+ add lr,r12,lr
+ str lr,[r0,#0x24]
+ ldr r1,[r0,#0x58]
+ ldr r4,[r0,#0x2c]
+ ldr lr,[r0,#0x34]
+ add r12,r1,r12
+ str r12,[r0,#0x2c]
+ ldr r12,[r0,#0x5c]
+ add r1,r12,r1
+ str r1,[r0,#0x34]
+ str r4,[r0,#0x58]
+ ldr r1,[r0,#0x60]
+ ldr r4,[r0,#0x3c]
+ add r12,r1,r12
+ str r12,[r0,#0x3c]
+ ldr r12,[r0,#0x64]
+ add r1,r12,r1
+ str r1,[r0,#0x44]
+ ldr r1,[r0,#0x68]
+ add r12,r1,r12
+ str r12,[r0,#0x4c]
+ ldr r12,[r0,#0x6c]
+ add r1,r12,r1
+ str r1,[r0,#0x54]
+ ldr r1,[r0,#0x70]
+ str r3,[r0,#0x60]
+ add r12,r1,r12
+ str r12,[r0,#0x5c]
+ ldr r3,[r0,#0x74]
+ add r1,r3,r1
+ str r1,[r0,#0x64]
+ str lr,[r0,#0x68]
+ ldr r1,[r0,#0x78]
+ str r2,[r0,#0x70]
+ add r3,r1,r3
+ str r3,[r0,#0x6c]
+ ldr r2,[r0,#0x7c]
+ add r1,r1,r2
+ str r1,[r0,#0x74]
+ str r4,[r0,#0x78]
+ ldmfd sp!,{r4,pc}
+
+
+@------------------------------------------------------------------------------
+
+.global pvmp3_split
+
+
+pvmp3_split:
+ stmfd sp!,{r4,r5,lr}
+ adr r1,constant16
+ ldr r2,[r1]
+ add r2,r1
+ sub r1,r0,#4
+ mov r3,#3
+loop1:
+ ldr r12,[r0]
+ ldr lr,[r1]
+ ldr r4,[r2],#-4
+ add r5,lr,r12
+ sub r12,lr,r12
+ smull r12,lr,r4,r12
+ str r5,[r1],#-4
+ mov r12,r12,lsr #27
+ add r12,r12,lr,lsl #5
+ str r12,[r0],#4
+ ldr r12,[r0]
+ ldr lr,[r1]
+ ldr r4,[r2],#-4
+ add r5,lr,r12
+ sub r12,lr,r12
+ smull r12,lr,r4,r12
+ str r5,[r1],#-4
+ mov r12,r12,lsr #27
+ add r12,r12,lr,lsl #5
+ str r12,[r0],#4
+ subs r3,r3,#1
+ bne loop1
+ mov r3,#5
+loop2:
+ ldr r12,[r0]
+ ldr lr,[r1]
+ ldr r4,[r2],#-4
+ add r5,lr,r12
+ sub r12,lr,r12
+ mov r12,r12,lsl #1
+ smull lr,r12,r4,r12
+ str r5,[r1],#-4
+ str r12,[r0],#4
+ ldr r12,[r0]
+ ldr lr,[r1]
+ ldr r4,[r2],#-4
+ add r5,lr,r12
+ sub r12,lr,r12
+ mov r12,r12,lsl #1
+ smull lr,r12,r4,r12
+ str r5,[r1],#-4
+ str r12,[r0],#4
+ subs r3,r3,#1
+ bne loop2
+ ldmfd sp!,{r4,r5,pc}
+constant1:
+ .word 0x404f4680
+constant2:
+ .word 0x519e4e00
+constant3:
+ .word 0x4140fb80
+constant4:
+ .word 0x42e13c00
+constant5:
+ .word 0x6e3c9300
+constant6:
+ .word 0x4cf8de80
+constant7:
+ .word 0x48919f80
+constant8:
+ .word 0x43e22480
+constant9:
+ .word 0x73326b80
+constant10:
+ .word 0x52cb0e80
+constant11:
+ .word 0x64e24000
+constant12:
+ .word 0x52036780
+constant13:
+ .word 0x4545ea00
+constant14:
+ .word 0x539eba80
+constant15:
+ .word 0x5a827980
+constant16:
+ .word (CosTable_dct32 + 60)-constant16
+
+
+
+CosTable_dct32:
+ .word 0x4013c280
+ .word 0x40b34580
+ .word 0x41fa2d80
+ .word 0x43f93400
+ .word 0x46cc1c00
+ .word 0x4a9d9d00
+ .word 0x4fae3700
+ .word 0x56601e80
+ .word 0x5f4cf700
+ .word 0x6b6fcf00
+ .word 0x07c7d1d8
+ .word 0x095b0350
+ .word 0x0bdf91b0
+ .word 0x107655e0
+ .word 0x1b42c840
+ .word 0x51852300
+
+
diff --git a/media/codecs/mp3dec/src/asm/pvmp3_dct_9_gcc.s b/media/codecs/mp3dec/src/asm/pvmp3_dct_9_gcc.s
new file mode 100644
index 0000000..618c50e
--- /dev/null
+++ b/media/codecs/mp3dec/src/asm/pvmp3_dct_9_gcc.s
@@ -0,0 +1,193 @@
+@ ------------------------------------------------------------------
+@ Copyright (C) 1998-2009 PacketVideo
+@
+@ Licensed under the Apache License, Version 2.0 (the "License");
+@ you may not use this file except in compliance with the License.
+@ You may obtain a copy of the License at
+@
+@ http://www.apache.org/licenses/LICENSE-2.0
+@
+@ Unless required by applicable law or agreed to in writing, software
+@ distributed under the License is distributed on an "AS IS" BASIS,
+@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+@ express or implied.
+@ See the License for the specific language governing permissions
+@ and limitations under the License.
+@ -------------------------------------------------------------------
+
+@
+@
+@ Filename: pvmp3_dct_9_gcc.s
+@
+@------------------------------------------------------------------------------
+@ REVISION HISTORY
+@
+@
+@ Who: Date: MM/DD/YYYY
+@ Description:
+@
+@------------------------------------------------------------------------------
+
+.arm
+
+.align 4
+
+.text
+
+
+@------------------------------------------------------------------------------
+
+.global pvmp3_dct_9
+
+pvmp3_dct_9:
+ stmfd sp!,{r4-r11,lr}
+ ldr r2, [r0, #0x20]
+ ldr r3, [r0, #0]
+ ldr r12,[r0, #4]
+ add r1,r2,r3
+ sub lr,r2,r3
+ ldr r3,[r0, #0x1c]
+ ldr r4,[r0, #0x18]
+ add r2,r3,r12
+ ldr r5,[r0,#8]
+ sub r3,r3,r12
+ add r12,r4,r5
+ sub r4,r4,r5
+ ldr r5,[r0, #0x14]
+ ldr r7,[r0, #0xc]
+ ldr r9,[r0, #0x10]
+ add r6,r5,r7
+ sub r5,r5,r7
+ add r7,r1,r12
+ add r8,r9,r2
+ add r7,r7,r6
+ add r10,r7,r8
+ rsb r7,r8,r7,asr #1
+ str r7,[r0, #0x18]
+ rsb r2,r9,r2,asr #1
+ str r10,[r0,#0]
+ ldr r11,cos_2pi_9
+ rsb r7,r2,#0
+
+ ldr r10,cos_4pi_9
+ mov r9,r1,lsl #1
+ mov r8,r7
+
+@ vec[4] = fxp_mac32_Q32( vec[4], tmp0<<1, cos_2pi_9)@
+
+ smlal r1,r8,r11,r9
+ ldr r11,cos_pi_9
+ mov r1,r9 @@@@@@ !!!!!!
+
+@ vec[8] = fxp_mac32_Q32( vec[8], tmp0<<1, cos_4pi_9)@
+
+ smlal r1,r7,r10,r9
+
+ mov r1,r12,lsl #1
+
+
+@ vec[2] = fxp_mac32_Q32( vec[2], tmp0<<1, cos_pi_9)@
+
+ smlal r9,r2,r11,r9
+ rsb r9,r10,#0
+ ldr r11,cos_5pi_9
+
+ smlal r12,r2,r9,r1
+
+
+
+@ vec[2] = fxp_mac32_Q32( vec[2], tmp2<<1, cos_5pi_9)@
+
+ ldr r9,cos_2pi_9
+ mov r12,r1 @@@@@@ !!!!!!
+ smlal r12,r8,r11,r1
+
+
+@ vec[8] = fxp_mac32_Q32( vec[8], tmp2<<1, cos_2pi_9)@
+
+ smlal r1,r7,r9,r1
+ mov r1,r6,lsl #1
+ smlal r12,r7,r11,r1
+ and r6,r10,r11,asr #14
+ smlal r12,r8,r6,r1
+ ldr r10,cos_11pi_18
+ add r12,r11,r6
+ smlal r1,r2,r12,r1
+ ldr r9,cos_8pi_9
+ str r2,[r0,#8]
+ mov r1,r5,lsl #1
+
+@ vec[8] = fxp_mac32_Q32( vec[8], tmp3<<1, cos_8pi_9)@
+
+ smull r2,r6,r9,r1
+ str r7,[r0,#0x20]
+ mov r2,r4,lsl #1
+ ldr r7,cos_13pi_18
+ smlal r12,r6,r10,r2
+
+ mov r3,r3,lsl #1
+
+@ vec[5] = fxp_mac32_Q32( vec[5], tmp8<<1, cos_13pi_18)@
+
+ smlal r12,r6,r7,r3
+ add r4,r5,r4
+ mov r12,lr,lsl #1
+ sub lr,r4,lr
+ ldr r7,cos_17pi_18
+ str r8,[r0, #0x10]
+ ldr r4,cos_pi_6
+
+ mov lr,lr,lsl #1
+
+@ vec[1] = fxp_mac32_Q32( vec[1], tmp8<<1, cos_17pi_18)@
+
+ smlal r8,r6,r7,r12
+
+@ vec[3] = fxp_mul32_Q32((tmp5 + tmp6 - tmp8)<<1, cos_pi_6)@
+
+ smull r5,lr,r4,lr
+ str r6,[r0, #4]
+ str lr,[r0, #0xc]
+
+
+@ vec[5] = fxp_mul32_Q32(tmp5<<1, cos_17pi_18)@
+ smull r5,lr,r7,r1
+ rsb r6,r9,#0
+@ vec[5] = fxp_mac32_Q32( vec[5], tmp6<<1, cos_7pi_18)@
+ smlal r5,lr,r6,r2
+@ vec[5] = fxp_mac32_Q32( vec[5], tmp7<<1, cos_pi_6)@
+ smlal r5,lr,r4,r3
+@ vec[5] = fxp_mac32_Q32( vec[5], tmp8<<1, cos_13pi_18)@
+ smlal r5,lr,r10,r12
+ str lr,[r0, #0x14]
+ rsb lr,r10,#0
+
+@ vec[7] = fxp_mul32_Q32(tmp5<<1, cos_5pi_18)@
+ smull r5,r1,lr,r1
+@ vec[7] = fxp_mac32_Q32( vec[7], tmp6<<1, cos_17pi_18)@
+ smlal r2,r1,r7,r2
+@ vec[7] = fxp_mac32_Q32( vec[7], tmp7<<1, cos_pi_6)@
+ smlal r3,r1,r4,r3
+@ vec[7] = fxp_mac32_Q32( vec[7], tmp8<<1, cos_11pi_18)@
+ smlal r12,r1,r9,r12
+ str r1,[r0, #0x1c]
+ ldmfd sp!,{r4-r11,pc}
+cos_2pi_9:
+ .word 0x620dbe80
+cos_4pi_9:
+ .word 0x163a1a80
+cos_pi_9:
+ .word 0x7847d900
+cos_5pi_9:
+ .word 0x87b82700
+cos_8pi_9:
+ .word 0xd438af00
+cos_11pi_18:
+ .word 0xadb92280
+cos_13pi_18:
+ .word 0x91261480
+cos_17pi_18:
+ .word 0x81f1d200
+cos_pi_6:
+ .word 0x6ed9eb80
+
diff --git a/media/codecs/mp3dec/src/asm/pvmp3_mdct_18_gcc.s b/media/codecs/mp3dec/src/asm/pvmp3_mdct_18_gcc.s
new file mode 100644
index 0000000..575acd6
--- /dev/null
+++ b/media/codecs/mp3dec/src/asm/pvmp3_mdct_18_gcc.s
@@ -0,0 +1,357 @@
+@ ------------------------------------------------------------------
+@ Copyright (C) 1998-2009 PacketVideo
+@
+@ Licensed under the Apache License, Version 2.0 (the "License");
+@ you may not use this file except in compliance with the License.
+@ You may obtain a copy of the License at
+@
+@ http://www.apache.org/licenses/LICENSE-2.0
+@
+@ Unless required by applicable law or agreed to in writing, software
+@ distributed under the License is distributed on an "AS IS" BASIS,
+@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+@ express or implied.
+@ See the License for the specific language governing permissions
+@ and limitations under the License.
+@ -------------------------------------------------------------------
+
+@
+@
+@ Filename: pvmp3_dct_18_gcc.s
+@
+@------------------------------------------------------------------------------
+@ REVISION HISTORY
+@
+@
+@ Who: Date: MM/DD/YYYY
+@ Description:
+@
+@------------------------------------------------------------------------------
+
+.arm
+
+.align 4
+
+.text
+
+.extern pvmp3_dct_9
+
+@------------------------------------------------------------------------------
+
+.global pvmp3_mdct_18
+
+pvmp3_mdct_18:
+ stmfd sp!,{r4-r11,lr}
+ mov r7,r2
+ adr r2,constdata$1
+ mov r6,r1
+ add r3,r2,#0x24
+ add r12,r3,#0x44
+ add r1,r0,#0x44
+ mov r5,r0
+
+@ for ( i=9@ i!=0@ i--)
+@ {
+
+ mov r4,#9
+Loop_1:
+
+@ tmp = *(pt_vec)
+@ tmp1 = *(pt_vec_o)
+
+ ldr lr,[r0] @@ tmp == lr
+ ldr r8,[r3],#4 @@ tmp1 == r8
+
+@ tmp = fxp_mul32_Q32( tmp<<1, *(pt_cos++ ))
+@ tmp1 = fxp_mul32_Q27( tmp1, *(pt_cos_x--))
+
+ mov lr,lr,lsl #1
+ smull r10,lr,r8,lr
+ ldr r8,[r12],#-4
+ ldr r9,[r1]
+ subs r4,r4,#1
+ smull r9,r10,r8,r9
+ mov r8,r9,lsr #27
+ add r8,r8,r10,lsl #5
+
+@ *(pt_vec++) = tmp + tmp1
+@ *(pt_vec_o--) = fxp_mul32_Q28( (tmp - tmp1), *(pt_cos_split++))
+
+ add r9,lr,r8
+ sub r8,lr,r8
+ ldr lr,[r2],#4
+ str r9,[r0],#4
+ smull r8,r9,lr,r8
+ mov lr,r8,lsr #28
+ add lr,lr,r9,lsl #4
+ str lr,[r1],#-4
+ bne Loop_1
+
+@ }
+
+ mov r0,r5 @@ r0 = vec
+ bl pvmp3_dct_9
+ add r0,r5,#0x24 @@ r0 = &vec[9]
+ bl pvmp3_dct_9
+
+ ldr r0,[r5,#0x20]
+ ldr r2,[r5,#0x40]
+ str r0,[r5,#0x40]
+ ldr r0,[r5,#0x1c]
+ ldr r3,[r5,#0x38]
+ str r0,[r5,#0x38]
+ ldr r1,[r5,#0x18]
+ ldr r0,[r5,#0x30]
+ str r1,[r5,#0x30]
+ ldr r12,[r5,#0x14]
+ ldr r1,[r5,#0x28]
+ str r12,[r5,#0x28]
+ ldr r12,[r5,#0x10]
+ str r12,[r5,#0x20]
+ ldr r12,[r5,#0xc]
+ str r12,[r5,#0x18]
+ ldr r12,[r5,#8]
+ str r12,[r5,#0x10]
+ ldr r12,[r5,#4]
+ str r12,[r5,#8]
+ ldr r12,[r5,#0x24]
+ sub r12,r12,r1
+ str r12,[r5,#4]
+ ldr r12,[r5,#0x2c]
+ sub r1,r12,r1
+ str r1,[r5,#0xc]
+ sub r1,r12,r0
+ str r1,[r5,#0x14]
+ ldr r1,[r5,#0x34]
+ sub r0,r1,r0
+ str r0,[r5,#0x1c]
+ sub r0,r1,r3
+ str r0,[r5,#0x24]
+ ldr r1,[r5,#0x3c]
+ sub r3,r1,r3
+ sub r1,r1,r2
+ str r1,[r5,#0x34]
+ str r3,[r5,#0x2c]
+ ldr r1,[r5,#0x44]
+ sub r1,r1,r2
+ str r1,[r5,#0x3c]
+ ldr r12,[r5,#0]
+
+Loop_2:
+ add r1,r5,r4,lsl #2
+ ldr r2,[r1,#0x28]
+ ldr r3,[r6,r4,lsl #2]
+ add r0,r0,r2
+ str r0,[r1,#0x28]
+ ldr lr,[r7,r4,lsl #2]
+ ldr r1,[r1,#4]
+ smlal r0,r3,lr,r0
+ mov r0,r2
+ add r2,r12,r1
+ rsb r2,r2,#0
+ str r3,[r5,r4,lsl #2]
+ str r2,[r6,r4,lsl #2]
+ add r4,r4,#1
+ cmp r4,#6
+ mov r12,r1
+
+ blt Loop_2
+
+ ldr r1,[r5,#0x40]
+ ldr r2,[r6,#0x18]
+ add r3,r0,r1
+ str r3,[r5,#0x40]
+ ldr lr,[r7,r4,lsl #2]
+ mov r3,r3,lsl #1
+ ldr r0,[r5,#0x1c]
+ smlal r3,r2,lr,r3
+ add r3,r12,r0
+ str r2,[r5,#0x18]
+ ldr r2,[r6,#0x1c]
+ rsb r3,r3,#0
+ str r3,[r6,#0x18]
+ ldr r3,[r5,#0x20]
+ add r0,r3,r0
+ rsb r0,r0,#0
+ str r0,[r6,#0x1c]
+ ldr r3,[r5,#0x44]
+ ldr r0,[r6,#0x20]
+ add r3,r3,r1
+ mov r1,r2
+ ldr r10,[r7,#0x1c]
+ mov r2,r3,lsl #1
+ smlal r12,r1,r10,r2
+ str r1,[r5,#0x1c]
+ ldr r1,[r5,#0x20]
+ ldr r3,[r5,#0x24]
+ add r1,r1,r3
+ rsb r1,r1,#0
+ str r1,[r6,#0x20]
+ ldr r1,[r5,#0x44]
+ ldr r3,[r7,#0x20]
+ mov r1,r1,lsl #1
+ smlal r12,r0,r3,r1
+ ldr lr,[r7,#0x24]
+ ldr r3,[r6,#0x24]
+ str r0,[r5,#0x20]
+ smlal r1,r3,lr,r1
+ ldr r0,[r6,#0x40]
+ ldr r12,[r6,#0x44]
+ str r3,[r5,#0x24]
+ ldr r1,[r5,#0x28]
+ ldr r3,[r7,#0x44]
+ mov r1,r1,lsl #1
+ smlal r1,r12,r3,r1
+ ldr r1,[r5,#0x40]
+ str r12,[r5,#0x44]
+ rsb r8,r1,#0
+ str r8,[r5,#0x28]
+ ldr r1,[r5,#0x2c]
+ ldr r3,[r7,#0x40]
+ mov r1,r1,lsl #1
+ smlal r1,r0,r3,r1
+ str r0,[r5,#0x40]
+ ldr r0,[r5,#0x3c]
+ ldr r1,[r6,#0x38]
+ ldr r3,[r6,#0x3c]
+ rsb r9,r0,#0
+ str r9,[r5,#0x2c]
+ ldr r0,[r5,#0x30]
+ ldr r12,[r7,#0x3c]
+ mov r0,r0,lsl #1
+ smlal r0,r3,r12,r0
+ str r3,[r5,#0x3c]
+ ldr r0,[r5,#0x38]
+ rsb r0,r0,#0
+ str r0,[r5,#0x30]
+ ldr r3,[r5,#0x34]
+ ldr r12,[r7,#0x38]
+ mov r3,r3,lsl #1
+ smlal r3,r1,r12,r3
+ mov r0,r0,lsl #1
+ str r1,[r5,#0x38]
+ ldr r4,[r7,#0x34]
+ ldr r1,[r6,#0x34]
+ ldr r3,[r6,#0x30]
+ smlal r0,r1,r4,r0
+ ldr r12,[r6,#0x2c]
+ ldr lr,[r6,#0x28]
+ str r1,[r5,#0x34]
+ ldr r1,[r7,#0x30]
+ mov r0,r9,lsl #1
+ smlal r0,r3,r1,r0
+ mov r0,r8,lsl #1
+ ldr r1,[r7,#0x2c]
+ str r3,[r5,#0x30]
+ smlal r0,r12,r1,r0
+ ldr r0,[r7,#0x28]
+ str r12,[r5,#0x2c]
+ smlal r2,lr,r0,r2
+ str lr,[r5,#0x28]
+ ldr r1,[r6,#4]
+ ldr r12,[r7,#0x48]
+ mov r2,r1,lsl #1
+ ldr r1,[r6,#0x20]
+ ldr r0,[r6,#0]
+ mov r1,r1,lsl #1
+ smull r4,lr,r12,r1
+ ldr r3,[r6,#0x1c]
+ str lr,[r6,#0]
+ ldr r12,[r7,#0x4c]
+ mov r3,r3,lsl #1
+ smull r4,lr,r12,r3
+ mov r0,r0,lsl #1
+ ldr r12,[r7,#0x64]
+ str lr,[r6,#4]
+ smull r4,lr,r12,r2
+ ldr r12,[r7,#0x68]
+ str lr,[r6,#0x1c]
+ smull r4,lr,r12,r0
+ ldr r12,[r7,#0x6c]
+ str lr,[r6,#0x20]
+ smull lr,r0,r12,r0
+ ldr r12,[r7,#0x70]
+ str r0,[r6,#0x24]
+ smull r0,r2,r12,r2
+ ldr r0,[r7,#0x88]
+ str r2,[r6,#0x28]
+ smull r3,r2,r0,r3
+ ldr r0,[r7,#0x8c]
+ str r2,[r6,#0x40]
+ smull r2,r1,r0,r1
+ str r1,[r6,#0x44]
+ ldr r0,[r6,#0x18]
+ ldr lr,[r7,#0x50]
+ mov r1,r0,lsl #1
+ ldr r0,[r6,#0x14]
+ smull r5,r4,lr,r1
+ mov r3,r0,lsl #1
+ ldr r0,[r6,#0x10]
+ mov r12,r0,lsl #1
+ ldr r0,[r6,#0xc]
+ mov r2,r0,lsl #1
+ ldr r0,[r6,#8]
+ str r4,[r6,#8]
+ ldr lr,[r7,#0x54]
+ mov r0,r0,lsl #1
+ smull r5,r4,lr,r3
+ ldr lr,[r7,#0x58]
+ str r4,[r6,#0xc]
+ smull r5,r4,lr,r12
+ ldr lr,[r7,#0x5c]
+ str r4,[r6,#0x10]
+ smull r5,r4,lr,r2
+ ldr lr,[r7,#0x60]
+ str r4,[r6,#0x14]
+ smull r5,r4,lr,r0
+ ldr lr,[r7,#0x74]
+ str r4,[r6,#0x18]
+ smull r4,r0,lr,r0
+ ldr lr,[r7,#0x78]
+ str r0,[r6,#0x2c]
+ smull r0,r2,lr,r2
+ ldr r0,[r7,#0x7c]
+ str r2,[r6,#0x30]
+ smull r12,r2,r0,r12
+ ldr r0,[r7,#0x80]
+ str r2,[r6,#0x34]
+ smull r3,r2,r0,r3
+ ldr r0,[r7,#0x84]
+ str r2,[r6,#0x38]
+ smull r2,r1,r0,r1
+ str r1,[r6,#0x3c]
+ ldmfd sp!,{r4-r11,pc}
+
+@------------------------------------------------------------------------------
+
+constdata$1:
+cosTerms_dct18:
+ .word 0x0807d2b0
+ .word 0x08483ee0
+ .word 0x08d3b7d0
+ .word 0x09c42570
+ .word 0x0b504f30
+ .word 0x0df29440
+ .word 0x12edfb20
+ .word 0x1ee8dd40
+ .word 0x5bca2a00
+cosTerms_1_ov_cos_phi:
+ .word 0x400f9c00
+ .word 0x408d6080
+ .word 0x418dcb80
+ .word 0x431b1a00
+ .word 0x4545ea00
+ .word 0x48270680
+ .word 0x4be25480
+ .word 0x50ab9480
+ .word 0x56ce4d80
+ .word 0x05ebb630
+ .word 0x06921a98
+ .word 0x0771d3a8
+ .word 0x08a9a830
+ .word 0x0a73d750
+ .word 0x0d4d5260
+ .word 0x127b1ca0
+ .word 0x1ea52b40
+ .word 0x5bb3cc80
+
diff --git a/media/codecs/mp3dec/src/asm/pvmp3_polyphase_filter_window_gcc.s b/media/codecs/mp3dec/src/asm/pvmp3_polyphase_filter_window_gcc.s
new file mode 100644
index 0000000..1140ed7
--- /dev/null
+++ b/media/codecs/mp3dec/src/asm/pvmp3_polyphase_filter_window_gcc.s
@@ -0,0 +1,233 @@
+@ ------------------------------------------------------------------
+@ Copyright (C) 1998-2009 PacketVideo
+@
+@ Licensed under the Apache License, Version 2.0 (the "License");
+@ you may not use this file except in compliance with the License.
+@ You may obtain a copy of the License at
+@
+@ http://www.apache.org/licenses/LICENSE-2.0
+@
+@ Unless required by applicable law or agreed to in writing, software
+@ distributed under the License is distributed on an "AS IS" BASIS,
+@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+@ express or implied.
+@ See the License for the specific language governing permissions
+@ and limitations under the License.
+@ -------------------------------------------------------------------
+
+@
+@
+@ Filename: pvmp3_polyphase_filter_window.s
+@
+@------------------------------------------------------------------------------
+@ REVISION HISTORY
+@
+@
+@ Who: Date: MM/DD/YYYY
+@ Description:
+@
+@------------------------------------------------------------------------------
+
+.arm
+
+.align 4
+
+.text
+
+.extern pqmfSynthWin
+.hidden pqmfSynthWin
+
+
+
+@------------------------------------------------------------------------------
+
+.global pvmp3_polyphase_filter_window
+
+pvmp3_polyphase_filter_window:
+ stmfd sp!,{r0-r2,r4-r11,lr}
+
+ sub sp,sp,#4
+ adr r2,PolyPh_filter_coeff
+ ldr r1,[r2]
+ add r1,r2
+ ldr r2,[sp,#0xc]
+
+ sub r2,r2,#1
+ mov r10,#1
+ str r2,[sp]
+
+@ Accumulators r9, r11::> Initialization
+
+Loop_j:
+ mov r9, #0x20
+ mov r11, #0x20
+ mov r4, #0x10
+Loop_i:
+ add r2,r4,r10
+ add r3,r0,r2,lsl #2
+ sub r2,r4,r10
+ ldr r5,[r3]
+ ldr lr,[r1]
+ add r12,r0,r2,lsl #2
+ ldr r6,[r12,#0x780]
+ smlal r2,r9,lr,r5
+ smlal r2,r11,lr,r6
+ ldr r2,[r1,#4]
+ ldr r7,[r12,#0x80]
+ smlal r5,r11,r2,r5
+ smull r6,r5,r2,r6
+ sub r9,r9,r5
+ ldr r5,[r1,#8]
+ ldr r8,[r3,#0x700]
+ add r4,r4,#0x200
+ smlal r6,r9,r5,r7
+ smull r6,r2,r5,r8
+ ldr r5,[r1,#0xc]
+ sub r11,r11,r2
+ smlal r8,r9,r5,r8
+ smlal r7,r11,r5,r7
+ ldr r5,[r3,#0x100]
+ ldr r2,[r1,#0x10]
+ ldr r6,[r12,#0x680]
+ smlal lr,r9,r2,r5
+ smlal lr,r11,r2,r6
+ ldr r2,[r1,#0x14]
+ ldr r7,[r12,#0x180]
+ smlal r5,r11,r2,r5
+ smull r6,r5,r2,r6
+ ldr r6,[r1,#0x18]
+ ldr r8,[r3,#0x600]
+ sub r9,r9,r5
+ smlal r5,r9,r6,r7
+ smull r2,r5,r6,r8
+ ldr r6,[r1,#0x1c]
+ sub r11,r11,r5
+ smlal r8,r9,r6,r8
+ ldr r2,[r1,#0x20]
+ ldr r5,[r3,#0x200]
+ smlal r7,r11,r6,r7
+ ldr r6,[r12,#0x580]
+ smlal lr,r9,r2,r5
+ smlal lr,r11,r2,r6
+ ldr r2,[r1,#0x24]
+ ldr r7,[r12,#0x280]
+ smlal r5,r11,r2,r5
+ smull r6,r5,r2,r6
+ ldr r6,[r1,#0x28]
+ ldr r8,[r3,#0x500]
+ sub r9,r9,r5
+ smlal r5,r9,r6,r7
+ smull r2,r5,r6,r8
+ ldr r6,[r1,#0x2c]
+ sub r11,r11,r5
+
+ smlal r8,r9,r6,r8
+ smlal r7,r11,r6,r7
+ ldr r5,[r3,#0x300]
+ ldr r8,[r1,#0x30]
+ ldr r6,[r12,#0x480]
+ smlal r7,r9,r8,r5
+ smlal r7,r11,r8,r6
+ ldr r8,[r1,#0x34]
+ ldr r12,[r12,#0x380]
+ smlal r5,r11,r8,r5
+ smull r6,r5,r8,r6
+ ldr r6,[r1,#0x38]
+
+
+ ldr r3,[r3,#0x400]
+ sub r9,r9,r5
+ smlal r7,r9,r6,r12
+ smull r8,r7,r6,r3
+ cmp r4,#0x210
+ sub r11,r11,r7
+
+ ldr r2,[r1,#0x3c]
+ add r1,r1,#0x40
+ smlal r3,r9,r2,r3
+ smlal r12,r11,r2,r12
+
+ blt Loop_i
+
+ mov r3,r9, asr #6
+ mov r4,r3, asr #15
+ teq r4,r3, asr #31
+ ldr r12,LOW_16BITS
+ ldr r2,[sp]
+ eorne r3,r12,r3,asr #31
+ ldr r4,[sp,#8]
+ mov r2,r10,lsl r2
+ add r4,r4,r2,lsl #1
+ strh r3,[r4]
+
+ mov r3,r11,asr #6
+ mov r4,r3,asr #15
+ teq r4,r3,asr #31
+ eorne r3,r12,r3,asr #31
+ ldr r12,[sp,#0xc]
+ ldr r11,[sp,#8]
+ rsb r2,r2,r12,lsl #5
+ add r2,r11,r2,lsl #1
+ strh r3,[r2]
+
+ add r10,r10,#1
+ cmp r10,#0x10
+ blt Loop_j
+
+@ Accumulators r4, r5 Initialization
+
+ mov r4,#0x20
+ mov r5,#0x20
+ mov r3,#0x10
+PolyPh_filter_loop2:
+ add r2,r0,r3,lsl #2
+ ldr r12,[r2]
+ ldr r8,[r1]
+ ldr r6,[r2,#0x80]
+ smlal r12,r4,r8,r12
+ ldr r12,[r1,#4]
+ ldr r7,[r2,#0x40]
+ smlal r6,r4,r12,r6
+
+ ldr r12,[r1,#8]
+ ldr r6,[r2,#0x180]
+ smlal r7,r5,r12,r7
+ ldr r12,[r2,#0x100]
+ ldr r7,[r1,#0xc]
+ ldr r2,[r2,#0x140]
+ smlal r12,r4,r7,r12
+ ldr r12,[r1,#0x10]
+ add r3,r3,#0x80
+ smlal r6,r4,r12,r6
+ ldr r6,[r1,#0x14]
+ cmp r3,#0x210
+ smlal r2,r5,r6,r2
+ add r1,r1,#0x18
+
+ blt PolyPh_filter_loop2
+ mov r0,r4,asr #6
+ mov r2,r0,asr #15
+ teq r2,r0,asr #31
+ ldrne r12,LOW_16BITS
+ ldr r1,[sp,#8]
+ eorne r0,r12,r0,asr #31
+ strh r0,[r1,#0]
+ mov r0,r5,asr #6
+ mov r2,r0,asr #15
+ teq r2,r0,asr #31
+ ldrne r12,LOW_16BITS
+ ldr r2,[sp]
+ mov r1,#0x10
+ eorne r0,r12,r0,asr #31
+ ldr r12,[sp,#8]
+ mov r1,r1,lsl r2
+ add r1,r12,r1,lsl #1
+ strh r0,[r1]
+ add sp,sp,#0x10
+ ldmfd sp!,{r4-r11,pc}
+
+PolyPh_filter_coeff:
+ .word pqmfSynthWin-PolyPh_filter_coeff
+LOW_16BITS:
+ .word 0x00007fff
+
diff --git a/media/codecs/mp3dec/src/mp3_mem_funcs.h b/media/codecs/mp3dec/src/mp3_mem_funcs.h
new file mode 100644
index 0000000..46e8022
--- /dev/null
+++ b/media/codecs/mp3dec/src/mp3_mem_funcs.h
@@ -0,0 +1,81 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: mp3_mem_funcs.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+------------------------------------------------------------------------------
+
+
+----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+
+#ifndef MP3_MEM_FUNCS_H
+#define MP3_MEM_FUNCS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include <string.h>
+
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES AND SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+
+#define pv_memset(to, c, n) memset(to, c, n)
+
+
+#define pv_memcpy(to, from, n) memcpy(to, from, n)
+#define pv_memmove(to, from, n) memmove(to, from, n)
+#define pv_memcmp(p, q, n) memcmp(p, q, n)
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+
+#endif
diff --git a/media/codecs/mp3dec/src/pv_mp3_huffman.h b/media/codecs/mp3dec/src/pv_mp3_huffman.h
new file mode 100644
index 0000000..31102ea
--- /dev/null
+++ b/media/codecs/mp3dec/src/pv_mp3_huffman.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pv_mp3_huffman.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+*/
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+
+#ifndef PV_MP3_HUFFMAN_H
+#define PV_MP3_HUFFMAN_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "s_mp3bits.h"
+#include "s_tmp3dec_file.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES AND SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int32 pvmp3_huffman_parsing(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ granuleInfo *grInfo,
+ tmp3dec_file *pVars,
+ int32 part2_start,
+ mp3Header *info);
+
+
+ void pvmp3_huffman_quad_decoding(struct huffcodetab *h,
+ int32 *is,
+ tmp3Bits *pMainData);
+
+ void pvmp3_huffman_pair_decoding(struct huffcodetab *h,
+ int32 *is,
+ tmp3Bits *pMainData);
+
+
+ void pvmp3_huffman_pair_decoding_linbits(struct huffcodetab *h,
+ int32 *is,
+ tmp3Bits *pMainData);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
+
+
diff --git a/media/codecs/mp3dec/src/pv_mp3dec_fxd_op.h b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op.h
new file mode 100644
index 0000000..f14e2de
--- /dev/null
+++ b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op.h
@@ -0,0 +1,84 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pv_mp3dec_fxd_op.h
+
+ Date: 09/21/2007
+
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file select the associated fixed point functions with the OS/ARCH.
+
+
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PV_MP3DEC_FXD_OP_H
+#define PV_MP3DEC_FXD_OP_H
+
+#include "pvmp3_audio_type_defs.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
+
+#include "pv_mp3dec_fxd_op_arm.h"
+
+#elif (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
+
+#include "pv_mp3dec_fxd_op_arm_gcc.h"
+
+#elif (defined(PV_ARM_MSC_EVC_V5)||defined(PV_ARM_MSC_EVC_V4))
+
+#include "pv_mp3dec_fxd_op_msc_evc.h"
+
+#else
+
+#ifndef C_EQUIVALENT
+#define C_EQUIVALENT
+#endif
+
+#include "pv_mp3dec_fxd_op_c_equivalent.h"
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+#endif /* PV_MP3DEC_FXD_OP_H */
diff --git a/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_arm.h b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_arm.h
new file mode 100644
index 0000000..76a8229
--- /dev/null
+++ b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_arm.h
@@ -0,0 +1,203 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Pathname: ./cpp/include/pv_mp3dec_fxd_op_arm.h
+
+ Date: 08/20/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file select the associated fixed point functions with the OS/ARCH.
+
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PV_MP3DEC_FXD_OP_ARM
+#define PV_MP3DEC_FXD_OP_ARM
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "pvmp3_audio_type_defs.h"
+
+
+#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
+
+
+ __inline Int32 fxp_mul32_Q30(const Int32 L_var1, const Int32 L_var2)
+ {
+
+ Int32 result64_hi;
+ Int32 result64_lo;
+ __asm
+ {
+ smull result64_lo, result64_hi, L_var2, L_var1
+ mov result64_lo, result64_lo, lsr #30
+ add result64_hi, result64_lo, result64_hi, asl #2
+ }
+ return (result64_hi);
+ }
+
+ __inline Int32 fxp_mac32_Q30(const Int32 L_var1, const Int32 L_var2, Int32 L_add)
+ {
+ Int32 result64_hi;
+ Int32 result64_lo;
+ __asm
+ {
+ smull result64_lo, result64_hi, L_var2, L_var1
+ add L_add, L_add, result64_hi, asl #2
+ add L_add, L_add, result64_lo, lsr #30
+ }
+ return (L_add);
+ }
+
+
+
+#define Qfmt_31(a) (Int32)(a*0x7FFFFFFF + (a>=0?0.5F:-0.5F))
+
+
+
+ __inline Int32 fxp_mul32_Q32(Int32 L_var1, const Int32 L_var2)
+ {
+ Int32 result64_hi;
+ __asm
+ {
+ smull L_var1, result64_hi, L_var2, L_var1
+ }
+ return (result64_hi);
+ }
+
+ __inline Int32 fxp_mul32_Q28(const Int32 L_var1, const Int32 L_var2)
+ {
+
+ Int32 result64_hi;
+ Int32 result64_lo;
+ __asm
+ {
+ smull result64_lo, result64_hi, L_var2, L_var1
+ mov result64_lo, result64_lo, lsr #28
+ add result64_hi, result64_lo, result64_hi, asl #4
+ }
+ return (result64_hi);
+ }
+
+
+ __inline Int32 fxp_mul32_Q27(const Int32 L_var1, const Int32 L_var2)
+ {
+
+ Int32 result64_hi;
+ Int32 result64_lo;
+ __asm
+ {
+ smull result64_lo, result64_hi, L_var2, L_var1
+ mov result64_lo, result64_lo, lsr #27
+ add result64_hi, result64_lo, result64_hi, asl #5
+ }
+ return (result64_hi);
+ }
+
+
+ __inline Int32 fxp_mul32_Q26(Int32 L_var1, Int32 L_var2)
+ {
+
+ Int32 result64_hi;
+ Int32 result64_lo;
+ __asm
+ {
+ smull result64_lo, result64_hi, L_var2, L_var1
+ mov result64_lo, result64_lo, lsr #26
+ add result64_hi, result64_lo, result64_hi, asl #6
+ }
+ return (result64_hi);
+ }
+
+
+
+ __inline Int32 fxp_mac32_Q32(Int32 L_add, Int32 L_var1, const Int32 L_var2)
+ {
+ __asm
+ {
+ smlal L_var1, L_add, L_var2, L_var1
+ }
+ return L_add;
+ }
+
+
+ __inline Int32 fxp_msb32_Q32(Int32 L_sub, Int32 L_var1, Int32 L_var2)
+ {
+
+ __asm
+ {
+ smull L_var2, L_var1, L_var2, L_var1
+ sub L_sub, L_sub, L_var1
+ }
+ return L_sub;
+ }
+
+
+ __inline Int32 fxp_mul32_Q29(const Int32 L_var1, const Int32 L_var2)
+ {
+ Int32 result64_hi;
+ Int32 result64_lo;
+ __asm
+ {
+ smull result64_lo, result64_hi, L_var2, L_var1
+ mov result64_lo, result64_lo, lsr #29
+ add result64_hi, result64_lo, result64_hi, asl #3
+ }
+ return (result64_hi);
+ }
+
+
+ __inline int32 pv_abs(int32 a)
+ {
+ Int32 b;
+ /*
+ b = a - (a<0);
+ a = b ^ sign(b)
+ */
+ __asm
+ {
+ sub b, a, a, lsr #31
+ eor a, b, b, asr #31
+ }
+ return (a);
+ }
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* PV_MP3DEC_FXD_OP_ARM */
+
diff --git a/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_arm_gcc.h b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_arm_gcc.h
new file mode 100644
index 0000000..71fbd20
--- /dev/null
+++ b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_arm_gcc.h
@@ -0,0 +1,252 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Pathname: ./cpp/include/pv_mp3dec_fxd_op_arm_gcc.h
+
+ Date: 08/20/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file select the associated fixed point functions with the OS/ARCH.
+
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PV_MP3DEC_FXD_OP_ARM_GCC_H
+#define PV_MP3DEC_FXD_OP_ARM_GCC_H
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "pvmp3_audio_type_defs.h"
+
+
+#if (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
+
+#define Qfmt_31(a) (int32)(a*0x7FFFFFFF + (a>=0?0.5F:-0.5F))
+
+#define Qfmt15(x) (Int16)(x*((int32)1<<15) + (x>=0?0.5F:-0.5F))
+
+ static inline int32 fxp_mul32_Q30(const int32 a, const int32 b)
+ {
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "mov %1, %1, lsr #30\n\t"
+ "add %0, %1, %0, asl #2"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb));
+ return (result64_hi);
+ }
+
+
+ static inline int32 fxp_mac32_Q30(const int32 a, const int32 b, int32 L_add)
+{
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ register int32 rc = (int32)L_add;
+
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "add %4, %4, %0, asl #2\n\t"
+ "add %0, %4, %1, lsr #30"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb),
+ "r"(rc));
+
+ return (result64_hi);
+ }
+
+
+
+ static inline int32 fxp_mul32_Q32(const int32 a, const int32 b)
+{
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ asm volatile(
+ "smull %1, %0, %2, %3"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb));
+
+ return (result64_hi);
+ }
+
+
+ static inline int32 fxp_mul32_Q29(const int32 a, const int32 b)
+{
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "mov %1, %1, lsr #29\n\t"
+ "add %0, %1, %0, asl #3"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb));
+ return (result64_hi);
+
+ }
+
+ static inline int32 fxp_mul32_Q28(const int32 a, const int32 b)
+{
+
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "mov %1, %1, lsr #28\n\t"
+ "add %0, %1, %0, asl #4"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb));
+ return (result64_hi);
+
+ }
+
+
+ static inline int32 fxp_mul32_Q27(const int32 a, const int32 b)
+{
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "mov %1, %1, lsr #27\n\t"
+ "add %0, %1, %0, asl #5"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb));
+ return (result64_hi);
+
+ }
+
+
+ static inline int32 fxp_mul32_Q26(const int32 a, const int32 b)
+{
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "mov %1, %1, lsr #26\n\t"
+ "add %0, %1, %0, asl #6"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb));
+ return (result64_hi);
+
+ }
+
+
+
+ static inline int32 fxp_mac32_Q32(int32 L_add, const int32 a, const int32 b)
+{
+
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ register int32 rc = (int32)L_add;
+
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "add %0, %0, %4"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb),
+ "r"(rc));
+
+ return (result64_hi);
+ }
+
+ static inline int32 fxp_msb32_Q32(int32 L_sub, const int32 a, const int32 b)
+{
+ int32 result64_hi;
+ int32 result64_lo;
+ register int32 ra = (int32)a;
+ register int32 rb = (int32)b;
+ register int32 rc = (int32)L_sub;
+
+ asm volatile("smull %1, %0, %2, %3\n\t"
+ "sub %0, %4, %0"
+ : "=&r*i"(result64_hi),
+ "=&r*i"(result64_lo)
+ : "r"(ra),
+ "r"(rb),
+ "r"(rc));
+
+
+ return (result64_hi);
+ }
+
+
+ __inline int32 pv_abs(int32 x)
+{
+ register int32 z;
+ register int32 y;
+ register int32 ra = x;
+ asm volatile(
+ "sub %0, %2, %2, lsr #31\n\t"
+ "eor %1, %0, %0, asr #31"
+ : "=&r*i"(z),
+ "=&r*i"(y)
+ : "r"(ra));
+
+ return (y);
+ }
+
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* PV_MP3DEC_FXD_OP_ARM_GCC_H */
+
diff --git a/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_c_equivalent.h b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_c_equivalent.h
new file mode 100644
index 0000000..f9d91b1
--- /dev/null
+++ b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_c_equivalent.h
@@ -0,0 +1,133 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Pathname: ./cpp/include/pv_mp3dec_fxd_op_c_equivalent.h
+
+ Date: 12/06/2005
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PV_MP3DEC_FXD_OP_C_EQUIVALENT
+#define PV_MP3DEC_FXD_OP_C_EQUIVALENT
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "pvmp3_audio_type_defs.h"
+#define Qfmt_31(a) (Int32)((float)(a)*(float)0x7FFFFFFF)
+
+#define Qfmt15(x) (Int16)((x)*((Int32)1<<15) + ((x)>=0?0.5F:-0.5F))
+
+
+
+ __attribute__((no_sanitize("integer")))
+ __inline int32 pv_abs(int32 a)
+ {
+ int32 b = (a < 0) ? -a : a;
+ return b;
+ }
+
+
+
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mul32_Q30(const Int32 a, const Int32 b)
+ {
+ return (Int32)(((int64)(a) * b) >> 30);
+ }
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mac32_Q30(const Int32 a, const Int32 b, Int32 L_add)
+ {
+ return (L_add + (Int32)(((int64)(a) * b) >> 30));
+ }
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mul32_Q32(const Int32 a, const Int32 b)
+ {
+ return (Int32)(((int64)(a) * b) >> 32);
+ }
+
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mul32_Q28(const Int32 a, const Int32 b)
+ {
+ return (Int32)(((int64)(a) * b) >> 28);
+ }
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mul32_Q27(const Int32 a, const Int32 b)
+ {
+ return (Int32)(((int64)(a) * b) >> 27);
+ }
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mul32_Q26(const Int32 a, const Int32 b)
+ {
+ return (Int32)(((int64)(a) * b) >> 26);
+ }
+
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mac32_Q32(Int32 L_add, const Int32 a, const Int32 b)
+ {
+ return (L_add + (Int32)(((int64)(a) * b) >> 32));
+ }
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_msb32_Q32(Int32 L_sub, const Int32 a, const Int32 b)
+ {
+ return (L_sub - ((Int32)(((int64)(a) * b) >> 32)));
+ }
+
+
+ __attribute__((no_sanitize("integer")))
+ __inline Int32 fxp_mul32_Q29(const Int32 a, const Int32 b)
+ {
+ return (Int32)(((int64)(a) * b) >> 29);
+ }
+
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* PV_MP3DEC_FXD_OP_C_EQUIVALENT */
+
+
+
diff --git a/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_msc_evc.h b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_msc_evc.h
new file mode 100644
index 0000000..271e6b7
--- /dev/null
+++ b/media/codecs/mp3dec/src/pv_mp3dec_fxd_op_msc_evc.h
@@ -0,0 +1,132 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Pathname: ./cpp/include/pv_mp3dec_fxd_op_msc_evc.h
+
+ Date: 08/20/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This file select the associated fixed point functions with the OS/ARCH.
+
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PV_MP3DEC_FXD_OP_MSC_EVC_H
+#define PV_MP3DEC_FXD_OP_MSC_EVC_H
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "pvmp3_audio_type_defs.h"
+
+
+#if (defined(PV_ARM_MSC_EVC_V5)||defined(PV_ARM_MSC_EVC_V4))
+#include "armintr.h"
+#include "cmnintrin.h"
+
+
+ __inline int32 fxp_mul32_Q30(const int32 a, const int32 b)
+ {
+ return (int32)(((int64)(a) * b) >> 30);
+ }
+
+
+ __inline int32 fxp_mac32_Q30(const int32 a, const int32 b, int32 L_add)
+ {
+ return (L_add + (int32)(((int64)(a) * b) >> 30));
+ }
+
+
+#define Qfmt_31(a) (int32)(a*0x7FFFFFFF + (a>=0?0.5F:-0.5F))
+
+#define Qfmt15(x) (Int16)(x*((int32)1<<15) + (x>=0?0.5F:-0.5F))
+
+#define fxp_mul32_Q32( a, b) _MulHigh( b, a)
+
+
+
+ __inline int32 fxp_mul32_Q28(const int32 a, const int32 b)
+ {
+ return (int32)(((int64)(a) * b) >> 28);
+ }
+
+
+ __inline int32 fxp_mul32_Q27(const int32 a, const int32 b)
+ {
+ return (int32)(((int64)(a) * b) >> 27);
+ }
+
+
+
+ __inline int32 fxp_mul32_Q26(const int32 a, const int32 b)
+ {
+ return (int32)(((int64)(a) * b) >> 26);
+ }
+
+
+ __inline int32 fxp_mac32_Q32(int32 L_add, const int32 a, const int32 b)
+ {
+ return (L_add + _MulHigh(b, a));
+ }
+
+
+ __inline int32 fxp_msb32_Q32(int32 L_sub, const int32 a, const int32 b)
+ {
+ return (L_sub - _MulHigh(b, a));
+ }
+
+
+
+ __inline int32 fxp_mul32_Q29(const int32 a, const int32 b)
+ {
+ return (int32)(((int64)(a) * b) >> 29);
+ }
+
+
+
+ __inline int32 pv_abs(int32 a)
+ {
+ int32 b = (a < 0) ? -a : a;
+ return b;
+ }
+
+
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* PV_MP3DEC_FXD_OP_MSC_EVC_H */
+
diff --git a/media/codecs/mp3dec/src/pvmp3_alias_reduction.cpp b/media/codecs/mp3dec/src/pvmp3_alias_reduction.cpp
new file mode 100644
index 0000000..6c8102b
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_alias_reduction.cpp
@@ -0,0 +1,261 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_alias_reduction.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ int32 *input_buffer, Ptr to fequency lines of current channel
+ struct gr_info_s *gr_info, structure with granuke information for the
+ input
+ mp3Header *info mp3 header information
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Alias Reduction
+
+
+
+ Alias reduction before processing by the IMDCT
+
+ Csi +
+ >---------0---------0-------->
+ \ / -
+ Cai \ /
+ \ /
+ \ /
+ \
+ / \
+ Cai / \
+ / \ +
+ >--------0---------0---------->
+ Csi +
+
+ Aliasing Butterfly
+ Alias reduction is not applied to short blocks
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+ 1 ci
+ csi = ---------------- csi = ----------------
+ sqrt( 1 + (ci^2)) sqrt( 1 + (ci^2))
+
+
+ ci = -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037
+
+ ------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_alias_reduction.h"
+#include "pv_mp3dec_fxd_op.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define NUM_BUTTERFLIES 8
+
+#define Q31_fmt(a) (int32(double(0x7FFFFFFF)*(a)))
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int32 c_signal [ NUM_BUTTERFLIES ] =
+{
+
+ Q31_fmt(0.85749292571254f), Q31_fmt(0.88174199731771f),
+ Q31_fmt(0.94962864910273f), Q31_fmt(0.98331459249179f),
+ Q31_fmt(0.99551781606759f), Q31_fmt(0.99916055817815f),
+ Q31_fmt(0.99989919524445f), Q31_fmt(0.99999315507028f)
+
+};
+
+
+const int32 c_alias [ NUM_BUTTERFLIES ] =
+{
+
+ Q31_fmt(-0.51449575542753f), Q31_fmt(-0.47173196856497f),
+ Q31_fmt(-0.31337745420390f), Q31_fmt(-0.18191319961098f),
+ Q31_fmt(-0.09457419252642f), Q31_fmt(-0.04096558288530f),
+ Q31_fmt(-0.01419856857247f), Q31_fmt(-0.00369997467376f)
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_alias_reduction(int32 *input_buffer, /* Ptr to spec values of current channel */
+ granuleInfo *gr_info,
+ int32 *used_freq_lines,
+ mp3Header *info)
+{
+ int32 *ptr1;
+ int32 *ptr2;
+ int32 *ptr3;
+ int32 *ptr4;
+ const int32 *ptr_csi;
+ const int32 *ptr_csa;
+ int32 sblim;
+
+ int32 i, j;
+
+ *used_freq_lines = fxp_mul32_Q32(*used_freq_lines << 16, (int32)((float)0x7FFFFFFF / (float)18 - 1.0f)) >> 15;
+
+
+ if (gr_info->window_switching_flag && gr_info->block_type == 2)
+ {
+ if (gr_info->mixed_block_flag)
+ {
+ sblim = ((info->version_x == MPEG_2_5) && (info->sampling_frequency == 2)) ? 3 : 1;
+ }
+ else
+ {
+ return; /* illegal parameter */
+ }
+ }
+ else
+ {
+ sblim = *used_freq_lines + 1;
+
+ if (sblim > SUBBANDS_NUMBER - 1)
+ {
+ sblim = SUBBANDS_NUMBER - 1; /* default */
+ }
+
+ }
+
+
+ ptr3 = &input_buffer[17];
+ ptr4 = &input_buffer[18];
+ ptr_csi = c_signal;
+ ptr_csa = c_alias;
+
+ /* NUM_BUTTERFLIES (=8) butterflies between each pair of sub-bands*/
+
+ for (i = NUM_BUTTERFLIES >> 1; i != 0; i--)
+ {
+ int32 csi1 = *ptr_csi++;
+ int32 csi2 = *ptr_csi++;
+ int32 csa1 = *ptr_csa++;
+ int32 csa2 = *ptr_csa++;
+
+ ptr1 = ptr3;
+ ptr3 -= 2;
+ ptr2 = ptr4;
+ ptr4 += 2;
+
+ /*
+ * "sblim" alias-reduction operations between each
+ * pair of sub-bands
+ */
+
+ for (j = sblim >> 1; j != 0; j--)
+ {
+ int32 y = *ptr2;
+ int32 x = *ptr1 << 1;
+ *ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
+ *ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
+ y = *ptr2;
+ x = *ptr1 << 1;
+ *ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
+ *ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
+ ptr1 += 19;
+ ptr2 += 17;
+ y = *ptr2;
+ x = *ptr1 << 1;
+ *ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
+ *ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
+ y = *ptr2;
+ x = *ptr1 << 1;
+ *ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
+ *ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
+ ptr1 += 19;
+ ptr2 += 17;
+
+ }
+
+ if (sblim & 1)
+ {
+ int32 x = *ptr1 << 1;
+ int32 y = *ptr2;
+ *ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
+ *ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
+
+ x = *ptr1 << 1;
+ y = *ptr2;
+ *ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
+ *ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
+ }
+ }
+
+}
diff --git a/media/codecs/mp3dec/src/pvmp3_alias_reduction.h b/media/codecs/mp3dec/src/pvmp3_alias_reduction.h
new file mode 100644
index 0000000..2292d5f
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_alias_reduction.h
@@ -0,0 +1,100 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_alias_reduction.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_ALIAS_REDUCTION_H
+#define PVMP3_ALIAS_REDUCTION_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_alias_reduction(int32 *input_buffer,
+ granuleInfo *gr_info,
+ int32 *used_freq_lines,
+ mp3Header *info);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_crc.cpp b/media/codecs/mp3dec/src/pvmp3_crc.cpp
new file mode 100644
index 0000000..20d0d82
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_crc.cpp
@@ -0,0 +1,161 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_crc.cpp
+
+ Functions:
+ getbits_crc
+ calculate_crc
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+getbits_crc
+
+Input
+ tbits *inputStream, bit stream structure
+ int32 neededBits, number of bits to read from the bit stream
+ uint32 *crc, memory location holding calculated crc value
+ uint32 crc_enabled flag to enable/disable crc checking
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+calculate_crc
+
+Input
+ uint32 data, data vector
+ uint32 length, number of element upon the crc will be calculated
+ uint32 *crc, memory location holding calculated crc value
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+ ------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_getbits.h"
+#include "pvmp3_crc.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+uint32 getbits_crc(tmp3Bits *inputStream, /* bit stream structure */
+ int32 neededBits, /* number of bits to read from the bit stream */
+ uint32 *crc,
+ uint32 crc_enabled)
+{
+ uint32 bits = getNbits(inputStream, neededBits);
+
+ if (crc_enabled)
+ {
+ calculate_crc(bits, neededBits, crc);
+ }
+ return(bits);
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void calculate_crc(uint32 data,
+ uint32 length,
+ uint32 *crc)
+{
+ uint32 carry;
+ uint32 masking = 1 << length;
+
+ while ((masking >>= 1))
+ {
+ carry = *crc & 0x8000;
+ *crc <<= 1;
+ if (!carry ^ !(data & masking))
+ {
+ *crc ^= CRC16_POLYNOMIAL;
+ }
+ }
+ *crc &= 0xffff;
+}
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_crc.h b/media/codecs/mp3dec/src/pvmp3_crc.h
new file mode 100644
index 0000000..b7c277a
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_crc.h
@@ -0,0 +1,110 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_crc.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_CRC_H
+#define PVMP3_CRC_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+#include "s_mp3bits.h"
+#include "pvmp3decoder_api.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define CRC16_POLYNOMIAL 0x8005
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ uint32 getbits_crc(tmp3Bits *inputStream,
+ int32 neededBits,
+ uint32 *crc,
+ uint32 crc_enabled);
+
+
+ void calculate_crc(uint32 data,
+ uint32 length,
+ uint32 *crc);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_dct_16.cpp b/media/codecs/mp3dec/src/pvmp3_dct_16.cpp
new file mode 100644
index 0000000..cc99d5c
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_dct_16.cpp
@@ -0,0 +1,413 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_dct_16.cpp
+
+ Functions:
+ dct_16
+ pv_merge_in_place_N32
+ pv_split
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ dct_16
+
+Input
+ int32 vec[], input vector length 16
+ Int flag processing direction: forward (1), backward ( 0)
+ Returns
+
+ int32 vec[], dct length 16
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ pv_merge_in_place_N32
+
+Input
+ int32 vec[], input vector length 16
+
+ Returns
+
+ int32 vec[], merged output of two dct 16 to create a dct 32
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ pv_split
+
+Input
+ int32 vec[], input vector length 16
+
+ Returns
+
+ int32 vec[], splitted even/odd and pre processing rotation
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ dct 16 and tools to assemble a dct32 output
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) )
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dct_16.h"
+#include "pv_mp3dec_fxd_op.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define Qfmt(a) (int32)((a)*((int32)1<<27))
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int32 CosTable_dct32[16] =
+{
+ Qfmt_31(0.50060299823520F) , Qfmt_31(0.50547095989754F) ,
+ Qfmt_31(0.51544730992262F) , Qfmt_31(0.53104259108978F) ,
+ Qfmt_31(0.55310389603444F) , Qfmt_31(0.58293496820613F) ,
+ Qfmt_31(0.62250412303566F) , Qfmt_31(0.67480834145501F) ,
+ Qfmt_31(0.74453627100230F) , Qfmt_31(0.83934964541553F) ,
+
+ Qfmt(0.97256823786196F) , Qfmt(1.16943993343288F) ,
+ Qfmt(1.48416461631417F) , Qfmt(2.05778100995341F) ,
+ Qfmt(3.40760841846872F) , Qfmt(10.19000812354803F)
+};
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+__attribute__((no_sanitize("integer")))
+void pvmp3_dct_16(int32 vec[], int32 flag)
+{
+ int32 tmp0;
+ int32 tmp1;
+ int32 tmp2;
+ int32 tmp3;
+ int32 tmp4;
+ int32 tmp5;
+ int32 tmp6;
+ int32 tmp7;
+ int32 tmp_o0;
+ int32 tmp_o1;
+ int32 tmp_o2;
+ int32 tmp_o3;
+ int32 tmp_o4;
+ int32 tmp_o5;
+ int32 tmp_o6;
+ int32 tmp_o7;
+ int32 itmp_e0;
+ int32 itmp_e1;
+ int32 itmp_e2;
+
+ /* split input vector */
+
+ tmp_o0 = fxp_mul32_Q32((vec[ 0] - vec[15]), Qfmt_31(0.50241928618816F));
+ tmp0 = vec[ 0] + vec[15];
+
+ tmp_o7 = fxp_mul32_Q32((vec[ 7] - vec[ 8]) << 3, Qfmt_31(0.63764357733614F));
+ tmp7 = vec[ 7] + vec[ 8];
+
+ itmp_e0 = fxp_mul32_Q32((tmp0 - tmp7), Qfmt_31(0.50979557910416F));
+ tmp7 = (tmp0 + tmp7);
+
+ tmp_o1 = fxp_mul32_Q32((vec[ 1] - vec[14]), Qfmt_31(0.52249861493969F));
+ tmp1 = vec[ 1] + vec[14];
+
+ tmp_o6 = fxp_mul32_Q32((vec[ 6] - vec[ 9]) << 1, Qfmt_31(0.86122354911916F));
+ tmp6 = vec[ 6] + vec[ 9];
+
+
+
+ itmp_e1 = (tmp1 + tmp6);
+ tmp6 = fxp_mul32_Q32((tmp1 - tmp6), Qfmt_31(0.60134488693505F));
+
+
+
+ tmp_o2 = fxp_mul32_Q32((vec[ 2] - vec[13]), Qfmt_31(0.56694403481636F));
+ tmp2 = vec[ 2] + vec[13];
+ tmp_o5 = fxp_mul32_Q32((vec[ 5] - vec[10]) << 1, Qfmt_31(0.53033884299517F));
+ tmp5 = vec[ 5] + vec[10];
+
+ itmp_e2 = (tmp2 + tmp5);
+ tmp5 = fxp_mul32_Q32((tmp2 - tmp5), Qfmt_31(0.89997622313642F));
+
+ tmp_o3 = fxp_mul32_Q32((vec[ 3] - vec[12]), Qfmt_31(0.64682178335999F));
+ tmp3 = vec[ 3] + vec[12];
+ tmp_o4 = fxp_mul32_Q32((vec[ 4] - vec[11]), Qfmt_31(0.78815462345125F));
+ tmp4 = vec[ 4] + vec[11];
+
+ tmp1 = (tmp3 + tmp4);
+ tmp4 = fxp_mul32_Q32((tmp3 - tmp4) << 2, Qfmt_31(0.64072886193538F));
+
+ /* split even part of tmp_e */
+
+ tmp0 = (tmp7 + tmp1);
+ tmp1 = fxp_mul32_Q32((tmp7 - tmp1), Qfmt_31(0.54119610014620F));
+
+ tmp3 = fxp_mul32_Q32((itmp_e1 - itmp_e2) << 1, Qfmt_31(0.65328148243819F));
+ tmp7 = (itmp_e1 + itmp_e2);
+
+ vec[ 0] = (tmp0 + tmp7) >> 1;
+ vec[ 8] = fxp_mul32_Q32((tmp0 - tmp7), Qfmt_31(0.70710678118655F));
+ tmp0 = fxp_mul32_Q32((tmp1 - tmp3) << 1, Qfmt_31(0.70710678118655F));
+ vec[ 4] = tmp1 + tmp3 + tmp0;
+ vec[12] = tmp0;
+
+ /* split odd part of tmp_e */
+
+ tmp1 = fxp_mul32_Q32((itmp_e0 - tmp4) << 1, Qfmt_31(0.54119610014620F));
+ tmp7 = itmp_e0 + tmp4;
+
+ tmp3 = fxp_mul32_Q32((tmp6 - tmp5) << 2, Qfmt_31(0.65328148243819F));
+ tmp6 += tmp5;
+
+ tmp4 = fxp_mul32_Q32((tmp7 - tmp6) << 1, Qfmt_31(0.70710678118655F));
+ tmp6 += tmp7;
+ tmp7 = fxp_mul32_Q32((tmp1 - tmp3) << 1, Qfmt_31(0.70710678118655F));
+
+ tmp1 += tmp3 + tmp7;
+ vec[ 2] = tmp1 + tmp6;
+ vec[ 6] = tmp1 + tmp4;
+ vec[10] = tmp7 + tmp4;
+ vec[14] = tmp7;
+
+
+ // dct8;
+
+ tmp1 = fxp_mul32_Q32((tmp_o0 - tmp_o7) << 1, Qfmt_31(0.50979557910416F));
+ tmp7 = tmp_o0 + tmp_o7;
+
+ tmp6 = tmp_o1 + tmp_o6;
+ tmp_o1 = fxp_mul32_Q32((tmp_o1 - tmp_o6) << 1, Qfmt_31(0.60134488693505F));
+
+ tmp5 = tmp_o2 + tmp_o5;
+ tmp_o5 = fxp_mul32_Q32((tmp_o2 - tmp_o5) << 1, Qfmt_31(0.89997622313642F));
+
+ tmp0 = fxp_mul32_Q32((tmp_o3 - tmp_o4) << 3, Qfmt_31(0.6407288619354F));
+ tmp4 = tmp_o3 + tmp_o4;
+
+ if (!flag)
+ {
+ tmp7 = -tmp7;
+ tmp1 = -tmp1;
+ tmp6 = -tmp6;
+ tmp_o1 = -tmp_o1;
+ tmp5 = -tmp5;
+ tmp_o5 = -tmp_o5;
+ tmp4 = -tmp4;
+ tmp0 = -tmp0;
+ }
+
+
+ tmp2 = fxp_mul32_Q32((tmp1 - tmp0) << 1, Qfmt_31(0.54119610014620F));
+ tmp0 += tmp1;
+ tmp1 = fxp_mul32_Q32((tmp7 - tmp4) << 1, Qfmt_31(0.54119610014620F));
+ tmp7 += tmp4;
+ tmp4 = fxp_mul32_Q32((tmp6 - tmp5) << 2, Qfmt_31(0.65328148243819F));
+ tmp6 += tmp5;
+ tmp5 = fxp_mul32_Q32((tmp_o1 - tmp_o5) << 2, Qfmt_31(0.65328148243819F));
+ tmp_o1 += tmp_o5;
+
+
+ vec[13] = fxp_mul32_Q32((tmp1 - tmp4) << 1, Qfmt_31(0.70710678118655F));
+ vec[ 5] = tmp1 + tmp4 + vec[13];
+
+ vec[ 9] = fxp_mul32_Q32((tmp7 - tmp6) << 1, Qfmt_31(0.70710678118655F));
+ vec[ 1] = tmp7 + tmp6;
+
+ tmp4 = fxp_mul32_Q32((tmp0 - tmp_o1) << 1, Qfmt_31(0.70710678118655F));
+ tmp0 += tmp_o1;
+ tmp6 = fxp_mul32_Q32((tmp2 - tmp5) << 1, Qfmt_31(0.70710678118655F));
+ tmp2 += tmp5 + tmp6;
+ tmp0 += tmp2;
+
+ vec[ 1] += tmp0;
+ vec[ 3] = tmp0 + vec[ 5];
+ tmp2 += tmp4;
+ vec[ 5] = tmp2 + vec[ 5];
+ vec[ 7] = tmp2 + vec[ 9];
+ tmp4 += tmp6;
+ vec[ 9] = tmp4 + vec[ 9];
+ vec[11] = tmp4 + vec[13];
+ vec[13] = tmp6 + vec[13];
+ vec[15] = tmp6;
+
+}
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+__attribute__((no_sanitize("integer")))
+void pvmp3_merge_in_place_N32(int32 vec[])
+{
+
+
+ int32 temp0;
+ int32 temp1;
+ int32 temp2;
+ int32 temp3;
+
+ temp0 = vec[14];
+ vec[14] = vec[ 7];
+ temp1 = vec[12];
+ vec[12] = vec[ 6];
+ temp2 = vec[10];
+ vec[10] = vec[ 5];
+ temp3 = vec[ 8];
+ vec[ 8] = vec[ 4];
+ vec[ 6] = vec[ 3];
+ vec[ 4] = vec[ 2];
+ vec[ 2] = vec[ 1];
+
+ vec[ 1] = (vec[16] + vec[17]);
+ vec[16] = temp3;
+ vec[ 3] = (vec[18] + vec[17]);
+ vec[ 5] = (vec[19] + vec[18]);
+ vec[18] = vec[9];
+
+ vec[ 7] = (vec[20] + vec[19]);
+ vec[ 9] = (vec[21] + vec[20]);
+ vec[20] = temp2;
+ temp2 = vec[13];
+ temp3 = vec[11];
+ vec[11] = (vec[22] + vec[21]);
+ vec[13] = (vec[23] + vec[22]);
+ vec[22] = temp3;
+ temp3 = vec[15];
+
+ vec[15] = (vec[24] + vec[23]);
+ vec[17] = (vec[25] + vec[24]);
+ vec[19] = (vec[26] + vec[25]);
+ vec[21] = (vec[27] + vec[26]);
+ vec[23] = (vec[28] + vec[27]);
+ vec[24] = temp1;
+ vec[25] = (vec[29] + vec[28]);
+ vec[26] = temp2;
+ vec[27] = (vec[30] + vec[29]);
+ vec[28] = temp0;
+ vec[29] = (vec[30] + vec[31]);
+ vec[30] = temp3;
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
+__attribute__((no_sanitize("integer")))
+void pvmp3_split(int32 *vect)
+{
+
+ int32 i;
+ const int32 *pt_cosTerms = &CosTable_dct32[15];
+ int32 *pt_vect = vect;
+ int32 *pt_vect_2 = pt_vect - 1;
+
+ for (i = 3; i != 0; i--)
+ {
+ int32 tmp2 = *(pt_vect);
+ int32 tmp1 = *(pt_vect_2);
+ int32 cosx = *(pt_cosTerms--);
+ *(pt_vect_2--) = (tmp1 + tmp2);
+ *(pt_vect++) = fxp_mul32_Q27((tmp1 - tmp2), cosx);
+
+ tmp2 = *(pt_vect);
+ tmp1 = *(pt_vect_2);
+ cosx = *(pt_cosTerms--);
+ *(pt_vect_2--) = (tmp1 + tmp2);
+ *(pt_vect++) = fxp_mul32_Q27((tmp1 - tmp2), cosx);
+
+ }
+
+ for (i = 5; i != 0; i--)
+ {
+ int32 tmp2 = *(pt_vect);
+ int32 tmp1 = *(pt_vect_2);
+ int32 cosx = *(pt_cosTerms--);
+ *(pt_vect_2--) = (tmp1 + tmp2);
+ *(pt_vect++) = fxp_mul32_Q32((tmp1 - tmp2) << 1, cosx);
+
+ tmp2 = *(pt_vect);
+ tmp1 = *(pt_vect_2);
+ cosx = *(pt_cosTerms--);
+ *(pt_vect_2--) = (tmp1 + tmp2);
+ *(pt_vect++) = fxp_mul32_Q32((tmp1 - tmp2) << 1, cosx);
+ }
+
+}
+
+#endif
diff --git a/media/codecs/mp3dec/src/pvmp3_dct_16.h b/media/codecs/mp3dec/src/pvmp3_dct_16.h
new file mode 100644
index 0000000..e8bf76e
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_dct_16.h
@@ -0,0 +1,102 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_dct_16.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_DCT_16_H
+#define PVMP3_DCT_16_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_dct_16(int32 vec[], int32 flag);
+
+ void pvmp3_merge_in_place_N32(int32 vec[]);
+
+ void pvmp3_split(int32 *vect);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_dct_6.cpp b/media/codecs/mp3dec/src/pvmp3_dct_6.cpp
new file mode 100644
index 0000000..c306873
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_dct_6.cpp
@@ -0,0 +1,153 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_dct6.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ Int32 vec[] vector of 6 32-bit integers
+Returns
+ Int32 vec[] dct computation in-place
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns the dct of length 6 of the input vector
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_mdct_6.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define Qfmt30(a) (Int32)((a)*((Int32)1<<30) + ((a)>=0?0.5F:-0.5F))
+
+#define cos_pi_6 Qfmt30( 0.86602540378444f)
+#define cos_2_pi_6 Qfmt30( 0.5f)
+#define cos_7_pi_12 Qfmt30( -0.25881904510252f)
+#define cos_3_pi_12 Qfmt30( 0.70710678118655f)
+#define cos_11_pi_12 Qfmt30( -0.96592582628907f)
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+__attribute__((no_sanitize("integer")))
+void pvmp3_dct_6(int32 vec[])
+{
+
+ Int32 tmp0;
+ Int32 tmp1;
+ Int32 tmp2;
+ Int32 tmp3;
+ Int32 tmp4;
+ Int32 tmp5;
+
+
+ /* split input vector */
+
+ tmp0 = vec[5] + vec[0];
+ tmp5 = vec[5] - vec[0];
+ tmp1 = vec[4] + vec[1];
+ tmp4 = vec[4] - vec[1];
+ tmp2 = vec[3] + vec[2];
+ tmp3 = vec[3] - vec[2];
+
+ vec[0] = tmp0 + tmp2 ;
+ vec[2] = fxp_mul32_Q30(tmp0 - tmp2, cos_pi_6);
+ vec[4] = (vec[0] >> 1) - tmp1;
+ vec[0] += tmp1;
+
+ tmp0 = fxp_mul32_Q30(tmp3, cos_7_pi_12);
+ tmp0 = fxp_mac32_Q30(tmp4, -cos_3_pi_12, tmp0);
+ vec[1] = fxp_mac32_Q30(tmp5, cos_11_pi_12, tmp0);
+
+ vec[3] = fxp_mul32_Q30((tmp3 + tmp4 - tmp5), cos_3_pi_12);
+ tmp0 = fxp_mul32_Q30(tmp3, cos_11_pi_12);
+ tmp0 = fxp_mac32_Q30(tmp4, cos_3_pi_12, tmp0);
+ vec[5] = fxp_mac32_Q30(tmp5, cos_7_pi_12, tmp0);
+
+}
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_dct_9.cpp b/media/codecs/mp3dec/src/pvmp3_dct_9.cpp
new file mode 100644
index 0000000..9cd0e91
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_dct_9.cpp
@@ -0,0 +1,168 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_dct_9.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ int32 vec[] vector of 9 32-bit integers
+Returns
+ int32 vec[] dct computation in-place
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns the dct of length 9 of the input vector
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_mdct_18.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define Qfmt31(a) (int32)((a)*((float)0x7FFFFFFF))
+
+#define cos_pi_9 Qfmt31( 0.93969262078591f)
+#define cos_2pi_9 Qfmt31( 0.76604444311898f)
+#define cos_4pi_9 Qfmt31( 0.17364817766693f)
+#define cos_5pi_9 Qfmt31(-0.17364817766693f)
+#define cos_7pi_9 Qfmt31(-0.76604444311898f)
+#define cos_8pi_9 Qfmt31(-0.93969262078591f)
+#define cos_pi_6 Qfmt31( 0.86602540378444f)
+#define cos_5pi_6 Qfmt31(-0.86602540378444f)
+#define cos_5pi_18 Qfmt31( 0.64278760968654f)
+#define cos_7pi_18 Qfmt31( 0.34202014332567f)
+#define cos_11pi_18 Qfmt31(-0.34202014332567f)
+#define cos_13pi_18 Qfmt31(-0.64278760968654f)
+#define cos_17pi_18 Qfmt31(-0.98480775301221f)
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+__attribute__((no_sanitize("integer")))
+void pvmp3_dct_9(int32 vec[])
+{
+
+ /* split input vector */
+
+ int32 tmp0 = vec[8] + vec[0];
+ int32 tmp8 = vec[8] - vec[0];
+ int32 tmp1 = vec[7] + vec[1];
+ int32 tmp7 = vec[7] - vec[1];
+ int32 tmp2 = vec[6] + vec[2];
+ int32 tmp6 = vec[6] - vec[2];
+ int32 tmp3 = vec[5] + vec[3];
+ int32 tmp5 = vec[5] - vec[3];
+
+ vec[0] = (tmp0 + tmp2 + tmp3) + (tmp1 + vec[4]);
+ vec[6] = ((tmp0 + tmp2 + tmp3) >> 1) - (tmp1 + vec[4]);
+ vec[2] = (tmp1 >> 1) - vec[4];
+ vec[4] = -vec[2];
+ vec[8] = -vec[2];
+ vec[4] = fxp_mac32_Q32(vec[4], tmp0 << 1, cos_2pi_9);
+ vec[8] = fxp_mac32_Q32(vec[8], tmp0 << 1, cos_4pi_9);
+ vec[2] = fxp_mac32_Q32(vec[2], tmp0 << 1, cos_pi_9);
+ vec[2] = fxp_mac32_Q32(vec[2], tmp2 << 1, cos_5pi_9);
+ vec[4] = fxp_mac32_Q32(vec[4], tmp2 << 1, cos_8pi_9);
+ vec[8] = fxp_mac32_Q32(vec[8], tmp2 << 1, cos_2pi_9);
+ vec[8] = fxp_mac32_Q32(vec[8], tmp3 << 1, cos_8pi_9);
+ vec[4] = fxp_mac32_Q32(vec[4], tmp3 << 1, cos_4pi_9);
+ vec[2] = fxp_mac32_Q32(vec[2], tmp3 << 1, cos_7pi_9);
+
+ vec[1] = fxp_mul32_Q32(tmp5 << 1, cos_11pi_18);
+ vec[1] = fxp_mac32_Q32(vec[1], tmp6 << 1, cos_13pi_18);
+ vec[1] = fxp_mac32_Q32(vec[1], tmp7 << 1, cos_5pi_6);
+ vec[1] = fxp_mac32_Q32(vec[1], tmp8 << 1, cos_17pi_18);
+ vec[3] = fxp_mul32_Q32((tmp5 + tmp6 - tmp8) << 1, cos_pi_6);
+ vec[5] = fxp_mul32_Q32(tmp5 << 1, cos_17pi_18);
+ vec[5] = fxp_mac32_Q32(vec[5], tmp6 << 1, cos_7pi_18);
+ vec[5] = fxp_mac32_Q32(vec[5], tmp7 << 1, cos_pi_6);
+ vec[5] = fxp_mac32_Q32(vec[5], tmp8 << 1, cos_13pi_18);
+ vec[7] = fxp_mul32_Q32(tmp5 << 1, cos_5pi_18);
+ vec[7] = fxp_mac32_Q32(vec[7], tmp6 << 1, cos_17pi_18);
+ vec[7] = fxp_mac32_Q32(vec[7], tmp7 << 1, cos_pi_6);
+ vec[7] = fxp_mac32_Q32(vec[7], tmp8 << 1, cos_11pi_18);
+
+}
+
+
+
+#endif // If not assembly
diff --git a/media/codecs/mp3dec/src/pvmp3_dec_defs.h b/media/codecs/mp3dec/src/pvmp3_dec_defs.h
new file mode 100644
index 0000000..2be9ab9
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_dec_defs.h
@@ -0,0 +1,199 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_dec_defs.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This include file has the mp3 decoder common defines.
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_DEC_DEFS_H
+#define PVMP3_DEC_DEFS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3decoder_api.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+#define module(x, POW2) ((x)&((POW2)-1))
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define BUFSIZE 8192 // big enough to hold 4608 bytes == biggest mp3 frame
+
+#define CHAN 2
+#define GRAN 2
+
+
+#define SUBBANDS_NUMBER 32
+#define FILTERBANK_BANDS 18
+#define HAN_SIZE 512
+
+
+/* MPEG Header Definitions - ID Bit Values */
+
+#define MPEG_1 0
+#define MPEG_2 1
+#define MPEG_2_5 2
+#define INVALID_VERSION (-1)
+
+/* MPEG Header Definitions - Mode Values */
+
+#define MPG_MD_STEREO 0
+#define MPG_MD_JOINT_STEREO 1
+#define MPG_MD_DUAL_CHANNEL 2
+#define MPG_MD_MONO 3
+
+
+
+#define LEFT 0
+#define RIGHT 1
+
+
+#define SYNC_WORD (int32)0x7ff
+#define SYNC_WORD_LNGTH 11
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*----------------------------------------------------------------------------
+ ; STRUCTURES TYPEDEF'S
+ ----------------------------------------------------------------------------*/
+
+ /* Header Information Structure */
+
+ typedef struct
+ {
+ int32 version_x;
+ int32 layer_description;
+ int32 error_protection;
+ int32 bitrate_index;
+ int32 sampling_frequency;
+ int32 padding;
+ int32 extension;
+ int32 mode;
+ int32 mode_ext;
+ int32 copyright;
+ int32 original;
+ int32 emphasis;
+ } mp3Header;
+
+
+ /* Layer III side information. */
+
+ typedef struct
+ {
+ uint32 part2_3_length;
+ uint32 big_values;
+ int32 global_gain;
+ uint32 scalefac_compress;
+ uint32 window_switching_flag;
+ uint32 block_type;
+ uint32 mixed_block_flag;
+ uint32 table_select[3];
+ uint32 subblock_gain[3];
+ uint32 region0_count;
+ uint32 region1_count;
+ uint32 preflag;
+ uint32 scalefac_scale;
+ uint32 count1table_select;
+
+ } granuleInfo;
+
+ typedef struct
+ {
+ uint32 scfsi[4];
+ granuleInfo gran[2];
+
+ } channelInfo;
+
+ /* Layer III side info. */
+
+ typedef struct
+ {
+ uint32 main_data_begin;
+ uint32 private_bits;
+ channelInfo ch[2];
+
+ } mp3SideInfo;
+
+ /* Layer III scale factors. */
+ typedef struct
+ {
+ int32 l[23]; /* [cb] */
+ int32 s[3][13]; /* [window][cb] */
+
+ } mp3ScaleFactors;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_decode_header.cpp b/media/codecs/mp3dec/src/pvmp3_decode_header.cpp
new file mode 100644
index 0000000..bc5fd79
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_decode_header.cpp
@@ -0,0 +1,194 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_decode_header.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ tbits *inputStream, bit stream
+ mp3Header *info,
+ uint32 *crc
+ Returns
+
+ mp3Header *info, structure holding the parsed mp3 header info
+ uint32 *crc initialized crc computation
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ gets mp3 header information
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_decode_header.h"
+#include "pvmp3_crc.h"
+#include "pvmp3_getbits.h"
+#include "pvmp3_seek_synch.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+ERROR_CODE pvmp3_decode_header(tmp3Bits *inputStream,
+ mp3Header *info,
+ uint32 *crc)
+{
+
+ ERROR_CODE err = NO_DECODING_ERROR;
+ uint32 temp;
+
+ /*
+ * Verify that at least the header is complete
+ * Note that SYNC_WORD_LNGTH is in unit of bits, but inputBufferCurrentLength
+ * is in unit of bytes.
+ */
+ if (inputStream->inputBufferCurrentLength < ((SYNC_WORD_LNGTH + 21) >> 3))
+ {
+ return NO_ENOUGH_MAIN_DATA_ERROR;
+ }
+
+ /*
+ * MPEG Audio Version ID
+ */
+ temp = getUpTo17bits(inputStream, SYNC_WORD_LNGTH);
+ if ((temp & SYNC_WORD) != SYNC_WORD)
+ {
+ err = pvmp3_header_sync(inputStream);
+
+ if (err != NO_DECODING_ERROR)
+ {
+ return err;
+ }
+ }
+
+ temp = getNbits(inputStream, 21); // to avoid multiple bitstream accesses
+
+
+ switch (temp >> 19) /* 2 */
+ {
+ case 0:
+ info->version_x = MPEG_2_5;
+ break;
+ case 2:
+ info->version_x = MPEG_2;
+ break;
+ case 3:
+ info->version_x = MPEG_1;
+ break;
+ default:
+ info->version_x = INVALID_VERSION;
+ err = UNSUPPORTED_LAYER;
+ break;
+ }
+
+ info->layer_description = 4 - ((temp << 13) >> 30); /* 2 */
+ info->error_protection = !((temp << 15) >> 31); /* 1 */
+
+ if (info->error_protection)
+ {
+ *crc = 0xffff; /* CRC start value */
+ calculate_crc((temp << 16) >> 16, 16, crc);
+ }
+
+ info->bitrate_index = (temp << 16) >> 28; /* 4 */
+ info->sampling_frequency = (temp << 20) >> 30; /* 2 */
+ info->padding = (temp << 22) >> 31; /* 1 */
+ info->extension = (temp << 23) >> 31; /* 1 */
+ info->mode = (temp << 24) >> 30; /* 2 */
+ info->mode_ext = (temp << 26) >> 30; /* 2 */
+ info->copyright = (temp << 27) >> 31; /* 1 */
+ info->original = (temp << 28) >> 31; /* 1 */
+ info->emphasis = (temp << 30) >> 30; /* 2 */
+
+
+ if (!info->bitrate_index || info->bitrate_index == 15 || info->sampling_frequency == 3)
+ {
+ err = UNSUPPORTED_FREE_BITRATE;
+ }
+
+ return(err);
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_decode_header.h b/media/codecs/mp3dec/src/pvmp3_decode_header.h
new file mode 100644
index 0000000..2c2e89e
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_decode_header.h
@@ -0,0 +1,101 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_decode_header.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_DECODE_HEADER_H
+#define PVMP3_DECODE_HEADER_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3_dec_defs.h"
+#include "s_mp3bits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ ERROR_CODE pvmp3_decode_header(tmp3Bits *inputStream,
+ mp3Header *info,
+ uint32 *crc);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_decode_huff_cw.cpp b/media/codecs/mp3dec/src/pvmp3_decode_huff_cw.cpp
new file mode 100644
index 0000000..6e45a18
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_decode_huff_cw.cpp
@@ -0,0 +1,758 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_decode_huff_cw.cpp
+
+ Funtions:
+ pvmp3_decode_huff_cw_tab0
+ pvmp3_decode_huff_cw_tab1
+ pvmp3_decode_huff_cw_tab2
+ pvmp3_decode_huff_cw_tab3
+ pvmp3_decode_huff_cw_tab5
+ pvmp3_decode_huff_cw_tab6
+ pvmp3_decode_huff_cw_tab7
+ pvmp3_decode_huff_cw_tab8
+ pvmp3_decode_huff_cw_tab9
+ pvmp3_decode_huff_cw_tab10
+ pvmp3_decode_huff_cw_tab11
+ pvmp3_decode_huff_cw_tab12
+ pvmp3_decode_huff_cw_tab13
+ pvmp3_decode_huff_cw_tab15
+ pvmp3_decode_huff_cw_tab16
+ pvmp3_decode_huff_cw_tab24
+ pvmp3_decode_huff_cw_tab32
+ pvmp3_decode_huff_cw_tab33
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ BITS *pMainData = pointer to input mp3 Main data bit stream
+
+
+ Outputs:
+ cw = bit field extracted from a leaf entry of packed mp3 Huffman Tables
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ These functions are used to decode huffman codewords from the input
+ bitstream using combined binary search and look-up table approach.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+ [2] Introduction to Algorithms,
+ Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest.
+ The MIT press, 1990
+
+ [3] "Selecting an Optimal Huffman Decoder for AAC",
+ Vladimir Z. Mesarovic, et al.
+ AES 111th Convention, September 21-24, 2001, New York, USA
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_tables.h"
+#include "pvmp3_getbits.h"
+#include "pvmp3_decode_huff_cw.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+uint16 pvmp3_decode_huff_cw_tab0(tmp3Bits *pMainData)
+{
+ OSCL_UNUSED_ARG(pMainData);
+ return(0);
+
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab1(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo9bits(pMainData, 3); /* hufftable1 */
+
+ cw = *(huffTable_1 + tmp);
+ pMainData->usedBits -= (3 - (cw & 0xFF));
+ return(cw >> 8);
+
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab2(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo9bits(pMainData, 6); /* huffTable_2,3 */
+
+ if (tmp >> 3)
+ {
+ tmp = (tmp >> 3) - 1;
+ }
+ else
+ {
+ tmp = tmp + 7;
+ }
+
+ cw = *(huffTable_2 + tmp);
+ pMainData->usedBits -= (6 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab3(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo9bits(pMainData, 6); /* huffTable_2,3 */
+
+ if (tmp >> 3)
+ {
+ tmp = (tmp >> 3) - 1;
+ }
+ else
+ {
+ tmp = tmp + 7;
+ }
+
+ cw = *(huffTable_3 + tmp);
+ pMainData->usedBits -= (6 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab5(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo9bits(pMainData, 8); /* huffTable_5 */
+
+ if ((tmp >> 5))
+ {
+ tmp = (tmp >> 5) - 1;
+ }
+ else if ((tmp >> 1) >= 2)
+ {
+ tmp = (tmp >> 1) - 2 + 7;
+ }
+ else
+ {
+ tmp = (tmp & 3) + 21;
+ }
+
+ cw = *(huffTable_5 + tmp);
+ pMainData->usedBits -= (8 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab6(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo9bits(pMainData, 7); /* huffTable_6 */
+ if ((tmp >> 3) >= 3)
+ {
+ tmp = (tmp >> 3) - 3;
+ }
+ else if (tmp >> 1)
+ {
+ tmp = (tmp >> 1) - 1 + 13;
+ }
+ else
+ {
+ tmp = tmp + 24;
+ }
+
+ cw = *(huffTable_6 + tmp);
+ pMainData->usedBits -= (7 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab7(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 10); /* huffTable_7 */
+ if ((tmp >> 7) >= 2)
+ {
+ tmp = (tmp >> 7) - 2;
+ }
+ else if ((tmp >> 4) >= 7)
+ {
+ tmp = (tmp >> 4) - 7 + 6;
+ }
+ else if ((tmp >> 1) >= 2)
+ {
+ tmp = (tmp >> 1) - 2 + 15;
+ }
+ else
+ {
+ tmp = (tmp & 3) + 69;
+ }
+
+ cw = *(huffTable_7 + tmp);
+ pMainData->usedBits -= (10 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab8(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 11); /* huffTable_8 */
+ if ((tmp >> 7) >= 2)
+ {
+ tmp = (tmp >> 7) - 2;
+ }
+ else if ((tmp >> 5) >= 5)
+ {
+ tmp = (tmp >> 5) - 5 + 14;
+ }
+ else if ((tmp >> 2) >= 3)
+ {
+ tmp = (tmp >> 2) - 3 + 17;
+ }
+ else
+ {
+ tmp = (tmp) + 54;
+ }
+
+ cw = *(huffTable_8 + tmp);
+ pMainData->usedBits -= (11 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab9(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo9bits(pMainData, 9); /* huffTable_9 */
+ if ((tmp >> 5) >= 5)
+ {
+ tmp = (tmp >> 5) - 5;
+ }
+ else if ((tmp >> 3) >= 6)
+ {
+ tmp = (tmp >> 3) - 6 + 11;
+ }
+ else if ((tmp >> 1) >= 4)
+ {
+ tmp = (tmp >> 1) - 4 + 25;
+ }
+ else
+ {
+ tmp = tmp + 45;
+ }
+
+ cw = *(huffTable_9 + tmp);
+ pMainData->usedBits -= (9 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab10(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 11); /* huffTable_10 */
+ if (tmp >> 10)
+ {
+ tmp = (tmp >> 10) - 1;
+ }
+ else if ((tmp >> 7) >= 3)
+ {
+ tmp = (tmp >> 7) - 3 + 1;
+ }
+ else if ((tmp >> 5) >= 8)
+ {
+ tmp = (tmp >> 5) - 8 + 6;
+ }
+ else if ((tmp >> 3) >= 18)
+ {
+ tmp = (tmp >> 3) - 18 + 10;
+ }
+ else if ((tmp >> 2) >= 24)
+ {
+ tmp = (tmp >> 2) - 24 + 24;
+ }
+ else if ((tmp >> 1) >= 12)
+ {
+ tmp = (tmp >> 1) - 12 + 36;
+ }
+ else
+ {
+ tmp = (tmp) + 72;
+ }
+
+ cw = *(huffTable_10 + tmp);
+ pMainData->usedBits -= (11 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab11(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 11); /* huffTable_11 */
+ if ((tmp >> 8) >= 3)
+ {
+ tmp = (tmp >> 8) - 3;
+ }
+ else if ((tmp >> 6) >= 7)
+ {
+ tmp = (tmp >> 6) - 7 + 5;
+ }
+ else if ((tmp >> 3) >= 32)
+ {
+ tmp = (tmp >> 3) - 32 + 10;
+ }
+ else if ((tmp >> 2) >= 10)
+ {
+ tmp = (tmp >> 2) - 10 + 34;
+ }
+ else if ((tmp >> 1) >= 8)
+ {
+ tmp = (tmp >> 1) - 8 + 88;
+ }
+ else
+ {
+ tmp = (tmp & 0xFF) + 100;
+ }
+ cw = *(huffTable_11 + tmp);
+ pMainData->usedBits -= (11 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab12(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 10); /* huffTable_12 */
+ if ((tmp >> 7) >= 5)
+ {
+ tmp = (tmp >> 7) - 5;
+ }
+ else if ((tmp >> 5) >= 12)
+ {
+ tmp = (tmp >> 5) - 12 + 3;
+ }
+ else if ((tmp >> 4) >= 17)
+ {
+ tmp = (tmp >> 4) - 17 + 11;
+ }
+ else if ((tmp >> 2) >= 32)
+ {
+ tmp = (tmp >> 2) - 32 + 18;
+ }
+ else if ((tmp >> 1) >= 16)
+ {
+ tmp = (tmp >> 1) - 16 + 54;
+ }
+ else
+ {
+ tmp = (tmp & 0x1F) + 102;
+
+ }
+ cw = *(huffTable_12 + tmp);
+ pMainData->usedBits -= (10 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab13(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getNbits(pMainData, 19); /* huffTable_13 */
+ if (tmp >> 18)
+ {
+ tmp = 0;
+ }
+ else if ((tmp >> 15) >= 4)
+ {
+ tmp = (tmp >> 15) - 4 + 1;
+ }
+ else if ((tmp >> 11) >= 32)
+ {
+ tmp = (tmp >> 11) - 32 + 5;
+ }
+ else if ((tmp >> 9) >= 64)
+ {
+ tmp = (tmp >> 9) - 64 + 37;
+ }
+ else if ((tmp >> 8) >= 64)
+ {
+ tmp = (tmp >> 8) - 64 + 101;
+ }
+ else if ((tmp >> 7) >= 64)
+ {
+ tmp = (tmp >> 7) - 64 + 165;
+ }
+ else if ((tmp >> 6) >= 32)
+ {
+ tmp = (tmp >> 6) - 32 + 229;
+ }
+ else if ((tmp >> 5) >= 32)
+ {
+ tmp = (tmp >> 5) - 32 + 325;
+ }
+ else if ((tmp >> 4) >= 32)
+ {
+ tmp = (tmp >> 4) - 32 + 357;
+ }
+ else if ((tmp >> 3) >= 32)
+ {
+ tmp = (tmp >> 3) - 32 + 389;
+ }
+ else if ((tmp >> 2) >= 2)
+ {
+ tmp = (tmp >> 2) - 2 + 421;
+ }
+ else
+ {
+ tmp = (tmp & 0x7) + 483;
+ }
+
+ cw = *(huffTable_13 + tmp);
+ pMainData->usedBits -= (19 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab15(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 13); /* huffTable_15 */
+ if ((tmp >> 9) >= 10)
+ {
+ tmp = (tmp >> 9) - 10;
+ }
+ else if ((tmp >> 6) >= 39)
+ {
+ tmp = (tmp >> 6) - 39 + 6;
+ }
+ else if ((tmp >> 4) >= 62)
+ {
+ tmp = (tmp >> 4) - 62 + 47;
+ }
+ else if ((tmp >> 3) >= 60)
+ {
+ tmp = (tmp >> 3) - 60 + 141;
+ }
+ else if ((tmp >> 2) >= 64)
+ {
+ tmp = (tmp >> 2) - 64 + 205;
+ }
+ else if ((tmp >> 1) >= 32)
+ {
+ tmp = (tmp >> 1) - 32 + 261;
+ }
+ else
+ {
+ tmp = (tmp & 0x3f) + 357;
+ }
+
+ cw = *(huffTable_15 + tmp);
+ pMainData->usedBits -= (13 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab16(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 17); /* huffTable_16 */
+ if (tmp >> 16)
+ {
+ tmp = 0;
+ }
+ else if ((tmp >> 13) >= 4)
+ {
+ tmp = (tmp >> 13) - 4 + 1;
+ }
+ else if ((tmp >> 9) >= 38)
+ {
+ tmp = (tmp >> 9) - 38 + 5;
+ }
+ else if ((tmp >> 7) >= 94)
+ {
+ tmp = (tmp >> 7) - 94 + 31;
+ }
+ else if ((tmp >> 5) >= 214)
+ {
+ tmp = (tmp >> 5) - 214 + 89;
+ }
+ else if ((tmp >> 3) >= 704)
+ {
+ if ((tmp >> 4) >= 384)
+ {
+ tmp = (tmp >> 4) - 384 + 315;
+ }
+ else
+ {
+ tmp = (tmp >> 3) - 704 + 251;
+ }
+ }
+ else if ((tmp >> 8) >= 14)
+ {
+ tmp = (tmp >> 8) - 14 + 359;
+ }
+ else if ((tmp) >= 3456)
+ {
+ if ((tmp >> 2) >= 868)
+ {
+ tmp = (tmp >> 2) - 868 + 383;
+ }
+ else
+ {
+ tmp = (tmp) - 3456 + 367;
+ }
+ }
+ else
+ {
+ tmp = ((tmp >> 6) & 0x3f) + 411;
+ }
+
+ cw = *(huffTable_16 + tmp);
+ pMainData->usedBits -= (17 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab24(tmp3Bits *pMainData)
+{
+ uint32 tmp;
+ uint16 cw;
+
+ tmp = getUpTo17bits(pMainData, 12); /* huffTable_24 */
+ if ((tmp >> 6) >= 41)
+ {
+ tmp = (tmp >> 6) - 41;
+ }
+ else if ((tmp >> 3) >= 218)
+ {
+ tmp = (tmp >> 3) - 218 + 23;
+ }
+ else if ((tmp >> 2) >= 336)
+ {
+ tmp = (tmp >> 2) - 336 + 133;
+ }
+ else if ((tmp >> 1) >= 520)
+ {
+ tmp = (tmp >> 1) - 520 + 233;
+ }
+ else if ((tmp) >= 1024)
+ {
+ tmp = (tmp) - 1024 + 385;
+ }
+ else if ((tmp >> 1) >= 352)
+ {
+ if ((tmp >> 8) == 3)
+ {
+ tmp = (tmp >> 8) - 3 + 433;
+ }
+ else
+ {
+ tmp = (tmp >> 1) - 352 + 401;
+ }
+ }
+ else
+ {
+ tmp = ((tmp >> 4) & 0x3f) + 434;
+ }
+
+ cw = *(huffTable_24 + tmp);
+ pMainData->usedBits -= (12 - (cw & 0xFF));
+
+ return(cw >> 8);
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+uint16 pvmp3_decode_huff_cw_tab32(tmp3Bits *pMainData)
+{
+ uint32 tmp = getUpTo9bits(pMainData, 6); /* huffTable_32 */
+ if ((tmp >> 5))
+ {
+ pMainData->usedBits -= 5;
+ return(0);
+ }
+ else
+ {
+ uint16 cw = *(huffTable_32 + (tmp & 0x1f));
+ pMainData->usedBits -= (6 - (cw & 0xFF));
+
+ return(cw >> 8);
+ }
+
+}
+
+
+uint16 pvmp3_decode_huff_cw_tab33(tmp3Bits *pMainData)
+{
+
+ uint16 tmp = getUpTo9bits(pMainData, 4); /* huffTable_33 */
+
+ return((0x0f - tmp));
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_decode_huff_cw.h b/media/codecs/mp3dec/src/pvmp3_decode_huff_cw.h
new file mode 100644
index 0000000..941ca6d
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_decode_huff_cw.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_decode_huff_cw.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_DECODE_HUFF_CW_H
+#define PVMP3_DECODE_HUFF_CW_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3_dec_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ uint16 pvmp3_decode_huff_cw_tab0(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab1(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab2(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab3(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab5(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab6(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab7(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab8(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab9(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab10(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab11(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab12(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab13(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab15(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab16(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab24(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab32(tmp3Bits *);
+ uint16 pvmp3_decode_huff_cw_tab33(tmp3Bits *);
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_dequantize_sample.cpp b/media/codecs/mp3dec/src/pvmp3_dequantize_sample.cpp
new file mode 100644
index 0000000..639df81
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_dequantize_sample.cpp
@@ -0,0 +1,452 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_dequantize_sample.cpp
+
+ Functions:
+ power_1_third
+ pvmp3_dequantize_sample
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+power_1_third
+int32 power_1_third( int32 xx)
+
+Input
+ int32 xx, int32 in the [0, 8192] range
+
+ Returns
+
+ int32 xx^(1/3) int32 Q26 number representing
+ the 1/3 power of the input
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+pvmp3_dequantize_sample
+
+Input
+ int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ mp3ScaleFactors *scalefac, scale factor structure
+ struct gr_info_s *gr_info, granule structure informatiom
+ mp3Header *info mp3 header info
+
+ Returns
+
+ int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS], dequantize output as (.)^(4/3)
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ dequantize sample
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_dequantize_sample.h"
+#include "pvmp3_normalize.h"
+#include "mp3_mem_funcs.h"
+#include "pvmp3_tables.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define Q30_fmt(a)(int32(double(0x40000000)*(a)))
+#define Q29_fmt(a)(int32(double(0x20000000)*(a)))
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int32 pretab[22] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0};
+
+const int32 pow_2_1_fourth[4] =
+{
+ Q30_fmt(1.0), Q30_fmt(1.18920711500272),
+ Q30_fmt(1.41421356237310), Q30_fmt(1.68179283050743)
+};
+
+const int32 two_cubic_roots[7] =
+{
+ Q29_fmt(0), Q29_fmt(1.25992104989487),
+ Q29_fmt(1.58740105196820), Q29_fmt(2.00000000000000),
+ Q29_fmt(2.51984209978975), Q29_fmt(3.17480210393640),
+ Q29_fmt(3.99999999999999)
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+int32 power_1_third(int32 xx)
+{
+
+ if (xx <= 512)
+ {
+ return (power_one_third[xx] >> 1);
+ }
+ else
+ {
+ if (xx >> 15)
+ {
+ return 0x7FFFFFFF; /* saturate any value over 32767 */
+ }
+ else
+ {
+ int32 x = xx;
+ int32 m = 22 - pvmp3_normalize(xx);
+
+ xx >>= m;
+ xx = (power_one_third[xx]) + (((power_one_third[xx+1] - power_one_third[xx]) >> m) * (x & ((1 << m) - 1)));
+ return (fxp_mul32_Q30(xx, two_cubic_roots[m]));
+ }
+
+ }
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
+void pvmp3_dequantize_sample(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ mp3ScaleFactors *scalefac,
+ granuleInfo *gr_info,
+ int32 used_freq_lines,
+ mp3Header *info)
+{
+ int32 ss;
+ int32 cb = 0;
+ int32 global_gain;
+ int32 sfreq = info->sampling_frequency + info->version_x + (info->version_x << 1);
+
+ /* apply formula per block type */
+
+ if (gr_info->window_switching_flag && (gr_info->block_type == 2))
+ {
+ int32 next_cb_boundary;
+ int32 cb_begin = 0;
+ int32 cb_width = 0;
+ int32 mixstart = 8; /* added 2003/08/21 efs */
+
+ if (info->version_x != MPEG_1)
+ {
+ mixstart = 6; /* different value in MPEG2 LSF */
+ }
+
+ if (gr_info->mixed_block_flag)
+ {
+ next_cb_boundary = mp3_sfBandIndex[sfreq].l[1]; /* LONG blocks: 0,1,3 */
+ }
+ else
+ {
+ next_cb_boundary = mp3_sfBandIndex[sfreq].s[1] * 3; /* pure SHORT block */
+ cb_width = 0;
+ }
+
+ global_gain = gr_info->global_gain;
+ int32 two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
+ global_gain = 12 + (global_gain >> 2);
+
+ for (ss = 0 ; ss < used_freq_lines ; ss++)
+ {
+ if (ss == next_cb_boundary)
+ {
+ cb++; /* critical band counter */
+ if (gr_info->mixed_block_flag)
+ {
+ if (next_cb_boundary == mp3_sfBandIndex[sfreq].l[mixstart])
+ {
+ next_cb_boundary = mp3_sfBandIndex[sfreq].s[4] * 3;
+
+ cb_begin = mp3_sfBandIndex[sfreq].s[3] * 3;
+ cb_width = 3;
+ cb = 3;
+ }
+ else if (ss < mp3_sfBandIndex[sfreq].l[mixstart])
+ {
+ next_cb_boundary = mp3_sfBandIndex[sfreq].l[cb+1];
+ }
+ else
+ {
+ next_cb_boundary = mp3_sfBandIndex[sfreq].s[cb+1] * 3;
+
+ cb_width = cb;
+ cb_begin = mp3_sfBandIndex[sfreq].s[cb] * 3;
+ }
+
+ if (ss < 2*FILTERBANK_BANDS)
+ { /* 1st 2 subbands of switched blocks */
+ global_gain = (gr_info->global_gain);
+ global_gain -= (1 + gr_info->scalefac_scale) *
+ (scalefac->l[cb] + gr_info->preflag * pretab[cb]) << 1;
+
+ two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
+ global_gain = 12 + (global_gain >> 2);
+ }
+ }
+ else
+ {
+ next_cb_boundary = mp3_sfBandIndex[sfreq].s[cb+1] * 3;
+ cb_width = cb;
+ cb_begin = mp3_sfBandIndex[sfreq].s[cb] * 3;
+ }
+
+ } /* end-if ( ss == next_cb_boundary) */
+
+ /* Do long/short dependent scaling operations. */
+ if ((gr_info->mixed_block_flag == 0) || (gr_info->mixed_block_flag && (ss >= 2*FILTERBANK_BANDS)))
+ {
+ int32 temp2 = fxp_mul32_Q32((ss - cb_begin) << 16, mp3_shortwindBandWidths[sfreq][cb_width]);
+ temp2 = (temp2 + 1) >> 15;
+
+ global_gain = (gr_info->global_gain);
+ global_gain -= gr_info->subblock_gain[temp2] << 3;
+ global_gain -= (1 + gr_info->scalefac_scale) * (scalefac->s[temp2][cb] << 1);
+
+ two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
+ global_gain = 12 + (global_gain >> 2);
+
+ }
+
+
+ /*
+ * xr[sb][ss] = 2^(global_gain/4)
+ */
+
+ /* Scale quantized value. */
+
+ /* 0 < abs(is[ss]) < 8192 */
+
+ int32 tmp = fxp_mul32_Q30((is[ss] << 16), power_1_third(pv_abs(is[ ss])));
+
+ tmp = fxp_mul32_Q30(tmp, two_raise_one_fourth);
+
+ if (global_gain < 0)
+ {
+ int32 temp = - global_gain;
+ if (temp < 32)
+ {
+ is[ss] = (tmp >> temp);
+ }
+ else
+ {
+ is[ss] = 0;
+ }
+ }
+ else
+ {
+ is[ss] = (tmp << global_gain);
+ }
+
+ } /* for (ss=0 ; ss < used_freq_lines ; ss++) */
+
+ }
+ else
+ {
+
+ for (cb = 0 ; cb < 22 ; cb++)
+ {
+
+ /* Compute overall (global) scaling. */
+
+ global_gain = (gr_info->global_gain);
+
+ global_gain -= (1 + gr_info->scalefac_scale) *
+ (scalefac->l[cb] + gr_info->preflag * pretab[cb]) << 1;
+
+
+ int32 two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
+ global_gain = 12 + (global_gain >> 2);
+
+ /*
+ * xr[sb][ss] = 2^(global_gain/4)
+ */
+
+ /* Scale quantized value. */
+
+ if (used_freq_lines >= mp3_sfBandIndex[sfreq].l[cb+1])
+ {
+ if (global_gain <= 0)
+ {
+ global_gain = - global_gain;
+ if (global_gain < 32)
+ {
+ for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < mp3_sfBandIndex[sfreq].l[cb+1]; ss += 2)
+ {
+ int32 tmp = is[ss];
+ if (tmp)
+ {
+ tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
+ is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
+ }
+ tmp = is[ss+1];
+ if (tmp)
+ {
+ tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
+ is[ss+1] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
+ }
+ }
+ }
+ else
+ {
+ pv_memset(&is[ mp3_sfBandIndex[sfreq].l[cb]],
+ 0,
+ (mp3_sfBandIndex[sfreq].l[cb+1] - mp3_sfBandIndex[sfreq].l[cb])*sizeof(*is));
+ }
+ }
+ else
+ {
+ for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < mp3_sfBandIndex[sfreq].l[cb+1]; ss += 2)
+ {
+ int32 tmp = is[ss];
+ if (tmp)
+ {
+ tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
+ is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) << global_gain;
+ }
+
+ tmp = is[ss+1];
+ if (tmp)
+ {
+ tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
+ is[ss+1] = fxp_mul32_Q30(tmp, two_raise_one_fourth) << global_gain;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (global_gain <= 0)
+ {
+ global_gain = - global_gain;
+ if (global_gain < 32)
+ {
+ for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < used_freq_lines; ss += 2)
+ {
+ int32 tmp = is[ss];
+ if (tmp)
+ {
+ tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
+ is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
+ }
+ tmp = is[ss+1];
+ if (tmp)
+ {
+ tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
+ is[ss+1] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
+ }
+ }
+
+ }
+ else
+ {
+ pv_memset(&is[ mp3_sfBandIndex[sfreq].l[cb]],
+ 0,
+ (mp3_sfBandIndex[sfreq].l[cb+1] - mp3_sfBandIndex[sfreq].l[cb])*sizeof(*is));
+ }
+ }
+ else
+ {
+ for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < used_freq_lines; ss++)
+ {
+ int32 tmp = is[ss];
+
+ if (tmp)
+ {
+ tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
+ is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) << global_gain;
+ }
+ }
+ }
+
+ cb = 22; // force breaking out of the loop
+
+ } /* if ( used_freq_lines >= mp3_sfBandIndex[sfreq].l[cb+1]) */
+
+ } /* for (cb=0 ; cb < 22 ; cb++) */
+
+ } /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
+
+
+ pv_memset(&is[used_freq_lines],
+ 0,
+ (FILTERBANK_BANDS*SUBBANDS_NUMBER - used_freq_lines)*sizeof(*is));
+
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_dequantize_sample.h b/media/codecs/mp3dec/src/pvmp3_dequantize_sample.h
new file mode 100644
index 0000000..9393eb1
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_dequantize_sample.h
@@ -0,0 +1,106 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_dequantize_sample.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_DEQUANTIZE_SAMPLE_H
+#define PVMP3_DEQUANTIZE_SAMPLE_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int32 power_1_third(int32 xx);
+
+ void pvmp3_dequantize_sample(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ mp3ScaleFactors *scalefac,
+ granuleInfo *gr_info,
+ int32 num_lines,
+ mp3Header *info);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_equalizer.cpp b/media/codecs/mp3dec/src/pvmp3_equalizer.cpp
new file mode 100644
index 0000000..61aef30
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_equalizer.cpp
@@ -0,0 +1,415 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_equalizer.cpp
+
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Input
+ int32 *inData, pointer to the spectrum frequency-line
+ e_equalization equalizerType, equalization mode
+ int32 *pt_work_buff
+
+ Output
+ int32 *pt_work_buff pointer to the equalized frequency-line
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Equalizer
+ Each subband sample is scaled according to a spectrum shape setting
+ defined by "equalizerType"
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_equalizer.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_dec_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define LEVEL__0__dB 0.999999970f
+#define LEVEL__1_5dB 0.841395142f
+#define LEVEL__3__dB 0.707106781f
+#define LEVEL__4_5dB 0.595662143f
+#define LEVEL__6__dB 0.500000000f
+#define LEVEL__7_5dB 0.421696503f
+#define LEVEL__9__dB 0.353553393f
+#define LEVEL_12__dB 0.250000000f
+#define LEVEL_15__dB 0.176776695f
+#define LEVEL_18__dB 0.125000000f
+#define LEVEL_21__dB 0.088388347f
+#define LEVEL_30__dB 0.031250000f
+#define LEVEL_45__dB 0.005524271f
+#define LEVEL_60__dB 0.000976562f
+
+#define Qmf31( x) (int32)((x)*(float)0x7FFFFFFF)
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+const int32 equalizerTbl[8][SUBBANDS_NUMBER] =
+{
+ /* FLAT */
+ {
+ Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB)
+ },
+ /* BASS BOOST */
+ {
+ Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__3__dB),
+
+ Qmf31(LEVEL__4_5dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB)
+ },
+ /* ROCK */
+ {
+ Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__3__dB),
+
+ Qmf31(LEVEL__4_5dB), Qmf31(LEVEL__6__dB),
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB)
+ },
+ /* POP */
+ {
+ Qmf31(LEVEL__6__dB),
+
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+
+ Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB)
+ },
+ /* JAZZ */
+ {
+ Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB)
+ },
+ /* CLASSICAL */
+ {
+ Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+ Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
+
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB)
+ },
+ /* TALK */
+ {
+ Qmf31(LEVEL__9__dB),
+
+ Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__1_5dB),
+
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
+ Qmf31(LEVEL__3__dB)
+ },
+ /* FLAT */
+ {
+ Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
+ Qmf31(LEVEL__0__dB)
+ }
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_equalizer(int32 *circ_buffer,
+ e_equalization equalizerType,
+ int32 *work_buff)
+{
+
+ if (equalizerType == flat)
+ {
+ for (int32 band = 0; band < FILTERBANK_BANDS; band += 2)
+ {
+
+ int32 *pt_work_buff = &work_buff[band];
+ int32 *inData = &circ_buffer[544 - (band<<5)];
+
+ int32 i;
+ for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
+ {
+ int32 temp1 = (pt_work_buff[ i ]);
+ int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
+ int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
+ int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
+ *(inData++) = temp1;
+ *(inData++) = temp2;
+ *(inData++) = temp3;
+ *(inData++) = temp4;
+ }
+
+ inData -= SUBBANDS_NUMBER << 1;
+ pt_work_buff++;
+
+ for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
+ {
+ int32 temp1 = (pt_work_buff[ i ]);
+ int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
+ int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
+ int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
+ *(inData++) = temp1;
+ *(inData++) = temp2;
+ *(inData++) = temp3;
+ *(inData++) = temp4;
+ }
+ }
+ }
+ else
+ {
+ const int32 *pt_equalizer = equalizerTbl[equalizerType&7];
+
+
+ for (int32 band = 0; band < FILTERBANK_BANDS; band += 3)
+ {
+ int32 *inData = &circ_buffer[544 - (band<<5)];
+
+ int32 *pt_work_buff = &work_buff[band];
+ int32 i;
+
+ for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
+ {
+ int32 temp1 = (pt_work_buff[ i ]);
+ int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
+ int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
+ int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
+ *(inData++) = fxp_mul32_Q32(temp1 << 1, *(pt_equalizer++));
+ *(inData++) = fxp_mul32_Q32(temp2 << 1, *(pt_equalizer++));
+ *(inData++) = fxp_mul32_Q32(temp3 << 1, *(pt_equalizer++));
+ *(inData++) = fxp_mul32_Q32(temp4 << 1, *(pt_equalizer++));
+ }
+
+ pt_equalizer -= SUBBANDS_NUMBER;
+
+ inData -= SUBBANDS_NUMBER << 1;
+ pt_work_buff++;
+
+ for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
+ {
+ int32 temp1 = (pt_work_buff[ i ]);
+ int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
+ int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
+ int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
+ *(inData++) = fxp_mul32_Q32(temp1 << 1, *(pt_equalizer++));
+ *(inData++) = fxp_mul32_Q32(temp2 << 1, *(pt_equalizer++));
+ *(inData++) = fxp_mul32_Q32(temp3 << 1, *(pt_equalizer++));
+ *(inData++) = fxp_mul32_Q32(temp4 << 1, *(pt_equalizer++));
+ }
+ pt_equalizer -= SUBBANDS_NUMBER;
+
+ }
+ }
+}
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_equalizer.h b/media/codecs/mp3dec/src/pvmp3_equalizer.h
new file mode 100644
index 0000000..bbf134f
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_equalizer.h
@@ -0,0 +1,101 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_equalizer.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_EQUALIZER_H
+#define PVMP3_EQUALIZER_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3decoder_api.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_equalizer(int32 *inData,
+ e_equalization equalizerType,
+ int32 *pt_work_buff);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_framedecoder.cpp b/media/codecs/mp3dec/src/pvmp3_framedecoder.cpp
new file mode 100644
index 0000000..a5c7f5e
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_framedecoder.cpp
@@ -0,0 +1,830 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_framedecoder.cpp
+
+ Functions:
+ pvmp3_framedecoder
+ pvmp3_InitDecoder
+ pvmp3_resetDecoder
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ pExt = pointer to the external interface structure. See the file
+ pvmp3decoder_api.h for a description of each field.
+ Data type of pointer to a tPVMP3DecoderExternal
+ structure.
+
+ pMem = void pointer to hide the internal implementation of the library
+ It is cast back to a tmp3dec_file structure. This structure
+ contains information that needs to persist between calls to
+ this function, or is too big to be placed on the stack, even
+ though the data is only needed during execution of this function
+ Data type void pointer, internally pointer to a tmp3dec_file
+ structure.
+
+
+ Outputs:
+ status = ERROR condition. see structure ERROR_CODE
+
+ Pointers and Buffers Modified:
+ pMem contents are modified.
+ pExt: (more detail in the file pvmp3decoder_api.h)
+ inputBufferUsedLength - number of array elements used up by the stream.
+ samplingRate - sampling rate in samples per sec
+ bitRate - bit rate in bits per second, varies frame to frame.
+
+
+
+------------------------------------------------------------------------------
+ FUNCTIONS DESCRIPTION
+
+ pvmp3_framedecoder
+ frame decoder library driver
+ pvmp3_InitDecoder
+ Decoder Initialization
+ pvmp3_resetDecoder
+ Reset Decoder
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+
+#include "pvmp3_framedecoder.h"
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_poly_phase_synthesis.h"
+#include "pvmp3_tables.h"
+#include "pvmp3_imdct_synth.h"
+#include "pvmp3_alias_reduction.h"
+#include "pvmp3_reorder.h"
+#include "pvmp3_dequantize_sample.h"
+#include "pvmp3_stereo_proc.h"
+#include "pvmp3_mpeg2_stereo_proc.h"
+#include "pvmp3_get_side_info.h"
+#include "pvmp3_get_scale_factors.h"
+#include "pvmp3_mpeg2_get_scale_factors.h"
+#include "pvmp3_decode_header.h"
+#include "pvmp3_get_main_data_size.h"
+#include "s_tmp3dec_file.h"
+#include "pvmp3_getbits.h"
+#include "mp3_mem_funcs.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
+ void *pMem)
+{
+
+ ERROR_CODE errorCode = NO_DECODING_ERROR;
+
+ int32 crc_error_count = 0;
+ uint32 sent_crc = 0;
+ uint32 computed_crc = 0;
+
+ tmp3dec_chan *pChVars[CHAN];
+ tmp3dec_file *pVars = (tmp3dec_file *)pMem;
+
+ mp3Header info_data;
+ mp3Header *info = &info_data;
+
+ pVars->inputStream.pBuffer = pExt->pInputBuffer;
+
+
+ pVars->inputStream.usedBits = pExt->inputBufferUsedLength << 3;
+ pVars->inputStream.inputBufferCurrentLength = pExt->inputBufferCurrentLength;
+
+
+ errorCode = pvmp3_decode_header(&pVars->inputStream,
+ info,
+ &computed_crc);
+
+ if (errorCode != NO_DECODING_ERROR)
+ {
+ pExt->outputFrameSize = 0;
+ return errorCode;
+ }
+
+ pVars->num_channels = (info->mode == MPG_MD_MONO) ? 1 : 2;
+ pExt->num_channels = pVars->num_channels;
+
+ int32 outputFrameSize = (info->version_x == MPEG_1) ?
+ 2 * SUBBANDS_NUMBER * FILTERBANK_BANDS :
+ SUBBANDS_NUMBER * FILTERBANK_BANDS;
+
+ outputFrameSize = (info->mode == MPG_MD_MONO) ? outputFrameSize : outputFrameSize << 1;
+
+
+ /*
+ * Check if output buffer has enough room to hold output PCM
+ */
+ if (pExt->outputFrameSize >= outputFrameSize)
+ {
+ pExt->outputFrameSize = outputFrameSize;
+ }
+ else
+ {
+ pExt->outputFrameSize = 0;
+ return OUTPUT_BUFFER_TOO_SMALL;
+ }
+
+
+ pChVars[ LEFT] = &pVars->perChan[ LEFT];
+ pChVars[RIGHT] = &pVars->perChan[RIGHT];
+
+
+
+
+ if (info->error_protection)
+ {
+ /*
+ * Get crc content
+ */
+ sent_crc = getUpTo17bits(&pVars->inputStream, 16);
+ }
+
+
+ if (info->layer_description == 3)
+ {
+ int32 gr;
+ int32 ch;
+ uint32 main_data_end;
+ int32 bytes_to_discard;
+ int16 *ptrOutBuffer = pExt->pOutputBuffer;
+
+ /*
+ * Side Information must be extracted from the bitstream and store for use
+ * during the decoded of the associated frame
+ */
+
+ errorCode = pvmp3_get_side_info(&pVars->inputStream,
+ &pVars->sideInfo,
+ info,
+ &computed_crc);
+
+ if (errorCode != NO_DECODING_ERROR)
+ {
+ pExt->outputFrameSize = 0;
+ return errorCode;
+ }
+
+ /*
+ * If CRC was sent, check that matches the one got while parsing data
+ * disable crc if this is the desired mode
+ */
+ if (info->error_protection)
+ {
+ if ((computed_crc != sent_crc) && pExt->crcEnabled)
+ {
+ crc_error_count++;
+ }
+ }
+
+ /*
+ * main data (scalefactors, Huffman coded, etc,) are not necessarily located
+ * adjacent to the side-info. Beginning of main data is located using
+ * field "main_data_begin" of the current frame. The length does not include
+ * header and side info.
+ * "main_data_begin" points to the first bit of main data of a frame. It is a negative
+ * offset in bytes from the first byte of the sync word
+ * main_data_begin = 0 <===> main data start rigth after side info.
+ */
+
+ int32 temp = pvmp3_get_main_data_size(info, pVars);
+
+
+ /*
+ * Check if available data holds a full frame, if not flag an error
+ */
+
+ if ((uint32)pVars->predicted_frame_size > pVars->inputStream.inputBufferCurrentLength)
+ {
+ pExt->outputFrameSize = 0;
+ return NO_ENOUGH_MAIN_DATA_ERROR;
+ }
+
+ /*
+ * Fill in internal circular buffer
+ */
+ fillMainDataBuf(pVars, temp);
+
+
+ main_data_end = pVars->mainDataStream.usedBits >> 3; /* in bytes */
+ if ((main_data_end << 3) < pVars->mainDataStream.usedBits)
+ {
+ main_data_end++;
+ pVars->mainDataStream.usedBits = main_data_end << 3;
+ }
+
+
+ // force signed computation; buffer sizes and offsets are all going to be
+ // well within the constraints of 32-bit signed math.
+ bytes_to_discard = pVars->frame_start
+ - ((int32)pVars->sideInfo.main_data_begin)
+ - ((int32)main_data_end);
+
+
+ if (main_data_end > BUFSIZE) /* check overflow on the buffer */
+ {
+ pVars->frame_start -= BUFSIZE;
+
+ pVars->mainDataStream.usedBits -= (BUFSIZE << 3);
+ }
+
+ pVars->frame_start += temp;
+
+
+ if (bytes_to_discard < 0 || crc_error_count)
+ {
+ /*
+ * Not enough data to decode, then we should avoid reading this
+ * data ( getting/ignoring sido info and scale data)
+ * Main data could be located in the previous frame, so an unaccounted
+ * frame can cause incorrect processing
+ * Just run the polyphase filter to "clean" the history buffer
+ */
+ errorCode = NO_ENOUGH_MAIN_DATA_ERROR;
+
+ /*
+ * Clear the input to these filters
+ */
+
+ pv_memset((void*)pChVars[RIGHT]->work_buf_int32,
+ 0,
+ SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[RIGHT]->work_buf_int32[0]));
+
+ pv_memset((void*)pChVars[LEFT]->work_buf_int32,
+ 0,
+ SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[LEFT]->work_buf_int32[0]));
+
+ /* clear circular buffers, to avoid any glitch */
+ pv_memset((void*)&pChVars[ LEFT]->circ_buffer[576],
+ 0,
+ 480*sizeof(pChVars[ LEFT]->circ_buffer[0]));
+ pv_memset((void*)&pChVars[RIGHT]->circ_buffer[576],
+ 0,
+ 480*sizeof(pChVars[RIGHT]->circ_buffer[0]));
+
+ pChVars[ LEFT]->used_freq_lines = 575;
+ pChVars[RIGHT]->used_freq_lines = 575;
+
+ }
+ else
+ {
+ pVars->mainDataStream.usedBits += (bytes_to_discard << 3);
+ }
+
+ /*
+ * if (fr_ps->header->version_x == MPEG_1), use 2 granules, otherwise just 1
+ */
+ for (gr = 0; gr < (1 + !(info->version_x)); gr++)
+ {
+ if (errorCode != NO_ENOUGH_MAIN_DATA_ERROR)
+ {
+ for (ch = 0; ch < pVars->num_channels; ch++)
+ {
+ int32 part2_start = pVars->mainDataStream.usedBits;
+
+ if (info->version_x == MPEG_1)
+ {
+
+ pvmp3_get_scale_factors(&pVars->scaleFactors[ch],
+ &pVars->sideInfo,
+ gr,
+ ch,
+ &pVars->mainDataStream);
+ }
+ else
+ {
+ int32 * tmp = pVars->Scratch_mem;
+ pvmp3_mpeg2_get_scale_factors(&pVars->scaleFactors[ch],
+ &pVars->sideInfo,
+ gr,
+ ch,
+ info,
+ (uint32 *)tmp,
+ &pVars->mainDataStream);
+ }
+
+ pChVars[ch]->used_freq_lines = pvmp3_huffman_parsing(pChVars[ch]->work_buf_int32,
+ &pVars->sideInfo.ch[ch].gran[gr],
+ pVars,
+ part2_start,
+ info);
+
+
+ pvmp3_dequantize_sample(pChVars[ch]->work_buf_int32,
+ &pVars->scaleFactors[ch],
+ &pVars->sideInfo.ch[ch].gran[gr],
+ pChVars[ch]->used_freq_lines,
+ info);
+
+
+
+
+ } /* for (ch=0; ch<stereo; ch++) */
+
+ if (pVars->num_channels == 2)
+ {
+
+ int32 used_freq_lines = (pChVars[ LEFT]->used_freq_lines >
+ pChVars[RIGHT]->used_freq_lines) ?
+ pChVars[ LEFT]->used_freq_lines :
+ pChVars[RIGHT]->used_freq_lines;
+
+ pChVars[ LEFT]->used_freq_lines = used_freq_lines;
+ pChVars[RIGHT]->used_freq_lines = used_freq_lines;
+
+ if (info->version_x == MPEG_1)
+ {
+ pvmp3_stereo_proc(pChVars[ LEFT]->work_buf_int32,
+ pChVars[RIGHT]->work_buf_int32,
+ &pVars->scaleFactors[RIGHT],
+ &pVars->sideInfo.ch[LEFT].gran[gr],
+ used_freq_lines,
+ info);
+ }
+ else
+ {
+ int32 * tmp = pVars->Scratch_mem;
+ pvmp3_mpeg2_stereo_proc(pChVars[ LEFT]->work_buf_int32,
+ pChVars[RIGHT]->work_buf_int32,
+ &pVars->scaleFactors[RIGHT],
+ &pVars->sideInfo.ch[ LEFT].gran[gr],
+ &pVars->sideInfo.ch[RIGHT].gran[gr],
+ (uint32 *)tmp,
+ used_freq_lines,
+ info);
+ }
+ }
+
+ } /* if ( errorCode != NO_ENOUGH_MAIN_DATA_ERROR) */
+
+ for (ch = 0; ch < pVars->num_channels; ch++)
+ {
+
+ pvmp3_reorder(pChVars[ch]->work_buf_int32,
+ &pVars->sideInfo.ch[ch].gran[gr],
+ &pChVars[ ch]->used_freq_lines,
+ info,
+ pVars->Scratch_mem);
+
+ pvmp3_alias_reduction(pChVars[ch]->work_buf_int32,
+ &pVars->sideInfo.ch[ch].gran[gr],
+ &pChVars[ ch]->used_freq_lines,
+ info);
+
+
+ /*
+ * IMDCT
+ */
+ /* set mxposition
+ * In case of mixed blocks, # of bands with long
+ * blocks (2 or 4) else 0
+ */
+ uint16 mixedBlocksLongBlocks = 0; /* 0 = long or short, 2=mixed, 4=mixed 2.5@8000 */
+ if (pVars->sideInfo.ch[ch].gran[gr].mixed_block_flag &&
+ pVars->sideInfo.ch[ch].gran[gr].window_switching_flag)
+ {
+ if ((info->version_x == MPEG_2_5) && (info->sampling_frequency == 2))
+ {
+ mixedBlocksLongBlocks = 4; /* mpeg2.5 @ 8 KHz */
+ }
+ else
+ {
+ mixedBlocksLongBlocks = 2;
+ }
+ }
+
+ pvmp3_imdct_synth(pChVars[ch]->work_buf_int32,
+ pChVars[ch]->overlap,
+ pVars->sideInfo.ch[ch].gran[gr].block_type,
+ mixedBlocksLongBlocks,
+ pChVars[ ch]->used_freq_lines,
+ pVars->Scratch_mem);
+
+
+ /*
+ * Polyphase synthesis
+ */
+
+ pvmp3_poly_phase_synthesis(pChVars[ch],
+ pVars->num_channels,
+ pExt->equalizerType,
+ &ptrOutBuffer[ch]);
+
+
+ }/* end ch loop */
+
+ ptrOutBuffer += pVars->num_channels * SUBBANDS_NUMBER * FILTERBANK_BANDS;
+ } /* for (gr=0;gr<Max_gr;gr++) */
+
+ /* skip ancillary data */
+ if (info->bitrate_index > 0)
+ { /* if not free-format */
+
+ int32 ancillary_data_lenght = pVars->predicted_frame_size << 3;
+
+ ancillary_data_lenght -= pVars->inputStream.usedBits;
+
+ /* skip ancillary data */
+ if (ancillary_data_lenght > 0)
+ {
+ pVars->inputStream.usedBits += ancillary_data_lenght;
+ }
+
+ }
+
+ /*
+ * This overrides a possible NO_ENOUGH_MAIN_DATA_ERROR
+ */
+ errorCode = NO_DECODING_ERROR;
+
+ }
+ else
+ {
+ /*
+ * The info on the header leads to an unsupported layer, more data
+ * will not fix this, so this is a bad frame,
+ */
+
+ pExt->outputFrameSize = 0;
+ return UNSUPPORTED_LAYER;
+ }
+
+ pExt->inputBufferUsedLength = pVars->inputStream.usedBits >> 3;
+ pExt->totalNumberOfBitsUsed += pVars->inputStream.usedBits;
+ pExt->version = info->version_x;
+ pExt->samplingRate = mp3_s_freq[info->version_x][info->sampling_frequency];
+ pExt->bitRate = mp3_bitrate[pExt->version][info->bitrate_index];
+
+
+ /*
+ * Always verify buffer overrun condition
+ */
+
+ if (pExt->inputBufferUsedLength > pExt->inputBufferCurrentLength)
+ {
+ pExt->outputFrameSize = 0;
+ errorCode = NO_ENOUGH_MAIN_DATA_ERROR;
+ }
+
+ return errorCode;
+
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+__inline void fillDataBuf(tmp3Bits *pMainData,
+ uint32 val) /* val to write into the buffer */
+{
+ pMainData->pBuffer[module(pMainData->offset++, BUFSIZE)] = (uint8)val;
+}
+
+
+void fillMainDataBuf(void *pMem, int32 temp)
+{
+ tmp3dec_file *pVars = (tmp3dec_file *)pMem;
+
+
+ int32 offset = (pVars->inputStream.usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
+
+ /*
+ * Check if input circular buffer boundaries need to be enforced
+ */
+ if ((offset + temp) < BUFSIZE)
+ {
+ uint8 * ptr = pVars->inputStream.pBuffer + offset;
+
+ offset = pVars->mainDataStream.offset;
+
+ /*
+ * Check if main data circular buffer boundaries need to be enforced
+ */
+ if ((offset + temp) < BUFSIZE)
+ {
+ pv_memcpy((pVars->mainDataStream.pBuffer + offset), ptr, temp*sizeof(uint8));
+ pVars->mainDataStream.offset += temp;
+ }
+ else
+ {
+ int32 tmp1 = *(ptr++);
+ for (int32 nBytes = temp >> 1; nBytes != 0; nBytes--) /* read main data. */
+ {
+ int32 tmp2 = *(ptr++);
+ fillDataBuf(&pVars->mainDataStream, tmp1);
+ fillDataBuf(&pVars->mainDataStream, tmp2);
+ tmp1 = *(ptr++);
+ }
+
+ if (temp&1)
+ {
+ fillDataBuf(&pVars->mainDataStream, tmp1);
+ }
+
+ /* adjust circular buffer counter */
+ pVars->mainDataStream.offset = module(pVars->mainDataStream.offset, BUFSIZE);
+ }
+ }
+ else
+ {
+ for (int32 nBytes = temp >> 1; nBytes != 0; nBytes--) /* read main data. */
+ {
+ fillDataBuf(&pVars->mainDataStream, *(pVars->inputStream.pBuffer + module(offset++ , BUFSIZE)));
+ fillDataBuf(&pVars->mainDataStream, *(pVars->inputStream.pBuffer + module(offset++ , BUFSIZE)));
+ }
+ if (temp&1)
+ {
+ fillDataBuf(&pVars->mainDataStream, *(pVars->inputStream.pBuffer + module(offset , BUFSIZE)));
+ }
+ }
+
+
+ pVars->inputStream.usedBits += (temp) << INBUF_ARRAY_INDEX_SHIFT;
+}
+
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+uint32 pvmp3_decoderMemRequirements(void)
+{
+ uint32 size;
+
+ size = (uint32) sizeof(tmp3dec_file);
+ return (size);
+}
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_decode_huff_cw.h"
+
+void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt,
+ void *pMem)
+{
+
+ tmp3dec_file *pVars;
+ huffcodetab *pHuff;
+
+ pVars = (tmp3dec_file *)pMem;
+ memset(pVars, 0, sizeof(*pVars));
+
+ pExt->totalNumberOfBitsUsed = 0;
+ pExt->inputBufferCurrentLength = 0;
+ pExt->inputBufferUsedLength = 0;
+
+ pVars->inputStream.pBuffer = pExt->pInputBuffer;
+
+ /*
+ * Initialize huffman decoding table
+ */
+
+ pHuff = pVars->ht;
+ pHuff[0].linbits = 0;
+ pHuff[0].pdec_huff_tab = pvmp3_decode_huff_cw_tab0;
+ pHuff[1].linbits = 0;
+ pHuff[1].pdec_huff_tab = pvmp3_decode_huff_cw_tab1;
+ pHuff[2].linbits = 0;
+ pHuff[2].pdec_huff_tab = pvmp3_decode_huff_cw_tab2;
+ pHuff[3].linbits = 0;
+ pHuff[3].pdec_huff_tab = pvmp3_decode_huff_cw_tab3;
+ pHuff[4].linbits = 0;
+ pHuff[4].pdec_huff_tab = pvmp3_decode_huff_cw_tab0; /* tbl 4 is not used */
+ pHuff[5].linbits = 4;
+ pHuff[5].pdec_huff_tab = pvmp3_decode_huff_cw_tab5;
+ pHuff[6].linbits = 0;
+ pHuff[6].pdec_huff_tab = pvmp3_decode_huff_cw_tab6;
+ pHuff[7].linbits = 0;
+ pHuff[7].pdec_huff_tab = pvmp3_decode_huff_cw_tab7;
+ pHuff[8].linbits = 0;
+ pHuff[8].pdec_huff_tab = pvmp3_decode_huff_cw_tab8;
+ pHuff[9].linbits = 0;
+ pHuff[9].pdec_huff_tab = pvmp3_decode_huff_cw_tab9;
+ pHuff[10].linbits = 0;
+ pHuff[10].pdec_huff_tab = pvmp3_decode_huff_cw_tab10;
+ pHuff[11].linbits = 0;
+ pHuff[11].pdec_huff_tab = pvmp3_decode_huff_cw_tab11;
+ pHuff[12].linbits = 0;
+ pHuff[12].pdec_huff_tab = pvmp3_decode_huff_cw_tab12;
+ pHuff[13].linbits = 0;
+ pHuff[13].pdec_huff_tab = pvmp3_decode_huff_cw_tab13;
+ pHuff[14].linbits = 0;
+ pHuff[14].pdec_huff_tab = pvmp3_decode_huff_cw_tab0; /* tbl 14 is not used */
+ pHuff[15].linbits = 0;
+ pHuff[15].pdec_huff_tab = pvmp3_decode_huff_cw_tab15;
+ pHuff[16].linbits = 1;
+ pHuff[16].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[17].linbits = 2;
+ pHuff[17].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[18].linbits = 3;
+ pHuff[18].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[19].linbits = 4;
+ pHuff[19].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[20].linbits = 6;
+ pHuff[20].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[21].linbits = 8;
+ pHuff[21].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[22].linbits = 10;
+ pHuff[22].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[23].linbits = 13;
+ pHuff[23].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
+ pHuff[24].linbits = 4;
+ pHuff[24].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[25].linbits = 5;
+ pHuff[25].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[26].linbits = 6;
+ pHuff[26].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[27].linbits = 7;
+ pHuff[27].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[28].linbits = 8;
+ pHuff[28].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[29].linbits = 9;
+ pHuff[29].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[30].linbits = 11;
+ pHuff[30].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[31].linbits = 13;
+ pHuff[31].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
+ pHuff[32].linbits = 0;
+ pHuff[32].pdec_huff_tab = pvmp3_decode_huff_cw_tab32;
+ pHuff[33].linbits = 0;
+ pHuff[33].pdec_huff_tab = pvmp3_decode_huff_cw_tab33;
+
+ /*
+ * Initialize polysynthesis circular buffer mechanism
+ */
+ /* clear buffers */
+
+ pvmp3_resetDecoder(pMem);
+
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void pvmp3_resetDecoder(void *pMem)
+{
+
+ tmp3dec_file *pVars;
+ tmp3dec_chan *pChVars[CHAN];
+
+ pVars = (tmp3dec_file *)pMem;
+ pChVars[ LEFT] = &pVars->perChan[ LEFT];
+ pChVars[RIGHT] = &pVars->perChan[RIGHT];
+
+ pVars->frame_start = 0;
+
+ pVars->mainDataStream.offset = 0;
+
+ pVars->mainDataStream.pBuffer = pVars->mainDataBuffer;
+ pVars->mainDataStream.usedBits = 0;
+
+
+ pVars->inputStream.usedBits = 0; // in bits
+
+
+ pChVars[ LEFT]->used_freq_lines = 575;
+ pChVars[RIGHT]->used_freq_lines = 575;
+
+
+ /*
+ * Initialize polysynthesis circular buffer mechanism
+ */
+
+ pv_memset((void*)&pChVars[ LEFT]->circ_buffer[576],
+ 0,
+ 480*sizeof(pChVars[ LEFT]->circ_buffer[0]));
+ pv_memset((void*)&pChVars[RIGHT]->circ_buffer[576],
+ 0,
+ 480*sizeof(pChVars[RIGHT]->circ_buffer[0]));
+
+
+ pv_memset((void*)pChVars[ LEFT]->overlap,
+ 0,
+ SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[ LEFT]->overlap[0]));
+
+
+ pv_memset((void*)pChVars[ RIGHT]->overlap,
+ 0,
+ SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[ RIGHT]->overlap[0]));
+
+
+
+
+
+ /*
+ * Clear all the structures
+ */
+
+
+ pv_memset((void*)&pVars->scaleFactors[RIGHT],
+ 0,
+ sizeof(mp3ScaleFactors));
+
+ pv_memset((void*)&pVars->scaleFactors[LEFT],
+ 0,
+ sizeof(mp3ScaleFactors));
+
+ pv_memset((void*)&pVars->sideInfo,
+ 0,
+ sizeof(mp3SideInfo));
+
+ pv_memset((void*)&pVars->sideInfo,
+ 0,
+ sizeof(mp3SideInfo));
+
+}
diff --git a/media/codecs/mp3dec/src/pvmp3_framedecoder.h b/media/codecs/mp3dec/src/pvmp3_framedecoder.h
new file mode 100644
index 0000000..f6d4a35
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_framedecoder.h
@@ -0,0 +1,115 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_framedecoder.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_FRAMEDECODER_H
+#define PVMP3_FRAMEDECODER_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3decoder_api.h"
+#include "s_mp3bits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
+ void *pMem);
+
+
+
+ uint32 pvmp3_decoderMemRequirements(void);
+
+ void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt,
+ void *pMem);
+
+
+ void pvmp3_resetDecoder(void *pMem);
+
+
+ void fillMainDataBuf(void *pMem, int32 temp);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_get_main_data_size.cpp b/media/codecs/mp3dec/src/pvmp3_get_main_data_size.cpp
new file mode 100644
index 0000000..423a7b1
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_get_main_data_size.cpp
@@ -0,0 +1,180 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_get_main_data_size.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Input
+ mp3Header *info, pointer to mp3 header info structure
+ tmp3dec_file *pVars
+ contains information that needs to persist
+ between calls to this function, or is too big to
+ be placed on the stack, even though the data is
+ only needed during execution of this function
+
+ Returns
+
+ main data frame size
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ get main data frame size
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_tables.h"
+#include "pvmp3_get_main_data_size.h"
+#include "pv_mp3dec_fxd_op.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int32 pvmp3_get_main_data_size(mp3Header *info,
+ tmp3dec_file *pVars)
+{
+
+
+ int32 numBytes = fxp_mul32_Q28(mp3_bitrate[info->version_x][info->bitrate_index] << 20,
+ inv_sfreq[info->sampling_frequency]);
+
+
+ numBytes >>= (20 - info->version_x);
+
+ /*
+ * Remove the size of the side information from the main data total
+ */
+ if (info->version_x == MPEG_1)
+ {
+ pVars->predicted_frame_size = numBytes;
+ if (info->mode == MPG_MD_MONO)
+ {
+ numBytes -= 17;
+ }
+ else
+ {
+ numBytes -= 32;
+ }
+ }
+ else
+ {
+ numBytes >>= 1;
+ pVars->predicted_frame_size = numBytes;
+
+ if (info->mode == MPG_MD_MONO)
+ {
+ numBytes -= 9;
+ }
+ else
+ {
+ numBytes -= 17;
+ }
+ }
+
+ if (info->padding)
+ {
+ numBytes++;
+ pVars->predicted_frame_size++;
+ }
+
+ if (info->error_protection)
+ {
+ numBytes -= 6;
+ }
+ else
+ {
+ numBytes -= 4;
+ }
+
+
+ if (numBytes < 0)
+ {
+ numBytes = 0;
+ }
+
+ return(numBytes);
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_get_main_data_size.h b/media/codecs/mp3dec/src/pvmp3_get_main_data_size.h
new file mode 100644
index 0000000..8e9eaa8
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_get_main_data_size.h
@@ -0,0 +1,101 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_get_main_data_size.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_GET_MAIN_DATA_SIZE_H
+#define PVMP3_GET_MAIN_DATA_SIZE_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+#include "s_tmp3dec_file.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int32 pvmp3_get_main_data_size(mp3Header *info,
+ tmp3dec_file *pVars);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_get_scale_factors.cpp b/media/codecs/mp3dec/src/pvmp3_get_scale_factors.cpp
new file mode 100644
index 0000000..d4a2060
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_get_scale_factors.cpp
@@ -0,0 +1,226 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_get_scale_factors.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Input
+ mp3ScaleFactors *scalefac,
+ mp3SideInfo *si, side info
+ int32 gr, granule
+ int32 ch, channel
+ tbits *pMainData bit stream
+
+ Returns
+
+ mp3ScaleFactors *scalefac, scale factors
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ get scale factors
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_get_scale_factors.h"
+#include "pvmp3_getbits.h"
+#include "mp3_mem_funcs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define Qfmt_28(a)(int32(double(0x10000000)*(a)))
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int32 slen[2][16] =
+{
+ {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
+ {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
+};
+
+const struct
+{
+ int32 l[5];
+ int32 s[3];
+} sfbtable =
+{
+ {0, 6, 11, 16, 21},
+ {0, 6, 12}
+};
+
+const int32 long_sfbtable[4] = { 6, 5, 5, 5};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_get_scale_factors(mp3ScaleFactors *scalefac,
+ mp3SideInfo *si,
+ int32 gr,
+ int32 ch,
+ tmp3Bits *pMainData)
+{
+ int32 sfb;
+ int32 i;
+ int32 window;
+ granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
+
+ if (gr_info->window_switching_flag && (gr_info->block_type == 2))
+ {
+ if (gr_info->mixed_block_flag)
+ { /* MIXED */
+ for (sfb = 0; sfb < 8; sfb++)
+ {
+ scalefac->l[sfb] = getNbits(pMainData, slen[0][gr_info->scalefac_compress]);
+ }
+
+ for (sfb = 3; sfb < 6; sfb++)
+ {
+ for (window = 0; window < 3; window++)
+ {
+ scalefac->s[window][sfb] = getNbits(pMainData, slen[0][gr_info->scalefac_compress]);
+ }
+ }
+ for (sfb = 6; sfb < 12; sfb++)
+ {
+ for (window = 0; window < 3; window++)
+ {
+ scalefac->s[window][sfb] = getNbits(pMainData, slen[1][gr_info->scalefac_compress]);
+ }
+ }
+ }
+ else
+ { /* SHORT*/
+ for (i = 0; i < 2; i++)
+ {
+ for (sfb = sfbtable.s[i]; sfb < sfbtable.s[i+1]; sfb++)
+ {
+ for (window = 0; window < 3; window++)
+ {
+ scalefac->s[window][sfb] = getNbits(pMainData, slen[i][gr_info->scalefac_compress]);
+ }
+ }
+ }
+ }
+
+ scalefac->s[0][12] = 0; /* sfb = 12 win= 0 */
+ scalefac->s[1][12] = 0; /* sfb = 12 win= 1 */
+ scalefac->s[2][12] = 0; /* sfb = 12 win= 2 */
+ }
+ else
+ { /* LONG types 0,1,3 */
+
+ int32 *ptr = &scalefac->l[0];
+
+ for (i = 0; i < 4; i++)
+ {
+ int32 tmp4 = long_sfbtable[i];
+
+ if ((si->ch[ch].scfsi[i] == 0) || (gr == 0))
+ {
+ int32 tmp1 = slen[(i>>1)][gr_info->scalefac_compress];
+
+ if (tmp1)
+ {
+ int32 tmp2 = tmp1 * tmp4;
+ uint32 tmp3 = getNbits(pMainData, tmp2);
+ tmp4 = 32 - tmp1;
+ for (; tmp2 > 0; tmp2 -= tmp1)
+ {
+ *(ptr++) = (tmp3 << (32 - tmp2)) >> tmp4;
+ }
+ }
+ else
+ {
+ for (sfb = tmp4; sfb != 0; sfb--)
+ {
+ *(ptr++) = 0;
+ }
+
+ }
+ }
+ else
+ {
+ ptr += tmp4;
+ }
+ }
+ scalefac->l[21] = 0;
+ scalefac->l[22] = 0;
+ }
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_get_scale_factors.h b/media/codecs/mp3dec/src/pvmp3_get_scale_factors.h
new file mode 100644
index 0000000..d4f262bf
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_get_scale_factors.h
@@ -0,0 +1,104 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_get_scale_factors.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_GET_SCALE_FACTORS_H
+#define PVMP3_GET_SCALE_FACTORS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+#include "s_mp3bits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_get_scale_factors(mp3ScaleFactors *scalefac,
+ mp3SideInfo *si,
+ int32 gr,
+ int32 ch,
+ tmp3Bits *pMainData);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_get_side_info.cpp b/media/codecs/mp3dec/src/pvmp3_get_side_info.cpp
new file mode 100644
index 0000000..d644207
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_get_side_info.cpp
@@ -0,0 +1,285 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_get_side_info.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ mp3SideInfo *si,
+ mp3Header *info, mp3 header information
+ uint32 *crc initialized crc value (if enabled)
+
+
+ Returns
+
+ mp3SideInfo *si, side information
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ acquires side information
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_get_side_info.h"
+#include "pvmp3_crc.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+ERROR_CODE pvmp3_get_side_info(tmp3Bits *inputStream,
+ mp3SideInfo *si,
+ mp3Header *info,
+ uint32 *crc)
+{
+ int32 ch, gr;
+ uint32 tmp;
+
+ int stereo = (info->mode == MPG_MD_MONO) ? 1 : 2;
+
+ if (info->version_x == MPEG_1)
+ {
+ if (stereo == 1)
+ {
+ tmp = getbits_crc(inputStream, 14, crc, info->error_protection);
+ si->main_data_begin = (tmp << 18) >> 23; /* 9 */
+ si->private_bits = (tmp << 27) >> 27; /* 5 */
+ }
+ else
+ {
+ tmp = getbits_crc(inputStream, 12, crc, info->error_protection);
+ si->main_data_begin = (tmp << 20) >> 23; /* 9 */
+ si->private_bits = (tmp << 29) >> 29; /* 3 */
+
+ }
+
+ for (ch = 0; ch < stereo; ch++)
+ {
+ tmp = getbits_crc(inputStream, 4, crc, info->error_protection);
+ si->ch[ch].scfsi[0] = (tmp << 28) >> 31; /* 1 */
+ si->ch[ch].scfsi[1] = (tmp << 29) >> 31; /* 1 */
+ si->ch[ch].scfsi[2] = (tmp << 30) >> 31; /* 1 */
+ si->ch[ch].scfsi[3] = tmp & 1; /* 1 */
+ }
+
+ for (gr = 0; gr < 2 ; gr++)
+ {
+ for (ch = 0; ch < stereo; ch++)
+ {
+ si->ch[ch].gran[gr].part2_3_length = getbits_crc(inputStream, 12, crc, info->error_protection);
+ tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
+
+ si->ch[ch].gran[gr].big_values = (tmp << 10) >> 23; /* 9 */
+ si->ch[ch].gran[gr].global_gain = (int32)((tmp << 19) >> 24) - 210; /* 8 */
+ si->ch[ch].gran[gr].scalefac_compress = (tmp << 27) >> 28; /* 4 */
+ si->ch[ch].gran[gr].window_switching_flag = tmp & 1; /* 1 */
+
+ if (si->ch[ch].gran[gr].window_switching_flag)
+ {
+ tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
+
+ si->ch[ch].gran[gr].block_type = (tmp << 10) >> 30; /* 2 */;
+ si->ch[ch].gran[gr].mixed_block_flag = (tmp << 12) >> 31; /* 1 */;
+
+ si->ch[ch].gran[gr].table_select[0] = (tmp << 13) >> 27; /* 5 */;
+ si->ch[ch].gran[gr].table_select[1] = (tmp << 18) >> 27; /* 5 */;
+
+ si->ch[ch].gran[gr].subblock_gain[0] = (tmp << 23) >> 29; /* 3 */;
+ si->ch[ch].gran[gr].subblock_gain[1] = (tmp << 26) >> 29; /* 3 */;
+ si->ch[ch].gran[gr].subblock_gain[2] = (tmp << 29) >> 29; /* 3 */;
+
+ /* Set region_count parameters since they are implicit in this case. */
+
+ if (si->ch[ch].gran[gr].block_type == 0)
+ {
+ return(SIDE_INFO_ERROR);
+ }
+ else if ((si->ch[ch].gran[gr].block_type == 2)
+ && (si->ch[ch].gran[gr].mixed_block_flag == 0))
+ {
+ si->ch[ch].gran[gr].region0_count = 8; /* MI 9; */
+ si->ch[ch].gran[gr].region1_count = 12;
+ }
+ else
+ {
+ si->ch[ch].gran[gr].region0_count = 7; /* MI 8; */
+ si->ch[ch].gran[gr].region1_count = 13;
+ }
+ }
+ else
+ {
+ tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
+
+ si->ch[ch].gran[gr].table_select[0] = (tmp << 10) >> 27; /* 5 */;
+ si->ch[ch].gran[gr].table_select[1] = (tmp << 15) >> 27; /* 5 */;
+ si->ch[ch].gran[gr].table_select[2] = (tmp << 20) >> 27; /* 5 */;
+
+ si->ch[ch].gran[gr].region0_count = (tmp << 25) >> 28; /* 4 */;
+ si->ch[ch].gran[gr].region1_count = (tmp << 29) >> 29; /* 3 */;
+
+ si->ch[ch].gran[gr].block_type = 0;
+ }
+
+ tmp = getbits_crc(inputStream, 3, crc, info->error_protection);
+ si->ch[ch].gran[gr].preflag = (tmp << 29) >> 31; /* 1 */
+ si->ch[ch].gran[gr].scalefac_scale = (tmp << 30) >> 31; /* 1 */
+ si->ch[ch].gran[gr].count1table_select = tmp & 1; /* 1 */
+ }
+ }
+ }
+ else /* Layer 3 LSF */
+ {
+ si->main_data_begin = getbits_crc(inputStream, 8, crc, info->error_protection);
+ si->private_bits = getbits_crc(inputStream, stereo, crc, info->error_protection);
+
+ for (ch = 0; ch < stereo; ch++)
+ {
+ tmp = getbits_crc(inputStream, 21, crc, info->error_protection);
+ si->ch[ch].gran[0].part2_3_length = (tmp << 11) >> 20; /* 12 */
+ si->ch[ch].gran[0].big_values = (tmp << 23) >> 23; /* 9 */
+
+ tmp = getbits_crc(inputStream, 18, crc, info->error_protection);
+ si->ch[ch].gran[0].global_gain = ((tmp << 14) >> 24) - 210; /* 8 */
+ si->ch[ch].gran[0].scalefac_compress = (tmp << 22) >> 23; /* 9 */
+ si->ch[ch].gran[0].window_switching_flag = tmp & 1; /* 1 */
+
+ if (si->ch[ch].gran[0].window_switching_flag)
+ {
+
+ tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
+
+ si->ch[ch].gran[0].block_type = (tmp << 10) >> 30; /* 2 */;
+ si->ch[ch].gran[0].mixed_block_flag = (tmp << 12) >> 31; /* 1 */;
+
+ si->ch[ch].gran[0].table_select[0] = (tmp << 13) >> 27; /* 5 */;
+ si->ch[ch].gran[0].table_select[1] = (tmp << 18) >> 27; /* 5 */;
+
+ si->ch[ch].gran[0].subblock_gain[0] = (tmp << 23) >> 29; /* 3 */;
+ si->ch[ch].gran[0].subblock_gain[1] = (tmp << 26) >> 29; /* 3 */;
+ si->ch[ch].gran[0].subblock_gain[2] = (tmp << 29) >> 29; /* 3 */;
+
+ /* Set region_count parameters since they are implicit in this case. */
+
+ if (si->ch[ch].gran[0].block_type == 0)
+ {
+ return(SIDE_INFO_ERROR);
+ }
+ else if ((si->ch[ch].gran[0].block_type == 2)
+ && (si->ch[ch].gran[0].mixed_block_flag == 0))
+ {
+ si->ch[ch].gran[0].region0_count = 8; /* MI 9; */
+ si->ch[ch].gran[0].region1_count = 12;
+ }
+ else
+ {
+ si->ch[ch].gran[0].region0_count = 7; /* MI 8; */
+ si->ch[ch].gran[0].region1_count = 13;
+ }
+ }
+ else
+ {
+ tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
+
+ si->ch[ch].gran[0].table_select[0] = (tmp << 10) >> 27; /* 5 */;
+ si->ch[ch].gran[0].table_select[1] = (tmp << 15) >> 27; /* 5 */;
+ si->ch[ch].gran[0].table_select[2] = (tmp << 20) >> 27; /* 5 */;
+
+ si->ch[ch].gran[0].region0_count = (tmp << 25) >> 28; /* 4 */;
+ si->ch[ch].gran[0].region1_count = (tmp << 29) >> 29; /* 3 */;
+
+ si->ch[ch].gran[0].block_type = 0;
+ }
+
+ tmp = getbits_crc(inputStream, 2, crc, info->error_protection);
+ si->ch[ch].gran[0].scalefac_scale = tmp >> 1; /* 1 */
+ si->ch[ch].gran[0].count1table_select = tmp & 1; /* 1 */
+
+ }
+ }
+ return (NO_DECODING_ERROR);
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_get_side_info.h b/media/codecs/mp3dec/src/pvmp3_get_side_info.h
new file mode 100644
index 0000000..2d6ccd8
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_get_side_info.h
@@ -0,0 +1,102 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_get_side_info.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_GET_SIDE_INFO_H
+#define PVMP3_GET_SIDE_INFO_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+#include "s_mp3bits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ ERROR_CODE pvmp3_get_side_info(tmp3Bits *inputStream,
+ mp3SideInfo *si,
+ mp3Header *info,
+ uint32 *crc);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_getbits.cpp b/media/codecs/mp3dec/src/pvmp3_getbits.cpp
new file mode 100644
index 0000000..8ff7953
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_getbits.cpp
@@ -0,0 +1,257 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_getbits.cpp
+
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+
+ tmp3Bits *inputStream, structure holding the input stream parameters
+ int32 neededBits number of bits to read from the bit stream
+
+ Outputs:
+
+ word parsed from teh bitstream, with size neededBits-bits,
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_getbits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+uint32 getNbits(tmp3Bits *ptBitStream,
+ int32 neededBits) /* number of bits to read from the bitstream (up to 25) */
+{
+
+ uint32 offset;
+ uint32 bitIndex;
+ uint8 Elem; /* Needs to be same type as pInput->pBuffer */
+ uint8 Elem1;
+ uint8 Elem2;
+ uint8 Elem3;
+ uint32 returnValue = 0;
+
+ if (!neededBits)
+ {
+ return (returnValue);
+ }
+
+ offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
+
+ Elem = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
+ Elem1 = *(ptBitStream->pBuffer + module(offset + 1, BUFSIZE));
+ Elem2 = *(ptBitStream->pBuffer + module(offset + 2, BUFSIZE));
+ Elem3 = *(ptBitStream->pBuffer + module(offset + 3, BUFSIZE));
+
+
+ returnValue = (((uint32)(Elem)) << 24) |
+ (((uint32)(Elem1)) << 16) |
+ (((uint32)(Elem2)) << 8) |
+ ((uint32)(Elem3));
+
+ /* Remove extra high bits by shifting up */
+ bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
+
+ /* This line is faster than to mask off the high bits. */
+ returnValue <<= bitIndex;
+
+ /* Move the field down. */
+ returnValue >>= (32 - neededBits);
+
+ ptBitStream->usedBits += neededBits;
+
+ return (returnValue);
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+uint16 getUpTo9bits(tmp3Bits *ptBitStream,
+ int32 neededBits) /* number of bits to read from the bit stream 2 to 9 */
+{
+
+ uint32 offset;
+ uint32 bitIndex;
+ uint8 Elem; /* Needs to be same type as pInput->pBuffer */
+ uint8 Elem1;
+ uint16 returnValue;
+
+ offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
+
+ Elem = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
+ Elem1 = *(ptBitStream->pBuffer + module(offset + 1, BUFSIZE));
+
+
+ returnValue = (((uint16)(Elem)) << 8) |
+ ((uint16)(Elem1));
+
+ /* Remove extra high bits by shifting up */
+ bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
+
+ ptBitStream->usedBits += neededBits;
+ /* This line is faster than to mask off the high bits. */
+ returnValue = (returnValue << (bitIndex));
+
+ /* Move the field down. */
+
+ return (uint16)(returnValue >> (16 - neededBits));
+
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+uint32 getUpTo17bits(tmp3Bits *ptBitStream,
+ int32 neededBits) /* number of bits to read from the bit stream 2 to 8 */
+{
+
+ uint32 offset;
+ uint32 bitIndex;
+ uint8 Elem; /* Needs to be same type as pInput->pBuffer */
+ uint8 Elem1;
+ uint8 Elem2;
+ uint32 returnValue;
+
+ offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
+
+ Elem = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
+ Elem1 = *(ptBitStream->pBuffer + module(offset + 1, BUFSIZE));
+ Elem2 = *(ptBitStream->pBuffer + module(offset + 2, BUFSIZE));
+
+
+ returnValue = (((uint32)(Elem)) << 16) |
+ (((uint32)(Elem1)) << 8) |
+ ((uint32)(Elem2));
+
+ /* Remove extra high bits by shifting up */
+ bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
+
+ ptBitStream->usedBits += neededBits;
+ /* This line is faster than to mask off the high bits. */
+ returnValue = 0xFFFFFF & (returnValue << (bitIndex));
+
+ /* Move the field down. */
+
+ return (uint32)(returnValue >> (24 - neededBits));
+
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+uint8 get1bit(tmp3Bits *ptBitStream) /* number of bits to read from the bit stream */
+{
+
+ uint32 offset;
+ uint32 bitIndex;
+ uint8 returnValue;
+
+ offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
+
+ returnValue = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
+
+ /* Remove extra high bits by shifting up */
+ bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
+ ptBitStream->usedBits++;
+
+ /* This line is faster than to mask off the high bits. */
+ returnValue = (returnValue << (bitIndex));
+
+ return (uint8)(returnValue >> 7);
+
+}
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_getbits.h b/media/codecs/mp3dec/src/pvmp3_getbits.h
new file mode 100644
index 0000000..b058b00
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_getbits.h
@@ -0,0 +1,112 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_getbits.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_GETBITS_H
+#define PVMP3_GETBITS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_dec_defs.h"
+#include "s_mp3bits.h"
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define INBUF_ARRAY_INDEX_SHIFT (3)
+#define INBUF_BIT_WIDTH (1<<(INBUF_ARRAY_INDEX_SHIFT))
+#define INBUF_BIT_MODULO_MASK ((INBUF_BIT_WIDTH)-1)
+
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ uint32 getNbits(tmp3Bits *pMainData,
+ int32 neededBits);
+
+ uint16 getUpTo9bits(tmp3Bits *pMainData,
+ int32 neededBits);
+
+ uint32 getUpTo17bits(tmp3Bits *pMainData,
+ int32 neededBits);
+
+ uint8 get1bit(tmp3Bits *pMainData);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_huffman_decoding.cpp b/media/codecs/mp3dec/src/pvmp3_huffman_decoding.cpp
new file mode 100644
index 0000000..5d58cd2
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_huffman_decoding.cpp
@@ -0,0 +1,304 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_huffman_decoding.cpp
+
+ Funtions:
+ pvmp3_huffman_quad_decoding
+ pvmp3_huffman_pair_decoding
+ pvmp3_huffman_pair_decoding_linbits
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ struct huffcodetab *h, pointer to huffman code record
+ int32 *x, returns decoded x value
+ int32 *y, returns decoded y value
+ int32 *v, returns decoded v value (only in quad function)
+ int32 *w, returns decoded w value (only in quad function)
+ tbits *pMainData bit stream
+
+ Outputs:
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ These functions are used to decode huffman codewords from the input
+ bitstream using combined binary search and look-up table approach.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_dec_defs.h"
+#include "pv_mp3_huffman.h"
+#include "pvmp3_getbits.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+void pvmp3_huffman_quad_decoding(struct huffcodetab *h,
+ int32 *is,
+ tmp3Bits *pMainData)
+{
+
+ int32 x;
+ int32 y;
+ int32 v;
+ int32 w;
+
+ y = (*h->pdec_huff_tab)(pMainData);
+
+
+ if (y)
+ {
+ v = (y >> 3);
+
+ if (v)
+ {
+ if (get1bit(pMainData))
+ {
+ v = -v;
+ }
+ }
+ w = (y >> 2) & 1;
+ if (w)
+ {
+ if (get1bit(pMainData))
+ {
+ w = -w;
+ }
+ }
+ x = (y >> 1) & 1;
+ if (x)
+ {
+ if (get1bit(pMainData))
+ {
+ x = -x;
+ }
+ }
+ y = y & 1;
+ if (y)
+ {
+ if (get1bit(pMainData))
+ {
+ y = -y;
+ }
+ }
+
+ }
+ else
+ {
+ v = 0;
+ w = 0;
+ x = 0;
+
+ }
+
+ *is = v;
+ *(is + 1) = w;
+ *(is + 2) = x;
+ *(is + 3) = y;
+
+}
+
+
+
+void pvmp3_huffman_pair_decoding(struct huffcodetab *h, /* pointer to huffman code record */
+ int32 *is,
+ tmp3Bits *pMainData)
+{
+ /* Lookup in Huffman table. */
+ int32 x;
+ int32 y;
+
+ uint16 cw = (*h->pdec_huff_tab)(pMainData);
+
+ /* Process sign and escape encodings for dual tables. */
+
+
+ if (cw)
+ {
+ x = cw >> 4;
+
+ if (x)
+ {
+ if (get1bit(pMainData))
+ {
+ x = -x;
+ }
+ y = cw & 0xf;
+ if (y && get1bit(pMainData))
+ {
+ y = -y;
+ }
+
+ }
+ else
+ {
+ y = cw & 0xf;
+ if (get1bit(pMainData))
+ {
+ y = -y;
+ }
+ }
+
+ *is = x;
+ *(is + 1) = y;
+ }
+ else
+ {
+ *is = 0;
+ *(is + 1) = 0;
+ }
+
+
+
+}
+
+
+
+
+void pvmp3_huffman_pair_decoding_linbits(struct huffcodetab *h, /* pointer to huffman code record */
+ int32 *is,
+ tmp3Bits *pMainData)
+{
+ int32 x;
+ int32 y;
+
+ uint16 cw;
+ /* Lookup in Huffman table. */
+
+
+ cw = (*h->pdec_huff_tab)(pMainData);
+ x = cw >> 4;
+
+ /* Process sign and escape encodings for dual tables. */
+
+
+ if (15 == (uint32)x)
+ {
+ int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
+ x += tmp >> 1;
+ if (tmp&1)
+ {
+ x = -x;
+ }
+ }
+ else if (x)
+ {
+ if (get1bit(pMainData))
+ {
+ x = -x;
+ }
+ }
+
+ y = cw & 0xf;
+ if (15 == (uint32)y)
+ {
+ int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
+ y += tmp >> 1;
+ if (tmp&1)
+ {
+ y = -y;
+ }
+ }
+ else if (y)
+ {
+ if (get1bit(pMainData))
+ {
+ y = -y;
+ }
+ }
+
+ *is = x;
+ *(is + 1) = y;
+
+}
+
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_huffman_parsing.cpp b/media/codecs/mp3dec/src/pvmp3_huffman_parsing.cpp
new file mode 100644
index 0000000..ff815dc
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_huffman_parsing.cpp
@@ -0,0 +1,328 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_huffman_decoding.cpp
+
+ Funtions:
+ pvmp3_huffman_quad_decoding
+ pvmp3_huffman_pair_decoding
+ pvmp3_huffman_pair_decoding_linbits
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+ int32 is[],
+ granuleInfo *grInfo, information for the given channel and granule
+ tmp3dec_file *pVars, decoder state structure
+ int32 part2_start, index to beginning of part 2 data
+ mp3Header *info mp3 header info
+
+ Outputs:
+ int32 is[], uncompressed data
+
+ Return:
+ non zero frequency lines
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ These functions are used to decode huffman codewords from the input
+ bitstream using combined binary search and look-up table approach.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pv_mp3_huffman.h"
+#include "s_mp3bits.h"
+#include "mp3_mem_funcs.h"
+#include "pvmp3_tables.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+int32 pvmp3_huffman_parsing(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ granuleInfo *grInfo,
+ tmp3dec_file *pVars,
+ int32 part2_start,
+ mp3Header *info)
+
+
+{
+ int32 i;
+ int32 region1Start;
+ int32 region2Start;
+ int32 sfreq;
+ uint32 grBits;
+ void(*pt_huff)(struct huffcodetab *, int32 *, tmp3Bits *);
+ struct huffcodetab *h;
+
+ tmp3Bits *pMainData = &pVars->mainDataStream;
+
+
+ /*int32 bt = (*si).ch[ch].gr[gr].window_switching_flag && ((*si).ch[ch].gr[gr].block_type == 2);*/
+
+ sfreq = info->sampling_frequency + info->version_x + (info->version_x << 1);
+
+ /* Find region boundary for short block case. */
+
+
+ if ((grInfo->window_switching_flag) && (grInfo->block_type == 2))
+ {
+ if (info->version_x == MPEG_1)
+ {
+ /* Region2. */
+ region1Start = 12;
+ }
+ else
+ {
+ /* Region2. */
+ i = grInfo->region0_count + 1;
+ region1Start = mp3_sfBandIndex[sfreq].s[i/3];
+ }
+
+ region1Start += region1Start << 1;
+ region2Start = 576; /* No Region2 for short block case. */
+ }
+ else
+ { /* Find region boundary for long block case. */
+ i = grInfo->region0_count + 1;
+ region1Start = mp3_sfBandIndex[sfreq].l[i];
+ region2Start = mp3_sfBandIndex[sfreq].l[i + grInfo->region1_count + 1];
+ }
+
+ /* Read bigvalues area. */
+
+
+ if (grInfo->big_values > (FILTERBANK_BANDS*SUBBANDS_NUMBER >> 1))
+ {
+ grInfo->big_values = (FILTERBANK_BANDS * SUBBANDS_NUMBER >> 1);
+ }
+
+ if ((grInfo->big_values << 1) > (uint32)region2Start)
+ {
+ h = &(pVars->ht[grInfo->table_select[0]]);
+ if (h->linbits)
+ {
+ pt_huff = pvmp3_huffman_pair_decoding_linbits;
+ }
+ else
+ {
+ pt_huff = pvmp3_huffman_pair_decoding;
+ }
+
+ for (i = 0; i < region1Start; i += 2)
+ {
+ (*pt_huff)(h, &is[i], pMainData);
+ }
+
+ h = &(pVars->ht[grInfo->table_select[1]]);
+ if (h->linbits)
+ {
+ pt_huff = pvmp3_huffman_pair_decoding_linbits;
+ }
+ else
+ {
+ pt_huff = pvmp3_huffman_pair_decoding;
+ }
+
+ for (; i < region2Start; i += 2)
+ {
+ (*pt_huff)(h, &is[i], pMainData);
+ }
+
+ h = &(pVars->ht[grInfo->table_select[2]]);
+ if (h->linbits)
+ {
+ pt_huff = pvmp3_huffman_pair_decoding_linbits;
+ }
+ else
+ {
+ pt_huff = pvmp3_huffman_pair_decoding;
+ }
+
+ for (; (uint32)i < (grInfo->big_values << 1); i += 2)
+ {
+ (*pt_huff)(h, &is[i], pMainData);
+ }
+ }
+ else if ((grInfo->big_values << 1) > (uint32)region1Start)
+ {
+ h = &(pVars->ht[grInfo->table_select[0]]);
+ if (h->linbits)
+ {
+ pt_huff = pvmp3_huffman_pair_decoding_linbits;
+ }
+ else
+ {
+ pt_huff = pvmp3_huffman_pair_decoding;
+ }
+ for (i = 0; i < region1Start; i += 2)
+ {
+ (*pt_huff)(h, &is[i], pMainData);
+ }
+
+ h = &(pVars->ht[grInfo->table_select[1]]);
+ if (h->linbits)
+ {
+ pt_huff = pvmp3_huffman_pair_decoding_linbits;
+ }
+ else
+ {
+ pt_huff = pvmp3_huffman_pair_decoding;
+ }
+ for (; (uint32)i < (grInfo->big_values << 1); i += 2)
+ {
+ (*pt_huff)(h, &is[i], pMainData);
+ }
+ }
+ else
+ {
+ h = &(pVars->ht[grInfo->table_select[0]]);
+ if (h->linbits)
+ {
+ pt_huff = pvmp3_huffman_pair_decoding_linbits;
+ }
+ else
+ {
+ pt_huff = pvmp3_huffman_pair_decoding;
+ }
+
+ for (i = 0; (uint32)i < (grInfo->big_values << 1); i += 2)
+ {
+ (*pt_huff)(h, &is[i], pMainData);
+ }
+ }
+
+
+
+ /* Read count1 area. */
+ h = &(pVars->ht[grInfo->count1table_select+32]);
+
+ grBits = part2_start + grInfo->part2_3_length;
+
+ while ((pMainData->usedBits < grBits) &&
+ (i < FILTERBANK_BANDS*SUBBANDS_NUMBER - 4))
+ {
+ pvmp3_huffman_quad_decoding(h, &is[i], pMainData);
+ i += 4;
+ }
+
+ if ((pMainData->usedBits < grBits) &&
+ (i < FILTERBANK_BANDS*SUBBANDS_NUMBER))
+ {
+ pvmp3_huffman_quad_decoding(h, &is[i], pMainData);
+ i += 4;
+
+ if ((i - 2) >= FILTERBANK_BANDS*SUBBANDS_NUMBER)
+ {
+ i -= 2;
+ is[i] = 0;
+ is[(i+1)] = 0;
+ }
+ }
+
+ if (pMainData->usedBits > grBits)
+ {
+ i -= 4;
+
+ if (i < 0 || i > FILTERBANK_BANDS*SUBBANDS_NUMBER - 4)
+ {
+ /* illegal parameters may cause invalid access, set i to 0 */
+ i = 0;
+ }
+
+ is[i] = 0;
+ is[(i+1)] = 0;
+ is[(i+2)] = 0;
+ is[(i+3)] = 0;
+
+ }
+
+ pMainData->usedBits = grBits;
+
+ return (i);
+
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_imdct_synth.cpp b/media/codecs/mp3dec/src/pvmp3_imdct_synth.cpp
new file mode 100644
index 0000000..11961d1
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_imdct_synth.cpp
@@ -0,0 +1,376 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_imdct_synth.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Input
+ int32 in[], Pointer to spec values of current channel
+ int32 overlap[], Pointer to overlap values of current channel
+ uint32 blk_type, Block type
+ int16 mx_band, In case of mixed blocks, # of bands with long
+ blocks (2 or 4) else 0
+ int32 *Scratch_mem
+ Returns
+
+ int32 in[],
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ The frequency lines are preprocessed by the "alias reduction" scheme
+ and fed into the IMDCT matrix, each 18 into one transform block.
+ The first half of the output values are added to the stored overlap
+ values from the last block. These values are new output values and
+ are input values for the polyphase filterbank. The second half of the
+ output values is stored for overlap with the next data granule.
+ The number of windowed samples is 12 for short blocks, and 36 for long
+ blocks
+
+Windowing
+
+ Depending on window_switching_flag[gr][ch], block_type[gr][ch] and
+ mixed_block_flag[gr][ch] different shapes of windows are used.
+ normal window
+ start window
+ stop window
+ short windows
+ Each of the three short blocks is windowed separately.
+ The windowed short blocks must be overlapped and concatenated.
+
+Overlapping and adding with previous block
+
+ The first half (18 values) of the current block (36 values) has to be
+ overlapped with the second half of the previous block. The second half
+ of the current block has to be stored for overlapping with the next block
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_imdct_synth.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_mdct_18.h"
+#include "pvmp3_mdct_6.h"
+#include "mp3_mem_funcs.h"
+
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define LONG 0
+#define START 1
+#define SHORT 2
+#define STOP 3
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+/*
+ * sin(pi/36*(k+0.5)),k=0..35
+ */
+
+const int32 normal_win[36] =
+{
+ Qfmt_31(0.08723877473068f), Qfmt_31(0.26105238444010f), Qfmt_31(0.43287922787620f),
+ Qfmt_31(0.60141159900854f), Qfmt_31(0.76536686473018f), Qfmt_31(0.92349722647006f),
+ Qfmt_31(0.53729960834682f), Qfmt_31(0.60876142900872f), Qfmt_31(0.67559020761566f),
+ Qfmt_31(-0.73727733681012f), Qfmt_31(-0.79335334029124f), Qfmt_31(0.84339144581289f),
+ Qfmt_31(0.88701083317822f), Qfmt_31(0.92387953251129f), Qfmt_31(-0.95371695074823f),
+ Qfmt_31(-0.97629600711993f), Qfmt_31(-0.99144486137381f), Qfmt_31(-0.99904822158186f),
+ Qfmt_31(0.99904822158186f), Qfmt_31(0.99144486137381f), Qfmt_31(0.97629600711993f),
+ Qfmt_31(0.95371695074823f), Qfmt_31(0.92387953251129f), Qfmt_31(0.88701083317822f),
+ Qfmt_31(0.84339144581289f), Qfmt_31(0.79335334029124f), Qfmt_31(0.73727733681012f),
+ Qfmt_31(0.67559020761566f), Qfmt_31(0.60876142900872f), Qfmt_31(0.53729960834682f),
+ Qfmt_31(0.46174861323503f), Qfmt_31(0.38268343236509f), Qfmt_31(0.30070579950427f),
+ Qfmt_31(0.21643961393810f), Qfmt_31(0.13052619222005f), Qfmt_31(0.04361938736534f)
+};
+
+
+const int32 start_win[36] =
+{
+ /* k=0..17 sin(pi/36*(k+0.5)), */
+ Qfmt_31(0.08723877473068f), Qfmt_31(0.26105238444010f), Qfmt_31(0.43287922787620f),
+ Qfmt_31(0.60141159900854f), Qfmt_31(0.76536686473018f), Qfmt_31(0.92349722647006f),
+ Qfmt_31(0.53729960834682f), Qfmt_31(0.60876142900872f), Qfmt_31(0.67559020761566f),
+ Qfmt_31(-0.73727733681012f), Qfmt_31(-0.79335334029124f), Qfmt_31(0.84339144581289f),
+ Qfmt_31(0.88701083317822f), Qfmt_31(0.92387953251129f), Qfmt_31(-0.95371695074823f),
+ Qfmt_31(-0.97629600711993f), Qfmt_31(-0.99144486137381f), Qfmt_31(-0.99904822158186f),
+
+ Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f),
+ Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f),
+ /* k=24..29; sin(pi/12*(k-18+0.5)) */
+ Qfmt_31(0.99144486137381f), Qfmt_31(0.92387953251129f), Qfmt_31(0.79335334029124f),
+ Qfmt_31(0.60876142900872f), Qfmt_31(0.38268343236509f), Qfmt_31(0.13052619222005f),
+
+ Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
+ Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f)
+};
+
+
+const int32 stop_win[36] =
+{
+ Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
+ Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
+ /* k=6..11; sin(pi/12*(k-6+0.5)) */
+ Qfmt_31(0.13052619222005f), Qfmt_31(0.38268343236509f), Qfmt_31(0.60876142900872f),
+ Qfmt_31(-0.79335334029124f), Qfmt_31(-0.92387953251129f), Qfmt_31(0.99144486137381f),
+
+ Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(-0.99999990000000f),
+ Qfmt_31(-0.99999990000000f), Qfmt_31(-0.99999990000000f), Qfmt_31(-0.99999990000000f),
+ /* k=18..35 sin(pi/36*(k+0.5)), */
+ Qfmt_31(0.99904822158186f), Qfmt_31(0.99144486137381f), Qfmt_31(0.97629600711993f),
+ Qfmt_31(0.95371695074823f), Qfmt_31(0.92387953251129f), Qfmt_31(0.88701083317822f),
+ Qfmt_31(0.84339144581289f), Qfmt_31(0.79335334029124f), Qfmt_31(0.73727733681012f),
+ Qfmt_31(0.67559020761566f), Qfmt_31(0.60876142900872f), Qfmt_31(0.53729960834682f),
+ Qfmt_31(0.46174861323503f), Qfmt_31(0.38268343236509f), Qfmt_31(0.30070579950427f),
+ Qfmt_31(0.21643961393810f), Qfmt_31(0.13052619222005f), Qfmt_31(0.04361938736534f)
+};
+
+
+const int32 short_win[12] =
+{
+ /* k=0..11; sin(pi/12*(k+0.5)) */
+ Qfmt_31(0.13052619222005f), Qfmt_31(0.38268343236509f), Qfmt_31(0.60876142900872f),
+ Qfmt_31(0.79335334029124f), Qfmt_31(0.92387953251129f), Qfmt_31(0.99144486137381f),
+ Qfmt_31(0.99144486137381f), Qfmt_31(0.92387953251129f), Qfmt_31(0.79335334029124f),
+ Qfmt_31(0.60876142900872f), Qfmt_31(0.38268343236509f), Qfmt_31(0.13052619222005f),
+};
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_imdct_synth(int32 in[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ uint32 blk_type,
+ int16 mx_band,
+ int32 used_freq_lines,
+ int32 *Scratch_mem)
+{
+
+ int32 band;
+ int32 bands2process = used_freq_lines + 2;
+
+ if (bands2process > SUBBANDS_NUMBER)
+ {
+ bands2process = SUBBANDS_NUMBER; /* default */
+ }
+
+
+ /*
+ * in case of mx_poly_band> 0, do
+ * long transforms
+ */
+
+
+ for (band = 0; band < bands2process; band++)
+ {
+ uint32 current_blk_type = (band < mx_band) ? LONG : blk_type;
+
+ int32 * out = in + (band * FILTERBANK_BANDS);
+ int32 * history = overlap + (band * FILTERBANK_BANDS);
+
+ switch (current_blk_type)
+ {
+ case LONG:
+
+ pvmp3_mdct_18(out, history, normal_win);
+
+ break;
+
+ case START:
+
+ pvmp3_mdct_18(out, history, start_win);
+
+ break;
+
+ case STOP:
+
+ pvmp3_mdct_18(out, history, stop_win);
+
+ break;
+
+ case SHORT:
+ {
+ int32 *tmp_prev_ovr = &Scratch_mem[FILTERBANK_BANDS];
+ int32 i;
+
+ for (i = 0; i < 6; i++)
+ {
+ Scratch_mem[i ] = out[(i*3)];
+ Scratch_mem[6 +i] = out[(i*3) + 1];
+ Scratch_mem[12 +i] = out[(i*3) + 2];
+ }
+
+ pvmp3_mdct_6(&Scratch_mem[ 0], &tmp_prev_ovr[ 0]);
+ pvmp3_mdct_6(&Scratch_mem[ 6], &tmp_prev_ovr[ 6]);
+ pvmp3_mdct_6(&Scratch_mem[12], &tmp_prev_ovr[12]);
+
+ for (i = 0; i < 6; i++)
+ {
+ int32 temp = history[i];
+ /* next iteration overlap */
+ history[i] = fxp_mul32_Q32(tmp_prev_ovr[ 6+i] << 1, short_win[6+i]);
+ history[i] += fxp_mul32_Q32(Scratch_mem[12+i] << 1, short_win[ i]);
+ out[i] = temp;
+ }
+
+ for (i = 0; i < 6; i++)
+ {
+ out[i+6] = fxp_mul32_Q32(Scratch_mem[i] << 1, short_win[i]);
+ out[i+6] += history[i+6];
+ /* next iteration overlap */
+ history[i+6] = fxp_mul32_Q32(tmp_prev_ovr[12+i] << 1, short_win[6+i]);
+
+ }
+ for (i = 0; i < 6; i++)
+ {
+ out[i+12] = fxp_mul32_Q32(tmp_prev_ovr[ i] << 1, short_win[6+i]);
+ out[i+12] += fxp_mul32_Q32(Scratch_mem[6+i] << 1, short_win[ i]);
+ out[i+12] += history[i+12];
+ history[12+i] = 0;
+ }
+ }
+
+ break;
+ }
+
+ /*
+ * Compensation for frequency inversion of polyphase filterbank
+ * every odd time sample of every odd odd subband is mulitplied by -1 before
+ * processing by the polyphase filter
+ */
+
+ if (band & 1)
+ {
+ for (int32 slot = 1; slot < FILTERBANK_BANDS; slot += 6)
+ {
+ int32 temp1 = out[slot ];
+ int32 temp2 = out[slot+2];
+ int32 temp3 = out[slot+4];
+ out[slot ] = -temp1;
+ out[slot+2] = -temp2;
+ out[slot+4] = -temp3;
+ }
+ }
+ }
+
+
+ for (band = bands2process; band < SUBBANDS_NUMBER; band++)
+ {
+ int32 * out = in + (band * FILTERBANK_BANDS);
+ int32 * history = overlap + (band * FILTERBANK_BANDS);
+ int32 slot;
+
+ if (band & 1)
+ {
+ for (slot = 0; slot < FILTERBANK_BANDS; slot += 6)
+ {
+ int32 temp1 = history[slot ];
+ int32 temp2 = history[slot+1];
+ int32 temp3 = history[slot+2];
+ out[slot ] = temp1;
+ out[slot+1] = -temp2;
+ out[slot+2] = temp3;
+
+ temp1 = history[slot+3];
+ temp2 = history[slot+4];
+ temp3 = history[slot+5];
+ out[slot+3] = -temp1;
+ out[slot+4] = temp2;
+ out[slot+5] = -temp3;
+ }
+ }
+ else
+ {
+ for (slot = 0; slot < FILTERBANK_BANDS; slot += 3)
+ {
+ int32 temp1 = history[slot ];
+ int32 temp2 = history[slot+1];
+ int32 temp3 = history[slot+2];
+ out[slot ] = temp1;
+ out[slot+1] = temp2;
+ out[slot+2] = temp3;
+ }
+ }
+
+ pv_memset(history, 0, FILTERBANK_BANDS*sizeof(*overlap));
+ }
+}
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_imdct_synth.h b/media/codecs/mp3dec/src/pvmp3_imdct_synth.h
new file mode 100644
index 0000000..ea42e49
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_imdct_synth.h
@@ -0,0 +1,102 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_imdct_synth.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+*/
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+
+#ifndef PVMP3_IMDCT_SYNTH_H
+#define PVMP3_IMDCT_SYNTH_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES AND SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_imdct_synth(int32 in[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ uint32 blk_type,
+ int16 mx_band,
+ int32 used_freq_lines,
+ int32 *Scratch_mem);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mdct_18.cpp b/media/codecs/mp3dec/src/pvmp3_mdct_18.cpp
new file mode 100644
index 0000000..324290e
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mdct_18.cpp
@@ -0,0 +1,290 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: mdct_18.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ int32 vec[], input vector of length 18
+ int32 *history input for overlap and add, vector updated with
+ next overlap and add values
+ const int32 *window sine window used in the mdct, three types are allowed
+ noraml, start and stop
+Returns
+ none mdct computation in-place
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns the mdct of length 18 of the input vector, as well as the overlap
+ vector for next iteration ( on history[])
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_mdct_18.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int32 cosTerms_dct18[9] =
+{
+ Qfmt(0.50190991877167f), Qfmt(0.51763809020504f), Qfmt(0.55168895948125f),
+ Qfmt(0.61038729438073f), Qfmt(0.70710678118655f), Qfmt(0.87172339781055f),
+ Qfmt(1.18310079157625f), Qfmt(1.93185165257814f), Qfmt(5.73685662283493f)
+};
+
+
+const int32 cosTerms_1_ov_cos_phi[18] =
+{
+
+ Qfmt1(0.50047634258166f), Qfmt1(0.50431448029008f), Qfmt1(0.51213975715725f),
+ Qfmt1(0.52426456257041f), Qfmt1(0.54119610014620f), Qfmt1(0.56369097343317f),
+ Qfmt1(0.59284452371708f), Qfmt1(0.63023620700513f), Qfmt1(0.67817085245463f),
+
+ Qfmt2(0.74009361646113f), Qfmt2(0.82133981585229f), Qfmt2(0.93057949835179f),
+ Qfmt2(1.08284028510010f), Qfmt2(1.30656296487638f), Qfmt2(1.66275476171152f),
+ Qfmt2(2.31011315767265f), Qfmt2(3.83064878777019f), Qfmt2(11.46279281302667f)
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
+__attribute__((no_sanitize("integer")))
+void pvmp3_mdct_18(int32 vec[], int32 *history, const int32 *window)
+{
+ int32 i;
+ int32 tmp;
+ int32 tmp1;
+ int32 tmp2;
+ int32 tmp3;
+ int32 tmp4;
+
+
+
+ const int32 *pt_cos_split = cosTerms_dct18;
+ const int32 *pt_cos = cosTerms_1_ov_cos_phi;
+ const int32 *pt_cos_x = &cosTerms_1_ov_cos_phi[17];
+ int32 *pt_vec = vec;
+ int32 *pt_vec_o = &vec[17];
+
+
+ for (i = 9; i != 0; i--)
+ {
+ tmp = *(pt_vec);
+ tmp1 = *(pt_vec_o);
+ tmp = fxp_mul32_Q32(tmp << 1, *(pt_cos++));
+ tmp1 = fxp_mul32_Q27(tmp1, *(pt_cos_x--));
+ *(pt_vec++) = tmp + tmp1 ;
+ *(pt_vec_o--) = fxp_mul32_Q28((tmp - tmp1), *(pt_cos_split++));
+ }
+
+
+ pvmp3_dct_9(vec); // Even terms
+ pvmp3_dct_9(&vec[9]); // Odd terms
+
+
+ tmp3 = vec[16]; //
+ vec[16] = vec[ 8];
+ tmp4 = vec[14]; //
+ vec[14] = vec[ 7];
+ tmp = vec[12];
+ vec[12] = vec[ 6];
+ tmp2 = vec[10]; // vec[10]
+ vec[10] = vec[ 5];
+ vec[ 8] = vec[ 4];
+ vec[ 6] = vec[ 3];
+ vec[ 4] = vec[ 2];
+ vec[ 2] = vec[ 1];
+ vec[ 1] = vec[ 9] - tmp2; // vec[9] + vec[10]
+ vec[ 3] = vec[11] - tmp2;
+ vec[ 5] = vec[11] - tmp;
+ vec[ 7] = vec[13] - tmp;
+ vec[ 9] = vec[13] - tmp4;
+ vec[11] = vec[15] - tmp4;
+ vec[13] = vec[15] - tmp3;
+ vec[15] = vec[17] - tmp3;
+
+
+ /* overlap and add */
+
+ tmp2 = vec[0];
+ tmp3 = vec[9];
+
+ for (i = 0; i < 6; i++)
+ {
+ tmp = history[ i];
+ tmp4 = vec[i+10];
+ vec[i+10] = tmp3 + tmp4;
+ tmp1 = vec[i+1];
+ vec[ i] = fxp_mac32_Q32(tmp, (vec[i+10]), window[ i]);
+ tmp3 = tmp4;
+ history[i ] = -(tmp2 + tmp1);
+ tmp2 = tmp1;
+ }
+
+ tmp = history[ 6];
+ tmp4 = vec[16];
+ vec[16] = tmp3 + tmp4;
+ tmp1 = vec[7];
+ vec[ 6] = fxp_mac32_Q32(tmp, vec[16] << 1, window[ i]);
+ tmp = history[ 7];
+ history[6] = -(tmp2 + tmp1);
+ history[7] = -(tmp1 + vec[8]);
+
+ tmp1 = history[ 8];
+ tmp4 = vec[17] + tmp4;
+ vec[ 7] = fxp_mac32_Q32(tmp, tmp4 << 1, window[ 7]);
+ history[8] = -(vec[8] + vec[9]);
+ vec[ 8] = fxp_mac32_Q32(tmp1, vec[17] << 1, window[ 8]);
+
+ tmp = history[9];
+ tmp1 = history[17];
+ tmp2 = history[16];
+ vec[ 9] = fxp_mac32_Q32(tmp, vec[17] << 1, window[ 9]);
+
+ vec[17] = fxp_mac32_Q32(tmp1, vec[10] << 1, window[17]);
+ vec[10] = -vec[ 16];
+ vec[16] = fxp_mac32_Q32(tmp2, vec[11] << 1, window[16]);
+ tmp1 = history[15];
+ tmp2 = history[14];
+ vec[11] = -vec[ 15];
+ vec[15] = fxp_mac32_Q32(tmp1, vec[12] << 1, window[15]);
+ vec[12] = -vec[ 14];
+ vec[14] = fxp_mac32_Q32(tmp2, vec[13] << 1, window[14]);
+
+ tmp = history[13];
+ tmp1 = history[12];
+ tmp2 = history[11];
+ tmp3 = history[10];
+ vec[13] = fxp_mac32_Q32(tmp, vec[12] << 1, window[13]);
+ vec[12] = fxp_mac32_Q32(tmp1, vec[11] << 1, window[12]);
+ vec[11] = fxp_mac32_Q32(tmp2, vec[10] << 1, window[11]);
+ vec[10] = fxp_mac32_Q32(tmp3, tmp4 << 1, window[10]);
+
+
+ /* next iteration overlap */
+
+ tmp1 = history[ 8];
+ tmp3 = history[ 7];
+ tmp2 = history[ 1];
+ tmp = history[ 0];
+ tmp1 <<= 1;
+ tmp3 <<= 1;
+
+ history[ 0] = fxp_mul32_Q32(tmp1, window[18]);
+ history[17] = fxp_mul32_Q32(tmp1, window[35]);
+ history[ 1] = fxp_mul32_Q32(tmp3, window[19]);
+ history[16] = fxp_mul32_Q32(tmp3, window[34]);
+
+ tmp2 <<= 1;
+ tmp <<= 1;
+ history[ 7] = fxp_mul32_Q32(tmp2, window[25]);
+ history[10] = fxp_mul32_Q32(tmp2, window[28]);
+ history[ 8] = fxp_mul32_Q32(tmp, window[26]);
+ history[ 9] = fxp_mul32_Q32(tmp, window[27]);
+
+ tmp1 = history[ 6];
+ tmp3 = history[ 5];
+ tmp4 = history[ 4];
+ tmp2 = history[ 3];
+ tmp = history[ 2];
+
+ tmp1 <<= 1;
+ tmp3 <<= 1;
+ tmp4 <<= 1;
+
+ history[ 2] = fxp_mul32_Q32(tmp1, window[20]);
+ history[15] = fxp_mul32_Q32(tmp1, window[33]);
+ history[ 3] = fxp_mul32_Q32(tmp3, window[21]);
+ history[14] = fxp_mul32_Q32(tmp3, window[32]);
+ history[ 4] = fxp_mul32_Q32(tmp4, window[22]);
+ history[13] = fxp_mul32_Q32(tmp4, window[31]);
+ tmp2 <<= 1;
+ tmp <<= 1;
+ history[ 5] = fxp_mul32_Q32(tmp2, window[23]);
+ history[12] = fxp_mul32_Q32(tmp2, window[30]);
+ history[ 6] = fxp_mul32_Q32(tmp, window[24]);
+ history[11] = fxp_mul32_Q32(tmp, window[29]);
+}
+
+#endif // If not assembly
diff --git a/media/codecs/mp3dec/src/pvmp3_mdct_18.h b/media/codecs/mp3dec/src/pvmp3_mdct_18.h
new file mode 100644
index 0000000..2f2f65c
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mdct_18.h
@@ -0,0 +1,109 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Pathname: ./include/pvmp3_mdct_18.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This include file defines function mdct_18, dct9, mdct_6 and dct_6
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef MDCT_18_H
+#define MDCT_18_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define Qfmt(a) (Int32)((a)*((Int32)1<<28) )
+#define Qfmt1(a) (Int32)((a)*((Int32)0x7FFFFFFF))
+#define Qfmt2(a) (Int32)((a)*((Int32)1<<27))
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_mdct_18(int32 vec[], int32 *history, const int32 *window);
+
+ void pvmp3_dct_9(int32 vec[]);
+
+ void pvmp3_mdct_6(int32 vec[], int32 *overlap);
+
+ void pvmp3_dct_6(int32 vec[]);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mdct_6.cpp b/media/codecs/mp3dec/src/pvmp3_mdct_6.cpp
new file mode 100644
index 0000000..1ba080d
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mdct_6.cpp
@@ -0,0 +1,165 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+ Filename: mdct_18.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ int32 vec[], input vector of length 6
+ int32 *history input for overlap and add, vector updated with
+ next overlap and add values
+Returns
+ none mdct computation in-place
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns the mdct of length 6 of the input vector, as well as the overlap
+ vector for next iteration ( on history[])
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_mdct_6.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define QFORMAT 29
+#define Qfmt29(a) (int32)((a)*((int32)1<<QFORMAT) + ((a)>=0?0.5F:-0.5F))
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+/*
+ * (1./(2*cos((pi/(2*N))*(2*i+1)))), N = 12, i = [0:N/2-1]
+ */
+
+const int32 cosTerms_1_ov_cos_phi_N6[6] =
+{
+
+ Qfmt29(0.50431448029008f), Qfmt29(0.54119610014620f),
+ Qfmt29(0.63023620700513f), Qfmt29(0.82133981585229f),
+ Qfmt29(1.30656296487638f), Qfmt29(3.83064878777019f)
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+__attribute__((no_sanitize("integer")))
+void pvmp3_mdct_6(int32 vec[], int32 *history)
+{
+ int32 i;
+ int32 tmp;
+ int32 tmp1;
+ int32 tmp2;
+
+ int32 *pt_vec = vec;
+ int32 *pt_vec_o = vec;
+ const int32 *pt_cos = cosTerms_1_ov_cos_phi_N6;
+
+ for (i = 2; i != 0; i--)
+ {
+ tmp = *(pt_vec++);
+ tmp1 = *(pt_vec++);
+ tmp2 = *(pt_vec++);
+ *(pt_vec_o++) = fxp_mul32_Q29(tmp, *(pt_cos++));
+ *(pt_vec_o++) = fxp_mul32_Q29(tmp1, *(pt_cos++));
+ *(pt_vec_o++) = fxp_mul32_Q29(tmp2, *(pt_cos++));
+ }
+
+
+ pvmp3_dct_6(vec); // Even terms
+
+
+ tmp = -(vec[0] + vec[1]);
+ history[3] = tmp;
+ history[2] = tmp;
+ tmp = -(vec[1] + vec[2]);
+ vec[0] = vec[3] + vec[4];
+ vec[1] = vec[4] + vec[5];
+ history[4] = tmp;
+ history[1] = tmp;
+ tmp = -(vec[2] + vec[3]);
+ vec[4] = -vec[1];
+ history[5] = tmp;
+ history[0] = tmp;
+
+ vec[2] = vec[5];
+ vec[3] = -vec[5];
+ vec[5] = -vec[0];
+
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mdct_6.h b/media/codecs/mp3dec/src/pvmp3_mdct_6.h
new file mode 100644
index 0000000..af4f286
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mdct_6.h
@@ -0,0 +1,106 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Pathname: ./include/pvmp3_mdct_6.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This include file defines function mdct_18, dct9, mdct_6 and dct_6
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_MDCT_6_H
+#define PVMP3_MDCT_6_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define Qfmt(a) (Int32)((a)*((Int32)1<<28) )
+#define Qfmt1(a) (Int32)((a)*((Int32)0x7FFFFFFF))
+#define Qfmt2(a) (Int32)((a)*((Int32)1<<27))
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ void pvmp3_mdct_6(int32 vec[], int32 *overlap);
+
+ void pvmp3_dct_6(int32 vec[]);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_data.cpp b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_data.cpp
new file mode 100644
index 0000000..499672b
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_data.cpp
@@ -0,0 +1,247 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_mpeg2_get_scale_data.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ mp3SideInfo *si, side information
+ int32 gr, granule
+ int32 ch, channel
+ mp3Header *info, mp3 header information
+ uint32 *scalefac_buffer,
+ uint32 *scalefac_IIP_buffer,
+ tbits *pMainData bit stream Data
+
+ Returns
+
+ uint32 *scalefac_buffer, acquired scale band data
+ uint32 *scalefac_IIP_buffer, auxiliary scale data
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ get scale data for mpeg2 layer III LSF extension
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_mpeg2_get_scale_data.h"
+#include "pvmp3_getbits.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+const uint32 nr_of_sfb_block[6][3][4] =
+{ {{ 6, 5, 5, 5}, { 9, 9, 9, 9}, { 6, 9, 9, 9}},
+ {{ 6, 5, 7, 3}, { 9, 9, 12, 6}, { 6, 9, 12, 6}},
+ {{11, 10, 0, 0}, { 18, 18, 0, 0}, {15, 18, 0, 0}},
+ {{ 7, 7, 7, 0}, { 12, 12, 12, 0}, { 6, 15, 12, 0}},
+ {{ 6, 6, 6, 3}, { 12, 9, 9, 6}, { 6, 12, 9, 6}},
+ {{ 8, 8, 5, 0}, { 15, 12, 9, 0}, { 6, 18, 9, 0}}
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_mpeg2_get_scale_data(mp3SideInfo *si,
+ int32 gr,
+ int32 ch,
+ mp3Header *info,
+ uint32 *scalefac_buffer,
+ uint32 *scalefac_IIP_buffer,
+ tmp3Bits *pMainData)
+{
+ int16 i;
+ int16 j;
+ int16 k;
+ int16 blocktypenumber = 0;
+ int16 blocknumber = 0;
+
+ granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
+ uint32 scalefac_comp, int_scalefac_comp, new_slen[4] = { 0,0,0,0 };
+
+ scalefac_comp = gr_info->scalefac_compress;
+
+
+
+ if ((((info->mode_ext &1)) && (ch == 1)))
+ {
+ /* intensity_scale = scalefac_comp %2; */
+ int_scalefac_comp = scalefac_comp >> 1;
+
+ if (int_scalefac_comp < 180)
+ {
+ new_slen[0] = int_scalefac_comp / 36;
+ new_slen[1] = (int_scalefac_comp % 36) / 6;
+ new_slen[2] = int_scalefac_comp % 6;
+ blocknumber = 3;
+ }
+ else if (int_scalefac_comp < 244)
+ {
+ int_scalefac_comp -= 180;
+ new_slen[0] = (int_scalefac_comp & 63) >> 4;
+ new_slen[1] = (int_scalefac_comp & 15) >> 2;
+ new_slen[2] = int_scalefac_comp & 3;
+ blocknumber = 4;
+ }
+ else if (int_scalefac_comp <= 255)
+ {
+ int_scalefac_comp -= 244;
+ new_slen[0] = (int_scalefac_comp) / 3;
+ new_slen[1] = (int_scalefac_comp) % 3;
+ new_slen[2] = 0;
+ blocknumber = 5;
+ }
+ new_slen[3] = 0;
+ si->ch[ch].gran[gr].preflag = 0;
+ }
+ else
+ {
+ if (scalefac_comp < 400)
+ {
+ new_slen[0] = (scalefac_comp >> 4) / 5;
+ new_slen[1] = (scalefac_comp >> 4) % 5;
+ new_slen[2] = (scalefac_comp & 15) >> 2 ;
+ new_slen[3] = (scalefac_comp & 3);
+ si->ch[ch].gran[gr].preflag = 0;
+
+ blocknumber = 0;
+ }
+ else if (scalefac_comp < 500)
+ {
+ scalefac_comp -= 400;
+ new_slen[0] = (scalefac_comp >> 2) / 5;
+ new_slen[1] = (scalefac_comp >> 2) % 5;
+ new_slen[2] = scalefac_comp & 3;
+ new_slen[3] = 0;
+ si->ch[ch].gran[gr].preflag = 0;
+ blocknumber = 1;
+ }
+ else if (scalefac_comp < 512)
+ {
+ scalefac_comp -= 500;
+ new_slen[0] = scalefac_comp / 3;
+ new_slen[1] = scalefac_comp % 3;
+ new_slen[2] = 0 ;
+ new_slen[3] = 0;
+ si->ch[ch].gran[gr].preflag = 1;
+ blocknumber = 2;
+ }
+ }
+
+ if (gr_info->block_type == 2)
+ {
+ if (gr_info->mixed_block_flag)
+ {
+ blocktypenumber = 2;
+ }
+ else
+ {
+ blocktypenumber = 1;
+ }
+ }
+
+ k = 0;
+ for (i = 0; i < 4; i++)
+ {
+ if (new_slen[i])
+ {
+ for (j = 0; j < (int16)nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++)
+ {
+ scalefac_buffer[k] = getNbits(pMainData, new_slen[i]);
+ scalefac_IIP_buffer[k] = (1L << new_slen[i]) - 1;
+ k++;
+ }
+ }
+ else
+ {
+ for (j = 0; j < (int16)nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++)
+ {
+ scalefac_buffer[k] = 0;
+ scalefac_IIP_buffer[k] = 0;
+ k++;
+ }
+ }
+ }
+}
diff --git a/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_data.h b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_data.h
new file mode 100644
index 0000000..630ed61
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_data.h
@@ -0,0 +1,105 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_mpeg2_get_scale_data.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_MPEG2_GET_SCALE_DATA_H
+#define PVMP3_MPEG2_GET_SCALE_DATA_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+#include "s_mp3bits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_mpeg2_get_scale_data(mp3SideInfo *si,
+ int32 gr,
+ int32 ch,
+ mp3Header *info,
+ uint32 *scalefac_buffer,
+ uint32 *scalefac_IIP_buffer,
+ tmp3Bits *pMainData);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_factors.cpp b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_factors.cpp
new file mode 100644
index 0000000..e4d29d6
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_factors.cpp
@@ -0,0 +1,202 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_mpeg2_get_scale_factors.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+
+ mp3ScaleFactors *scalefac,
+ mp3SideInfo *si, side information
+ int32 gr, granule
+ int32 ch, channel
+ mp3Header *info, mp3 header information
+ uint32 *scalefac_IIP_buffer, auxiliary scale data
+ tbits *pMainData bit stream Data
+
+ Returns
+
+ III_scalefac_t *scalefac, scale factor
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ get scale factor for mpe2 layer III LSF extension
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_mpeg2_get_scale_factors.h"
+#include "pvmp3_mpeg2_get_scale_data.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_mpeg2_get_scale_factors(mp3ScaleFactors *scalefac,
+ mp3SideInfo *si,
+ int32 gr,
+ int32 ch,
+ mp3Header *info,
+ uint32 *scalefac_IIP_buffer,
+ tmp3Bits *pMainData)
+{
+
+ int32 sfb;
+ int32 k = 0;
+ int32 window;
+ uint32 *scalefac_buffer = &scalefac_IIP_buffer[56];
+
+ granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
+
+ pvmp3_mpeg2_get_scale_data(si,
+ gr,
+ ch,
+ info,
+ (uint32 *)scalefac_buffer,
+ (uint32 *)scalefac_IIP_buffer,
+ pMainData);
+
+
+ if (gr_info->window_switching_flag && (gr_info->block_type == 2))
+ {
+ if (gr_info->mixed_block_flag)
+ {
+ for (sfb = 0; sfb < 6; sfb++)
+ {
+ scalefac->l[sfb] = scalefac_buffer[sfb];
+ }
+
+
+ k = 6;
+ for (sfb = 3; sfb < 12; sfb++)
+ {
+ for (window = 0; window < 3; window++)
+ {
+ scalefac->s[window][sfb] = scalefac_buffer[k];
+ k++;
+ }
+ }
+
+
+ /* adjust position of "illegal position" information in scalefac_IIP_buffer[] */
+ /* in mixed blocks mode for short sfb, move them 3 places up. efs 3002-07-04 */
+ for (sfb = 11; sfb >= 3; sfb--)
+ {
+ scalefac_IIP_buffer[3*sfb + 2] = scalefac_IIP_buffer[3*sfb - 1];
+ scalefac_IIP_buffer[3*sfb + 1] = scalefac_IIP_buffer[3*sfb - 2];
+ scalefac_IIP_buffer[3*sfb ] = scalefac_IIP_buffer[3*sfb - 3];
+
+ }
+ }
+ else
+ { /* SHORT*/
+ for (sfb = 0; sfb < 12; sfb++)
+ {
+ for (window = 0; window < 3; window++)
+ {
+ scalefac->s[window][sfb] = scalefac_buffer[k];
+ k++;
+ }
+ }
+ }
+
+ scalefac->s[0][12] = 0;
+ scalefac->s[1][12] = 0;
+ scalefac->s[2][12] = 0;
+
+ }
+ else
+ { /* LONG types 0,1,3 */
+ for (sfb = 0; sfb < 21; sfb++)
+ {
+ scalefac->l[sfb] = scalefac_buffer[sfb];
+ }
+ scalefac->l[21] = 0;
+ scalefac->l[22] = 0;
+
+ }
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_factors.h b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_factors.h
new file mode 100644
index 0000000..46d16b3
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mpeg2_get_scale_factors.h
@@ -0,0 +1,105 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_mpeg2_get_scale_factors.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_MPEG2_GET_SCALE_FACTORS_H
+#define PVMP3_MPEG2_GET_SCALE_FACTORS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+#include "s_mp3bits.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_mpeg2_get_scale_factors(mp3ScaleFactors *scalefac,
+ mp3SideInfo *si,
+ int32 gr,
+ int32 ch,
+ mp3Header *info,
+ uint32 *scalefac_IIP_buffer,
+ tmp3Bits *pMainData);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.cpp b/media/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.cpp
new file mode 100644
index 0000000..a70e716
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.cpp
@@ -0,0 +1,700 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_mpeg2_stereo_proc.cpp
+
+ Functions:
+
+ pvmp3_st_intensity_ver2
+ pvmp3_mpeg2_stereo_proc
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+
+------------------------------------------------------------------------------
+
+pvmp3_st_intensity_ver2
+
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+
+ int32 xr[], input channel
+ int32 xl[],
+ int32 m, selecting index: io = 2(1/4) (m=0), io = 2(1/8) (m=1)
+ int32 is_pos, index on table is_pos_pow_eitgh_root_of_2
+ int32 Start, Location of first element where stereo intensity is applied
+ int32 Number number of elements affected
+
+ Returns
+
+ int32 xl[], generated stereo channel
+
+
+
+
+------------------------------------------------------------------------------
+
+pvmp3_mpeg2_stereo_proc
+
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+
+ int32 xr[], input channel
+ int32 xl[],
+ mp3ScaleFactors *scalefac, scale factors structure for Right channel
+ granuleInfo *gr_info_l, granule structure for the left channel
+ granuleInfo *gr_info_r, granule structure for the rigth channel
+ uint32 *scalefac_IIP_buffer, auxiliary scale factor vector
+ mp3Header *info mp3 header info
+ Returns
+
+ int32 xl[], generated stereo channel
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ stereo processing for mpeg2 layer III LSF extension
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_mpeg2_stereo_proc.h"
+#include "pvmp3_stereo_proc.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_tables.h"
+#include "mp3_mem_funcs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+#define Q31_fmt(a) (int32(double(0x7FFFFFFF)*(a)))
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+const int32 is_pos_pow_eitgh_root_of_2[8] =
+{
+ /* --- 2^(1/8) ----- */
+ Q31_fmt(1.00000000000000), Q31_fmt(0.91700404320467), Q31_fmt(0.84089641525371),
+ Q31_fmt(0.77110541270397), Q31_fmt(0.70710678118655), Q31_fmt(0.64841977732550),
+ Q31_fmt(0.59460355750136), Q31_fmt(0.54525386633263)
+};
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_st_intensity_ver2(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 m,
+ int32 is_pos,
+ int32 Start,
+ int32 Number)
+{
+ int32 k[2];
+
+ /* pow(io, ((is_pos + 1)>>1)); io = 2(1/4) (m=0), io = 2(1/8) (m=1) */
+ k[0] = is_pos_pow_eitgh_root_of_2[((is_pos+1)&(3+(m<<2)))<<(1-m)] >> ((is_pos + 1) >> (2 + m));
+ /* pow(io, (is_pos>>1)); io = 2(1/4) (m=0), io = 2(1/8) (m=1) */
+ k[1] = is_pos_pow_eitgh_root_of_2[(is_pos&(3+(m<<2)))<<(1-m)] >> (is_pos >> (2 + m));
+
+
+ int32 *pt_xr = &xr[Start];
+ int32 *pt_xl = &xl[Start];
+
+ if (is_pos == 0) /* 0 < is_pos < 31 */
+ {
+ pv_memcpy(pt_xl, pt_xr, Number*sizeof(*pt_xr));
+ }
+ else if (is_pos & 1)
+ {
+ for (int32 i = Number >> 1; i != 0; i--)
+ {
+ *(pt_xl++) = (*pt_xr);
+ *(pt_xr) = fxp_mul32_Q32((*pt_xr) << 1, k[0]);
+ pt_xr++;
+ *(pt_xl++) = (*pt_xr);
+ *(pt_xr) = fxp_mul32_Q32((*pt_xr) << 1, k[0]);
+ pt_xr++;
+ }
+ if (Number&1)
+ {
+ *(pt_xl) = (*pt_xr);
+ *(pt_xr) = fxp_mul32_Q32((*pt_xr) << 1, k[0]);
+ }
+ }
+ else
+ {
+ for (int32 i = Number >> 1; i != 0; i--)
+ {
+ *(pt_xl++) = fxp_mul32_Q32((*(pt_xr++)) << 1, k[1]);
+ *(pt_xl++) = fxp_mul32_Q32((*(pt_xr++)) << 1, k[1]);
+ }
+ if (Number&1)
+ {
+ *(pt_xl) = fxp_mul32_Q32((*pt_xr) << 1, k[1]);
+ }
+ }
+
+}
+
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void pvmp3_mpeg2_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ mp3ScaleFactors *scalefac_R,
+ granuleInfo *gr_info_l,
+ granuleInfo *gr_info_r,
+ uint32 *scalefac_IIP_buffer,
+ int32 used_freq_lines,
+ mp3Header *info)
+{
+
+ int32 sfreq;
+ int32 sb;
+ int32 ss;
+ int32 sfbNo;
+ int32 sfbStart;
+ int32 sfb;
+ int32 sfbTemp;
+ int32 i;
+ int32 j;
+ int32 io;
+
+
+ int32 i_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
+ (info->mode_ext & 0x1);
+
+ int32 ms_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
+ (info->mode_ext & 0x2);
+
+
+ if (i_stereo)
+ {
+ if (gr_info_r->scalefac_compress & 1)
+ {
+ io = 0; /* 2^(-1/4) */
+ }
+ else
+ {
+ io = 1; /* 2^(-1/8) */
+ }
+
+ sfreq = info->version_x + (info->version_x << 1);
+ sfreq += info->sampling_frequency;
+
+ if (gr_info_l->window_switching_flag && (gr_info_l->block_type == 2))
+ {
+ if (gr_info_l->mixed_block_flag)
+ {
+ /*
+ * mixed blocks processing
+ */
+ i = 31;
+ ss = 17;
+ sb = -1;
+
+ while (i >= 0)
+ {
+ if (xl[(i*FILTERBANK_BANDS) + ss])
+ {
+ sb = (i << 4) + (i << 1) + ss;
+ i = -1;
+ }
+ else
+ {
+ ss--;
+ if (ss < 0)
+ {
+ i--;
+ ss = 17;
+ }
+ }
+ } /* now sb is the number of highest line with value != 0 */
+ /* can be between -1 (all lines zero) and 575 (no line zero) */
+
+ if (sb < 36) /* was (sb <= 36) */
+ {
+ /*
+ * mixed blocks processing: intensity bound inside long blocks
+ */
+ /* 1. long blocks up to intensity border: Stereo or M/S */
+ if (mp3_sfBandIndex[sfreq].l[4] <= sb)
+ {
+ i = 4;
+ }
+ else
+ {
+ i = 0;
+ }
+
+ while (mp3_sfBandIndex[sfreq].l[i] <= sb)
+ {
+ i++;
+ }
+ sfbTemp = i; /* from that (long) sfb on we have intensity stereo */
+
+ sfbNo = mp3_sfBandIndex[sfreq].l[sfbTemp]; /* number of lines to process */
+
+ /* from sfbStart up sfbNo lines do ms_stereo or normal stereo */
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, 0, sfbNo);
+ }
+
+ /* 2. long blocks from intensity border up to sfb band 6: intensity */
+ /* calc. MPEG_1_2_Factor[0], MPEG_1_2_Factor[1] */
+
+ for (sfb = sfbTemp; sfb < 6; sfb++)
+ {
+ sfbStart = mp3_sfBandIndex[sfreq].l[sfb]; /* = Start in 0 ... 575 */
+ sfbNo = mp3_sfBandIndex[sfreq].l[sfb+1] - mp3_sfBandIndex[sfreq].l[sfb]; /* No of lines to process */
+
+ if ((uint32)(scalefac_R->l[sfb]) != scalefac_IIP_buffer[sfb])
+ {
+ pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->l[sfb], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+ }
+
+ /* 3. now process all sfb with short blocks (3...12), all in intensity mode */
+
+ for (j = 0; j < 3; j++)
+ {
+ /* first calculate directional factors for intensity stereo,
+ * for all sfb in intensity mode, but only
+ * if they do not have "illegal" position:
+ */
+ /* to do this for all sfb we have to get information for last scale factor band:
+ * here we clearly have more than one sfb in intensity mode,
+ * so copy factors and legal/illegal information from sfb11 to sfb12
+ */
+ (scalefac_R->s[j][12]) = (scalefac_R->s[j][11]);
+ scalefac_IIP_buffer[36 + j] = scalefac_IIP_buffer[33 + j]; /* legal/illegal in sfb 12 same as in sfb 11 */
+
+ for (sfb = 3; sfb < 13; sfb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb]; /* No of lines to process */
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
+
+ if ((uint32)(scalefac_R->s[j][sfb]) != scalefac_IIP_buffer[3*sfb + j])
+ {
+ pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->s[j][sfb], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+ }
+ } /* for (j = 0; j < 3; j++) */
+ }
+ else /* else then (sb >= 36) */
+ {
+ /*
+ * mixed blocks processing: intensity bound outside long blocks
+ */
+
+ /* 2. short blocks, do for all 3 */
+ /* ------------------------------ */
+ for (j = 0; j < 3; j++)
+ {
+ int32 sfbcnt = -1;
+
+ for (sfb = 12; sfb >= 3; sfb--)
+ {
+ int32 lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+
+ i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
+
+ while (lines > 0)
+ {
+ if (xl[i])
+ {
+ sfbcnt = sfb;
+ sfb = -10;
+ lines = -10;
+ }
+ lines--;
+ i--;
+ }
+ }
+
+ sfbcnt += 1;
+ if (sfbcnt < 3)
+ {
+ sfbcnt = 3; /* should not be necessary */
+ }
+
+ sfbTemp = sfbcnt; /* from this (short) sfb on we have intensity mode */
+ /* can have values between 3 (all short sfb in intensity) */
+ /* and 13 (no short sfb in intensity mode) */
+
+ /* 3. from sfbTemp to last sfb calculate is_ratio values: */
+ /* first calculate directional factors for intensity stereo, */
+ /* for all sfb in intensity mode, but only */
+ /* if they do not have "illegal" position: */
+
+ /* to do this for all sfb we have to get information for last scale factor band: */
+ /* get factors for last scale factor band: */
+ /* more than one sfb in intensity mode,
+ copy factors and legal/illegal information from sfb11 to sfb12 */
+ if (sfbTemp < 12)
+ {
+ (scalefac_R->s[j][12]) = (scalefac_R->s[j][11]);
+ scalefac_IIP_buffer[36 + j] = scalefac_IIP_buffer[33 + j]; /* legal/illegal in sfb 12 same as in sfb 11 */
+ }
+ else if (sfbTemp == sfb)
+ /* only sfb 12 in intensity mode, use factors corresponding to is_pos[12] == 0 */
+ {
+ (scalefac_R->s[j][12]) = 0;
+ scalefac_IIP_buffer[36 + j] = 1; /* the scf value 0 in sfb12 is "legal" */
+ }
+ /* if sfbTemp > sfb (no sfb in intensity mode): do nothing */
+
+
+ /* 4. do normal stereo or MS stereo from sfb 3 to < sfbTemp: */
+ for (sfb = 3; sfb < sfbTemp; sfb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
+
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+ }
+
+ /* 5. now intensity stereo processing of the remaining sfb's: */
+
+ for (sfb = sfbTemp; sfb < 13; sfb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb]; /* No of lines to process */
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
+ if ((uint32)(scalefac_R->s[j][sfb]) != scalefac_IIP_buffer[3*sfb + j])
+ {
+ pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->s[j][sfb], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+ }
+ /* end of correction by efs 2003-07-04 */
+ } /* for (j = 0; j < 3; j++) */
+
+
+ /* long blocks 0 up to sfb band 6: no intensity */
+
+ sfbNo = mp3_sfBandIndex[sfreq].l[6]; /* number of lines to process */
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, 0, sfbNo);
+ }
+
+ } /* if intensity bound inside or outside long blocks */
+ } /* if (gr_info->mixed_block_flag) */
+ else
+ {
+ /*
+ * short block processing
+ */
+ for (j = 0; j < 3; j++)
+ {
+ int32 sfbcnt = -1;
+
+ for (sfb = 12; sfb >= 0; sfb--)
+ {
+ int32 lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+ i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
+
+ while (lines > 0)
+ {
+ if (xl[i])
+ {
+ sfbcnt = sfb;
+ sfb = -10;
+ lines = -10;
+ }
+ lines--;
+ i--;
+ }
+ }
+
+ sfbcnt += 1;
+
+ /* start of corrected version by efs 2003-07-04 */
+ sfbTemp = sfbcnt; /* from this (short) sfb on we have intensity mode */
+ /* can have values between 3 (all short sfb in intensity) */
+ /* and 13 (no short sfb in intensity mode) */
+
+ /* first calculate directional factors for intensity stereo,
+ for all sfb in intensity mode, but only
+ if they do not have "illegal" position: */
+
+ /* to do this for all sfb we have to get information for last scale factor band: */
+ /* get factors for last scale factor band: */
+ /* more than one sfb in intensity mode,
+ copy factors and legal/illegal information from sfb11 to sfb12 */
+ if (sfbTemp < 12)
+ {
+ (scalefac_R->s[j][12]) = (scalefac_R->s[j][11]);
+ scalefac_IIP_buffer[36 + j] = scalefac_IIP_buffer[33 + j]; /* legal/illegal in sfb 12 same as in sfb 11 */
+ }
+ else if (sfbTemp == 12)
+ /* only sfb 12 in intensity mode, use factors corresponding to is_pos[12] == 0 */
+ {
+ (scalefac_R->s[j][12]) = 0;
+ scalefac_IIP_buffer[36 + j] = 1; /* the scf value 0 in sfb12 is "legal" */
+ }
+ /* if sfbTemp > sfb (no sfb in intensity mode): do nothing */
+
+
+ /* Now process audio samples */
+ /* first process lower sfb's not in intensity mode */
+ for (sfb = 0; sfb < sfbTemp; sfb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
+
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+ }
+
+ /* now intensity stereo processing of the remaining sfb's: */
+ for (sfb = sfbTemp; sfb < 13; sfb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb]; /* No of lines to process */
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
+
+ if ((uint32)(scalefac_R->s[j][sfb]) != scalefac_IIP_buffer[3*sfb + j])
+ {
+ pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->s[j][sfb], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+ }
+
+ } /* for (j = 0; j < 3; j++) */
+
+ } /* end of else ( gr_info->mixed_block_flag) */
+
+ } /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
+ else
+ {
+ /*
+ * long block processing
+ */
+ i = 31;
+ ss = 17;
+ sb = 0;
+
+ while (i >= 0)
+ {
+ if (xl[(i*FILTERBANK_BANDS) + ss])
+ {
+ sb = (i << 4) + (i << 1) + ss;
+ /* i = -1 patched RF 24-09-2002 */
+ i = -2;
+ }
+ else
+ {
+ ss--;
+ if (ss < 0)
+ {
+ i--;
+ ss = 17;
+ }
+ }
+ }
+
+ /* patched RF 24-09-2002 */
+ if (sb)
+ {
+ if (mp3_sfBandIndex[sfreq].l[14] <= sb)
+ {
+ i = 14;
+ }
+ else if (mp3_sfBandIndex[sfreq].l[7] <= sb)
+ {
+ i = 7;
+ }
+ else
+ {
+ i = 0;
+ }
+
+ while (mp3_sfBandIndex[sfreq].l[i] <= sb)
+ {
+ i++;
+ }
+ }
+
+ else
+ {
+ if (i == -1)
+ {
+ /* all xr[1][][] are 0: set IS bound sfb to 0 */
+ i = 0;
+ }
+ else
+ {
+ /* xr[1][0][0] is unequal 0 and all others are 0: set IS bound sfb to 1 */
+ i = 1;
+ }
+ }
+ /* corrected version by efs 2003-07-04 */
+ sfbTemp = i; /* from this (long) sfb on we have intensity mode */
+ /* can have values between 0 (all long sfb in intensity) */
+ /* and 22 (no long sfb in intensity mode) */
+
+ /* first calculate directional factors for intensity stereo,
+ for all sfb in intensity mode, but only if they
+ do not have "illegal" position: */
+
+ /* to do this for all sfb we have to get information for last scale factor band: */
+ if (sfbTemp < 21)
+ /* more than one sfb in intensity mode, */
+ /* copy factors and legal/illegal information from sfb20 to sfb21 */
+ {
+ (scalefac_R->l[21]) = (scalefac_R->l[20]);
+ scalefac_IIP_buffer[21] = scalefac_IIP_buffer[20]; /* legal/illegal in sfb 21 same as in sfb 20 */
+ }
+ else if (sfbTemp == 21)
+ /* only sfb 21 in intensity mode, is_pos[21] = 0 */
+ {
+ (scalefac_R->l[21]) = 0;
+ scalefac_IIP_buffer[21] = 1; /* the scf value 0 in sfb21 is "legal" */
+ }
+ /* if sfbTemp > 21 (no sfb in intensity mode): do nothing */
+
+
+ /* Now process audio samples */
+ /* first process lower sfb's not in intensity mode */
+
+ sfbNo = mp3_sfBandIndex[sfreq].l[sfbTemp] - mp3_sfBandIndex[sfreq].l[0];
+ sfbStart = mp3_sfBandIndex[sfreq].l[0];
+
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ /* now intensity stereo processing of the remaining sfb's: */
+ for (sfb = sfbTemp; sfb < 22; sfb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].l[sfb+1] - mp3_sfBandIndex[sfreq].l[sfb]; /* number of lines to process */
+ sfbStart = mp3_sfBandIndex[sfreq].l[sfb]; /* start of sfb */
+
+ if ((uint32)(scalefac_R->l[sfb]) != scalefac_IIP_buffer[sfb]) /* "legal" position ? */
+ {
+ pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->l[sfb], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ } /* for (sfb = sfbTemp; sfb < 22; sfb++) */
+
+ } /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
+
+ } /* if (i_stereo) */
+ else
+ {
+ /*
+ * normal or ms stereo processing
+ */
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, 0, used_freq_lines);
+ }
+
+ } /* if (i_stereo) */
+
+}
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.h b/media/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.h
new file mode 100644
index 0000000..7db0c53
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.h
@@ -0,0 +1,112 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_mpeg2_stereo_proc.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_MPEG2_STEREO_PROC_H
+#define PVMP3_MPEG2_STEREO_PROC_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_mpeg2_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ mp3ScaleFactors *scalefac,
+ granuleInfo *gr_info_l,
+ granuleInfo *gr_info_r,
+ uint32 *scalefac_IIP_buffer,
+ int32 used_freq_lines,
+ mp3Header *info);
+
+
+ void pvmp3_st_intensity_ver2(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 m,
+ int32 is_pos,
+ int32 Start,
+ int32 Number);
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_normalize.cpp b/media/codecs/mp3dec/src/pvmp3_normalize.cpp
new file mode 100644
index 0000000..885ab08
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_normalize.cpp
@@ -0,0 +1,174 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_normalize.cpp
+
+ Date: 10/02/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+ Int32 x 32-bit integer non-zero input
+Returns
+ Int32 i number of leading zeros on x
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ Returns number of leading zeros on the non-zero input
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3_normalize.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
+#elif (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
+
+
+/* function is inlined in header file */
+
+
+#else
+
+int32 pvmp3_normalize(int32 x)
+{
+ /*----------------------------------------------------------------------------
+ ; Define all local variables
+ ----------------------------------------------------------------------------*/
+ int32 i;
+
+
+ if (x > 0x0FFFFFFF)
+ {
+ i = 0; /* most likely case */
+ }
+ else if (x > 0x00FFFFFF)
+ {
+ i = 3; /* second most likely case */
+ }
+ else if (x > 0x0000FFFF)
+ {
+ i = x > 0x000FFFFF ? 7 : 11;
+ }
+ else
+ {
+ if (x > 0x000000FF)
+ {
+ i = x > 0x00000FFF ? 15 : 19;
+ }
+ else
+ {
+ i = x > 0x0000000F ? 23 : 27;
+ }
+ }
+
+
+ x <<= i;
+
+ switch (x & 0x78000000)
+ {
+ case 0x08000000:
+ i += 3;
+ break;
+
+ case 0x18000000:
+ case 0x10000000:
+ i += 2;
+ break;
+ case 0x28000000:
+ case 0x20000000:
+ case 0x38000000:
+ case 0x30000000:
+ i++;
+ break;
+
+ default:
+ ;
+ }
+
+ return i;
+
+}
+
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_normalize.h b/media/codecs/mp3dec/src/pvmp3_normalize.h
new file mode 100644
index 0000000..5471771
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_normalize.h
@@ -0,0 +1,108 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_normalize.h
+
+ Date: 10/02/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PVMP3_NORMALIZE_H
+#define PVMP3_NORMALIZE_H
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES AND SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
+
+__inline int32 pvmp3_normalize(int32 x)
+{
+ int32 y;
+ __asm
+ {
+ clz y, x;
+ sub y, y, #1
+ }
+ return (y);
+}
+
+
+#elif (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
+
+__inline int32 pvmp3_normalize(int32 x)
+{
+ register int32 y;
+ register int32 ra = x;
+
+
+ asm volatile(
+ "clz %0, %1\n\t"
+ "sub %0, %0, #1"
+ : "=&r*i"(y)
+ : "r"(ra));
+ return (y);
+
+}
+
+#else
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int32 pvmp3_normalize(int32 x);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+#endif /* PV_NORMALIZE_H */
diff --git a/media/codecs/mp3dec/src/pvmp3_poly_phase_synthesis.cpp b/media/codecs/mp3dec/src/pvmp3_poly_phase_synthesis.cpp
new file mode 100644
index 0000000..33c8e61
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_poly_phase_synthesis.cpp
@@ -0,0 +1,187 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_poly_phase_synthesis.cpp
+
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Input
+ tmp3dec_chan *pChVars, decoder state structure per channel
+ int32 numChannels, number of channels
+ e_equalization equalizerType, equalization mode
+ int16 *outPcm pointer to the PCM output data
+
+ Output
+ int16 *outPcm pointer to the PCM output data
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ polyphase synthesis
+ Each time the subband samples for all 32 polyphase subbands of one
+ channel have been calculated, they can be applied to the synthesis
+ subband filter and 32 consecutive audio samples can be calculated
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_poly_phase_synthesis.h"
+#include "pvmp3_polyphase_filter_window.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_dct_16.h"
+#include "pvmp3_equalizer.h"
+#include "mp3_mem_funcs.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_poly_phase_synthesis(tmp3dec_chan *pChVars,
+ int32 numChannels,
+ e_equalization equalizerType,
+ int16 *outPcm)
+{
+ /*
+ * Equalizer
+ */
+ pvmp3_equalizer(pChVars->circ_buffer,
+ equalizerType,
+ pChVars->work_buf_int32);
+
+
+ int16 * ptr_out = outPcm;
+
+
+ for (int32 band = 0; band < FILTERBANK_BANDS; band += 2)
+ {
+ int32 *inData = &pChVars->circ_buffer[544 - (band<<5)];
+
+ /*
+ * DCT 32
+ */
+
+ pvmp3_split(&inData[16]);
+
+ pvmp3_dct_16(&inData[16], 0);
+ pvmp3_dct_16(inData, 1); // Even terms
+
+ pvmp3_merge_in_place_N32(inData);
+
+ pvmp3_polyphase_filter_window(inData,
+ ptr_out,
+ numChannels);
+
+ inData -= SUBBANDS_NUMBER;
+
+ /*
+ * DCT 32
+ */
+
+ pvmp3_split(&inData[16]);
+
+ pvmp3_dct_16(&inData[16], 0);
+ pvmp3_dct_16(inData, 1); // Even terms
+
+ pvmp3_merge_in_place_N32(inData);
+
+ pvmp3_polyphase_filter_window(inData,
+ ptr_out + (numChannels << 5),
+ numChannels);
+
+ ptr_out += (numChannels << 6);
+
+ inData -= SUBBANDS_NUMBER;
+
+ }/* end band loop */
+
+ pv_memmove(&pChVars->circ_buffer[576],
+ pChVars->circ_buffer,
+ 480*sizeof(*pChVars->circ_buffer));
+
+}
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_poly_phase_synthesis.h b/media/codecs/mp3dec/src/pvmp3_poly_phase_synthesis.h
new file mode 100644
index 0000000..166cffd
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_poly_phase_synthesis.h
@@ -0,0 +1,102 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_poly_phase_synthesis.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_POLY_PHASE_SYNTHESIS_H
+#define PVMP3_POLY_PHASE_SYNTHESIS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "s_tmp3dec_chan.h"
+#include "pvmp3decoder_api.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_poly_phase_synthesis(tmp3dec_chan *pChVars,
+ int32 numChannels,
+ e_equalization equalizerType,
+ int16 *outPcm);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_polyphase_filter_window.cpp b/media/codecs/mp3dec/src/pvmp3_polyphase_filter_window.cpp
new file mode 100644
index 0000000..8380437
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_polyphase_filter_window.cpp
@@ -0,0 +1,239 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_polyphase_filter_window.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+
+Input
+ int32 *synth_buffer, synthesis input buffer
+ int16 *outPcm, generated output ( 32 values)
+ int32 numChannels number of channels
+ Returns
+
+ int16 *outPcm
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ apply polyphase filter window
+ Input 32 subband samples
+ Calculate 64 values
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_polyphase_filter_window.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_tables.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module1 specific macros here
+----------------------------------------------------------------------------*/
+
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module1
+----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module_x
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module_x but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_polyphase_filter_window(int32 *synth_buffer,
+ int16 *outPcm,
+ int32 numChannels)
+{
+ int32 sum1;
+ int32 sum2;
+ const int32 *winPtr = pqmfSynthWin;
+ int32 i;
+
+
+ for (int16 j = 1; j < SUBBANDS_NUMBER / 2; j++)
+ {
+ sum1 = 0x00000020;
+ sum2 = 0x00000020;
+
+
+ for (i = (SUBBANDS_NUMBER >> 1);
+ i < HAN_SIZE + (SUBBANDS_NUMBER >> 1);
+ i += SUBBANDS_NUMBER << 4)
+ {
+ int32 *pt_1 = &synth_buffer[ i+j];
+ int32 *pt_2 = &synth_buffer[ i-j];
+ int32 temp1 = pt_1[ 0];
+ int32 temp3 = pt_2[ SUBBANDS_NUMBER*15 ];
+ int32 temp2 = pt_2[ SUBBANDS_NUMBER* 1 ];
+ int32 temp4 = pt_1[ SUBBANDS_NUMBER*14 ];
+
+ sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[ 0]);
+ sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[ 0]);
+ sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[ 1]);
+ sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[ 1]);
+ sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[ 2]);
+ sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[ 2]);
+ sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[ 3]);
+ sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[ 3]);
+
+ temp1 = pt_1[ SUBBANDS_NUMBER* 2];
+ temp3 = pt_2[ SUBBANDS_NUMBER*13];
+ temp2 = pt_2[ SUBBANDS_NUMBER* 3];
+ temp4 = pt_1[ SUBBANDS_NUMBER*12];
+
+ sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[ 4]);
+ sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[ 4]);
+ sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[ 5]);
+ sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[ 5]);
+ sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[ 6]);
+ sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[ 6]);
+ sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[ 7]);
+ sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[ 7]);
+
+ temp1 = pt_1[ SUBBANDS_NUMBER* 4 ];
+ temp3 = pt_2[ SUBBANDS_NUMBER*11 ];
+ temp2 = pt_2[ SUBBANDS_NUMBER* 5 ];
+ temp4 = pt_1[ SUBBANDS_NUMBER*10 ];
+
+ sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[ 8]);
+ sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[ 8]);
+ sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[ 9]);
+ sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[ 9]);
+ sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[10]);
+ sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[10]);
+ sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[11]);
+ sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[11]);
+
+ temp1 = pt_1[ SUBBANDS_NUMBER*6 ];
+ temp3 = pt_2[ SUBBANDS_NUMBER*9 ];
+ temp2 = pt_2[ SUBBANDS_NUMBER*7 ];
+ temp4 = pt_1[ SUBBANDS_NUMBER*8 ];
+
+ sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[12]);
+ sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[12]);
+ sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[13]);
+ sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[13]);
+ sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[14]);
+ sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[14]);
+ sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[15]);
+ sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[15]);
+
+ winPtr += 16;
+ }
+
+
+
+ int32 k = j << (numChannels - 1);
+ outPcm[k] = saturate16(sum1 >> 6);
+ outPcm[(numChannels<<5) - k] = saturate16(sum2 >> 6);
+ }
+
+
+
+ sum1 = 0x00000020;
+ sum2 = 0x00000020;
+
+
+ for (i = 16; i < HAN_SIZE + 16; i += (SUBBANDS_NUMBER << 2))
+ {
+ int32 *pt_synth = &synth_buffer[i];
+ int32 temp1 = pt_synth[ 0 ];
+ int32 temp2 = pt_synth[ SUBBANDS_NUMBER ];
+ int32 temp3 = pt_synth[ SUBBANDS_NUMBER/2];
+
+ sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[0]) ;
+ sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[1]) ;
+ sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[2]) ;
+
+ temp1 = pt_synth[ SUBBANDS_NUMBER<<1 ];
+ temp2 = pt_synth[ 3*SUBBANDS_NUMBER ];
+ temp3 = pt_synth[ SUBBANDS_NUMBER*5/2];
+
+ sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[3]) ;
+ sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[4]) ;
+ sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[5]) ;
+
+ winPtr += 6;
+ }
+
+
+ outPcm[0] = saturate16(sum1 >> 6);
+ outPcm[(SUBBANDS_NUMBER/2)<<(numChannels-1)] = saturate16(sum2 >> 6);
+
+
+}
+
+#endif // If not assembly
+
diff --git a/media/codecs/mp3dec/src/pvmp3_polyphase_filter_window.h b/media/codecs/mp3dec/src/pvmp3_polyphase_filter_window.h
new file mode 100644
index 0000000..b9eccad
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_polyphase_filter_window.h
@@ -0,0 +1,138 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_decode_header.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_POLYPHASE_FILTER_WINDOW_H
+#define PVMP3_POLYPHASE_FILTER_WINDOW_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_audio_type_defs.h"
+#include "s_tmp3dec_chan.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define MAX_16BITS_INT 0x7FFF
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
+
+
+ __inline int16 saturate16(int32 sample)
+ {
+ int32 a;
+ int32 b = 31;
+ __asm
+ {
+ mov a, sample, asr#15
+ teq a, sample, asr b
+ eorne sample, MAX_16BITS_INT, sample, asr#31
+ }
+ return sample ;
+ }
+
+#else
+
+ inline int16 saturate16(int32 sample)
+ {
+
+ if ((sample >> 15) ^(sample >> 31))
+ {
+ sample = MAX_16BITS_INT ^(sample >> 31);
+ }
+ return sample;
+
+ }
+#endif
+
+
+ void pvmp3_polyphase_filter_window(int32 *synth_buffer,
+ int16 *outPcm,
+ int32 numChannels);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_reorder.cpp b/media/codecs/mp3dec/src/pvmp3_reorder.cpp
new file mode 100644
index 0000000..286c636
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_reorder.cpp
@@ -0,0 +1,197 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_reorder.cpp
+
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+ Inputs:
+
+ int32 xr[ ], rescaled data
+ struct gr_info_s *gr_info, granule structure
+ mp3Header *info, mp3 header info
+ int32 Scratch_mem[198] for temporary usage
+
+ Outputs:
+
+ int32 xr[ ], reordered data
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ If short blocks are used (block_type[gr][ch]=='10'), the rescaled data
+ xr[scf_band][window][freq_line] shall be reordered in polyphase subband
+ order, xr[subband][window][freq_line], prior to the IMDCT operation.
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_reorder.h"
+#include "pvmp3_tables.h"
+#include "mp3_mem_funcs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_reorder(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ granuleInfo *gr_info,
+ int32 *used_freq_lines,
+ mp3Header *info,
+ int32 Scratch_mem[198])
+{
+ int32 sfreq = info->version_x + (info->version_x << 1);
+ sfreq += info->sampling_frequency;
+
+ if (gr_info->window_switching_flag && (gr_info->block_type == 2))
+ {
+ int32 sfb_lines;
+ int32 freq;
+ int32 src_line;
+ int32 sfb;
+ if (gr_info->mixed_block_flag)
+ {
+ /* REORDERING FOR REST SWITCHED SHORT */
+ sfb = 3; /* no reorder for low 2 subbands */
+ src_line = 36;
+ }
+ else
+ { /* pure short */
+ sfb = 0;
+ src_line = 0;
+ }
+ int16 ct = src_line;
+
+ for (; sfb < 13; sfb++)
+ {
+ if (*used_freq_lines > 3*mp3_sfBandIndex[sfreq].s[sfb+1])
+ {
+ sfb_lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+
+ for (freq = 0; freq < 3*sfb_lines; freq += 3)
+ {
+ int32 tmp1 = xr[src_line];
+ int32 tmp2 = xr[src_line+(sfb_lines)];
+ int32 tmp3 = xr[src_line+(sfb_lines<<1)];
+ src_line++;
+ Scratch_mem[freq ] = tmp1;
+ Scratch_mem[freq+1] = tmp2;
+ Scratch_mem[freq+2] = tmp3;
+ }
+ src_line += (sfb_lines << 1);
+
+ pv_memcpy(&xr[ct], Scratch_mem, sfb_lines*3*sizeof(int32));
+ ct += sfb_lines + (sfb_lines << 1);
+
+ }
+ else
+ {
+
+ sfb_lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+
+ for (freq = 0; freq < 3*sfb_lines; freq += 3)
+ {
+ int32 tmp1 = xr[src_line];
+ int32 tmp2 = xr[src_line+(sfb_lines)];
+ int32 tmp3 = xr[src_line+(sfb_lines<<1)];
+ src_line++;
+ Scratch_mem[freq ] = tmp1;
+ Scratch_mem[freq+1] = tmp2;
+ Scratch_mem[freq+2] = tmp3;
+ }
+
+ pv_memcpy(&xr[ct], Scratch_mem, sfb_lines*3*sizeof(int32));
+
+ *used_freq_lines = mp3_sfBandIndex[sfreq].s[sfb+1] * 3;
+
+ sfb = 13; /* force out of the for-loop */
+ }
+ }
+ }
+}
+
+
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_reorder.h b/media/codecs/mp3dec/src/pvmp3_reorder.h
new file mode 100644
index 0000000..5248951
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_reorder.h
@@ -0,0 +1,103 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_reorder.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_REORDER_H
+#define PVMP3_REORDER_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void pvmp3_reorder(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ granuleInfo *gr_info,
+ int32 *used_freq_lines,
+ mp3Header *info,
+ int32 Scratch_mem[198]);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_seek_synch.cpp b/media/codecs/mp3dec/src/pvmp3_seek_synch.cpp
new file mode 100644
index 0000000..82faafd
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_seek_synch.cpp
@@ -0,0 +1,308 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_seek_synch.cpp
+
+ Functions:
+ pvmp3_seek_synch
+ pvmp3_header_sync
+
+
+ Date: 9/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+pvmp3_frame_synch
+
+Input
+ pExt = pointer to the external interface structure. See the file
+ pvmp3decoder_api.h for a description of each field.
+ Data type of pointer to a tPVMP3DecoderExternal
+ structure.
+
+ pMem = void pointer to hide the internal implementation of the library
+ It is cast back to a tmp3dec_file structure. This structure
+ contains information that needs to persist between calls to
+ this function, or is too big to be placed on the stack, even
+ though the data is only needed during execution of this function
+ Data type void pointer, internally pointer to a tmp3dec_file
+ structure.
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ search mp3 sync word, when found, it verifies, based on header parameters,
+ the locations of the very next sync word,
+ - if fails, then indicates a false sync,
+ - otherwise, it confirm synchronization of at least 2 consecutives frames
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_seek_synch.h"
+#include "pvmp3_getbits.h"
+#include "s_tmp3dec_file.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_tables.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+
+ERROR_CODE pvmp3_frame_synch(tPVMP3DecoderExternal *pExt,
+ void *pMem) /* bit stream structure */
+{
+ uint16 val;
+ ERROR_CODE err;
+
+ tmp3dec_file *pVars;
+
+ pVars = (tmp3dec_file *)pMem;
+
+ pVars->inputStream.pBuffer = pExt->pInputBuffer;
+ pVars->inputStream.usedBits = (pExt->inputBufferUsedLength << 3); // in bits
+
+
+ pVars->inputStream.inputBufferCurrentLength = (pExt->inputBufferCurrentLength); // in bits
+
+ err = pvmp3_header_sync(&pVars->inputStream);
+
+ if (err == NO_DECODING_ERROR)
+ {
+ /* validate synchronization by checking two consecutive sync words */
+
+ // to avoid multiple bitstream accesses
+ uint32 temp = getNbits(&pVars->inputStream, 21);
+ // put back whole header
+ pVars->inputStream.usedBits -= 21 + SYNC_WORD_LNGTH;
+
+ int32 version;
+
+ switch (temp >> 19) /* 2 */
+ {
+ case 0:
+ version = MPEG_2_5;
+ break;
+ case 2:
+ version = MPEG_2;
+ break;
+ case 3:
+ version = MPEG_1;
+ break;
+ default:
+ version = INVALID_VERSION;
+ break;
+ }
+
+ int32 freq_index = (temp << 20) >> 30;
+
+ if (version != INVALID_VERSION && (freq_index != 3))
+ {
+ int32 numBytes = fxp_mul32_Q28(mp3_bitrate[version][(temp<<16)>>28] << 20,
+ inv_sfreq[freq_index]);
+
+ numBytes >>= (20 - version);
+
+ if (version != MPEG_1)
+ {
+ numBytes >>= 1;
+ }
+ if ((temp << 22) >> 31)
+ {
+ numBytes++;
+ }
+
+ if (numBytes > (int32)pVars->inputStream.inputBufferCurrentLength)
+ {
+ /* frame should account for padding and 2 bytes to check sync */
+ pExt->CurrentFrameLength = numBytes + 3;
+ return (SYNCH_LOST_ERROR);
+ }
+ else if (numBytes == (int32)pVars->inputStream.inputBufferCurrentLength)
+ {
+ /* No enough data to validate, but current frame appears to be correct ( EOF case) */
+ pExt->inputBufferUsedLength = pVars->inputStream.usedBits >> 3;
+ return (NO_DECODING_ERROR);
+ }
+ else
+ {
+
+ int32 offset = pVars->inputStream.usedBits + ((numBytes) << 3);
+
+ offset >>= INBUF_ARRAY_INDEX_SHIFT;
+ uint8 *pElem = pVars->inputStream.pBuffer + offset;
+ uint16 tmp1 = *(pElem++);
+ uint16 tmp2 = *(pElem);
+
+ val = (tmp1 << 3);
+ val |= (tmp2 >> 5);
+ }
+ }
+ else
+ {
+ val = 0; // force mismatch
+ }
+
+ if (val == SYNC_WORD)
+ {
+ pExt->inputBufferUsedLength = pVars->inputStream.usedBits >> 3; /// !!!!!
+ err = NO_DECODING_ERROR;
+ }
+ else
+ {
+ pExt->inputBufferCurrentLength = 0;
+ err = SYNCH_LOST_ERROR;
+ }
+ }
+ else
+ {
+ pExt->inputBufferCurrentLength = 0;
+ }
+
+ return(err);
+
+}
+
+/*
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+------------------------------------------------------------------------------
+ INPUT AND OUTPUT DEFINITIONS
+
+pvmp3_header_sync
+
+Input
+ tmp3Bits *inputStream, structure holding the input stream parameters
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ search mp3 sync word
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+
+ERROR_CODE pvmp3_header_sync(tmp3Bits *inputStream)
+{
+ uint16 val;
+ uint32 availableBits = (inputStream->inputBufferCurrentLength << 3); // in bits
+
+ // byte aligment
+ inputStream->usedBits = (inputStream->usedBits + 7) & 8;
+
+ val = (uint16)getUpTo17bits(inputStream, SYNC_WORD_LNGTH);
+
+ while (((val&SYNC_WORD) != SYNC_WORD) && (inputStream->usedBits < availableBits))
+ {
+ val <<= 8;
+ val |= getUpTo9bits(inputStream, 8);
+ }
+
+ if ((val&SYNC_WORD) == SYNC_WORD && (inputStream->usedBits < availableBits))
+ {
+ return(NO_DECODING_ERROR);
+ }
+ else
+ {
+ return(SYNCH_LOST_ERROR);
+ }
+
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_seek_synch.h b/media/codecs/mp3dec/src/pvmp3_seek_synch.h
new file mode 100644
index 0000000..8097cee
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_seek_synch.h
@@ -0,0 +1,106 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_seek_synch.h
+
+ Date: 09/21/2007
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_SEEK_SYNCH_H
+#define PVMP3_SEEK_SYNCH_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3decoder_api.h"
+#include "s_tmp3dec_file.h"
+#include "pvmp3_dec_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ ERROR_CODE pvmp3_frame_synch(tPVMP3DecoderExternal *pExt,
+ void *pMem);
+
+ ERROR_CODE pvmp3_header_sync(tmp3Bits *inputStream);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif /* DECODE_READ_INPUT_H */
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_stereo_proc.cpp b/media/codecs/mp3dec/src/pvmp3_stereo_proc.cpp
new file mode 100644
index 0000000..4338c43
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_stereo_proc.cpp
@@ -0,0 +1,680 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_stereo_proc.cpp
+
+ Functions:
+
+ pvmp3_st_mid_side
+ pvmp3_st_intensity
+ pvmp3_stereo_proc
+
+------------------------------------------------------------------------------
+
+pvmp3_st_mid_side
+
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+
+ int32 xr[], input channel
+ int32 xl[],
+ int32 Start, Location of first element where stereo intensity is applied
+ int32 Number number of elements affected
+
+ Returns
+
+ int32 xl[], generated stereo channel
+
+
+------------------------------------------------------------------------------
+
+pvmp3_st_intensity
+
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+
+ int32 xr[], input channel
+ int32 xl[],
+ int32 is_pos, index to table is_ratio_factor[]
+ int32 Start, Location of first element where stereo intensity is applied
+ int32 Number number of elements affected
+
+ Returns
+
+ int32 xl[], generated stereo channel
+
+
+------------------------------------------------------------------------------
+
+pvmp3_stereo_proc
+
+ INPUT AND OUTPUT DEFINITIONS
+
+Input
+
+ int32 xr[], input channel
+ int32 xl[],
+ mp3ScaleFactors *scalefac, scale factors structure
+ struct gr_info_s *gr_info, granule structure
+ mp3Header *info mp3 header info
+ Returns
+
+ int32 xl[], generated stereo channel
+
+
+------------------------------------------------------------------------------
+ FUNCTION DESCRIPTION
+
+ stereo processing for mpeg1 layer III
+ After requantization, the reconstructed values are processed for ms_stereo
+ or intensity_stereo modes or both, before passing them to the synthesis
+ filterbank
+
+ In ms_stereo mode the values of the normalized middle/side channels
+ M[l] and S[l] are transmitted instead of the left/right channel values
+ L[l] and R[l]. From here, L[l] and R[l] are reconstructed
+
+ Intensity_stereo is done by specifying the magnitude (via the
+ scalefactors of the left channel) and a stereo position is_pos[sfb],
+ which is transmitted instead of scalefactors of the right channel.
+ The stereo position is used to derive the left and right channel signals
+
+------------------------------------------------------------------------------
+ REQUIREMENTS
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+ PSEUDO-CODE
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_stereo_proc.h"
+#include "pv_mp3dec_fxd_op.h"
+#include "pvmp3_tables.h"
+
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+#define N31 31
+
+#define Q31_fmt(a) (int32(double(0x7FFFFFFF)*(a)))
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+/*
+ * TmpFac= tan(is_pos * (PI /12));
+ *
+ * TmpFac /= (1 + TmpFac);
+ *
+ */
+
+const int32 is_ratio_factor[8] = {0,
+ Q31_fmt(0.21132486540519), Q31_fmt(0.36602540378444), Q31_fmt(0.50000000000000),
+ Q31_fmt(0.63397459621556), Q31_fmt(0.78867513459481), Q31_fmt(1.00000000000000),
+ 0
+ };
+
+/*----------------------------------------------------------------------------
+; EXTERNAL FUNCTION REFERENCES
+; Declare functions defined elsewhere and referenced in this module
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+#if __has_attribute(no_sanitize)
+// deliberately playing near overflow points of int32
+__attribute__((no_sanitize("integer")))
+#endif
+void pvmp3_st_mid_side(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 Start,
+ int32 Number)
+{
+
+ int32 *pt_xr = &xr[Start];
+ int32 *pt_xl = &xl[Start];
+
+ for (int32 i = Number >> 1; i != 0; i--)
+ {
+ int32 xxr = *(pt_xr) << 1;
+ int32 xxl = *(pt_xl) << 1;
+ *(pt_xr++) = fxp_mul32_Q32((xxr + xxl), Q31_fmt(0.70710678118655)); /* Sum */
+ *(pt_xl++) = fxp_mul32_Q32((xxr - xxl), Q31_fmt(0.70710678118655)); /* Diff */
+ xxr = *(pt_xr) << 1;
+ xxl = *(pt_xl) << 1;
+ *(pt_xr++) = fxp_mul32_Q32((xxr + xxl), Q31_fmt(0.70710678118655)); /* Sum */
+ *(pt_xl++) = fxp_mul32_Q32((xxr - xxl), Q31_fmt(0.70710678118655)); /* Diff */
+ }
+
+
+ if (Number&1)
+ {
+ int32 xxr = *(pt_xr) << 1;
+ int32 xxl = *(pt_xl) << 1;
+ *(pt_xr) = fxp_mul32_Q32((xxr + xxl), Q31_fmt(0.70710678118655)); /* Sum */
+ *(pt_xl) = fxp_mul32_Q32((xxr - xxl), Q31_fmt(0.70710678118655)); /* Diff */
+ }
+
+}
+
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+
+void pvmp3_st_intensity(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 is_pos,
+ int32 Start,
+ int32 Number)
+{
+
+ int32 TmpFac = is_ratio_factor[ is_pos & 7];
+
+ int32 *pt_xr = &xr[Start];
+ int32 *pt_xl = &xl[Start];
+
+ for (int32 i = Number >> 1; i != 0; i--)
+ {
+ int32 tmp = fxp_mul32_Q32((*pt_xr) << 1, TmpFac);
+ *(pt_xl++) = (*pt_xr) - tmp;
+ *(pt_xr++) = tmp;
+ tmp = fxp_mul32_Q32((*pt_xr) << 1, TmpFac);
+ *(pt_xl++) = (*pt_xr) - tmp;
+ *(pt_xr++) = tmp;
+ }
+
+ if (Number&1)
+ {
+ int32 tmp = fxp_mul32_Q32((*pt_xr) << 1, TmpFac);
+ *(pt_xl) = (*pt_xr) - tmp;
+ *(pt_xr) = tmp;
+ }
+
+}
+
+/*----------------------------------------------------------------------------
+; FUNCTION CODE
+----------------------------------------------------------------------------*/
+void pvmp3_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ mp3ScaleFactors *scalefac,
+ granuleInfo *gr_info,
+ int32 used_freq_lines,
+ mp3Header *info)
+{
+
+
+ int32 sb;
+ int32 ss;
+ int32 sfbNo;
+ int32 sfbStart;
+
+ int32 sfb;
+ int32 sfbTemp;
+ int32 i;
+ int32 j;
+
+
+ int32 i_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
+ (info->mode_ext & 0x1);
+
+ int32 ms_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
+ (info->mode_ext & 0x2);
+
+ int32 sfreq = info->version_x + (info->version_x << 1);
+ sfreq += info->sampling_frequency;
+
+
+
+
+ if (i_stereo)
+ {
+ if (gr_info->window_switching_flag && (gr_info->block_type == 2))
+ {
+ if (gr_info->mixed_block_flag)
+ {
+ /*
+ * mixed blocks processing
+ */
+ i = 31;
+ ss = 17;
+ sb = 0;
+ while (i >= 0)
+ {
+ if (xl[(i*FILTERBANK_BANDS) + ss])
+ {
+ sb = (i << 4) + (i << 1) + ss;
+ i = -1;
+ }
+ else
+ {
+ ss--;
+ if (ss < 0)
+ {
+ i--;
+ ss = 17;
+ }
+ }
+ }
+
+ if (sb < 36)
+ {
+ /*
+ * mixed blocks processing: intensity bound inside long blocks
+ */
+ /* 1. long blocks up to intensity border: not intensity */
+
+ if (mp3_sfBandIndex[sfreq].l[4] <= sb)
+ {
+ sfb = 4;
+ }
+ else
+ {
+ sfb = 0;
+ }
+
+ while (mp3_sfBandIndex[sfreq].l[sfb] < sb)
+ {
+ sfb++;
+ }
+
+ /* from that sfb on intensity stereo */
+ sfbTemp = sfb; /* save for later use */
+
+ sfbStart = mp3_sfBandIndex[sfreq].l[sfb];
+
+ /* from 0 up to sfbStart do ms_stereo or normal stereo */
+
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, 0, sfbStart);
+ }
+
+ /* 2. long blocks from intensity border up to sfb band 8: intensity */
+ /* calc. is_ratio */
+
+
+ /* Start of intensity stereo of remaining sfc bands: */
+ for (; sfbTemp < 8; sfbTemp++)
+ {
+ sfbStart = mp3_sfBandIndex[sfreq].l[sfbTemp]; /* = Start in 0 ... 575 */
+ sfbNo = mp3_sfBandIndex[sfreq].l[sfbTemp+1] - mp3_sfBandIndex[sfreq].l[sfbTemp]; /* No of lines to process */
+
+ if (scalefac->l[sfbTemp] != 7)
+ {
+ pvmp3_st_intensity(xr, xl, scalefac->l[sfbTemp], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ } /* for (; sfbTemp < 8; sfbTemp++) */
+
+ for (j = 0; j < 3; j++)
+ {
+ /* 3. short blocks from sfbcnt to last sfb do intensity stereo */
+ for (sfbTemp = 3; sfbTemp < 13; sfbTemp++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfbTemp+1] - mp3_sfBandIndex[sfreq].s[sfbTemp]; /* No of lines to process */
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfbTemp] + j * sfbNo;
+
+ if (scalefac->s[j][sfbTemp] != 7)
+ {
+ pvmp3_st_intensity(xr, xl, scalefac->s[j][sfbTemp], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ } /* for (; sfbTemp < 22; sfbTemp++) */
+ } /* for (j = 0; j < 3; j++) */
+ }
+ else /* else for (sb >= 36) */
+ {
+ /*
+ * mixed blocks processing: intensity bound outside long blocks
+ */
+
+
+ /*
+ * 2. short blocks from sfb band 3 up to intensity border: normal stereo, ms stereo and intensity
+ */
+ for (j = 0; j < 3; j++)
+ {
+ int32 sfbcnt;
+ sfbcnt = -1;
+
+ for (sfb = 12; sfb >= 3; sfb--)
+ {
+ int32 lines;
+ lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+ i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
+
+ while (lines > 0)
+ {
+ if (xl[i])
+ {
+ sfbcnt = sfb;
+ sfb = -10;
+ lines = -10;
+ }
+ lines--;
+ i--;
+ }
+ }
+
+ sfbcnt += 1;
+ if (sfbcnt < 3)
+ {
+ sfbcnt = 3;
+ }
+
+ sfbTemp = sfbcnt; /* for later use */
+
+
+ /*
+ * do normal stereo or MS stereo from sfb 3 to < sfbcnt:
+ */
+ for (sb = 3; sb < sfbcnt; sb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sb+1] - mp3_sfBandIndex[sfreq].s[sb];
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sb] + j * sfbNo;
+
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ }
+
+ /* from sfbcnt to last sfb do intensity stereo */
+ for (; sfbTemp < 13; sfbTemp++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfbTemp+1] - mp3_sfBandIndex[sfreq].s[sfbTemp]; /* No of lines to process */
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfbTemp] + j * sfbNo;
+
+ if (scalefac->s[j][sfbTemp] != 7)
+ {
+ pvmp3_st_intensity(xr, xl, scalefac->s[j][sfbTemp], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ } /* for (; sfbTemp < 22; sfbTemp++) */
+
+ } /* for (j = 0; j < 3; j++) */
+
+ /* 1. long blocks up to sfb band 8: not intensity */
+ /* from 0 to sfb 8 ms_stereo or normal stereo */
+
+ sfbStart = mp3_sfBandIndex[sfreq].l[8];
+
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, 0, sfbStart);
+ }
+
+ }
+ } /* if (gr_info->mixed_block_flag) */
+ else
+ {
+ /*
+ * short block processing
+ */
+ for (j = 0; j < 3; j++)
+ {
+ int32 sfbcnt = -1;
+
+ for (sfb = 12; sfb >= 0; sfb--)
+ {
+ int32 lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
+ i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
+
+ while (lines > 0)
+ {
+ if (xl[i])
+ {
+ sfbcnt = sfb;
+ sfb = -10;
+ lines = -10;
+ }
+ lines--;
+ i--;
+ }
+ }
+
+ sfbcnt += 1;
+ sfbTemp = sfbcnt; /* for later use */
+
+ /* do normal stereo or MS stereo from 0 to sfbcnt */
+ for (sb = 0; sb < sfbcnt; sb++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sb+1] - mp3_sfBandIndex[sfreq].s[sb];
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sb] + j * sfbNo;
+
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+ }
+
+
+ /* from sfbcnt to last sfb do intensity stereo */
+ for (; sfbTemp < 13; sfbTemp++)
+ {
+ sfbNo = mp3_sfBandIndex[sfreq].s[sfbTemp+1] - mp3_sfBandIndex[sfreq].s[sfbTemp]; /* No of lines to process */
+ sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfbTemp] + j * sfbNo;
+
+ if (scalefac->s[j][sfbTemp] != 7)
+ {
+ pvmp3_st_intensity(xr, xl, scalefac->s[j][sfbTemp], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ } /* for (; sfbTemp < 22; sfbTemp++) */
+
+ } /* for (j = 0; j < 3; j++) */
+
+ } /* if( gr_info->mixed_block_flag) */
+
+
+
+ } /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
+ else
+ {
+ /*
+ * long block processing
+ */
+ i = 31;
+ ss = 17;
+ sb = 0;
+
+ while (i >= 0)
+ {
+ if (xl[(i*FILTERBANK_BANDS) + ss] != 0)
+ {
+ sb = (i << 4) + (i << 1) + ss;
+ i = -2;
+ }
+ else
+ {
+ ss--;
+ if (ss < 0)
+ {
+ i--;
+ ss = 17;
+ }
+ }
+ }
+
+ if (sb)
+ {
+ if (mp3_sfBandIndex[sfreq].l[14] <= sb)
+ {
+ sfb = 14;
+ }
+ else if (mp3_sfBandIndex[sfreq].l[7] <= sb)
+ {
+ sfb = 7;
+ }
+ else
+ {
+ sfb = 0;
+ }
+
+
+ while (mp3_sfBandIndex[sfreq].l[sfb] <= sb)
+ {
+ sfb++;
+ }
+ }
+ else
+ {
+ if (i == -1)
+ {
+ /* all xr[1][][] are 0: set IS bound sfb to 0 */
+ sfb = 0;
+ }
+ else
+ {
+ /* xr[1][0][0] is unequal 0 and all others are 0: set IS bound sfb to 1 */
+ sfb = 1;
+ }
+ }
+
+ sfbTemp = sfb; /* save for later use */
+
+
+ sfbStart = mp3_sfBandIndex[sfreq].l[sfb];
+
+ /* from 0 to sfbStart ms_stereo or normal stereo */
+ if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, 0, sfbStart);
+ }
+
+ /* now intensity stereo of the remaining sfb's: */
+ for (; sfb < 21; sfb++)
+ {
+ sfbStart = mp3_sfBandIndex[sfreq].l[sfb];
+ sfbNo = mp3_sfBandIndex[sfreq].l[sfb+1] - mp3_sfBandIndex[sfreq].l[sfb]; /* No of lines to process */
+
+ if (scalefac->l[sfb] != 7)
+ {
+ pvmp3_st_intensity(xr, xl, scalefac->l[sfb], sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ } /* for (; sfbTemp < 22; sfbTemp++) */
+
+
+
+ sfbStart = mp3_sfBandIndex[sfreq].l[21];
+ sfbNo = mp3_sfBandIndex[sfreq].l[22] - mp3_sfBandIndex[sfreq].l[21]; /* No of lines to process */
+
+ if (scalefac->l[21] != 7)
+ {
+ if (sfbTemp < 21)
+ {
+ sfbTemp = scalefac->l[20];
+ }
+ else
+ {
+ sfbTemp = 0; /* if scalefac[20] is not an intensity position, is_pos = 0 */
+ }
+
+ pvmp3_st_intensity(xr, xl, sfbTemp, sfbStart, sfbNo);
+ }
+ else if (ms_stereo)
+ {
+ pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
+ }
+
+ } /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
+
+
+ } /* if (i_stereo) */
+ else
+ {
+ /*
+ * normal or ms stereo processing
+ */
+ if (ms_stereo)
+ {
+
+ pvmp3_st_mid_side(xr, xl, 0, used_freq_lines);
+
+ }
+
+ } /* if (i_stereo) */
+
+}
+
diff --git a/media/codecs/mp3dec/src/pvmp3_stereo_proc.h b/media/codecs/mp3dec/src/pvmp3_stereo_proc.h
new file mode 100644
index 0000000..bfaf1a1
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_stereo_proc.h
@@ -0,0 +1,114 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_stereo_proc.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef PVMP3_STEREO_PROC_H
+#define PVMP3_STEREO_PROC_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+ void pvmp3_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ mp3ScaleFactors *scalefac,
+ granuleInfo *gr_info,
+ int32 used_freq_lines,
+ mp3Header *info);
+
+ void pvmp3_st_intensity(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 is_pos,
+ int32 Start,
+ int32 Number);
+
+ void pvmp3_st_mid_side(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
+ int32 Start,
+ int32 Number);
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/pvmp3_tables.cpp b/media/codecs/mp3dec/src/pvmp3_tables.cpp
new file mode 100644
index 0000000..91113e3
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_tables.cpp
@@ -0,0 +1,2934 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: pvmp3_tables.cpp
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+
+ Description:
+
+
+------------------------------------------------------------------------------
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+------------------------------------------------------------------------------
+*/
+
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_tables.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here. Include conditional
+; compile variables also.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; LOCAL STORE/BUFFER/POINTER DEFINITIONS
+; Variable declaration - defined here and used outside this module
+----------------------------------------------------------------------------*/
+
+const int32 mp3_s_freq[4][4] =
+{
+ {44100, 48000, 32000, 0},
+ {22050, 24000, 16000, 0},
+ {11025, 12000, 8000, 0}
+}; // MPEG-2.5
+
+
+/*
+ * 144000./s_freq
+ */
+const int32 inv_sfreq[4] =
+{
+ Qfmt_28(3.26530612244898),
+ Qfmt_28(3.0),
+ Qfmt_28(4.5),
+ 0
+};
+
+
+/* 1: MPEG-1, 0: MPEG-2 LSF, 1995-07-11 shn */
+
+
+const int16 mp3_bitrate[3][15] =
+{
+ {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320},
+ {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
+ {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}
+};
+
+
+const mp3_scaleFactorBandIndex mp3_sfBandIndex[9] =
+{
+
+ /* MPEG 1 */
+
+ {{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576},
+ {0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192}},
+ {{0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576},
+ {0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192}},
+ {{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576},
+ {0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192}},
+
+ /* MPEG 2 - LSF */
+
+ {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+ {0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192}},
+ {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 332, 394, 464, 540, 576},
+ {0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192}},
+ {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+ {0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192}},
+
+ /* MPEG 2.5 extension */
+
+ {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+ {0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192}},
+ {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576},
+ {0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192}},
+ {{0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576},
+ {0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192}}
+
+};
+
+#define INV_Q31( x) (int32)(0x7FFFFFFF/(float)(x) - 1.0f)
+
+const int32 mp3_shortwindBandWidths[9][13] =
+{
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(8), INV_Q31(10),
+ INV_Q31(12), INV_Q31(14), INV_Q31(18), INV_Q31(22), INV_Q31(30), INV_Q31(56)},
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(6), INV_Q31(10),
+ INV_Q31(12), INV_Q31(14), INV_Q31(16), INV_Q31(20), INV_Q31(26), INV_Q31(66)},
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(8), INV_Q31(12),
+ INV_Q31(16), INV_Q31(20), INV_Q31(26), INV_Q31(34), INV_Q31(42), INV_Q31(12)},
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(6), INV_Q31(8), INV_Q31(10),
+ INV_Q31(14), INV_Q31(18), INV_Q31(26), INV_Q31(32), INV_Q31(42), INV_Q31(18)},
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(8), INV_Q31(10), INV_Q31(12),
+ INV_Q31(14), INV_Q31(18), INV_Q31(24), INV_Q31(32), INV_Q31(44), INV_Q31(12)},
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(8), INV_Q31(10), INV_Q31(12),
+ INV_Q31(14), INV_Q31(18), INV_Q31(24), INV_Q31(30), INV_Q31(40), INV_Q31(18)},
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(8), INV_Q31(10), INV_Q31(12),
+ INV_Q31(14), INV_Q31(18), INV_Q31(24), INV_Q31(30), INV_Q31(40), INV_Q31(18)},
+ { INV_Q31(4), INV_Q31(4), INV_Q31(4), INV_Q31(6), INV_Q31(8), INV_Q31(10), INV_Q31(12),
+ INV_Q31(14), INV_Q31(18), INV_Q31(24), INV_Q31(30), INV_Q31(40), INV_Q31(18)},
+ { INV_Q31(8), INV_Q31(8), INV_Q31(8), INV_Q31(12), INV_Q31(16), INV_Q31(20), INV_Q31(24),
+ INV_Q31(28), INV_Q31(36), INV_Q31(2), INV_Q31(2), INV_Q31(2), INV_Q31(26)}
+};
+
+
+#define Q30_fmt(a) (int32((0x40000000)*(a)))
+
+const int32 pqmfSynthWin[(HAN_SIZE/2) + 8] =
+{
+ Q30_fmt(-0.000015259F), Q30_fmt(0.000396729F), Q30_fmt(0.000473022F), Q30_fmt(0.003173828F),
+ Q30_fmt(0.003326416F), Q30_fmt(0.006118770F), Q30_fmt(0.007919310F), Q30_fmt(0.031478880F),
+ Q30_fmt(0.030517578F), Q30_fmt(0.073059080F), Q30_fmt(0.084182740F), Q30_fmt(0.108856200F),
+ Q30_fmt(0.090927124F), Q30_fmt(0.543823240F), Q30_fmt(0.600219727F), Q30_fmt(1.144287109F),
+
+ Q30_fmt(-0.000015259F), Q30_fmt(0.000366211F), Q30_fmt(0.000534058F), Q30_fmt(0.003082275F),
+ Q30_fmt(0.003387451F), Q30_fmt(0.005294800F), Q30_fmt(0.008865360F), Q30_fmt(0.031738280F),
+ Q30_fmt(0.029785160F), Q30_fmt(0.067520140F), Q30_fmt(0.089706420F), Q30_fmt(0.116577150F),
+ Q30_fmt(0.080688480F), Q30_fmt(0.515609740F), Q30_fmt(0.628295900F), Q30_fmt(1.142211914F),
+
+ Q30_fmt(-0.000015259F), Q30_fmt(0.000320435F), Q30_fmt(0.000579834F), Q30_fmt(0.002990723F),
+ Q30_fmt(0.003433228F), Q30_fmt(0.004486080F), Q30_fmt(0.009841920F), Q30_fmt(0.031845090F),
+ Q30_fmt(0.028884890F), Q30_fmt(0.061996460F), Q30_fmt(0.095169070F), Q30_fmt(0.123474120F),
+ Q30_fmt(0.069595340F), Q30_fmt(0.487472530F), Q30_fmt(0.656219480F), Q30_fmt(1.138763428F),
+
+ Q30_fmt(-0.000015259F), Q30_fmt(0.000289917F), Q30_fmt(0.000625610F), Q30_fmt(0.002899170F),
+ Q30_fmt(0.003463745F), Q30_fmt(0.003723140F), Q30_fmt(0.010849000F), Q30_fmt(0.031814580F),
+ Q30_fmt(0.027801510F), Q30_fmt(0.056533810F), Q30_fmt(0.100540160F), Q30_fmt(0.129577640F),
+ Q30_fmt(0.057617190F), Q30_fmt(0.459472660F), Q30_fmt(0.683914180F), Q30_fmt(1.133926392F),
+
+ Q30_fmt(-0.000015259F), Q30_fmt(0.000259399F), Q30_fmt(0.000686646F), Q30_fmt(0.002792358F),
+ Q30_fmt(0.003479004F), Q30_fmt(0.003005981F), Q30_fmt(0.011886600F), Q30_fmt(0.031661990F),
+ Q30_fmt(0.026535030F), Q30_fmt(0.051132200F), Q30_fmt(0.105819700F), Q30_fmt(0.134887700F),
+ Q30_fmt(0.044784550F), Q30_fmt(0.431655880F), Q30_fmt(0.711318970F), Q30_fmt(1.127746582F),
+
+ Q30_fmt(-0.000015259F), Q30_fmt(0.000244141F), Q30_fmt(0.000747681F), Q30_fmt(0.002685547F),
+ Q30_fmt(0.003479004F), Q30_fmt(0.002334595F), Q30_fmt(0.012939450F), Q30_fmt(0.031387330F),
+ Q30_fmt(0.025085450F), Q30_fmt(0.045837400F), Q30_fmt(0.110946660F), Q30_fmt(0.139450070F),
+ Q30_fmt(0.031082153F), Q30_fmt(0.404083250F), Q30_fmt(0.738372800F), Q30_fmt(1.120223999F),
+
+ Q30_fmt(-0.000030518F), Q30_fmt(0.000213623F), Q30_fmt(0.000808716F), Q30_fmt(0.002578735F),
+ Q30_fmt(0.003463745F), Q30_fmt(0.001693726F), Q30_fmt(0.014022830F), Q30_fmt(0.031005860F),
+ Q30_fmt(0.023422240F), Q30_fmt(0.040634160F), Q30_fmt(0.115921020F), Q30_fmt(0.143264770F),
+ Q30_fmt(0.016510010F), Q30_fmt(0.376800540F), Q30_fmt(0.765029907F), Q30_fmt(1.111373901F),
+
+ Q30_fmt(-0.000030518F), Q30_fmt(0.000198364F), Q30_fmt(0.000885010F), Q30_fmt(0.002456665F),
+ Q30_fmt(0.003417969F), Q30_fmt(0.001098633F), Q30_fmt(0.015121460F), Q30_fmt(0.030532840F),
+ Q30_fmt(0.021575930F), Q30_fmt(0.035552980F), Q30_fmt(0.120697020F), Q30_fmt(0.146362300F),
+ Q30_fmt(0.001068120F), Q30_fmt(0.349868770F), Q30_fmt(0.791213990F), Q30_fmt(1.101211548F),
+
+ Q30_fmt(-0.000030518F), Q30_fmt(0.000167847F), Q30_fmt(0.000961304F), Q30_fmt(0.002349854F),
+ Q30_fmt(0.003372192F), Q30_fmt(0.000549316F), Q30_fmt(0.016235350F), Q30_fmt(0.029937740F),
+ Q30_fmt(0.019531250F), Q30_fmt(0.030609130F), Q30_fmt(0.125259400F), Q30_fmt(0.148773190F),
+ Q30_fmt(-0.015228270F), Q30_fmt(0.323318480F), Q30_fmt(0.816864010F), Q30_fmt(1.089782715F),
+
+ Q30_fmt(-0.000030518F), Q30_fmt(0.000152588F), Q30_fmt(0.001037598F), Q30_fmt(0.002243042F),
+ Q30_fmt(0.003280640F), Q30_fmt(0.000030518F), Q30_fmt(0.017349240F), Q30_fmt(0.029281620F),
+ Q30_fmt(0.017257690F), Q30_fmt(0.025817870F), Q30_fmt(0.129562380F), Q30_fmt(0.150497440F),
+ Q30_fmt(-0.032379150F), Q30_fmt(0.297210693F), Q30_fmt(0.841949463F), Q30_fmt(1.077117920F),
+
+ Q30_fmt(-0.000045776F), Q30_fmt(0.000137329F), Q30_fmt(0.001113892F), Q30_fmt(0.002120972F),
+ Q30_fmt(0.003173828F), Q30_fmt(-0.000442505F), Q30_fmt(0.018463130F), Q30_fmt(0.028533940F),
+ Q30_fmt(0.014801030F), Q30_fmt(0.021179200F), Q30_fmt(0.133590700F), Q30_fmt(0.151596070F),
+ Q30_fmt(-0.050354000F), Q30_fmt(0.271591190F), Q30_fmt(0.866363530F), Q30_fmt(1.063217163F),
+
+ Q30_fmt(-0.000045776F), Q30_fmt(0.000122070F), Q30_fmt(0.001205444F), Q30_fmt(0.002014160F),
+ Q30_fmt(0.003051758F), Q30_fmt(-0.000869751F), Q30_fmt(0.019577030F), Q30_fmt(0.027725220F),
+ Q30_fmt(0.012115480F), Q30_fmt(0.016708370F), Q30_fmt(0.137298580F), Q30_fmt(0.152069090F),
+ Q30_fmt(-0.069168090F), Q30_fmt(0.246505740F), Q30_fmt(0.890090940F), Q30_fmt(1.048156738F),
+
+ Q30_fmt(-0.000061035F), Q30_fmt(0.000106812F), Q30_fmt(0.001296997F), Q30_fmt(0.001907349F),
+ Q30_fmt(0.002883911F), Q30_fmt(-0.001266479F), Q30_fmt(0.020690920F), Q30_fmt(0.026840210F),
+ Q30_fmt(0.009231570F), Q30_fmt(0.012420650F), Q30_fmt(0.140670780F), Q30_fmt(0.151962280F),
+ Q30_fmt(-0.088775630F), Q30_fmt(0.221984860F), Q30_fmt(0.913055420F), Q30_fmt(1.031936646F),
+
+ Q30_fmt(-0.000061035F), Q30_fmt(0.000106812F), Q30_fmt(0.001388550F), Q30_fmt(0.001785278F),
+ Q30_fmt(0.002700806F), Q30_fmt(-0.001617432F), Q30_fmt(0.021789550F), Q30_fmt(0.025909420F),
+ Q30_fmt(0.006134030F), Q30_fmt(0.008316040F), Q30_fmt(0.143676760F), Q30_fmt(0.151306150F),
+ Q30_fmt(-0.109161380F), Q30_fmt(0.198059080F), Q30_fmt(0.935195920F), Q30_fmt(1.014617920F),
+
+ Q30_fmt(-0.000076294F), Q30_fmt(0.000091553F), Q30_fmt(0.001480103F), Q30_fmt(0.001693726F),
+ Q30_fmt(0.002487183F), Q30_fmt(-0.001937866F), Q30_fmt(0.022857670F), Q30_fmt(0.024932860F),
+ Q30_fmt(0.002822880F), Q30_fmt(0.004394530F), Q30_fmt(0.146255490F), Q30_fmt(0.150115970F),
+ Q30_fmt(-0.130310060F), Q30_fmt(0.174789430F), Q30_fmt(0.956481930F), Q30_fmt(0.996246338F),
+
+ Q30_fmt(0.000000000F), Q30_fmt(0.000442505F), Q30_fmt(0.001586910F), Q30_fmt(0.003250122F),
+ Q30_fmt(0.007003780F), Q30_fmt(0.023910525F), Q30_fmt(0.031082153F), Q30_fmt(0.078628545F),
+ Q30_fmt(0.148422240F), Q30_fmt(0.100311279F), Q30_fmt(0.572036740F), Q30_fmt(0.976852417F),
+ Q30_fmt(1.144989014F), Q30_fmt(-0.572036745F), Q30_fmt(-0.152206421F), Q30_fmt(0.100311279F),
+
+ Q30_fmt(-0.078628540F), Q30_fmt(-0.000686646F), Q30_fmt(0.031082153F), Q30_fmt(-0.007003785F),
+ Q30_fmt(0.002227783F), Q30_fmt(0.003250122F), Q30_fmt(-0.000442500F), Q30_fmt(-0.000076294F),
+};
+
+
+
+
+
+const uint16 huffTable_1[8] =
+{
+ 0x1103, 0x0103, 0x1002, 0x1002,
+ 0x0001, 0x0001, 0x0001, 0x0001
+};
+
+const uint16 huffTable_2[15] =
+{
+ 0x1103, 0x0103, 0x1003, 0x0001,
+ 0x0001, 0x0001, 0x0001, 0x2206,
+ 0x0206, 0x1205, 0x1205, 0x2105,
+ 0x2105, 0x2005, 0x2005
+};
+
+const uint16 huffTable_3[15] =
+{
+
+ 0x1003, 0x1102, 0x1102, 0x0102,
+ 0x0102, 0x0002, 0x0002, 0x2206,
+ 0x0206, 0x1205, 0x1205, 0x2105,
+ 0x2105, 0x2005, 0x2005
+};
+
+const uint16 huffTable_5[25] =
+{
+
+ 0x1103, 0x0103, 0x1003, 0x0001,
+ 0x0001, 0x0001, 0x0001, 0x3106,
+ 0x3106, 0x1307, 0x0307, 0x3007,
+ 0x2207, 0x1206, 0x1206, 0x2106,
+ 0x2106, 0x0206, 0x0206, 0x2006,
+ 0x2006, 0x3308, 0x2308, 0x3207,
+ 0x3207
+};
+
+
+const uint16 huffTable_6[26] =
+{
+
+ 0x1204, 0x2104, 0x2004, 0x0103,
+ 0x0103, 0x1102, 0x1102, 0x1102,
+ 0x1102, 0x1003, 0x1003, 0x0003,
+ 0x0003, 0x2306, 0x3206, 0x3006,
+ 0x1305, 0x1305, 0x3105, 0x3105,
+ 0x2205, 0x2205, 0x0205, 0x0205,
+ 0x3307, 0x0307
+};
+
+
+
+const uint16 huffTable_7[73] =
+{
+ 0x0103,
+ 0x1003,
+ 0x0001,
+ 0x0001,
+ 0x0001,
+ 0x0001,
+ 0x1206,
+ 0x2105,
+ 0x2105,
+ 0x0206,
+ 0x2006,
+ 0x1104,
+ 0x1104,
+ 0x1104,
+ 0x1104,
+ 0x3509,
+ 0x4409,
+ 0x2509,
+ 0x5209,
+ 0x1508,
+ 0x1508,
+ 0x5108,
+ 0x5108,
+ 0x0509,
+ 0x3409,
+ 0x5008,
+ 0x5008,
+ 0x4309,
+ 0x3309,
+ 0x2408,
+ 0x2408,
+ 0x4208,
+ 0x4208,
+ 0x1407,
+ 0x1407,
+ 0x1407,
+ 0x1407,
+ 0x4107,
+ 0x4107,
+ 0x4107,
+ 0x4107,
+ 0x4007,
+ 0x4007,
+ 0x4007,
+ 0x4007,
+ 0x0408,
+ 0x0408,
+ 0x2308,
+ 0x2308,
+ 0x3208,
+ 0x3208,
+ 0x0308,
+ 0x0308,
+ 0x1307,
+ 0x1307,
+ 0x1307,
+ 0x1307,
+ 0x3107,
+ 0x3107,
+ 0x3107,
+ 0x3107,
+ 0x3007,
+ 0x3007,
+ 0x3007,
+ 0x3007,
+ 0x2207,
+ 0x2207,
+ 0x2207,
+ 0x2207,
+ 0x550a,
+ 0x450a,
+ 0x540a,
+ 0x530a
+};
+
+const uint16 huffTable_8[66] =
+{
+ 0x1204,
+ 0x2104,
+ 0x1102,
+ 0x1102,
+ 0x1102,
+ 0x1102,
+ 0x0103,
+ 0x0103,
+ 0x1003,
+ 0x1003,
+ 0x0002,
+ 0x0002,
+ 0x0002,
+ 0x0002,
+ 0x2206,
+ 0x0206,
+ 0x2006,
+ 0x2509,
+ 0x5209,
+ 0x0509,
+ 0x1508,
+ 0x1508,
+ 0x5108,
+ 0x5108,
+ 0x3409,
+ 0x4309,
+ 0x5009,
+ 0x3309,
+ 0x2408,
+ 0x2408,
+ 0x4208,
+ 0x4208,
+ 0x1408,
+ 0x1408,
+ 0x4107,
+ 0x4107,
+ 0x4107,
+ 0x4107,
+ 0x0408,
+ 0x0408,
+ 0x4008,
+ 0x4008,
+ 0x2308,
+ 0x2308,
+ 0x3208,
+ 0x3208,
+ 0x1308,
+ 0x1308,
+ 0x3108,
+ 0x3108,
+ 0x0308,
+ 0x0308,
+ 0x3008,
+ 0x3008,
+ 0x550b,
+ 0x540b,
+ 0x450a,
+ 0x450a,
+ 0x5309,
+ 0x5309,
+ 0x5309,
+ 0x5309,
+ 0x350a,
+ 0x350a,
+ 0x440a,
+ 0x440a
+
+};
+
+
+const uint16 huffTable_9[53] =
+{
+ 0x1204,
+ 0x2104,
+ 0x2004,
+ 0x1103,
+ 0x1103,
+ 0x0103,
+ 0x0103,
+ 0x1003,
+ 0x1003,
+ 0x0003,
+ 0x0003,
+ 0x1406,
+ 0x4106,
+ 0x2306,
+ 0x3206,
+ 0x1305,
+ 0x1305,
+ 0x3105,
+ 0x3105,
+ 0x0306,
+ 0x3006,
+ 0x2205,
+ 0x2205,
+ 0x0205,
+ 0x0205,
+ 0x4408,
+ 0x2508,
+ 0x5208,
+ 0x1508,
+ 0x5107,
+ 0x5107,
+ 0x3407,
+ 0x3407,
+ 0x4307,
+ 0x4307,
+ 0x5008,
+ 0x0408,
+ 0x2407,
+ 0x2407,
+ 0x4207,
+ 0x4207,
+ 0x3307,
+ 0x3307,
+ 0x4007,
+ 0x4007,
+ 0x5509,
+ 0x4509,
+ 0x3508,
+ 0x3508,
+ 0x5308,
+ 0x5308,
+ 0x5409,
+ 0x0509
+
+};
+
+
+const uint16 huffTable_10[96] =
+{
+ 0x0001,
+ 0x1104,
+ 0x0103,
+ 0x0103,
+ 0x1003,
+ 0x1003,
+ 0x1206,
+ 0x2106,
+ 0x0206,
+ 0x2006,
+ 0x1408,
+ 0x4108,
+ 0x4008,
+ 0x2308,
+ 0x3208,
+ 0x0308,
+ 0x1307,
+ 0x1307,
+ 0x3107,
+ 0x3107,
+ 0x3007,
+ 0x3007,
+ 0x2207,
+ 0x2207,
+ 0x1608,
+ 0x1608,
+ 0x6108,
+ 0x6108,
+ 0x6008,
+ 0x6008,
+ 0x0509,
+ 0x5009,
+ 0x2409,
+ 0x4209,
+ 0x3309,
+ 0x0409,
+ 0x2709,
+ 0x2709,
+ 0x7209,
+ 0x7209,
+ 0x640a,
+ 0x070a,
+ 0x7009,
+ 0x7009,
+ 0x6209,
+ 0x6209,
+ 0x450a,
+ 0x350a,
+ 0x0609,
+ 0x0609,
+ 0x530a,
+ 0x440a,
+ 0x1708,
+ 0x1708,
+ 0x1708,
+ 0x1708,
+ 0x7108,
+ 0x7108,
+ 0x7108,
+ 0x7108,
+ 0x3609,
+ 0x3609,
+ 0x2609,
+ 0x2609,
+ 0x250a,
+ 0x520a,
+ 0x1509,
+ 0x1509,
+ 0x5109,
+ 0x5109,
+ 0x340a,
+ 0x430a,
+ 0x770b,
+ 0x670b,
+ 0x760b,
+ 0x570b,
+ 0x750b,
+ 0x660b,
+ 0x470a,
+ 0x470a,
+ 0x740a,
+ 0x740a,
+ 0x560a,
+ 0x560a,
+ 0x650a,
+ 0x650a,
+ 0x370a,
+ 0x370a,
+ 0x730a,
+ 0x730a,
+ 0x460a,
+ 0x460a,
+ 0x550b,
+ 0x540b,
+ 0x630a,
+ 0x630a
+};
+
+
+const uint16 huffTable_11[116] =
+{
+ 0x1103,
+ 0x0103,
+ 0x1003,
+ 0x0002,
+ 0x0002,
+ 0x2105,
+ 0x1204, /* 0100 */
+ 0x1204, /* 010 */
+ 0x0205, /* 01010 */
+ 0x2005, /* 01011 */
+ 0x1408, /* 10 */
+ 0x4108, /* 00 */
+ 0x0408, /* 0 0 */
+ 0x4008, /* 0 1 */
+ 0x2307, /* 0 */
+ 0x2307, /* */
+ 0x3207, /* 1 */
+ 0x3207, /* */
+ 0x1306, /* 010 */
+ 0x1306, /* 01 */
+ 0x1306, /* 01 */
+ 0x1306, /* 01 */
+ 0x3106, /* 011 */
+ 0x3106, /* 01 */
+ 0x3106, /* 01 */
+ 0x3106, /* 01 */
+ 0x0307, /* 1000 */
+ 0x0307, /* 100 */
+ 0x3007, /* 1 */
+ 0x3007, /* 100 */
+ 0x2206, /* 101 */
+ 0x2206, /* 10 */
+ 0x2206, /* 10 */
+ 0x2206, /* 10 */
+ 0x2708,
+ 0x2708, /* 000 0 */
+ 0x7208, /* 000 10 */
+ 0x7208, /* 000 1 */
+ 0x6409, /* 000 110 */
+ 0x0709,
+ 0x7107,
+ 0x7107,
+ 0x7107, /* 00 0 */
+ 0x7107, /* 00 0 */
+ 0x1708,
+ 0x1708, /* 00 01 */
+ 0x7008,
+ 0x7008,
+ 0x3608,
+ 0x3608, /* 00 10 */
+ 0x6308, /* 00 101 */
+ 0x6308, /* 00 10 */
+ 0x6008,
+ 0x6008, /* 00 11 */
+ 0x4409,
+ 0x2509,
+ 0x5209, /* 0 */
+ 0x0509, /* 0 00 */
+ 0x1508, /* 0 0 */
+ 0x1508, /* 0 000 */
+ 0x6207, /* 0 */
+ 0x6207, /* 0 00 */
+ 0x6207, /* 0 00 */
+ 0x6207, /* 0 00 */
+ 0x2608,
+ 0x2608, /* 0 010 */
+ 0x0608,
+ 0x0608,
+ 0x1607,
+ 0x1607,
+ 0x1607,
+ 0x1607,
+ 0x6107,
+ 0x6107,
+ 0x6107,
+ 0x6107,
+ 0x5108,
+ 0x5108,
+ 0x3408,
+ 0x3408,
+ 0x5008,
+ 0x5008,
+ 0x4309,
+ 0x3309,
+ 0x2408,
+ 0x2408, /* 0 111 */
+ 0x4208, /* 0 1111 */
+ 0x4208, /* 0 111 */
+ 0x560a,
+ 0x650a,
+ 0x3709,
+ 0x3709,
+ 0x7309,
+ 0x7309,
+ 0x4609,
+ 0x4609,
+ 0x450a,
+ 0x540a, /* 000 0 */
+ 0x350a, /* 000 0 */
+ 0x530a, /* 000 1 */
+ 0x770a,
+ 0x770a,
+ 0x670a,
+ 0x670a,
+ 0x760a, /* 0 */
+ 0x760a, /* */
+ 0x750a, /* 1 */
+ 0x750a, /* */
+ 0x660a, /* 00 */
+ 0x660a, /* 0 */
+ 0x470a, /* 01 */
+ 0x470a, /* 0 */
+ 0x740a, /* 10 */
+ 0x740a, /* 1 */
+ 0x570b, /* 110 */
+ 0x550b /* 111 */
+
+};
+
+const uint16 huffTable_12[134] =
+{
+
+ 0x1103, /* 101 */
+ 0x0103, /* 110 */
+ 0x1003, /* 111 */
+ 0x1204,
+ 0x1204, /* 011 */
+ 0x2104, /* 0111 */
+ 0x2104, /* 011 */
+ 0x0205, /* 10000 */
+ 0x2005, /* 10 */
+ 0x0004, /* 1 */
+ 0x0004, /* 100 */
+ 0x3006,
+ 0x1305, /* 01 */
+ 0x1305, /* 0100 */
+ 0x3105,
+ 0x3105,
+ 0x2205,
+ 0x2205, /* 0101 */
+ 0x1507,
+ 0x1507, /* 000 */
+ 0x5107, /* 0 */
+ 0x5107, /* 000 */
+ 0x3407, /* 0 */
+ 0x3407, /* */
+ 0x4307, /* 1 */
+ 0x4307, /* */
+ 0x5008,
+ 0x0408,
+ 0x2407,
+ 0x2407, /* 010 */
+ 0x4207,
+ 0x4207,
+ 0x1407, /* 0111 */
+ 0x1407, /* 011 */
+ 0x3306,
+ 0x3306,
+ 0x3306,
+ 0x3306,
+ 0x4106,
+ 0x4106,
+ 0x4106,
+ 0x4106,
+ 0x2306,
+ 0x2306,
+ 0x2306,
+ 0x2306,
+ 0x3206,
+ 0x3206,
+ 0x3206,
+ 0x3206,
+ 0x4007,
+ 0x4007,
+ 0x0307,
+ 0x0307, /* 010000 */
+ 0x7208,
+ 0x7208, /* 00 00 */
+ 0x4608, /* 00 */
+ 0x4608, /* 00 00 */
+ 0x6408,
+ 0x6408, /* 00 01 */
+ 0x1708, /* 00 011 */
+ 0x1708,
+ 0x7108, /* 00 100 */
+ 0x7108,
+ 0x0709,
+ 0x7009,
+ 0x3608,
+ 0x3608, /* 00 11 */
+ 0x6308,
+ 0x6308,
+ 0x4508,
+ 0x4508,
+ 0x5408, /* 0 0 */
+ 0x5408, /* 0 000 */
+ 0x4408, /* 0 0 */
+ 0x4408, /* 0 */
+ 0x0609, /* 0 10 */
+ 0x0509, /* 0 11 */
+ 0x2607,
+ 0x2607,
+ 0x2607,
+ 0x2607,
+ 0x6207,
+ 0x6207,
+ 0x6207,
+ 0x6207,
+ 0x6107,
+ 0x6107,
+ 0x6107,
+ 0x6107,
+ 0x1608, /* 0 1010 */
+ 0x1608, /* 0 101 */
+ 0x6008, /* 0 1011 */
+ 0x6008, /* 0 101 */
+ 0x3508,
+ 0x3508, /* 0 110 */
+ 0x5308, /* 0 1101 */
+ 0x5308, /* 0 110 */
+ 0x2508,
+ 0x2508, /* 0 111 */
+ 0x5208, /* 0 1111 */
+ 0x5208, /* 0 111 */
+ 0x770a,
+ 0x670a,
+ 0x7609, /* */
+ 0x7609,
+ 0x5709, /* 0 */
+ 0x5709, /* */
+ 0x7509, /* 1 */
+ 0x7509, /* */
+ 0x6609,
+ 0x6609,
+ 0x4709, /* 0000 01 */
+ 0x4709, /* 0000 0 */
+ 0x7409,
+ 0x7409, /* 0000 1 */
+ 0x6509,
+ 0x6509, /* 0000 1 */
+ 0x5608,
+ 0x5608,
+ 0x5608,
+ 0x5608,
+ 0x3708,
+ 0x3708,
+ 0x3708,
+ 0x3708,
+ 0x7309, /* 000 100 */
+ 0x7309, /* 000 10 */
+ 0x5509,
+ 0x5509, /* 000 10 */
+ 0x2708,
+ 0x2708,
+ 0x2708,
+ 0x2708,
+};
+
+
+
+const uint16 huffTable_13[491] =
+{
+ 0x0001,
+ 0x1104,
+ 0x0104,
+ 0x1003,
+ 0x1003,
+ 0x4107,
+ 0x4107,
+ 0x0408,
+ 0x4008,
+ 0x2308,
+ 0x3208,
+ 0x1307,
+ 0x1307,
+ 0x3107,
+ 0x3107,
+ 0x0307,
+ 0x0307,
+ 0x3007,
+ 0x3007,
+ 0x2207,
+ 0x2207,
+ 0x1206,
+ 0x1206,
+ 0x1206,
+ 0x1206,
+ 0x2106,
+ 0x2106,
+ 0x2106,
+ 0x2106,
+ 0x0206,
+ 0x0206,
+ 0x0206,
+ 0x0206,
+ 0x2006,
+ 0x2006,
+ 0x2006,
+ 0x2006,
+ 0x370a,
+ 0x270a, /* 0 000 */
+ 0x1709, /* 0 00 */
+ 0x1709,
+ 0x7109,
+ 0x7109, /* 0 0 */
+ 0x550a,
+ 0x070a, /* 0 0 11 */
+ 0x700a,
+ 0x360a, /* 0 */
+ 0x630a,
+ 0x450a, /* 0 011 */
+ 0x540a,
+ 0x260a, /* 0 101 */
+ 0x620a,
+ 0x350a, /* 0 111 */
+ 0x8108,
+ 0x8108, /* 0 010 */
+ 0x8108,
+ 0x8108, /* 0 010 */
+ 0x0809,
+ 0x0809, /* 0 0101 */
+ 0x8009,
+ 0x8009, /* 0 0101 */
+ 0x1609,
+ 0x1609, /* 0 0110 */
+ 0x6109,
+ 0x6109, /* 0 0110 */
+ 0x0609,
+ 0x0609, /* 0 0111 */
+ 0x6009,
+ 0x6009, /* 0 0111 */
+ 0x530a,
+ 0x440a, /* 0 100 */
+ 0x2509,
+ 0x2509, /* 0 1000 */
+ 0x5209,
+ 0x5209, /* 0 1 */
+ 0x0509,
+ 0x0509, /* 0 1 */
+ 0x1508,
+ 0x1508, /* 0 101 */
+ 0x1508,
+ 0x1508, /* 0 101 */
+ 0x5108,
+ 0x5108, /* 0 101 */
+ 0x5108,
+ 0x5108, /* 0 101 */
+ 0x3409,
+ 0x3409, /* 0 1100 */
+ 0x4309,
+ 0x4309, /* 0 1100 */
+ 0x5009,
+ 0x5009, /* 0 1101 */
+ 0x2409,
+ 0x2409, /* 0 1101 */
+ 0x4209,
+ 0x4209, /* 0 1110 */
+ 0x3309,
+ 0x3309, /* 0 1110 */
+ 0x1408,
+ 0x1408, /* 0 111 */
+ 0x1408,
+ 0x1408, /* 0 111 */
+ 0x1a0a,
+ 0x1a0a,
+ 0xa10a, /* 00 00 */
+ 0xa10a,
+ 0x0a0b,
+ 0x680b,
+ 0xa00a,
+ 0xa00a,
+ 0x860b,
+ 0x490b,
+ 0x930a,
+ 0x930a,
+ 0x390b,
+ 0x580b,
+ 0x850b,
+ 0x670b,
+ 0x290a,
+ 0x290a,
+ 0x920a,
+ 0x920a,
+ 0x570b,
+ 0x750b,
+ 0x380a,
+ 0x380a,
+ 0x830a,
+ 0x830a,
+ 0x660b,
+ 0x470b,
+ 0x740b,
+ 0x560b,
+ 0x650b,
+ 0x730b,
+ 0x1909,
+ 0x1909,
+ 0x1909,
+ 0x1909,
+ 0x9109,
+ 0x9109,
+ 0x9109,
+ 0x9109,
+ 0x090a, /* 00 10100 */
+ 0x090a,
+ 0x900a, /* 00 10101 */
+ 0x900a,
+ 0x480a, /* 00 10110 */
+ 0x480a,
+ 0x840a, /* 00 10111 */
+ 0x840a,
+ 0x720a, /* 00 11000 */
+ 0x720a,
+ 0x460b, /* 00 11 0 */
+ 0x640b,
+ 0x2809,
+ 0x2809,
+ 0x2809,
+ 0x2809,
+ 0x8209,
+ 0x8209,
+ 0x8209,
+ 0x8209,
+ 0x1809,
+ 0x1809,
+ 0x1809,
+ 0x1809,
+ 0xc10b,
+ 0xc10b, /* 000 0000 */
+ 0x980c,
+ 0x0c0c, /* 000 00 1 */
+ 0xc00b,
+ 0xc00b, /* 000 0 */
+ 0xb40c,
+ 0x6a0c, /* 000 0 11 */
+ 0xa60c,
+ 0x790c, /* 000 */
+ 0x3b0b,
+ 0x3b0b, /* 000 0 */
+ 0xb30b,
+ 0xb30b, /* 000 1 */
+ 0x880c,
+ 0x5a0c, /* 000 111 */
+ 0x2b0b,
+ 0x2b0b, /* 000 0100 */
+ 0xa50c,
+ 0x690c, /* 000 01 1 */
+ 0xa40b,
+ 0xa40b, /* 000 0101 */
+ 0x780c,
+ 0x870c,
+ 0x940b,
+ 0x940b, /* 000 0110 */
+ 0x770c,
+ 0x760c, /* 000 011011 */
+ 0xb20a,
+ 0xb20a, /* 000 011 */
+ 0xb20a,
+ 0xb20a, /* 000 011 */
+ 0x1b0a,
+ 0x1b0a, /* 000 100 */
+ 0x1b0a,
+ 0x1b0a, /* 000 100 */
+ 0xb10a,
+ 0xb10a,
+ 0xb10a, /* 000 100 */
+ 0xb10a, /* 000 100 */
+ 0x0b0b, /* 000 10100 */
+ 0x0b0b, /* 000 1010 */
+ 0xb00b,
+ 0xb00b, /* 000 1010 */
+ 0x960b, /* 000 10110 */
+ 0x960b, /* 000 1011 */
+ 0x4a0b,
+ 0x4a0b, /* 000 1011 */
+ 0x3a0b, /* 000 11000 */
+ 0x3a0b, /* 000 1100 */
+ 0xa30b, /* 000 11 */
+ 0xa30b, /* 000 1100 */
+ 0x590b,
+ 0x590b, /* 000 1101 */
+ 0x950b, /* 000 11011 */
+ 0x950b, /* 000 1101 */
+ 0x2a0a,
+ 0x2a0a,
+ 0x2a0a,
+ 0x2a0a,
+ 0xa20a,
+ 0xa20a,
+ 0xa20a,
+ 0xa20a,
+ 0xf00c,
+ 0xf00c, /* 000 */
+ 0xba0d,
+ 0xe50d, /* 0 1 */
+ 0xe40d,
+ 0x8c0d, /* 01 */
+ 0x6d0d,
+ 0xe30d, /* 11 */
+ 0xe20c, /* 0100 */
+ 0xe20c,
+ 0x2e0d, /* 01010 */
+ 0x0e0d,
+ 0x1e0c, /* 0110 */
+ 0x1e0c,
+ 0xe10c, /* 0111 */
+ 0xe10c,
+ 0xe00d, /* 10000 */
+ 0x5d0d,
+ 0xd50d, /* 1 0 */
+ 0x7c0d,
+ 0xc70d,
+ 0x4d0d,
+ 0x8b0d,
+ 0xb80d,
+ 0xd40d,
+ 0x9a0d,
+ 0xa90d,
+ 0x6c0d,
+ 0xc60c,
+ 0xc60c,
+ 0x3d0c,
+ 0x3d0c, /* 111 */
+ 0xd30d, /* 0000 */
+ 0x7b0d,
+ 0x2d0c,
+ 0x2d0c,
+ 0xd20c,
+ 0xd20c,
+ 0x1d0c,
+ 0x1d0c,
+ 0xb70c,
+ 0xb70c, /* 0000 0 */
+ 0x5c0d,
+ 0xc50d, /* 0000 011 */
+ 0x990d,
+ 0x7a0d,
+ 0xc30c,
+ 0xc30c, /* 0000 1 */
+ 0xa70d,
+ 0x970d,
+ 0x4b0c,
+ 0x4b0c,
+ 0xd10b,
+ 0xd10b,
+ 0xd10b, /* 0000 010 */
+ 0xd10b,
+ 0x0d0c,
+ 0x0d0c,
+ 0xd00c,
+ 0xd00c,
+ 0x8a0c,
+ 0x8a0c,
+ 0xa80c,
+ 0xa80c,
+ 0x4c0c,
+ 0x4c0c,
+ 0xc40c,
+ 0xc40c,
+ 0x6b0c,
+ 0x6b0c, /* 0000 1 */
+ 0xb60c, /* 0000 1 1 */
+ 0xb60c, /* 0000 1 */
+ 0x3c0b,
+ 0x3c0b,
+ 0x3c0b,
+ 0x3c0b,
+ 0x2c0b, /* 0000 1011 */
+ 0x2c0b, /* 0000 101 */
+ 0x2c0b, /* 0000 101 */
+ 0x2c0b, /* 0000 101 */
+ 0xc20b,
+ 0xc20b,
+ 0xc20b,
+ 0xc20b,
+ 0x5b0b, /* 0000 1101 */
+ 0x5b0b,
+ 0x5b0b, /* 0000 110 */
+ 0x5b0b, /* 0000 110 */
+ 0xb50c,
+ 0xb50c,
+ 0x890c,
+ 0x890c, /* 0000 1110 */
+ 0x1c0b,
+ 0x1c0b,
+ 0x1c0b,
+ 0x1c0b,
+ 0x2f0d,
+ 0x2f0d, /* 000 */
+ 0xf20d, /* 0 */
+ 0xf20d, /* 000 */
+ 0x6e0e, /* 00 */
+ 0x9c0e, /* 01 */
+ 0x0f0d, /* 1 */
+ 0x0f0d, /* */
+ 0xc90e,
+ 0x5e0e, /* 01 */
+ 0xab0d, /* 0101 */
+ 0xab0d,
+ 0x7d0e, /* 01100 */
+ 0xd70e,
+ 0x4e0d, /* 0111 */
+ 0x4e0d,
+ 0xc80e,
+ 0xd60e, /* 10 */
+ 0x3e0d,
+ 0x3e0d, /* 100 */
+ 0xb90d,
+ 0xb90d, /* 101 */
+ 0x9b0e,
+ 0xaa0e, /* 10111 */
+ 0x1f0c,
+ 0x1f0c, /* 11 */
+ 0x1f0c, /* 11 */
+ 0x1f0c,
+ 0xf10c, /* 111 */
+ 0xf10c, /* 11 */
+ 0xf10c, /* 11 */
+ 0xf10c, /* 11 */
+ 0xe80e,
+ 0xe80e,
+ 0x5f0e,
+ 0x5f0e,
+ 0x9d0e,
+ 0x9d0e,
+ 0xd90e,
+ 0xd90e, /* 0000000 */
+ 0xf50e,
+ 0xf50e,
+ 0xe70e,
+ 0xe70e,
+ 0xac0e,
+ 0xac0e,
+ 0xbb0e,
+ 0xbb0e,
+ 0x4f0e,
+ 0x4f0e,
+ 0xf40e, /* 0000000 1 */
+ 0xf40e,
+ 0xca0f,
+ 0xe60f,
+ 0xf30e,
+ 0xf30e, /* 0000000 101 */
+ 0x3f0d,
+ 0x3f0d, /* 0000000 11 */
+ 0x3f0d,
+ 0x3f0d, /* 0000000 11 */
+ 0x8d0e,
+ 0x8d0e,
+ 0xd80e, /* 0000000 1111 */
+ 0xd80e,
+ 0x8f0f,
+ 0x8f0f, /* 00000000 000 */
+ 0xf80f, /* 00000000 0 */
+ 0xf80f,
+ 0xcc0f, /* 00000000 0 */
+ 0xcc0f,
+ 0xae10,
+ 0x9e10, /* 00000000 11 */
+ 0x8e0f,
+ 0x8e0f,
+ 0x7f10,
+ 0x7e10,
+ 0xf70e, /* 00000000 011 */
+ 0xf70e,
+ 0xf70e,
+ 0xf70e, /* 00000000 01 */
+ 0xda0e,
+ 0xda0e, /* 00000000 10 */
+ 0xda0e,
+ 0xda0e, /* 00000000 10 */
+ 0xad0f,
+ 0xad0f, /* 00000000 101 */
+ 0xbc0f,
+ 0xbc0f, /* 00000000 101 */
+ 0xcb0f,
+ 0xcb0f, /* 00000000 110 */
+ 0xf60f,
+ 0xf60f, /* 00000000 110 */
+ 0x6f0e,
+ 0x6f0e, /* 00000000 11 */
+ 0x6f0e, /* 00000000 11 */
+ 0x6f0e, /* 00000000 11 */
+ 0xff10,
+ 0xff10,
+ 0xef10,
+ 0xef10, /* 000000000000 */
+ 0xdf10, /* 000000000000 1 */
+ 0xdf10, /* 000000000000 */
+ 0xee10, /* 00000000000 00 */
+ 0xee10, /* 00000000000 0 */
+ 0xcf10, /* 00000000000 01 */
+ 0xcf10,
+ 0xde10, /* 00000000000 10 */
+ 0xde10,
+ 0xbf10, /* 00000000000 11 */
+ 0xbf10, /* 00000000000 1 */
+ 0xfb10,
+ 0xfb10,
+ 0xce10,
+ 0xce10, /* 0000000000 00 */
+ 0xdc10, /* 0000000000 010 */
+ 0xdc10,
+ 0xaf11,
+ 0xe911,
+ 0xec0f, /* 0000000000 10 */
+ 0xec0f, /* 0000000000 1 */
+ 0xec0f, /* 0000000000 1 */
+ 0xec0f, /* 0000000000 1 */
+ 0xdd0f, /* 0000000000 11 */
+ 0xdd0f, /* 0000000000 1 */
+ 0xdd0f, /* 0000000000 1 */
+ 0xdd0f, /* 0000000000 1 */
+ 0xfa10, /* 000000000 0000 */
+ 0xfa10, /* 000000000 000 */
+ 0xcd10, /* 000000000 0 */
+ 0xcd10, /* 000000000 000 */
+ 0xbe0f, /* 000000000 */
+ 0xbe0f,
+ 0xbe0f,
+ 0xbe0f,
+ 0xeb0f,
+ 0xeb0f,
+ 0xeb0f,
+ 0xeb0f, /* 000000000 01 */
+ 0x9f0f, /* 000000000 011 */
+ 0x9f0f, /* 000000000 01 */
+ 0x9f0f,
+ 0x9f0f,
+ 0xf90f, /* 000000000 100 */
+ 0xf90f, /* 000000000 10 */
+ 0xf90f, /* 000000000 10 */
+ 0xf90f, /* 000000000 10 */
+ 0xea0f, /* 000000000 101 */
+ 0xea0f, /* 000000000 10 */
+ 0xea0f, /* 000000000 10 */
+ 0xea0f, /* 000000000 10 */
+ 0xbd0f, /* 000000000 110 */
+ 0xbd0f, /* 000000000 11 */
+ 0xbd0f, /* 000000000 11 */
+ 0xbd0f, /* 000000000 11 */
+ 0xdb0f, /* 000000000 111 */
+ 0xdb0f, /* 000000000 11 */
+ 0xdb0f, /* 000000000 11 */
+ 0xdb0f, /* 000000000 11 */
+ 0xfe13,
+ 0xfc13,
+ 0xfd12,
+ 0xfd12,
+ 0xed11,
+ 0xed11,
+ 0xed11,
+ 0xed11
+
+};
+
+
+
+const uint16 huffTable_15[421] =
+{
+ 0x1103,
+ 0x1103,
+ 0x0104,
+ 0x1004,
+ 0x0003, /* 111 */
+ 0x0003, /* 11 */
+ 0x3407,
+ 0x4307,
+ 0x2407, /* 0101 */
+ 0x4207, /* 0101010 */
+ 0x3307,
+ 0x4106, /* 010110 */
+ 0x4106,
+ 0x1407, /* 0101110 */
+ 0x0407,
+ 0x2306, /* 011000 */
+ 0x2306,
+ 0x3206, /* 011 */
+ 0x3206,
+ 0x4007,
+ 0x0307,
+ 0x1306, /* 011011 */
+ 0x1306, /* 01101 */
+ 0x3106, /* 011100 */
+ 0x3106, /* 01110 */
+ 0x3006, /* 011101 */
+ 0x3006, /* 01110 */
+ 0x2205, /* 01111 */
+ 0x2205, /* 0111 */
+ 0x2205, /* 0111 */
+ 0x2205, /* 0111 */
+ 0x1205, /* 10000 */
+ 0x1205, /* 1000 */
+ 0x1205, /* 1000 */
+ 0x1205, /* 1000 */
+ 0x2105, /* 10 */
+ 0x2105, /* 1000 */
+ 0x2105, /* 1000 */
+ 0x2105, /* 1000 */
+ 0x0205,
+ 0x0205, /* 1 */
+ 0x0205, /* 1 */
+ 0x0205, /* 1 */
+ 0x2005, /* 1 1 */
+ 0x2005, /* 1 */
+ 0x2005, /* 1 */
+ 0x2005, /* 1 */
+ 0x5809,
+ 0x8509,
+ 0x2909, /* */
+ 0x6709, /* 000 */
+ 0x7609, /* 00 0 */
+ 0x9209, /* 00 1 */
+ 0x9108, /* 0 0 */
+ 0x9108, /* 0 */
+ 0x1909, /* 0 10 */
+ 0x9009, /* 0 11 */
+ 0x4809, /* 000 */
+ 0x8409, /* */
+ 0x5709, /* 010 */
+ 0x7509, /* 011 */
+ 0x3809, /* 100 */
+ 0x8309, /* 101 */
+ 0x6609, /* 110 */
+ 0x4709, /* 111 */
+ 0x2808,
+ 0x2808, /* 0100 */
+ 0x8208, /* 01 */
+ 0x8208, /* 0100 */
+ 0x1808, /* 01010 */
+ 0x1808, /* 0101 */
+ 0x8108, /* 01011 */
+ 0x8108, /* 0101 */
+ 0x7409,
+ 0x0809, /* 011 */
+ 0x8009, /* 011010 */
+ 0x5609,
+ 0x6509, /* 011100 */
+ 0x3709,
+ 0x7309, /* 011110 */
+ 0x4609,
+ 0x2708, /* 10000 */
+ 0x2708, /* 1000 */
+ 0x7208, /* 10 */
+ 0x7208, /* 1000 */
+ 0x6408, /* 1 0 */
+ 0x6408, /* 1 */
+ 0x1708, /* 1 1 */
+ 0x1708, /* 1 */
+ 0x5508, /* 10100 */
+ 0x5508,
+ 0x7108, /* 10101 */
+ 0x7108,
+ 0x0709, /* 101100 */
+ 0x7009, /* 101101 */
+ 0x3608, /* 10111 */
+ 0x3608, /* 1011 */
+ 0x6308, /* 11000 */
+ 0x6308, /* 1100 */
+ 0x4508, /* 11 */
+ 0x4508, /* 1100 */
+ 0x5408, /* 11010 */
+ 0x5408, /* 1101 */
+ 0x2608, /* 11011 */
+ 0x2608, /* 1101 */
+ 0x6208, /* 11100 */
+ 0x6208, /* 1110 */
+ 0x1608, /* 11101 */
+ 0x1608, /* 1110 */
+ 0x0609, /* 111100 */
+ 0x6009, /* 111101 */
+ 0x3508, /* 11111 */
+ 0x3508, /* 1111 */
+ 0x6107,
+ 0x6107,
+ 0x6107,
+ 0x6107,
+ 0x5308, /* 0100 0 */
+ 0x5308, /* 0100 */
+ 0x4408, /* 0100 1 */
+ 0x4408, /* 0100 */
+ 0x2507, /* 010 0 */
+ 0x2507, /* 010 */
+ 0x2507, /* 010 */
+ 0x2507, /* 010 */
+ 0x5207, /* 010 1 */
+ 0x5207, /* 010 */
+ 0x5207, /* 010 */
+ 0x5207, /* 010 */
+ 0x1507, /* 01 00 */
+ 0x1507, /* 01 0 */
+ 0x1507, /* 01 0 */
+ 0x1507, /* 01 0 */
+ 0x5107, /* 01 01 */
+ 0x5107, /* 01 0 */
+ 0x5107, /* 01 0 */
+ 0x5107, /* 01 0 */
+ 0x0508, /* 01 100 */
+ 0x0508, /* 01 10 */
+ 0x5008, /* 01 101 */
+ 0x5008, /* 01 10 */
+ 0xc209,
+ 0xc209,
+ 0x2c0a, /* 00 11110 */
+ 0x5b0a,
+ 0xb50a, /* 0 */
+ 0x1c0a, /* 0 000 */
+ 0x890a, /* 0 00 0 */
+ 0x980a,
+ 0xc10a, /* 0 0 00 */
+ 0x4b0a, /* 0 0 01 */
+ 0xb40a, /* 0 0 10 */
+ 0x6a0a, /* 0 0 11 */
+ 0x3b0a, /* 0 000 */
+ 0x790a, /* 0 */
+ 0xb309, /* 0 01 */
+ 0xb309, /* 0 0 */
+ 0x970a, /* 0 100 */
+ 0x880a, /* 0 101 */
+ 0x2b0a, /* 0 110 */
+ 0x5a0a, /* 0 111 */
+ 0xb209, /* 0 01000 */
+ 0xb209, /* 0 0100 */
+ 0xa50a, /* 0 01 0 */
+ 0x1b0a, /* 0 01 1 */
+ 0xb109, /* 0 01010 */
+ 0xb109, /* 0 0101 */
+ 0xb00a, /* 0 010110 */
+ 0x690a, /* 0 010111 */
+ 0x960a, /* 0 011000 */
+ 0x4a0a, /* 0 011 */
+ 0xa40a, /* 0 011010 */
+ 0x780a, /* 0 011011 */
+ 0x870a, /* 0 011100 */
+ 0x3a0a, /* 0 011101 */
+ 0xa309, /* 0 01111 */
+ 0xa309, /* 0 0111 */
+ 0x5909, /* 0 10000 */
+ 0x5909, /* 0 1000 */
+ 0x9509, /* 0 10 */
+ 0x9509, /* 0 1000 */
+ 0x2a09, /* 0 1 0 */
+ 0x2a09, /* 0 1 */
+ 0xa209, /* 0 1 1 */
+ 0xa209, /* 0 1 */
+ 0x1a09, /* 0 10100 */
+ 0x1a09, /* 0 1010 */
+ 0xa109, /* 0 10101 */
+ 0xa109, /* 0 1010 */
+ 0x0a0a, /* 0 101100 */
+ 0xa00a, /* 0 101101 */
+ 0x6809, /* 0 10111 */
+ 0x6809, /* 0 1011 */
+ 0x8609, /* 0 11000 */
+ 0x8609, /* 0 1100 */
+ 0x4909, /* 0 11 */
+ 0x4909, /* 0 1100 */
+ 0x9409, /* 0 11010 */
+ 0x9409, /* 0 1101 */
+ 0x3909, /* 0 11011 */
+ 0x3909, /* 0 1101 */
+ 0x9309, /* 0 11100 */
+ 0x9309, /* 0 1110 */
+ 0x770a, /* 0 111010 */
+ 0x090a, /* 0 111011 */
+ 0x7c0b,
+ 0xc70b, /* 00 000 */
+ 0x4d0b, /* 00 00 0 */
+ 0x8b0b, /* 00 00 1 */
+ 0xd40a, /* 00 0 0 */
+ 0xd40a, /* 00 0 */
+ 0xb80b, /* 00 0 10 */
+ 0x9a0b, /* 00 0 11 */
+ 0xa90b, /* 00 000 */
+ 0x6c0b, /* 00 */
+ 0xc60b, /* 00 010 */
+ 0x3d0b, /* 00 011 */
+ 0xd30a, /* 00 10 */
+ 0xd30a, /* 00 1 */
+ 0xd20a, /* 00 11 */
+ 0xd20a, /* 00 1 */
+ 0x2d0b, /* 00 010000 */
+ 0x0d0b, /* 00 010 */
+ 0x1d0a, /* 00 01 */
+ 0x1d0a, /* 00 0100 */
+ 0x7b0a, /* 00 01010 */
+ 0x7b0a, /* 00 0101 */
+ 0xb70a, /* 00 01011 */
+ 0xb70a, /* 00 0101 */
+ 0xd10a, /* 00 01100 */
+ 0xd10a, /* 00 0110 */
+ 0x5c0b, /* 00 011010 */
+ 0xd00b, /* 00 011011 */
+ 0xc50a, /* 00 01110 */
+ 0xc50a, /* 00 0111 */
+ 0x8a0a, /* 00 01111 */
+ 0x8a0a, /* 00 0111 */
+ 0xa80a, /* 00 10000 */
+ 0xa80a, /* 00 1000 */
+ 0x4c0a, /* 00 10 */
+ 0x4c0a, /* 00 1000 */
+ 0xc40a, /* 00 1 0 */
+ 0xc40a, /* 00 1 */
+ 0x6b0a, /* 00 1 1 */
+ 0x6b0a, /* 00 1 */
+ 0xb60a, /* 00 10100 */
+ 0xb60a, /* 00 1010 */
+ 0x990b, /* 00 101010 */
+ 0x0c0b, /* 00 101011 */
+ 0x3c0a, /* 00 10110 */
+ 0x3c0a, /* 00 1011 */
+ 0xc30a, /* 00 10111 */
+ 0xc30a, /* 00 1011 */
+ 0x7a0a, /* 00 11000 */
+ 0x7a0a, /* 00 1100 */
+ 0xa70a, /* 00 11 */
+ 0xa70a, /* 00 1100 */
+ 0xa60a, /* 00 11010 */
+ 0xa60a, /* 00 1101 */
+ 0xc00b, /* 00 110110 */
+ 0x0b0b, /* 00 110111 */
+ 0xcb0b,
+ 0xcb0b, /* 0000 000 */
+ 0xf60b, /* 0000 0 */
+ 0xf60b, /* 0000 000 */
+ 0x8e0c, /* 0000 00 */
+ 0xe80c, /* 0000 01 */
+ 0x5f0c, /* 0000 10 */
+ 0x9d0c, /* 0000 11 */
+ 0xf50b, /* 0000 0100 */
+ 0xf50b, /* 0000 010 */
+ 0x7e0b, /* 0000 0101 */
+ 0x7e0b, /* 0000 010 */
+ 0xe70b, /* 0000 0110 */
+ 0xe70b, /* 0000 011 */
+ 0xac0b, /* 0000 0111 */
+ 0xac0b, /* 0000 011 */
+ 0xca0b, /* 0000 1000 */
+ 0xca0b, /* 0000 100 */
+ 0xbb0b, /* 0000 1 */
+ 0xbb0b, /* 0000 100 */
+ 0xd90c, /* 0000 10100 */
+ 0x8d0c, /* 0000 10101 */
+ 0x4f0b, /* 0000 1011 */
+ 0x4f0b, /* 0000 101 */
+ 0xf40b, /* 0000 1100 */
+ 0xf40b, /* 0000 110 */
+ 0x3f0b, /* 0000 1101 */
+ 0x3f0b, /* 0000 110 */
+ 0xf30b, /* 0000 1110 */
+ 0xf30b, /* 0000 111 */
+ 0xd80b, /* 0000 1111 */
+ 0xd80b, /* 0000 111 */
+ 0xe60b, /* 000 */
+ 0xe60b, /* 000 0000 */
+ 0x2f0b, /* 000 00 */
+ 0x2f0b, /* 000 0000 */
+ 0xf20b, /* 000 0 0 */
+ 0xf20b, /* 000 0 */
+ 0x6e0c, /* 000 0 10 */
+ 0xf00c, /* 000 0 11 */
+ 0x1f0b, /* 000 00 */
+ 0x1f0b, /* 000 0 */
+ 0xf10b, /* 000 01 */
+ 0xf10b, /* 000 0 */
+ 0x9c0b, /* 000 10 */
+ 0x9c0b, /* 000 1 */
+ 0xc90b, /* 000 11 */
+ 0xc90b, /* 000 1 */
+ 0x5e0b, /* 000 01000 */
+ 0x5e0b, /* 000 0100 */
+ 0xab0b, /* 000 01 */
+ 0xab0b, /* 000 0100 */
+ 0xba0b, /* 000 01010 */
+ 0xba0b, /* 000 0101 */
+ 0xe50b, /* 000 01011 */
+ 0xe50b, /* 000 0101 */
+ 0x7d0b, /* 000 01100 */
+ 0x7d0b, /* 000 0110 */
+ 0xd70b, /* 000 01101 */
+ 0xd70b,
+ 0x4e0b, /* 000 01110 */
+ 0x4e0b,
+ 0xe40b, /* 000 01111 */
+ 0xe40b, /* 000 0111 */
+ 0x8c0b,
+ 0x8c0b, /* 000 1000 */
+ 0xc80b, /* 000 10 */
+ 0xc80b,
+ 0x3e0b, /* 000 1 0 */
+ 0x3e0b, /* 000 1 */
+ 0x6d0b,
+ 0x6d0b, /* 000 1 */
+ 0xd60b, /* 000 10100 */
+ 0xd60b, /* 000 1010 */
+ 0xe30b,
+ 0xe30b, /* 000 1010 */
+ 0x9b0b, /* 000 10110 */
+ 0x9b0b, /* 000 1011 */
+ 0xb90b,
+ 0xb90b, /* 000 1011 */
+ 0x2e0b, /* 000 11000 */
+ 0x2e0b, /* 000 1100 */
+ 0xaa0b,
+ 0xaa0b, /* 000 1100 */
+ 0xe20b,
+ 0xe20b, /* 000 1101 */
+ 0x1e0b,
+ 0x1e0b, /* 000 1101 */
+ 0xe10b,
+ 0xe10b, /* 000 1110 */
+ 0x0e0c,
+ 0xe00c, /* 000 111011 */
+ 0x5d0b,
+ 0x5d0b, /* 000 1111 */
+ 0xd50b,
+ 0xd50b, /* 000 1111 */
+ 0xff0d,
+ 0xef0d,
+ 0xfe0d,
+ 0xdf0d,
+ 0xee0c,
+ 0xee0c,
+ 0xfd0d,
+ 0xcf0d,
+ 0xfc0d,
+ 0xde0d,
+ 0xed0d,
+ 0xbf0d,
+ 0xfb0c,
+ 0xfb0c,
+ 0xce0d,
+ 0xec0d,
+ 0xdd0c, /* 000 */
+ 0xdd0c, /* 00 */
+ 0xaf0c, /* */
+ 0xaf0c, /* 00 */
+ 0xfa0c, /* 010 */
+ 0xfa0c, /* 01 */
+ 0xbe0c, /* 011 */
+ 0xbe0c, /* 01 */
+ 0xeb0c, /* 100 */
+ 0xeb0c, /* 10 */
+ 0xcd0c, /* 101 */
+ 0xcd0c, /* 10 */
+ 0xdc0c, /* 110 */
+ 0xdc0c, /* 11 */
+ 0x9f0c, /* 111 */
+ 0x9f0c, /* 11 */
+ 0xf90c, /* 0000 */
+ 0xf90c, /* 000 */
+ 0xea0c, /* 0 */
+ 0xea0c, /* 000 */
+ 0xbd0c, /* 0 */
+ 0xbd0c, /* */
+ 0xdb0c, /* 1 */
+ 0xdb0c, /* */
+ 0x8f0c, /* 0100 */
+ 0x8f0c, /* 010 */
+ 0xf80c, /* 0101 */
+ 0xf80c, /* 010 */
+ 0xcc0c,
+ 0xcc0c, /* 011 */
+ 0x9e0c, /* 0111 */
+ 0x9e0c, /* 011 */
+ 0xe90c, /* 1000 */
+ 0xe90c, /* 100 */
+ 0x7f0c, /* 1 */
+ 0x7f0c,
+ 0xf70c, /* 1010 */
+ 0xf70c, /* 101 */
+ 0xad0c, /* 1011 */
+ 0xad0c, /* 101 */
+ 0xda0c, /* 1100 */
+ 0xda0c, /* 110 */
+ 0xbc0c,
+ 0xbc0c, /* 110 */
+ 0x6f0c, /* 1110 */
+ 0x6f0c, /* 111 */
+ 0xae0d, /* 11110 */
+ 0x0f0d
+};
+
+const uint16 huffTable_16[465] =
+{
+ 0x0001,
+ 0x1104,
+ 0x0104,
+ 0x1003,
+ 0x1003,
+ 0x2308,
+ 0x3208, /* 11 */
+ 0x1307, /* 0100 */
+ 0x1307, /* 010 */
+ 0x3107,
+ 0x3107,
+ 0x0308,
+ 0x3008,
+ 0x2207, /* 0111 */
+ 0x2207, /* 011 */
+ 0x1206, /* 100 */
+ 0x1206, /* 10 */
+ 0x1206, /* 10 */
+ 0x1206, /* 10 */
+ 0x2106, /* 101 */
+ 0x2106, /* 10 */
+ 0x2106, /* 10 */
+ 0x2106, /* 10 */
+ 0x0206,
+ 0x0206,
+ 0x0206,
+ 0x0206,
+ 0x2006,
+ 0x2006,
+ 0x2006,
+ 0x2006,
+ 0x1709,
+ 0x1709, /* 0 0111 */
+ 0x7109, /* 0 10000 */
+ 0x7109, /* 0 1000 */
+ 0x700a, /* 0 10 0 */
+ 0x360a, /* 0 10 1 */
+ 0x630a, /* 0 1 00 */
+ 0x450a, /* 0 1 01 */
+ 0x540a, /* 0 1 10 */
+ 0x260a, /* 0 1 11 */
+ 0x6209, /* 0 10100 */
+ 0x6209, /* 0 1010 */
+ 0x1609,
+ 0x1609,
+ 0x6109, /* 0 10110 */
+ 0x6109, /* 0 1011 */
+ 0x060a, /* 0 101110 */
+ 0x600a,
+ 0x5309,
+ 0x5309, /* 0 1100 */
+ 0x350a, /* 0 11 0 */
+ 0x440a, /* 0 11 1 */
+ 0x2509, /* 0 11010 */
+ 0x2509, /* 0 1101 */
+ 0x5209, /* 0 11011 */
+ 0x5209, /* 0 1101 */
+ 0x5108,
+ 0x5108,
+ 0x5108,
+ 0x5108,
+ 0x1509,
+ 0x1509, /* 0 1111 */
+ 0x0509, /* 0 11111 */
+ 0x0509, /* 0 1111 */
+ 0x3409, /* */
+ 0x3409, /* */
+ 0x4309, /* 000 */
+ 0x4309, /* */
+ 0x5009, /* 00 0 */
+ 0x5009, /* 00 */
+ 0x2409, /* 00 1 */
+ 0x2409, /* 00 */
+ 0x4209, /* 0 00 */
+ 0x4209, /* 0 0 */
+ 0x3309, /* 0 01 */
+ 0x3309, /* 0 0 */
+ 0x1408, /* 0 1 */
+ 0x1408, /* 0 */
+ 0x1408, /* 0 */
+ 0x1408, /* 0 */
+ 0x4108, /* 00 */
+ 0x4108, /* 0 */
+ 0x4108, /* 0 */
+ 0x4108, /* 0 */
+ 0x0409, /* 010 */
+ 0x0409, /* 01 */
+ 0x4009, /* 011 */
+ 0x4009, /* 01 */
+ 0x1d0b,
+ 0x1d0b, /* 00 10101 */
+ 0xc40c, /* 00 1011000 */
+ 0x6b0c, /* 00 1011 */
+ 0xc30c, /* 00 1011010 */
+ 0xa70c, /* 00 1011011 */
+ 0x2c0b, /* 00 101110 */
+ 0x2c0b, /* 00 10111 */
+ 0xc20c, /* 00 1011110 */
+ 0xb50c, /* 00 1011111 */
+ 0xc10c, /* 00 1100000 */
+ 0x0c0c, /* 00 1100 */
+ 0x4b0c, /* 00 110 0 */
+ 0xb40c, /* 00 110 1 */
+ 0x6a0c, /* 00 11 00 */
+ 0xa60c, /* 00 11 01 */
+ 0xb30b, /* 00 11 1 */
+ 0xb30b, /* 00 11 */
+ 0x5a0c, /* 00 1101000 */
+ 0xa50c, /* 00 1101 */
+ 0x2b0b, /* 00 110101 */
+ 0x2b0b, /* 00 11010 */
+ 0xb20b, /* 00 110110 */
+ 0xb20b, /* 00 11011 */
+ 0x1b0b, /* 00 110111 */
+ 0x1b0b, /* 00 11011 */
+ 0xb10b, /* 00 111000 */
+ 0xb10b, /* 00 11100 */
+ 0x0b0c, /* 00 111 0 */
+ 0xb00c, /* 00 111 1 */
+ 0x690c, /* 00 1110100 */
+ 0x960c, /* 00 1110101 */
+ 0x4a0c, /* 00 1110110 */
+ 0xa40c, /* 00 1110111 */
+ 0x780c, /* 00 1111000 */
+ 0x870c, /* 00 1111 */
+ 0xa30b, /* 00 111101 */
+ 0xa30b, /* 00 11110 */
+ 0x3a0c, /* 00 1111100 */
+ 0x590c, /* 00 1111101 */
+ 0x2a0b, /* 00 111111 */
+ 0x2a0b, /* 00 11111 */
+ 0x950c, /* 0 00000000 */
+ 0x680c, /* 0 */
+ 0xa10b, /* 0 0000 */
+ 0xa10b, /* 0 */
+ 0x860c, /* 0 000 00 */
+ 0x770c, /* 0 000 01 */
+ 0x940b, /* 0 000 1 */
+ 0x940b, /* 0 000 */
+ 0x490c, /* 0 00 000 */
+ 0x570c, /* 0 00 */
+ 0x670b, /* 0 00 01 */
+ 0x670b, /* 0 00 0 */
+ 0xa20a, /* 0 00 1 */
+ 0xa20a, /* 0 00 */
+ 0xa20a, /* 0 00 */
+ 0xa20a, /* 0 00 */
+ 0x1a0a, /* 0 0 00 */
+ 0x1a0a, /* 0 0 0 */
+ 0x1a0a, /* 0 0 0 */
+ 0x1a0a, /* 0 0 0 */
+ 0x0a0b, /* 0 0 010 */
+ 0x0a0b, /* 0 0 01 */
+ 0xa00b, /* 0 0 011 */
+ 0xa00b, /* 0 0 01 */
+ 0x390b, /* 0 0 100 */
+ 0x390b, /* 0 0 10 */
+ 0x930b, /* 0 0 101 */
+ 0x930b, /* 0 0 10 */
+ 0x580b, /* 0 0 110 */
+ 0x580b, /* 0 0 11 */
+ 0x850b, /* 0 0 111 */
+ 0x850b, /* 0 0 11 */
+ 0x290a, /* 0 000 */
+ 0x290a, /* 0 00 */
+ 0x290a, /* 0 00 */
+ 0x290a, /* 0 00 */
+ 0x920a, /* 0 */
+ 0x920a, /* 0 00 */
+ 0x920a, /* 0 00 */
+ 0x920a, /* 0 00 */
+ 0x760b, /* 0 0100 */
+ 0x760b, /* 0 010 */
+ 0x090b, /* 0 0101 */
+ 0x090b, /* 0 010 */
+ 0x190a, /* 0 011 */
+ 0x190a, /* 0 01 */
+ 0x190a, /* 0 01 */
+ 0x190a, /* 0 01 */
+ 0x910a, /* 0 100 */
+ 0x910a, /* 0 10 */
+ 0x910a, /* 0 10 */
+ 0x910a, /* 0 10 */
+ 0x900b, /* 0 1010 */
+ 0x900b, /* 0 101 */
+ 0x480b, /* 0 1011 */
+ 0x480b, /* 0 101 */
+ 0x840b, /* 0 1100 */
+ 0x840b, /* 0 110 */
+ 0x750b, /* 0 1101 */
+ 0x750b, /* 0 110 */
+ 0x380b, /* 0 1110 */
+ 0x380b, /* 0 111 */
+ 0x830b, /* 0 1111 */
+ 0x830b, /* 0 111 */
+ 0x660b, /* 0 0100000 */
+ 0x660b, /* 0 010000 */
+ 0x280b, /* 0 0100 */
+ 0x280b, /* 0 010000 */
+ 0x820a, /* 0 010 */
+ 0x820a, /* 0 01000 */
+ 0x820a, /* 0 01000 */
+ 0x820a, /* 0 01000 */
+ 0x470b, /* 0 01 00 */
+ 0x470b, /* 0 01 0 */
+ 0x740b, /* 0 01 01 */
+ 0x740b, /* 0 01 0 */
+ 0x180a, /* 0 01 1 */
+ 0x180a, /* 0 01 */
+ 0x180a, /* 0 01 */
+ 0x180a, /* 0 01 */
+ 0x810a, /* 0 010100 */
+ 0x810a, /* 0 01010 */
+ 0x810a, /* 0 01010 */
+ 0x810a, /* 0 01010 */
+ 0x800a, /* 0 010101 */
+ 0x800a, /* 0 01010 */
+ 0x800a, /* 0 01010 */
+ 0x800a, /* 0 01010 */
+ 0x080b, /* 0 0101100 */
+ 0x080b, /* 0 010110 */
+ 0x560b, /* 0 0101101 */
+ 0x560b, /* 0 010110 */
+ 0x370a, /* 0 010111 */
+ 0x370a, /* 0 01011 */
+ 0x370a, /* 0 01011 */
+ 0x370a, /* 0 01011 */
+ 0x730a, /* 0 011000 */
+ 0x730a, /* 0 01100 */
+ 0x730a, /* 0 01100 */
+ 0x730a, /* 0 01100 */
+ 0x650b, /* 0 011 0 */
+ 0x650b, /* 0 011 */
+ 0x460b, /* 0 011 1 */
+ 0x460b, /* 0 011 */
+ 0x270a, /* 0 011010 */
+ 0x270a, /* 0 01101 */
+ 0x270a, /* 0 01101 */
+ 0x270a, /* 0 01101 */
+ 0x720a, /* 0 011011 */
+ 0x720a, /* 0 01101 */
+ 0x720a, /* 0 01101 */
+ 0x720a, /* 0 01101 */
+ 0x640b, /* 0 0111000 */
+ 0x640b, /* 0 011100 */
+ 0x550b, /* 0 0111 */
+ 0x550b, /* 0 011100 */
+ 0x070a, /* 0 011101 */
+ 0x070a, /* 0 01110 */
+ 0x070a, /* 0 01110 */
+ 0x070a, /* 0 01110 */
+ 0x9e0d,
+ 0x9e0d, /* 00 0110000 */
+ 0xbc0e, /* 00 01100 0 */
+ 0xcb0e, /* 00 01100 1 */
+ 0x8e0e, /* 00 0110 00 */
+ 0xe80e, /* 00 0110 01 */
+ 0x9d0e, /* 00 0110 10 */
+ 0xe70e, /* 00 0110 11 */
+ 0xbb0e, /* 00 011 000 */
+ 0x8d0e, /* 00 011 */
+ 0xd80e, /* 00 011 010 */
+ 0x6e0e, /* 00 011 011 */
+ 0xe60d, /* 00 011 10 */
+ 0xe60d, /* 00 011 1 */
+ 0x9c0d, /* 00 011 11 */
+ 0x9c0d, /* 00 011 1 */
+ 0xab0e, /* 00 011010000 */
+ 0xba0e, /* 00 011010 */
+ 0xe50e, /* 00 01101 0 */
+ 0xd70e, /* 00 01101 1 */
+ 0x4e0d, /* 00 01101010 */
+ 0x4e0d, /* 00 0110101 */
+ 0xe40e, /* 00 011010110 */
+ 0x8c0e, /* 00 011010111 */
+ 0xc80d, /* 00 01101100 */
+ 0xc80d, /* 00 0110110 */
+ 0x3e0d, /* 00 01101101 */
+ 0x3e0d, /* 00 0110110 */
+ 0x6d0d, /* 00 01101110 */
+ 0x6d0d, /* 00 0110111 */
+ 0xd60e, /* 00 011011110 */
+ 0x9b0e, /* 00 011011111 */
+ 0xb90e, /* 00 011100000 */
+ 0xaa0e, /* 00 011100 */
+ 0xe10d, /* 00 01110 */
+ 0xe10d, /* 00 0111000 */
+ 0xd40d, /* 00 0111 0 */
+ 0xd40d, /* 00 0111 */
+ 0xb80e, /* 00 0111 10 */
+ 0xa90e, /* 00 0111 11 */
+ 0x7b0d, /* 00 01110100 */
+ 0x7b0d, /* 00 0111010 */
+ 0xb70e, /* 00 011101010 */
+ 0xd00e, /* 00 011101011 */
+ 0xe30c, /* 00 0111011 */
+ 0xe30c, /* 00 011101 */
+ 0xe30c, /* 00 011101 */
+ 0xe30c, /* 00 011101 */
+ 0x0e0d, /* 00 01111000 */
+ 0x0e0d, /* 00 0111100 */
+ 0xe00d, /* 00 01111 */
+ 0xe00d, /* 00 0111100 */
+ 0x5d0d, /* 00 01111010 */
+ 0x5d0d, /* 00 0111101 */
+ 0xd50d, /* 00 01111011 */
+ 0xd50d, /* 00 0111101 */
+ 0x7c0d, /* 00 01111100 */
+ 0x7c0d, /* 00 0111110 */
+ 0xc70d, /* 00 01111101 */
+ 0xc70d, /* 00 0111110 */
+ 0x4d0d, /* 00 01111110 */
+ 0x4d0d, /* 00 0111111 */
+ 0x8b0d, /* 00 01111111 */
+ 0x8b0d, /* 00 0111111 */
+ 0x9a0d,
+ 0x6c0d, /* 00 10000 */
+ 0xc60d, /* 00 1000 0 */
+ 0x3d0d, /* 00 1000 1 */
+ 0x5c0d, /* 00 100 00 */
+ 0xc50d, /* 00 100 01 */
+ 0x0d0c, /* 00 100 1 */
+ 0x0d0c, /* 00 100 */
+ 0x8a0d, /* 00 10 000 */
+ 0xa80d, /* 00 10 */
+ 0x990d, /* 00 10 010 */
+ 0x4c0d, /* 00 10 011 */
+ 0xb60d, /* 00 10 100 */
+ 0x7a0d, /* 00 10 101 */
+ 0x3c0c, /* 00 10 11 */
+ 0x3c0c, /* 00 10 1 */
+ 0x5b0d, /* 00 1 0000 */
+ 0x890d, /* 00 1 0 */
+ 0x1c0c, /* 00 1 */
+ 0x1c0c, /* 00 1 00 */
+ 0xc00c, /* 00 1 010 */
+ 0xc00c, /* 00 1 01 */
+ 0x980d, /* 00 1 0110 */
+ 0x790d, /* 00 1 0111 */
+ 0xe20b, /* 00 1 10 */
+ 0xe20b, /* 00 1 1 */
+ 0xe20b, /* 00 1 1 */
+ 0xe20b, /* 00 1 1 */
+ 0x2e0c, /* 00 1 110 */
+ 0x2e0c, /* 00 1 11 */
+ 0x1e0c, /* 00 1 111 */
+ 0x1e0c, /* 00 1 11 */
+ 0xd30c, /* 00 1010000 */
+ 0xd30c, /* 00 101000 */
+ 0x2d0c, /* 00 1010 */
+ 0x2d0c, /* 00 101000 */
+ 0xd20c, /* 00 101 0 */
+ 0xd20c, /* 00 101 */
+ 0xd10c, /* 00 101 1 */
+ 0xd10c, /* 00 101 */
+ 0x3b0c, /* 00 1010100 */
+ 0x3b0c, /* 00 101010 */
+ 0x970d, /* 00 10101010 */
+ 0x880d, /* 00 10101011 */
+ 0xf208,
+ 0xf208, /* 000 1 */
+ 0x2f09, /* 00 0000 */
+ 0x0f09, /* 00 0 */
+ 0x1f08, /* 00 */
+ 0x1f08, /* 00 00 */
+ 0xf108, /* 00 010 */
+ 0xf108, /* 00 01 */
+ 0xce10,
+ 0xce10, /* 000 101100000 */
+ 0xec11, /* 000 1011000 0 */
+ 0xdd11, /* 000 1011000 1 */
+ 0xde0f, /* 000 101100 */
+ 0xde0f, /* 000 10110000 */
+ 0xde0f, /* 000 10110000 */
+ 0xde0f, /* 000 10110000 */
+ 0xe90f, /* 000 10110 0 */
+ 0xe90f, /* 000 10110 */
+ 0xe90f, /* 000 10110 */
+ 0xe90f, /* 000 10110 */
+ 0xea10, /* 000 10110 10 */
+ 0xea10, /* 000 10110 1 */
+ 0xd910, /* 000 10110 11 */
+ 0xd910, /* 000 10110 1 */
+ 0xee0e,
+ 0xee0e, /* 000 1011 */
+ 0xed0f, /* 000 1011 10 */
+ 0xeb0f, /* 000 1011 11 */
+ 0xbe0e, /* 000 10110100 */
+ 0xbe0e, /* 000 1011010 */
+ 0xcd0e, /* 000 10110101 */
+ 0xcd0e, /* 000 1011010 */
+ 0xdc0f, /* 000 101101100 */
+ 0xdb0f, /* 000 101101101 */
+ 0xae0e, /* 000 10110111 */
+ 0xae0e, /* 000 1011011 */
+ 0xcc0e, /* 000 10111000 */
+ 0xcc0e, /* 000 1011100 */
+ 0xad0f, /* 000 10111 0 */
+ 0xda0f, /* 000 10111 1 */
+ 0x7e0f, /* 000 101110100 */
+ 0xac0f, /* 000 101110101 */
+ 0xca0e, /* 000 10111011 */
+ 0xca0e, /* 000 1011101 */
+ 0xc90f, /* 000 101111000 */
+ 0x7d0f, /* 000 101111 */
+ 0x5e0e, /* 000 10111101 */
+ 0x5e0e, /* 000 1011110 */
+ 0xbd0d, /* 000 1011111 */
+ 0xbd0d, /* 000 101111 */
+ 0xbd0d, /* 000 101111 */
+ 0xbd0d, /* 000 101111 */
+ 0xef0b,
+ 0xfe0b, /* 00000000 */
+ 0xdf0b, /* 0000000 0 */
+ 0xfd0b, /* 0000000 1 */
+ 0xcf0b, /* 00 */
+ 0xfc0b, /* 01 */
+ 0xbf0b, /* 10 */
+ 0xfb0b, /* 11 */
+ 0xaf0a, /* 00 */
+ 0xaf0a, /* 0 */
+ 0xfa0b, /* 010 */
+ 0x9f0b, /* 011 */
+ 0xf90b, /* 100 */
+ 0xf80b, /* 101 */
+ 0x8f0a, /* 11 */
+ 0x8f0a, /* 1 */
+ 0x7f0a, /* 0000 000 */
+ 0x7f0a, /* 0000 00 */
+ 0xf70a, /* 0000 */
+ 0xf70a, /* 0000 00 */
+ 0x6f0a, /* 0000 010 */
+ 0x6f0a, /* 0000 01 */
+ 0xf60a, /* 0000 011 */
+ 0xf60a, /* 0000 01 */
+ 0xff08, /* 0000 1 */
+ 0xff08, /* 0000 */
+ 0xff08, /* 0000 */
+ 0xff08, /* 0000 */
+ 0xff08, /* 0000 */
+ 0xff08, /* 0000 */
+ 0xff08, /* 0000 */
+ 0xff08, /* 0000 */
+ 0x5f0a, /* 000 0000 */
+ 0x5f0a, /* 000 000 */
+ 0xf50a, /* 000 0 */
+ 0xf50a, /* 000 000 */
+ 0x4f09, /* 000 */
+ 0x4f09, /* 000 00 */
+ 0x4f09, /* 000 00 */
+ 0x4f09, /* 000 00 */
+ 0xf409, /* 000 010 */
+ 0xf409, /* 000 01 */
+ 0xf409, /* 000 01 */
+ 0xf409, /* 000 01 */
+ 0xf309, /* 000 011 */
+ 0xf309, /* 000 01 */
+ 0xf309, /* 000 01 */
+ 0xf309, /* 000 01 */
+ 0xf009, /* 000 100 */
+ 0xf009, /* 000 10 */
+ 0xf009, /* 000 10 */
+ 0xf009, /* 000 10 */
+ 0x3f0a,
+ 0x3f0a
+};
+
+
+
+const uint16 huffTable_24[478] =
+{
+
+ 0x2206, /* 101 */
+ 0x1205, /* 10101 */
+ 0x1205, /* 1010 */
+ 0x2105, /* 10110 */
+ 0x2105, /* 1011 */
+ 0x0206, /* 101110 */
+ 0x2006, /* 101111 */
+ 0x1104,
+ 0x1104,
+ 0x1104,
+ 0x1104,
+ 0x0104,
+ 0x0104,
+ 0x0104,
+ 0x0104,
+ 0x1004,
+ 0x1004,
+ 0x1004,
+ 0x1004,
+ 0x0004,
+ 0x0004,
+ 0x0004,
+ 0x0004,
+ 0x7308,
+ 0x7308,
+ 0x3709,
+ 0x2709,
+ 0x7208,
+ 0x7208,
+ 0x4608, /* 01110000 */
+ 0x4608, /* 0111000 */
+ 0x6408, /* 01110 */
+ 0x6408, /* 0111000 */
+ 0x5508, /* 0111 0 */
+ 0x5508, /* 0111 */
+ 0x7108, /* 0111 1 */
+ 0x7108, /* 0111 */
+ 0x3608, /* 01110100 */
+ 0x3608, /* 0111010 */
+ 0x6308, /* 01110101 */
+ 0x6308, /* 0111010 */
+ 0x4508, /* 01110110 */
+ 0x4508, /* 0111011 */
+ 0x5408, /* 01110111 */
+ 0x5408, /* 0111011 */
+ 0x2608, /* 01111000 */
+ 0x2608, /* 0111100 */
+ 0x6208, /* 01111 */
+ 0x6208, /* 0111100 */
+ 0x1608, /* 01111010 */
+ 0x1608, /* 0111101 */
+ 0x6108, /* 01111011 */
+ 0x6108, /* 0111101 */
+ 0x0609, /* 011111000 */
+ 0x6009, /* 011111 */
+ 0x3508, /* 01111101 */
+ 0x3508, /* 0111110 */
+ 0x5308, /* 01111110 */
+ 0x5308, /* 0111111 */
+ 0x4408, /* 01111111 */
+ 0x4408, /* 0111111 */
+ 0x2508, /* 10000000 */
+ 0x2508, /* 1000000 */
+ 0x5208, /* 10000 */
+ 0x5208, /* 1000000 */
+ 0x1508, /* 1000 0 */
+ 0x1508, /* 1000 */
+ 0x0509, /* 1000 10 */
+ 0x5009, /* 1000 11 */
+ 0x5107, /* 100 0 */
+ 0x5107, /* 100 */
+ 0x5107, /* 100 */
+ 0x5107, /* 100 */
+ 0x3408, /* 100 10 */
+ 0x3408, /* 100 1 */
+ 0x4308, /* 100 11 */
+ 0x4308, /* 100 1 */
+ 0x2407, /* 10 00 */
+ 0x2407, /* 10 0 */
+ 0x2407, /* 10 0 */
+ 0x2407, /* 10 0 */
+ 0x4207, /* 10 01 */
+ 0x4207, /* 10 0 */
+ 0x4207, /* 10 0 */
+ 0x4207, /* 10 0 */
+ 0x3307, /* 10 10 */
+ 0x3307, /* 10 1 */
+ 0x3307, /* 10 1 */
+ 0x3307, /* 10 1 */
+ 0x1407, /* 10 11 */
+ 0x1407, /* 10 1 */
+ 0x1407, /* 10 1 */
+ 0x1407, /* 10 1 */
+ 0x4107, /* 1 000 */
+ 0x4107, /* 1 00 */
+ 0x4107, /* 1 00 */
+ 0x4107, /* 1 00 */
+ 0x0408, /* 1 0 */
+ 0x0408, /* 1 */
+ 0x4008, /* 1 1 */
+ 0x4008, /* 1 */
+ 0x2307, /* 1 010 */
+ 0x2307, /* 1 01 */
+ 0x2307, /* 1 01 */
+ 0x2307, /* 1 01 */
+ 0x3207, /* 1 011 */
+ 0x3207, /* 1 01 */
+ 0x3207, /* 1 01 */
+ 0x3207, /* 1 01 */
+ 0x1306, /* 1 10 */
+ 0x1306, /* 1 1 */
+ 0x1306, /* 1 1 */
+ 0x1306, /* 1 1 */
+ 0x1306, /* 1 1 */
+ 0x1306, /* 1 1 */
+ 0x1306, /* 1 1 */
+ 0x1306, /* 1 1 */
+ 0x3106, /* 1 11 */
+ 0x3106, /* 1 1 */
+ 0x3106, /* 1 1 */
+ 0x3106, /* 1 1 */
+ 0x3106, /* 1 1 */
+ 0x3106, /* 1 1 */
+ 0x3106, /* 1 1 */
+ 0x3106, /* 1 1 */
+ 0x0307, /* 1010000 */
+ 0x0307, /* 101000 */
+ 0x0307, /* 101000 */
+ 0x0307, /* 101000 */
+ 0x3007, /* 1010 */
+ 0x3007, /* 101000 */
+ 0x3007, /* 101000 */
+ 0x3007, /* 101000 */
+ 0xb309,
+ 0xb309,
+ 0x8809, /* 010101 */
+ 0x8809, /* 01010100 */
+ 0x2b0a, /* 0101010100 */
+ 0x5a0a, /* 0101010101 */
+ 0xb209, /* 010101011 */
+ 0xb209, /* 01010101 */
+ 0xa50a, /* 0101011000 */
+ 0x1b0a, /* 0101011 */
+ 0xb10a, /* 0101011010 */
+ 0x690a, /* 0101011011 */
+ 0x9609, /* 010101110 */
+ 0x9609, /* 01010111 */
+ 0xa409, /* 010101111 */
+ 0xa409, /* 01010111 */
+ 0x4a0a, /* 0101100000 */
+ 0x780a, /* 0101100 */
+ 0x8709, /* 010110 */
+ 0x8709, /* 01011000 */
+ 0x3a09, /* 01011 0 */
+ 0x3a09, /* 01011 */
+ 0xa309, /* 01011 1 */
+ 0xa309, /* 01011 */
+ 0x5909, /* 010110100 */
+ 0x5909, /* 01011010 */
+ 0x9509, /* 010110101 */
+ 0x9509, /* 01011010 */
+ 0x2a09, /* 010110110 */
+ 0x2a09, /* 01011011 */
+ 0xa209, /* 010110111 */
+ 0xa209, /* 01011011 */
+ 0xa109, /* 010111000 */
+ 0xa109, /* 01011100 */
+ 0x6809, /* 010111 */
+ 0x6809, /* 01011100 */
+ 0x8609, /* 010111010 */
+ 0x8609, /* 01011101 */
+ 0x7709, /* 010111011 */
+ 0x7709, /* 01011101 */
+ 0x4909, /* 010111100 */
+ 0x4909, /* 01011110 */
+ 0x9409, /* 010111101 */
+ 0x9409, /* 01011110 */
+ 0x3909, /* 010111110 */
+ 0x3909, /* 01011111 */
+ 0x9309, /* 010111111 */
+ 0x9309, /* 01011111 */
+ 0x5809, /* 011000000 */
+ 0x5809, /* 01100000 */
+ 0x8509, /* 011000 */
+ 0x8509, /* 01100000 */
+ 0x2909, /* 01100 0 */
+ 0x2909, /* 01100 */
+ 0x6709, /* 01100 1 */
+ 0x6709, /* 01100 */
+ 0x7609, /* 0110 00 */
+ 0x7609, /* 0110 0 */
+ 0x9209, /* 0110 01 */
+ 0x9209, /* 0110 0 */
+ 0x1909, /* 0110 10 */
+ 0x1909, /* 0110 1 */
+ 0x9109, /* 0110 11 */
+ 0x9109, /* 0110 1 */
+ 0x4809, /* 011 000 */
+ 0x4809, /* 011 00 */
+ 0x8409, /* 011 */
+ 0x8409, /* 011 00 */
+ 0x5709, /* 011 010 */
+ 0x5709, /* 011 01 */
+ 0x7509, /* 011 011 */
+ 0x7509, /* 011 01 */
+ 0x3809, /* 011 100 */
+ 0x3809, /* 011 10 */
+ 0x8309, /* 011 101 */
+ 0x8309, /* 011 10 */
+ 0x6609, /* 011 110 */
+ 0x6609, /* 011 11 */
+ 0x2809, /* 011 111 */
+ 0x2809, /* 011 11 */
+ 0x8209, /* 011010000 */
+ 0x8209, /* 01101000 */
+ 0x1809, /* 011010 */
+ 0x1809, /* 01101000 */
+ 0x4709, /* 01101 0 */
+ 0x4709, /* 01101 */
+ 0x7409, /* 01101 1 */
+ 0x7409, /* 01101 */
+ 0x8109, /* 011010100 */
+ 0x8109, /* 01101010 */
+ 0x080a, /* 0110101010 */
+ 0x800a, /* 0110101011 */
+ 0x5609, /* 011010110 */
+ 0x5609, /* 01101011 */
+ 0x6509, /* 011010111 */
+ 0x6509, /* 01101011 */
+ 0x1709, /* 011011000 */
+ 0x1709, /* 01101100 */
+ 0x070a, /* 011011 0 */
+ 0x700a, /* 011011 1 */
+ 0x6e0b,
+ 0x9c0b,
+ 0xc90a, /* 01000 01 */
+ 0xc90a, /* 01000 0 */
+ 0x5e0a, /* 01000 10 */
+ 0x5e0a, /* 01000 1 */
+ 0xba0a, /* 01000 11 */
+ 0xba0a, /* 01000 1 */
+ 0xe50a, /* 0100 000 */
+ 0xe50a, /* 0100 00 */
+ 0xab0b, /* 0100 0 */
+ 0x7d0b, /* 0100 1 */
+ 0xd70a, /* 0100 010 */
+ 0xd70a, /* 0100 01 */
+ 0xe40a, /* 0100 011 */
+ 0xe40a, /* 0100 01 */
+ 0x8c0a, /* 0100 100 */
+ 0x8c0a,
+ 0xc80a,
+ 0xc80a,
+ 0x4e0b, /* 0100 1100 */
+ 0x2e0b, /* 0100 1101 */
+ 0x3e0a, /* 0100 111 */
+ 0x3e0a, /* 0100 11 */
+ 0x6d0a, /* 010 0000 */
+ 0x6d0a, /* 010 000 */
+ 0xd60a, /* 010 0 */
+ 0xd60a, /* 010 000 */
+ 0xe30a, /* 010 0 */
+ 0xe30a, /* 010 */
+ 0x9b0a, /* 010 1 */
+ 0x9b0a, /* 010 */
+ 0xb90a, /* 010 0100 */
+ 0xb90a, /* 010 010 */
+ 0xaa0a, /* 010 0101 */
+ 0xaa0a,
+ 0xe20a,
+ 0xe20a,
+ 0x1e0a,
+ 0x1e0a,
+ 0xe10a,
+ 0xe10a,
+ 0x5d0a,
+ 0x5d0a,
+ 0xd50a,
+ 0xd50a,
+ 0x7c0a,
+ 0x7c0a,
+ 0xc70a,
+ 0xc70a,
+ 0x4d0a,
+ 0x4d0a,
+ 0x8b0a,
+ 0x8b0a,
+ 0xb80a,
+ 0xb80a,
+ 0xd40a,
+ 0xd40a,
+ 0x9a0a,
+ 0x9a0a,
+ 0xa90a, /* 01 0 0 */
+ 0xa90a, /* 01 0 */
+ 0x6c0a, /* 01 0 1 */
+ 0x6c0a, /* 01 0 */
+ 0xc60a, /* 01 00 */
+ 0xc60a, /* 01 0 */
+ 0x3d0a, /* 01 01 */
+ 0x3d0a, /* 01 0 */
+ 0xd30a, /* 01 10 */
+ 0xd30a, /* 01 1 */
+ 0x2d0a, /* 01 11 */
+ 0x2d0a, /* 01 1 */
+ 0xd20a,
+ 0xd20a,
+ 0x1d0a, /* 01 01 */
+ 0x1d0a, /* 01 0100 */
+ 0x7b0a, /* 01 01010 */
+ 0x7b0a, /* 01 0101 */
+ 0xb70a, /* 01 01011 */
+ 0xb70a,
+ 0xd10a,
+ 0xd10a, /* 01 0110 */
+ 0x5c0a, /* 01 01101 */
+ 0x5c0a, /* 01 0110 */
+ 0xc50a, /* 01 01110 */
+ 0xc50a, /* 01 0111 */
+ 0x8a0a, /* 01 01111 */
+ 0x8a0a, /* 01 0111 */
+ 0xa80a, /* 01 10000 */
+ 0xa80a, /* 01 1000 */
+ 0x990a, /* 01 10 */
+ 0x990a, /* 01 1000 */
+ 0x4c0a, /* 01 1 0 */
+ 0x4c0a, /* 01 1 */
+ 0xc40a, /* 01 1 1 */
+ 0xc40a, /* 01 1 */
+ 0x6b0a, /* 01 10100 */
+ 0x6b0a, /* 01 1010 */
+ 0xb60a, /* 01 10101 */
+ 0xb60a, /* 01 1010 */
+ 0xd00b, /* 01 101100 */
+ 0x0c0b, /* 01 101101 */
+ 0x3c0a, /* 01 10111 */
+ 0x3c0a, /* 01 1011 */
+ 0xc30a, /* 01 11000 */
+ 0xc30a, /* 01 1100 */
+ 0x7a0a, /* 01 11 */
+ 0x7a0a, /* 01 1100 */
+ 0xa70a, /* 01 11010 */
+ 0xa70a, /* 01 1101 */
+ 0x2c0a, /* 01 11011 */
+ 0x2c0a, /* 01 1101 */
+ 0xc20a, /* 01 11100 */
+ 0xc20a, /* 01 1110 */
+ 0x5b0a, /* 01 11101 */
+ 0x5b0a, /* 01 1110 */
+ 0xb50a, /* 01 11110 */
+ 0xb50a, /* 01 1111 */
+ 0x1c0a,
+ 0x1c0a,
+ 0x890a,
+ 0x890a,
+ 0x980a,
+ 0x980a,
+ 0xc10a, /* 010100 0 */
+ 0xc10a, /* 010100 */
+ 0x4b0a, /* 010100 1 */
+ 0x4b0a, /* 010100 */
+ 0xc00b, /* 01010 000 */
+ 0x0b0b, /* 01010 */
+ 0x3b0a, /* 01010 01 */
+ 0x3b0a, /* 01010 0 */
+ 0xb00b, /* 01010 100 */
+ 0x0a0b, /* 01010 101 */
+ 0x1a0a, /* 01010 11 */
+ 0x1a0a, /* 01010 1 */
+ 0xb409, /* 0101 00 */
+ 0xb409, /* 0101 0 */
+ 0xb409, /* 0101 0 */
+ 0xb409, /* 0101 0 */
+ 0x6a0a, /* 0101 010 */
+ 0x6a0a, /* 0101 01 */
+ 0xa60a, /* 0101 011 */
+ 0xa60a, /* 0101 01 */
+ 0x790a, /* 0101 100 */
+ 0x790a, /* 0101 10 */
+ 0x970a, /* 0101 101 */
+ 0x970a, /* 0101 10 */
+ 0xa00b, /* 0101 1100 */
+ 0x090b, /* 0101 1101 */
+ 0x900a, /* 0101 111 */
+ 0x900a, /* 0101 11 */
+ 0xca0b,
+ 0xca0b,
+ 0xbb0b,
+ 0xbb0b,
+ 0x8d0b,
+ 0x8d0b, /* 0100000 */
+ 0xd80b, /* 0100000 1 */
+ 0xd80b, /* 0100000 */
+ 0x0e0c, /* 010000 000 */
+ 0xe00c, /* 010000 */
+ 0x0d0b, /* 010000 01 */
+ 0x0d0b, /* 010000 0 */
+ 0xe60a, /* 010000 1 */
+ 0xe60a, /* 010000 */
+ 0xe60a, /* 010000 */
+ 0xe60a, /* 010000 */
+ 0x0f09, /* 011000 401 */
+ 0x0f09, /* 01100 */
+ 0x0f09, /* 01100 */
+ 0x0f09, /* 01100 */
+ 0xee0b, /* 011 00 */
+ 0xde0b, /* 011 01 */
+ 0xed0b, /* 011 10 */
+ 0xce0b, /* 011 11 */
+ 0xec0b, /* 01101000 */
+ 0xdd0b, /* 01101 */
+ 0xbe0b, /* 01101010 */
+ 0xeb0b, /* 01101011 */
+ 0xcd0b, /* 01101100 */
+ 0xdc0b, /* 01101101 */
+ 0xae0b, /* 01101110 */
+ 0xea0b, /* 01101111 */
+ 0xbd0b, /* 01110000 */
+ 0xdb0b, /* 01110 */
+ 0xcc0b, /* 0111 0 */
+ 0x9e0b, /* 0111 1 */
+ 0xe90b, /* 01110100 */
+ 0xad0b, /* 01110101 */
+ 0xda0b, /* 01110110 */
+ 0xbc0b, /* 01110111 */
+ 0xcb0b, /* 01111000 */
+ 0x8e0b,
+ 0xe80b,
+ 0x9d0b,
+ 0xd90b,
+ 0x7e0b,
+ 0xe70b,
+ 0xac0b,
+ 0xff04,
+ 0xef08,
+ 0xfe08,
+ 0xdf08, /* 0000 0 */
+ 0xfd08, /* 0000 1 */
+ 0xcf08, /* 000 00 */
+ 0xfc08, /* 000 01 */
+ 0xbf08, /* 000 10 */
+ 0xfb08, /* 000 11 */
+ 0xfa07, /* 00 00 */
+ 0xfa07, /* 00 0 */
+ 0xaf08, /* 00 010 */
+ 0x9f08, /* 00 011 */
+ 0xf907, /* 00 10 */
+ 0xf907, /* 00 1 */
+ 0xf807, /* 00 11 */
+ 0xf807, /* 00 1 */
+ 0x8f08,
+ 0x7f08, /* 0 0 */
+ 0xf707, /* 0 */
+ 0xf707, /* 0 00 */
+ 0x6f07, /* 0 010 */
+ 0x6f07, /* 0 01 */
+ 0xf607, /* 0 011 */
+ 0xf607, /* 0 01 */
+ 0x5f07,
+ 0x5f07, /* 0 10 */
+ 0xf507, /* 0 101 */
+ 0xf507, /* 0 10 */
+ 0x4f07, /* 0 110 */
+ 0x4f07, /* 0 11 */
+ 0xf407, /* 0 111 */
+ 0xf407, /* 0 11 */
+ 0x3f07,
+ 0x3f07,
+ 0xf307, /* 0 */
+ 0xf307,
+ 0x2f07, /* 0 */
+ 0x2f07, /* */
+ 0xf207, /* 1 */
+ 0xf207, /* */
+ 0xf107,
+ 0xf107,
+ 0x1f08,
+ 0xf008
+
+};
+
+
+const uint16 huffTable_32[33] =
+{
+
+ 0x0b06,
+ 0x0f06,
+ 0x0d06,
+ 0x0e06,
+ 0x0706,
+ 0x0506,
+ 0x0905,
+ 0x0905,
+ 0x0605,
+ 0x0605,
+ 0x0305,
+ 0x0305,
+ 0x0a05,
+ 0x0a05,
+ 0x0c05,
+ 0x0c05,
+ 0x0204,
+ 0x0204,
+ 0x0204,
+ 0x0204,
+ 0x0104,
+ 0x0104,
+ 0x0104,
+ 0x0104,
+ 0x0404,
+ 0x0404,
+ 0x0404,
+ 0x0404,
+ 0x0804,
+ 0x0804,
+ 0x0804,
+ 0x0804,
+ 0x0001
+
+};
+
+
+/*
+ * MM = 512; z = [0:(MM)]; a = z.^(1/3);
+ * Table is in Q27
+ */
+const int32 power_one_third[513] =
+{
+
+ 0x00000000, 0x08000000, 0x0A14517D, 0x0B89BA25,
+ 0x0CB2FF53, 0x0DAE07DE, 0x0E897685, 0x0F4DAEDD,
+ 0x10000000, 0x10A402FD, 0x113C4841, 0x11CAB613,
+ 0x1250BFE2, 0x12CF8890, 0x1347F8AB, 0x13BACD65,
+ 0x1428A2FA, 0x1491FC15, 0x14F74744, 0x1558E2F7,
+ 0x15B72095, 0x161246D7, 0x166A9399, 0x16C03D55,
+ 0x17137449, 0x17646369, 0x17B33124, 0x18000000,
+ 0x184AEF29, 0x18941AD8, 0x18DB9CB7, 0x19218C2E,
+ 0x1965FEA5, 0x19A907C2, 0x19EAB998, 0x1A2B24D0,
+ 0x1A6A58D5, 0x1AA863EE, 0x1AE5535D, 0x1B213377,
+ 0x1B5C0FBD, 0x1B95F2EC, 0x1BCEE70F, 0x1C06F590,
+ 0x1C3E2745, 0x1C74847A, 0x1CAA1501, 0x1CDEE035,
+ 0x1D12ED0B, 0x1D464212, 0x1D78E582, 0x1DAADD3A,
+ 0x1DDC2ECF, 0x1E0CDF8C, 0x1E3CF476, 0x1E6C7257,
+ 0x1E9B5DBA, 0x1EC9BAF6, 0x1EF78E2C, 0x1F24DB4E,
+ 0x1F51A620, 0x1F7DF23C, 0x1FA9C314, 0x1FD51BF2,
+ 0x20000000, 0x202A7244, 0x205475A6, 0x207E0CEE,
+ 0x20A73ACA, 0x20D001CC, 0x20F8646D, 0x2120650E,
+ 0x214805FA, 0x216F4963, 0x2196316C, 0x21BCC020,
+ 0x21E2F77A, 0x2208D961, 0x222E67AD, 0x2253A425,
+ 0x22789082, 0x229D2E6E, 0x22C17F82, 0x22E5854F,
+ 0x23094155, 0x232CB509, 0x234FE1D5, 0x2372C918,
+ 0x23956C26, 0x23B7CC47, 0x23D9EABB, 0x23FBC8B9,
+ 0x241D676E, 0x243EC7FF, 0x245FEB86, 0x2480D319,
+ 0x24A17FC3, 0x24C1F28B, 0x24E22C6C, 0x25022E5F,
+ 0x2521F954, 0x25418E33, 0x2560EDE2, 0x2580193E,
+ 0x259F111F, 0x25BDD657, 0x25DC69B4, 0x25FACBFE,
+ 0x2618FDF8, 0x26370060, 0x2654D3EF, 0x2672795C,
+ 0x268FF156, 0x26AD3C8A, 0x26CA5BA2, 0x26E74F41,
+ 0x27041808, 0x2720B695, 0x273D2B81, 0x27597762,
+ 0x27759ACB, 0x2791964B, 0x27AD6A6F, 0x27C917C0,
+ 0x27E49EC5, 0x28000000, 0x281B3BF3, 0x2836531B,
+ 0x285145F3, 0x286C14F5, 0x2886C096, 0x28A1494B,
+ 0x28BBAF85, 0x28D5F3B3, 0x28F01641, 0x290A179B,
+ 0x2923F82A, 0x293DB854, 0x2957587E, 0x2970D90A,
+ 0x298A3A59, 0x29A37CCA, 0x29BCA0BB, 0x29D5A687,
+ 0x29EE8E87, 0x2A075914, 0x2A200684, 0x2A38972C,
+ 0x2A510B5F, 0x2A696370, 0x2A819FAE, 0x2A99C069,
+ 0x2AB1C5ED, 0x2AC9B088, 0x2AE18085, 0x2AF9362C,
+ 0x2B10D1C6, 0x2B28539B, 0x2B3FBBEF, 0x2B570B09,
+ 0x2B6E412B, 0x2B855E97, 0x2B9C6390, 0x2BB35056,
+ 0x2BCA2527, 0x2BE0E242, 0x2BF787E4, 0x2C0E1649,
+ 0x2C248DAD, 0x2C3AEE4A, 0x2C513859, 0x2C676C13,
+ 0x2C7D89AF, 0x2C939164, 0x2CA98368, 0x2CBF5FF1,
+ 0x2CD52731, 0x2CEAD95E, 0x2D0076A9, 0x2D15FF45,
+ 0x2D2B7363, 0x2D40D332, 0x2D561EE4, 0x2D6B56A7,
+ 0x2D807AAA, 0x2D958B19, 0x2DAA8823, 0x2DBF71F4,
+ 0x2DD448B7, 0x2DE90C98, 0x2DFDBDC0, 0x2E125C5C,
+ 0x2E26E892, 0x2E3B628D, 0x2E4FCA75, 0x2E642070,
+ 0x2E7864A8, 0x2E8C9741, 0x2EA0B862, 0x2EB4C831,
+ 0x2EC8C6D3, 0x2EDCB46C, 0x2EF09121, 0x2F045D14,
+ 0x2F18186A, 0x2F2BC345, 0x2F3F5DC7, 0x2F52E812,
+ 0x2F666247, 0x2F79CC88, 0x2F8D26F4, 0x2FA071AC,
+ 0x2FB3ACD0, 0x2FC6D87F, 0x2FD9F4D7, 0x2FED01F8,
+ 0x30000000, 0x3012EF0C, 0x3025CF39, 0x3038A0A6,
+ 0x304B636D, 0x305E17AD, 0x3070BD81, 0x30835504,
+ 0x3095DE51, 0x30A85985, 0x30BAC6B9, 0x30CD2609,
+ 0x30DF778D, 0x30F1BB60, 0x3103F19C, 0x31161A59,
+ 0x312835B0, 0x313A43BA, 0x314C4490, 0x315E3849,
+ 0x31701EFD, 0x3181F8C4, 0x3193C5B4, 0x31A585E6,
+ 0x31B7396F, 0x31C8E066, 0x31DA7AE1, 0x31EC08F6,
+ 0x31FD8ABC, 0x320F0047, 0x322069AC, 0x3231C702,
+ 0x3243185C, 0x32545DCF, 0x32659770, 0x3276C552,
+ 0x3287E78A, 0x3298FE2C, 0x32AA094A, 0x32BB08F9,
+ 0x32CBFD4A, 0x32DCE652, 0x32EDC423, 0x32FE96D0,
+ 0x330F5E6A, 0x33201B04, 0x3330CCB0, 0x33417380,
+ 0x33520F85, 0x3362A0D0, 0x33732774, 0x3383A380,
+ 0x33941506, 0x33A47C17, 0x33B4D8C4, 0x33C52B1B,
+ 0x33D5732F, 0x33E5B10F, 0x33F5E4CA, 0x34060E71,
+ 0x34162E14, 0x342643C1, 0x34364F88, 0x34465178,
+ 0x345649A1, 0x34663810, 0x34761CD6, 0x3485F800,
+ 0x3495C99D, 0x34A591BB, 0x34B55069, 0x34C505B4,
+ 0x34D4B1AB, 0x34E4545B, 0x34F3EDD2, 0x35037E1D,
+ 0x3513054B, 0x35228367, 0x3531F881, 0x354164A3,
+ 0x3550C7DC, 0x35602239, 0x356F73C5, 0x357EBC8E,
+ 0x358DFCA0, 0x359D3408, 0x35AC62D1, 0x35BB8908,
+ 0x35CAA6B9, 0x35D9BBF0, 0x35E8C8B9, 0x35F7CD20,
+ 0x3606C92F, 0x3615BCF3, 0x3624A878, 0x36338BC8,
+ 0x364266EE, 0x365139F6, 0x366004EC, 0x366EC7D9,
+ 0x367D82C9, 0x368C35C6, 0x369AE0DC, 0x36A98414,
+ 0x36B81F7A, 0x36C6B317, 0x36D53EF7, 0x36E3C323,
+ 0x36F23FA5, 0x3700B488, 0x370F21D5, 0x371D8797,
+ 0x372BE5D7, 0x373A3CA0, 0x37488BF9, 0x3756D3EF,
+ 0x37651489, 0x37734DD1, 0x37817FD1, 0x378FAA92,
+ 0x379DCE1D, 0x37ABEA7C, 0x37B9FFB7, 0x37C80DD7,
+ 0x37D614E6, 0x37E414EC, 0x37F20DF1, 0x38000000,
+ 0x380DEB20, 0x381BCF5A, 0x3829ACB6, 0x3837833D,
+ 0x384552F8, 0x38531BEE, 0x3860DE28, 0x386E99AF,
+ 0x387C4E89, 0x3889FCC0, 0x3897A45B, 0x38A54563,
+ 0x38B2DFDF, 0x38C073D7, 0x38CE0152, 0x38DB885A,
+ 0x38E908F4, 0x38F68329, 0x3903F701, 0x39116483,
+ 0x391ECBB6, 0x392C2CA1, 0x3939874D, 0x3946DBC0,
+ 0x39542A01, 0x39617218, 0x396EB40C, 0x397BEFE4,
+ 0x398925A7, 0x3996555C, 0x39A37F09, 0x39B0A2B7,
+ 0x39BDC06A, 0x39CAD82B, 0x39D7EA01, 0x39E4F5F0,
+ 0x39F1FC01, 0x39FEFC3A, 0x3A0BF6A2, 0x3A18EB3E,
+ 0x3A25DA16, 0x3A32C32F, 0x3A3FA691, 0x3A4C8441,
+ 0x3A595C46, 0x3A662EA6, 0x3A72FB67, 0x3A7FC28F,
+ 0x3A8C8425, 0x3A99402E, 0x3AA5F6B1, 0x3AB2A7B3,
+ 0x3ABF533A, 0x3ACBF94D, 0x3AD899F1, 0x3AE5352C,
+ 0x3AF1CB03, 0x3AFE5B7D, 0x3B0AE6A0, 0x3B176C70,
+ 0x3B23ECF3, 0x3B306830, 0x3B3CDE2C, 0x3B494EEB,
+ 0x3B55BA74, 0x3B6220CC, 0x3B6E81F9, 0x3B7ADE00,
+ 0x3B8734E5, 0x3B9386B0, 0x3B9FD364, 0x3BAC1B07,
+ 0x3BB85D9E, 0x3BC49B2F, 0x3BD0D3BE, 0x3BDD0751,
+ 0x3BE935ED, 0x3BF55F97, 0x3C018453, 0x3C0DA427,
+ 0x3C19BF17, 0x3C25D52A, 0x3C31E662, 0x3C3DF2C6,
+ 0x3C49FA5B, 0x3C55FD24, 0x3C61FB27, 0x3C6DF468,
+ 0x3C79E8ED, 0x3C85D8B9, 0x3C91C3D2, 0x3C9DAA3C,
+ 0x3CA98BFC, 0x3CB56915, 0x3CC1418E, 0x3CCD156A,
+ 0x3CD8E4AE, 0x3CE4AF5E, 0x3CF0757F, 0x3CFC3714,
+ 0x3D07F423, 0x3D13ACB0, 0x3D1F60BF, 0x3D2B1055,
+ 0x3D36BB75, 0x3D426224, 0x3D4E0466, 0x3D59A23F,
+ 0x3D653BB4, 0x3D70D0C8, 0x3D7C6180, 0x3D87EDE0,
+ 0x3D9375EC, 0x3D9EF9A8, 0x3DAA7918, 0x3DB5F43F,
+ 0x3DC16B23, 0x3DCCDDC7, 0x3DD84C2E, 0x3DE3B65D,
+ 0x3DEF1C58, 0x3DFA7E22, 0x3E05DBC0, 0x3E113535,
+ 0x3E1C8A85, 0x3E27DBB3, 0x3E3328C4, 0x3E3E71BB,
+ 0x3E49B69C, 0x3E54F76B, 0x3E60342B, 0x3E6B6CE0,
+ 0x3E76A18D, 0x3E81D237, 0x3E8CFEE0, 0x3E98278D,
+ 0x3EA34C40, 0x3EAE6CFE, 0x3EB989CA, 0x3EC4A2A8,
+ 0x3ECFB79A, 0x3EDAC8A5, 0x3EE5D5CB, 0x3EF0DF10,
+ 0x3EFBE478, 0x3F06E606, 0x3F11E3BE, 0x3F1CDDA2,
+ 0x3F27D3B6, 0x3F32C5FD, 0x3F3DB47B, 0x3F489F32,
+ 0x3F538627, 0x3F5E695C, 0x3F6948D5, 0x3F742494,
+ 0x3F7EFC9D, 0x3F89D0F3, 0x3F94A19A, 0x3F9F6E94,
+ 0x3FAA37E4, 0x3FB4FD8E, 0x3FBFBF94, 0x3FCA7DFB,
+ 0x3FD538C4, 0x3FDFEFF3, 0x3FEAA38A, 0x3FF5538E,
+ 0x40000000
+};
+
+
diff --git a/media/codecs/mp3dec/src/pvmp3_tables.h b/media/codecs/mp3dec/src/pvmp3_tables.h
new file mode 100644
index 0000000..8f8509c
--- /dev/null
+++ b/media/codecs/mp3dec/src/pvmp3_tables.h
@@ -0,0 +1,124 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+ Filename: pvmp3_tables.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+------------------------------------------------------------------------------
+*/
+
+#ifndef PVMP3_TABLES_H
+#define PVMP3_TABLES_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+
+#include "pvmp3_dec_defs.h"
+#include "pv_mp3_huffman.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES AND SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+#define Qfmt_28(a) (int32(double(0x10000000)*(a)))
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+typedef struct
+{
+ int16 l[23];
+ int16 s[14];
+} mp3_scaleFactorBandIndex;
+
+
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ extern const int32 mp3_s_freq[4][4];
+ extern const int32 inv_sfreq[4];
+ extern const int16 mp3_bitrate[3][15];
+ extern const int32 power_one_third[513];
+
+ extern const mp3_scaleFactorBandIndex mp3_sfBandIndex[9];
+ extern const int32 mp3_shortwindBandWidths[9][13];
+ extern const int32 pqmfSynthWin[(HAN_SIZE/2) + 8];
+
+
+ extern const uint16 huffTable_1[];
+ extern const uint16 huffTable_2[];
+ extern const uint16 huffTable_3[];
+ extern const uint16 huffTable_5[];
+ extern const uint16 huffTable_6[];
+ extern const uint16 huffTable_7[];
+ extern const uint16 huffTable_8[];
+ extern const uint16 huffTable_9[];
+ extern const uint16 huffTable_10[];
+ extern const uint16 huffTable_11[];
+ extern const uint16 huffTable_12[];
+ extern const uint16 huffTable_13[];
+ extern const uint16 huffTable_15[];
+ extern const uint16 huffTable_16[];
+ extern const uint16 huffTable_24[];
+ extern const uint16 huffTable_32[];
+ extern const uint16 huffTable_33[];
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
diff --git a/media/codecs/mp3dec/src/s_huffcodetab.h b/media/codecs/mp3dec/src/s_huffcodetab.h
new file mode 100644
index 0000000..874943d
--- /dev/null
+++ b/media/codecs/mp3dec/src/s_huffcodetab.h
@@ -0,0 +1,98 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: s_huffcodetab.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+
+------------------------------------------------------------------------------
+ REFERENCES
+
+ [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
+ ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
+
+----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef S_HUFFCODETAB_H
+#define S_HUFFCODETAB_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+#define HUFF_TBL 34
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+struct huffcodetab
+{
+ uint32 linbits; /*number of linbits */
+ uint16(*pdec_huff_tab)(tmp3Bits *);
+};
+
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/s_mp3bits.h b/media/codecs/mp3dec/src/s_mp3bits.h
new file mode 100644
index 0000000..b905b9a
--- /dev/null
+++ b/media/codecs/mp3dec/src/s_mp3bits.h
@@ -0,0 +1,107 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: s_mp3bits.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This include file defines the structure, BITS
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef S_MP3BITS_H
+#define S_MP3BITS_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+/*
+ * Name: BITS
+ * Description: Holds information for processing the input data buffer
+ * as a "stream". The data is in packed format.
+ * Fields:
+ * pBuffer - pointer to the beginning of the buffer. If the data type of
+ * this changes, make sure to update the constants in ibstream.h
+ * usedBits - number of bits read thus far from the buffer. Bit 0 is
+ * the LSB of pBuffer[0].
+ */
+
+
+typedef struct
+{
+ uint8 *pBuffer;
+ uint32 usedBits;
+ uint32 inputBufferCurrentLength;
+ uint32 offset;
+} tmp3Bits;
+
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+#endif
+
diff --git a/media/codecs/mp3dec/src/s_tmp3dec_chan.h b/media/codecs/mp3dec/src/s_tmp3dec_chan.h
new file mode 100644
index 0000000..6eb8835
--- /dev/null
+++ b/media/codecs/mp3dec/src/s_tmp3dec_chan.h
@@ -0,0 +1,110 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: s_tmp3dec_chan.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This include file defines the structure, tmp3dec_chan.
+ This structure contains information per channel that needs to persist
+ between calls
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef S_TMP3DEC_CHAN_H
+#define S_TMP3DEC_CHAN_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "pvmp3_audio_type_defs.h"
+#include "pvmp3_dec_defs.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ typedef struct
+ {
+ int32 used_freq_lines;
+ int32 overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS];
+ int32 work_buf_int32[SUBBANDS_NUMBER*FILTERBANK_BANDS]; /* working buffer */
+ int32 circ_buffer[480 + 576];
+
+ } tmp3dec_chan;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
+
diff --git a/media/codecs/mp3dec/src/s_tmp3dec_file.h b/media/codecs/mp3dec/src/s_tmp3dec_file.h
new file mode 100644
index 0000000..611e08f
--- /dev/null
+++ b/media/codecs/mp3dec/src/s_tmp3dec_file.h
@@ -0,0 +1,118 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 1998-2009 PacketVideo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+/*
+------------------------------------------------------------------------------
+ PacketVideo Corp.
+ MP3 Decoder Library
+
+ Filename: s_tmp3dec_file.h
+
+ Date: 09/21/2007
+
+------------------------------------------------------------------------------
+ REVISION HISTORY
+
+ Description:
+
+------------------------------------------------------------------------------
+ INCLUDE DESCRIPTION
+
+ This include file defines the structure, tmp3dec_file.
+ This structure contains information that needs to persist between calls
+
+------------------------------------------------------------------------------
+*/
+
+/*----------------------------------------------------------------------------
+; CONTINUE ONLY IF NOT ALREADY DEFINED
+----------------------------------------------------------------------------*/
+#ifndef S_TMP3DEC_FILE_H
+#define S_TMP3DEC_FILE_H
+
+/*----------------------------------------------------------------------------
+; INCLUDES
+----------------------------------------------------------------------------*/
+#include "s_tmp3dec_chan.h"
+#include "s_mp3bits.h"
+#include "s_huffcodetab.h"
+
+/*----------------------------------------------------------------------------
+; MACROS
+; Define module specific macros here
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; DEFINES
+; Include all pre-processor statements here.
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; EXTERNAL VARIABLES REFERENCES
+; Declare variables used in this module but defined elsewhere
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; SIMPLE TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; ENUMERATED TYPEDEF'S
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; STRUCTURES TYPEDEF'S
+----------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ typedef struct
+ {
+ int32 num_channels;
+ int32 predicted_frame_size;
+ int32 frame_start;
+ int32 Scratch_mem[198];
+ tmp3dec_chan perChan[CHAN];
+ mp3ScaleFactors scaleFactors[CHAN];
+ mp3SideInfo sideInfo;
+ tmp3Bits mainDataStream;
+ uint8 mainDataBuffer[BUFSIZE];
+ tmp3Bits inputStream;
+ huffcodetab ht[HUFF_TBL];
+ } tmp3dec_file;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/*----------------------------------------------------------------------------
+; GLOBAL FUNCTION DEFINITIONS
+; Function Prototype declaration
+----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+; END
+----------------------------------------------------------------------------*/
+
+#endif
+
+
+
+
diff --git a/media/codecs/mp3dec/test/Android.bp b/media/codecs/mp3dec/test/Android.bp
new file mode 100644
index 0000000..0ff8b12
--- /dev/null
+++ b/media/codecs/mp3dec/test/Android.bp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+cc_test {
+ name: "Mp3DecoderTest",
+ gtest: true,
+
+ srcs: [
+ "mp3reader.cpp",
+ "Mp3DecoderTest.cpp",
+ ],
+
+ static_libs: [
+ "libstagefright_mp3dec",
+ "libsndfile",
+ "libaudioutils",
+ ],
+
+ shared_libs: [
+ "liblog",
+ ],
+
+ cflags: [
+ "-Werror",
+ "-Wall",
+ ],
+
+ sanitize: {
+ cfi: true,
+ misc_undefined: [
+ "unsigned-integer-overflow",
+ "signed-integer-overflow",
+ ],
+ },
+}
diff --git a/media/codecs/mp3dec/test/AndroidTest.xml b/media/codecs/mp3dec/test/AndroidTest.xml
new file mode 100644
index 0000000..29952eb
--- /dev/null
+++ b/media/codecs/mp3dec/test/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Test module config for Mp3 Decoder unit test">
+ <option name="test-suite-tag" value="Mp3DecoderTest" />
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="Mp3DecoderTest->/data/local/tmp/Mp3DecoderTest" />
+ <option name="push-file"
+ key="https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/mp3dec/test/Mp3DecoderTest-1.2.zip?unzip=true"
+ value="/data/local/tmp/Mp3DecoderTestRes/" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="Mp3DecoderTest" />
+ <option name="native-test-flag" value="-P /data/local/tmp/Mp3DecoderTestRes/" />
+ </test>
+</configuration>
diff --git a/media/codecs/mp3dec/test/Mp3DecoderTest.cpp b/media/codecs/mp3dec/test/Mp3DecoderTest.cpp
new file mode 100644
index 0000000..91326a8
--- /dev/null
+++ b/media/codecs/mp3dec/test/Mp3DecoderTest.cpp
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "Mp3DecoderTest"
+
+#include <utils/Log.h>
+
+#include <audio_utils/sndfile.h>
+#include <stdio.h>
+
+#include "mp3reader.h"
+#include "pvmp3decoder_api.h"
+
+#include "Mp3DecoderTestEnvironment.h"
+
+#define OUTPUT_FILE "/data/local/tmp/mp3Decode.out"
+
+constexpr int32_t kInputBufferSize = 1024 * 10;
+constexpr int32_t kOutputBufferSize = 4608 * 2;
+constexpr int32_t kMaxCount = 10;
+constexpr int32_t kNumFrameReset = 150;
+
+static Mp3DecoderTestEnvironment *gEnv = nullptr;
+
+class Mp3DecoderTest : public ::testing::TestWithParam<string> {
+ public:
+ Mp3DecoderTest() : mConfig(nullptr) {}
+
+ ~Mp3DecoderTest() {
+ if (mConfig) {
+ delete mConfig;
+ mConfig = nullptr;
+ }
+ }
+
+ virtual void SetUp() override {
+ mConfig = new tPVMP3DecoderExternal{};
+ ASSERT_NE(mConfig, nullptr) << "Failed to initialize config. No Memory available";
+ mConfig->equalizerType = flat;
+ mConfig->crcEnabled = false;
+ }
+
+ tPVMP3DecoderExternal *mConfig;
+ Mp3Reader mMp3Reader;
+
+ ERROR_CODE DecodeFrames(void *decoderbuf, SNDFILE *outFileHandle, SF_INFO sfInfo,
+ int32_t frameCount = INT32_MAX);
+ SNDFILE *openOutputFile(SF_INFO *sfInfo);
+};
+
+ERROR_CODE Mp3DecoderTest::DecodeFrames(void *decoderBuf, SNDFILE *outFileHandle, SF_INFO sfInfo,
+ int32_t frameCount) {
+ uint8_t inputBuf[kInputBufferSize];
+ int16_t outputBuf[kOutputBufferSize];
+ uint32_t bytesRead;
+ ERROR_CODE decoderErr;
+ while (frameCount > 0) {
+ bool success = mMp3Reader.getFrame(inputBuf, &bytesRead);
+ if (!success) {
+ break;
+ }
+ mConfig->inputBufferCurrentLength = bytesRead;
+ mConfig->inputBufferMaxLength = 0;
+ mConfig->inputBufferUsedLength = 0;
+ mConfig->pInputBuffer = inputBuf;
+ mConfig->pOutputBuffer = outputBuf;
+ mConfig->outputFrameSize = kOutputBufferSize / sizeof(int16_t);
+ decoderErr = pvmp3_framedecoder(mConfig, decoderBuf);
+ if (decoderErr != NO_DECODING_ERROR) break;
+ sf_writef_short(outFileHandle, outputBuf, mConfig->outputFrameSize / sfInfo.channels);
+ frameCount--;
+ }
+ return decoderErr;
+}
+
+SNDFILE *Mp3DecoderTest::openOutputFile(SF_INFO *sfInfo) {
+ memset(sfInfo, 0, sizeof(SF_INFO));
+ sfInfo->channels = mMp3Reader.getNumChannels();
+ sfInfo->format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ sfInfo->samplerate = mMp3Reader.getSampleRate();
+ SNDFILE *outFileHandle = sf_open(OUTPUT_FILE, SFM_WRITE, sfInfo);
+ return outFileHandle;
+}
+
+TEST_F(Mp3DecoderTest, MultiCreateMp3DecoderTest) {
+ size_t memRequirements = pvmp3_decoderMemRequirements();
+ ASSERT_NE(memRequirements, 0) << "Failed to get the memory requirement size";
+ void *decoderBuf = malloc(memRequirements);
+ ASSERT_NE(decoderBuf, nullptr)
+ << "Failed to allocate decoder memory of size " << memRequirements;
+ for (int count = 0; count < kMaxCount; count++) {
+ pvmp3_InitDecoder(mConfig, decoderBuf);
+ ALOGV("Decoder created successfully");
+ }
+ if (decoderBuf) {
+ free(decoderBuf);
+ decoderBuf = nullptr;
+ }
+}
+
+TEST_P(Mp3DecoderTest, DecodeTest) {
+ size_t memRequirements = pvmp3_decoderMemRequirements();
+ ASSERT_NE(memRequirements, 0) << "Failed to get the memory requirement size";
+ void *decoderBuf = malloc(memRequirements);
+ ASSERT_NE(decoderBuf, nullptr)
+ << "Failed to allocate decoder memory of size " << memRequirements;
+
+ pvmp3_InitDecoder(mConfig, decoderBuf);
+ ALOGV("Decoder created successfully");
+ string inputFile = gEnv->getRes() + GetParam();
+ bool status = mMp3Reader.init(inputFile.c_str());
+ ASSERT_TRUE(status) << "Unable to initialize the mp3Reader";
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ SNDFILE *outFileHandle = openOutputFile(&sfInfo);
+ ASSERT_NE(outFileHandle, nullptr) << "Error opening output file for writing decoded output";
+
+ ERROR_CODE decoderErr = DecodeFrames(decoderBuf, outFileHandle, sfInfo);
+ ASSERT_EQ(decoderErr, NO_DECODING_ERROR) << "Failed to decode the frames";
+ ASSERT_EQ(sfInfo.channels, mConfig->num_channels) << "Number of channels does not match";
+ ASSERT_EQ(sfInfo.samplerate, mConfig->samplingRate) << "Sample rate does not match";
+
+ mMp3Reader.close();
+ sf_close(outFileHandle);
+ if (decoderBuf) {
+ free(decoderBuf);
+ decoderBuf = nullptr;
+ }
+}
+
+TEST_P(Mp3DecoderTest, ResetDecoderTest) {
+ size_t memRequirements = pvmp3_decoderMemRequirements();
+ ASSERT_NE(memRequirements, 0) << "Failed to get the memory requirement size";
+ void *decoderBuf = malloc(memRequirements);
+ ASSERT_NE(decoderBuf, nullptr)
+ << "Failed to allocate decoder memory of size " << memRequirements;
+
+ pvmp3_InitDecoder(mConfig, decoderBuf);
+ ALOGV("Decoder created successfully.");
+ string inputFile = gEnv->getRes() + GetParam();
+ bool status = mMp3Reader.init(inputFile.c_str());
+ ASSERT_TRUE(status) << "Unable to initialize the mp3Reader";
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ SNDFILE *outFileHandle = openOutputFile(&sfInfo);
+ ASSERT_NE(outFileHandle, nullptr) << "Error opening output file for writing decoded output";
+
+ ERROR_CODE decoderErr;
+ decoderErr = DecodeFrames(decoderBuf, outFileHandle, sfInfo, kNumFrameReset);
+ ASSERT_EQ(decoderErr, NO_DECODING_ERROR) << "Failed to decode the frames";
+ ASSERT_EQ(sfInfo.channels, mConfig->num_channels) << "Number of channels does not match";
+ ASSERT_EQ(sfInfo.samplerate, mConfig->samplingRate) << "Sample rate does not match";
+
+ pvmp3_resetDecoder(decoderBuf);
+ // Decode the same file.
+ decoderErr = DecodeFrames(decoderBuf, outFileHandle, sfInfo);
+ ASSERT_EQ(decoderErr, NO_DECODING_ERROR) << "Failed to decode the frames";
+ ASSERT_EQ(sfInfo.channels, mConfig->num_channels) << "Number of channels does not match";
+ ASSERT_EQ(sfInfo.samplerate, mConfig->samplingRate) << "Sample rate does not match";
+
+ mMp3Reader.close();
+ sf_close(outFileHandle);
+ if (decoderBuf) {
+ free(decoderBuf);
+ decoderBuf = nullptr;
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(Mp3DecoderTestAll, Mp3DecoderTest,
+ ::testing::Values(("bbb_44100hz_2ch_128kbps_mp3_30sec.mp3"),
+ ("bbb_44100hz_2ch_128kbps_mp3_5mins.mp3"),
+ ("bug_136053885.mp3"),
+ ("bbb_2ch_44kHz_lame_crc.mp3"),
+ ("bbb_mp3_stereo_192kbps_48000hz.mp3")));
+
+int main(int argc, char **argv) {
+ gEnv = new Mp3DecoderTestEnvironment();
+ ::testing::AddGlobalTestEnvironment(gEnv);
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = gEnv->initFromOptions(argc, argv);
+ if (status == 0) {
+ status = RUN_ALL_TESTS();
+ ALOGV("Test result = %d\n", status);
+ }
+ return status;
+}
diff --git a/media/codecs/mp3dec/test/Mp3DecoderTestEnvironment.h b/media/codecs/mp3dec/test/Mp3DecoderTestEnvironment.h
new file mode 100644
index 0000000..a54b34c
--- /dev/null
+++ b/media/codecs/mp3dec/test/Mp3DecoderTestEnvironment.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MP3DECODER_TEST_ENVIRONMENT_H__
+#define __MP3DECODER_TEST_ENVIRONMENT_H__
+
+#include <gtest/gtest.h>
+
+#include <getopt.h>
+
+using namespace std;
+
+class Mp3DecoderTestEnvironment : public ::testing::Environment {
+ public:
+ Mp3DecoderTestEnvironment() : res("/data/local/tmp/") {}
+
+ // Parses the command line arguments
+ int initFromOptions(int argc, char **argv);
+
+ void setRes(const char *_res) { res = _res; }
+
+ const string getRes() const { return res; }
+
+ private:
+ string res;
+};
+
+int Mp3DecoderTestEnvironment::initFromOptions(int argc, char **argv) {
+ static struct option options[] = {{"res", required_argument, 0, 'P'}, {0, 0, 0, 0}};
+
+ while (true) {
+ int index = 0;
+ int c = getopt_long(argc, argv, "P:", options, &index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'P':
+ setRes(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr,
+ "unrecognized option: %s\n\n"
+ "usage: %s <gtest options> <test options>\n\n"
+ "test options are:\n\n"
+ "-P, --path: Resource files directory location\n",
+ argv[optind ?: 1], argv[0]);
+ return 2;
+ }
+ return 0;
+}
+
+#endif // __MP3DECODER_TEST_ENVIRONMENT_H__
diff --git a/media/codecs/mp3dec/test/README.md b/media/codecs/mp3dec/test/README.md
new file mode 100644
index 0000000..f59fec7
--- /dev/null
+++ b/media/codecs/mp3dec/test/README.md
@@ -0,0 +1,39 @@
+## Media Testing ##
+---
+#### Mp3Decoder :
+The Mp3Decoder Test Suite validates the mp3decoder available in libstagefright.
+
+Run the following steps to build the test suite:
+```
+m Mp3DecoderTest
+```
+
+The 32-bit binaries will be created in the following path : ${OUT}/data/nativetest/
+
+The 64-bit binaries will be created in the following path : ${OUT}/data/nativetest64/
+
+To test 64-bit binary push binaries from nativetest64.
+```
+adb push ${OUT}/data/nativetest64/Mp3DecoderTest/Mp3DecoderTest /data/local/tmp/
+```
+
+To test 32-bit binary push binaries from nativetest.
+```
+adb push ${OUT}/data/nativetest/Mp3DecoderTest/Mp3DecoderTest /data/local/tmp/
+```
+
+The resource file for the tests is taken from [here](https://storage.googleapis.com/android_media/frameworks/av/media/libstagefright/mp3dec/test/Mp3DecoderTest.zip). Download, unzip and push these files into device for testing.
+
+```
+adb push Mp3DecoderTestRes/. /data/local/tmp/
+```
+
+usage: Mp3DecoderTest -P \<path_to_folder\>
+```
+adb shell /data/local/tmp/Mp3DecoderTest -P /data/local/tmp/Mp3DecoderTestRes/
+```
+Alternatively, the test can also be run using atest command.
+
+```
+atest Mp3DecoderTest -- --enable-module-dynamic-download=true
+```
diff --git a/media/codecs/mp3dec/test/mp3dec_test.cpp b/media/codecs/mp3dec/test/mp3dec_test.cpp
new file mode 100644
index 0000000..26d62f3
--- /dev/null
+++ b/media/codecs/mp3dec/test/mp3dec_test.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+#include "pvmp3decoder_api.h"
+#include "mp3reader.h"
+#include <audio_utils/sndfile.h>
+
+using namespace std;
+
+enum {
+ kInputBufferSize = 10 * 1024,
+ kOutputBufferSize = 4608 * 2,
+};
+
+int main(int argc, const char **argv) {
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage %s <input file> <output file>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ // Initialize the config.
+ tPVMP3DecoderExternal config;
+ config.equalizerType = flat;
+ config.crcEnabled = false;
+
+ // Allocate the decoder memory.
+ uint32_t memRequirements = pvmp3_decoderMemRequirements();
+ void *decoderBuf = malloc(memRequirements);
+ assert(decoderBuf != NULL);
+
+ // Initialize the decoder.
+ pvmp3_InitDecoder(&config, decoderBuf);
+
+ // Open the input file.
+ Mp3Reader mp3Reader;
+ bool success = mp3Reader.init(argv[1]);
+ if (!success) {
+ fprintf(stderr, "Encountered error reading %s\n", argv[1]);
+ free(decoderBuf);
+ return EXIT_FAILURE;
+ }
+
+ // Open the output file.
+ SF_INFO sfInfo;
+ memset(&sfInfo, 0, sizeof(SF_INFO));
+ sfInfo.channels = mp3Reader.getNumChannels();
+ sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ sfInfo.samplerate = mp3Reader.getSampleRate();
+ SNDFILE *handle = sf_open(argv[2], SFM_WRITE, &sfInfo);
+ if (handle == NULL) {
+ fprintf(stderr, "Encountered error writing %s\n", argv[2]);
+ mp3Reader.close();
+ free(decoderBuf);
+ return EXIT_FAILURE;
+ }
+
+ // Allocate input buffer.
+ uint8_t *inputBuf = static_cast<uint8_t*>(malloc(kInputBufferSize));
+ assert(inputBuf != NULL);
+
+ // Allocate output buffer.
+ int16_t *outputBuf = static_cast<int16_t*>(malloc(kOutputBufferSize));
+ assert(outputBuf != NULL);
+
+ // Decode loop.
+ int retVal = EXIT_SUCCESS;
+ while (1) {
+ // Read input from the file.
+ uint32_t bytesRead;
+ bool success = mp3Reader.getFrame(inputBuf, &bytesRead);
+ if (!success) break;
+
+ // Set the input config.
+ config.inputBufferCurrentLength = bytesRead;
+ config.inputBufferMaxLength = 0;
+ config.inputBufferUsedLength = 0;
+ config.pInputBuffer = inputBuf;
+ config.pOutputBuffer = outputBuf;
+ config.outputFrameSize = kOutputBufferSize / sizeof(int16_t);
+
+ ERROR_CODE decoderErr;
+ decoderErr = pvmp3_framedecoder(&config, decoderBuf);
+ if (decoderErr != NO_DECODING_ERROR) {
+ fprintf(stderr, "Decoder encountered error\n");
+ retVal = EXIT_FAILURE;
+ break;
+ }
+ sf_writef_short(handle, outputBuf,
+ config.outputFrameSize / sfInfo.channels);
+ }
+
+ // Close input reader and output writer.
+ mp3Reader.close();
+ sf_close(handle);
+
+ // Free allocated memory.
+ free(inputBuf);
+ free(outputBuf);
+ free(decoderBuf);
+
+ return retVal;
+}
diff --git a/media/codecs/mp3dec/test/mp3reader.cpp b/media/codecs/mp3dec/test/mp3reader.cpp
new file mode 100644
index 0000000..b3138ec
--- /dev/null
+++ b/media/codecs/mp3dec/test/mp3reader.cpp
@@ -0,0 +1,425 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <stdint.h>
+#include "mp3reader.h"
+
+static uint32_t U32_AT(const uint8_t *ptr) {
+ return ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
+}
+
+static bool parseHeader(
+ uint32_t header, size_t *frame_size,
+ uint32_t *out_sampling_rate = NULL, uint32_t *out_channels = NULL ,
+ uint32_t *out_bitrate = NULL, uint32_t *out_num_samples = NULL) {
+ *frame_size = 0;
+
+ if (out_sampling_rate) {
+ *out_sampling_rate = 0;
+ }
+
+ if (out_channels) {
+ *out_channels = 0;
+ }
+
+ if (out_bitrate) {
+ *out_bitrate = 0;
+ }
+
+ if (out_num_samples) {
+ *out_num_samples = 1152;
+ }
+
+ if ((header & 0xffe00000) != 0xffe00000) {
+ return false;
+ }
+
+ unsigned version = (header >> 19) & 3;
+
+ if (version == 0x01) {
+ return false;
+ }
+
+ unsigned layer = (header >> 17) & 3;
+
+ if (layer == 0x00) {
+ return false;
+ }
+
+ unsigned bitrate_index = (header >> 12) & 0x0f;
+
+ if (bitrate_index == 0 || bitrate_index == 0x0f) {
+ // Disallow "free" bitrate.
+ return false;
+ }
+
+ unsigned sampling_rate_index = (header >> 10) & 3;
+
+ if (sampling_rate_index == 3) {
+ return false;
+ }
+
+ static const int kSamplingRateV1[] = { 44100, 48000, 32000 };
+ int sampling_rate = kSamplingRateV1[sampling_rate_index];
+ if (version == 2 /* V2 */) {
+ sampling_rate /= 2;
+ } else if (version == 0 /* V2.5 */) {
+ sampling_rate /= 4;
+ }
+
+ unsigned padding = (header >> 9) & 1;
+
+ if (layer == 3) {
+ // layer I
+
+ static const int kBitrateV1[] = {
+ 32, 64, 96, 128, 160, 192, 224, 256,
+ 288, 320, 352, 384, 416, 448
+ };
+
+ static const int kBitrateV2[] = {
+ 32, 48, 56, 64, 80, 96, 112, 128,
+ 144, 160, 176, 192, 224, 256
+ };
+
+ int bitrate =
+ (version == 3 /* V1 */)
+ ? kBitrateV1[bitrate_index - 1]
+ : kBitrateV2[bitrate_index - 1];
+
+ if (out_bitrate) {
+ *out_bitrate = bitrate;
+ }
+
+ *frame_size = (12000 * bitrate / sampling_rate + padding) * 4;
+
+ if (out_num_samples) {
+ *out_num_samples = 384;
+ }
+ } else {
+ // layer II or III
+
+ static const int kBitrateV1L2[] = {
+ 32, 48, 56, 64, 80, 96, 112, 128,
+ 160, 192, 224, 256, 320, 384
+ };
+
+ static const int kBitrateV1L3[] = {
+ 32, 40, 48, 56, 64, 80, 96, 112,
+ 128, 160, 192, 224, 256, 320
+ };
+
+ static const int kBitrateV2[] = {
+ 8, 16, 24, 32, 40, 48, 56, 64,
+ 80, 96, 112, 128, 144, 160
+ };
+
+ int bitrate;
+ if (version == 3 /* V1 */) {
+ bitrate = (layer == 2 /* L2 */)
+ ? kBitrateV1L2[bitrate_index - 1]
+ : kBitrateV1L3[bitrate_index - 1];
+
+ if (out_num_samples) {
+ *out_num_samples = 1152;
+ }
+ } else {
+ // V2 (or 2.5)
+
+ bitrate = kBitrateV2[bitrate_index - 1];
+ if (out_num_samples) {
+ *out_num_samples = (layer == 1 /* L3 */) ? 576 : 1152;
+ }
+ }
+
+ if (out_bitrate) {
+ *out_bitrate = bitrate;
+ }
+
+ if (version == 3 /* V1 */) {
+ *frame_size = 144000 * bitrate / sampling_rate + padding;
+ } else {
+ // V2 or V2.5
+ size_t tmp = (layer == 1 /* L3 */) ? 72000 : 144000;
+ *frame_size = tmp * bitrate / sampling_rate + padding;
+ }
+ }
+
+ if (out_sampling_rate) {
+ *out_sampling_rate = sampling_rate;
+ }
+
+ if (out_channels) {
+ int channel_mode = (header >> 6) & 3;
+
+ *out_channels = (channel_mode == 3) ? 1 : 2;
+ }
+
+ return true;
+}
+
+// Mask to extract the version, layer, sampling rate parts of the MP3 header,
+// which should be same for all MP3 frames.
+static const uint32_t kMask = 0xfffe0c00;
+
+static ssize_t sourceReadAt(FILE *fp, off64_t offset, void *data, size_t size) {
+ int retVal = fseek(fp, offset, SEEK_SET);
+ if (retVal != EXIT_SUCCESS) {
+ return 0;
+ } else {
+ return fread(data, 1, size, fp);
+ }
+}
+
+// Resync to next valid MP3 frame in the file.
+static bool resync(
+ FILE *fp, uint32_t match_header,
+ off64_t *inout_pos, uint32_t *out_header) {
+
+ if (*inout_pos == 0) {
+ // Skip an optional ID3 header if syncing at the very beginning
+ // of the datasource.
+
+ for (;;) {
+ uint8_t id3header[10];
+ int retVal = sourceReadAt(fp, *inout_pos, id3header,
+ sizeof(id3header));
+ if (retVal < (ssize_t)sizeof(id3header)) {
+ // If we can't even read these 10 bytes, we might as well bail
+ // out, even if there _were_ 10 bytes of valid mp3 audio data...
+ return false;
+ }
+
+ if (memcmp("ID3", id3header, 3)) {
+ break;
+ }
+
+ // Skip the ID3v2 header.
+
+ size_t len =
+ ((id3header[6] & 0x7f) << 21)
+ | ((id3header[7] & 0x7f) << 14)
+ | ((id3header[8] & 0x7f) << 7)
+ | (id3header[9] & 0x7f);
+
+ len += 10;
+
+ *inout_pos += len;
+ }
+
+ }
+
+ off64_t pos = *inout_pos;
+ bool valid = false;
+
+ const int32_t kMaxReadBytes = 1024;
+ const int32_t kMaxBytesChecked = 128 * 1024;
+ uint8_t buf[kMaxReadBytes];
+ ssize_t bytesToRead = kMaxReadBytes;
+ ssize_t totalBytesRead = 0;
+ ssize_t remainingBytes = 0;
+ bool reachEOS = false;
+ uint8_t *tmp = buf;
+
+ do {
+ if (pos >= *inout_pos + kMaxBytesChecked) {
+ // Don't scan forever.
+ break;
+ }
+
+ if (remainingBytes < 4) {
+ if (reachEOS) {
+ break;
+ } else {
+ memcpy(buf, tmp, remainingBytes);
+ bytesToRead = kMaxReadBytes - remainingBytes;
+
+ /*
+ * The next read position should start from the end of
+ * the last buffer, and thus should include the remaining
+ * bytes in the buffer.
+ */
+ totalBytesRead = sourceReadAt(fp, pos + remainingBytes,
+ buf + remainingBytes, bytesToRead);
+
+ if (totalBytesRead <= 0) {
+ break;
+ }
+ reachEOS = (totalBytesRead != bytesToRead);
+ remainingBytes += totalBytesRead;
+ tmp = buf;
+ continue;
+ }
+ }
+
+ uint32_t header = U32_AT(tmp);
+
+ if (match_header != 0 && (header & kMask) != (match_header & kMask)) {
+ ++pos;
+ ++tmp;
+ --remainingBytes;
+ continue;
+ }
+
+ size_t frame_size;
+ uint32_t sample_rate, num_channels, bitrate;
+ if (!parseHeader(
+ header, &frame_size,
+ &sample_rate, &num_channels, &bitrate)) {
+ ++pos;
+ ++tmp;
+ --remainingBytes;
+ continue;
+ }
+
+ // We found what looks like a valid frame,
+ // now find its successors.
+
+ off64_t test_pos = pos + frame_size;
+
+ valid = true;
+ const int FRAME_MATCH_REQUIRED = 3;
+ for (int j = 0; j < FRAME_MATCH_REQUIRED; ++j) {
+ uint8_t tmp[4];
+ ssize_t retval = sourceReadAt(fp, test_pos, tmp, sizeof(tmp));
+ if (retval < (ssize_t)sizeof(tmp)) {
+ valid = false;
+ break;
+ }
+
+ uint32_t test_header = U32_AT(tmp);
+
+ if ((test_header & kMask) != (header & kMask)) {
+ valid = false;
+ break;
+ }
+
+ size_t test_frame_size;
+ if (!parseHeader(test_header, &test_frame_size)) {
+ valid = false;
+ break;
+ }
+
+ test_pos += test_frame_size;
+ }
+
+ if (valid) {
+ *inout_pos = pos;
+
+ if (out_header != NULL) {
+ *out_header = header;
+ }
+ }
+
+ ++pos;
+ ++tmp;
+ --remainingBytes;
+ } while (!valid);
+
+ return valid;
+}
+
+Mp3Reader::Mp3Reader() : mFp(NULL) {
+}
+
+// Initialize the MP3 reader.
+bool Mp3Reader::init(const char *file) {
+
+ // Open the file.
+ mFp = fopen(file, "rb");
+ if (mFp == NULL) return false;
+
+ // Sync to the first valid frame.
+ off64_t pos = 0;
+ uint32_t header;
+ bool success = resync(mFp, 0 /*match_header*/, &pos, &header);
+ if (success == false) return false;
+
+ mCurrentPos = pos;
+ mFixedHeader = header;
+
+ size_t frame_size;
+ return parseHeader(header, &frame_size, &mSampleRate,
+ &mNumChannels, &mBitrate);
+}
+
+// Get the next valid MP3 frame.
+bool Mp3Reader::getFrame(void *buffer, uint32_t *size) {
+
+ size_t frame_size;
+ uint32_t bitrate;
+ uint32_t num_samples;
+ uint32_t sample_rate;
+ for (;;) {
+ ssize_t n = sourceReadAt(mFp, mCurrentPos, buffer, 4);
+ if (n < 4) {
+ return false;
+ }
+
+ uint32_t header = U32_AT((const uint8_t *)buffer);
+
+ if ((header & kMask) == (mFixedHeader & kMask)
+ && parseHeader(
+ header, &frame_size, &sample_rate, NULL /*out_channels*/,
+ &bitrate, &num_samples)) {
+ break;
+ }
+
+ // Lost sync.
+ off64_t pos = mCurrentPos;
+ if (!resync(mFp, mFixedHeader, &pos, NULL /*out_header*/)) {
+ // Unable to resync. Signalling end of stream.
+ return false;
+ }
+
+ mCurrentPos = pos;
+
+ // Try again with the new position.
+ }
+ ssize_t n = sourceReadAt(mFp, mCurrentPos, buffer, frame_size);
+ if (n < (ssize_t)frame_size) {
+ return false;
+ }
+
+ *size = frame_size;
+ mCurrentPos += frame_size;
+ return true;
+}
+
+// Close the MP3 reader.
+void Mp3Reader::close() {
+ assert(mFp != NULL);
+ fclose(mFp);
+}
+
+Mp3Reader::~Mp3Reader() {
+}
diff --git a/media/codecs/mp3dec/test/mp3reader.h b/media/codecs/mp3dec/test/mp3reader.h
new file mode 100644
index 0000000..871f664
--- /dev/null
+++ b/media/codecs/mp3dec/test/mp3reader.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef MP3READER_H_
+#define MP3READER_H_
+
+class Mp3Reader {
+public:
+ Mp3Reader();
+ bool init(const char *file);
+ bool getFrame(void *buffer, uint32_t *size);
+ uint32_t getSampleRate() { return mSampleRate;}
+ uint32_t getNumChannels() { return mNumChannels;}
+ void close();
+ ~Mp3Reader();
+private:
+ FILE *mFp;
+ uint32_t mFixedHeader;
+ off64_t mCurrentPos;
+ uint32_t mSampleRate;
+ uint32_t mNumChannels;
+ uint32_t mBitrate;
+};
+
+
+#endif /* MP3READER_H_ */